Skip to content

Commit 2ba5a17

Browse files
committed
see 01/13 log
1 parent 939a496 commit 2ba5a17

File tree

11 files changed

+121
-46
lines changed

11 files changed

+121
-46
lines changed

app/src/main/java/com/blankj/androidutilcode/activities/DeviceActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
3131
findViewById(R.id.btn_reboot_to_recovery).setOnClickListener(this);
3232
findViewById(R.id.btn_reboot_to_bootloader).setOnClickListener(this);
3333

34-
tvAboutDevice.setText("isRoot: " + DeviceUtils.isDeviceRoot()
34+
tvAboutDevice.setText("isRoot: " + DeviceUtils.isDeviceRooted()
3535
+ "\ngetSDKVersion: " + DeviceUtils.getSDKVersion()
3636
+ "\ngetAndroidID: " + DeviceUtils.getAndroidID()
3737
+ "\ngetMacAddress: " + DeviceUtils.getMacAddress()

app/src/main/java/com/blankj/androidutilcode/activities/NetworkActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private void setAboutNetwork() {
5858
+ "\ngetWifiEnabled: " + NetworkUtils.getWifiEnabled()
5959
+ "\nisWifiConnected: " + NetworkUtils.isWifiConnected()
6060
+ "\nisWifiAvailable: " + NetworkUtils.isWifiAvailable()
61+
+ "\nisAvailableByPing: " + NetworkUtils.isAvailableByPing()
6162
+ "\ngetNetworkOperatorName: " + NetworkUtils.getNetworkOperatorName()
6263
+ "\ngetNetworkTypeName: " + NetworkUtils.getNetworkType()
6364
+ "\ngetIPAddress: " + NetworkUtils.getIPAddress(true)

utilcode/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ android {
66

77
defaultConfig {
88
minSdkVersion rootProject.ext.android.minSdkVersion
9-
targetSdkVersion rootProject.ext.android.targetSdkVersion
109
versionCode rootProject.ext.android.versionCode
1110
versionName rootProject.ext.android.versionName
1211
}
@@ -26,5 +25,5 @@ dependencies {
2625
testCompile rootProject.ext.deps.truth
2726
testCompile rootProject.ext.deps.robolectric
2827
}
29-
apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
28+
//apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
3029
//gradlew bintrayUpload

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ public class CrashUtils
2828
private volatile static CrashUtils mInstance;
2929

3030
private UncaughtExceptionHandler mHandler;
31-
private boolean mInitialized;
32-
private String crashDir;
33-
private String versionName;
34-
private int versionCode;
31+
32+
private boolean mInitialized;
33+
private String crashDir;
34+
private String versionName;
35+
private int versionCode;
3536

3637
private CrashUtils() {
3738
}
@@ -62,9 +63,13 @@ public static CrashUtils getInstance() {
6263
public boolean init() {
6364
if (mInitialized) return true;
6465
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
65-
crashDir = Utils.getContext().getExternalCacheDir().getPath() + File.separator + "crash" + File.separator;
66+
File baseCache = Utils.getContext().getExternalCacheDir();
67+
if (baseCache == null) return false;
68+
crashDir = baseCache.getPath() + File.separator + "crash" + File.separator;
6669
} else {
67-
crashDir = Utils.getContext().getCacheDir().getPath() + File.separator + "crash" + File.separator;
70+
File baseCache = Utils.getContext().getCacheDir();
71+
if (baseCache == null) return false;
72+
crashDir = baseCache.getPath() + File.separator + "crash" + File.separator;
6873
}
6974
try {
7075
PackageInfo pi = Utils.getContext().getPackageManager().getPackageInfo(Utils.getContext().getPackageName(), 0);

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import android.content.ComponentName;
44
import android.content.Context;
55
import android.content.Intent;
6-
import android.graphics.Bitmap;
76
import android.net.Uri;
87
import android.os.Build;
98
import android.os.Bundle;
109
import android.provider.MediaStore;
10+
import android.support.v4.content.FileProvider;
1111
import android.webkit.MimeTypeMap;
1212

1313
import java.io.File;
@@ -46,11 +46,17 @@ public static Intent getInstallAppIntent(File file) {
4646
if (file == null) return null;
4747
Intent intent = new Intent(Intent.ACTION_VIEW);
4848
String type;
49+
4950
if (Build.VERSION.SDK_INT < 23) {
5051
type = "application/vnd.android.package-archive";
5152
} else {
5253
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(FileUtils.getFileExtension(file));
5354
}
55+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
56+
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
57+
Uri contentUri = FileProvider.getUriForFile(Utils.getContext(), "com.your.package.fileProvider", file);
58+
intent.setDataAndType(contentUri, type);
59+
}
5460
intent.setDataAndType(Uri.fromFile(file), type);
5561
return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
5662
}
@@ -179,6 +185,11 @@ public static Intent getShutdownIntent() {
179185
return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
180186
}
181187

188+
// public static Intent getDailIntent(){
189+
//
190+
// }
191+
192+
182193
/**
183194
* 获取拍照的意图
184195
*

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public enum NetworkType {
5252
*/
5353
public static void openWirelessSettings() {
5454
if (android.os.Build.VERSION.SDK_INT > 10) {
55-
Utils.getContext().startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
55+
Utils.getContext().startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
5656
} else {
57-
Utils.getContext().startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
57+
Utils.getContext().startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
5858
}
5959
}
6060

@@ -88,7 +88,7 @@ public static boolean isConnected() {
8888
* @return {@code true}: 可用<br>{@code false}: 不可用
8989
*/
9090
public static boolean isAvailableByPing() {
91-
ShellUtils.CommandResult result = ShellUtils.execCmd("ping -c 1 -w 1 123.125.114.144", false);
91+
ShellUtils.CommandResult result = ShellUtils.execCmd("ping -c 1 -w 1 223.5.5.5", false);
9292
boolean ret = result.result == 0;
9393
if (result.errorMsg != null) {
9494
LogUtils.d("isAvailableByPing errorMsg", result.errorMsg);

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static boolean isPhone() {
4949
* 获取IMEI码
5050
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
5151
*
52-
* @return IMIE码
52+
* @return IMEI码
5353
*/
5454
@SuppressLint("HardwareIds")
5555
public static String getIMEI() {
@@ -61,7 +61,7 @@ public static String getIMEI() {
6161
* 获取IMSI码
6262
* <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
6363
*
64-
* @return IMIE码
64+
* @return IMSI码
6565
*/
6666
@SuppressLint("HardwareIds")
6767
public static String getIMSI() {
@@ -178,7 +178,9 @@ public static String getPhoneStatus() {
178178
* @param phoneNumber 电话号码
179179
*/
180180
public static void dial(String phoneNumber) {
181-
Utils.getContext().startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber)));
181+
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
182+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
183+
Utils.getContext().startActivity(intent);
182184
}
183185

184186
/**
@@ -188,7 +190,9 @@ public static void dial(String phoneNumber) {
188190
* @param phoneNumber 电话号码
189191
*/
190192
public static void call(String phoneNumber) {
191-
Utils.getContext().startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + phoneNumber)));
193+
Intent intent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + phoneNumber));
194+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
195+
Utils.getContext().startActivity(intent);
192196
}
193197

194198
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static String getSDCardPath() {
5656
}
5757
}
5858
if (p.waitFor() != 0 && p.exitValue() == 1) {
59-
return " 命令执行失败";
59+
break;
6060
}
6161
}
6262
} catch (Exception e) {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.pm.ActivityInfo;
77
import android.content.res.Configuration;
88
import android.graphics.Bitmap;
9+
import android.provider.Settings;
910
import android.util.DisplayMetrics;
1011
import android.view.Surface;
1112
import android.view.View;
@@ -157,4 +158,28 @@ public static boolean isScreenLock() {
157158
.getSystemService(Context.KEYGUARD_SERVICE);
158159
return km.inKeyguardRestrictedInputMode();
159160
}
161+
162+
/**
163+
* 设置进入休眠时长
164+
* <uses-permission android:name="android.permission.WRITE_SETTINGS" />
165+
*
166+
* @param duration 时长
167+
*/
168+
public static void setSleepDuration(int duration) {
169+
Settings.System.putInt(Utils.getContext().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, duration);
170+
}
171+
172+
/**
173+
* 获取进入休眠时长
174+
*
175+
* @return 进入休眠时长,报错返回-123
176+
*/
177+
public static int getSleepDuration() {
178+
try {
179+
return Settings.System.getInt(Utils.getContext().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
180+
} catch (Settings.SettingNotFoundException e) {
181+
e.printStackTrace();
182+
return -123;
183+
}
184+
}
160185
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.blankj.utilcode.utils;
22

33
import android.support.annotation.ColorInt;
4-
import android.support.design.widget.BaseTransientBottomBar;
54
import android.support.design.widget.Snackbar;
65
import android.view.Gravity;
76
import android.view.LayoutInflater;
@@ -89,7 +88,6 @@ public static void showLongSnackbar(View parent, CharSequence text, @ColorInt in
8988
*
9089
* @param parent 父视图(CoordinatorLayout或者DecorView)
9190
* @param text 文本
92-
* @param duration 自定义时长
9391
* @param textColor 文本颜色
9492
* @param bgColor 背景色
9593
*/
@@ -102,7 +100,6 @@ public static void showIndefiniteSnackbar(View parent, CharSequence text, @Color
102100
*
103101
* @param parent 父视图(CoordinatorLayout或者DecorView)
104102
* @param text 文本
105-
* @param duration 自定义时长
106103
* @param textColor 文本颜色
107104
* @param bgColor 背景色
108105
* @param actionText 事件文本
@@ -128,7 +125,7 @@ public static void showIndefiniteSnackbar(View parent, CharSequence text, @Color
128125
* @param listener 监听器
129126
*/
130127
private static void showSnackbar(View parent, CharSequence text,
131-
@BaseTransientBottomBar.Duration int duration,
128+
int duration,
132129
@ColorInt int textColor, @ColorInt int bgColor,
133130
CharSequence actionText, int actionTextColor,
134131
View.OnClickListener listener) {

utilcode/src/test/java/com/blankj/utilcode/utils/DogeTest.java

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import org.junit.Test;
44

55
import java.io.File;
6+
import java.util.ArrayList;
67
import java.util.List;
8+
import java.util.Locale;
79

810
/**
911
* <pre>
@@ -15,39 +17,70 @@
1517
*/
1618
public class DogeTest {
1719

20+
private static List<File> dogeFiles = new ArrayList<>();
21+
private static int[] indexes = {0, 50, 100, 150, 200, 300, 400, 450, 500, 550, 600, 700};
22+
23+
private static int bitNum = 3;
24+
25+
static {
26+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_00_000_049_SingleRun"));
27+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_01_050_099_Tear"));
28+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_02_100_149_Lines"));
29+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_03_150_199_MoreRun"));
30+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_04_200_299_ToLeft"));
31+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_05_300_399_ToRight"));
32+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_06_400_449_Big"));
33+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_07_450_499_Hug"));
34+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_08_500_549_Wang"));
35+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_09_550_599_ToWall"));
36+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_10_600_699_OtherGif"));
37+
dogeFiles.add(new File("F:/MyGithub/doge-expression/_11_700_799_OtherJpg"));
38+
}
39+
40+
1841
@Test
1942
public void generateDogeMD() throws Exception {
43+
bitNum = 4;
44+
renameDogeNames();
45+
bitNum = 3;
46+
renameDogeNames();
2047
StringBuilder sb = new StringBuilder();
21-
sb.append("卡通doge的表情大集合,喜爱doge的朋友的福利到了,花了大半天的时间整理出来的狗东西,就被你们这么轻而易举地拿走了,现附上QQ表情包链接[doge-expression.eif](https://github.com/Blankj/doge-expression/blob/master/doge-expression.eif)(进去点击Download即可)\n\n");
48+
sb.append("卡通doge的表情大集合,喜爱doge的朋友的福利到了,花了很多的时间整理出来的狗东西,就被你们这么轻而易举地拿走了,现附上QQ表情包链接[doge-expression.eif](https://raw.githubusercontent.com/Blankj/doge-expression/master/doge-expression.eif)(进去点击Download即可)\n\n");
2249
sb.append("下面展示doge各种姿势,请系好安全带,开车啦,滴滴滴~~\n\n");
23-
File file = new File("F:/MyGithub/doge-expression/expression");
24-
List<File> files = FileUtils.listFilesInDir(file);
25-
for (File f : files) {
26-
String name = f.getName();
27-
sb.append("![")
28-
.append(name)
29-
.append("]")
30-
.append("(https://github.com/Blankj/doge-expression/raw/master/expression/")
31-
.append(name)
32-
.append(") \n");
50+
for (int i = 0; i < dogeFiles.size(); ++i) {
51+
List<File> files = FileUtils.listFilesInDir(dogeFiles.get(i));
52+
for (File f : files) {
53+
String name = f.getName();
54+
sb.append("![")
55+
.append(name)
56+
.append("]")
57+
.append("(https://github.com/Blankj/doge-expression/raw/master/")
58+
.append(f.getParentFile().getName())
59+
.append("/")
60+
.append(name)
61+
.append(") \n");
62+
}
3363
}
64+
// System.out.println(sb.toString());
3465
FileUtils.writeFileFromString("F:/MyGithub/doge-expression/README.md", sb.toString(), false);
3566
}
3667

3768
@Test
38-
public void generateDogeNames() throws Exception {
39-
StringBuilder sb = new StringBuilder();
40-
File file = new File("F:/MyGithub/doge-expression/expression");
41-
List<File> files = FileUtils.listFilesInDir(file);
42-
for (File f : files) {
43-
String name = f.getName();
44-
sb.append("![")
45-
.append(name)
46-
.append("]")
47-
.append("(https://github.com/Blankj/doge-expression/raw/master/expression/")
48-
.append(name)
49-
.append(") \n");
69+
public void renameDogeNames() throws Exception {
70+
for (int i = 0; i < dogeFiles.size(); ++i) {
71+
List<File> files = FileUtils.listFilesInDir(dogeFiles.get(i));
72+
int index = indexes[i];
73+
for (File f : files) {
74+
String name = f.getName();
75+
String rename = String.format(
76+
Locale.getDefault(),
77+
"%s%0" + bitNum + "d%s",
78+
f.getParent() + File.separator,
79+
index++,
80+
name.substring(name.length() - 4)
81+
);
82+
f.renameTo(new File(rename));
83+
}
5084
}
51-
FileUtils.writeFileFromString("F:/MyGithub/doge-expression/README.md", sb.toString(), false);
5285
}
5386
}

0 commit comments

Comments
 (0)