diff options
author | Tor Norbye <tnorbye@google.com> | 2013-09-12 22:22:06 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-12 22:22:06 +0000 |
commit | b6a3ef18342e6671d9674312b66a015d6caa80ed (patch) | |
tree | 80f3de660aa6be323291dac5106220b25e5622a0 /core/java/android | |
parent | 0f05de62e73c6361e06422e3cf7c36a6bcdb2c3f (diff) | |
parent | d9273d6f289d9b55da3fd0db2f659fdfb48106a8 (diff) | |
download | frameworks_base-b6a3ef18342e6671d9674312b66a015d6caa80ed.zip frameworks_base-b6a3ef18342e6671d9674312b66a015d6caa80ed.tar.gz frameworks_base-b6a3ef18342e6671d9674312b66a015d6caa80ed.tar.bz2 |
Merge "Add typedefs and nullness annotations."
Diffstat (limited to 'core/java/android')
21 files changed, 621 insertions, 156 deletions
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java index c4ddf1f..fbe8987 100644 --- a/core/java/android/app/ActionBar.java +++ b/core/java/android/app/ActionBar.java @@ -16,6 +16,9 @@ package android.app; +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; @@ -28,6 +31,9 @@ import android.view.ViewGroup.MarginLayoutParams; import android.view.Window; import android.widget.SpinnerAdapter; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * A window feature at the top of the activity that may display the activity title, navigation * modes, and other interactive items. @@ -57,6 +63,11 @@ import android.widget.SpinnerAdapter; * </div> */ public abstract class ActionBar { + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS}) + public @interface NavigationMode {} + /** * Standard navigation mode. Consists of either a logo or icon * and title text with an optional subtitle. Clicking any of these elements @@ -78,6 +89,19 @@ public abstract class ActionBar { */ public static final int NAVIGATION_MODE_TABS = 2; + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(flag = true, + value = { + DISPLAY_USE_LOGO, + DISPLAY_SHOW_HOME, + DISPLAY_HOME_AS_UP, + DISPLAY_SHOW_TITLE, + DISPLAY_SHOW_CUSTOM, + DISPLAY_TITLE_MULTIPLE_LINES + }) + public @interface DisplayOptions {} + /** * Use logo instead of icon if available. This flag will cause appropriate * navigation modes to use a wider logo in place of the standard icon. @@ -341,7 +365,7 @@ public abstract class ActionBar { * @param options A combination of the bits defined by the DISPLAY_ constants * defined in ActionBar. */ - public abstract void setDisplayOptions(int options); + public abstract void setDisplayOptions(@DisplayOptions int options); /** * Set selected display options. Only the options specified by mask will be changed. @@ -356,7 +380,7 @@ public abstract class ActionBar { * defined in ActionBar. * @param mask A bit mask declaring which display options should be changed. */ - public abstract void setDisplayOptions(int options, int mask); + public abstract void setDisplayOptions(@DisplayOptions int options, @DisplayOptions int mask); /** * Set whether to display the activity logo rather than the activity icon. @@ -431,7 +455,7 @@ public abstract class ActionBar { * @see #setStackedBackgroundDrawable(Drawable) * @see #setSplitBackgroundDrawable(Drawable) */ - public abstract void setBackgroundDrawable(Drawable d); + public abstract void setBackgroundDrawable(@Nullable Drawable d); /** * Set the ActionBar's stacked background. This will appear @@ -484,6 +508,7 @@ public abstract class ActionBar { * * @return The current navigation mode. */ + @NavigationMode public abstract int getNavigationMode(); /** @@ -494,7 +519,7 @@ public abstract class ActionBar { * @see #NAVIGATION_MODE_LIST * @see #NAVIGATION_MODE_TABS */ - public abstract void setNavigationMode(int mode); + public abstract void setNavigationMode(@NavigationMode int mode); /** * @return The current set of display options. @@ -1024,7 +1049,7 @@ public abstract class ActionBar { }) public int gravity = Gravity.NO_GRAVITY; - public LayoutParams(Context c, AttributeSet attrs) { + public LayoutParams(@NonNull Context c, AttributeSet attrs) { super(c, attrs); TypedArray a = c.obtainStyledAttributes(attrs, diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 57686a4..c2d35e7 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -16,11 +16,14 @@ package android.app; +import android.annotation.NonNull; import android.util.ArrayMap; import android.util.SuperNotCalledException; import com.android.internal.app.ActionBarImpl; import com.android.internal.policy.PolicyManager; +import android.annotation.IntDef; +import android.annotation.Nullable; import android.content.ComponentCallbacks2; import android.content.ComponentName; import android.content.ContentResolver; @@ -83,6 +86,8 @@ import android.widget.AdapterView; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.HashMap; @@ -851,6 +856,7 @@ public class Activity extends ContextThemeWrapper * @see #getWindow * @see android.view.Window#getCurrentFocus */ + @Nullable public View getCurrentFocus() { return mWindow != null ? mWindow.getCurrentFocus() : null; } @@ -881,7 +887,7 @@ public class Activity extends ContextThemeWrapper * @see #onRestoreInstanceState * @see #onPostCreate */ - protected void onCreate(Bundle savedInstanceState) { + protected void onCreate(@Nullable Bundle savedInstanceState) { if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); if (mLastNonConfigurationInstances != null) { mAllLoaderManagers = mLastNonConfigurationInstances.loaders; @@ -1009,7 +1015,7 @@ public class Activity extends ContextThemeWrapper * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> * @see #onCreate */ - protected void onPostCreate(Bundle savedInstanceState) { + protected void onPostCreate(@Nullable Bundle savedInstanceState) { if (!isChild()) { mTitleReady = true; onTitleChanged(getTitle(), getTitleColor()); @@ -1346,6 +1352,7 @@ public class Activity extends ContextThemeWrapper * @see #onSaveInstanceState * @see #onPause */ + @Nullable public CharSequence onCreateDescription() { return null; } @@ -1548,6 +1555,7 @@ public class Activity extends ContextThemeWrapper * {@link Fragment#setRetainInstance(boolean)} instead; this is also * available on older platforms through the Android compatibility package. */ + @Nullable @Deprecated public Object getLastNonConfigurationInstance() { return mLastNonConfigurationInstances != null @@ -1627,6 +1635,7 @@ public class Activity extends ContextThemeWrapper * @return Returns the object previously returned by * {@link #onRetainNonConfigurationChildInstances()} */ + @Nullable HashMap<String, Object> getLastNonConfigurationChildInstances() { return mLastNonConfigurationInstances != null ? mLastNonConfigurationInstances.children : null; @@ -1639,6 +1648,7 @@ public class Activity extends ContextThemeWrapper * set of child activities, such as ActivityGroup. The same guarantees and restrictions apply * as for {@link #onRetainNonConfigurationInstance()}. The default implementation returns null. */ + @Nullable HashMap<String,Object> onRetainNonConfigurationChildInstances() { return null; } @@ -1886,6 +1896,7 @@ public class Activity extends ContextThemeWrapper * * @return The Activity's ActionBar, or null if it does not have one. */ + @Nullable public ActionBar getActionBar() { initActionBar(); return mActionBar; @@ -1982,7 +1993,17 @@ public class Activity extends ContextThemeWrapper public void setFinishOnTouchOutside(boolean finish) { mWindow.setCloseOnTouchOutside(finish); } - + + /** @hide */ + @IntDef({ + DEFAULT_KEYS_DISABLE, + DEFAULT_KEYS_DIALER, + DEFAULT_KEYS_SHORTCUT, + DEFAULT_KEYS_SEARCH_LOCAL, + DEFAULT_KEYS_SEARCH_GLOBAL}) + @Retention(RetentionPolicy.SOURCE) + @interface DefaultKeyMode {} + /** * Use with {@link #setDefaultKeyMode} to turn off default handling of * keys. @@ -2052,7 +2073,7 @@ public class Activity extends ContextThemeWrapper * @see #DEFAULT_KEYS_SEARCH_GLOBAL * @see #onKeyDown */ - public final void setDefaultKeyMode(int mode) { + public final void setDefaultKeyMode(@DefaultKeyMode int mode) { mDefaultKeyMode = mode; // Some modes use a SpannableStringBuilder to track & dispatch input events @@ -2518,6 +2539,7 @@ public class Activity extends ContextThemeWrapper * simply returns null so that all panel sub-windows will have the default * menu behavior. */ + @Nullable public View onCreatePanelView(int featureId) { return null; } @@ -3015,6 +3037,7 @@ public class Activity extends ContextThemeWrapper * {@link FragmentManager} instead; this is also * available on older platforms through the Android compatibility package. */ + @Nullable @Deprecated protected Dialog onCreateDialog(int id, Bundle args) { return onCreateDialog(id); @@ -3102,6 +3125,7 @@ public class Activity extends ContextThemeWrapper * {@link FragmentManager} instead; this is also * available on older platforms through the Android compatibility package. */ + @Nullable @Deprecated public final boolean showDialog(int id, Bundle args) { if (mManagedDialogs == null) { @@ -3223,13 +3247,13 @@ public class Activity extends ContextThemeWrapper * <p>It is typically called from onSearchRequested(), either directly from * Activity.onSearchRequested() or from an overridden version in any given * Activity. If your goal is simply to activate search, it is preferred to call - * onSearchRequested(), which may have been overriden elsewhere in your Activity. If your goal + * onSearchRequested(), which may have been overridden elsewhere in your Activity. If your goal * is to inject specific data such as context data, it is preferred to <i>override</i> * onSearchRequested(), so that any callers to it will benefit from the override. * * @param initialQuery Any non-null non-empty string will be inserted as * pre-entered text in the search query box. - * @param selectInitialQuery If true, the intial query will be preselected, which means that + * @param selectInitialQuery If true, the initial query will be preselected, which means that * any further typing will replace it. This is useful for cases where an entire pre-formed * query is being inserted. If false, the selection point will be placed at the end of the * inserted query. This is useful when the inserted query is text that the user entered, @@ -3247,8 +3271,8 @@ public class Activity extends ContextThemeWrapper * @see android.app.SearchManager * @see #onSearchRequested */ - public void startSearch(String initialQuery, boolean selectInitialQuery, - Bundle appSearchData, boolean globalSearch) { + public void startSearch(@Nullable String initialQuery, boolean selectInitialQuery, + @Nullable Bundle appSearchData, boolean globalSearch) { ensureSearchManager(); mSearchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), appSearchData, globalSearch); @@ -3264,7 +3288,7 @@ public class Activity extends ContextThemeWrapper * searches. This data will be returned with SEARCH intent(s). Null if * no extra data is required. */ - public void triggerSearch(String query, Bundle appSearchData) { + public void triggerSearch(String query, @Nullable Bundle appSearchData) { ensureSearchManager(); mSearchManager.triggerSearch(query, getComponentName(), appSearchData); } @@ -3331,6 +3355,7 @@ public class Activity extends ContextThemeWrapper * Convenience for calling * {@link android.view.Window#getLayoutInflater}. */ + @NonNull public LayoutInflater getLayoutInflater() { return getWindow().getLayoutInflater(); } @@ -3338,6 +3363,7 @@ public class Activity extends ContextThemeWrapper /** * Returns a {@link MenuInflater} with this context. */ + @NonNull public MenuInflater getMenuInflater() { // Make sure that action views can get an appropriate theme. if (mMenuInflater == null) { @@ -3416,7 +3442,7 @@ public class Activity extends ContextThemeWrapper * * @see #startActivity */ - public void startActivityForResult(Intent intent, int requestCode, Bundle options) { + public void startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options) { if (mParent == null) { Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( @@ -3495,7 +3521,7 @@ public class Activity extends ContextThemeWrapper * @param extraFlags Always set to 0. */ public void startIntentSenderForResult(IntentSender intent, int requestCode, - Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) + @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException { startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, flagsValues, extraFlags, null); @@ -3527,7 +3553,7 @@ public class Activity extends ContextThemeWrapper * override any that conflict with those given by the IntentSender. */ public void startIntentSenderForResult(IntentSender intent, int requestCode, - Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) throws IntentSender.SendIntentException { if (mParent == null) { startIntentSenderForResultInner(intent, requestCode, fillInIntent, @@ -3615,7 +3641,7 @@ public class Activity extends ContextThemeWrapper * @see #startActivityForResult */ @Override - public void startActivity(Intent intent, Bundle options) { + public void startActivity(Intent intent, @Nullable Bundle options) { if (options != null) { startActivityForResult(intent, -1, options); } else { @@ -3664,7 +3690,7 @@ public class Activity extends ContextThemeWrapper * @see #startActivityForResult */ @Override - public void startActivities(Intent[] intents, Bundle options) { + public void startActivities(Intent[] intents, @Nullable Bundle options) { mInstrumentation.execStartActivities(this, mMainThread.getApplicationThread(), mToken, this, intents, options); } @@ -3683,7 +3709,7 @@ public class Activity extends ContextThemeWrapper * @param extraFlags Always set to 0. */ public void startIntentSender(IntentSender intent, - Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) + @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) throws IntentSender.SendIntentException { startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags, null); @@ -3710,7 +3736,7 @@ public class Activity extends ContextThemeWrapper * override any that conflict with those given by the IntentSender. */ public void startIntentSender(IntentSender intent, - Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) throws IntentSender.SendIntentException { if (options != null) { startIntentSenderForResult(intent, -1, fillInIntent, flagsMask, @@ -3738,7 +3764,7 @@ public class Activity extends ContextThemeWrapper * @see #startActivity * @see #startActivityForResult */ - public boolean startActivityIfNeeded(Intent intent, int requestCode) { + public boolean startActivityIfNeeded(@NonNull Intent intent, int requestCode) { return startActivityIfNeeded(intent, requestCode, null); } @@ -3772,7 +3798,8 @@ public class Activity extends ContextThemeWrapper * @see #startActivity * @see #startActivityForResult */ - public boolean startActivityIfNeeded(Intent intent, int requestCode, Bundle options) { + public boolean startActivityIfNeeded(@NonNull Intent intent, int requestCode, + @Nullable Bundle options) { if (mParent == null) { int result = ActivityManager.START_RETURN_INTENT_TO_CALLER; try { @@ -3821,7 +3848,7 @@ public class Activity extends ContextThemeWrapper * wasn't. In general, if true is returned you will then want to call * finish() on yourself. */ - public boolean startNextMatchingActivity(Intent intent) { + public boolean startNextMatchingActivity(@NonNull Intent intent) { return startNextMatchingActivity(intent, null); } @@ -3844,7 +3871,7 @@ public class Activity extends ContextThemeWrapper * wasn't. In general, if true is returned you will then want to call * finish() on yourself. */ - public boolean startNextMatchingActivity(Intent intent, Bundle options) { + public boolean startNextMatchingActivity(@NonNull Intent intent, @Nullable Bundle options) { if (mParent == null) { try { intent.migrateExtraStreamToClipData(); @@ -3874,7 +3901,7 @@ public class Activity extends ContextThemeWrapper * @see #startActivity * @see #startActivityForResult */ - public void startActivityFromChild(Activity child, Intent intent, + public void startActivityFromChild(@NonNull Activity child, Intent intent, int requestCode) { startActivityFromChild(child, intent, requestCode, null); } @@ -3898,8 +3925,8 @@ public class Activity extends ContextThemeWrapper * @see #startActivity * @see #startActivityForResult */ - public void startActivityFromChild(Activity child, Intent intent, - int requestCode, Bundle options) { + public void startActivityFromChild(@NonNull Activity child, Intent intent, + int requestCode, @Nullable Bundle options) { Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( this, mMainThread.getApplicationThread(), mToken, child, @@ -3924,7 +3951,7 @@ public class Activity extends ContextThemeWrapper * @see Fragment#startActivity * @see Fragment#startActivityForResult */ - public void startActivityFromFragment(Fragment fragment, Intent intent, + public void startActivityFromFragment(@NonNull Fragment fragment, Intent intent, int requestCode) { startActivityFromFragment(fragment, intent, requestCode, null); } @@ -3949,8 +3976,8 @@ public class Activity extends ContextThemeWrapper * @see Fragment#startActivity * @see Fragment#startActivityForResult */ - public void startActivityFromFragment(Fragment fragment, Intent intent, - int requestCode, Bundle options) { + public void startActivityFromFragment(@NonNull Fragment fragment, Intent intent, + int requestCode, @Nullable Bundle options) { Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( this, mMainThread.getApplicationThread(), mToken, fragment, @@ -3982,7 +4009,7 @@ public class Activity extends ContextThemeWrapper */ public void startIntentSenderFromChild(Activity child, IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, - int extraFlags, Bundle options) + int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException { startIntentSenderForResultInner(intent, requestCode, fillInIntent, flagsMask, flagsValues, child, options); @@ -4081,6 +4108,7 @@ public class Activity extends ContextThemeWrapper * @return The package of the activity that will receive your * reply, or null if none. */ + @Nullable public String getCallingPackage() { try { return ActivityManagerNative.getDefault().getCallingPackage(mToken); @@ -4103,6 +4131,7 @@ public class Activity extends ContextThemeWrapper * @return The ComponentName of the activity that will receive your * reply, or null if none. */ + @Nullable public ComponentName getCallingActivity() { try { return ActivityManagerNative.getDefault().getCallingActivity(mToken); @@ -4295,7 +4324,7 @@ public class Activity extends ContextThemeWrapper * @param requestCode Request code that had been used to start the * activity. */ - public void finishActivityFromChild(Activity child, int requestCode) { + public void finishActivityFromChild(@NonNull Activity child, int requestCode) { try { ActivityManagerNative.getDefault() .finishSubActivity(mToken, child.mEmbeddedID, requestCode); @@ -4356,8 +4385,8 @@ public class Activity extends ContextThemeWrapper * * @see PendingIntent */ - public PendingIntent createPendingResult(int requestCode, Intent data, - int flags) { + public PendingIntent createPendingResult(int requestCode, @NonNull Intent data, + @PendingIntent.Flags int flags) { String packageName = getPackageName(); try { data.prepareToLeaveProcess(); @@ -4384,7 +4413,7 @@ public class Activity extends ContextThemeWrapper * @param requestedOrientation An orientation constant as used in * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. */ - public void setRequestedOrientation(int requestedOrientation) { + public void setRequestedOrientation(@ActivityInfo.ScreenOrientation int requestedOrientation) { if (mParent == null) { try { ActivityManagerNative.getDefault().setRequestedOrientation( @@ -4406,6 +4435,7 @@ public class Activity extends ContextThemeWrapper * @return Returns an orientation constant as used in * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. */ + @ActivityInfo.ScreenOrientation public int getRequestedOrientation() { if (mParent == null) { try { @@ -4477,6 +4507,7 @@ public class Activity extends ContextThemeWrapper * * @return The local class name. */ + @NonNull public String getLocalClassName() { final String pkg = getPackageName(); final String cls = mComponent.getClassName(); @@ -4522,9 +4553,9 @@ public class Activity extends ContextThemeWrapper mSearchManager = new SearchManager(this, null); } - + @Override - public Object getSystemService(String name) { + public Object getSystemService(@ServiceName @NonNull String name) { if (getBaseContext() == null) { throw new IllegalStateException( "System services not available to Activities before onCreate()"); @@ -4686,7 +4717,7 @@ public class Activity extends ContextThemeWrapper /** * Gets the suggested audio stream whose volume should be changed by the - * harwdare volume controls. + * hardware volume controls. * * @return The suggested audio stream type whose volume should be changed by * the hardware volume controls. @@ -4722,6 +4753,7 @@ public class Activity extends ContextThemeWrapper * @see android.view.LayoutInflater#createView * @see android.view.Window#getLayoutInflater */ + @Nullable public View onCreateView(String name, Context context, AttributeSet attrs) { return null; } @@ -4989,6 +5021,7 @@ public class Activity extends ContextThemeWrapper * * @see ActionMode */ + @Nullable public ActionMode startActionMode(ActionMode.Callback callback) { return mWindow.getDecorView().startActionMode(callback); } @@ -5004,6 +5037,7 @@ public class Activity extends ContextThemeWrapper * @return The new action mode, or <code>null</code> if the activity does not want to * provide special handling for this action mode. (It will be handled by the system.) */ + @Nullable @Override public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) { initActionBar(); @@ -5147,6 +5181,7 @@ public class Activity extends ContextThemeWrapper * @return a new Intent targeting the defined parent of this activity or null if * there is no valid parent. */ + @Nullable public Intent getParentActivityIntent() { final String parentName = mActivityInfo.parentActivityName; if (TextUtils.isEmpty(parentName)) { diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java index d626e5f..c09da87 100644 --- a/core/java/android/app/Fragment.java +++ b/core/java/android/app/Fragment.java @@ -17,6 +17,7 @@ package android.app; import android.animation.Animator; +import android.annotation.Nullable; import android.content.ComponentCallbacks2; import android.content.Context; import android.content.Intent; @@ -575,7 +576,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene * the given fragment class. This is a runtime exception; it is not * normally expected to happen. */ - public static Fragment instantiate(Context context, String fname, Bundle args) { + public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) { try { Class<?> clazz = sClassMap.get(fname); if (clazz == null) { @@ -1213,7 +1214,8 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene * * @return Return the View for the fragment's UI, or null. */ - public View onCreateView(LayoutInflater inflater, ViewGroup container, + @Nullable + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { return null; } @@ -1228,7 +1230,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene * @param savedInstanceState If non-null, this fragment is being re-constructed * from a previous saved state as given here. */ - public void onViewCreated(View view, Bundle savedInstanceState) { + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { } /** @@ -1237,6 +1239,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene * * @return The fragment's root view, or null if it has no layout. */ + @Nullable public View getView() { return mView; } diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index e70ad1c..45992e3 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -18,6 +18,7 @@ package android.app; import com.android.internal.R; +import android.annotation.IntDef; import android.content.Context; import android.content.Intent; import android.content.res.Resources; @@ -37,6 +38,8 @@ import android.view.View; import android.widget.ProgressBar; import android.widget.RemoteViews; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.text.NumberFormat; import java.util.ArrayList; @@ -350,6 +353,11 @@ public class Notification implements Parcelable public int flags; + /** @hide */ + @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX}) + @Retention(RetentionPolicy.SOURCE) + public @interface Priority {} + /** * Default notification {@link #priority}. If your application does not prioritize its own * notifications, use this value for all notifications. @@ -391,6 +399,7 @@ public class Notification implements Parcelable * system will make a determination about how to interpret this priority when presenting * the notification. */ + @Priority public int priority; /** @@ -1434,7 +1443,7 @@ public class Notification implements Parcelable * * @see Notification#priority */ - public Builder setPriority(int pri) { + public Builder setPriority(@Priority int pri) { mPriority = pri; return this; } diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java index bdd0adb..a03e5b6 100644 --- a/core/java/android/app/PendingIntent.java +++ b/core/java/android/app/PendingIntent.java @@ -16,6 +16,9 @@ package android.app; +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.content.Context; import android.content.Intent; import android.content.IIntentReceiver; @@ -30,6 +33,9 @@ import android.os.Parcelable; import android.os.UserHandle; import android.util.AndroidException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * A description of an Intent and target action to perform with it. Instances * of this class are created with {@link #getActivity}, {@link #getActivities}, @@ -86,6 +92,26 @@ import android.util.AndroidException; public final class PendingIntent implements Parcelable { private final IIntentSender mTarget; + /** @hide */ + @IntDef(flag = true, + value = { + FLAG_ONE_SHOT, + FLAG_NO_CREATE, + FLAG_CANCEL_CURRENT, + FLAG_UPDATE_CURRENT, + + Intent.FILL_IN_ACTION, + Intent.FILL_IN_DATA, + Intent.FILL_IN_CATEGORIES, + Intent.FILL_IN_COMPONENT, + Intent.FILL_IN_PACKAGE, + Intent.FILL_IN_SOURCE_BOUNDS, + Intent.FILL_IN_SELECTOR, + Intent.FILL_IN_CLIP_DATA + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Flags {} + /** * Flag for use with {@link #getActivity}, {@link #getBroadcast}, and * {@link #getService}: this @@ -220,7 +246,7 @@ public final class PendingIntent implements Parcelable { * supplied. */ public static PendingIntent getActivity(Context context, int requestCode, - Intent intent, int flags) { + Intent intent, @Flags int flags) { return getActivity(context, requestCode, intent, flags, null); } @@ -253,7 +279,7 @@ public final class PendingIntent implements Parcelable { * supplied. */ public static PendingIntent getActivity(Context context, int requestCode, - Intent intent, int flags, Bundle options) { + @NonNull Intent intent, @Flags int flags, @Nullable Bundle options) { String packageName = context.getPackageName(); String resolvedType = intent != null ? intent.resolveTypeIfNeeded( context.getContentResolver()) : null; @@ -278,7 +304,7 @@ public final class PendingIntent implements Parcelable { * activity is started, not when the pending intent is created. */ public static PendingIntent getActivityAsUser(Context context, int requestCode, - Intent intent, int flags, Bundle options, UserHandle user) { + @NonNull Intent intent, int flags, Bundle options, UserHandle user) { String packageName = context.getPackageName(); String resolvedType = intent != null ? intent.resolveTypeIfNeeded( context.getContentResolver()) : null; @@ -343,7 +369,7 @@ public final class PendingIntent implements Parcelable { * supplied. */ public static PendingIntent getActivities(Context context, int requestCode, - Intent[] intents, int flags) { + @NonNull Intent[] intents, @Flags int flags) { return getActivities(context, requestCode, intents, flags, null); } @@ -393,7 +419,7 @@ public final class PendingIntent implements Parcelable { * supplied. */ public static PendingIntent getActivities(Context context, int requestCode, - Intent[] intents, int flags, Bundle options) { + @NonNull Intent[] intents, @Flags int flags, @Nullable Bundle options) { String packageName = context.getPackageName(); String[] resolvedTypes = new String[intents.length]; for (int i=0; i<intents.length; i++) { @@ -419,7 +445,7 @@ public final class PendingIntent implements Parcelable { * activity is started, not when the pending intent is created. */ public static PendingIntent getActivitiesAsUser(Context context, int requestCode, - Intent[] intents, int flags, Bundle options, UserHandle user) { + @NonNull Intent[] intents, int flags, Bundle options, UserHandle user) { String packageName = context.getPackageName(); String[] resolvedTypes = new String[intents.length]; for (int i=0; i<intents.length; i++) { @@ -463,7 +489,7 @@ public final class PendingIntent implements Parcelable { * supplied. */ public static PendingIntent getBroadcast(Context context, int requestCode, - Intent intent, int flags) { + Intent intent, @Flags int flags) { return getBroadcastAsUser(context, requestCode, intent, flags, new UserHandle(UserHandle.myUserId())); } @@ -517,7 +543,7 @@ public final class PendingIntent implements Parcelable { * supplied. */ public static PendingIntent getService(Context context, int requestCode, - Intent intent, int flags) { + @NonNull Intent intent, @Flags int flags) { String packageName = context.getPackageName(); String resolvedType = intent != null ? intent.resolveTypeIfNeeded( context.getContentResolver()) : null; @@ -747,6 +773,7 @@ public final class PendingIntent implements Parcelable { * @return The package name of the PendingIntent, or null if there is * none associated with it. */ + @Nullable public String getCreatorPackage() { try { return ActivityManagerNative.getDefault() @@ -805,6 +832,7 @@ public final class PendingIntent implements Parcelable { * @return The user handle of the PendingIntent, or null if there is * none associated with it. */ + @Nullable public UserHandle getCreatorUserHandle() { try { int uid = ActivityManagerNative.getDefault() @@ -920,8 +948,8 @@ public final class PendingIntent implements Parcelable { * @param sender The PendingIntent to write, or null. * @param out Where to write the PendingIntent. */ - public static void writePendingIntentOrNullToParcel(PendingIntent sender, - Parcel out) { + public static void writePendingIntentOrNullToParcel(@Nullable PendingIntent sender, + @NonNull Parcel out) { out.writeStrongBinder(sender != null ? sender.mTarget.asBinder() : null); } @@ -936,7 +964,8 @@ public final class PendingIntent implements Parcelable { * @return Returns the Messenger read from the Parcel, or null if null had * been written. */ - public static PendingIntent readPendingIntentOrNullFromParcel(Parcel in) { + @Nullable + public static PendingIntent readPendingIntentOrNullFromParcel(@NonNull Parcel in) { IBinder b = in.readStrongBinder(); return b != null ? new PendingIntent(b) : null; } diff --git a/core/java/android/app/TaskStackBuilder.java b/core/java/android/app/TaskStackBuilder.java index 3e0ac7e..0077db1 100644 --- a/core/java/android/app/TaskStackBuilder.java +++ b/core/java/android/app/TaskStackBuilder.java @@ -16,6 +16,7 @@ package android.app; +import android.annotation.NonNull; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -244,7 +245,7 @@ public class TaskStackBuilder { * * @return The obtained PendingIntent */ - public PendingIntent getPendingIntent(int requestCode, int flags) { + public PendingIntent getPendingIntent(int requestCode, @PendingIntent.Flags int flags) { return getPendingIntent(requestCode, flags, null); } @@ -263,7 +264,8 @@ public class TaskStackBuilder { * * @return The obtained PendingIntent */ - public PendingIntent getPendingIntent(int requestCode, int flags, Bundle options) { + public PendingIntent getPendingIntent(int requestCode, @PendingIntent.Flags int flags, + Bundle options) { if (mIntents.isEmpty()) { throw new IllegalStateException( "No intents added to TaskStackBuilder; cannot getPendingIntent"); @@ -294,6 +296,7 @@ public class TaskStackBuilder { * * @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; diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 92a9c7c..bea5e42 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -16,6 +16,10 @@ package android.content; +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.StringDef; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.AssetManager; @@ -45,6 +49,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; /** * Interface to global information about an application environment. This is @@ -130,6 +136,20 @@ public abstract class Context { */ public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008; + /** @hide */ + @IntDef(flag = true, + value = { + BIND_AUTO_CREATE, + BIND_AUTO_CREATE, + BIND_DEBUG_UNBIND, + BIND_NOT_FOREGROUND, + BIND_ABOVE_CLIENT, + BIND_ALLOW_OOM_MANAGEMENT, + BIND_WAIVE_PRIORITY + }) + @Retention(RetentionPolicy.SOURCE) + public @interface BindServiceFlags {} + /** * Flag for {@link #bindService}: automatically create the service as long * as the binding exists. Note that while this will create the service, @@ -493,7 +513,7 @@ public abstract class Context { * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS} - * is always on in apps targetting Gingerbread (Android 2.3) and below, and + * is always on in apps targeting Gingerbread (Android 2.3) and below, and * off by default in later versions. * * @return The single {@link SharedPreferences} instance that can be used @@ -669,7 +689,8 @@ public abstract class Context { * @see #getFilesDir * @see android.os.Environment#getExternalStoragePublicDirectory */ - public abstract File getExternalFilesDir(String type); + @Nullable + public abstract File getExternalFilesDir(@Nullable String type); /** * Returns absolute paths to application-specific directories on all @@ -794,6 +815,7 @@ public abstract class Context { * * @see #getCacheDir */ + @Nullable public abstract File getExternalCacheDir(); /** @@ -900,7 +922,8 @@ public abstract class Context { * @see #deleteDatabase */ public abstract SQLiteDatabase openOrCreateDatabase(String name, - int mode, CursorFactory factory, DatabaseErrorHandler errorHandler); + int mode, CursorFactory factory, + @Nullable DatabaseErrorHandler errorHandler); /** * Delete an existing private SQLiteDatabase associated with this Context's @@ -1046,7 +1069,7 @@ public abstract class Context { * @see #startActivity(Intent) * @see PackageManager#resolveActivity */ - public abstract void startActivity(Intent intent, Bundle options); + public abstract void startActivity(Intent intent, @Nullable Bundle options); /** * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the @@ -1062,7 +1085,7 @@ public abstract class Context { * @throws ActivityNotFoundException * @hide */ - public void startActivityAsUser(Intent intent, Bundle options, UserHandle userId) { + public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) { throw new RuntimeException("Not implemented. Must override in a subclass."); } @@ -1181,7 +1204,7 @@ public abstract class Context { * @see #startIntentSender(IntentSender, Intent, int, int, int) */ public abstract void startIntentSender(IntentSender intent, - Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) throws IntentSender.SendIntentException; /** @@ -1231,11 +1254,11 @@ public abstract class Context { * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) */ public abstract void sendBroadcast(Intent intent, - String receiverPermission); + @Nullable String receiverPermission); /** * Like {@link #sendBroadcast(Intent, String)}, but also allows specification - * of an assocated app op as per {@link android.app.AppOpsManager}. + * of an associated app op as per {@link android.app.AppOpsManager}. * @hide */ public abstract void sendBroadcast(Intent intent, @@ -1262,7 +1285,7 @@ public abstract class Context { * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) */ public abstract void sendOrderedBroadcast(Intent intent, - String receiverPermission); + @Nullable String receiverPermission); /** * Version of {@link #sendBroadcast(Intent)} that allows you to @@ -1306,15 +1329,15 @@ public abstract class Context { * @see #registerReceiver * @see android.app.Activity#RESULT_OK */ - public abstract void sendOrderedBroadcast(Intent intent, - String receiverPermission, BroadcastReceiver resultReceiver, - Handler scheduler, int initialCode, String initialData, - Bundle initialExtras); + public abstract void sendOrderedBroadcast(@NonNull Intent intent, + @Nullable String receiverPermission, BroadcastReceiver resultReceiver, + @Nullable Handler scheduler, int initialCode, @Nullable String initialData, + @Nullable Bundle initialExtras); /** * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, * int, String, android.os.Bundle)}, but also allows specification - * of an assocated app op as per {@link android.app.AppOpsManager}. + * of an associated app op as per {@link android.app.AppOpsManager}. * @hide */ public abstract void sendOrderedBroadcast(Intent intent, @@ -1349,7 +1372,7 @@ public abstract class Context { * @see #sendBroadcast(Intent, String) */ public abstract void sendBroadcastAsUser(Intent intent, UserHandle user, - String receiverPermission); + @Nullable String receiverPermission); /** * Version of @@ -1382,8 +1405,9 @@ public abstract class Context { * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle) */ public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, - String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, - int initialCode, String initialData, Bundle initialExtras); + @Nullable String receiverPermission, BroadcastReceiver resultReceiver, + @Nullable Handler scheduler, int initialCode, @Nullable String initialData, + @Nullable Bundle initialExtras); /** * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the @@ -1448,8 +1472,8 @@ public abstract class Context { */ public abstract void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver resultReceiver, - Handler scheduler, int initialCode, String initialData, - Bundle initialExtras); + @Nullable Handler scheduler, int initialCode, @Nullable String initialData, + @Nullable Bundle initialExtras); /** * Remove the data previously sent with {@link #sendStickyBroadcast}, @@ -1509,8 +1533,8 @@ public abstract class Context { */ public abstract void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle user, BroadcastReceiver resultReceiver, - Handler scheduler, int initialCode, String initialData, - Bundle initialExtras); + @Nullable Handler scheduler, int initialCode, @Nullable String initialData, + @Nullable Bundle initialExtras); /** * Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the @@ -1577,7 +1601,8 @@ public abstract class Context { * @see #sendBroadcast * @see #unregisterReceiver */ - public abstract Intent registerReceiver(BroadcastReceiver receiver, + @Nullable + public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter); /** @@ -1611,8 +1636,10 @@ public abstract class Context { * @see #sendBroadcast * @see #unregisterReceiver */ + @Nullable public abstract Intent registerReceiver(BroadcastReceiver receiver, - IntentFilter filter, String broadcastPermission, Handler scheduler); + IntentFilter filter, @Nullable String broadcastPermission, + @Nullable Handler scheduler); /** * @hide @@ -1638,9 +1665,10 @@ public abstract class Context { * @see #sendBroadcast * @see #unregisterReceiver */ + @Nullable public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver, - UserHandle user, IntentFilter filter, String broadcastPermission, - Handler scheduler); + UserHandle user, IntentFilter filter, @Nullable String broadcastPermission, + @Nullable Handler scheduler); /** * Unregister a previously registered BroadcastReceiver. <em>All</em> @@ -1700,6 +1728,7 @@ public abstract class Context { * @see #stopService * @see #bindService */ + @Nullable public abstract ComponentName startService(Intent service); /** @@ -1787,8 +1816,8 @@ public abstract class Context { * @see #BIND_DEBUG_UNBIND * @see #BIND_NOT_FOREGROUND */ - public abstract boolean bindService(Intent service, ServiceConnection conn, - int flags); + public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn, + @BindServiceFlags int flags); /** * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle @@ -1809,7 +1838,7 @@ public abstract class Context { * * @see #bindService */ - public abstract void unbindService(ServiceConnection conn); + public abstract void unbindService(@NonNull ServiceConnection conn); /** * Start executing an {@link android.app.Instrumentation} class. The given @@ -1834,8 +1863,64 @@ public abstract class Context { * @return {@code true} if the instrumentation was successfully started, * else {@code false} if it could not be found. */ - public abstract boolean startInstrumentation(ComponentName className, - String profileFile, Bundle arguments); + public abstract boolean startInstrumentation(@NonNull ComponentName className, + @Nullable String profileFile, @Nullable Bundle arguments); + + /** @hide */ + @StringDef({ + POWER_SERVICE, + WINDOW_SERVICE, + LAYOUT_INFLATER_SERVICE, + ACCOUNT_SERVICE, + ACTIVITY_SERVICE, + ALARM_SERVICE, + NOTIFICATION_SERVICE, + ACCESSIBILITY_SERVICE, + CAPTIONING_SERVICE, + KEYGUARD_SERVICE, + LOCATION_SERVICE, + //@hide: COUNTRY_DETECTOR, + SEARCH_SERVICE, + SENSOR_SERVICE, + STORAGE_SERVICE, + WALLPAPER_SERVICE, + VIBRATOR_SERVICE, + //@hide: STATUS_BAR_SERVICE, + CONNECTIVITY_SERVICE, + //@hide: UPDATE_LOCK_SERVICE, + //@hide: NETWORKMANAGEMENT_SERVICE, + //@hide: NETWORK_STATS_SERVICE, + //@hide: NETWORK_POLICY_SERVICE, + WIFI_SERVICE, + WIFI_P2P_SERVICE, + NSD_SERVICE, + AUDIO_SERVICE, + MEDIA_ROUTER_SERVICE, + TELEPHONY_SERVICE, + CLIPBOARD_SERVICE, + INPUT_METHOD_SERVICE, + TEXT_SERVICES_MANAGER_SERVICE, + //@hide: APPWIDGET_SERVICE, + //@hide: BACKUP_SERVICE, + DROPBOX_SERVICE, + DEVICE_POLICY_SERVICE, + UI_MODE_SERVICE, + DOWNLOAD_SERVICE, + NFC_SERVICE, + BLUETOOTH_SERVICE, + //@hide: SIP_SERVICE, + USB_SERVICE, + //@hide: SERIAL_SERVICE, + INPUT_SERVICE, + DISPLAY_SERVICE, + //@hide: SCHEDULING_POLICY_SERVICE, + USER_SERVICE, + //@hide: APP_OPS_SERVICE + CAMERA_SERVICE, + PRINT_SERVICE + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ServiceName {} /** * Return the handle to a system-level service by name. The class of the @@ -1936,7 +2021,7 @@ public abstract class Context { * @see #DOWNLOAD_SERVICE * @see android.app.DownloadManager */ - public abstract Object getSystemService(String name); + public abstract Object getSystemService(@ServiceName @NonNull String name); /** * Use with {@link #getSystemService} to retrieve a @@ -2426,7 +2511,8 @@ public abstract class Context { * @see PackageManager#checkPermission(String, String) * @see #checkCallingPermission */ - public abstract int checkPermission(String permission, int pid, int uid); + @PackageManager.PermissionResult + public abstract int checkPermission(@NonNull String permission, int pid, int uid); /** * Determine whether the calling process of an IPC you are handling has been @@ -2449,7 +2535,8 @@ public abstract class Context { * @see #checkPermission * @see #checkCallingOrSelfPermission */ - public abstract int checkCallingPermission(String permission); + @PackageManager.PermissionResult + public abstract int checkCallingPermission(@NonNull String permission); /** * Determine whether the calling process of an IPC <em>or you</em> have been @@ -2467,7 +2554,8 @@ public abstract class Context { * @see #checkPermission * @see #checkCallingPermission */ - public abstract int checkCallingOrSelfPermission(String permission); + @PackageManager.PermissionResult + public abstract int checkCallingOrSelfPermission(@NonNull String permission); /** * If the given permission is not allowed for a particular process @@ -2482,7 +2570,7 @@ public abstract class Context { * @see #checkPermission(String, int, int) */ public abstract void enforcePermission( - String permission, int pid, int uid, String message); + @NonNull String permission, int pid, int uid, @Nullable String message); /** * If the calling process of an IPC you are handling has not been @@ -2503,7 +2591,7 @@ public abstract class Context { * @see #checkCallingPermission(String) */ public abstract void enforceCallingPermission( - String permission, String message); + @NonNull String permission, @Nullable String message); /** * If neither you nor the calling process of an IPC you are @@ -2519,7 +2607,7 @@ public abstract class Context { * @see #checkCallingOrSelfPermission(String) */ public abstract void enforceCallingOrSelfPermission( - String permission, String message); + @NonNull String permission, @Nullable String message); /** * Grant permission to access a specific Uri to another package, regardless @@ -2555,7 +2643,7 @@ public abstract class Context { * @see #revokeUriPermission */ public abstract void grantUriPermission(String toPackage, Uri uri, - int modeFlags); + @Intent.GrantUriMode int modeFlags); /** * Remove all permissions to access a particular content provider Uri @@ -2574,7 +2662,7 @@ public abstract class Context { * * @see #grantUriPermission */ - public abstract void revokeUriPermission(Uri uri, int modeFlags); + public abstract void revokeUriPermission(Uri uri, @Intent.GrantUriMode int modeFlags); /** * Determine whether a particular process and user ID has been granted @@ -2597,7 +2685,8 @@ public abstract class Context { * * @see #checkCallingUriPermission */ - public abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags); + public abstract int checkUriPermission(Uri uri, int pid, int uid, + @Intent.GrantUriMode int modeFlags); /** * Determine whether the calling process and user ID has been @@ -2620,7 +2709,7 @@ public abstract class Context { * * @see #checkUriPermission(Uri, int, int, int) */ - public abstract int checkCallingUriPermission(Uri uri, int modeFlags); + public abstract int checkCallingUriPermission(Uri uri, @Intent.GrantUriMode int modeFlags); /** * Determine whether the calling process of an IPC <em>or you</em> has been granted @@ -2639,7 +2728,8 @@ public abstract class Context { * * @see #checkCallingUriPermission */ - public abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags); + public abstract int checkCallingOrSelfUriPermission(Uri uri, + @Intent.GrantUriMode int modeFlags); /** * Check both a Uri and normal permission. This allows you to perform @@ -2651,7 +2741,7 @@ public abstract class Context { * @param readPermission The permission that provides overall read access, * or null to not do this check. * @param writePermission The permission that provides overall write - * acess, or null to not do this check. + * access, or null to not do this check. * @param pid The process ID being checked against. Must be > 0. * @param uid The user ID being checked against. A uid of 0 is the root * user, which will pass every permission check. @@ -2663,8 +2753,9 @@ public abstract class Context { * is allowed to access that uri or holds one of the given permissions, or * {@link PackageManager#PERMISSION_DENIED} if it is not. */ - public abstract int checkUriPermission(Uri uri, String readPermission, - String writePermission, int pid, int uid, int modeFlags); + public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission, + @Nullable String writePermission, int pid, int uid, + @Intent.GrantUriMode int modeFlags); /** * If a particular process and user ID has not been granted @@ -2686,7 +2777,7 @@ public abstract class Context { * @see #checkUriPermission(Uri, int, int, int) */ public abstract void enforceUriPermission( - Uri uri, int pid, int uid, int modeFlags, String message); + Uri uri, int pid, int uid, @Intent.GrantUriMode int modeFlags, String message); /** * If the calling process and user ID has not been granted @@ -2708,7 +2799,7 @@ public abstract class Context { * @see #checkCallingUriPermission(Uri, int) */ public abstract void enforceCallingUriPermission( - Uri uri, int modeFlags, String message); + Uri uri, @Intent.GrantUriMode int modeFlags, String message); /** * If the calling process of an IPC <em>or you</em> has not been @@ -2727,7 +2818,7 @@ public abstract class Context { * @see #checkCallingOrSelfUriPermission(Uri, int) */ public abstract void enforceCallingOrSelfUriPermission( - Uri uri, int modeFlags, String message); + Uri uri, @Intent.GrantUriMode int modeFlags, String message); /** * Enforce both a Uri and normal permission. This allows you to perform @@ -2739,7 +2830,7 @@ public abstract class Context { * @param readPermission The permission that provides overall read access, * or null to not do this check. * @param writePermission The permission that provides overall write - * acess, or null to not do this check. + * access, or null to not do this check. * @param pid The process ID being checked against. Must be > 0. * @param uid The user ID being checked against. A uid of 0 is the root * user, which will pass every permission check. @@ -2751,8 +2842,15 @@ public abstract class Context { * @see #checkUriPermission(Uri, String, String, int, int, int) */ public abstract void enforceUriPermission( - Uri uri, String readPermission, String writePermission, - int pid, int uid, int modeFlags, String message); + @Nullable Uri uri, @Nullable String readPermission, + @Nullable String writePermission, int pid, int uid, @Intent.GrantUriMode int modeFlags, + @Nullable String message); + + /** @hide */ + @IntDef(flag = true, + value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED}) + @Retention(RetentionPolicy.SOURCE) + public @interface CreatePackageOptions {} /** * Flag for use with {@link #createPackageContext}: include the application @@ -2810,7 +2908,7 @@ public abstract class Context { * the given package name. */ public abstract Context createPackageContext(String packageName, - int flags) throws PackageManager.NameNotFoundException; + @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException; /** * Similar to {@link #createPackageContext(String, int)}, but with a @@ -2846,7 +2944,8 @@ public abstract class Context { * * @return A {@link Context} with the given configuration override. */ - public abstract Context createConfigurationContext(Configuration overrideConfiguration); + public abstract Context createConfigurationContext( + @NonNull Configuration overrideConfiguration); /** * Return a new Context object for the current Context but whose resources @@ -2866,7 +2965,7 @@ public abstract class Context { * * @return A {@link Context} for the display. */ - public abstract Context createDisplayContext(Display display); + public abstract Context createDisplayContext(@NonNull Display display); /** * Gets the display adjustments holder for this context. This information diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 7925123..fc0d0aa 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -21,6 +21,7 @@ import android.util.ArraySet; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import android.annotation.IntDef; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.content.pm.ActivityInfo; @@ -43,6 +44,8 @@ import com.android.internal.util.XmlUtils; import java.io.IOException; import java.io.Serializable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Iterator; @@ -3293,6 +3296,12 @@ public class Intent implements Parcelable, Cloneable { // --------------------------------------------------------------------- // Intent flags (see mFlags variable). + /** @hide */ + @IntDef(flag = true, + value = {FLAG_GRANT_READ_URI_PERMISSION, FLAG_GRANT_WRITE_URI_PERMISSION}) + @Retention(RetentionPolicy.SOURCE) + public @interface GrantUriMode {} + /** * If set, the recipient of this Intent will be granted permission to * perform read operations on the Uri in the Intent's data and any URIs @@ -6319,6 +6328,21 @@ public class Intent implements Parcelable, Cloneable { } } + /** @hide */ + @IntDef(flag = true, + value = { + FILL_IN_ACTION, + FILL_IN_DATA, + FILL_IN_CATEGORIES, + FILL_IN_COMPONENT, + FILL_IN_PACKAGE, + FILL_IN_SOURCE_BOUNDS, + FILL_IN_SELECTOR, + FILL_IN_CLIP_DATA + }) + @Retention(RetentionPolicy.SOURCE) + public @interface FillInFlags {} + /** * Use with {@link #fillIn} to allow the current action value to be * overwritten, even if it is already set. @@ -6412,10 +6436,12 @@ public class Intent implements Parcelable, Cloneable { * * @return Returns a bit mask of {@link #FILL_IN_ACTION}, * {@link #FILL_IN_DATA}, {@link #FILL_IN_CATEGORIES}, {@link #FILL_IN_PACKAGE}, - * {@link #FILL_IN_COMPONENT}, {@link #FILL_IN_SOURCE_BOUNDS}, and - * {@link #FILL_IN_SELECTOR} indicating which fields were changed. + * {@link #FILL_IN_COMPONENT}, {@link #FILL_IN_SOURCE_BOUNDS}, + * {@link #FILL_IN_SELECTOR} and {@link #FILL_IN_CLIP_DATA indicating which fields were + * changed. */ - public int fillIn(Intent other, int flags) { + @FillInFlags + public int fillIn(Intent other, @FillInFlags int flags) { int changes = 0; if (other.mAction != null && (mAction == null || (flags&FILL_IN_ACTION) != 0)) { diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java index b8ac3bf..40275d8 100644 --- a/core/java/android/content/pm/ActivityInfo.java +++ b/core/java/android/content/pm/ActivityInfo.java @@ -16,11 +16,15 @@ package android.content.pm; +import android.annotation.IntDef; import android.content.res.Configuration; import android.os.Parcel; import android.os.Parcelable; import android.util.Printer; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * Information you can retrieve about a particular application * activity or receiver. This corresponds to information collected @@ -212,6 +216,28 @@ public class ActivityInfo extends ComponentInfo */ public int flags; + /** @hide */ + @IntDef({ + SCREEN_ORIENTATION_UNSPECIFIED, + SCREEN_ORIENTATION_LANDSCAPE, + SCREEN_ORIENTATION_PORTRAIT, + SCREEN_ORIENTATION_USER, + SCREEN_ORIENTATION_BEHIND, + SCREEN_ORIENTATION_SENSOR, + SCREEN_ORIENTATION_NOSENSOR, + SCREEN_ORIENTATION_SENSOR_LANDSCAPE, + SCREEN_ORIENTATION_SENSOR_PORTRAIT, + SCREEN_ORIENTATION_REVERSE_LANDSCAPE, + SCREEN_ORIENTATION_REVERSE_PORTRAIT, + SCREEN_ORIENTATION_FULL_SENSOR, + SCREEN_ORIENTATION_USER_LANDSCAPE, + SCREEN_ORIENTATION_USER_PORTRAIT, + SCREEN_ORIENTATION_FULL_USER, + SCREEN_ORIENTATION_LOCKED + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ScreenOrientation {} + /** * Constant corresponding to <code>unspecified</code> in * the {@link android.R.attr#screenOrientation} attribute. @@ -323,6 +349,7 @@ public class ActivityInfo extends ComponentInfo * {@link #SCREEN_ORIENTATION_FULL_USER}, * {@link #SCREEN_ORIENTATION_LOCKED}, */ + @ScreenOrientation public int screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED; /** diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index d58b14c..0be61d3 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -16,6 +16,7 @@ package android.content.pm; +import android.annotation.IntDef; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.content.ComponentName; @@ -33,6 +34,8 @@ import android.util.AndroidException; import android.util.DisplayMetrics; import java.io.File; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.List; /** @@ -190,6 +193,11 @@ public abstract class PackageManager { */ public static final int MATCH_DEFAULT_ONLY = 0x00010000; + /** @hide */ + @IntDef({PERMISSION_GRANTED, PERMISSION_DENIED}) + @Retention(RetentionPolicy.SOURCE) + public @interface PermissionResult {} + /** * Permission check result: this is returned by {@link #checkPermission} * if the permission has been granted to the given package. diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java index 354ea66..27e3b08 100644 --- a/core/java/android/view/Display.java +++ b/core/java/android/view/Display.java @@ -528,6 +528,7 @@ public final class Display { * 90 degrees clockwise and thus the returned value here will be * {@link Surface#ROTATION_90 Surface.ROTATION_90}. */ + @Surface.Rotation public int getRotation() { synchronized (this) { updateDisplayInfoLocked(); @@ -540,6 +541,7 @@ public final class Display { * @return orientation of this display. */ @Deprecated + @Surface.Rotation public int getOrientation() { return getRotation(); } diff --git a/core/java/android/view/DisplayInfo.java b/core/java/android/view/DisplayInfo.java index 8944207..8af2b63 100644 --- a/core/java/android/view/DisplayInfo.java +++ b/core/java/android/view/DisplayInfo.java @@ -144,6 +144,7 @@ public final class DisplayInfo implements Parcelable { * more than one physical display. * </p> */ + @Surface.Rotation public int rotation; /** diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java index 1bfda2d..a2775d4 100644 --- a/core/java/android/view/Surface.java +++ b/core/java/android/view/Surface.java @@ -16,6 +16,7 @@ package android.view; +import android.annotation.IntDef; import android.content.res.CompatibilityInfo.Translator; import android.graphics.Canvas; import android.graphics.Matrix; @@ -24,6 +25,10 @@ import android.graphics.SurfaceTexture; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + import dalvik.system.CloseGuard; /** @@ -80,6 +85,11 @@ public class Surface implements Parcelable { // non compatibility mode. private Matrix mCompatibleMatrix; + /** @hide */ + @IntDef({ROTATION_0, ROTATION_90, ROTATION_180, ROTATION_270}) + @Retention(RetentionPolicy.SOURCE) + public @interface Rotation {} + /** * Rotation constant: 0 degree rotation (natural orientation) */ diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index edcef1e..16da481 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -16,6 +16,9 @@ package android.view; +import android.annotation.IntDef; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.content.ClipData; import android.content.Context; import android.content.res.Configuration; @@ -86,6 +89,8 @@ import com.android.internal.view.menu.MenuBuilder; import com.google.android.collect.Lists; import com.google.android.collect.Maps; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -715,6 +720,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ private static final int FITS_SYSTEM_WINDOWS = 0x00000002; + /** @hide */ + @IntDef({VISIBLE, INVISIBLE, GONE}) + @Retention(RetentionPolicy.SOURCE) + public @interface Visibility {} + /** * This view is visible. * Use with {@link #setVisibility} and <a href="#attr_android:visibility">{@code @@ -882,6 +892,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ static final int FOCUSABLE_IN_TOUCH_MODE = 0x00040000; + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({DRAWING_CACHE_QUALITY_LOW, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_AUTO}) + public @interface DrawingCacheQuality {} + /** * <p>Enables low quality mode for the drawing cache.</p> */ @@ -926,6 +941,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ static final int DUPLICATE_PARENT_STATE = 0x00400000; + /** @hide */ + @IntDef({ + SCROLLBARS_INSIDE_OVERLAY, + SCROLLBARS_INSIDE_INSET, + SCROLLBARS_OUTSIDE_OVERLAY, + SCROLLBARS_OUTSIDE_INSET + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ScrollBarStyle {} + /** * The scrollbar style to display the scrollbars inside the content area, * without increasing the padding. The scrollbars will be overlaid with @@ -1006,6 +1031,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ static final int PARENT_SAVE_DISABLED_MASK = 0x20000000; + /** @hide */ + @IntDef(flag = true, + value = { + FOCUSABLES_ALL, + FOCUSABLES_TOUCH_MODE, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface FocusableMode {} + /** * View flag indicating whether {@link #addFocusables(ArrayList, int, int)} * should add all focusable Views regardless if they are focusable in touch mode. @@ -1018,6 +1052,28 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public static final int FOCUSABLES_TOUCH_MODE = 0x00000001; + /** @hide */ + @IntDef({ + FOCUS_BACKWARD, + FOCUS_FORWARD, + FOCUS_LEFT, + FOCUS_UP, + FOCUS_RIGHT, + FOCUS_DOWN + }) + @Retention(RetentionPolicy.SOURCE) + public @interface FocusDirection {} + + /** @hide */ + @IntDef({ + FOCUS_LEFT, + FOCUS_UP, + FOCUS_RIGHT, + FOCUS_DOWN + }) + @Retention(RetentionPolicy.SOURCE) + public @interface FocusRealDirection {} // Like @FocusDirection, but without forward/backward + /** * Use with {@link #focusSearch(int)}. Move focus to the previous selectable * item. @@ -1796,6 +1852,25 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ static final int PFLAG2_DRAG_HOVERED = 0x00000002; + /** @hide */ + @IntDef({ + LAYOUT_DIRECTION_LTR, + LAYOUT_DIRECTION_RTL, + LAYOUT_DIRECTION_INHERIT, + LAYOUT_DIRECTION_LOCALE + }) + @Retention(RetentionPolicy.SOURCE) + // Not called LayoutDirection to avoid conflict with android.util.LayoutDirection + public @interface LayoutDir {} + + /** @hide */ + @IntDef({ + LAYOUT_DIRECTION_LTR, + LAYOUT_DIRECTION_RTL + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ResolvedLayoutDir {} + /** * Horizontal layout direction of this view is from Left to Right. * Use with {@link #setLayoutDirection}. @@ -1983,7 +2058,20 @@ public class View implements Drawable.Callback, KeyEvent.Callback, static final int PFLAG2_TEXT_DIRECTION_RESOLVED_DEFAULT = TEXT_DIRECTION_RESOLVED_DEFAULT << PFLAG2_TEXT_DIRECTION_RESOLVED_MASK_SHIFT; - /* + /** @hide */ + @IntDef({ + TEXT_ALIGNMENT_INHERIT, + TEXT_ALIGNMENT_GRAVITY, + TEXT_ALIGNMENT_CENTER, + TEXT_ALIGNMENT_TEXT_START, + TEXT_ALIGNMENT_TEXT_END, + TEXT_ALIGNMENT_VIEW_START, + TEXT_ALIGNMENT_VIEW_END + }) + @Retention(RetentionPolicy.SOURCE) + public @interface TextAlignment {} + + /** * Default text alignment. The text alignment of this View is inherited from its parent. * Use with {@link #setTextAlignment(int)} */ @@ -2595,6 +2683,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + /** @hide */ + @IntDef(flag = true, + value = { FIND_VIEWS_WITH_TEXT, FIND_VIEWS_WITH_CONTENT_DESCRIPTION }) + @Retention(RetentionPolicy.SOURCE) + public @interface FindViewFlags {} + /** * Find views that render the specified text. * @@ -2616,7 +2710,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * added and it is a responsibility of the client to call the APIs of * the provider to determine whether the virtual tree rooted at this View * contains the text, i.e. getting the list of {@link AccessibilityNodeInfo}s - * represeting the virtual views with this text. + * representing the virtual views with this text. * * @see #findViewsWithText(ArrayList, CharSequence, int) * @@ -4532,7 +4626,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param previouslyFocusedRect The rectangle of the view that had focus * prior in this View's coordinate system. */ - void handleFocusGainInternal(int direction, Rect previouslyFocusedRect) { + void handleFocusGainInternal(@FocusRealDirection int direction, Rect previouslyFocusedRect) { if (DBG) { System.out.println(this + " requestFocus()"); } @@ -4743,7 +4837,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * passed in as finer grained information about where the focus is coming * from (in addition to direction). Will be <code>null</code> otherwise. */ - protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) { + protected void onFocusChanged(boolean gainFocus, @FocusDirection int direction, + @Nullable Rect previouslyFocusedRect) { if (gainFocus) { sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); } else { @@ -5599,6 +5694,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @attr ref android.R.styleable#View_drawingCacheQuality */ + @DrawingCacheQuality public int getDrawingCacheQuality() { return mViewFlags & DRAWING_CACHE_QUALITY_MASK; } @@ -5616,7 +5712,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @attr ref android.R.styleable#View_drawingCacheQuality */ - public void setDrawingCacheQuality(int quality) { + public void setDrawingCacheQuality(@DrawingCacheQuality int quality) { setFlags(quality, DRAWING_CACHE_QUALITY_MASK); } @@ -5951,6 +6047,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), @ViewDebug.IntToString(from = GONE, to = "GONE") }) + @Visibility public int getVisibility() { return mViewFlags & VISIBILITY_MASK; } @@ -5962,7 +6059,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @attr ref android.R.styleable#View_visibility */ @RemotableViewMethod - public void setVisibility(int visibility) { + public void setVisibility(@Visibility int visibility) { setFlags(visibility, VISIBILITY_MASK); if (mBackground != null) mBackground.setVisible(visibility == VISIBLE, false); } @@ -6121,6 +6218,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = LAYOUT_DIRECTION_INHERIT, to = "INHERIT"), @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LOCALE, to = "LOCALE") }) + @LayoutDir public int getRawLayoutDirection() { return (mPrivateFlags2 & PFLAG2_LAYOUT_DIRECTION_MASK) >> PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT; } @@ -6143,7 +6241,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @attr ref android.R.styleable#View_layoutDirection */ @RemotableViewMethod - public void setLayoutDirection(int layoutDirection) { + public void setLayoutDirection(@LayoutDir int layoutDirection) { if (getRawLayoutDirection() != layoutDirection) { // Reset the current layout direction and the resolved one mPrivateFlags2 &= ~PFLAG2_LAYOUT_DIRECTION_MASK; @@ -6173,6 +6271,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = LAYOUT_DIRECTION_LTR, to = "RESOLVED_DIRECTION_LTR"), @ViewDebug.IntToString(from = LAYOUT_DIRECTION_RTL, to = "RESOLVED_DIRECTION_RTL") }) + @ResolvedLayoutDir public int getLayoutDirection() { final int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; if (targetSdkVersion < JELLY_BEAN_MR1) { @@ -6542,7 +6641,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @return The nearest focusable in the specified direction, or null if none * can be found. */ - public View focusSearch(int direction) { + public View focusSearch(@FocusRealDirection int direction) { if (mParent != null) { return mParent.focusSearch(this, direction); } else { @@ -6561,7 +6660,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT. * @return True if the this view consumed this unhandled move. */ - public boolean dispatchUnhandledMove(View focused, int direction) { + public boolean dispatchUnhandledMove(View focused, @FocusRealDirection int direction) { return false; } @@ -6573,7 +6672,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * or FOCUS_BACKWARD. * @return The user specified next view, or null if there is none. */ - View findUserSetNextFocus(View root, int direction) { + View findUserSetNextFocus(View root, @FocusDirection int direction) { switch (direction) { case FOCUS_LEFT: if (mNextFocusLeftId == View.NO_ID) return null; @@ -6623,7 +6722,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param direction The direction of the focus * @return A list of focusable views */ - public ArrayList<View> getFocusables(int direction) { + public ArrayList<View> getFocusables(@FocusDirection int direction) { ArrayList<View> result = new ArrayList<View>(24); addFocusables(result, direction); return result; @@ -6637,7 +6736,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param views Focusable views found so far * @param direction The direction of the focus */ - public void addFocusables(ArrayList<View> views, int direction) { + public void addFocusables(ArrayList<View> views, @FocusDirection int direction) { addFocusables(views, direction, FOCUSABLES_TOUCH_MODE); } @@ -6657,7 +6756,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @see #FOCUSABLES_ALL * @see #FOCUSABLES_TOUCH_MODE */ - public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { + public void addFocusables(ArrayList<View> views, @FocusDirection int direction, + @FocusableMode int focusableMode) { if (views == null) { return; } @@ -6686,7 +6786,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @see #FIND_VIEWS_WITH_CONTENT_DESCRIPTION * @see #setContentDescription(CharSequence) */ - public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, int flags) { + public void findViewsWithText(ArrayList<View> outViews, CharSequence searched, + @FindViewFlags int flags) { if (getAccessibilityNodeProvider() != null) { if ((flags & FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS) != 0) { outViews.add(this); @@ -7036,7 +7137,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return isActionableForAccessibility() || hasListenersForAccessibility() || getAccessibilityNodeProvider() != null; default: - throw new IllegalArgumentException("Unknow important for accessibility mode: " + throw new IllegalArgumentException("Unknown important for accessibility mode: " + mode); } } @@ -7108,7 +7209,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** - * Returns whether the View has registered callbacks wich makes it + * Returns whether the View has registered callbacks which makes it * important for accessibility. * * @return True if the view is actionable for accessibility. @@ -7127,7 +7228,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * notification is at at most once every * {@link ViewConfiguration#getSendRecurringAccessibilityEventsInterval()} * to avoid unnecessary load to the system. Also once a view has a pending - * notifucation this method is a NOP until the notification has been sent. + * notification this method is a NOP until the notification has been sent. * * @hide */ @@ -7805,7 +7906,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param visibility The new visibility of changedView: {@link #VISIBLE}, * {@link #INVISIBLE} or {@link #GONE}. */ - protected void dispatchVisibilityChanged(View changedView, int visibility) { + protected void dispatchVisibilityChanged(@NonNull View changedView, + @Visibility int visibility) { onVisibilityChanged(changedView, visibility); } @@ -7816,7 +7918,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param visibility The new visibility of changedView: {@link #VISIBLE}, * {@link #INVISIBLE} or {@link #GONE}. */ - protected void onVisibilityChanged(View changedView, int visibility) { + protected void onVisibilityChanged(@NonNull View changedView, @Visibility int visibility) { if (visibility == VISIBLE) { if (mAttachInfo != null) { initialAwakenScrollBars(); @@ -7835,7 +7937,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param hint A hint about whether or not this view is displayed: * {@link #VISIBLE} or {@link #INVISIBLE}. */ - public void dispatchDisplayHint(int hint) { + public void dispatchDisplayHint(@Visibility int hint) { onDisplayHint(hint); } @@ -7848,7 +7950,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param hint A hint about whether or not this view is displayed: * {@link #VISIBLE} or {@link #INVISIBLE}. */ - protected void onDisplayHint(int hint) { + protected void onDisplayHint(@Visibility int hint) { } /** @@ -7859,7 +7961,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @see #onWindowVisibilityChanged(int) */ - public void dispatchWindowVisibilityChanged(int visibility) { + public void dispatchWindowVisibilityChanged(@Visibility int visibility) { onWindowVisibilityChanged(visibility); } @@ -7873,7 +7975,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @param visibility The new visibility of the window. */ - protected void onWindowVisibilityChanged(int visibility) { + protected void onWindowVisibilityChanged(@Visibility int visibility) { if (visibility == VISIBLE) { initialAwakenScrollBars(); } @@ -7885,6 +7987,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @return Returns the current visibility of the view's window. */ + @Visibility public int getWindowVisibility() { return mAttachInfo != null ? mAttachInfo.mWindowVisibility : GONE; } @@ -11521,7 +11624,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @attr ref android.R.styleable#View_scrollbarStyle */ - public void setScrollBarStyle(int style) { + public void setScrollBarStyle(@ScrollBarStyle int style) { if (style != (mViewFlags & SCROLLBARS_STYLE_MASK)) { mViewFlags = (mViewFlags & ~SCROLLBARS_STYLE_MASK) | (style & SCROLLBARS_STYLE_MASK); computeOpaqueFlags(); @@ -11545,6 +11648,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_OVERLAY, to = "OUTSIDE_OVERLAY"), @ViewDebug.IntToString(from = SCROLLBARS_OUTSIDE_INSET, to = "OUTSIDE_INSET") }) + @ScrollBarStyle public int getScrollBarStyle() { return mViewFlags & SCROLLBARS_STYLE_MASK; } @@ -12044,7 +12148,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @see #LAYOUT_DIRECTION_LTR * @see #LAYOUT_DIRECTION_RTL */ - public void onRtlPropertiesChanged(int layoutDirection) { + public void onRtlPropertiesChanged(@ResolvedLayoutDir int layoutDirection) { } /** @@ -14840,7 +14944,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @hide */ - public void onResolveDrawables(int layoutDirection) { + public void onResolveDrawables(@ResolvedLayoutDir int layoutDirection) { } /** @@ -17636,6 +17740,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") }) + @TextAlignment public int getRawTextAlignment() { return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_MASK) >> PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT; } @@ -17659,7 +17764,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @attr ref android.R.styleable#View_textAlignment */ - public void setTextAlignment(int textAlignment) { + public void setTextAlignment(@TextAlignment int textAlignment) { if (textAlignment != getRawTextAlignment()) { // Reset the current and resolved text alignment mPrivateFlags2 &= ~PFLAG2_TEXT_ALIGNMENT_MASK; @@ -17700,6 +17805,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_START, to = "VIEW_START"), @ViewDebug.IntToString(from = TEXT_ALIGNMENT_VIEW_END, to = "VIEW_END") }) + @TextAlignment public int getTextAlignment() { return (mPrivateFlags2 & PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK) >> PFLAG2_TEXT_ALIGNMENT_RESOLVED_MASK_SHIFT; diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index 7a24243..2606657 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -16,6 +16,8 @@ package android.view; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.content.Context; import android.content.res.Configuration; import android.content.res.TypedArray; @@ -240,6 +242,7 @@ public abstract class Window { * * @see #onPreparePanel */ + @Nullable public View onCreatePanelView(int featureId); /** @@ -368,6 +371,7 @@ public abstract class Window { * @param callback Callback to control the lifecycle of this action mode * @return The ActionMode that was started, or null if the system should present it */ + @Nullable public ActionMode onWindowStartingActionMode(ActionMode.Callback callback); /** @@ -956,6 +960,7 @@ public abstract class Window { * * @return View The current View with focus or null. */ + @Nullable public abstract View getCurrentFocus(); /** @@ -964,6 +969,7 @@ public abstract class Window { * * @return LayoutInflater The shared LayoutInflater. */ + @NonNull public abstract LayoutInflater getLayoutInflater(); public abstract void setTitle(CharSequence title); diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java index e116662..3fe2375 100644 --- a/core/java/android/view/WindowManagerPolicy.java +++ b/core/java/android/view/WindowManagerPolicy.java @@ -16,7 +16,9 @@ package android.view; +import android.annotation.IntDef; import android.content.Context; +import android.content.pm.ActivityInfo; import android.content.res.CompatibilityInfo; import android.content.res.Configuration; import android.graphics.Rect; @@ -27,6 +29,8 @@ import android.os.Looper; import android.view.animation.Animation; import java.io.PrintWriter; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; /** * This interface supplies all UI-specific behavior of the window manager. An @@ -462,6 +466,11 @@ public interface WindowManagerPolicy { /** Screen turned off because of proximity sensor */ public final int OFF_BECAUSE_OF_PROX_SENSOR = 4; + /** @hide */ + @IntDef({USER_ROTATION_FREE, USER_ROTATION_LOCKED}) + @Retention(RetentionPolicy.SOURCE) + public @interface UserRotationMode {} + /** When not otherwise specified by the activity's screenOrientation, rotation should be * determined by the system (that is, using sensors). */ public final int USER_ROTATION_FREE = 0; @@ -1029,7 +1038,8 @@ public interface WindowManagerPolicy { * @param lastRotation The most recently used rotation. * @return The surface rotation to use. */ - public int rotationForOrientationLw(int orientation, int lastRotation); + public int rotationForOrientationLw(@ActivityInfo.ScreenOrientation int orientation, + int lastRotation); /** * Given an orientation constant and a rotation, returns true if the rotation @@ -1044,7 +1054,8 @@ public interface WindowManagerPolicy { * @param rotation The rotation to check. * @return True if the rotation is compatible with the requested orientation. */ - public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation); + public boolean rotationHasCompatibleMetricsLw(@ActivityInfo.ScreenOrientation int orientation, + int rotation); /** * Called by the window manager when the rotation changes. @@ -1093,7 +1104,7 @@ public interface WindowManagerPolicy { */ public void enableScreenAfterBoot(); - public void setCurrentOrientationLw(int newOrientation); + public void setCurrentOrientationLw(@ActivityInfo.ScreenOrientation int newOrientation); /** * Call from application to perform haptic feedback on its window. @@ -1120,6 +1131,7 @@ public interface WindowManagerPolicy { * @see WindowManagerPolicy#USER_ROTATION_LOCKED * @see WindowManagerPolicy#USER_ROTATION_FREE */ + @UserRotationMode public int getUserRotationMode(); /** @@ -1130,12 +1142,12 @@ public interface WindowManagerPolicy { * @param rotation One of {@link Surface#ROTATION_0}, {@link Surface#ROTATION_90}, * {@link Surface#ROTATION_180}, {@link Surface#ROTATION_270}. */ - public void setUserRotationMode(int mode, int rotation); + public void setUserRotationMode(@UserRotationMode int mode, @Surface.Rotation int rotation); /** * Called when a new system UI visibility is being reported, allowing * the policy to adjust what is actually reported. - * @param visibility The raw visiblity reported by the status bar. + * @param visibility The raw visibility reported by the status bar. * @return The new desired visibility. */ public int adjustSystemUiVisibilityLw(int visibility); diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java index 932dac3..4305361 100644 --- a/core/java/android/widget/GridLayout.java +++ b/core/java/android/widget/GridLayout.java @@ -16,6 +16,7 @@ package android.widget; +import android.annotation.IntDef; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -35,6 +36,8 @@ import android.view.accessibility.AccessibilityNodeInfo; import android.widget.RemoteViews.RemoteView; import com.android.internal.R; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; @@ -165,6 +168,11 @@ public class GridLayout extends ViewGroup { // Public constants + /** @hide */ + @IntDef({HORIZONTAL, VERTICAL}) + @Retention(RetentionPolicy.SOURCE) + public @interface Orientation {} + /** * The horizontal orientation. */ @@ -186,6 +194,11 @@ public class GridLayout extends ViewGroup { */ public static final int UNDEFINED = Integer.MIN_VALUE; + /** @hide */ + @IntDef({ALIGN_BOUNDS, ALIGN_MARGINS}) + @Retention(RetentionPolicy.SOURCE) + public @interface AlignmentMode {} + /** * This constant is an {@link #setAlignmentMode(int) alignmentMode}. * When the {@code alignmentMode} is set to {@link #ALIGN_BOUNDS}, alignment @@ -313,6 +326,7 @@ public class GridLayout extends ViewGroup { * * @attr ref android.R.styleable#GridLayout_orientation */ + @Orientation public int getOrientation() { return mOrientation; } @@ -353,7 +367,7 @@ public class GridLayout extends ViewGroup { * * @attr ref android.R.styleable#GridLayout_orientation */ - public void setOrientation(int orientation) { + public void setOrientation(@Orientation int orientation) { if (this.mOrientation != orientation) { this.mOrientation = orientation; invalidateStructure(); @@ -484,6 +498,7 @@ public class GridLayout extends ViewGroup { * * @attr ref android.R.styleable#GridLayout_alignmentMode */ + @AlignmentMode public int getAlignmentMode() { return mAlignmentMode; } @@ -503,7 +518,7 @@ public class GridLayout extends ViewGroup { * * @attr ref android.R.styleable#GridLayout_alignmentMode */ - public void setAlignmentMode(int alignmentMode) { + public void setAlignmentMode(@AlignmentMode int alignmentMode) { this.mAlignmentMode = alignmentMode; requestLayout(); } diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java index cf81476..696c3c4 100644 --- a/core/java/android/widget/GridView.java +++ b/core/java/android/widget/GridView.java @@ -16,6 +16,7 @@ package android.widget; +import android.annotation.IntDef; import android.content.Context; import android.content.Intent; import android.content.res.TypedArray; @@ -36,6 +37,9 @@ import android.view.animation.GridLayoutAnimationController; import android.widget.AbsListView.LayoutParams; import android.widget.RemoteViews.RemoteView; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * A view that shows items in two-dimensional scrolling grid. The items in the @@ -53,6 +57,11 @@ import android.widget.RemoteViews.RemoteView; */ @RemoteView public class GridView extends AbsListView { + /** @hide */ + @IntDef({NO_STRETCH, STRETCH_SPACING, STRETCH_COLUMN_WIDTH, STRETCH_SPACING_UNIFORM}) + @Retention(RetentionPolicy.SOURCE) + public @interface StretchMode {} + /** * Disables stretching. * @@ -2060,13 +2069,14 @@ public class GridView extends AbsListView { * * @attr ref android.R.styleable#GridView_stretchMode */ - public void setStretchMode(int stretchMode) { + public void setStretchMode(@StretchMode int stretchMode) { if (stretchMode != mStretchMode) { mStretchMode = stretchMode; requestLayoutIfNecessary(); } } + @StretchMode public int getStretchMode() { return mStretchMode; } diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java index 9bae7b8..cf562f3 100644 --- a/core/java/android/widget/LinearLayout.java +++ b/core/java/android/widget/LinearLayout.java @@ -18,6 +18,7 @@ package android.widget; import com.android.internal.R; +import android.annotation.IntDef; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -31,6 +32,9 @@ import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.RemoteViews.RemoteView; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * A Layout that arranges its children in a single column or a single row. The direction of @@ -57,9 +61,25 @@ import android.widget.RemoteViews.RemoteView; */ @RemoteView public class LinearLayout extends ViewGroup { + /** @hide */ + @IntDef({HORIZONTAL, VERTICAL}) + @Retention(RetentionPolicy.SOURCE) + public @interface OrientationMode {} + public static final int HORIZONTAL = 0; public static final int VERTICAL = 1; + /** @hide */ + @IntDef(flag = true, + value = { + SHOW_DIVIDER_NONE, + SHOW_DIVIDER_BEGINNING, + SHOW_DIVIDER_MIDDLE, + SHOW_DIVIDER_END + }) + @Retention(RetentionPolicy.SOURCE) + public @interface DividerMode {} + /** * Don't show any dividers. */ @@ -218,7 +238,7 @@ public class LinearLayout extends ViewGroup { * {@link #SHOW_DIVIDER_MIDDLE}, or {@link #SHOW_DIVIDER_END}, * or {@link #SHOW_DIVIDER_NONE} to show no dividers. */ - public void setShowDividers(int showDividers) { + public void setShowDividers(@DividerMode int showDividers) { if (showDividers != mShowDividers) { requestLayout(); } @@ -234,6 +254,7 @@ public class LinearLayout extends ViewGroup { * @return A flag set indicating how dividers should be shown around items. * @see #setShowDividers(int) */ + @DividerMode public int getShowDividers() { return mShowDividers; } @@ -1677,12 +1698,12 @@ public class LinearLayout extends ViewGroup { /** * Should the layout be a column or a row. - * @param orientation Pass HORIZONTAL or VERTICAL. Default - * value is HORIZONTAL. + * @param orientation Pass {@link #HORIZONTAL} or {@link #VERTICAL}. Default + * value is {@link #HORIZONTAL}. * * @attr ref android.R.styleable#LinearLayout_orientation */ - public void setOrientation(int orientation) { + public void setOrientation(@OrientationMode int orientation) { if (mOrientation != orientation) { mOrientation = orientation; requestLayout(); @@ -1694,6 +1715,7 @@ public class LinearLayout extends ViewGroup { * * @return either {@link #HORIZONTAL} or {@link #VERTICAL} */ + @OrientationMode public int getOrientation() { return mOrientation; } diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java index 02491f4..df9917f 100644 --- a/core/java/android/widget/NumberPicker.java +++ b/core/java/android/widget/NumberPicker.java @@ -16,6 +16,7 @@ package android.widget; +import android.annotation.IntDef; import android.annotation.Widget; import android.content.Context; import android.content.res.ColorStateList; @@ -53,6 +54,8 @@ import android.view.inputmethod.InputMethodManager; import com.android.internal.R; import libcore.icu.LocaleData; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -493,6 +496,10 @@ public class NumberPicker extends LinearLayout { * Interface to listen for the picker scroll state. */ public interface OnScrollListener { + /** @hide */ + @IntDef({SCROLL_STATE_IDLE, SCROLL_STATE_TOUCH_SCROLL, SCROLL_STATE_FLING}) + @Retention(RetentionPolicy.SOURCE) + public @interface ScrollState {} /** * The view is not scrolling. @@ -518,7 +525,7 @@ public class NumberPicker extends LinearLayout { * {@link #SCROLL_STATE_TOUCH_SCROLL} or * {@link #SCROLL_STATE_IDLE}. */ - public void onScrollStateChange(NumberPicker view, int scrollState); + public void onScrollStateChange(NumberPicker view, @ScrollState int scrollState); } /** diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java index 4b71e36..46f9adf 100644 --- a/core/java/android/widget/Toast.java +++ b/core/java/android/widget/Toast.java @@ -16,6 +16,7 @@ package android.widget; +import android.annotation.IntDef; import android.app.INotificationManager; import android.app.ITransientNotification; import android.content.Context; @@ -34,6 +35,9 @@ import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * A toast is a view containing a quick little message for the user. The toast class * helps you create and show those. @@ -61,6 +65,11 @@ public class Toast { static final String TAG = "Toast"; static final boolean localLOGV = false; + /** @hide */ + @IntDef({LENGTH_SHORT, LENGTH_LONG}) + @Retention(RetentionPolicy.SOURCE) + public @interface Duration {} + /** * Show the view or text notification for a short period of time. This time * could be user-definable. This is the default. @@ -155,7 +164,7 @@ public class Toast { * @see #LENGTH_SHORT * @see #LENGTH_LONG */ - public void setDuration(int duration) { + public void setDuration(@Duration int duration) { mDuration = duration; } @@ -163,6 +172,7 @@ public class Toast { * Return the duration. * @see #setDuration */ + @Duration public int getDuration() { return mDuration; } @@ -240,7 +250,7 @@ public class Toast { * {@link #LENGTH_LONG} * */ - public static Toast makeText(Context context, CharSequence text, int duration) { + public static Toast makeText(Context context, CharSequence text, @Duration int duration) { Toast result = new Toast(context); LayoutInflater inflate = (LayoutInflater) @@ -266,7 +276,7 @@ public class Toast { * * @throws Resources.NotFoundException if the resource can't be found. */ - public static Toast makeText(Context context, int resId, int duration) + public static Toast makeText(Context context, int resId, @Duration int duration) throws Resources.NotFoundException { return makeText(context, context.getResources().getText(resId), duration); } |