diff --git a/README-CN.md b/README-CN.md index da35b6112c547fba205b440ed006812608a47683..2c253cdef6921db52e2eadc11ea8643ff7b3f650 100644 --- a/README-CN.md +++ b/README-CN.md @@ -41,7 +41,7 @@ [logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png -[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.15.0-brightgreen.svg +[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.15.1-brightgreen.svg [auc]: https://github.com/Blankj/AndroidUtilCode [apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg diff --git a/README.md b/README.md index 1002964dc95f712a049de279a10ca7d6b6881832..32a0b9a174323b52f1bcf3fd893e409016cd56c6 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ If this project helps you a lot and you want to support the project's developmen [logo]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/logo.png -[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.15.0-brightgreen.svg +[aucsvg]: https://img.shields.io/badge/AndroidUtilCode-v1.15.1-brightgreen.svg [auc]: https://github.com/Blankj/AndroidUtilCode [apisvg]: https://img.shields.io/badge/API-14+-brightgreen.svg diff --git a/app/build.gradle b/app/build.gradle index 0c7eed3289150ec4fcd2d8b120d8d95837263b85..fe964d0b48ab832d607b852d1634ddc17fe86c3d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,7 +56,7 @@ dependencies { // LeakCanary debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version" releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakcanary_version" -// implementation 'com.blankj:utilcode:1.15.0' +// implementation 'com.blankj:utilcode:1.15.1' } diff --git a/build.gradle b/build.gradle index 49db818dc235e776e4165cf238956a53cd377bbf..6996162521cfb9f746aeef75046b992f7bea92ab 100644 --- a/build.gradle +++ b/build.gradle @@ -44,8 +44,8 @@ ext { min_sdk_version = 14 target_sdk_version = 27 - version_code = 1_015_000 - version_name = '1.15.0'// E.g 1.9.72 => 1,009,072 + version_code = 1_015_001 + version_name = '1.15.1'// E.g 1.9.72 => 1,009,072 // App dependencies support_version = '27.1.0' diff --git a/update_log.md b/update_log.md index b24fe921796f8d23aae356b8d3728b7dbc13ac15..19b6f33371fd10880e6da20a6dbe63f233990559 100644 --- a/update_log.md +++ b/update_log.md @@ -1,3 +1,4 @@ +* 18/05/15 新增 MetaDataUtils 和 ActivityUtils#startActivityForResult,发布 1.15.1 版本 * 18/05/08 新增 ResourceUtils,发布 1.15.0 版本 * 18/05/07 修复 ZipUtils 漏洞,发布 1.14.4 版本 * 18/05/03 修复 ToastUtils 默认字体大小问题,发布 1.14.3 版本 diff --git a/utilcode/README-CN.md b/utilcode/README-CN.md index f09a35130d5023f0187391a12a4afa3470051ac3..eb236f894afdde9a0e405266e370d9937765efe4 100644 --- a/utilcode/README-CN.md +++ b/utilcode/README-CN.md @@ -2,7 +2,7 @@ Gradle: ```groovy -implementation 'com.blankj:utilcode:1.15.0' +implementation 'com.blankj:utilcode:1.15.1' ``` @@ -25,6 +25,7 @@ U needn't do anything, because I add `consumerProguardFiles 'proguard-rules.pro' ``` isActivityExists : 判断 Activity 是否存在 startActivity : 启动 Activity +startActivityForResult : 启动 Activity 为返回结果 startActivities : 启动多个 Activity startHomeActivity : 回到桌面 getActivityList : 获取 Activity 栈链表 diff --git a/utilcode/README.md b/utilcode/README.md index 4576a85f9b9dee5b327b2f15441dcaab726b485c..d44c65784297c30a195b3e568d0f9fd6f1188792 100644 --- a/utilcode/README.md +++ b/utilcode/README.md @@ -2,7 +2,7 @@ Gradle: ```groovy -implementation 'com.blankj:utilcode:1.15.0' +implementation 'com.blankj:utilcode:1.15.1' ``` @@ -25,6 +25,7 @@ U needn't do anything, because I add `consumerProguardFiles 'proguard-rules.pro' ``` isActivityExists startActivity +startActivityForResult startActivities startHomeActivity getActivityList diff --git a/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java b/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java index f94e99c52afcf6c5a8fae89695ac2bf149e6f1b5..e697eb9bf6ba3e26858502ebf0a87a6e7be4458f 100644 --- a/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java +++ b/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java @@ -597,6 +597,321 @@ public final class ActivityUtils { } } + /** + * Start the activity. + * + * @param activity The activity. + * @param clz The activity class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + */ + public static void startActivityForResult(@NonNull final Activity activity, + @NonNull final Class clz, + final int requestCode) { + startActivityForResult(activity, null, activity.getPackageName(), clz.getName(), + requestCode, null); + } + + /** + * Start the activity. + * + * @param activity The activity. + * @param clz The activity class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param options Additional options for how the Activity should be started. + */ + public static void startActivityForResult(@NonNull final Activity activity, + @NonNull final Class clz, + final int requestCode, + final Bundle options) { + startActivityForResult(activity, null, activity.getPackageName(), clz.getName(), + requestCode, options); + } + + /** + * Start the activity. + * + * @param activity The activity. + * @param clz The activity class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param sharedElements The names of the shared elements to transfer to the called + * Activity and their associated Views. + */ + public static void startActivityForResult(@NonNull final Activity activity, + @NonNull final Class clz, + final int requestCode, + final View... sharedElements) { + startActivityForResult(activity, null, activity.getPackageName(), clz.getName(), + requestCode, getOptionsBundle(activity, sharedElements)); + } + + /** + * Start the activity. + * + * @param activity The activity. + * @param clz The activity class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param enterAnim A resource ID of the animation resource to use for the + * incoming activity. + * @param exitAnim A resource ID of the animation resource to use for the + * outgoing activity. + */ + public static void startActivityForResult(@NonNull final Activity activity, + @NonNull final Class clz, + final int requestCode, + @AnimRes final int enterAnim, + @AnimRes final int exitAnim) { + startActivityForResult(activity, null, activity.getPackageName(), clz.getName(), + requestCode, getOptionsBundle(activity, enterAnim, exitAnim)); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + activity.overridePendingTransition(enterAnim, exitAnim); + } + } + + /** + * Start the activity. + * + * @param extras The Bundle of extras to add to this intent. + * @param activity The activity. + * @param clz The activity class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + */ + public static void startActivityForResult(@NonNull final Bundle extras, + @NonNull final Activity activity, + @NonNull final Class clz, + final int requestCode) { + startActivityForResult(activity, extras, activity.getPackageName(), clz.getName(), + requestCode, null); + } + + /** + * Start the activity. + * + * @param extras The Bundle of extras to add to this intent. + * @param activity The activity. + * @param clz The activity class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param options Additional options for how the Activity should be started. + */ + public static void startActivityForResult(@NonNull final Bundle extras, + @NonNull final Activity activity, + @NonNull final Class clz, + final int requestCode, + @NonNull final Bundle options) { + startActivityForResult(activity, extras, activity.getPackageName(), clz.getName(), + requestCode, options); + } + + /** + * Start the activity. + * + * @param extras The Bundle of extras to add to this intent. + * @param activity The activity. + * @param clz The activity class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param sharedElements The names of the shared elements to transfer to the called + * Activity and their associated Views. + */ + public static void startActivityForResult(@NonNull final Bundle extras, + @NonNull final Activity activity, + @NonNull final Class clz, + final int requestCode, + final View... sharedElements) { + startActivityForResult(activity, extras, activity.getPackageName(), clz.getName(), + requestCode, getOptionsBundle(activity, sharedElements)); + } + + /** + * Start the activity. + * + * @param extras The Bundle of extras to add to this intent. + * @param activity The activity. + * @param clz The activity class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param enterAnim A resource ID of the animation resource to use for the + * incoming activity. + * @param exitAnim A resource ID of the animation resource to use for the + * outgoing activity. + */ + public static void startActivityForResult(@NonNull final Bundle extras, + @NonNull final Activity activity, + @NonNull final Class clz, + final int requestCode, + @AnimRes final int enterAnim, + @AnimRes final int exitAnim) { + startActivityForResult(activity, extras, activity.getPackageName(), clz.getName(), + requestCode, getOptionsBundle(activity, enterAnim, exitAnim)); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + activity.overridePendingTransition(enterAnim, exitAnim); + } + } + + /** + * Start the activity for result. + * + * @param activity The activity. + * @param extras The Bundle of extras to add to this intent. + * @param pkg The name of the package. + * @param cls The name of the class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + */ + public static void startActivityForResult(@NonNull final Bundle extras, + @NonNull final Activity activity, + @NonNull final String pkg, + @NonNull final String cls, + final int requestCode) { + startActivityForResult(activity, extras, pkg, cls, requestCode, null); + } + + /** + * Start the activity for result. + * + * @param extras The Bundle of extras to add to this intent. + * @param activity The activity. + * @param pkg The name of the package. + * @param cls The name of the class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param options Additional options for how the Activity should be started. + */ + public static void startActivityForResult(@NonNull final Bundle extras, + @NonNull final Activity activity, + @NonNull final String pkg, + @NonNull final String cls, + final int requestCode, + final Bundle options) { + startActivityForResult(activity, extras, pkg, cls, requestCode, options); + } + + /** + * Start the activity for result. + * + * @param extras The Bundle of extras to add to this intent. + * @param activity The activity. + * @param pkg The name of the package. + * @param cls The name of the class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param sharedElements The names of the shared elements to transfer to the called + * Activity and their associated Views. + */ + public static void startActivityForResult(@NonNull final Bundle extras, + @NonNull final Activity activity, + @NonNull final String pkg, + @NonNull final String cls, + final int requestCode, + final View... sharedElements) { + startActivityForResult(activity, extras, pkg, cls, + requestCode, getOptionsBundle(activity, sharedElements)); + } + + /** + * Start the activity for result. + * + * @param extras The Bundle of extras to add to this intent. + * @param pkg The name of the package. + * @param cls The name of the class. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param enterAnim A resource ID of the animation resource to use for the + * incoming activity. + * @param exitAnim A resource ID of the animation resource to use for the + * outgoing activity. + */ + public static void startActivityForResult(@NonNull final Bundle extras, + @NonNull final Activity activity, + @NonNull final String pkg, + @NonNull final String cls, + final int requestCode, + @AnimRes final int enterAnim, + @AnimRes final int exitAnim) { + startActivityForResult(activity, extras, pkg, cls, + requestCode, getOptionsBundle(activity, enterAnim, exitAnim)); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + activity.overridePendingTransition(enterAnim, exitAnim); + } + } + + /** + * Start the activity for result. + * + * @param activity The activity. + * @param intent The description of the activity to start. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + */ + public static void startActivityForResult(@NonNull final Activity activity, + @NonNull final Intent intent, + final int requestCode) { + startActivityForResult(intent, activity, requestCode, null); + } + + /** + * Start the activity for result. + * + * @param activity The activity. + * @param intent The description of the activity to start. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param options Additional options for how the Activity should be started. + */ + public static void startActivityForResult(@NonNull final Activity activity, + @NonNull final Intent intent, + final int requestCode, + final Bundle options) { + startActivityForResult(intent, activity, requestCode, options); + } + + /** + * Start the activity for result. + * + * @param activity The activity. + * @param intent The description of the activity to start. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param sharedElements The names of the shared elements to transfer to the called + * Activity and their associated Views. + */ + public static void startActivityForResult(@NonNull final Activity activity, + @NonNull final Intent intent, + final int requestCode, + final View... sharedElements) { + startActivityForResult(intent, activity, + requestCode, getOptionsBundle(activity, sharedElements)); + } + + /** + * Start the activity for result. + * + * @param activity The activity. + * @param intent The description of the activity to start. + * @param requestCode if >= 0, this code will be returned in + * onActivityResult() when the activity exits. + * @param enterAnim A resource ID of the animation resource to use for the + * incoming activity. + * @param exitAnim A resource ID of the animation resource to use for the + * outgoing activity. + */ + public static void startActivityForResult(@NonNull final Activity activity, + @NonNull final Intent intent, + final int requestCode, + @AnimRes final int enterAnim, + @AnimRes final int exitAnim) { + startActivityForResult(intent, activity, + requestCode, getOptionsBundle(activity, enterAnim, exitAnim)); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + activity.overridePendingTransition(enterAnim, exitAnim); + } + } + /** * Start activities. * @@ -1203,6 +1518,29 @@ public final class ActivityUtils { } } + private static void startActivityForResult(final Activity activity, + final Bundle extras, + final String pkg, + final String cls, + final int requestCode, + final Bundle options) { + Intent intent = new Intent(Intent.ACTION_VIEW); + if (extras != null) intent.putExtras(extras); + intent.setComponent(new ComponentName(pkg, cls)); + startActivityForResult(intent, activity, requestCode, options); + } + + private static void startActivityForResult(final Intent intent, + final Activity activity, + final int requestCode, + final Bundle options) { + if (options != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + activity.startActivityForResult(intent, requestCode, options); + } else { + activity.startActivityForResult(intent, requestCode); + } + } + private static void startActivities(final Intent[] intents, final Context context, final Bundle options) {