Skip to content

Commit 0774589

Browse files
committed
see 12/22 log
1 parent 9bce4e9 commit 0774589

24 files changed

+109
-94
lines changed

README-CN.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,11 @@ Gradle:
568568
compile 'com.blankj:utilcode:1.3.4'
569569
```
570570

571+
### How to use
572+
```
573+
Utils.
574+
```
575+
571576
### Proguard
572577
***
573578
```

utilcode/src/main/java/com/blankj/utilcode/utils/AppUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static boolean installAppSilent(String filePath) {
9494
File file = FileUtils.getFileByPath(filePath);
9595
if (!FileUtils.isFileExists(file)) return false;
9696
String command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib pm install " + filePath;
97-
ShellUtils.CommandResult commandResult = ShellUtils.execCmd(command, !isSystemApp(Utils.context), true);
97+
ShellUtils.CommandResult commandResult = ShellUtils.execCmd(command, !isSystemApp(Utils.getContext()), true);
9898
return commandResult.successMsg != null && commandResult.successMsg.toLowerCase().contains("success");
9999
}
100100

utilcode/src/main/java/com/blankj/utilcode/utils/CleanUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private CleanUtils() {
2323
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
2424
*/
2525
public static boolean cleanInternalCache() {
26-
return FileUtils.deleteFilesInDir(Utils.context.getCacheDir());
26+
return FileUtils.deleteFilesInDir(Utils.getContext().getCacheDir());
2727
}
2828

2929
/**
@@ -33,7 +33,7 @@ public static boolean cleanInternalCache() {
3333
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
3434
*/
3535
public static boolean cleanInternalFiles() {
36-
return FileUtils.deleteFilesInDir(Utils.context.getFilesDir());
36+
return FileUtils.deleteFilesInDir(Utils.getContext().getFilesDir());
3737
}
3838

3939
/**
@@ -43,7 +43,7 @@ public static boolean cleanInternalFiles() {
4343
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
4444
*/
4545
public static boolean cleanInternalDbs() {
46-
return FileUtils.deleteFilesInDir(Utils.context.getFilesDir().getParent() + File.separator + "databases");
46+
return FileUtils.deleteFilesInDir(Utils.getContext().getFilesDir().getParent() + File.separator + "databases");
4747
}
4848

4949
/**
@@ -54,7 +54,7 @@ public static boolean cleanInternalDbs() {
5454
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
5555
*/
5656
public static boolean cleanInternalDbByName( String dbName) {
57-
return Utils.context.deleteDatabase(dbName);
57+
return Utils.getContext().deleteDatabase(dbName);
5858
}
5959

6060
/**
@@ -64,7 +64,7 @@ public static boolean cleanInternalDbByName( String dbName) {
6464
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
6565
*/
6666
public static boolean cleanInternalSP() {
67-
return FileUtils.deleteFilesInDir(Utils.context.getFilesDir().getParent() + File.separator + "shared_prefs");
67+
return FileUtils.deleteFilesInDir(Utils.getContext().getFilesDir().getParent() + File.separator + "shared_prefs");
6868
}
6969

7070
/**
@@ -74,7 +74,7 @@ public static boolean cleanInternalSP() {
7474
* @return {@code true}: 清除成功<br>{@code false}: 清除失败
7575
*/
7676
public static boolean cleanExternalCache() {
77-
return SDCardUtils.isSDCardEnable() && FileUtils.deleteFilesInDir(Utils.context.getExternalCacheDir());
77+
return SDCardUtils.isSDCardEnable() && FileUtils.deleteFilesInDir(Utils.getContext().getExternalCacheDir());
7878
}
7979

8080
/**

utilcode/src/main/java/com/blankj/utilcode/utils/ClipboardUtils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private ClipboardUtils() {
2626
* @param text 文本
2727
*/
2828
public static void copyText(CharSequence text) {
29-
ClipboardManager clipboard = (ClipboardManager) Utils.context.getSystemService(Context.CLIPBOARD_SERVICE);
29+
ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
3030
clipboard.setPrimaryClip(ClipData.newPlainText("text", text));
3131
}
3232

@@ -36,10 +36,10 @@ public static void copyText(CharSequence text) {
3636
* @return 剪贴板的文本
3737
*/
3838
public static CharSequence getText() {
39-
ClipboardManager clipboard = (ClipboardManager) Utils.context.getSystemService(Context.CLIPBOARD_SERVICE);
39+
ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
4040
ClipData clip = clipboard.getPrimaryClip();
4141
if (clip != null && clip.getItemCount() > 0) {
42-
return clip.getItemAt(0).coerceToText(Utils.context);
42+
return clip.getItemAt(0).coerceToText(Utils.getContext());
4343
}
4444
return null;
4545
}
@@ -50,8 +50,8 @@ public static CharSequence getText() {
5050
* @param uri uri
5151
*/
5252
public static void copyUri(Uri uri) {
53-
ClipboardManager clipboard = (ClipboardManager) Utils.context.getSystemService(Context.CLIPBOARD_SERVICE);
54-
clipboard.setPrimaryClip(ClipData.newUri(Utils.context.getContentResolver(), "uri", uri));
53+
ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
54+
clipboard.setPrimaryClip(ClipData.newUri(Utils.getContext().getContentResolver(), "uri", uri));
5555
}
5656

5757
/**
@@ -60,7 +60,7 @@ public static void copyUri(Uri uri) {
6060
* @return 剪贴板的uri
6161
*/
6262
public static Uri getUri() {
63-
ClipboardManager clipboard = (ClipboardManager) Utils.context.getSystemService(Context.CLIPBOARD_SERVICE);
63+
ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
6464
ClipData clip = clipboard.getPrimaryClip();
6565
if (clip != null && clip.getItemCount() > 0) {
6666
return clip.getItemAt(0).getUri();
@@ -74,7 +74,7 @@ public static Uri getUri() {
7474
* @param intent 意图
7575
*/
7676
public static void copyIntent(Intent intent) {
77-
ClipboardManager clipboard = (ClipboardManager) Utils.context.getSystemService(Context.CLIPBOARD_SERVICE);
77+
ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
7878
clipboard.setPrimaryClip(ClipData.newIntent("intent", intent));
7979
}
8080

@@ -84,7 +84,7 @@ public static void copyIntent(Intent intent) {
8484
* @return 剪贴板的意图
8585
*/
8686
public static Intent getIntent() {
87-
ClipboardManager clipboard = (ClipboardManager) Utils.context.getSystemService(Context.CLIPBOARD_SERVICE);
87+
ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
8888
ClipData clip = clipboard.getPrimaryClip();
8989
if (clip != null && clip.getItemCount() > 0) {
9090
return clip.getItemAt(0).getIntent();

utilcode/src/main/java/com/blankj/utilcode/utils/ConvertUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ public static Bitmap view2Bitmap(View view) {
589589
* @return px值
590590
*/
591591
public static int dp2px(float dpValue) {
592-
final float scale = Utils.context.getResources().getDisplayMetrics().density;
592+
final float scale = Utils.getContext().getResources().getDisplayMetrics().density;
593593
return (int) (dpValue * scale + 0.5f);
594594
}
595595

@@ -600,7 +600,7 @@ public static int dp2px(float dpValue) {
600600
* @return dp值
601601
*/
602602
public static int px2dp(float pxValue) {
603-
final float scale = Utils.context.getResources().getDisplayMetrics().density;
603+
final float scale = Utils.getContext().getResources().getDisplayMetrics().density;
604604
return (int) (pxValue / scale + 0.5f);
605605
}
606606

@@ -611,7 +611,7 @@ public static int px2dp(float pxValue) {
611611
* @return px值
612612
*/
613613
public static int sp2px(float spValue) {
614-
final float fontScale = Utils.context.getResources().getDisplayMetrics().scaledDensity;
614+
final float fontScale = Utils.getContext().getResources().getDisplayMetrics().scaledDensity;
615615
return (int) (spValue * fontScale + 0.5f);
616616
}
617617

@@ -622,7 +622,7 @@ public static int sp2px(float spValue) {
622622
* @return sp值
623623
*/
624624
public static int px2sp(float pxValue) {
625-
final float fontScale = Utils.context.getResources().getDisplayMetrics().scaledDensity;
625+
final float fontScale = Utils.getContext().getResources().getDisplayMetrics().scaledDensity;
626626
return (int) (pxValue / fontScale + 0.5f);
627627
}
628628
}

utilcode/src/main/java/com/blankj/utilcode/utils/CrashUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public static CrashUtils getInstance() {
6161
public boolean init() {
6262
if (mInitialized) return true;
6363
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
64-
crashDir = Utils.context.getExternalCacheDir().getPath() + File.separator + "crash" + File.separator;
64+
crashDir = Utils.getContext().getExternalCacheDir().getPath() + File.separator + "crash" + File.separator;
6565
} else {
66-
crashDir = Utils.context.getCacheDir().getPath() + File.separator + "crash" + File.separator;
66+
crashDir = Utils.getContext().getCacheDir().getPath() + File.separator + "crash" + File.separator;
6767
}
6868
try {
69-
PackageInfo pi = Utils.context.getPackageManager().getPackageInfo(Utils.context.getPackageName(), 0);
69+
PackageInfo pi = Utils.getContext().getPackageManager().getPackageInfo(Utils.getContext().getPackageName(), 0);
7070
versionName = pi.versionName;
7171
versionCode = pi.versionCode;
7272
} catch (PackageManager.NameNotFoundException e) {

utilcode/src/main/java/com/blankj/utilcode/utils/DeviceUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static int getSDKVersion() {
6262
*/
6363
@SuppressLint("HardwareIds")
6464
public static String getAndroidID() {
65-
return Settings.Secure.getString(Utils.context.getContentResolver(), Settings.Secure.ANDROID_ID);
65+
return Settings.Secure.getString(Utils.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
6666
}
6767

6868
/**
@@ -97,7 +97,7 @@ public static String getMacAddress() {
9797
@SuppressLint("HardwareIds")
9898
private static String getMacAddressByWifiInfo() {
9999
try {
100-
WifiManager wifi = (WifiManager) Utils.context.getSystemService(Context.WIFI_SERVICE);
100+
WifiManager wifi = (WifiManager) Utils.getContext().getSystemService(Context.WIFI_SERVICE);
101101
if (wifi != null) {
102102
WifiInfo info = wifi.getConnectionInfo();
103103
if (info != null) return info.getMacAddress();
@@ -191,7 +191,7 @@ public static void shutdown() {
191191
Intent intent = new Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN");
192192
intent.putExtra("android.intent.extra.KEY_CONFIRM", false);
193193
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
194-
Utils.context.startActivity(intent);
194+
Utils.getContext().startActivity(intent);
195195
}
196196

197197
/**
@@ -205,7 +205,7 @@ public static void reboot() {
205205
intent.putExtra("nowait", 1);
206206
intent.putExtra("interval", 1);
207207
intent.putExtra("window", 0);
208-
Utils.context.sendBroadcast(intent);
208+
Utils.getContext().sendBroadcast(intent);
209209
}
210210

211211
/**
@@ -215,7 +215,7 @@ public static void reboot() {
215215
* @param reason 传递给内核来请求特殊的引导模式,如"recovery"
216216
*/
217217
public static void reboot(String reason) {
218-
PowerManager mPowerManager = (PowerManager) Utils.context.getSystemService(Context.POWER_SERVICE);
218+
PowerManager mPowerManager = (PowerManager) Utils.getContext().getSystemService(Context.POWER_SERVICE);
219219
try {
220220
mPowerManager.reboot(reason);
221221
} catch (Exception e) {

utilcode/src/main/java/com/blankj/utilcode/utils/ImageUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ public static Bitmap fastBlur(Bitmap src, float scale, float radius, boolean rec
679679
canvas.scale(scale, scale);
680680
canvas.drawBitmap(scaleBitmap, 0, 0, paint);
681681
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
682-
scaleBitmap = renderScriptBlur(Utils.context, scaleBitmap, radius);
682+
scaleBitmap = renderScriptBlur(Utils.getContext(), scaleBitmap, radius);
683683
} else {
684684
scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle);
685685
}

utilcode/src/main/java/com/blankj/utilcode/utils/KeyboardUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static void showSoftInput(EditText edit) {
8686
edit.setFocusable(true);
8787
edit.setFocusableInTouchMode(true);
8888
edit.requestFocus();
89-
InputMethodManager imm = (InputMethodManager) Utils.context
89+
InputMethodManager imm = (InputMethodManager) Utils.getContext()
9090
.getSystemService(Context.INPUT_METHOD_SERVICE);
9191
imm.showSoftInput(edit, 0);
9292
}
@@ -95,7 +95,7 @@ public static void showSoftInput(EditText edit) {
9595
* 切换键盘显示与否状态
9696
*/
9797
public static void toggleSoftInput() {
98-
InputMethodManager imm = (InputMethodManager) Utils.context
98+
InputMethodManager imm = (InputMethodManager) Utils.getContext()
9999
.getSystemService(Context.INPUT_METHOD_SERVICE);
100100
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
101101
}

utilcode/src/main/java/com/blankj/utilcode/utils/LocationUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private LocationUtils() {
4040
* @return {@code true}: 是<br>{@code false}: 否
4141
*/
4242
public static boolean isGpsEnabled() {
43-
LocationManager lm = (LocationManager) Utils.context.getSystemService(Context.LOCATION_SERVICE);
43+
LocationManager lm = (LocationManager) Utils.getContext().getSystemService(Context.LOCATION_SERVICE);
4444
return lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
4545
}
4646

@@ -50,7 +50,7 @@ public static boolean isGpsEnabled() {
5050
* @return {@code true}: 是<br>{@code false}: 否
5151
*/
5252
public static boolean isLocationEnabled() {
53-
LocationManager lm = (LocationManager) Utils.context.getSystemService(Context.LOCATION_SERVICE);
53+
LocationManager lm = (LocationManager) Utils.getContext().getSystemService(Context.LOCATION_SERVICE);
5454
return lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) || lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
5555
}
5656

@@ -60,7 +60,7 @@ public static boolean isLocationEnabled() {
6060
public static void openGpsSettings() {
6161
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
6262
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
63-
Utils.context.startActivity(intent);
63+
Utils.getContext().startActivity(intent);
6464
}
6565

6666
/**
@@ -80,7 +80,7 @@ public static void openGpsSettings() {
8080
*/
8181
public static boolean register(long minTime, long minDistance, OnLocationChangeListener listener) {
8282
if (listener == null) return false;
83-
mLocationManager = (LocationManager) Utils.context.getSystemService(Context.LOCATION_SERVICE);
83+
mLocationManager = (LocationManager) Utils.getContext().getSystemService(Context.LOCATION_SERVICE);
8484
mListener = listener;
8585
if (!isLocationEnabled()) {
8686
ToastUtils.showShortToastSafe("无法定位,请打开定位服务");
@@ -138,7 +138,7 @@ private static Criteria getCriteria() {
138138
* @return {@link Address}
139139
*/
140140
public static Address getAddress(double latitude, double longitude) {
141-
Geocoder geocoder = new Geocoder(Utils.context, Locale.getDefault());
141+
Geocoder geocoder = new Geocoder(Utils.getContext(), Locale.getDefault());
142142
try {
143143
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
144144
if (addresses.size() > 0) return addresses.get(0);

utilcode/src/main/java/com/blankj/utilcode/utils/LogUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ private LogUtils() {
4242
*/
4343
public static void init(boolean logSwitch, boolean log2FileSwitch, char logFilter, String tag) {
4444
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
45-
dir = Utils.context.getExternalCacheDir().getPath() + File.separator;
45+
dir = Utils.getContext().getExternalCacheDir().getPath() + File.separator;
4646
} else {
47-
dir = Utils.context.getCacheDir().getPath() + File.separator;
47+
dir = Utils.getContext().getCacheDir().getPath() + File.separator;
4848
}
4949
LogUtils.logSwitch = logSwitch;
5050
LogUtils.log2FileSwitch = log2FileSwitch;
@@ -60,9 +60,9 @@ public static void init(boolean logSwitch, boolean log2FileSwitch, char logFilte
6060
*/
6161
public static Builder getBuilder() {
6262
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
63-
dir = Utils.context.getExternalCacheDir().getPath() + File.separator + "log" + File.separator;
63+
dir = Utils.getContext().getExternalCacheDir().getPath() + File.separator + "log" + File.separator;
6464
} else {
65-
dir = Utils.context.getCacheDir().getPath() + File.separator + "log" + File.separator;
65+
dir = Utils.getContext().getCacheDir().getPath() + File.separator + "log" + File.separator;
6666
}
6767
return new Builder();
6868
}

0 commit comments

Comments
 (0)