diff options
Diffstat (limited to 'android/support/v4/app')
19 files changed, 282 insertions, 102 deletions
diff --git a/android/support/v4/app/ActivityCompat.java b/android/support/v4/app/ActivityCompat.java index f260508c..5833481a 100644 --- a/android/support/v4/app/ActivityCompat.java +++ b/android/support/v4/app/ActivityCompat.java @@ -74,6 +74,61 @@ public class ActivityCompat extends ContextCompat { } /** + * Customizable delegate that allows delegating permission compatibility methods to a custom + * implementation. + * + * <p> + * To delegate permission compatibility methods to a custom class, implement this interface, + * and call {@code ActivityCompat.setPermissionCompatDelegate(delegate);}. All future calls + * to the permission compatibility methods in this class will first check whether the + * delegate can handle the method call, and invoke the corresponding method if it can. + * </p> + */ + public interface PermissionCompatDelegate { + + /** + * Determines whether the delegate should handle + * {@link ActivityCompat#requestPermissions(Activity, String[], int)}, and request + * permissions if applicable. If this method returns true, it means that permission + * request is successfully handled by the delegate, and platform should not perform any + * further requests for permission. + * + * @param activity The target activity. + * @param permissions The requested permissions. Must me non-null and not empty. + * @param requestCode Application specific request code to match with a result reported to + * {@link + * OnRequestPermissionsResultCallback#onRequestPermissionsResult(int, String[], int[])}. + * Should be >= 0. + * + * @return Whether the delegate has handled the permission request. + * @see ActivityCompat#requestPermissions(Activity, String[], int) + */ + boolean requestPermissions(@NonNull Activity activity, + @NonNull String[] permissions, @IntRange(from = 0) int requestCode); + + /** + * Determines whether the delegate should handle the permission request as part of + * {@code FragmentActivity#onActivityResult(int, int, Intent)}. If this method returns true, + * it means that activity result is successfully handled by the delegate, and no further + * action is needed on this activity result. + * + * @param activity The target Activity. + * @param requestCode The integer request code originally supplied to + * {@code startActivityForResult()}, allowing you to identify who this + * result came from. + * @param resultCode The integer result code returned by the child activity + * through its {@code }setResult()}. + * @param data An Intent, which can return result data to the caller + * (various data can be attached to Intent "extras"). + * + * @return Whether the delegate has handled the activity result. + * @see ActivityCompat#requestPermissions(Activity, String[], int) + */ + boolean onActivityResult(@NonNull Activity activity, + @IntRange(from = 0) int requestCode, int resultCode, @Nullable Intent data); + } + + /** * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @@ -81,6 +136,8 @@ public class ActivityCompat extends ContextCompat { void validateRequestPermissionsRequestCode(int requestCode); } + private static PermissionCompatDelegate sDelegate; + /** * This class should not be instantiated, but the constructor must be * visible for the class to be extended (as in support-v13). @@ -90,6 +147,25 @@ public class ActivityCompat extends ContextCompat { } /** + * Sets the permission delegate for {@code ActivityCompat}. Replaces the previously set + * delegate. + * + * @param delegate The delegate to be set. {@code null} to clear the set delegate. + */ + public static void setPermissionCompatDelegate( + @Nullable PermissionCompatDelegate delegate) { + sDelegate = delegate; + } + + /** + * @hide + */ + @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) + public static PermissionCompatDelegate getPermissionCompatDelegate() { + return sDelegate; + } + + /** * Invalidate the activity's options menu, if able. * * <p>Before API level 11 (Android 3.0/Honeycomb) the lifecycle of the @@ -120,7 +196,9 @@ public class ActivityCompat extends ContextCompat { * * @param activity Invalidate the options menu of this activity * @return true if this operation was supported and it completed; false if it was not available. + * @deprecated Use {@link Activity#invalidateOptionsMenu()} directly. */ + @Deprecated public static boolean invalidateOptionsMenu(Activity activity) { activity.invalidateOptionsMenu(); return true; @@ -146,8 +224,8 @@ public class ActivityCompat extends ContextCompat { * supplied here; there are no supported definitions for * building it manually. */ - public static void startActivityForResult(Activity activity, Intent intent, int requestCode, - @Nullable Bundle options) { + public static void startActivityForResult(@NonNull Activity activity, @NonNull Intent intent, + int requestCode, @Nullable Bundle options) { if (Build.VERSION.SDK_INT >= 16) { activity.startActivityForResult(intent, requestCode, options); } else { @@ -181,9 +259,10 @@ public class ActivityCompat extends ContextCompat { * supplied here; there are no supported definitions for * building it manually. */ - public static void startIntentSenderForResult(Activity activity, IntentSender intent, - int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, - int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException { + public static void startIntentSenderForResult(@NonNull Activity activity, + @NonNull IntentSender intent, int requestCode, @Nullable Intent fillInIntent, + int flagsMask, int flagsValues, int extraFlags, @Nullable Bundle options) + throws IntentSender.SendIntentException { if (Build.VERSION.SDK_INT >= 16) { activity.startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, flagsValues, extraFlags, options); @@ -200,7 +279,7 @@ public class ActivityCompat extends ContextCompat { * <p>On Android 4.1+ calling this method will call through to the native version of this * method. For other platforms {@link Activity#finish()} will be called instead.</p> */ - public static void finishAffinity(Activity activity) { + public static void finishAffinity(@NonNull Activity activity) { if (Build.VERSION.SDK_INT >= 16) { activity.finishAffinity(); } else { @@ -217,7 +296,7 @@ public class ActivityCompat extends ContextCompat { * <p>On Android 4.4 or lower, this method only finishes the Activity with no * special exit transition.</p> */ - public static void finishAfterTransition(Activity activity) { + public static void finishAfterTransition(@NonNull Activity activity) { if (Build.VERSION.SDK_INT >= 21) { activity.finishAfterTransition(); } else { @@ -242,7 +321,7 @@ public class ActivityCompat extends ContextCompat { * referrer information, applications can spoof it.</p> */ @Nullable - public static Uri getReferrer(Activity activity) { + public static Uri getReferrer(@NonNull Activity activity) { if (Build.VERSION.SDK_INT >= 22) { return activity.getReferrer(); } @@ -266,8 +345,8 @@ public class ActivityCompat extends ContextCompat { * * @param callback Used to manipulate shared element transitions on the launched Activity. */ - public static void setEnterSharedElementCallback(Activity activity, - SharedElementCallback callback) { + public static void setEnterSharedElementCallback(@NonNull Activity activity, + @Nullable SharedElementCallback callback) { if (Build.VERSION.SDK_INT >= 23) { android.app.SharedElementCallback frameworkCallback = callback != null ? new SharedElementCallback23Impl(callback) @@ -290,8 +369,8 @@ public class ActivityCompat extends ContextCompat { * * @param callback Used to manipulate shared element transitions on the launching Activity. */ - public static void setExitSharedElementCallback(Activity activity, - SharedElementCallback callback) { + public static void setExitSharedElementCallback(@NonNull Activity activity, + @Nullable SharedElementCallback callback) { if (Build.VERSION.SDK_INT >= 23) { android.app.SharedElementCallback frameworkCallback = callback != null ? new SharedElementCallback23Impl(callback) @@ -305,13 +384,13 @@ public class ActivityCompat extends ContextCompat { } } - public static void postponeEnterTransition(Activity activity) { + public static void postponeEnterTransition(@NonNull Activity activity) { if (Build.VERSION.SDK_INT >= 21) { activity.postponeEnterTransition(); } } - public static void startPostponedEnterTransition(Activity activity) { + public static void startPostponedEnterTransition(@NonNull Activity activity) { if (Build.VERSION.SDK_INT >= 21) { activity.startPostponedEnterTransition(); } @@ -386,6 +465,12 @@ public class ActivityCompat extends ContextCompat { */ public static void requestPermissions(final @NonNull Activity activity, final @NonNull String[] permissions, final @IntRange(from = 0) int requestCode) { + if (sDelegate != null + && sDelegate.requestPermissions(activity, permissions, requestCode)) { + // Delegate has handled the permission request. + return; + } + if (Build.VERSION.SDK_INT >= 23) { if (activity instanceof RequestPermissionsRequestCodeValidator) { ((RequestPermissionsRequestCodeValidator) activity) diff --git a/android/support/v4/app/ActivityOptionsCompat.java b/android/support/v4/app/ActivityOptionsCompat.java index 7b5916f5..66768058 100644 --- a/android/support/v4/app/ActivityOptionsCompat.java +++ b/android/support/v4/app/ActivityOptionsCompat.java @@ -24,6 +24,7 @@ import android.graphics.Bitmap; import android.graphics.Rect; import android.os.Build; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.RequiresApi; import android.support.v4.util.Pair; @@ -60,7 +61,8 @@ public class ActivityOptionsCompat { * @return Returns a new ActivityOptions object that you can use to supply * these options as the options Bundle when starting an activity. */ - public static ActivityOptionsCompat makeCustomAnimation(Context context, + @NonNull + public static ActivityOptionsCompat makeCustomAnimation(@NonNull Context context, int enterResId, int exitResId) { if (Build.VERSION.SDK_INT >= 16) { return createImpl(ActivityOptions.makeCustomAnimation(context, enterResId, exitResId)); @@ -88,7 +90,8 @@ public class ActivityOptionsCompat { * @return Returns a new ActivityOptions object that you can use to supply * these options as the options Bundle when starting an activity. */ - public static ActivityOptionsCompat makeScaleUpAnimation(View source, + @NonNull + public static ActivityOptionsCompat makeScaleUpAnimation(@NonNull View source, int startX, int startY, int startWidth, int startHeight) { if (Build.VERSION.SDK_INT >= 16) { return createImpl(ActivityOptions.makeScaleUpAnimation( @@ -111,7 +114,8 @@ public class ActivityOptionsCompat { * @return Returns a new ActivityOptions object that you can use to * supply these options as the options Bundle when starting an activity. */ - public static ActivityOptionsCompat makeClipRevealAnimation(View source, + @NonNull + public static ActivityOptionsCompat makeClipRevealAnimation(@NonNull View source, int startX, int startY, int width, int height) { if (Build.VERSION.SDK_INT >= 23) { return createImpl(ActivityOptions.makeClipRevealAnimation( @@ -139,8 +143,9 @@ public class ActivityOptionsCompat { * @return Returns a new ActivityOptions object that you can use to supply * these options as the options Bundle when starting an activity. */ - public static ActivityOptionsCompat makeThumbnailScaleUpAnimation(View source, - Bitmap thumbnail, int startX, int startY) { + @NonNull + public static ActivityOptionsCompat makeThumbnailScaleUpAnimation(@NonNull View source, + @NonNull Bitmap thumbnail, int startX, int startY) { if (Build.VERSION.SDK_INT >= 16) { return createImpl(ActivityOptions.makeThumbnailScaleUpAnimation( source, thumbnail, startX, startY)); @@ -166,8 +171,9 @@ public class ActivityOptionsCompat { * @return Returns a new ActivityOptions object that you can use to * supply these options as the options Bundle when starting an activity. */ - public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity, - View sharedElement, String sharedElementName) { + @NonNull + public static ActivityOptionsCompat makeSceneTransitionAnimation(@NonNull Activity activity, + @NonNull View sharedElement, @NonNull String sharedElementName) { if (Build.VERSION.SDK_INT >= 21) { return createImpl(ActivityOptions.makeSceneTransitionAnimation( activity, sharedElement, sharedElementName)); @@ -192,8 +198,9 @@ public class ActivityOptionsCompat { * @return Returns a new ActivityOptions object that you can use to * supply these options as the options Bundle when starting an activity. */ + @NonNull @SuppressWarnings("unchecked") - public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity, + public static ActivityOptionsCompat makeSceneTransitionAnimation(@NonNull Activity activity, Pair<View, String>... sharedElements) { if (Build.VERSION.SDK_INT >= 21) { android.util.Pair<View, String>[] pairs = null; @@ -219,6 +226,7 @@ public class ActivityOptionsCompat { * {@link android.R.attr#launchMode launchMode} values of * <code>singleInstance</code> or <code>singleTask</code>. */ + @NonNull public static ActivityOptionsCompat makeTaskLaunchBehind() { if (Build.VERSION.SDK_INT >= 21) { return createImpl(ActivityOptions.makeTaskLaunchBehind()); @@ -230,6 +238,7 @@ public class ActivityOptionsCompat { * Create a basic ActivityOptions that has no special animation associated with it. * Other options can still be set. */ + @NonNull public static ActivityOptionsCompat makeBasic() { if (Build.VERSION.SDK_INT >= 23) { return createImpl(ActivityOptions.makeBasic()); @@ -314,8 +323,9 @@ public class ActivityOptionsCompat { * {@link android.content.pm.PackageManager#FEATURE_PICTURE_IN_PICTURE} enabled. * @param screenSpacePixelRect Launch bounds to use for the activity or null for fullscreen. */ + @NonNull public ActivityOptionsCompat setLaunchBounds(@Nullable Rect screenSpacePixelRect) { - return null; + return this; } /** @@ -335,6 +345,7 @@ public class ActivityOptionsCompat { * object; you must not modify it, but can supply it to the startActivity * methods that take an options Bundle. */ + @Nullable public Bundle toBundle() { return null; } @@ -344,7 +355,7 @@ public class ActivityOptionsCompat { * otherOptions. Any values defined in otherOptions replace those in the * base options. */ - public void update(ActivityOptionsCompat otherOptions) { + public void update(@NonNull ActivityOptionsCompat otherOptions) { // Do nothing. } @@ -372,7 +383,7 @@ public class ActivityOptionsCompat { * * @param receiver A broadcast receiver that will receive the report. */ - public void requestUsageTimeReport(PendingIntent receiver) { + public void requestUsageTimeReport(@NonNull PendingIntent receiver) { // Do nothing. } } diff --git a/android/support/v4/app/AlarmManagerCompat.java b/android/support/v4/app/AlarmManagerCompat.java index 5a4582ba..a297cb5a 100644 --- a/android/support/v4/app/AlarmManagerCompat.java +++ b/android/support/v4/app/AlarmManagerCompat.java @@ -19,6 +19,7 @@ package android.support.v4.app; import android.app.AlarmManager; import android.app.PendingIntent; import android.os.Build; +import android.support.annotation.NonNull; /** * Compatibility library for {@link AlarmManager} with fallbacks for older platforms. @@ -52,8 +53,8 @@ public final class AlarmManagerCompat { * @see android.content.Context#registerReceiver * @see android.content.Intent#filterEquals */ - public static void setAlarmClock(AlarmManager alarmManager, long triggerTime, - PendingIntent showIntent, PendingIntent operation) { + public static void setAlarmClock(@NonNull AlarmManager alarmManager, long triggerTime, + @NonNull PendingIntent showIntent, @NonNull PendingIntent operation) { if (Build.VERSION.SDK_INT >= 21) { alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(triggerTime, showIntent), operation); @@ -110,8 +111,8 @@ public final class AlarmManagerCompat { * @see AlarmManager#RTC * @see AlarmManager#RTC_WAKEUP */ - public static void setAndAllowWhileIdle(AlarmManager alarmManager, int type, - long triggerAtMillis, PendingIntent operation) { + public static void setAndAllowWhileIdle(@NonNull AlarmManager alarmManager, int type, + long triggerAtMillis, @NonNull PendingIntent operation) { if (Build.VERSION.SDK_INT >= 23) { alarmManager.setAndAllowWhileIdle(type, triggerAtMillis, operation); } else { @@ -155,8 +156,8 @@ public final class AlarmManagerCompat { * @see AlarmManager#RTC * @see AlarmManager#RTC_WAKEUP */ - public static void setExact(AlarmManager alarmManager, int type, long triggerAtMillis, - PendingIntent operation) { + public static void setExact(@NonNull AlarmManager alarmManager, int type, long triggerAtMillis, + @NonNull PendingIntent operation) { if (Build.VERSION.SDK_INT >= 19) { alarmManager.setExact(type, triggerAtMillis, operation); } else { @@ -215,8 +216,8 @@ public final class AlarmManagerCompat { * @see AlarmManager#RTC * @see AlarmManager#RTC_WAKEUP */ - public static void setExactAndAllowWhileIdle(AlarmManager alarmManager, int type, - long triggerAtMillis, PendingIntent operation) { + public static void setExactAndAllowWhileIdle(@NonNull AlarmManager alarmManager, int type, + long triggerAtMillis, @NonNull PendingIntent operation) { if (Build.VERSION.SDK_INT >= 23) { alarmManager.setExactAndAllowWhileIdle(type, triggerAtMillis, operation); } else { diff --git a/android/support/v4/app/AppLaunchChecker.java b/android/support/v4/app/AppLaunchChecker.java index f8beb91c..af9512ad 100644 --- a/android/support/v4/app/AppLaunchChecker.java +++ b/android/support/v4/app/AppLaunchChecker.java @@ -22,8 +22,8 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.content.IntentCompat; -import android.support.v4.content.SharedPreferencesCompat; /** * This class provides APIs for determining how an app has been launched. @@ -46,7 +46,7 @@ public class AppLaunchChecker { * @param context Context to check * @return true if this app has been started by the user from the launcher at least once */ - public static boolean hasStartedFromLauncher(Context context) { + public static boolean hasStartedFromLauncher(@NonNull Context context) { return context.getSharedPreferences(SHARED_PREFS_NAME, 0) .getBoolean(KEY_STARTED_FROM_LAUNCHER, false); } @@ -62,7 +62,7 @@ public class AppLaunchChecker { * * @param activity the Activity currently running onCreate */ - public static void onActivityCreate(Activity activity) { + public static void onActivityCreate(@NonNull Activity activity) { final SharedPreferences sp = activity.getSharedPreferences(SHARED_PREFS_NAME, 0); if (sp.getBoolean(KEY_STARTED_FROM_LAUNCHER, false)) { return; @@ -76,8 +76,7 @@ public class AppLaunchChecker { if (Intent.ACTION_MAIN.equals(launchIntent.getAction()) && (launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER) || launchIntent.hasCategory(IntentCompat.CATEGORY_LEANBACK_LAUNCHER))) { - SharedPreferencesCompat.EditorCompat.getInstance().apply( - sp.edit().putBoolean(KEY_STARTED_FROM_LAUNCHER, true)); + sp.edit().putBoolean(KEY_STARTED_FROM_LAUNCHER, true).apply(); } } } diff --git a/android/support/v4/app/AppOpsManagerCompat.java b/android/support/v4/app/AppOpsManagerCompat.java index ce2d2c6b..7e97199a 100644 --- a/android/support/v4/app/AppOpsManagerCompat.java +++ b/android/support/v4/app/AppOpsManagerCompat.java @@ -21,6 +21,7 @@ import static android.os.Build.VERSION.SDK_INT; import android.app.AppOpsManager; import android.content.Context; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; /** * Helper for accessing features in {@link android.app.AppOpsManager}. @@ -56,6 +57,7 @@ public final class AppOpsManagerCompat { * @param permission The permission. * @return The app op associated with the permission or null. */ + @Nullable public static String permissionToOp(@NonNull String permission) { if (SDK_INT >= 23) { return AppOpsManager.permissionToOp(permission); diff --git a/android/support/v4/app/BundleCompat.java b/android/support/v4/app/BundleCompat.java index e5fc3027..21d730d8 100644 --- a/android/support/v4/app/BundleCompat.java +++ b/android/support/v4/app/BundleCompat.java @@ -19,6 +19,8 @@ package android.support.v4.app; import android.os.Build; import android.os.Bundle; import android.os.IBinder; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.Log; import java.lang.reflect.InvocationTargetException; @@ -94,7 +96,8 @@ public final class BundleCompat { * @param key The key to use while getting the {@link IBinder}. * @return The {@link IBinder} that was obtained. */ - public static IBinder getBinder(Bundle bundle, String key) { + @Nullable + public static IBinder getBinder(@NonNull Bundle bundle, @Nullable String key) { if (Build.VERSION.SDK_INT >= 18) { return bundle.getBinder(key); } else { @@ -109,7 +112,8 @@ public final class BundleCompat { * @param key The key to use while putting the {@link IBinder}. * @param binder The {@link IBinder} to put. */ - public static void putBinder(Bundle bundle, String key, IBinder binder) { + public static void putBinder(@NonNull Bundle bundle, @Nullable String key, + @Nullable IBinder binder) { if (Build.VERSION.SDK_INT >= 18) { bundle.putBinder(key, binder); } else { diff --git a/android/support/v4/app/Fragment.java b/android/support/v4/app/Fragment.java index ba74521d..e734a274 100644 --- a/android/support/v4/app/Fragment.java +++ b/android/support/v4/app/Fragment.java @@ -463,6 +463,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener /** * Get the tag name of the fragment, if specified. */ + @Nullable final public String getTag() { return mTag; } @@ -474,7 +475,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * <p>This method cannot be called if the fragment is added to a FragmentManager and * if {@link #isStateSaved()} would return true.</p> */ - public void setArguments(Bundle args) { + public void setArguments(@Nullable Bundle args) { if (mIndex >= 0 && isStateSaved()) { throw new IllegalStateException("Fragment already active and state has been saved"); } @@ -485,6 +486,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * Return the arguments supplied when the fragment was instantiated, * if any. */ + @Nullable final public Bundle getArguments() { return mArguments; } @@ -512,7 +514,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * * @param state The state the fragment should be restored from. */ - public void setInitialSavedState(SavedState state) { + public void setInitialSavedState(@Nullable SavedState state) { if (mIndex >= 0) { throw new IllegalStateException("Fragment already active"); } @@ -532,7 +534,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * are going to call back with {@link #onActivityResult(int, int, Intent)}. */ @SuppressWarnings("ReferenceEquality") - public void setTargetFragment(Fragment fragment, int requestCode) { + public void setTargetFragment(@Nullable Fragment fragment, int requestCode) { // Don't allow a caller to set a target fragment in another FragmentManager, // but there's a snag: people do set target fragments before fragments get added. // We'll have the FragmentManager check that for validity when we move @@ -558,6 +560,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener /** * Return the target fragment set by {@link #setTargetFragment}. */ + @Nullable final public Fragment getTargetFragment() { return mTarget; } @@ -572,6 +575,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener /** * Return the {@link Context} this fragment is currently associated with. */ + @Nullable public Context getContext() { return mHost == null ? null : mHost.getContext(); } @@ -581,6 +585,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * May return {@code null} if the fragment is associated with a {@link Context} * instead. */ + @Nullable final public FragmentActivity getActivity() { return mHost == null ? null : (FragmentActivity) mHost.getActivity(); } @@ -589,6 +594,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * Return the host object of this fragment. May return {@code null} if the fragment * isn't currently being hosted. */ + @Nullable final public Object getHost() { return mHost == null ? null : mHost.onGetHost(); } @@ -596,6 +602,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener /** * Return <code>getActivity().getResources()</code>. */ + @NonNull final public Resources getResources() { if (mHost == null) { throw new IllegalStateException("Fragment " + this + " not attached to Activity"); @@ -609,6 +616,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * * @param resId Resource id for the CharSequence text */ + @NonNull public final CharSequence getText(@StringRes int resId) { return getResources().getText(resId); } @@ -619,6 +627,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * * @param resId Resource id for the string */ + @NonNull public final String getString(@StringRes int resId) { return getResources().getString(resId); } @@ -631,7 +640,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * @param resId Resource id for the format string * @param formatArgs The format arguments that will be used for substitution. */ - + @NonNull public final String getString(@StringRes int resId, Object... formatArgs) { return getResources().getString(resId, formatArgs); } @@ -646,6 +655,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * <p>If this Fragment is a child of another Fragment, the FragmentManager * returned here will be the parent's {@link #getChildFragmentManager()}. */ + @Nullable final public FragmentManager getFragmentManager() { return mFragmentManager; } @@ -654,6 +664,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * Return a private FragmentManager for placing and managing Fragments * inside of this Fragment. */ + @NonNull final public FragmentManager getChildFragmentManager() { if (mChildFragmentManager == null) { instantiateChildFragmentManager(); @@ -674,6 +685,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * Return this fragment's child FragmentManager one has been previously created, * otherwise null. */ + @Nullable FragmentManager peekChildFragmentManager() { return mChildFragmentManager; } @@ -682,6 +694,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * Returns the parent Fragment containing this Fragment. If this Fragment * is attached directly to an Activity, returns null. */ + @Nullable final public Fragment getParentFragment() { return mParentFragment; } @@ -1082,7 +1095,8 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * a previous saved state, this is the state. * @return The LayoutInflater used to inflate Views of this Fragment. */ - public LayoutInflater onGetLayoutInflater(Bundle savedInstanceState) { + @NonNull + public LayoutInflater onGetLayoutInflater(@Nullable Bundle savedInstanceState) { // TODO: move the implementation in getLayoutInflater to here return getLayoutInflater(savedInstanceState); } @@ -1113,7 +1127,8 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * a previous saved state, this is the state. * @return The LayoutInflater used to inflate Views of this Fragment. */ - LayoutInflater performGetLayoutInflater(Bundle savedInstanceState) { + @NonNull + LayoutInflater performGetLayoutInflater(@Nullable Bundle savedInstanceState) { LayoutInflater layoutInflater = onGetLayoutInflater(savedInstanceState); mLayoutInflater = layoutInflater; return mLayoutInflater; @@ -1129,8 +1144,9 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * {@link #getLayoutInflater()} instead of this method. */ @Deprecated + @NonNull @RestrictTo(LIBRARY_GROUP) - public LayoutInflater getLayoutInflater(Bundle savedFragmentState) { + public LayoutInflater getLayoutInflater(@Nullable Bundle savedFragmentState) { if (mHost == null) { throw new IllegalStateException("onGetLayoutInflater() cannot be executed until the " + "Fragment is attached to the FragmentManager."); @@ -1157,24 +1173,24 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * <p>Here is a typical implementation of a fragment that can take parameters * both through attributes supplied here as well from {@link #getArguments()}:</p> * - * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java + * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentArgumentsSupport.java * fragment} * * <p>Note that parsing the XML attributes uses a "styleable" resource. The * declaration for the styleable used here is:</p> * - * {@sample frameworks/support/samples/Support4Demos/res/values/attrs.xml fragment_arguments} + * {@sample frameworks/support/samples/Support4Demos/src/main/res/values/attrs.xml fragment_arguments} * * <p>The fragment can then be declared within its activity's content layout * through a tag like this:</p> * - * {@sample frameworks/support/samples/Support4Demos/res/layout/fragment_arguments_support.xml from_attributes} + * {@sample frameworks/support/samples/Support4Demos/src/main/res/layout/fragment_arguments_support.xml from_attributes} * * <p>This fragment can also be created dynamically from arguments given * at runtime in the arguments Bundle; here is an example of doing so at * creation of the containing activity:</p> * - * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentArgumentsSupport.java + * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentArgumentsSupport.java * create} * * @param context The Activity that is inflating this fragment. @@ -1356,7 +1372,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * @return Return the View for the fragment's UI, or null. */ @Nullable - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return null; } @@ -1371,7 +1387,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * @param savedInstanceState If non-null, this fragment is being re-constructed * from a previous saved state as given here. */ - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { } /** @@ -1469,7 +1485,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * * @param outState Bundle in which to place your saved state. */ - public void onSaveInstanceState(Bundle outState) { + public void onSaveInstanceState(@NonNull Bundle outState) { } /** @@ -1768,7 +1784,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * * @param transition The Transition to use to move Views into the initial Scene. */ - public void setEnterTransition(Object transition) { + public void setEnterTransition(@Nullable Object transition) { ensureAnimationInfo().mEnterTransition = transition; } @@ -1781,6 +1797,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * * @return the Transition to use to move Views into the initial Scene. */ + @Nullable public Object getEnterTransition() { if (mAnimationInfo == null) { return null; @@ -1802,7 +1819,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * is preparing to close. <code>transition</code> must be an * android.transition.Transition. */ - public void setReturnTransition(Object transition) { + public void setReturnTransition(@Nullable Object transition) { ensureAnimationInfo().mReturnTransition = transition; } @@ -1818,6 +1835,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * @return the Transition to use to move Views out of the Scene when the Fragment * is preparing to close. */ + @Nullable public Object getReturnTransition() { if (mAnimationInfo == null) { return null; @@ -1839,7 +1857,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * is being closed not due to popping the back stack. <code>transition</code> * must be an android.transition.Transition. */ - public void setExitTransition(Object transition) { + public void setExitTransition(@Nullable Object transition) { ensureAnimationInfo().mExitTransition = transition; } @@ -1855,6 +1873,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * @return the Transition to use to move Views out of the Scene when the Fragment * is being closed not due to popping the back stack. */ + @Nullable public Object getExitTransition() { if (mAnimationInfo == null) { return null; @@ -1875,7 +1894,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * previously-started Activity. <code>transition</code> * must be an android.transition.Transition. */ - public void setReenterTransition(Object transition) { + public void setReenterTransition(@Nullable Object transition) { ensureAnimationInfo().mReenterTransition = transition; } @@ -1908,7 +1927,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * @param transition The Transition to use for shared elements transferred into the content * Scene. <code>transition</code> must be an android.transition.Transition. */ - public void setSharedElementEnterTransition(Object transition) { + public void setSharedElementEnterTransition(@Nullable Object transition) { ensureAnimationInfo().mSharedElementEnterTransition = transition; } @@ -1921,6 +1940,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * @return The Transition to use for shared elements transferred into the content * Scene. */ + @Nullable public Object getSharedElementEnterTransition() { if (mAnimationInfo == null) { return null; @@ -1940,7 +1960,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * @param transition The Transition to use for shared elements transferred out of the content * Scene. <code>transition</code> must be an android.transition.Transition. */ - public void setSharedElementReturnTransition(Object transition) { + public void setSharedElementReturnTransition(@Nullable Object transition) { ensureAnimationInfo().mSharedElementReturnTransition = transition; } @@ -1956,6 +1976,7 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener * @return The Transition to use for shared elements transferred out of the content * Scene. */ + @Nullable public Object getSharedElementReturnTransition() { if (mAnimationInfo == null) { return null; @@ -2231,8 +2252,8 @@ public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener mLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE); } - View performCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + View performCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { if (mChildFragmentManager != null) { mChildFragmentManager.noteStateNotSaved(); } diff --git a/android/support/v4/app/FragmentActivity.java b/android/support/v4/app/FragmentActivity.java index 481f50d3..cb3c59a6 100644 --- a/android/support/v4/app/FragmentActivity.java +++ b/android/support/v4/app/FragmentActivity.java @@ -153,6 +153,13 @@ public class FragmentActivity extends BaseFragmentActivityApi16 implements return; } + ActivityCompat.PermissionCompatDelegate delegate = + ActivityCompat.getPermissionCompatDelegate(); + if (delegate != null && delegate.onActivityResult(this, requestCode, resultCode, data)) { + // Delegate has handled the activity result + return; + } + super.onActivityResult(requestCode, resultCode, data); } @@ -270,6 +277,16 @@ public class FragmentActivity extends BaseFragmentActivityApi16 implements } /** + * Returns the Lifecycle of the provider. + * + * @return The lifecycle of the provider. + */ + @Override + public Lifecycle getLifecycle() { + return super.getLifecycle(); + } + + /** * Perform initialization of all fragments and loaders. */ @SuppressWarnings("deprecation") @@ -750,6 +767,7 @@ public class FragmentActivity extends BaseFragmentActivityApi16 implements @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + mFragments.noteStateNotSaved(); int index = (requestCode >> 16) & 0xffff; if (index != 0) { index--; diff --git a/android/support/v4/app/FragmentHostCallback.java b/android/support/v4/app/FragmentHostCallback.java index 7dc9f595..eeae62a5 100644 --- a/android/support/v4/app/FragmentHostCallback.java +++ b/android/support/v4/app/FragmentHostCallback.java @@ -94,8 +94,9 @@ public abstract class FragmentHostCallback<E> extends FragmentContainer { * Return a {@link LayoutInflater}. * See {@link Activity#getLayoutInflater()}. */ + @NonNull public LayoutInflater onGetLayoutInflater() { - return (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + return LayoutInflater.from(mContext); } /** diff --git a/android/support/v4/app/FragmentManager.java b/android/support/v4/app/FragmentManager.java index 6e6caa04..16103f8c 100644 --- a/android/support/v4/app/FragmentManager.java +++ b/android/support/v4/app/FragmentManager.java @@ -1605,12 +1605,21 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate @Override public void onAnimationEnd(Animation animation) { super.onAnimationEnd(animation); - container.endViewTransition(viewToAnimate); - - if (fragment.getAnimatingAway() != null) { - fragment.setAnimatingAway(null); - moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0, false); - } + // onAnimationEnd() comes during draw(), so there can still be some + // draw events happening after this call. We don't want to detach + // the view until after the onAnimationEnd() + container.post(new Runnable() { + @Override + public void run() { + container.endViewTransition(viewToAnimate); + + if (fragment.getAnimatingAway() != null) { + fragment.setAnimatingAway(null); + moveToState(fragment, fragment.getStateAfterAnimating(), 0, 0, + false); + } + } + }); } }); setHWLayerAnimListenerIfAlpha(viewToAnimate, anim); diff --git a/android/support/v4/app/FragmentPagerAdapter.java b/android/support/v4/app/FragmentPagerAdapter.java index 61b181df..6b25d2f7 100644 --- a/android/support/v4/app/FragmentPagerAdapter.java +++ b/android/support/v4/app/FragmentPagerAdapter.java @@ -44,18 +44,18 @@ import android.view.ViewGroup; * <p>Here is an example implementation of a pager containing fragments of * lists: * - * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentPagerSupport.java + * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentPagerSupport.java * complete} * * <p>The <code>R.layout.fragment_pager</code> resource of the top-level fragment is: * - * {@sample frameworks/support/samples/Support4Demos/res/layout/fragment_pager.xml + * {@sample frameworks/support/samples/Support4Demos/src/main/res/layout/fragment_pager.xml * complete} * * <p>The <code>R.layout.fragment_pager_list</code> resource containing each * individual fragment's layout is: * - * {@sample frameworks/support/samples/Support4Demos/res/layout/fragment_pager_list.xml + * {@sample frameworks/support/samples/Support4Demos/src/main/res/layout/fragment_pager_list.xml * complete} */ public abstract class FragmentPagerAdapter extends PagerAdapter { diff --git a/android/support/v4/app/FragmentStatePagerAdapter.java b/android/support/v4/app/FragmentStatePagerAdapter.java index fc27c4fc..040f2db2 100644 --- a/android/support/v4/app/FragmentStatePagerAdapter.java +++ b/android/support/v4/app/FragmentStatePagerAdapter.java @@ -47,18 +47,18 @@ import java.util.ArrayList; * <p>Here is an example implementation of a pager containing fragments of * lists: * - * {@sample frameworks/support/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentStatePagerSupport.java + * {@sample frameworks/support/samples/Support13Demos/src/main/java/com/example/android/supportv13/app/FragmentStatePagerSupport.java * complete} * * <p>The <code>R.layout.fragment_pager</code> resource of the top-level fragment is: * - * {@sample frameworks/support/samples/Support13Demos/res/layout/fragment_pager.xml + * {@sample frameworks/support/samples/Support13Demos/src/main/res/layout/fragment_pager.xml * complete} * * <p>The <code>R.layout.fragment_pager_list</code> resource containing each * individual fragment's layout is: * - * {@sample frameworks/support/samples/Support13Demos/res/layout/fragment_pager_list.xml + * {@sample frameworks/support/samples/Support13Demos/src/main/res/layout/fragment_pager_list.xml * complete} */ public abstract class FragmentStatePagerAdapter extends PagerAdapter { diff --git a/android/support/v4/app/FragmentTabHost.java b/android/support/v4/app/FragmentTabHost.java index 09b89b7f..6b914fef 100644 --- a/android/support/v4/app/FragmentTabHost.java +++ b/android/support/v4/app/FragmentTabHost.java @@ -41,12 +41,12 @@ import java.util.ArrayList; * * <p>Here is a simple example of using a FragmentTabHost in an Activity: * - * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.java + * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentTabs.java * complete} * * <p>This can also be used inside of a fragment through fragment nesting: * - * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsFragmentSupport.java + * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/FragmentTabsFragmentSupport.java * complete} */ public class FragmentTabHost extends TabHost diff --git a/android/support/v4/app/JobIntentService.java b/android/support/v4/app/JobIntentService.java index c0d7f13e..87b7441e 100644 --- a/android/support/v4/app/JobIntentService.java +++ b/android/support/v4/app/JobIntentService.java @@ -84,7 +84,7 @@ import java.util.HashMap; * * <p>Here is an example implementation of this class:</p> * - * {@sample frameworks/support/samples/Support4Demos/src/com/example/android/supportv4/app/SimpleJobIntentService.java + * {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/SimpleJobIntentService.java * complete} */ public abstract class JobIntentService extends Service { diff --git a/android/support/v4/app/ListFragment.java b/android/support/v4/app/ListFragment.java index 21617ad0..496bd8e1 100644 --- a/android/support/v4/app/ListFragment.java +++ b/android/support/v4/app/ListFragment.java @@ -19,6 +19,8 @@ package android.support.v4.app; import android.content.Context; import android.os.Bundle; import android.os.Handler; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; @@ -142,7 +144,7 @@ public class ListFragment extends Fragment { * Attach to list view once the view hierarchy has been created. */ @Override - public void onViewCreated(View view, Bundle savedInstanceState) { + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ensureList(); } diff --git a/android/support/v4/app/NavUtils.java b/android/support/v4/app/NavUtils.java index 99d44939..d2594178 100644 --- a/android/support/v4/app/NavUtils.java +++ b/android/support/v4/app/NavUtils.java @@ -24,6 +24,7 @@ import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Build; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; @@ -53,7 +54,8 @@ public final class NavUtils { * @return true if navigating up should recreate a new task stack, false if the same task * should be used for the destination */ - public static boolean shouldUpRecreateTask(Activity sourceActivity, Intent targetIntent) { + public static boolean shouldUpRecreateTask(@NonNull Activity sourceActivity, + @NonNull Intent targetIntent) { if (Build.VERSION.SDK_INT >= 16) { return sourceActivity.shouldUpRecreateTask(targetIntent); } else { @@ -74,7 +76,7 @@ public final class NavUtils { * * @param sourceActivity The current activity from which the user is attempting to navigate up */ - public static void navigateUpFromSameTask(Activity sourceActivity) { + public static void navigateUpFromSameTask(@NonNull Activity sourceActivity) { Intent upIntent = getParentActivityIntent(sourceActivity); if (upIntent == null) { @@ -101,7 +103,7 @@ public final class NavUtils { * @param sourceActivity The current activity from which the user is attempting to navigate up * @param upIntent An intent representing the target destination for up navigation */ - public static void navigateUpTo(Activity sourceActivity, Intent upIntent) { + public static void navigateUpTo(@NonNull Activity sourceActivity, @NonNull Intent upIntent) { if (Build.VERSION.SDK_INT >= 16) { sourceActivity.navigateUpTo(upIntent); } else { @@ -121,7 +123,8 @@ public final class NavUtils { * @param sourceActivity Activity to fetch a parent intent for * @return a new Intent targeting the defined parent activity of sourceActivity */ - public static Intent getParentActivityIntent(Activity sourceActivity) { + @Nullable + public static Intent getParentActivityIntent(@NonNull Activity sourceActivity) { if (Build.VERSION.SDK_INT >= 16) { // Prefer the "real" JB definition if available, // else fall back to the meta-data element. @@ -157,7 +160,9 @@ public final class NavUtils { * @return a new Intent targeting the defined parent activity of sourceActivity * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid */ - public static Intent getParentActivityIntent(Context context, Class<?> sourceActivityClass) + @Nullable + public static Intent getParentActivityIntent(@NonNull Context context, + @NonNull Class<?> sourceActivityClass) throws NameNotFoundException { String parentActivity = getParentActivityName(context, new ComponentName(context, sourceActivityClass)); @@ -182,7 +187,9 @@ public final class NavUtils { * @return a new Intent targeting the defined parent activity of sourceActivity * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid */ - public static Intent getParentActivityIntent(Context context, ComponentName componentName) + @Nullable + public static Intent getParentActivityIntent(@NonNull Context context, + @NonNull ComponentName componentName) throws NameNotFoundException { String parentActivity = getParentActivityName(context, componentName); if (parentActivity == null) return null; @@ -207,7 +214,7 @@ public final class NavUtils { * it was not specified */ @Nullable - public static String getParentActivityName(Activity sourceActivity) { + public static String getParentActivityName(@NonNull Activity sourceActivity) { try { return getParentActivityName(sourceActivity, sourceActivity.getComponentName()); } catch (NameNotFoundException e) { @@ -226,7 +233,8 @@ public final class NavUtils { * it was not specified */ @Nullable - public static String getParentActivityName(Context context, ComponentName componentName) + public static String getParentActivityName(@NonNull Context context, + @NonNull ComponentName componentName) throws NameNotFoundException { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(componentName, PackageManager.GET_META_DATA); diff --git a/android/support/v4/app/NotificationManagerCompat.java b/android/support/v4/app/NotificationManagerCompat.java index 93775eca..1a0f1bca 100644 --- a/android/support/v4/app/NotificationManagerCompat.java +++ b/android/support/v4/app/NotificationManagerCompat.java @@ -36,6 +36,8 @@ import android.os.Message; import android.os.RemoteException; import android.provider.Settings; import android.support.annotation.GuardedBy; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.Log; import java.lang.reflect.Field; @@ -144,7 +146,8 @@ public final class NotificationManagerCompat { public static final int IMPORTANCE_MAX = 5; /** Get a {@link NotificationManagerCompat} instance for a provided context. */ - public static NotificationManagerCompat from(Context context) { + @NonNull + public static NotificationManagerCompat from(@NonNull Context context) { return new NotificationManagerCompat(context); } @@ -167,7 +170,7 @@ public final class NotificationManagerCompat { * @param tag the string identifier of the notification. * @param id the ID of the notification */ - public void cancel(String tag, int id) { + public void cancel(@Nullable String tag, int id) { mNotificationManager.cancel(tag, id); if (Build.VERSION.SDK_INT <= MAX_SIDE_CHANNEL_SDK_VERSION) { pushSideChannelQueue(new CancelTask(mContext.getPackageName(), id, tag)); @@ -197,7 +200,7 @@ public final class NotificationManagerCompat { * @param id the ID of the notification. The pair (tag, id) must be unique within your app. * @param notification the notification to post to the system */ - public void notify(String tag, int id, Notification notification) { + public void notify(@Nullable String tag, int id, @NonNull Notification notification) { if (useSideChannelForNotification(notification)) { pushSideChannelQueue(new NotifyTask(mContext.getPackageName(), id, tag, notification)); // Cancel this notification in notification manager if it just transitioned to being @@ -253,7 +256,8 @@ public final class NotificationManagerCompat { /** * Get the set of packages that have an enabled notification listener component within them. */ - public static Set<String> getEnabledListenerPackages(Context context) { + @NonNull + public static Set<String> getEnabledListenerPackages(@NonNull Context context) { final String enabledNotificationListeners = Settings.Secure.getString( context.getContentResolver(), SETTING_ENABLED_NOTIFICATION_LISTENERS); diff --git a/android/support/v4/app/ServiceCompat.java b/android/support/v4/app/ServiceCompat.java index 1676ee8a..2e63b237 100644 --- a/android/support/v4/app/ServiceCompat.java +++ b/android/support/v4/app/ServiceCompat.java @@ -22,6 +22,7 @@ import android.app.Notification; import android.app.Service; import android.os.Build; import android.support.annotation.IntDef; +import android.support.annotation.NonNull; import android.support.annotation.RestrictTo; import java.lang.annotation.Retention; @@ -92,7 +93,7 @@ public final class ServiceCompat { * {@link #STOP_FOREGROUND_DETACH}. * @see Service#startForeground(int, Notification) */ - public static void stopForeground(Service service, @StopForegroundFlags int flags) { + public static void stopForeground(@NonNull Service service, @StopForegroundFlags int flags) { if (Build.VERSION.SDK_INT >= 24) { service.stopForeground(flags); } else { diff --git a/android/support/v4/app/TaskStackBuilder.java b/android/support/v4/app/TaskStackBuilder.java index dc9a2dc0..14aadce2 100644 --- a/android/support/v4/app/TaskStackBuilder.java +++ b/android/support/v4/app/TaskStackBuilder.java @@ -16,7 +16,6 @@ package android.support.v4.app; -import android.support.annotation.RequiresApi; import android.app.Activity; import android.app.PendingIntent; import android.content.ComponentName; @@ -25,6 +24,9 @@ import android.content.Intent; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Build; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.RequiresApi; import android.support.v4.content.ContextCompat; import android.util.Log; @@ -70,6 +72,7 @@ public final class TaskStackBuilder implements Iterable<Intent> { private static final String TAG = "TaskStackBuilder"; public interface SupportParentable { + @Nullable Intent getSupportParentActivityIntent(); } @@ -117,7 +120,8 @@ public final class TaskStackBuilder implements Iterable<Intent> { * @param context The context that will launch the new task stack or generate a PendingIntent * @return A new TaskStackBuilder */ - public static TaskStackBuilder create(Context context) { + @NonNull + public static TaskStackBuilder create(@NonNull Context context) { return new TaskStackBuilder(context); } @@ -142,7 +146,8 @@ public final class TaskStackBuilder implements Iterable<Intent> { * @param nextIntent Intent for the next Activity in the synthesized task stack * @return This TaskStackBuilder for method chaining */ - public TaskStackBuilder addNextIntent(Intent nextIntent) { + @NonNull + public TaskStackBuilder addNextIntent(@NonNull Intent nextIntent) { mIntents.add(nextIntent); return this; } @@ -159,7 +164,8 @@ public final class TaskStackBuilder implements Iterable<Intent> { * Its chain of parents as specified in the manifest will be added. * @return This TaskStackBuilder for method chaining. */ - public TaskStackBuilder addNextIntentWithParentStack(Intent nextIntent) { + @NonNull + public TaskStackBuilder addNextIntentWithParentStack(@NonNull Intent nextIntent) { ComponentName target = nextIntent.getComponent(); if (target == null) { target = nextIntent.resolveActivity(mSourceContext.getPackageManager()); @@ -178,7 +184,8 @@ public final class TaskStackBuilder implements Iterable<Intent> { * @param sourceActivity All parents of this activity will be added * @return This TaskStackBuilder for method chaining */ - public TaskStackBuilder addParentStack(Activity sourceActivity) { + @NonNull + public TaskStackBuilder addParentStack(@NonNull Activity sourceActivity) { Intent parent = null; if (sourceActivity instanceof SupportParentable) { parent = ((SupportParentable) sourceActivity).getSupportParentActivityIntent(); @@ -207,7 +214,8 @@ public final class TaskStackBuilder implements Iterable<Intent> { * @param sourceActivityClass All parents of this activity will be added * @return This TaskStackBuilder for method chaining */ - public TaskStackBuilder addParentStack(Class<?> sourceActivityClass) { + @NonNull + public TaskStackBuilder addParentStack(@NonNull Class<?> sourceActivityClass) { return addParentStack(new ComponentName(mSourceContext, sourceActivityClass)); } @@ -264,6 +272,7 @@ public final class TaskStackBuilder implements Iterable<Intent> { * @param index Index from 0-getIntentCount() * @return the intent at position index */ + @Nullable public Intent editIntentAt(int index) { return mIntents.get(index); } @@ -300,7 +309,7 @@ public final class TaskStackBuilder implements Iterable<Intent> { * @param options Additional options for how the Activity should be started. * See {@link android.content.Context#startActivity(Intent, Bundle)} */ - public void startActivities(Bundle options) { + public void startActivities(@Nullable Bundle options) { if (mIntents.isEmpty()) { throw new IllegalStateException( "No intents added to TaskStackBuilder; cannot startActivities"); @@ -325,8 +334,10 @@ public final class TaskStackBuilder implements Iterable<Intent> { * {@link PendingIntent#FLAG_UPDATE_CURRENT}, or any of the flags supported by * {@link Intent#fillIn(Intent, int)} to control which unspecified parts of the * intent that can be supplied when the actual send happens. - * @return The obtained PendingIntent + * @return The obtained PendingIntent. May return null only if + * {@link PendingIntent#FLAG_NO_CREATE} has been supplied. */ + @Nullable public PendingIntent getPendingIntent(int requestCode, int flags) { return getPendingIntent(requestCode, flags, null); } @@ -342,9 +353,11 @@ public final class TaskStackBuilder implements Iterable<Intent> { * intent that can be supplied when the actual send happens. * @param options Additional options for how the Activity should be started. * See {@link android.content.Context#startActivity(Intent, Bundle)} - * @return The obtained PendingIntent + * @return The obtained PendingIntent. May return null only if + * {@link PendingIntent#FLAG_NO_CREATE} has been supplied. */ - public PendingIntent getPendingIntent(int requestCode, int flags, Bundle options) { + @Nullable + public PendingIntent getPendingIntent(int requestCode, int flags, @Nullable Bundle options) { if (mIntents.isEmpty()) { throw new IllegalStateException( "No intents added to TaskStackBuilder; cannot getPendingIntent"); @@ -364,6 +377,7 @@ public final class TaskStackBuilder implements Iterable<Intent> { * * @return An array containing the intents added to this builder. */ + @NonNull public Intent[] getIntents() { Intent[] intents = new Intent[mIntents.size()]; if (intents.length == 0) return intents; |