public class LogUtils {
private static Boolean isDebug = null;
private static String TAG = Constants.APP_TAG;
public static void e(String s) {
if (isDebug) {
e(TAG, s);
}
}
public static void e(String tag, String s) {
if (isDebug) {
Log.e(tag, s);
}
}
/**
* Sync lib debug with app's debug value. Should be called in module Application
*
* @param context
*/
public static void syncIsDebug(Context context) {
if (isDebug == null) {
isDebug = context.getApplicationInfo() != null &&
(context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
}
public static boolean isDebug() {
return isDebug == null ? false : isDebug.booleanValue();
}
}
public class WordUtil {
private static Resources sResources;
static {
sResources = CommonAppContext.sInstance.getResources();
}
public static String getString(int res) {
return sResources.getString(res);
}
}
/**
- Created by cxf on 2017/8/3.
*/
public class ToastUtil {
private static Toast sToast;
private static long sLastTime;
private static String sLastString;
static {
sToast = makeToast();
}
private static Toast makeToast() {
Toast toast = new Toast(CommonAppContext.sInstance);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
View view = LayoutInflater.from(CommonAppContext.sInstance).inflate(R.layout.view_toast, null);
toast.setView(view);
return toast;
}
public static void show(int res) {
show(WordUtil.getString(res));
}
public static void show(String s) {
if (TextUtils.isEmpty(s)) {
return;
}
long curTime = System.currentTimeMillis();
if (curTime - sLastTime > 2000) {
sLastTime = curTime;
sLastString = s;
sToast.setText(s);
sToast.show();
} else {
if (!s.equals(sLastString)) {
sLastTime = curTime;
sLastString = s;
sToast = makeToast();
sToast.setText(s);
sToast.show();
}
}
}
}
package com.zliang.chunzhen.utils;
import android.widget.EditText;
import android.widget.TextView;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
/**
- Created by cxf on 2018/9/29.
*/
public class StringUtil {
// 判断字符串是否为空
public static boolean isEmpty(String str) {
if (str == null)
return true;
if (str.length() == 0)
return true;
if (str.trim().length() == 0)
return true;
if (str.equals("null"))
return true;
return false;
}
public static String dropNull(String str) {
if (!isEmpty(str)) {
return str;
}
return "";
}
public static String nullToZero(String str) {
if (!isEmpty(str)) {
return str;
}
return "0";
}
public static String getTextViewValue(TextView textView) {
return textView.getText().toString().trim();
}
public static String getEditViewValue(EditText editText) {
return editText.getText().toString().trim();
}
public static int formatPingJiaScore(String score) {
return Integer.parseInt(String.valueOf(Math.round(Double.parseDouble(score))));
}
public static String formatTimeDropSecond(String time) {
if (isEmpty(time)){
return "";
}
if (time.length() >= 3) {
return time.substring(0, time.length() - 3);
}
return "";
}
public static String formatMoney(String money) {
NumberFormat nf = new DecimalFormat("0.00");
Double d = Double.parseDouble(nullToZero(money));
String temp = nf.format(d);
return "¥"+getPrettyNumber(temp);
// NumberFormat nf = new DecimalFormat(“¥0.00”);
// Double d = Double.parseDouble(nullToZero(money));
// return nf.format(d);
}
public static String format2Point(String money) {
NumberFormat nf = new DecimalFormat("0.00");
Double d = Double.parseDouble(nullToZero(money));
return nf.format(d);
}
public static String getPrettyNumber(String number) {
return BigDecimal.valueOf(Double.parseDouble(number))
.stripTrailingZeros().toPlainString();
}
}
<?xml version="1.0" encoding="utf-8"?><View
android:layout_width="match_parent"
android:layout_height="@dimen/line_height"
android:background="@color/common_line_color" />
public class Adapter_Bank extends RefreshAdapter {
private View.OnClickListener mOnClickListener;
public Adapter_Bank(Context context) {
super(context);
mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Object tag = v.getTag();
if (tag != null) {
int position = (int) tag;
if (mOnItemClickListener != null) {
mOnItemClickListener.onItemClick(mList.get(position), position);
}
}
}
};
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new Vh(mInflater.inflate(R.layout.item_bank, parent, false));
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder vh, int position) {
((Vh) vh).setData(mList.get(position), position);
}
class Vh extends RecyclerView.ViewHolder {
ImageView imgHead;
TextView textName;
public Vh(View itemView) {
super(itemView);
imgHead = (ImageView) itemView.findViewById(R.id.imgHead);
textName = (TextView) itemView.findViewById(R.id.textName);
itemView.setOnClickListener(mOnClickListener);
}
void setData(CardBean bean, int position) {
itemView.setTag(position);
if (StringUtil.isEmpty(bean.getImgs())){
imgHead.setVisibility(View.GONE);
}else {
imgHead.setVisibility(View.VISIBLE);
GlideApp.with(mContext)
.load(bean.getImgs()).into(imgHead);
}
textName.setText(bean.getName());
}
}
}