admin
7 天以前 7f0825f8195a522ed7e8bcdb6347f3a719e06c74
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
package com.weikou.beibeivideo.util.downutil;
 
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.widget.TextView;
 
import com.lcjian.library.util.common.DeviceUtil;
 
public class StringUtils {
 
    public static boolean isInt(String text) {
        if (text == null || text.length() == 0) {
            return false;
        }
        try {
            Integer.parseInt(text);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
 
    public static final String[] imageEndWiths = new String[] { ".jpg", ".gif",
            ".png", ".bmp" };
 
    public static boolean isEmail(String email) {
        String regex = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(email);
        return m.find();
    }
 
    /**
     * 是否是正确的电话号码
     * 
     * @param mobile
     * @return
     */
    public static boolean isMobile(String mobile) {
 
        String regex = "^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(mobile);
 
        if (mobile == null || mobile.equals("") || mobile.length() != 11) {
 
            return false;
 
        } else {
            return m.find();
        }
    }
 
    public static boolean isVoice(String text) {
 
        return text.toLowerCase().endsWith(".amr");
 
    }
 
    public static boolean isImage(String text) {
        text = text.toLowerCase();
        for (int i = 0; i < imageEndWiths.length; i++) {
            String endWidth = imageEndWiths[i];
            if (text.endsWith(endWidth)) {
                return true;
            }
        }
        return false;
    }
 
    public static String createNewFileName(String fileName) {
 
        int i = fileName.lastIndexOf(".");
 
        String end = fileName.substring(i, fileName.length());
 
        return System.currentTimeMillis() + end;
 
    }
 
    public static boolean isTrimEmpty(String text) {
        if (text == null || text.trim().length() == 0) {
            return true;
        }
        return false;
    }
 
    public static boolean isNullOrEmpty(String text) {
        if (text == null || text.length() == 0 || text.equals("null")) {
            return true;
        }
        return false;
    }
 
    public static String itrim(String beginTimeDis) {
        if (beginTimeDis != null) {
            int length = beginTimeDis.length();
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < length; i++) {
                char c = beginTimeDis.charAt(i);
                if (c != ':') {
                    buffer.append(c);
                } else {
                    buffer.append(":");
                }
            }
            return buffer.toString();
        }
 
        return null;
    }
 
    public static String getLocationDis(double distance) {
        if (distance < 0) {
            return "0m";
        } else if (distance < 100) {
            int d = (int) distance;
            return d + "m";
        } else {
            String desc = "";
 
            double f = distance / 1000d;
 
            DecimalFormat df = new DecimalFormat("#.###");
 
            desc = df.format(f);
 
            return desc + "km";
 
        }
 
    }
 
    public static int toInt(String nextText, int i) {
        try {
            int value = Integer.parseInt(nextText);
            return value;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return i;
    }
 
    /**
     * 身份证验�?
     * 
     * @param card
     * @return
     */
    public static boolean isIdCard(String card) {
        Pattern p = Pattern.compile("^(\\d{14}|\\d{17})(\\d|[xX])$");
        Matcher matcher = p.matcher(card);
        return matcher.matches();
    }
 
    public static boolean isCharecter(String str) {
        String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#�?…�?&*()—�?+|{}【�?‘;:�?“�?。,、?]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.find();
    }
 
    private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
 
    private static String toHexString(byte[] b) {
        // String to byte
        StringBuilder sb = new StringBuilder(b.length * 2);
        for (int i = 0; i < b.length; i++) {
            sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
            sb.append(HEX_DIGITS[b[i] & 0x0f]);
        }
        return sb.toString();
    }
 
    /*
     * MD5加密
     */
    public static String MD5(String s) {
        try {
            // Create MD5 Hash
            MessageDigest digest = java.security.MessageDigest
                    .getInstance("MD5");
            digest.update(s.getBytes());
            byte messageDigest[] = digest.digest();
 
            return toHexString(messageDigest);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
 
        return "";
    }
 
    public static String getSimpleString(String st) {
        if (isNullOrEmpty(st)) {
            return "暂无";
        }
        return st;
    }
 
    // 判断List是否为空
 
    public static boolean listIsNullOrEmpty(List<String> list) {
        if (list == null || list.size() == 0)
            return true;
        else
            return false;
    }
 
    // 获取手机型号
    public static String PeopleModel() {
        Build bd = new Build();
        String model = bd.MODEL;
        return model;
    };
 
    public static String PeopleDeviceId(Context context) {
        return    DeviceUtil.getImeiCache(context);
    }
 
    public static void getdiffrentColor(TextView tv, int color, int start,
            int end) {
        SpannableStringBuilder style = new SpannableStringBuilder(tv.getText());
        ForegroundColorSpan redSpan = new ForegroundColorSpan(color);
        style.setSpan(redSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv.setText(style);
    }
 
    public static void getdiffrentColor(TextView tv, int color, int size,
            int start, int end) {
        SpannableStringBuilder style = new SpannableStringBuilder(tv.getText());
        ForegroundColorSpan redSpan = new ForegroundColorSpan(color);
        style.setSpan(redSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        RelativeSizeSpan sizeSpan = new RelativeSizeSpan(size);
        style.setSpan(sizeSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv.setText(style);
    }
 
    public static String get2Number(int number) {
        if (number >= 0 && number < 10)
            return "0" + number;
        else
            return number + "";
    }
 
}