Skip to content

Commit 9911151

Browse files
committed
see 05/03 log
1 parent e5b5bcc commit 9911151

File tree

14 files changed

+229
-40
lines changed

14 files changed

+229
-40
lines changed

README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.14.2-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.14.3-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen
4141

4242
[logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png
4343

44-
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.14.2-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.14.3-brightgreen.svg
4545
[auc]: https://github.com/Blankj/AndroidUtilCode
4646

4747
[apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies {
5656
// LeakCanary
5757
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
5858
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version"
59-
// implementation 'com.blankj:utilcode:1.14.2'
59+
// implementation 'com.blankj:utilcode:1.14.3'
6060
}
6161

6262

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ ext {
4444
min_sdk_version = 14
4545
target_sdk_version = 27
4646

47-
version_code = 1_014_002
48-
version_name = '1.14.2'// E.g 1.9.72 => 1,009,072
47+
version_code = 1_014_003
48+
version_name = '1.14.3'// E.g 1.9.72 => 1,009,072
4949

5050
// App dependencies
5151
support_version = '27.1.0'

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 18/05/03 修复 ToastUtils 默认字体大小问题,发布 1.14.3 版本
12
* 18/05/02 修复 PermissionUtils 空异常,发布 1.14.2 版本
23
* 18/04/28 新增 FlashlightUtils,发布 1.14.1 版本
34
* 18/04/26 修复 KeyboardUtils 全屏 NO_LIMIT 的 bug

utilcode/README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.14.2'
5+
implementation 'com.blankj:utilcode:1.14.3'
66
```
77

88

utilcode/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.14.2'
5+
implementation 'com.blankj:utilcode:1.14.3'
66
```
77

88

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,28 @@ public static boolean installAppSilent(final String filePath, final String param
208208
* @return {@code true}: success<br>{@code false}: fail
209209
*/
210210
public static boolean installAppSilent(final File file, final String params) {
211+
return installAppSilent(file, params, isDeviceRooted());
212+
}
213+
214+
/**
215+
* Install the app silently.
216+
* <p>Without root permission must hold
217+
* {@code <uses-permission android:name="android.permission.INSTALL_PACKAGES" />}</p>
218+
*
219+
* @param file The file.
220+
* @param params The params of installation(e.g.,<code>-r</code>, <code>-s</code>).
221+
* @param isRooted True to use root, false otherwise.
222+
* @return {@code true}: success<br>{@code false}: fail
223+
*/
224+
public static boolean installAppSilent(final File file,
225+
final String params,
226+
final boolean isRooted) {
211227
if (!isFileExists(file)) return false;
212-
boolean isRoot = isDeviceRooted();
213228
String filePath = '"' + file.getAbsolutePath() + '"';
214229
String command = "LD_LIBRARY_PATH=/vendor/lib*:/system/lib* pm install " +
215230
(params == null ? "" : params + " ")
216231
+ filePath;
217-
ShellUtils.CommandResult commandResult = ShellUtils.execCmd(command, isRoot);
232+
ShellUtils.CommandResult commandResult = ShellUtils.execCmd(command, isRooted);
218233
if (commandResult.successMsg != null
219234
&& commandResult.successMsg.toLowerCase().contains("success")) {
220235
return true;
@@ -275,12 +290,27 @@ public static boolean uninstallAppSilent(final String packageName) {
275290
* @return {@code true}: success<br>{@code false}: fail
276291
*/
277292
public static boolean uninstallAppSilent(final String packageName, final boolean isKeepData) {
293+
return uninstallAppSilent(packageName, isKeepData, isDeviceRooted());
294+
}
295+
296+
/**
297+
* Uninstall the app silently.
298+
* <p>Without root permission must hold
299+
* {@code <uses-permission android:name="android.permission.DELETE_PACKAGES" />}</p>
300+
*
301+
* @param packageName The name of the package.
302+
* @param isKeepData Is keep the data.
303+
* @param isRooted True to use root, false otherwise.
304+
* @return {@code true}: success<br>{@code false}: fail
305+
*/
306+
public static boolean uninstallAppSilent(final String packageName,
307+
final boolean isKeepData,
308+
final boolean isRooted) {
278309
if (isSpace(packageName)) return false;
279-
boolean isRoot = isDeviceRooted();
280310
String command = "LD_LIBRARY_PATH=/vendor/lib*:/system/lib* pm uninstall "
281311
+ (isKeepData ? "-k " : "")
282312
+ packageName;
283-
ShellUtils.CommandResult commandResult = ShellUtils.execCmd(command, isRoot, true);
313+
ShellUtils.CommandResult commandResult = ShellUtils.execCmd(command, isRooted);
284314
if (commandResult.successMsg != null
285315
&& commandResult.successMsg.toLowerCase().contains("success")) {
286316
return true;
@@ -299,7 +329,7 @@ public static boolean uninstallAppSilent(final String packageName, final boolean
299329
* @return {@code true}: yes<br>{@code false}: no
300330
*/
301331
public static boolean isAppInstalled(@NonNull final String action,
302-
@NonNull final String category) {
332+
@NonNull final String category) {
303333
Intent intent = new Intent(action);
304334
intent.addCategory(category);
305335
PackageManager pm = Utils.getApp().getPackageManager();

utilcode/src/main/java/com/blankj/utilcode/util/ReflectUtils.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import java.lang.reflect.AccessibleObject;
44
import java.lang.reflect.Constructor;
55
import java.lang.reflect.Field;
6+
import java.lang.reflect.InvocationHandler;
67
import java.lang.reflect.Member;
78
import java.lang.reflect.Method;
89
import java.lang.reflect.Modifier;
10+
import java.lang.reflect.Proxy;
911
import java.util.ArrayList;
1012
import java.util.Arrays;
1113
import java.util.Collections;
1214
import java.util.Comparator;
1315
import java.util.List;
16+
import java.util.Map;
1417

1518
/**
1619
* <pre>
@@ -414,6 +417,66 @@ private <T extends AccessibleObject> T accessible(T accessible) {
414417
return accessible;
415418
}
416419

420+
///////////////////////////////////////////////////////////////////////////
421+
// proxy
422+
///////////////////////////////////////////////////////////////////////////
423+
424+
/**
425+
* Create a proxy for the wrapped object allowing to typesafely invoke
426+
* methods on it using a custom interface.
427+
*
428+
* @param proxyType The interface type that is implemented by the proxy.
429+
* @return a proxy for the wrapped object
430+
*/
431+
@SuppressWarnings("unchecked")
432+
public <P> P proxy(final Class<P> proxyType) {
433+
final boolean isMap = (object instanceof Map);
434+
final InvocationHandler handler = new InvocationHandler() {
435+
@Override
436+
@SuppressWarnings("null")
437+
public Object invoke(Object proxy, Method method, Object[] args) {
438+
String name = method.getName();
439+
try {
440+
return reflect(object).method(name, args).get();
441+
}
442+
catch (ReflectException e) {
443+
if (isMap) {
444+
Map<String, Object> map = (Map<String, Object>) object;
445+
int length = (args == null ? 0 : args.length);
446+
447+
if (length == 0 && name.startsWith("get")) {
448+
return map.get(property(name.substring(3)));
449+
} else if (length == 0 && name.startsWith("is")) {
450+
return map.get(property(name.substring(2)));
451+
} else if (length == 1 && name.startsWith("set")) {
452+
map.put(property(name.substring(3)), args[0]);
453+
return null;
454+
}
455+
}
456+
throw e;
457+
}
458+
}
459+
};
460+
return (P) Proxy.newProxyInstance(proxyType.getClassLoader(),
461+
new Class[]{proxyType},
462+
handler);
463+
}
464+
465+
/**
466+
* Get the POJO property name of an getter/setter
467+
*/
468+
private static String property(String string) {
469+
int length = string.length();
470+
471+
if (length == 0) {
472+
return "";
473+
} else if (length == 1) {
474+
return string.toLowerCase();
475+
} else {
476+
return string.substring(0, 1).toLowerCase() + string.substring(1);
477+
}
478+
}
479+
417480
private Class<?> type() {
418481
return type;
419482
}

utilcode/src/main/java/com/blankj/utilcode/util/ShellUtils.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,76 +25,76 @@ private ShellUtils() {
2525
/**
2626
* Execute the command.
2727
*
28-
* @param command The command.
29-
* @param isRoot True to use root, false otherwise.
28+
* @param command The command.
29+
* @param isRooted True to use root, false otherwise.
3030
* @return the single {@link CommandResult} instance
3131
*/
32-
public static CommandResult execCmd(final String command, final boolean isRoot) {
33-
return execCmd(new String[]{command}, isRoot, true);
32+
public static CommandResult execCmd(final String command, final boolean isRooted) {
33+
return execCmd(new String[]{command}, isRooted, true);
3434
}
3535

3636
/**
3737
* Execute the command.
3838
*
3939
* @param commands The commands.
40-
* @param isRoot True to use root, false otherwise.
40+
* @param isRooted True to use root, false otherwise.
4141
* @return the single {@link CommandResult} instance
4242
*/
43-
public static CommandResult execCmd(final List<String> commands, final boolean isRoot) {
44-
return execCmd(commands == null ? null : commands.toArray(new String[]{}), isRoot, true);
43+
public static CommandResult execCmd(final List<String> commands, final boolean isRooted) {
44+
return execCmd(commands == null ? null : commands.toArray(new String[]{}), isRooted, true);
4545
}
4646

4747
/**
4848
* Execute the command.
4949
*
5050
* @param commands The commands.
51-
* @param isRoot True to use root, false otherwise.
51+
* @param isRooted True to use root, false otherwise.
5252
* @return the single {@link CommandResult} instance
5353
*/
54-
public static CommandResult execCmd(final String[] commands, final boolean isRoot) {
55-
return execCmd(commands, isRoot, true);
54+
public static CommandResult execCmd(final String[] commands, final boolean isRooted) {
55+
return execCmd(commands, isRooted, true);
5656
}
5757

5858
/**
5959
* Execute the command.
6060
*
6161
* @param command The command.
62-
* @param isRoot True to use root, false otherwise.
62+
* @param isRooted True to use root, false otherwise.
6363
* @param isNeedResultMsg True to return the message of result, false otherwise.
6464
* @return the single {@link CommandResult} instance
6565
*/
6666
public static CommandResult execCmd(final String command,
67-
final boolean isRoot,
67+
final boolean isRooted,
6868
final boolean isNeedResultMsg) {
69-
return execCmd(new String[]{command}, isRoot, isNeedResultMsg);
69+
return execCmd(new String[]{command}, isRooted, isNeedResultMsg);
7070
}
7171

7272
/**
7373
* Execute the command.
7474
*
7575
* @param commands The commands.
76-
* @param isRoot True to use root, false otherwise.
76+
* @param isRooted True to use root, false otherwise.
7777
* @param isNeedResultMsg True to return the message of result, false otherwise.
7878
* @return the single {@link CommandResult} instance
7979
*/
8080
public static CommandResult execCmd(final List<String> commands,
81-
final boolean isRoot,
81+
final boolean isRooted,
8282
final boolean isNeedResultMsg) {
8383
return execCmd(commands == null ? null : commands.toArray(new String[]{}),
84-
isRoot,
84+
isRooted,
8585
isNeedResultMsg);
8686
}
8787

8888
/**
8989
* Execute the command.
9090
*
9191
* @param commands The commands.
92-
* @param isRoot True to use root, false otherwise.
92+
* @param isRooted True to use root, false otherwise.
9393
* @param isNeedResultMsg True to return the message of result, false otherwise.
9494
* @return the single {@link CommandResult} instance
9595
*/
9696
public static CommandResult execCmd(final String[] commands,
97-
final boolean isRoot,
97+
final boolean isRooted,
9898
final boolean isNeedResultMsg) {
9999
int result = -1;
100100
if (commands == null || commands.length == 0) {
@@ -107,7 +107,7 @@ public static CommandResult execCmd(final String[] commands,
107107
StringBuilder errorMsg = null;
108108
DataOutputStream os = null;
109109
try {
110-
process = Runtime.getRuntime().exec(isRoot ? "su" : "sh");
110+
process = Runtime.getRuntime().exec(isRooted ? "su" : "sh");
111111
os = new DataOutputStream(process.getOutputStream());
112112
for (String command : commands) {
113113
if (command == null) continue;

utilcode/src/main/java/com/blankj/utilcode/util/ToastUtils.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,8 @@ public void run() {
241241
final Toast toast = Toast.makeText(Utils.getTopActivityOrApp(), text, duration);
242242
sWeakToast = new WeakReference<>(toast);
243243
final TextView tvMessage = toast.getView().findViewById(android.R.id.message);
244-
int msgColor = tvMessage.getCurrentTextColor();
245-
//it solve the font of toast
246-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
247-
tvMessage.setTextAppearance(android.R.style.TextAppearance);
248-
} else {
249-
tvMessage.setTextAppearance(tvMessage.getContext(), android.R.style.TextAppearance);
250-
}
251244
if (sMsgColor != COLOR_DEFAULT) {
252245
tvMessage.setTextColor(sMsgColor);
253-
} else {
254-
tvMessage.setTextColor(msgColor);
255246
}
256247
if (sMsgTextSize != -1) {
257248
tvMessage.setTextSize(sMsgTextSize);

0 commit comments

Comments
 (0)