Skip to content

Commit c8b2c8d

Browse files
committed
see 06/29 log
1 parent 711d1ce commit c8b2c8d

File tree

13 files changed

+87
-37
lines changed

13 files changed

+87
-37
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.17.1-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.17.2-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.17.1-brightgreen.svg
44+
[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.17.2-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
@@ -57,5 +57,5 @@ dependencies {
5757
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
5858
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
5959
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version"
60-
// implementation 'com.blankj:utilcode:1.17.1'
60+
// implementation 'com.blankj:utilcode:1.17.2'
6161
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ buildscript {
77
min_sdk_version = 14
88
target_sdk_version = 27
99

10-
version_code = 1_017_001
11-
version_name = '1.17.1'// E.g 1.9.72 => 1,009,072
10+
version_code = 1_017_002
11+
version_name = '1.17.2'// E.g 1.9.72 => 1,009,072
1212

1313
// App dependencies
1414
support_version = '27.1.0'

update_log.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* 18/06/29 修复 FragmentUtils 中 getFragmentManager 空指针错误,发布 1.17.2
2+
* 18/06/27 新增 UriUtils#uri2File
13
* 18/06/25 新增 KeyboardUtils#fixAndroidBug5497,发布 1.17.1 版本
24
* 18/06/21 修复 FragmentUtils#add 死循环的 BUG
35
* 18/06/14 替换 CacheUtils 为 CacheDiskUtils,CacheUtils 标记 deprecated,发布 1.17.0 版本

utilcode/README-CN.md

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

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

88

@@ -745,7 +745,8 @@ cancel : 取消吐司显示
745745

746746
* ### URI 相关 -> [UriUtils.java][uri.java]
747747
```
748-
getUriForFile: 获取文件 URI
748+
file2Uri: file 转 uri
749+
uri2File: uri 转 file
749750
```
750751

751752
* ### 压缩相关 -> [ZipUtils.java][zip.java] -> [Test][zip.test]

utilcode/README.md

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

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

88

@@ -745,7 +745,8 @@ cancel
745745

746746
* ### About Uri -> [UriUtils.java][uri.java]
747747
```
748-
getUriForFile
748+
file2Uri
749+
uri2File
749750
```
750751

751752
* ### About Zip -> [ZipUtils.java][zip.java] -> [Test][zip.test]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* author: Blankj
4242
* blog : http://blankj.com
4343
* time : 2017/05/24
44-
* desc : utils about cache
44+
* desc : utils about disk cache
4545
* </pre>
4646
*/
4747
public final class CacheDiskUtils implements CacheConstants {
@@ -128,7 +128,7 @@ public static CacheDiskUtils getInstance(@NonNull final File cacheDir) {
128128
public static CacheDiskUtils getInstance(@NonNull final File cacheDir,
129129
final long maxSize,
130130
final int maxCount) {
131-
final String cacheKey = cacheDir.getAbsoluteFile() + "_" + maxCount + "_" + maxCount;
131+
final String cacheKey = cacheDir.getAbsoluteFile() + "_" + maxSize + "_" + maxCount;
132132
CacheDiskUtils cache = CACHE_MAP.get(cacheKey);
133133
if (cache == null) {
134134
if (!cacheDir.exists() && !cacheDir.mkdirs()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* author: Blankj
1414
* blog : http://blankj.com
1515
* time : 2017/05/24
16-
* desc : utils about LRU cache
16+
* desc : utils about memory cache
1717
* </pre>
1818
*/
1919
public final class CacheMemoryUtils implements CacheConstants {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static CacheUtils getInstance(@NonNull final File cacheDir) {
131131
public static CacheUtils getInstance(@NonNull final File cacheDir,
132132
final long maxSize,
133133
final int maxCount) {
134-
final String cacheKey = cacheDir.getAbsoluteFile() + "_" + maxCount + "_" + maxCount;
134+
final String cacheKey = cacheDir.getAbsoluteFile() + "_" + maxSize + "_" + maxCount;
135135
CacheUtils cache = CACHE_MAP.get(cacheKey);
136136
if (cache == null) {
137137
if (!cacheDir.exists() && !cacheDir.mkdirs()) {

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

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.support.annotation.DrawableRes;
99
import android.support.annotation.IdRes;
1010
import android.support.annotation.NonNull;
11+
import android.support.annotation.Nullable;
1112
import android.support.v4.app.Fragment;
1213
import android.support.v4.app.FragmentManager;
1314
import android.support.v4.app.FragmentTransaction;
@@ -933,8 +934,10 @@ public static void replace(@NonNull final Fragment srcFragment,
933934
@NonNull final Fragment destFragment,
934935
final String destTag,
935936
final boolean isAddStack) {
937+
FragmentManager fm = srcFragment.getFragmentManager();
938+
if (fm == null) return;
936939
Args args = getArgs(srcFragment);
937-
replace(srcFragment.getFragmentManager(), destFragment, args.id, destTag, isAddStack);
940+
replace(fm, destFragment, args.id, destTag, isAddStack);
938941
}
939942

940943
/**
@@ -1031,8 +1034,10 @@ public static void replace(@NonNull final Fragment srcFragment,
10311034
@AnimRes final int exitAnim,
10321035
@AnimRes final int popEnterAnim,
10331036
@AnimRes final int popExitAnim) {
1037+
FragmentManager fm = srcFragment.getFragmentManager();
1038+
if (fm == null) return;
10341039
Args args = getArgs(srcFragment);
1035-
replace(srcFragment.getFragmentManager(), destFragment, args.id, destTag, isAddStack,
1040+
replace(fm, destFragment, args.id, destTag, isAddStack,
10361041
enterAnim, exitAnim, popEnterAnim, popExitAnim);
10371042
}
10381043

@@ -1067,8 +1072,10 @@ public static void replace(@NonNull final Fragment srcFragment,
10671072
final String destTag,
10681073
final boolean isAddStack,
10691074
final View... sharedElements) {
1075+
FragmentManager fm = srcFragment.getFragmentManager();
1076+
if (fm == null) return;
10701077
Args args = getArgs(srcFragment);
1071-
replace(srcFragment.getFragmentManager(),
1078+
replace(fm,
10721079
destFragment,
10731080
args.id,
10741081
destTag,
@@ -1399,21 +1406,23 @@ private static void putArgs(final Fragment fragment, final boolean isHide) {
13991406

14001407
private static Args getArgs(final Fragment fragment) {
14011408
Bundle bundle = fragment.getArguments();
1409+
if (bundle == null) bundle = Bundle.EMPTY;
14021410
return new Args(bundle.getInt(ARGS_ID, fragment.getId()),
14031411
bundle.getBoolean(ARGS_IS_HIDE),
14041412
bundle.getBoolean(ARGS_IS_ADD_STACK));
14051413
}
14061414

1407-
private static void operateNoAnim(final FragmentManager fm,
1415+
private static void operateNoAnim(@Nullable final FragmentManager fm,
14081416
final int type,
14091417
final Fragment src,
14101418
Fragment... dest) {
1419+
if (fm == null) return;
14111420
FragmentTransaction ft = fm.beginTransaction();
14121421
operate(type, fm, ft, src, dest);
14131422
}
14141423

14151424
private static void operate(final int type,
1416-
final FragmentManager fm,
1425+
@NonNull final FragmentManager fm,
14171426
final FragmentTransaction ft,
14181427
final Fragment src,
14191428
final Fragment... dest) {
@@ -1528,7 +1537,8 @@ private static Fragment getTopIsInStack(@NonNull final FragmentManager fm,
15281537
Fragment fragment = fragments.get(i);
15291538
if (fragment != null) {
15301539
if (isInStack) {
1531-
if (fragment.getArguments().getBoolean(ARGS_IS_ADD_STACK)) {
1540+
Bundle args = fragment.getArguments();
1541+
if (args != null && args.getBoolean(ARGS_IS_ADD_STACK)) {
15321542
return fragment;
15331543
}
15341544
} else {
@@ -1569,7 +1579,8 @@ private static Fragment getTopShowIsInStack(@NonNull final FragmentManager fm,
15691579
&& fragment.isVisible()
15701580
&& fragment.getUserVisibleHint()) {
15711581
if (isInStack) {
1572-
if (fragment.getArguments().getBoolean(ARGS_IS_ADD_STACK)) {
1582+
Bundle args = fragment.getArguments();
1583+
if (args != null && args.getBoolean(ARGS_IS_ADD_STACK)) {
15731584
return fragment;
15741585
}
15751586
} else {
@@ -1587,7 +1598,6 @@ private static Fragment getTopShowIsInStack(@NonNull final FragmentManager fm,
15871598
* @return the fragments in manager
15881599
*/
15891600
public static List<Fragment> getFragments(@NonNull final FragmentManager fm) {
1590-
@SuppressWarnings("RestrictedApi")
15911601
List<Fragment> fragments = fm.getFragments();
15921602
if (fragments == null || fragments.isEmpty()) return Collections.emptyList();
15931603
return fragments;
@@ -1603,8 +1613,11 @@ public static List<Fragment> getFragmentsInStack(@NonNull final FragmentManager
16031613
List<Fragment> fragments = getFragments(fm);
16041614
List<Fragment> result = new ArrayList<>();
16051615
for (Fragment fragment : fragments) {
1606-
if (fragment != null && fragment.getArguments().getBoolean(ARGS_IS_ADD_STACK)) {
1607-
result.add(fragment);
1616+
if (fragment != null) {
1617+
Bundle args = fragment.getArguments();
1618+
if (args != null && args.getBoolean(ARGS_IS_ADD_STACK)) {
1619+
result.add(fragment);
1620+
}
16081621
}
16091622
}
16101623
return result;
@@ -1649,10 +1662,13 @@ private static List<FragmentNode> getAllFragmentsInStack(@NonNull final Fragment
16491662
List<Fragment> fragments = getFragments(fm);
16501663
for (int i = fragments.size() - 1; i >= 0; --i) {
16511664
Fragment fragment = fragments.get(i);
1652-
if (fragment != null && fragment.getArguments().getBoolean(ARGS_IS_ADD_STACK)) {
1653-
result.add(new FragmentNode(fragment,
1654-
getAllFragmentsInStack(fragment.getChildFragmentManager(),
1655-
new ArrayList<FragmentNode>())));
1665+
if (fragment != null) {
1666+
Bundle args = fragment.getArguments();
1667+
if (args != null && args.getBoolean(ARGS_IS_ADD_STACK)) {
1668+
result.add(new FragmentNode(fragment,
1669+
getAllFragmentsInStack(fragment.getChildFragmentManager(),
1670+
new ArrayList<FragmentNode>())));
1671+
}
16561672
}
16571673
}
16581674
return result;
@@ -1774,10 +1790,10 @@ public static String getSimpleName(final Fragment fragment) {
17741790
}
17751791

17761792
private static class Args {
1777-
int id;
1778-
boolean isHide;
1779-
boolean isAddStack;
1780-
String tag;
1793+
final int id;
1794+
final boolean isHide;
1795+
final boolean isAddStack;
1796+
final String tag;
17811797

17821798
private Args(final int id, final boolean isHide, final boolean isAddStack) {
17831799
this(id, null, isHide, isAddStack);
@@ -1793,8 +1809,8 @@ private Args(final int id, final String tag,
17931809
}
17941810

17951811
public static class FragmentNode {
1796-
Fragment fragment;
1797-
List<FragmentNode> next;
1812+
final Fragment fragment;
1813+
final List<FragmentNode> next;
17981814

17991815
public FragmentNode(final Fragment fragment, final List<FragmentNode> next) {
18001816
this.fragment = fragment;

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.blankj.utilcode.util;
22

3+
import android.content.CursorLoader;
4+
import android.database.Cursor;
35
import android.net.Uri;
46
import android.os.Build;
7+
import android.provider.MediaStore;
58
import android.support.v4.content.FileProvider;
69

710
import java.io.File;
@@ -21,12 +24,20 @@ private UriUtils() {
2124
}
2225

2326
/**
24-
* Return a content URI for a given file.
27+
* @deprecated Use {@link UriUtils#file2Uri(File)} instead.
28+
*/
29+
@Deprecated
30+
public static Uri getUriForFile(final File file) {
31+
return file2Uri(file);
32+
}
33+
34+
/**
35+
* File to uri.
2536
*
2637
* @param file The file.
27-
* @return a content URI for a given file
38+
* @return uri
2839
*/
29-
public static Uri getUriForFile(final File file) {
40+
public static Uri file2Uri(final File file) {
3041
if (file == null) return null;
3142
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
3243
String authority = Utils.getApp().getPackageName() + ".utilcode.provider";
@@ -35,4 +46,23 @@ public static Uri getUriForFile(final File file) {
3546
return Uri.fromFile(file);
3647
}
3748
}
49+
50+
/**
51+
* Uri to file.
52+
*
53+
* @param uri The uri.
54+
* @param columnName The name of the target column.
55+
* <p>e.g. {@link MediaStore.Images.Media#DATA}</p>
56+
* @return file
57+
*/
58+
public static File uri2File(final Uri uri, final String columnName) {
59+
if (uri == null) return null;
60+
CursorLoader cl = new CursorLoader(Utils.getApp());
61+
cl.setUri(uri);
62+
cl.setProjection(new String[]{columnName});
63+
Cursor cursor = cl.loadInBackground();
64+
int columnIndex = cursor.getColumnIndexOrThrow(columnName);
65+
cursor.moveToFirst();
66+
return new File(cursor.getString(columnIndex));
67+
}
3868
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class Utils {
4040
@SuppressLint("StaticFieldLeak")
4141
private static Application sApplication;
4242

43-
private static final ActivityLifecycleImpl ACTIVITY_LIFECYCLE = new ActivityLifecycleImpl();
43+
static final ActivityLifecycleImpl ACTIVITY_LIFECYCLE = new ActivityLifecycleImpl();
4444

4545
private Utils() {
4646
throw new UnsupportedOperationException("u can't instantiate me...");

0 commit comments

Comments
 (0)