Skip to content

Commit 8880b13

Browse files
committed
see 04/26 log
1 parent 17dd4d8 commit 8880b13

File tree

14 files changed

+140
-45
lines changed

14 files changed

+140
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* `19/04/25` [fix] LogUtils delete due log.
12
* `19/04/24` [upd] The swipe panel.
23
* `19/03/17` [fix] The ugly UI.
34
* `19/03/14` [fix] AdaptScreenUtils didn't work on some HaWei tablet.

utilcode/README-CN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ shutdown : 关机
281281
reboot : 重启
282282
reboot2Recovery : 重启到 recovery
283283
reboot2Bootloader: 重启到 bootloader
284-
isTablet : 判断是否是平板
285-
isEmulator : 判断是否是模拟器
284+
isTablet : 判断是否是平板
285+
isEmulator : 判断是否是模拟器
286286
```
287287

288288
* ### 闪光灯相关 -> [FlashlightUtils.java][flashlight.java] -> [Demo][flashlight.demo]
@@ -543,7 +543,7 @@ isWifiConnected : 判断 wifi 是否连接状态
543543
isWifiAvailable[Async] : 判断 wifi 数据是否可用
544544
getNetworkOperatorName : 获取移动网络运营商名称
545545
getNetworkType : 获取当前网络类型
546-
getIPAddress : 获取 IP 地址
546+
getIPAddress[Async] : 获取 IP 地址
547547
getDomainAddress[Async] : 获取域名 IP 地址
548548
getIpAddressByWifi : 根据 WiFi 获取网络 IP 地址
549549
getGatewayByWifi : 根据 WiFi 获取网关 IP 地址

utilcode/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ shutdown
281281
reboot
282282
reboot2Recovery
283283
reboot2Bootloader
284+
isTablet
285+
isEmulator
284286
```
285287

286288
* ### About Flashlight -> [FlashlightUtils.java][flashlight.java] -> [Demo][flashlight.demo]
@@ -541,7 +543,7 @@ isWifiConnected
541543
isWifiAvailable[Async] : 判断 wifi 数据是否可用
542544
getNetworkOperatorName
543545
getNetworkType
544-
getIPAddress
546+
getIPAddress[Async] : 获取 IP 地址
545547
getDomainAddress[Async] : 获取域名 IP 地址
546548
getIpAddressByWifi
547549
getGatewayByWifi
@@ -712,6 +714,8 @@ getRomInfo
712714
```
713715
getScreenWidth
714716
getScreenHeight
717+
getAppScreenWidth
718+
getAppScreenHeight
715719
getScreenDensity
716720
getScreenDensityDpi
717721
setFullScreen
@@ -727,7 +731,6 @@ screenShot
727731
isScreenLock
728732
setSleepDuration
729733
getSleepDuration
730-
isTablet
731734
```
732735

733736
* ### About SDCard -> [SDCardUtils.java][sdcard.java] -> [Demo][sdcard.demo]

utilcode/lib/src/main/java/com/blankj/utilcode/util/AdaptScreenUtils.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public final class AdaptScreenUtils {
1717
* Adapt for the horizontal screen, and call it in [android.app.Activity.getResources].
1818
*/
1919
public static Resources adaptWidth(final Resources resources, final int designWidth) {
20-
float newXdpi = (Resources.getSystem().getDisplayMetrics().widthPixels * 72f) / designWidth;
20+
float newXdpi = (resources.getDisplayMetrics().widthPixels * 72f) / designWidth;
2121
applyDisplayMetrics(resources, newXdpi);
2222
return resources;
2323
}
@@ -26,11 +26,29 @@ public static Resources adaptWidth(final Resources resources, final int designWi
2626
* Adapt for the vertical screen, and call it in [android.app.Activity.getResources].
2727
*/
2828
public static Resources adaptHeight(final Resources resources, final int designHeight) {
29-
float newXdpi = (Resources.getSystem().getDisplayMetrics().heightPixels * 72f) / designHeight;
29+
return adaptHeight(resources, designHeight, false);
30+
}
31+
32+
/**
33+
* Adapt for the vertical screen, and call it in [android.app.Activity.getResources].
34+
*/
35+
public static Resources adaptHeight(final Resources resources, final int designHeight, final boolean includeNavBar) {
36+
float screenHeight = resources.getDisplayMetrics().heightPixels * 72f
37+
+ (includeNavBar ? getNavBarHeight(resources) : 0);
38+
float newXdpi = screenHeight / designHeight;
3039
applyDisplayMetrics(resources, newXdpi);
3140
return resources;
3241
}
3342

43+
private static int getNavBarHeight(final Resources resources) {
44+
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
45+
if (resourceId != 0) {
46+
return resources.getDimensionPixelSize(resourceId);
47+
} else {
48+
return 0;
49+
}
50+
}
51+
3452
/**
3553
* @param resources The resources.
3654
* @return the resource

utilcode/lib/src/main/java/com/blankj/utilcode/util/FileIOUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
public final class FileIOUtils {
3333

34-
private static int sBufferSize = 8192;
34+
private static int sBufferSize = 524288;
3535

3636
private FileIOUtils() {
3737
throw new UnsupportedOperationException("u can't instantiate me...");

utilcode/lib/src/main/java/com/blankj/utilcode/util/LogUtils.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import java.util.Set;
4747
import java.util.concurrent.ExecutorService;
4848
import java.util.concurrent.Executors;
49+
import java.util.regex.Matcher;
50+
import java.util.regex.Pattern;
4951

5052
import javax.xml.transform.OutputKeys;
5153
import javax.xml.transform.Source;
@@ -526,19 +528,19 @@ private static void deleteDueLogs(String filePath) {
526528
File[] files = parentFile.listFiles(new FilenameFilter() {
527529
@Override
528530
public boolean accept(File dir, String name) {
529-
return name.matches("^" + CONFIG.getFilePrefix() + "-[0-9]{4}-[0-9]{2}-[0-9]{2}-" + CONFIG.getProcessName() + ".txt$");
531+
return name.matches("^" + CONFIG.getFilePrefix() + "-[0-9]{4}-[0-9]{2}-[0-9]{2}-.*\\.txt$");
530532
}
531533
});
532534
if (files == null || files.length <= 0) return;
533535
final int length = filePath.length();
534536
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
535537
try {
536-
String curDay = filePath.substring(length - 14, length - 4);
538+
String curDay = findDate(filePath);
537539
long dueMillis = sdf.parse(curDay).getTime() - CONFIG.getSaveDays() * 86400000L;
538540
for (final File aFile : files) {
539541
String name = aFile.getName();
540542
int l = name.length();
541-
String logDay = name.substring(l - 14, l - 4);
543+
String logDay = findDate(name);
542544
if (sdf.parse(logDay).getTime() <= dueMillis) {
543545
EXECUTOR.execute(new Runnable() {
544546
@Override
@@ -556,6 +558,15 @@ public void run() {
556558
}
557559
}
558560

561+
private static String findDate(String str) {
562+
Pattern pattern = Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2}");
563+
Matcher matcher = pattern.matcher(str);
564+
if (matcher.find()) {
565+
return matcher.group();
566+
}
567+
return "";
568+
}
569+
559570
private static void printDeviceInfo(final String filePath) {
560571
String versionName = "";
561572
int versionCode = 0;
@@ -817,7 +828,7 @@ private static String getCurrentProcessName() {
817828
BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
818829
String processName = mBufferedReader.readLine().trim();
819830
mBufferedReader.close();
820-
return processName;
831+
return processName.replace(":", "_");
821832
} catch (Exception e) {
822833
e.printStackTrace();
823834
return "";

utilcode/lib/src/main/java/com/blankj/utilcode/util/NetworkUtils.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static boolean isConnected() {
8282
* <p>Must hold {@code <uses-permission android:name="android.permission.INTERNET" />}</p>
8383
*
8484
* @param callback The callback.
85+
* @return the task
8586
*/
8687
@RequiresPermission(INTERNET)
8788
public static Utils.Task<Boolean> isAvailableAsync(@NonNull final Utils.Callback<Boolean> callback) {
@@ -123,6 +124,7 @@ public static void isAvailableByPingAsync(final Utils.Callback<Boolean> callback
123124
*
124125
* @param ip The ip address.
125126
* @param callback The callback.
127+
* @return the task
126128
*/
127129
@RequiresPermission(INTERNET)
128130
public static Utils.Task<Boolean> isAvailableByPingAsync(final String ip,
@@ -186,6 +188,7 @@ public static void isAvailableByDnsAsync(final Utils.Callback<Boolean> callback)
186188
*
187189
* @param domain The name of domain.
188190
* @param callback The callback.
191+
* @return the task
189192
*/
190193
@RequiresPermission(INTERNET)
191194
public static Utils.Task isAvailableByDnsAsync(final String domain,
@@ -373,6 +376,9 @@ public static boolean isWifiAvailable() {
373376
* Return whether wifi is available.
374377
* <p>Must hold {@code <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />},
375378
* {@code <uses-permission android:name="android.permission.INTERNET" />}</p>
379+
*
380+
* @param callback The callback.
381+
* @return the task
376382
*/
377383
@RequiresPermission(allOf = {ACCESS_WIFI_STATE, INTERNET})
378384
public static Utils.Task<Boolean> isWifiAvailableAsync(@NonNull final Utils.Callback<Boolean> callback) {
@@ -487,6 +493,25 @@ private static NetworkInfo getActiveNetworkInfo() {
487493
return cm.getActiveNetworkInfo();
488494
}
489495

496+
/**
497+
* Return the ip address.
498+
* <p>Must hold {@code <uses-permission android:name="android.permission.INTERNET" />}</p>
499+
*
500+
* @param useIPv4 True to use ipv4, false otherwise.
501+
* @param callback The callback.
502+
* @return the task
503+
*/
504+
public static Utils.Task<String> getIPAddressAsync(final boolean useIPv4,
505+
@NonNull final Utils.Callback<String> callback) {
506+
return Utils.doAsync(new Utils.Task<String>(callback) {
507+
@RequiresPermission(INTERNET)
508+
@Override
509+
public String doInBackground() {
510+
return getIPAddress(useIPv4);
511+
}
512+
});
513+
}
514+
490515
/**
491516
* Return the ip address.
492517
* <p>Must hold {@code <uses-permission android:name="android.permission.INTERNET" />}</p>
@@ -563,6 +588,7 @@ public static String getBroadcastIpAddress() {
563588
*
564589
* @param domain The name of domain.
565590
* @param callback The callback.
591+
* @return the task
566592
*/
567593
@RequiresPermission(INTERNET)
568594
public static Utils.Task<String> getDomainAddressAsync(final String domain,

utilcode/lib/src/main/java/com/blankj/utilcode/util/ResourceUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ private ResourceUtils() {
3131
throw new UnsupportedOperationException("u can't instantiate me...");
3232
}
3333

34+
/**
35+
* Return the drawable identifier by name.
36+
*
37+
* @param name The name of drawable.
38+
* @return the drawable identifier by name
39+
*/
40+
public static int getDrawableIdByName(String name) {
41+
return Utils.getApp().getResources().getIdentifier(name, "drawable", Utils.getApp().getPackageName());
42+
}
43+
3444
/**
3545
* Copy the file from assets.
3646
*

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ private ShellUtils() {
3131
* @param isRooted True to use root, false otherwise.
3232
* @param callback The callback.
3333
*/
34-
public static void execCmdAsync(final String command, final boolean isRooted, final Utils.Callback<CommandResult> callback) {
34+
public static void execCmdAsync(final String command,
35+
final boolean isRooted,
36+
final Utils.Callback<CommandResult> callback) {
3537
execCmdAsync(new String[]{command}, isRooted, true, callback);
3638
}
3739

@@ -42,7 +44,9 @@ public static void execCmdAsync(final String command, final boolean isRooted, fi
4244
* @param isRooted True to use root, false otherwise.
4345
* @param callback The callback.
4446
*/
45-
public static void execCmdAsync(final List<String> commands, final boolean isRooted, final Utils.Callback<CommandResult> callback) {
47+
public static void execCmdAsync(final List<String> commands,
48+
final boolean isRooted,
49+
final Utils.Callback<CommandResult> callback) {
4650
execCmdAsync(commands == null ? null : commands.toArray(new String[]{}), isRooted, true, callback);
4751
}
4852

@@ -53,7 +57,9 @@ public static void execCmdAsync(final List<String> commands, final boolean isRoo
5357
* @param isRooted True to use root, false otherwise.
5458
* @param callback The callback.
5559
*/
56-
public static void execCmdAsync(final String[] commands, final boolean isRooted, final Utils.Callback<CommandResult> callback) {
60+
public static void execCmdAsync(final String[] commands,
61+
final boolean isRooted,
62+
final Utils.Callback<CommandResult> callback) {
5763
execCmdAsync(commands, isRooted, true, callback);
5864
}
5965

@@ -97,6 +103,7 @@ public static void execCmdAsync(final List<String> commands,
97103
* @param isRooted True to use root, false otherwise.
98104
* @param isNeedResultMsg True to return the message of result, false otherwise.
99105
* @param callback The callback.
106+
* @return the task
100107
*/
101108
public static Utils.Task<CommandResult> execCmdAsync(final String[] commands,
102109
final boolean isRooted,

utilcode/lib/src/main/java/com/blankj/utilcode/util/ThreadUtils.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import android.os.Looper;
55
import android.support.annotation.IntRange;
66
import android.support.annotation.NonNull;
7+
import android.support.annotation.Nullable;
78
import android.util.Log;
8-
import android.util.SparseArray;
99

1010
import java.util.HashMap;
1111
import java.util.Map;
@@ -30,8 +30,8 @@
3030
*/
3131
public final class ThreadUtils {
3232

33-
private static final SparseArray<SparseArray<ExecutorService>> TYPE_PRIORITY_POOLS = new SparseArray<>();
34-
private static final Map<Task, ScheduledExecutorService> TASK_SCHEDULED = new HashMap<>();
33+
private static final HashMap<Integer, Map<Integer, ExecutorService>> TYPE_PRIORITY_POOLS = new HashMap<>();
34+
private static final Map<Task, ScheduledExecutorService> TASK_SCHEDULED = new HashMap<>();
3535

3636
private static final byte TYPE_SINGLE = -1;
3737
private static final byte TYPE_CACHED = -2;
@@ -912,9 +912,9 @@ private static ExecutorService getPoolByTypeAndPriority(final int type) {
912912

913913
private synchronized static ExecutorService getPoolByTypeAndPriority(final int type, final int priority) {
914914
ExecutorService pool;
915-
SparseArray<ExecutorService> priorityPools = TYPE_PRIORITY_POOLS.get(type);
915+
Map<Integer, ExecutorService> priorityPools = TYPE_PRIORITY_POOLS.get(type);
916916
if (priorityPools == null) {
917-
priorityPools = new SparseArray<>();
917+
priorityPools = new HashMap<>();
918918
pool = createPoolByTypeAndPriority(type, priority);
919919
priorityPools.put(priority, pool);
920920
TYPE_PRIORITY_POOLS.put(type, priorityPools);
@@ -998,9 +998,10 @@ public abstract static class Task<T> implements Runnable {
998998
private volatile int state = NEW;
999999
private boolean isSchedule;
10001000

1001+
@Nullable
10011002
public abstract T doInBackground() throws Throwable;
10021003

1003-
public abstract void onSuccess(T result);
1004+
public abstract void onSuccess(@Nullable T result);
10041005

10051006
public abstract void onCancel();
10061007

@@ -1080,6 +1081,7 @@ private static final class UtilsThreadFactory extends AtomicLong
10801081
this.priority = priority;
10811082
}
10821083

1084+
@Override
10831085
public Thread newThread(@NonNull Runnable r) {
10841086
Thread t = new Thread(r, namePrefix + getAndIncrement()) {
10851087
@Override

utilcode/lib/src/test/java/com/blankj/utilcode/util/BaseTest.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.robolectric.annotation.Config;
1111
import org.robolectric.shadows.ShadowLog;
1212

13-
import java.util.TreeSet;
13+
import java.util.concurrent.Executor;
1414

1515
/**
1616
* <pre>
@@ -21,28 +21,22 @@
2121
* </pre>
2222
*/
2323
@RunWith(RobolectricTestRunner.class)
24-
@Config(manifest = Config.NONE, shadows = {ShadowLog.class}, sdk = 19)
24+
@Config(manifest = Config.NONE, shadows = {ShadowLog.class})
2525
public class BaseTest {
2626

2727
public BaseTest() {
2828
ShadowLog.stream = System.out;
29+
ThreadUtils.setDeliver(new Executor() {
30+
@Override
31+
public void execute(@NonNull Runnable command) {
32+
command.run();
33+
}
34+
});
2935
Utils.init(RuntimeEnvironment.application);
3036
}
3137

3238
@Test
3339
public void test() throws Exception {
34-
35-
TreeSet<Person> people = new TreeSet<>();
36-
people.add(new Person("1", 1, 0));
37-
people.add(new Person("3", 3, 0));
38-
people.add(new Person("3", 3, 1));
39-
people.add(new Person("2", 2, 0));
40-
for (Person person : people) {
41-
System.out.println(person);
42-
}
43-
System.out.println(people);
44-
45-
4640
// final Scanner scanner = new Scanner(System.in);
4741
//
4842
// final CountDownLatch countDownLatch = new CountDownLatch(1);

0 commit comments

Comments
 (0)