UIUtil.java
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.metroapp.utils;
import android.app.Activity;
import android.content.Context;
import android.widget.Toast;
import com.metroapp.widget.CustomProgressDialog;
import java.text.SimpleDateFormat;
import java.util.Date;
public class UIUtil {
public static void showWaitDialog(Activity aty) {
CustomProgressDialog.show(aty);
}
public static void showWaitDialogWithoutTitle(Activity aty) {
CustomProgressDialog.showWithoutTitleBar(aty);
}
public static int dip2px(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
public static void dismissDlg() {
CustomProgressDialog.hidden();
}
public static void showToast(Activity aty, String msg) {
Toast.makeText(aty, msg, Toast.LENGTH_SHORT).show();
}
public static void showToast(Activity aty, int msg) {
Toast.makeText(aty, aty.getResources().getText(msg), Toast.LENGTH_SHORT).show();
}
private static long lastClickTime = 0;
// 防止按钮重复点击
public static boolean isFastDoubleClick(float ts) {
long time = System.currentTimeMillis();
long timeD = time - lastClickTime;
lastClickTime = time;
return 0 < timeD && timeD < ts * 1000;
}
public static int getScreenWidth(Context context) {
return context.getResources().getDisplayMetrics().widthPixels;
}
public static String isNull(String msg) {
if (null == msg || "null".equals(msg)) {
return "0";
} else {
return msg;
}
}
public static String formatTime(Long time){
Date date = new Date(time);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String dateString = formatter.format(date);
return dateString;
}
}