getAll(Context context) {
120 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
121 | Context.MODE_PRIVATE);
122 | return sp.getAll();
123 | }
124 |
125 | /**
126 | * 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类
127 | *
128 | * @author zhy
129 | *
130 | */
131 | private static class SharedPreferencesCompat {
132 | private static final Method sApplyMethod = findApplyMethod();
133 |
134 | /**
135 | * 反射查找apply的方法
136 | *
137 | * @return
138 | */
139 | @SuppressWarnings({ "unchecked", "rawtypes" })
140 | private static Method findApplyMethod() {
141 | try {
142 | Class clz = SharedPreferences.Editor.class;
143 | return clz.getMethod("apply");
144 | } catch (NoSuchMethodException e) {
145 | }
146 | return null;
147 | }
148 |
149 | /**
150 | * 如果找到则使用apply执行,否则使用commit
151 | *
152 | * @param editor
153 | */
154 | public static void apply(SharedPreferences.Editor editor) {
155 | try {
156 | if (sApplyMethod != null) {
157 | sApplyMethod.invoke(editor);
158 | return;
159 | }
160 | } catch (IllegalArgumentException e) {
161 | } catch (IllegalAccessException e) {
162 | } catch (InvocationTargetException e) {
163 | }
164 | editor.commit();
165 | }
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/app/src/main/java/utils/ScreenUtil.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Rect;
7 | import android.util.DisplayMetrics;
8 | import android.view.View;
9 | import android.view.WindowManager;
10 |
11 | /**
12 | * 屏幕相关辅助类
13 | */
14 | public class ScreenUtil {
15 |
16 | private ScreenUtil(){
17 | /*cannot be instantiated*/
18 | throw new UnsupportedOperationException("cannot be instantiated");
19 | }
20 |
21 | /**
22 | * 获得屏幕宽度
23 | *
24 | * @param context
25 | * @return
26 | */
27 | public static int getScreenWidth(Context context) {
28 | WindowManager wm = (WindowManager) context
29 | .getSystemService(Context.WINDOW_SERVICE);
30 | DisplayMetrics outMetrics = new DisplayMetrics();
31 | wm.getDefaultDisplay().getMetrics(outMetrics);
32 | return outMetrics.widthPixels;
33 | }
34 |
35 | /**
36 | * 获得屏幕高度
37 | *
38 | * @param context
39 | * @return
40 | */
41 | public static int getScreenHeight(Context context) {
42 | WindowManager wm = (WindowManager) context
43 | .getSystemService(Context.WINDOW_SERVICE);
44 | DisplayMetrics outMetrics = new DisplayMetrics();
45 | wm.getDefaultDisplay().getMetrics(outMetrics);
46 | return outMetrics.heightPixels;
47 | }
48 |
49 | /**
50 | * 获得状态栏的高度
51 | *
52 | * @param context
53 | * @return
54 | */
55 | public static int getStatusHeight(Context context) {
56 |
57 | int statusHeight = -1;
58 | try {
59 | Class> clazz = Class.forName("com.android.internal.R$dimen");
60 | Object object = clazz.newInstance();
61 | int height = Integer.parseInt(clazz.getField("status_bar_height")
62 | .get(object).toString());
63 | statusHeight = context.getResources().getDimensionPixelSize(height);
64 | } catch (Exception e) {
65 | e.printStackTrace();
66 | }
67 | return statusHeight;
68 | }
69 |
70 | /**
71 | * 获取当前屏幕截图,包含状态栏
72 | *
73 | * @param activity
74 | * @return
75 | */
76 | public static Bitmap snapShotWithStatusBar(Activity activity) {
77 | View view = activity.getWindow().getDecorView();
78 | view.setDrawingCacheEnabled(true);
79 | view.buildDrawingCache();
80 | Bitmap bmp = view.getDrawingCache();
81 | int width = getScreenWidth(activity);
82 | int height = getScreenHeight(activity);
83 | Bitmap bp = null;
84 | bp = Bitmap.createBitmap(bmp, 0, 0, width, height);
85 | view.destroyDrawingCache();
86 | return bp;
87 | }
88 |
89 | /**
90 | * 获取当前屏幕截图,不包含状态栏
91 | *
92 | * @param activity
93 | * @return
94 | */
95 | public static Bitmap snapShotWithoutStatusBar(Activity activity) {
96 | View view = activity.getWindow().getDecorView();
97 | view.setDrawingCacheEnabled(true);
98 | view.buildDrawingCache();
99 | Bitmap bmp = view.getDrawingCache();
100 | Rect frame = new Rect();
101 | activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
102 | int statusBarHeight = frame.top;
103 |
104 | int width = getScreenWidth(activity);
105 | int height = getScreenHeight(activity);
106 | Bitmap bp = null;
107 | bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height
108 | - statusBarHeight);
109 | view.destroyDrawingCache();
110 | return bp;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/app/src/main/java/utils/ShortCutUtil.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | import android.app.Activity;
4 | import android.content.ComponentName;
5 | import android.content.ContentResolver;
6 | import android.content.Intent;
7 | import android.database.Cursor;
8 | import android.net.Uri;
9 |
10 | import com.example.hjx.androidutils.R;
11 |
12 | /**
13 | * 创建删除快捷图标
14 | *
15 | * 需要权限: com.android.launcher.permission.INSTALL_SHORTCUT
16 | * com.android.launcher.permission.UNINSTALL_SHORTCUT
17 | */
18 | public final class ShortCutUtil {
19 |
20 | /**
21 | * Don't let anyone instantiate this class.
22 | */
23 | private ShortCutUtil() {
24 | throw new Error("Do not need instantiate!");
25 | }
26 |
27 | /**
28 | * 检测是否存在快捷键
29 | *
30 | * @param activity Activity
31 | * @return 是否存在桌面图标
32 | */
33 | public static boolean hasShortcut(Activity activity) {
34 | boolean isInstallShortcut = false;
35 | final ContentResolver cr = activity.getContentResolver();
36 | final String AUTHORITY = "com.android.launcher.settings";
37 | final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
38 | + "/favorites?notify=true");
39 | Cursor c = cr.query(CONTENT_URI,
40 | new String[]{"title", "iconResource"}, "title=?",
41 | new String[]{activity.getString(R.string.app_name).trim()},
42 | null);
43 | if (c != null && c.getCount() > 0) {
44 | isInstallShortcut = true;
45 | }
46 | return isInstallShortcut;
47 | }
48 |
49 | /**
50 | * 为程序创建桌面快捷方式
51 | *
52 | * @param activity Activity
53 | * @param res res
54 | */
55 | public static void addShortcut(Activity activity,int res) {
56 |
57 | Intent shortcut = new Intent(
58 | "com.android.launcher.action.INSTALL_SHORTCUT");
59 | // 快捷方式的名称
60 | shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
61 | activity.getString(R.string.app_name));
62 | // 不允许重复创建
63 | shortcut.putExtra("duplicate", false);
64 | Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
65 | shortcutIntent.setClassName(activity, activity.getClass().getName());
66 | shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
67 | // 快捷方式的图标
68 | Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(
69 | activity, res);
70 | shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
71 |
72 | activity.sendBroadcast(shortcut);
73 | }
74 |
75 | /**
76 | * 删除程序的快捷方式
77 | *
78 | * @param activity Activity
79 | */
80 | public static void delShortcut(Activity activity) {
81 |
82 | Intent shortcut = new Intent(
83 | "com.android.launcher.action.UNINSTALL_SHORTCUT");
84 | // 快捷方式的名称
85 | shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
86 | activity.getString(R.string.app_name));
87 | String appClass = activity.getPackageName() + "."
88 | + activity.getLocalClassName();
89 | ComponentName comp = new ComponentName(activity.getPackageName(),
90 | appClass);
91 | shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(
92 | Intent.ACTION_MAIN).setComponent(comp));
93 | activity.sendBroadcast(shortcut);
94 | }
95 | }
96 |
97 |
--------------------------------------------------------------------------------
/app/src/main/java/utils/StringUtil.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLEncoder;
5 | import java.security.MessageDigest;
6 | import java.util.ArrayList;
7 | import java.util.Locale;
8 | import java.util.regex.Matcher;
9 | import java.util.regex.Pattern;
10 |
11 | /**
12 | * 字符串工具类,提供一些字符串相关的便捷方法
13 | */
14 | public class StringUtil {
15 |
16 | private StringUtil() {
17 | throw new AssertionError();
18 | }
19 |
20 |
21 | /**
22 | * is null or its length is 0 or it is made by space
23 | *
24 | *
25 | * isBlank(null) = true;
26 | * isBlank("") = true;
27 | * isBlank(" ") = true;
28 | * isBlank("a") = false;
29 | * isBlank("a ") = false;
30 | * isBlank(" a") = false;
31 | * isBlank("a b") = false;
32 | *
33 | *
34 | * @param str str
35 | * @return if string is null or its size is 0 or it is made by space, return
36 | * true, else return false.
37 | */
38 | public static boolean isBlank(String str) {
39 |
40 | return (str == null || str.trim().length() == 0);
41 | }
42 |
43 |
44 | /**
45 | * is null or its length is 0
46 | *
47 | *
48 | * isEmpty(null) = true;
49 | * isEmpty("") = true;
50 | * isEmpty(" ") = false;
51 | *
52 | *
53 | * @param str str
54 | * @return if string is null or its size is 0, return true, else return
55 | * false.
56 | */
57 | public static boolean isEmpty(CharSequence str) {
58 |
59 | return (str == null || str.length() == 0);
60 | }
61 |
62 |
63 | /**
64 | * get length of CharSequence
65 | *
66 | *
67 | * length(null) = 0;
68 | * length(\"\") = 0;
69 | * length(\"abc\") = 3;
70 | *
71 | *
72 | * @param str str
73 | * @return if str is null or empty, return 0, else return {@link
74 | * CharSequence#length()}.
75 | */
76 | public static int length(CharSequence str) {
77 |
78 | return str == null ? 0 : str.length();
79 | }
80 |
81 |
82 | /**
83 | * null Object to empty string
84 | *
85 | *
86 | * nullStrToEmpty(null) = "";
87 | * nullStrToEmpty("") = "";
88 | * nullStrToEmpty("aa") = "aa";
89 | *
90 | *
91 | * @param str str
92 | * @return String
93 | */
94 | public static String nullStrToEmpty(Object str) {
95 |
96 | return (str == null
97 | ? ""
98 | : (str instanceof String ? (String) str : str.toString()));
99 | }
100 |
101 |
102 | /**
103 | * @param str str
104 | * @return String
105 | */
106 | public static String capitalizeFirstLetter(String str) {
107 |
108 | if (isEmpty(str)) {
109 | return str;
110 | }
111 |
112 | char c = str.charAt(0);
113 | return (!Character.isLetter(c) || Character.isUpperCase(c))
114 | ? str
115 | : new StringBuilder(str.length()).append(
116 | Character.toUpperCase(c))
117 | .append(str.substring(1))
118 | .toString();
119 | }
120 |
121 |
122 | /**
123 | * encoded in utf-8
124 | *
125 | * @param str 字符串
126 | * @return 返回一个utf8的字符串
127 | */
128 | public static String utf8Encode(String str) {
129 |
130 | if (!isEmpty(str) && str.getBytes().length != str.length()) {
131 | try {
132 | return URLEncoder.encode(str, "UTF-8");
133 | } catch (UnsupportedEncodingException e) {
134 | throw new RuntimeException(
135 | "UnsupportedEncodingException occurred. ", e);
136 | }
137 | }
138 | return str;
139 | }
140 |
141 |
142 | /**
143 | * @param href 字符串
144 | * @return 返回一个html
145 | */
146 | public static String getHrefInnerHtml(String href) {
147 |
148 | if (isEmpty(href)) {
149 | return "";
150 | }
151 |
152 | String hrefReg = ".*<[\\s]*a[\\s]*.*>(.+?)<[\\s]*/a[\\s]*>.*";
153 | Pattern hrefPattern = Pattern.compile(hrefReg,
154 | Pattern.CASE_INSENSITIVE);
155 | Matcher hrefMatcher = hrefPattern.matcher(href);
156 | if (hrefMatcher.matches()) {
157 | return hrefMatcher.group(1);
158 | }
159 | return href;
160 | }
161 |
162 |
163 | /**
164 | * @param source 字符串
165 | * @return 返回htmL到字符串
166 | */
167 | public static String htmlEscapeCharsToString(String source) {
168 |
169 | return StringUtil.isEmpty(source)
170 | ? source
171 | : source.replaceAll("<", "<")
172 | .replaceAll(">", ">")
173 | .replaceAll("&", "&")
174 | .replaceAll(""", "\"");
175 | }
176 |
177 |
178 | /**
179 | * @param s str
180 | * @return String
181 | */
182 | public static String fullWidthToHalfWidth(String s) {
183 |
184 | if (isEmpty(s)) {
185 | return s;
186 | }
187 |
188 | char[] source = s.toCharArray();
189 | for (int i = 0; i < source.length; i++) {
190 | if (source[i] == 12288) {
191 | source[i] = ' ';
192 | // } else if (source[i] == 12290) {
193 | // source[i] = '.';
194 | }
195 | else if (source[i] >= 65281 && source[i] <= 65374) {
196 | source[i] = (char) (source[i] - 65248);
197 | }
198 | else {
199 | source[i] = source[i];
200 | }
201 | }
202 | return new String(source);
203 | }
204 |
205 |
206 | /**
207 | * @param s 字符串
208 | * @return 返回的数值
209 | */
210 | public static String halfWidthToFullWidth(String s) {
211 |
212 | if (isEmpty(s)) {
213 | return s;
214 | }
215 |
216 | char[] source = s.toCharArray();
217 | for (int i = 0; i < source.length; i++) {
218 | if (source[i] == ' ') {
219 | source[i] = (char) 12288;
220 | // } else if (source[i] == '.') {
221 | // source[i] = (char)12290;
222 | }
223 | else if (source[i] >= 33 && source[i] <= 126) {
224 | source[i] = (char) (source[i] + 65248);
225 | }
226 | else {
227 | source[i] = source[i];
228 | }
229 | }
230 | return new String(source);
231 | }
232 |
233 |
234 | /**
235 | * @param str 资源
236 | * @return 特殊字符串切换
237 | */
238 |
239 | public static String replaceBlanktihuan(String str) {
240 |
241 | String dest = "";
242 | if (str != null) {
243 | Pattern p = Pattern.compile("\\s*|\t|\r|\n");
244 | Matcher m = p.matcher(str);
245 | dest = m.replaceAll("");
246 | }
247 | return dest;
248 | }
249 |
250 |
251 | /**
252 | * 判断给定的字符串是否为null或者是空的
253 | *
254 | * @param string 给定的字符串
255 | */
256 | public static boolean isEmpty(String string) {
257 | return string == null || "".equals(string.trim());
258 | }
259 |
260 |
261 | /**
262 | * 判断给定的字符串是否不为null且不为空
263 | *
264 | * @param string 给定的字符串
265 | */
266 | public static boolean isNotEmpty(String string) {
267 | return !isEmpty(string);
268 | }
269 |
270 |
271 | /**
272 | * 判断给定的字符串数组中的所有字符串是否都为null或者是空的
273 | *
274 | * @param strings 给定的字符串
275 | */
276 | public static boolean isEmpty(String... strings) {
277 | boolean result = true;
278 | for (String string : strings) {
279 | if (isNotEmpty(string)) {
280 | result = false;
281 | break;
282 | }
283 | }
284 | return result;
285 | }
286 |
287 |
288 | /**
289 | * 判断给定的字符串数组中是否全部都不为null且不为空
290 | *
291 | * @param strings 给定的字符串数组
292 | * @return 是否全部都不为null且不为空
293 | */
294 | public static boolean isNotEmpty(String... strings) {
295 | boolean result = true;
296 | for (String string : strings) {
297 | if (isEmpty(string)) {
298 | result = false;
299 | break;
300 | }
301 | }
302 | return result;
303 | }
304 |
305 |
306 | /**
307 | * 如果字符串是null或者空就返回""
308 | */
309 | public static String filterEmpty(String string) {
310 | return StringUtil.isNotEmpty(string) ? string : "";
311 | }
312 |
313 |
314 | /**
315 | * 在给定的字符串中,用新的字符替换所有旧的字符
316 | *
317 | * @param string 给定的字符串
318 | * @param oldchar 旧的字符
319 | * @param newchar 新的字符
320 | * @return 替换后的字符串
321 | */
322 | public static String replace(String string, char oldchar, char newchar) {
323 | char chars[] = string.toCharArray();
324 | for (int w = 0; w < chars.length; w++) {
325 | if (chars[w] == oldchar) {
326 | chars[w] = newchar;
327 | break;
328 | }
329 | }
330 | return new String(chars);
331 | }
332 |
333 |
334 | /**
335 | * 把给定的字符串用给定的字符分割
336 | *
337 | * @param string 给定的字符串
338 | * @param ch 给定的字符
339 | * @return 分割后的字符串数组
340 | */
341 | public static String[] split(String string, char ch) {
342 | ArrayList stringList = new ArrayList();
343 | char chars[] = string.toCharArray();
344 | int nextStart = 0;
345 | for (int w = 0; w < chars.length; w++) {
346 | if (ch == chars[w]) {
347 | stringList.add(new String(chars, nextStart, w - nextStart));
348 | nextStart = w + 1;
349 | if (nextStart ==
350 | chars.length) { //当最后一位是分割符的话,就再添加一个空的字符串到分割数组中去
351 | stringList.add("");
352 | }
353 | }
354 | }
355 | if (nextStart <
356 | chars.length) { //如果最后一位不是分隔符的话,就将最后一个分割符到最后一个字符中间的左右字符串作为一个字符串添加到分割数组中去
357 | stringList.add(new String(chars, nextStart,
358 | chars.length - 1 - nextStart + 1));
359 | }
360 | return stringList.toArray(new String[stringList.size()]);
361 | }
362 |
363 |
364 | /**
365 | * 计算给定的字符串的长度,计算规则是:一个汉字的长度为2,一个字符的长度为1
366 | *
367 | * @param string 给定的字符串
368 | * @return 长度
369 | */
370 | public static int countLength(String string) {
371 | int length = 0;
372 | char[] chars = string.toCharArray();
373 | for (int w = 0; w < string.length(); w++) {
374 | char ch = chars[w];
375 | if (ch >= '\u0391' && ch <= '\uFFE5') {
376 | length++;
377 | length++;
378 | }
379 | else {
380 | length++;
381 | }
382 | }
383 | return length;
384 | }
385 |
386 |
387 | private static char[] getChars(char[] chars, int startIndex) {
388 | int endIndex = startIndex + 1;
389 | //如果第一个是数字
390 | if (Character.isDigit(chars[startIndex])) {
391 | //如果下一个是数字
392 | while (endIndex < chars.length &&
393 | Character.isDigit(chars[endIndex])) {
394 | endIndex++;
395 | }
396 | }
397 | char[] resultChars = new char[endIndex - startIndex];
398 | System.arraycopy(chars, startIndex, resultChars, 0, resultChars.length);
399 | return resultChars;
400 | }
401 |
402 |
403 | /**
404 | * 是否全是数字
405 | */
406 | public static boolean isAllDigital(char[] chars) {
407 | boolean result = true;
408 | for (int w = 0; w < chars.length; w++) {
409 | if (!Character.isDigit(chars[w])) {
410 | result = false;
411 | break;
412 | }
413 | }
414 | return result;
415 | }
416 |
417 |
418 |
419 |
420 | /**
421 | * 删除给定字符串中所有的旧的字符
422 | *
423 | * @param string 源字符串
424 | * @param ch 要删除的字符
425 | * @return 删除后的字符串
426 | */
427 | public static String removeChar(String string, char ch) {
428 | StringBuffer sb = new StringBuffer();
429 | for (char cha : string.toCharArray()) {
430 | if (cha != '-') {
431 | sb.append(cha);
432 | }
433 | }
434 | return sb.toString();
435 | }
436 |
437 |
438 | /**
439 | * 删除给定字符串中给定位置处的字符
440 | *
441 | * @param string 给定字符串
442 | * @param index 给定位置
443 | */
444 | public static String removeChar(String string, int index) {
445 | String result = null;
446 | char[] chars = string.toCharArray();
447 | if (index == 0) {
448 | result = new String(chars, 1, chars.length - 1);
449 | }
450 | else if (index == chars.length - 1) {
451 | result = new String(chars, 0, chars.length - 1);
452 | }
453 | else {
454 | result = new String(chars, 0, index) +
455 | new String(chars, index + 1, chars.length - index);
456 | ;
457 | }
458 | return result;
459 | }
460 |
461 |
462 | /**
463 | * 删除给定字符串中给定位置处的字符
464 | *
465 | * @param string 给定字符串
466 | * @param index 给定位置
467 | * @param ch 如果同给定位置处的字符相同,则将给定位置处的字符删除
468 | */
469 | public static String removeChar(String string, int index, char ch) {
470 | String result = null;
471 | char[] chars = string.toCharArray();
472 | if (chars.length > 0 && chars[index] == ch) {
473 | if (index == 0) {
474 | result = new String(chars, 1, chars.length - 1);
475 | }
476 | else if (index == chars.length - 1) {
477 | result = new String(chars, 0, chars.length - 1);
478 | }
479 | else {
480 | result = new String(chars, 0, index) +
481 | new String(chars, index + 1, chars.length - index);
482 | ;
483 | }
484 | }
485 | else {
486 | result = string;
487 | }
488 | return result;
489 | }
490 |
491 |
492 | /**
493 | * 对给定的字符串进行空白过滤
494 | *
495 | * @param string 给定的字符串
496 | * @return 如果给定的字符串是一个空白字符串,那么返回null;否则返回本身。
497 | */
498 | public static String filterBlank(String string) {
499 | if ("".equals(string)) {
500 | return null;
501 | }
502 | else {
503 | return string;
504 | }
505 | }
506 |
507 |
508 | /**
509 | * 将给定字符串中给定的区域的字符转换成小写
510 | *
511 | * @param str 给定字符串中
512 | * @param beginIndex 开始索引(包括)
513 | * @param endIndex 结束索引(不包括)
514 | * @return 新的字符串
515 | */
516 | public static String toLowerCase(String str, int beginIndex, int endIndex) {
517 | return str.replaceFirst(str.substring(beginIndex, endIndex),
518 | str.substring(beginIndex, endIndex)
519 | .toLowerCase(Locale.getDefault()));
520 | }
521 |
522 |
523 | /**
524 | * 将给定字符串中给定的区域的字符转换成大写
525 | *
526 | * @param str 给定字符串中
527 | * @param beginIndex 开始索引(包括)
528 | * @param endIndex 结束索引(不包括)
529 | * @return 新的字符串
530 | */
531 | public static String toUpperCase(String str, int beginIndex, int endIndex) {
532 | return str.replaceFirst(str.substring(beginIndex, endIndex),
533 | str.substring(beginIndex, endIndex)
534 | .toUpperCase(Locale.getDefault()));
535 | }
536 |
537 |
538 | /**
539 | * 将给定字符串的首字母转为小写
540 | *
541 | * @param str 给定字符串
542 | * @return 新的字符串
543 | */
544 | public static String firstLetterToLowerCase(String str) {
545 | return toLowerCase(str, 0, 1);
546 | }
547 |
548 |
549 | /**
550 | * 将给定字符串的首字母转为大写
551 | *
552 | * @param str 给定字符串
553 | * @return 新的字符串
554 | */
555 | public static String firstLetterToUpperCase(String str) {
556 | return toUpperCase(str, 0, 1);
557 | }
558 |
559 |
560 | /**
561 | * 将给定的字符串MD5加密
562 | *
563 | * @param string 给定的字符串
564 | * @return MD5加密后生成的字符串
565 | */
566 | public static String MD5(String string) {
567 | String result = null;
568 | try {
569 | char[] charArray = string.toCharArray();
570 | byte[] byteArray = new byte[charArray.length];
571 | for (int i = 0; i < charArray.length; i++) {
572 | byteArray[i] = (byte) charArray[i];
573 | }
574 |
575 | StringBuffer hexValue = new StringBuffer();
576 | byte[] md5Bytes = MessageDigest.getInstance("MD5")
577 | .digest(byteArray);
578 | for (int i = 0; i < md5Bytes.length; i++) {
579 | int val = ((int) md5Bytes[i]) & 0xff;
580 | if (val < 16) {
581 | hexValue.append("0");
582 | }
583 | hexValue.append(Integer.toHexString(val));
584 | }
585 |
586 | result = hexValue.toString();
587 | } catch (Exception e) {
588 | e.printStackTrace();
589 | }
590 | return result;
591 | }
592 |
593 |
594 | /**
595 | * 判断给定的字符串是否以一个特定的字符串开头,忽略大小写
596 | *
597 | * @param sourceString 给定的字符串
598 | * @param newString 一个特定的字符串
599 | */
600 | public static boolean startsWithIgnoreCase(String sourceString, String newString) {
601 | int newLength = newString.length();
602 | int sourceLength = sourceString.length();
603 | if (newLength == sourceLength) {
604 | return newString.equalsIgnoreCase(sourceString);
605 | }
606 | else if (newLength < sourceLength) {
607 | char[] newChars = new char[newLength];
608 | sourceString.getChars(0, newLength, newChars, 0);
609 | return newString.equalsIgnoreCase(String.valueOf(newChars));
610 | }
611 | else {
612 | return false;
613 | }
614 | }
615 |
616 |
617 | /**
618 | * 判断给定的字符串是否以一个特定的字符串结尾,忽略大小写
619 | *
620 | * @param sourceString 给定的字符串
621 | * @param newString 一个特定的字符串
622 | */
623 | public static boolean endsWithIgnoreCase(String sourceString, String newString) {
624 | int newLength = newString.length();
625 | int sourceLength = sourceString.length();
626 | if (newLength == sourceLength) {
627 | return newString.equalsIgnoreCase(sourceString);
628 | }
629 | else if (newLength < sourceLength) {
630 | char[] newChars = new char[newLength];
631 | sourceString.getChars(sourceLength - newLength, sourceLength,
632 | newChars, 0);
633 | return newString.equalsIgnoreCase(String.valueOf(newChars));
634 | }
635 | else {
636 | return false;
637 | }
638 | }
639 |
640 |
641 | /**
642 | * 检查字符串长度,如果字符串的长度超过maxLength,就截取前maxLength个字符串并在末尾拼上appendString
643 | */
644 | public static String checkLength(String string, int maxLength, String appendString) {
645 | if (string.length() > maxLength) {
646 | string = string.substring(0, maxLength);
647 | if (appendString != null) {
648 | string += appendString;
649 | }
650 | }
651 | return string;
652 | }
653 |
654 |
655 | /**
656 | * 检查字符串长度,如果字符串的长度超过maxLength,就截取前maxLength个字符串并在末尾拼上…
657 | */
658 | public static String checkLength(String string, int maxLength) {
659 | return checkLength(string, maxLength, "…");
660 | }
661 | }
662 |
--------------------------------------------------------------------------------
/app/src/main/java/utils/ToastUtil.java:
--------------------------------------------------------------------------------
1 | package utils;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 |
6 | /**
7 | * Toast统一管理类
8 | */
9 | public class ToastUtil {
10 |
11 | public static boolean isShow = true;
12 |
13 | /*cannot be instantiated*/
14 | private ToastUtil(){
15 | throw new UnsupportedOperationException("cannot be instantiated");
16 | }
17 |
18 | /**
19 | * 短时间显示Toast
20 | *
21 | * @param context
22 | * @param message
23 | */
24 | public static void showShort(Context context, CharSequence message) {
25 | if (isShow)
26 | Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
27 | }
28 |
29 | /**
30 | * 短时间显示Toast
31 | *
32 | * @param context
33 | * @param message
34 | */
35 | public static void showShort(Context context, int message) {
36 | if (isShow)
37 | Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
38 | }
39 |
40 | /**
41 | * 长时间显示Toast
42 | *
43 | * @param context
44 | * @param message
45 | */
46 | public static void showLong(Context context, CharSequence message) {
47 | if (isShow)
48 | Toast.makeText(context, message, Toast.LENGTH_LONG).show();
49 | }
50 |
51 | /**
52 | * 长时间显示Toast
53 | *
54 | * @param context
55 | * @param message
56 | */
57 | public static void showLong(Context context, int message) {
58 | if (isShow)
59 | Toast.makeText(context, message, Toast.LENGTH_LONG).show();
60 | }
61 |
62 | /**
63 | * 自定义显示Toast时间
64 | *
65 | * @param context
66 | * @param message
67 | * @param duration
68 | */
69 | public static void show(Context context, CharSequence message, int duration) {
70 | if (isShow)
71 | Toast.makeText(context, message, duration).show();
72 | }
73 |
74 | /**
75 | * 自定义显示Toast时间
76 | *
77 | * @param context
78 | * @param message
79 | * @param duration
80 | */
81 | public static void show(Context context, int message, int duration) {
82 | if (isShow)
83 | Toast.makeText(context, message, duration).show();
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/utils/view/CheckBoxView.java:
--------------------------------------------------------------------------------
1 | package utils.view;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.PorterDuff;
10 | import android.graphics.PorterDuffXfermode;
11 | import android.graphics.drawable.Drawable;
12 | import android.util.AttributeSet;
13 | import android.view.View;
14 | import android.widget.Checkable;
15 |
16 | import com.example.hjx.androidutils.R;
17 |
18 | /**
19 | * 自定义CheckBox
20 | */
21 | public class CheckBoxView extends View implements Checkable{
22 |
23 | private final static float BOUNCE_VALUE = 0.2f;
24 |
25 | private Drawable checkDrawable;
26 |
27 | private Paint bitmapPaint;
28 | private Paint bitmapEraser;
29 | private Paint checkEraser;
30 | private Paint borderPaint;
31 |
32 | private Bitmap drawBitmap;
33 | private Bitmap checkBitmap;
34 | private Canvas bitmapCanvas;
35 | private Canvas checkCanvas;
36 |
37 | private float progress;
38 | private ObjectAnimator checkAnim;
39 |
40 | private boolean attachedToWindow;
41 | private boolean isChecked;
42 |
43 | private int size = 22;
44 | private int bitmapColor = 0xFF3F51B5;
45 | private int borderColor = 0xFFFFFFFF;
46 |
47 | public CheckBoxView(Context context) {
48 | this(context, null);
49 | }
50 |
51 | public CheckBoxView(Context context, AttributeSet attrs) {
52 | this(context, attrs, 0);
53 | }
54 |
55 | public CheckBoxView(Context context, AttributeSet attrs, int defStyle) {
56 | super(context, attrs, defStyle);
57 | init(context, attrs);
58 | }
59 |
60 | private void init(Context context, AttributeSet attrs) {
61 | TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.CheckBoxView);
62 | size = ta.getDimensionPixelSize(R.styleable.CheckBoxView_size, dp(size));
63 | bitmapColor = ta.getColor(R.styleable.CheckBoxView_color_background, bitmapColor);
64 | borderColor = ta.getColor(R.styleable.CheckBoxView_color_border, borderColor);
65 |
66 | bitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
67 | bitmapEraser = new Paint(Paint.ANTI_ALIAS_FLAG);
68 | bitmapEraser.setColor(0);
69 | bitmapEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
70 | checkEraser = new Paint(Paint.ANTI_ALIAS_FLAG);
71 | checkEraser.setColor(0);
72 | checkEraser.setStyle(Paint.Style.STROKE);
73 | checkEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
74 | borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
75 | borderPaint.setStyle(Paint.Style.STROKE);
76 | borderPaint.setStrokeWidth(dp(2));
77 | checkDrawable = context.getResources().getDrawable(R.mipmap.check);
78 | setVisibility(VISIBLE);
79 | ta.recycle();
80 | }
81 |
82 | @Override
83 | public void setVisibility(int visibility) {
84 | super.setVisibility(visibility);
85 | if (visibility == VISIBLE && drawBitmap == null) {
86 | drawBitmap = Bitmap.createBitmap(dp(size), dp(size), Bitmap.Config.ARGB_8888);
87 | bitmapCanvas = new Canvas(drawBitmap);
88 | checkBitmap = Bitmap.createBitmap(dp(size), dp(size), Bitmap.Config.ARGB_8888);
89 | checkCanvas = new Canvas(checkBitmap);
90 | }
91 | }
92 |
93 | @Override
94 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
95 | int newSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.getMode(Math.min(widthMeasureSpec, heightMeasureSpec)));
96 | super.onMeasure(newSpec, newSpec);
97 | }
98 |
99 | @Override
100 | protected void onDraw(Canvas canvas) {
101 | if (getVisibility() != VISIBLE) {
102 | return;
103 | }
104 | checkEraser.setStrokeWidth(size);
105 |
106 | drawBitmap.eraseColor(0);
107 | float rad = getMeasuredWidth() / 2;
108 |
109 | float bitmapProgress = progress >= 0.5f ? 1.0f : progress / 0.5f;
110 | float checkProgress = progress < 0.5f ? 0.0f : (progress - 0.5f) / 0.5f;
111 |
112 | float p = isChecked ? progress : (1.0f - progress);
113 |
114 | if (p < BOUNCE_VALUE) {
115 | rad -= dp(2) * p ;
116 | } else if (p < BOUNCE_VALUE * 2) {
117 | rad -= dp(2) - dp(2) * p;
118 | }
119 |
120 | borderPaint.setColor(borderColor);
121 | canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, rad - dp(1), borderPaint);
122 |
123 | bitmapPaint.setColor(bitmapColor);
124 |
125 | bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, rad, bitmapPaint);
126 | bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, rad * (1 - bitmapProgress), bitmapEraser);
127 | canvas.drawBitmap(drawBitmap, 0, 0, null);
128 |
129 | checkBitmap.eraseColor(0);
130 | int w = checkDrawable.getIntrinsicWidth();
131 | int h = checkDrawable.getIntrinsicHeight();
132 | int x = (getMeasuredWidth() - w) / 2;
133 | int y = (getMeasuredHeight() - h) / 2;
134 |
135 | checkDrawable.setBounds(x, y , x + w, y + h );
136 | checkDrawable.draw(checkCanvas);
137 | checkCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, rad * (1 - checkProgress), checkEraser);
138 |
139 | canvas.drawBitmap(checkBitmap, 0, 0, null);
140 | }
141 |
142 | @Override
143 | protected void onAttachedToWindow() {
144 | super.onAttachedToWindow();
145 | attachedToWindow = true;
146 | }
147 |
148 | @Override
149 | protected void onDetachedFromWindow() {
150 | super.onDetachedFromWindow();
151 | attachedToWindow = false;
152 | }
153 |
154 |
155 | public void setProgress(float value) {
156 | if (progress == value) {
157 | return;
158 | }
159 | progress = value;
160 | invalidate();
161 | }
162 |
163 | public void setSize(int size) {
164 | this.size = size;
165 | }
166 |
167 | public float getProgress() {
168 | return progress;
169 | }
170 |
171 | public void setCheckedColor(int value) {
172 | bitmapColor = value;
173 | }
174 |
175 | public void setBorderColor(int value) {
176 | borderColor = value;
177 | borderPaint.setColor(borderColor);
178 | }
179 |
180 | private void cancelAnim() {
181 | if (checkAnim != null) {
182 | checkAnim.cancel();
183 | }
184 | }
185 |
186 | private void addAnim(boolean isChecked) {
187 | checkAnim = ObjectAnimator.ofFloat(this, "progress", isChecked ? 1.0f : 0.0f);
188 | checkAnim.setDuration(300);
189 | checkAnim.start();
190 | }
191 |
192 | public void setChecked(boolean checked, boolean animated) {
193 | if (checked == isChecked) {
194 | return;
195 | }
196 | isChecked = checked;
197 |
198 | if (attachedToWindow && animated) {
199 | addAnim(checked);
200 | } else {
201 | cancelAnim();
202 | setProgress(checked ? 1.0f : 0.0f);
203 | }
204 | }
205 |
206 |
207 | @Override
208 | public void toggle() {
209 | setChecked(!isChecked);
210 | }
211 |
212 | @Override
213 | public void setChecked(boolean b) {
214 | setChecked(b, true);
215 | }
216 |
217 | @Override
218 | public boolean isChecked() {
219 | return isChecked;
220 | }
221 |
222 | public int dp(float value) {
223 | if (value == 0) {
224 | return 0;
225 | }
226 | float density = getContext().getResources().getDisplayMetrics().density;
227 | return (int) Math.ceil(density * value);
228 | }
229 | }
230 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HJXANDHMR/AndroidUtils/e31f90cbfc498fc918d37f4860a5cddbb29ea05b/app/src/main/res/mipmap-hdpi/check.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HJXANDHMR/AndroidUtils/e31f90cbfc498fc918d37f4860a5cddbb29ea05b/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HJXANDHMR/AndroidUtils/e31f90cbfc498fc918d37f4860a5cddbb29ea05b/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HJXANDHMR/AndroidUtils/e31f90cbfc498fc918d37f4860a5cddbb29ea05b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HJXANDHMR/AndroidUtils/e31f90cbfc498fc918d37f4860a5cddbb29ea05b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidUtils
3 |
4 | Hello world!
5 | Settings
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.0.0'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HJXANDHMR/AndroidUtils/e31f90cbfc498fc918d37f4860a5cddbb29ea05b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------