Skip to content

Commit bebbaae

Browse files
committed
see 01/11 log
1 parent 933ebc8 commit bebbaae

File tree

12 files changed

+181
-92
lines changed

12 files changed

+181
-92
lines changed

utilcode/README-CN.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ getAppSignatureSHA256 : 获取应用签名的的 SHA256 值
6969
getAppSignatureMD5 : 获取应用签名的的 MD5 值
7070
getAppInfo : 获取 App 信息
7171
getAppsInfo : 获取所有已安装 App 信息
72+
getApkInfo : 获取 Apk 信息
7273
```
7374

7475
* ### 栏相关 -> [BarUtils.java][bar.java] -> [Demo][bar.demo]
@@ -372,9 +373,13 @@ setBackground : 设置背景
372373

373374
* ### Gson 相关 -> [GsonUtils.java][gson.java] -> [Test][gson.test]
374375
```
375-
getGson : 获取 Gson 对象
376-
toJson : 对象转 Json 串
377-
fromJson: Json 串转对象
376+
getGson : 获取 Gson 对象
377+
toJson : 对象转 Json 串
378+
fromJson : Json 串转对象
379+
getCollectionType: 获取集合类型
380+
getMapType : 获取字典类型
381+
getArrayType : 获取数组类型
382+
getType : 获取类型
378383
```
379384

380385
* ### 图片相关 -> [ImageUtils.java][image.java] -> [Demo][image.demo]

utilcode/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ getAppSignatureSHA256
6969
getAppSignatureMD5
7070
getAppInfo
7171
getAppsInfo
72+
getApkInfo
7273
```
7374

7475
* ### About Bar -> [BarUtils.java][bar.java] -> [Demo][bar.demo]
@@ -375,6 +376,10 @@ setBackground
375376
getGson
376377
toJson
377378
fromJson
379+
getCollectionType
380+
getMapType
381+
getArrayType
382+
getType
378383
```
379384

380385
* ### About Image -> [ImageUtils.java][image.java] -> [Demo][image.demo]

utilcode/lib/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
<application>
55
<activity
6-
android:name=".util.PermissionUtils$PermissionActivity"
6+
android:name="com.blankj.utilcode.util.PermissionUtils$PermissionActivity"
77
android:configChanges="orientation|keyboardHidden|screenSize"
88
android:multiprocess="true"
99
android:theme="@style/ActivityTranslucent"
1010
android:windowSoftInputMode="stateHidden|stateAlwaysHidden" />
1111

1212
<provider
13-
android:name=".util.Utils$FileProvider4UtilCode"
13+
android:name="com.blankj.utilcode.util.Utils$FileProvider4UtilCode"
1414
android:authorities="${applicationId}.utilcode.provider"
1515
android:exported="false"
1616
android:grantUriPermissions="true"

utilcode/lib/src/main/java/com/blankj/utilcode/constant/PermissionConstants.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.lang.annotation.Retention;
1010
import java.lang.annotation.RetentionPolicy;
11-
import java.util.Arrays;
1211

1312

1413
/**
@@ -52,9 +51,11 @@ public final class PermissionConstants {
5251
permission.READ_CALL_LOG, permission.WRITE_CALL_LOG, permission.ADD_VOICEMAIL,
5352
permission.USE_SIP, permission.PROCESS_OUTGOING_CALLS, permission.ANSWER_PHONE_CALLS
5453
};
55-
private static final String[] GROUP_PHONE_BELOW_O = Arrays.copyOf(
56-
GROUP_PHONE, GROUP_PHONE.length - 1
57-
);
54+
private static final String[] GROUP_PHONE_BELOW_O = {
55+
permission.READ_PHONE_STATE, permission.READ_PHONE_NUMBERS, permission.CALL_PHONE,
56+
permission.READ_CALL_LOG, permission.WRITE_CALL_LOG, permission.ADD_VOICEMAIL,
57+
permission.USE_SIP, permission.PROCESS_OUTGOING_CALLS
58+
};
5859
private static final String[] GROUP_SENSORS = {
5960
permission.BODY_SENSORS
6061
};

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,28 @@ public static List<AppInfo> getAppsInfo() {
766766
return list;
767767
}
768768

769+
/**
770+
* Return the application's package information.
771+
*
772+
* @return the application's package information
773+
*/
774+
public static AppUtils.AppInfo getApkInfo(final File apkFile) {
775+
if (apkFile == null || !apkFile.isFile() || !apkFile.exists()) return null;
776+
return getApkInfo(apkFile.getAbsolutePath());
777+
}
778+
779+
/**
780+
* Return the application's package information.
781+
*
782+
* @return the application's package information
783+
*/
784+
public static AppUtils.AppInfo getApkInfo(final String apkFilePath) {
785+
if (isSpace(apkFilePath)) return null;
786+
PackageManager pm = Utils.getApp().getPackageManager();
787+
PackageInfo pi = pm.getPackageArchiveInfo(apkFilePath, 0);
788+
return getBean(pm, pi);
789+
}
790+
769791
private static AppInfo getBean(final PackageManager pm, final PackageInfo pi) {
770792
if (pm == null || pi == null) return null;
771793
ApplicationInfo ai = pi.applicationInfo;

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
5+
import com.google.gson.reflect.TypeToken;
56

67
import java.io.Reader;
78
import java.lang.reflect.Type;
9+
import java.util.Collection;
10+
import java.util.Map;
811

912

1013
/**
@@ -110,6 +113,48 @@ public static <T> T fromJson(final Reader reader, final Type type) {
110113
return GSON.fromJson(reader, type);
111114
}
112115

116+
/**
117+
* Return the type of collection with the {@code type}.
118+
*
119+
* @param type The type.
120+
* @return the type of collection with the {@code type}
121+
*/
122+
public static Type getCollectionType(final Type type) {
123+
return TypeToken.getParameterized(Collection.class, type).getType();
124+
}
125+
126+
/**
127+
* Return the type of map with the {@code keyType} and {@code valueType}.
128+
*
129+
* @param keyType The type of key.
130+
* @param valueType The type of value.
131+
* @return the type of map with the {@code keyType} and {@code valueType}
132+
*/
133+
public static Type getMapType(final Type keyType, final Type valueType) {
134+
return TypeToken.getParameterized(Map.class, keyType, valueType).getType();
135+
}
136+
137+
/**
138+
* Return the type of array with the {@code type}.
139+
*
140+
* @param type The type.
141+
* @return the type of map with the {@code type}
142+
*/
143+
public static Type getArrayType(final Type type) {
144+
return TypeToken.getArray(type).getType();
145+
}
146+
147+
/**
148+
* Return the type of {@code rawType} with the {@code typeArguments}.
149+
*
150+
* @param rawType The raw type.
151+
* @param typeArguments The type of arguments.
152+
* @return the type of map with the {@code type}
153+
*/
154+
public static Type getType(final Type rawType, final Type... typeArguments) {
155+
return TypeToken.getParameterized(rawType, typeArguments).getType();
156+
}
157+
113158
/**
114159
* Create a pre-configured {@link Gson} instance.
115160
*

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@
3939
import java.text.ParseException;
4040
import java.text.SimpleDateFormat;
4141
import java.util.Arrays;
42-
import java.util.Collection;
43-
import java.util.Collections;
4442
import java.util.Date;
4543
import java.util.Formatter;
4644
import java.util.Iterator;
4745
import java.util.Locale;
48-
import java.util.Map;
4946
import java.util.Set;
5047
import java.util.concurrent.ExecutorService;
5148
import java.util.concurrent.Executors;
@@ -798,7 +795,7 @@ static String object2Json(Object object) {
798795
return formatJson(object.toString());
799796
}
800797
try {
801-
return formatJson(GSON.toJson(object));
798+
return GSON.toJson(object);
802799
} catch (Throwable t) {
803800
return object.toString();
804801
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
import android.net.Uri;
88
import android.os.Build;
99
import android.os.Environment;
10-
import android.os.ParcelFileDescriptor;
1110
import android.provider.DocumentsContract;
1211
import android.provider.MediaStore;
1312
import android.support.annotation.NonNull;
14-
import android.support.annotation.Nullable;
1513
import android.support.v4.content.FileProvider;
1614
import android.util.Log;
1715

1816
import java.io.File;
19-
import java.io.FileDescriptor;
2017

2118
/**
2219
* <pre>
@@ -63,7 +60,7 @@ public static File uri2File(@NonNull final Uri uri) {
6360
Log.d("UriUtils", uri.toString() + " parse failed. -> 0");
6461
return null;
6562
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) {
66-
return getFileFromUri(uri, null, null);
63+
return getFileFromUri(uri);
6764
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
6865
&& DocumentsContract.isDocumentUri(Utils.getApp(), uri)) {
6966
if ("com.android.externalstorage.documents".equals(authority)) {
@@ -81,7 +78,7 @@ public static File uri2File(@NonNull final Uri uri) {
8178
Uri.parse("content://downloads/public_downloads"),
8279
Long.valueOf(id)
8380
);
84-
return getFileFromUri(contentUri, null, null);
81+
return getFileFromUri(contentUri);
8582
} else if ("com.android.providers.media.documents".equals(authority)) {
8683
final String docId = DocumentsContract.getDocumentId(uri);
8784
final String[] split = docId.split(":");
@@ -110,11 +107,11 @@ public static File uri2File(@NonNull final Uri uri) {
110107
}
111108
}
112109

113-
private static File getFileFromUri(@NonNull final Uri uri) {
110+
private static File getFileFromUri(final Uri uri) {
114111
return getFileFromUri(uri, null, null);
115112
}
116113

117-
private static File getFileFromUri(@NonNull final Uri uri,
114+
private static File getFileFromUri(final Uri uri,
118115
final String selection,
119116
final String[] selectionArgs) {
120117
CursorLoader cl = new CursorLoader(Utils.getApp());

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import org.robolectric.RuntimeEnvironment;
88
import org.robolectric.annotation.Config;
99
import org.robolectric.shadows.ShadowLog;
10-
import org.robolectric.shadows.ShadowLooper;
1110

1211
/**
1312
* <pre>
@@ -30,6 +29,7 @@ public BaseTest() {
3029

3130
@Test
3231
public void test() throws Exception {
32+
3333
// final CountDownLatch countDownLatch = new CountDownLatch(1);
3434
// final Scanner scanner = new Scanner(System.in);
3535
// ExecutorService singlePool = ThreadUtils.getSinglePool();
@@ -117,4 +117,27 @@ public void test() throws Exception {
117117
// countDownLatch.await();
118118

119119
}
120+
121+
static class Person {
122+
123+
String name;
124+
int gender;
125+
String address;
126+
127+
public Person(String name) {
128+
this.name = name;
129+
}
130+
131+
@Override
132+
public boolean equals(Object obj) {
133+
if (obj == this) return true;
134+
if (!(obj instanceof Person)) return false;
135+
Person p = (Person) obj;
136+
return equals(name, p.name) && p.gender == gender && equals(address, p.address);
137+
}
138+
139+
private static boolean equals(final Object o1, final Object o2) {
140+
return o1 == o2 || (o1 != null && o1.equals(o2));
141+
}
142+
}
120143
}

0 commit comments

Comments
 (0)