summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2013-05-30 16:48:33 -0700
committerTor Norbye <tnorbye@google.com>2015-02-18 07:49:03 -0800
commit7b9c912f536925ac6ec43935d6e97506851b33d6 (patch)
tree8dd71557e2555fde0d506ef77c46dc29184e91c4 /core
parent44bc07d8740058398d4009615681120168673dd8 (diff)
downloadframeworks_base-7b9c912f536925ac6ec43935d6e97506851b33d6.zip
frameworks_base-7b9c912f536925ac6ec43935d6e97506851b33d6.tar.gz
frameworks_base-7b9c912f536925ac6ec43935d6e97506851b33d6.tar.bz2
Add @ResourceInt annotations on APIs
Change-Id: I119cc059c2f8bd98fd585fc84ac2b1b7d5892a08
Diffstat (limited to 'core')
-rw-r--r--core/java/android/animation/AnimatorInflater.java3
-rw-r--r--core/java/android/app/ActionBar.java25
-rw-r--r--core/java/android/app/Activity.java14
-rw-r--r--core/java/android/app/AlertDialog.java30
-rw-r--r--core/java/android/app/ApplicationPackageManager.java9
-rw-r--r--core/java/android/app/Dialog.java12
-rw-r--r--core/java/android/app/Fragment.java7
-rw-r--r--core/java/android/app/FragmentManager.java3
-rw-r--r--core/java/android/app/Notification.java6
-rw-r--r--core/java/android/app/SearchableInfo.java4
-rw-r--r--core/java/android/app/WallpaperManager.java5
-rw-r--r--core/java/android/content/Context.java13
-rw-r--r--core/java/android/content/Intent.java7
-rw-r--r--core/java/android/content/RestrictionEntry.java5
-rw-r--r--core/java/android/content/pm/PackageManager.java9
-rw-r--r--core/java/android/content/res/Resources.java103
-rw-r--r--core/java/android/content/res/TypedArray.java2
-rw-r--r--core/java/android/gesture/GestureLibraries.java3
-rw-r--r--core/java/android/inputmethodservice/InputMethodService.java3
-rw-r--r--core/java/android/inputmethodservice/Keyboard.java6
-rw-r--r--core/java/android/preference/DialogPreference.java8
-rw-r--r--core/java/android/preference/GenericInflater.java6
-rw-r--r--core/java/android/preference/ListPreference.java5
-rw-r--r--core/java/android/preference/MultiCheckPreference.java5
-rw-r--r--core/java/android/preference/MultiSelectListPreference.java5
-rw-r--r--core/java/android/preference/Preference.java16
-rw-r--r--core/java/android/preference/PreferenceActivity.java17
-rw-r--r--core/java/android/preference/PreferenceManager.java5
-rw-r--r--core/java/android/preference/SwitchPreference.java5
-rw-r--r--core/java/android/preference/TwoStatePreference.java5
-rw-r--r--core/java/android/service/dreams/DreamService.java6
-rw-r--r--core/java/android/speech/tts/TextToSpeech.java5
-rw-r--r--core/java/android/text/style/ImageSpan.java5
-rw-r--r--core/java/android/util/TypedValue.java3
-rw-r--r--core/java/android/view/ActionMode.java6
-rw-r--r--core/java/android/view/ContextMenu.java6
-rw-r--r--core/java/android/view/LayoutInflater.java5
-rw-r--r--core/java/android/view/Menu.java9
-rw-r--r--core/java/android/view/MenuInflater.java3
-rw-r--r--core/java/android/view/MenuItem.java9
-rw-r--r--core/java/android/view/PointerIcon.java5
-rw-r--r--core/java/android/view/SubMenu.java8
-rw-r--r--core/java/android/view/View.java14
-rw-r--r--core/java/android/view/ViewGroup.java3
-rw-r--r--core/java/android/view/ViewStub.java10
-rw-r--r--core/java/android/view/Window.java21
-rw-r--r--core/java/android/view/animation/AnimationUtils.java9
-rw-r--r--core/java/android/widget/AbsListView.java3
-rw-r--r--core/java/android/widget/ActivityChooserView.java5
-rw-r--r--core/java/android/widget/ArrayAdapter.java17
-rw-r--r--core/java/android/widget/AutoCompleteTextView.java3
-rw-r--r--core/java/android/widget/CalendarView.java3
-rw-r--r--core/java/android/widget/CheckedTextView.java4
-rw-r--r--core/java/android/widget/CompoundButton.java1
-rw-r--r--core/java/android/widget/ImageSwitcher.java4
-rw-r--r--core/java/android/widget/ImageView.java3
-rw-r--r--core/java/android/widget/ListView.java3
-rw-r--r--core/java/android/widget/PopupMenu.java3
-rw-r--r--core/java/android/widget/ProgressBar.java3
-rw-r--r--core/java/android/widget/RadioGroup.java8
-rw-r--r--core/java/android/widget/Spinner.java4
-rw-r--r--core/java/android/widget/Switch.java8
-rw-r--r--core/java/android/widget/TabWidget.java7
-rw-r--r--core/java/android/widget/TextView.java21
-rw-r--r--core/java/android/widget/Toast.java5
65 files changed, 362 insertions, 216 deletions
diff --git a/core/java/android/animation/AnimatorInflater.java b/core/java/android/animation/AnimatorInflater.java
index 6ef3da8..d5ae6c6 100644
--- a/core/java/android/animation/AnimatorInflater.java
+++ b/core/java/android/animation/AnimatorInflater.java
@@ -15,6 +15,7 @@
*/
package android.animation;
+import android.annotation.AnimatorRes;
import android.content.Context;
import android.content.res.ConfigurationBoundResourceCache;
import android.content.res.ConstantState;
@@ -82,7 +83,7 @@ public class AnimatorInflater {
* @return The animator object reference by the specified id
* @throws android.content.res.Resources.NotFoundException when the animation cannot be loaded
*/
- public static Animator loadAnimator(Context context, int id)
+ public static Animator loadAnimator(Context context, @AnimatorRes int id)
throws NotFoundException {
return loadAnimator(context.getResources(), context.getTheme(), id);
}
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java
index 014a7af..4cdd397 100644
--- a/core/java/android/app/ActionBar.java
+++ b/core/java/android/app/ActionBar.java
@@ -16,9 +16,12 @@
package android.app;
+import android.annotation.DrawableRes;
import android.annotation.IntDef;
+import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.StringRes;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
@@ -256,7 +259,7 @@ public abstract class ActionBar {
*
* @see #setDisplayOptions(int, int)
*/
- public abstract void setCustomView(int resId);
+ public abstract void setCustomView(@LayoutRes int resId);
/**
* Set the icon to display in the 'home' section of the action bar.
@@ -271,7 +274,7 @@ public abstract class ActionBar {
* @see #setDisplayUseLogoEnabled(boolean)
* @see #setDisplayShowHomeEnabled(boolean)
*/
- public abstract void setIcon(int resId);
+ public abstract void setIcon(@DrawableRes int resId);
/**
* Set the icon to display in the 'home' section of the action bar.
@@ -301,7 +304,7 @@ public abstract class ActionBar {
* @see #setDisplayUseLogoEnabled(boolean)
* @see #setDisplayShowHomeEnabled(boolean)
*/
- public abstract void setLogo(int resId);
+ public abstract void setLogo(@DrawableRes int resId);
/**
* Set the logo to display in the 'home' section of the action bar.
@@ -397,7 +400,7 @@ public abstract class ActionBar {
* @see #setTitle(CharSequence)
* @see #setDisplayOptions(int, int)
*/
- public abstract void setTitle(int resId);
+ public abstract void setTitle(@StringRes int resId);
/**
* Set the action bar's subtitle. This will only be displayed if
@@ -420,7 +423,7 @@ public abstract class ActionBar {
* @see #setSubtitle(CharSequence)
* @see #setDisplayOptions(int, int)
*/
- public abstract void setSubtitle(int resId);
+ public abstract void setSubtitle(@StringRes int resId);
/**
* Set display options. This changes all display option bits at once. To change
@@ -892,7 +895,7 @@ public abstract class ActionBar {
* @see #setDisplayHomeAsUpEnabled(boolean)
* @see #setHomeActionContentDescription(int)
*/
- public void setHomeAsUpIndicator(int resId) { }
+ public void setHomeAsUpIndicator(@DrawableRes int resId) { }
/**
* Set an alternate description for the Home/Up action, when enabled.
@@ -931,7 +934,7 @@ public abstract class ActionBar {
* @see #setHomeAsUpIndicator(int)
* @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
*/
- public void setHomeActionContentDescription(int resId) { }
+ public void setHomeActionContentDescription(@StringRes int resId) { }
/**
* Enable hiding the action bar on content scroll.
@@ -1154,7 +1157,7 @@ public abstract class ActionBar {
* @param resId Resource ID referring to the drawable to use as an icon
* @return The current instance for call chaining
*/
- public abstract Tab setIcon(int resId);
+ public abstract Tab setIcon(@DrawableRes int resId);
/**
* Set the text displayed on this tab. Text may be truncated if there is not
@@ -1172,7 +1175,7 @@ public abstract class ActionBar {
* @param resId A resource ID referring to the text that should be displayed
* @return The current instance for call chaining
*/
- public abstract Tab setText(int resId);
+ public abstract Tab setText(@StringRes int resId);
/**
* Set a custom view to be used for this tab. This overrides values set by
@@ -1190,7 +1193,7 @@ public abstract class ActionBar {
* @param layoutResId A layout resource to inflate and use as a custom tab view
* @return The current instance for call chaining
*/
- public abstract Tab setCustomView(int layoutResId);
+ public abstract Tab setCustomView(@LayoutRes int layoutResId);
/**
* Retrieve a previously set custom view for this tab.
@@ -1235,7 +1238,7 @@ public abstract class ActionBar {
* @see #setContentDescription(CharSequence)
* @see #getContentDescription()
*/
- public abstract Tab setContentDescription(int resId);
+ public abstract Tab setContentDescription(@StringRes int resId);
/**
* Set a description of this tab's content for use in accessibility support.
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index aa1c70e..f0d98f8 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -16,7 +16,13 @@
package android.app;
+import android.annotation.DrawableRes;
+import android.annotation.IdRes;
+import android.annotation.IntDef;
+import android.annotation.LayoutRes;
import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.StyleRes;
import android.os.PersistableBundle;
import android.transition.Scene;
import android.transition.TransitionManager;
@@ -2070,7 +2076,7 @@ public class Activity extends ContextThemeWrapper
* @return The view if found or null otherwise.
*/
@Nullable
- public View findViewById(int id) {
+ public View findViewById(@IdRes int id) {
return getWindow().findViewById(id);
}
@@ -2143,7 +2149,7 @@ public class Activity extends ContextThemeWrapper
* @see #setContentView(android.view.View)
* @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
- public void setContentView(int layoutResID) {
+ public void setContentView(@LayoutRes int layoutResID) {
getWindow().setContentView(layoutResID);
initWindowDecorActionBar();
}
@@ -3611,7 +3617,7 @@ public class Activity extends ContextThemeWrapper
* Convenience for calling
* {@link android.view.Window#setFeatureDrawableResource}.
*/
- public final void setFeatureDrawableResource(int featureId, int resId) {
+ public final void setFeatureDrawableResource(int featureId, @DrawableRes int resId) {
getWindow().setFeatureDrawableResource(featureId, resId);
}
@@ -3666,7 +3672,7 @@ public class Activity extends ContextThemeWrapper
}
@Override
- protected void onApplyThemeResource(Resources.Theme theme, int resid,
+ protected void onApplyThemeResource(Resources.Theme theme, @StyleRes int resid,
boolean first) {
if (mParent == null) {
super.onApplyThemeResource(theme, resid, first);
diff --git a/core/java/android/app/AlertDialog.java b/core/java/android/app/AlertDialog.java
index 3c6458f..c8f58c6 100644
--- a/core/java/android/app/AlertDialog.java
+++ b/core/java/android/app/AlertDialog.java
@@ -18,6 +18,10 @@ package android.app;
import com.android.internal.app.AlertController;
+import android.annotation.ArrayRes;
+import android.annotation.AttrRes;
+import android.annotation.DrawableRes;
+import android.annotation.StringRes;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
@@ -117,7 +121,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
* or one of the constants {@link #THEME_TRADITIONAL},
* {@link #THEME_HOLO_DARK}, or {@link #THEME_HOLO_LIGHT}.
*/
- protected AlertDialog(Context context, int theme) {
+ protected AlertDialog(Context context, @AttrRes int theme) {
this(context, theme, true);
}
@@ -327,7 +331,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
* @param resId the resourceId of the drawable to use as the icon or 0
* if you don't want an icon.
*/
- public void setIcon(int resId) {
+ public void setIcon(@DrawableRes int resId) {
mAlert.setIcon(resId);
}
@@ -340,7 +344,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @param attrId ID of a theme attribute that points to a drawable resource.
*/
- public void setIconAttribute(int attrId) {
+ public void setIconAttribute(@AttrRes int attrId) {
TypedValue out = new TypedValue();
mContext.getTheme().resolveAttribute(attrId, out, true);
mAlert.setIcon(out.resourceId);
@@ -413,7 +417,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
- public Builder setTitle(int titleId) {
+ public Builder setTitle(@StringRes int titleId) {
P.mTitle = P.mContext.getText(titleId);
return this;
}
@@ -449,7 +453,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
- public Builder setMessage(int messageId) {
+ public Builder setMessage(@StringRes int messageId) {
P.mMessage = P.mContext.getText(messageId);
return this;
}
@@ -471,7 +475,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
- public Builder setIcon(int iconId) {
+ public Builder setIcon(@DrawableRes int iconId) {
P.mIconId = iconId;
return this;
}
@@ -495,7 +499,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @param attrId ID of a theme attribute that points to a drawable resource.
*/
- public Builder setIconAttribute(int attrId) {
+ public Builder setIconAttribute(@AttrRes int attrId) {
TypedValue out = new TypedValue();
P.mContext.getTheme().resolveAttribute(attrId, out, true);
P.mIconId = out.resourceId;
@@ -509,7 +513,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
- public Builder setPositiveButton(int textId, final OnClickListener listener) {
+ public Builder setPositiveButton(@StringRes int textId, final OnClickListener listener) {
P.mPositiveButtonText = P.mContext.getText(textId);
P.mPositiveButtonListener = listener;
return this;
@@ -535,7 +539,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
- public Builder setNegativeButton(int textId, final OnClickListener listener) {
+ public Builder setNegativeButton(@StringRes int textId, final OnClickListener listener) {
P.mNegativeButtonText = P.mContext.getText(textId);
P.mNegativeButtonListener = listener;
return this;
@@ -561,7 +565,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
- public Builder setNeutralButton(int textId, final OnClickListener listener) {
+ public Builder setNeutralButton(@StringRes int textId, final OnClickListener listener) {
P.mNeutralButtonText = P.mContext.getText(textId);
P.mNeutralButtonListener = listener;
return this;
@@ -634,7 +638,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
- public Builder setItems(int itemsId, final OnClickListener listener) {
+ public Builder setItems(@ArrayRes int itemsId, final OnClickListener listener) {
P.mItems = P.mContext.getResources().getTextArray(itemsId);
P.mOnClickListener = listener;
return this;
@@ -706,7 +710,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
- public Builder setMultiChoiceItems(int itemsId, boolean[] checkedItems,
+ public Builder setMultiChoiceItems(@ArrayRes int itemsId, boolean[] checkedItems,
final OnMultiChoiceClickListener listener) {
P.mItems = P.mContext.getResources().getTextArray(itemsId);
P.mOnCheckboxClickListener = listener;
@@ -785,7 +789,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
*
* @return This Builder object to allow for chaining of calls to set methods
*/
- public Builder setSingleChoiceItems(int itemsId, int checkedItem,
+ public Builder setSingleChoiceItems(@ArrayRes int itemsId, int checkedItem,
final OnClickListener listener) {
P.mItems = P.mContext.getResources().getTextArray(itemsId);
P.mOnClickListener = listener;
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index d808c8b..f35e746 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -16,6 +16,9 @@
package android.app;
+import android.annotation.DrawableRes;
+import android.annotation.StringRes;
+import android.annotation.XmlRes;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Intent;
@@ -730,7 +733,7 @@ final class ApplicationPackageManager extends PackageManager {
}
}
- @Override public Drawable getDrawable(String packageName, int resid,
+ @Override public Drawable getDrawable(String packageName, @DrawableRes int resid,
ApplicationInfo appInfo) {
ResourceName name = new ResourceName(packageName, resid);
Drawable dr = getCachedIcon(name);
@@ -1137,7 +1140,7 @@ final class ApplicationPackageManager extends PackageManager {
}
@Override
- public CharSequence getText(String packageName, int resid,
+ public CharSequence getText(String packageName, @StringRes int resid,
ApplicationInfo appInfo) {
ResourceName name = new ResourceName(packageName, resid);
CharSequence text = getCachedString(name);
@@ -1170,7 +1173,7 @@ final class ApplicationPackageManager extends PackageManager {
}
@Override
- public XmlResourceParser getXml(String packageName, int resid,
+ public XmlResourceParser getXml(String packageName, @XmlRes int resid,
ApplicationInfo appInfo) {
if (appInfo == null) {
try {
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index a3662b2..e465d57 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -16,6 +16,10 @@
package android.app;
+import android.annotation.DrawableRes;
+import android.annotation.IdRes;
+import android.annotation.LayoutRes;
+import android.annotation.StringRes;
import com.android.internal.app.WindowDecorActionBar;
import android.annotation.Nullable;
@@ -478,7 +482,7 @@ public class Dialog implements DialogInterface, Window.Callback,
* @return The view with the given id or null.
*/
@Nullable
- public View findViewById(int id) {
+ public View findViewById(@IdRes int id) {
return mWindow.findViewById(id);
}
@@ -488,7 +492,7 @@ public class Dialog implements DialogInterface, Window.Callback,
*
* @param layoutResID Resource ID to be inflated.
*/
- public void setContentView(int layoutResID) {
+ public void setContentView(@LayoutRes int layoutResID) {
mWindow.setContentView(layoutResID);
}
@@ -542,7 +546,7 @@ public class Dialog implements DialogInterface, Window.Callback,
*
* @param titleId the title's text resource identifier
*/
- public void setTitle(int titleId) {
+ public void setTitle(@StringRes int titleId) {
setTitle(mContext.getText(titleId));
}
@@ -1072,7 +1076,7 @@ public class Dialog implements DialogInterface, Window.Callback,
* Convenience for calling
* {@link android.view.Window#setFeatureDrawableResource}.
*/
- public final void setFeatureDrawableResource(int featureId, int resId) {
+ public final void setFeatureDrawableResource(int featureId, @DrawableRes int resId) {
getWindow().setFeatureDrawableResource(featureId, resId);
}
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java
index f319309..c5f534c 100644
--- a/core/java/android/app/Fragment.java
+++ b/core/java/android/app/Fragment.java
@@ -18,6 +18,7 @@ package android.app;
import android.animation.Animator;
import android.annotation.Nullable;
+import android.annotation.StringRes;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.Intent;
@@ -795,7 +796,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
*
* @param resId Resource id for the CharSequence text
*/
- public final CharSequence getText(int resId) {
+ public final CharSequence getText(@StringRes int resId) {
return getResources().getText(resId);
}
@@ -805,7 +806,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
*
* @param resId Resource id for the string
*/
- public final String getString(int resId) {
+ public final String getString(@StringRes int resId) {
return getResources().getString(resId);
}
@@ -818,7 +819,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
* @param formatArgs The format arguments that will be used for substitution.
*/
- public final String getString(int resId, Object... formatArgs) {
+ public final String getString(@StringRes int resId, Object... formatArgs) {
return getResources().getString(resId, formatArgs);
}
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index afdc917..975b20d 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -21,6 +21,7 @@ import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.annotation.Nullable;
import android.content.Context;
+import android.annotation.IdRes;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
@@ -396,7 +397,7 @@ final class FragmentManagerState implements Parcelable {
*/
interface FragmentContainer {
@Nullable
- public View findViewById(int id);
+ public View findViewById(@IdRes int id);
public boolean hasView();
}
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 87e744c..9c00e1c 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -16,6 +16,7 @@
package android.app;
+import android.annotation.DrawableRes;
import android.annotation.IntDef;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
@@ -165,6 +166,7 @@ public class Notification implements Parcelable
* The resource id of a drawable to use as the icon in the status bar.
* This is required; notifications with an invalid icon resource will not be shown.
*/
+ @DrawableRes
public int icon;
/**
@@ -2128,7 +2130,7 @@ public class Notification implements Parcelable
* A resource ID in the application's package of the drawable to use.
* @see Notification#icon
*/
- public Builder setSmallIcon(int icon) {
+ public Builder setSmallIcon(@DrawableRes int icon) {
mSmallIcon = icon;
return this;
}
@@ -2144,7 +2146,7 @@ public class Notification implements Parcelable
* @see Notification#icon
* @see Notification#iconLevel
*/
- public Builder setSmallIcon(int icon, int level) {
+ public Builder setSmallIcon(@DrawableRes int icon, int level) {
mSmallIcon = icon;
mSmallIconLevel = level;
return this;
diff --git a/core/java/android/app/SearchableInfo.java b/core/java/android/app/SearchableInfo.java
index 922ebdd..c7d2140 100644
--- a/core/java/android/app/SearchableInfo.java
+++ b/core/java/android/app/SearchableInfo.java
@@ -19,6 +19,7 @@ package android.app;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.annotation.StringRes;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
@@ -682,6 +683,7 @@ public final class SearchableInfo implements Parcelable {
* @return A resource id, or {@code 0} if no language model was specified.
* @see android.R.styleable#Searchable_voiceLanguageModel
*/
+ @StringRes
public int getVoiceLanguageModeId() {
return mVoiceLanguageModeId;
}
@@ -692,6 +694,7 @@ public final class SearchableInfo implements Parcelable {
* @return A resource id, or {@code 0} if no voice prompt text was specified.
* @see android.R.styleable#Searchable_voicePromptText
*/
+ @StringRes
public int getVoicePromptTextId() {
return mVoicePromptTextId;
}
@@ -702,6 +705,7 @@ public final class SearchableInfo implements Parcelable {
* @return A resource id, or {@code 0} if no language was specified.
* @see android.R.styleable#Searchable_voiceLanguage
*/
+ @StringRes
public int getVoiceLanguageId() {
return mVoiceLanguageId;
}
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 90d84ee..dcbd669 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -16,6 +16,7 @@
package android.app;
+import android.annotation.RawRes;
import android.annotation.SystemApi;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -707,7 +708,7 @@ public class WallpaperManager {
* @throws IOException If an error occurs reverting to the built-in
* wallpaper.
*/
- public void setResource(int resid) throws IOException {
+ public void setResource(@RawRes int resid) throws IOException {
if (sGlobals.mService == null) {
Log.w(TAG, "WallpaperService not running");
return;
@@ -823,7 +824,7 @@ public class WallpaperManager {
* with the given resource ID. That is, their wallpaper has been
* set through {@link #setResource(int)} with the same resource id.
*/
- public boolean hasResourceWallpaper(int resid) {
+ public boolean hasResourceWallpaper(@RawRes int resid) {
if (sGlobals.mService == null) {
Log.w(TAG, "WallpaperService not running");
return false;
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index df620d0..eabe297 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -20,6 +20,9 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
+import android.annotation.StringRes;
+import android.annotation.StyleRes;
+import android.annotation.StyleableRes;
import android.annotation.SystemApi;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -365,7 +368,7 @@ public abstract class Context {
*
* @param resId Resource id for the CharSequence text
*/
- public final CharSequence getText(int resId) {
+ public final CharSequence getText(@StringRes int resId) {
return getResources().getText(resId);
}
@@ -375,7 +378,7 @@ public abstract class Context {
*
* @param resId Resource id for the string
*/
- public final String getString(int resId) {
+ public final String getString(@StringRes int resId) {
return getResources().getString(resId);
}
@@ -388,7 +391,7 @@ public abstract class Context {
* @param formatArgs The format arguments that will be used for substitution.
*/
- public final String getString(int resId, Object... formatArgs) {
+ public final String getString(@StringRes int resId, Object... formatArgs) {
return getResources().getString(resId, formatArgs);
}
@@ -450,7 +453,7 @@ public abstract class Context {
*
* @param resid The style resource describing the theme.
*/
- public abstract void setTheme(int resid);
+ public abstract void setTheme(@StyleRes int resid);
/** @hide Needed for some internal implementation... not public because
* you can't assume this actually means anything. */
@@ -484,7 +487,7 @@ public abstract class Context {
* @see Resources.Theme#obtainStyledAttributes(int, int[])
*/
public final TypedArray obtainStyledAttributes(
- int resid, int[] attrs) throws Resources.NotFoundException {
+ @StyleableRes int resid, int[] attrs) throws Resources.NotFoundException {
return getTheme().obtainStyledAttributes(resid, attrs);
}
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 582802b..3222b2b 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -23,6 +23,7 @@ import android.util.ArraySet;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.annotation.AnyRes;
import android.annotation.IntDef;
import android.annotation.SdkConstant;
import android.annotation.SystemApi;
@@ -762,11 +763,11 @@ public class Intent implements Parcelable, Cloneable {
* identifier.
*
* @param context The context of the application.
- * @param resourceId The resource idenfitier for the icon.
+ * @param resourceId The resource identifier for the icon.
* @return A new ShortcutIconResource with the specified's context package name
- * and icon resource idenfitier.
+ * and icon resource identifier.``
*/
- public static ShortcutIconResource fromContext(Context context, int resourceId) {
+ public static ShortcutIconResource fromContext(Context context, @AnyRes int resourceId) {
ShortcutIconResource icon = new ShortcutIconResource();
icon.packageName = context.getPackageName();
icon.resourceName = context.getResources().getResourceName(resourceId);
diff --git a/core/java/android/content/RestrictionEntry.java b/core/java/android/content/RestrictionEntry.java
index 5341ea8..6d79626 100644
--- a/core/java/android/content/RestrictionEntry.java
+++ b/core/java/android/content/RestrictionEntry.java
@@ -16,6 +16,7 @@
package android.content;
+import android.annotation.ArrayRes;
import android.os.Parcel;
import android.os.Parcelable;
@@ -277,7 +278,7 @@ public class RestrictionEntry implements Parcelable {
* @param stringArrayResId the resource id for a string array containing the possible values.
* @see #setChoiceValues(String[])
*/
- public void setChoiceValues(Context context, int stringArrayResId) {
+ public void setChoiceValues(Context context, @ArrayRes int stringArrayResId) {
mChoiceValues = context.getResources().getStringArray(stringArrayResId);
}
@@ -307,7 +308,7 @@ public class RestrictionEntry implements Parcelable {
* @param context the application context, used for retrieving the resources.
* @param stringArrayResId the resource id of a string array containing the possible entries.
*/
- public void setChoiceEntries(Context context, int stringArrayResId) {
+ public void setChoiceEntries(Context context, @ArrayRes int stringArrayResId) {
mChoiceEntries = context.getResources().getStringArray(stringArrayResId);
}
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index e9f7c50..ebc8e1e 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -16,11 +16,14 @@
package android.content.pm;
+import android.annotation.DrawableRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
+import android.annotation.StringRes;
import android.annotation.SystemApi;
+import android.annotation.XmlRes;
import android.app.PackageDeleteObserver;
import android.app.PackageInstallObserver;
import android.app.admin.DevicePolicyManager;
@@ -2710,7 +2713,7 @@ public abstract class PackageManager {
* @return Returns a Drawable holding the requested image. Returns null if
* an image could not be found for any reason.
*/
- public abstract Drawable getDrawable(String packageName, int resid,
+ public abstract Drawable getDrawable(String packageName, @DrawableRes int resid,
ApplicationInfo appInfo);
/**
@@ -3012,7 +3015,7 @@ public abstract class PackageManager {
* @return Returns a CharSequence holding the requested text. Returns null
* if the text could not be found for any reason.
*/
- public abstract CharSequence getText(String packageName, int resid,
+ public abstract CharSequence getText(String packageName, @StringRes int resid,
ApplicationInfo appInfo);
/**
@@ -3031,7 +3034,7 @@ public abstract class PackageManager {
* data. Returns null if the xml resource could not be found for any
* reason.
*/
- public abstract XmlResourceParser getXml(String packageName, int resid,
+ public abstract XmlResourceParser getXml(String packageName, @XmlRes int resid,
ApplicationInfo appInfo);
/**
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index 6fb7299..3e922f2 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -23,8 +23,22 @@ import org.xmlpull.v1.XmlPullParserException;
import android.animation.Animator;
import android.animation.StateListAnimator;
+import android.annotation.AnimRes;
+import android.annotation.AnyRes;
+import android.annotation.ArrayRes;
+import android.annotation.BoolRes;
+import android.annotation.ColorRes;
+import android.annotation.DimenRes;
+import android.annotation.DrawableRes;
+import android.annotation.FractionRes;
+import android.annotation.IntegerRes;
+import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.PluralsRes;
+import android.annotation.RawRes;
+import android.annotation.StringRes;
+import android.annotation.XmlRes;
import android.content.pm.ActivityInfo;
import android.content.res.ColorStateList.ColorStateListFactory;
import android.graphics.Movie;
@@ -287,7 +301,7 @@ public class Resources {
* @return CharSequence The string data associated with the resource, plus
* possibly styled text information.
*/
- public CharSequence getText(int id) throws NotFoundException {
+ public CharSequence getText(@StringRes int id) throws NotFoundException {
CharSequence res = mAssets.getResourceText(id);
if (res != null) {
return res;
@@ -316,7 +330,8 @@ public class Resources {
* @return CharSequence The string data associated with the resource, plus
* possibly styled text information.
*/
- public CharSequence getQuantityText(int id, int quantity) throws NotFoundException {
+ public CharSequence getQuantityText(@PluralsRes int id, int quantity)
+ throws NotFoundException {
NativePluralRules rule = getPluralRule();
CharSequence res = mAssets.getResourceBagText(id,
attrForQuantityCode(rule.quantityForInt(quantity)));
@@ -377,7 +392,7 @@ public class Resources {
* @return String The string data associated with the resource,
* stripped of styled text information.
*/
- public String getString(int id) throws NotFoundException {
+ public String getString(@StringRes int id) throws NotFoundException {
CharSequence res = getText(id);
if (res != null) {
return res.toString();
@@ -405,7 +420,8 @@ public class Resources {
* @return String The string data associated with the resource,
* stripped of styled text information.
*/
- public String getString(int id, Object... formatArgs) throws NotFoundException {
+ public String getString(@StringRes int id, Object... formatArgs)
+ throws NotFoundException {
String raw = getString(id);
return String.format(mConfiguration.locale, raw, formatArgs);
}
@@ -435,7 +451,7 @@ public class Resources {
* @return String The string data associated with the resource,
* stripped of styled text information.
*/
- public String getQuantityString(int id, int quantity, Object... formatArgs)
+ public String getQuantityString(@PluralsRes int id, int quantity, Object... formatArgs)
throws NotFoundException {
String raw = getQuantityText(id, quantity).toString();
return String.format(mConfiguration.locale, raw, formatArgs);
@@ -461,7 +477,8 @@ public class Resources {
* @return String The string data associated with the resource,
* stripped of styled text information.
*/
- public String getQuantityString(int id, int quantity) throws NotFoundException {
+ public String getQuantityString(@PluralsRes int id, int quantity)
+ throws NotFoundException {
return getQuantityText(id, quantity).toString();
}
@@ -479,7 +496,7 @@ public class Resources {
* @return CharSequence The string data associated with the resource, plus
* possibly styled text information, or def if id is 0 or not found.
*/
- public CharSequence getText(int id, CharSequence def) {
+ public CharSequence getText(@StringRes int id, CharSequence def) {
CharSequence res = id != 0 ? mAssets.getResourceText(id) : null;
return res != null ? res : def;
}
@@ -495,7 +512,7 @@ public class Resources {
*
* @return The styled text array associated with the resource.
*/
- public CharSequence[] getTextArray(int id) throws NotFoundException {
+ public CharSequence[] getTextArray(@ArrayRes int id) throws NotFoundException {
CharSequence[] res = mAssets.getResourceTextArray(id);
if (res != null) {
return res;
@@ -515,7 +532,8 @@ public class Resources {
*
* @return The string array associated with the resource.
*/
- public String[] getStringArray(int id) throws NotFoundException {
+ public String[] getStringArray(@ArrayRes int id)
+ throws NotFoundException {
String[] res = mAssets.getResourceStringArray(id);
if (res != null) {
return res;
@@ -535,7 +553,7 @@ public class Resources {
*
* @return The int array associated with the resource.
*/
- public int[] getIntArray(int id) throws NotFoundException {
+ public int[] getIntArray(@ArrayRes int id) throws NotFoundException {
int[] res = mAssets.getArrayIntResource(id);
if (res != null) {
return res;
@@ -557,7 +575,8 @@ public class Resources {
* Be sure to call {@link TypedArray#recycle() TypedArray.recycle()}
* when done with it.
*/
- public TypedArray obtainTypedArray(int id) throws NotFoundException {
+ public TypedArray obtainTypedArray(@ArrayRes int id)
+ throws NotFoundException {
int len = mAssets.getArraySize(id);
if (len < 0) {
throw new NotFoundException("Array resource ID #0x"
@@ -588,7 +607,7 @@ public class Resources {
* @see #getDimensionPixelOffset
* @see #getDimensionPixelSize
*/
- public float getDimension(int id) throws NotFoundException {
+ public float getDimension(@DimenRes int id) throws NotFoundException {
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
@@ -623,7 +642,7 @@ public class Resources {
* @see #getDimension
* @see #getDimensionPixelSize
*/
- public int getDimensionPixelOffset(int id) throws NotFoundException {
+ public int getDimensionPixelOffset(@DimenRes int id) throws NotFoundException {
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
@@ -660,7 +679,7 @@ public class Resources {
* @see #getDimension
* @see #getDimensionPixelOffset
*/
- public int getDimensionPixelSize(int id) throws NotFoundException {
+ public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException {
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
@@ -694,7 +713,7 @@ public class Resources {
*
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
*/
- public float getFraction(int id, int base, int pbase) {
+ public float getFraction(@FractionRes int id, int base, int pbase) {
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
@@ -744,7 +763,7 @@ public class Resources {
*/
@Deprecated
@Nullable
- public Drawable getDrawable(int id) throws NotFoundException {
+ public Drawable getDrawable(@DrawableRes int id) throws NotFoundException {
final Drawable d = getDrawable(id, null);
if (d != null && d.canApplyTheme()) {
Log.w(TAG, "Drawable " + getResourceName(id) + " has unresolved theme "
@@ -769,7 +788,7 @@ public class Resources {
* not exist.
*/
@Nullable
- public Drawable getDrawable(int id, @Nullable Theme theme) throws NotFoundException {
+ public Drawable getDrawable(@DrawableRes int id, @Nullable Theme theme) throws NotFoundException {
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
@@ -817,7 +836,7 @@ public class Resources {
*/
@Deprecated
@Nullable
- public Drawable getDrawableForDensity(int id, int density) throws NotFoundException {
+ public Drawable getDrawableForDensity(@DrawableRes int id, int density) throws NotFoundException {
return getDrawableForDensity(id, density, null);
}
@@ -836,7 +855,7 @@ public class Resources {
* not exist.
*/
@Nullable
- public Drawable getDrawableForDensity(int id, int density, @Nullable Theme theme) {
+ public Drawable getDrawableForDensity(@DrawableRes int id, int density, @Nullable Theme theme) {
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
@@ -880,7 +899,7 @@ public class Resources {
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
*
*/
- public Movie getMovie(int id) throws NotFoundException {
+ public Movie getMovie(@RawRes int id) throws NotFoundException {
InputStream is = openRawResource(id);
Movie movie = Movie.decodeStream(is);
try {
@@ -907,7 +926,7 @@ public class Resources {
* @return A single color value in the form 0xAARRGGBB.
* @deprecated Use {@link #getColor(int, Theme)} instead.
*/
- public int getColor(int id) throws NotFoundException {
+ public int getColor(@ColorRes int id) throws NotFoundException {
return getColor(id, null);
}
@@ -927,7 +946,7 @@ public class Resources {
*
* @return A single color value in the form 0xAARRGGBB.
*/
- public int getColor(int id, @Nullable Theme theme) throws NotFoundException {
+ public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException {
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
@@ -975,7 +994,7 @@ public class Resources {
* @deprecated Use {@link #getColorStateList(int, Theme)} instead.
*/
@Nullable
- public ColorStateList getColorStateList(int id) throws NotFoundException {
+ public ColorStateList getColorStateList(@ColorRes int id) throws NotFoundException {
final ColorStateList csl = getColorStateList(id, null);
if (csl != null && csl.canApplyTheme()) {
Log.w(TAG, "ColorStateList " + getResourceName(id) + " has "
@@ -1005,7 +1024,7 @@ public class Resources {
* color or multiple colors that can be selected based on a state.
*/
@Nullable
- public ColorStateList getColorStateList(int id, @Nullable Theme theme)
+ public ColorStateList getColorStateList(@ColorRes int id, @Nullable Theme theme)
throws NotFoundException {
TypedValue value;
synchronized (mAccessLock) {
@@ -1043,7 +1062,7 @@ public class Resources {
*
* @return Returns the boolean value contained in the resource.
*/
- public boolean getBoolean(int id) throws NotFoundException {
+ public boolean getBoolean(@BoolRes int id) throws NotFoundException {
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
@@ -1071,7 +1090,7 @@ public class Resources {
*
* @return Returns the integer value contained in the resource.
*/
- public int getInteger(int id) throws NotFoundException {
+ public int getInteger(@IntegerRes int id) throws NotFoundException {
synchronized (mAccessLock) {
TypedValue value = mTmpValue;
if (value == null) {
@@ -1136,7 +1155,7 @@ public class Resources {
*
* @see #getXml
*/
- public XmlResourceParser getLayout(int id) throws NotFoundException {
+ public XmlResourceParser getLayout(@LayoutRes int id) throws NotFoundException {
return loadXmlResourceParser(id, "layout");
}
@@ -1160,7 +1179,7 @@ public class Resources {
*
* @see #getXml
*/
- public XmlResourceParser getAnimation(int id) throws NotFoundException {
+ public XmlResourceParser getAnimation(@AnimRes int id) throws NotFoundException {
return loadXmlResourceParser(id, "anim");
}
@@ -1185,7 +1204,7 @@ public class Resources {
*
* @see android.util.AttributeSet
*/
- public XmlResourceParser getXml(int id) throws NotFoundException {
+ public XmlResourceParser getXml(@XmlRes int id) throws NotFoundException {
return loadXmlResourceParser(id, "xml");
}
@@ -1203,7 +1222,7 @@ public class Resources {
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
*
*/
- public InputStream openRawResource(int id) throws NotFoundException {
+ public InputStream openRawResource(@RawRes int id) throws NotFoundException {
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
@@ -1235,7 +1254,8 @@ public class Resources {
*
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
*/
- public InputStream openRawResource(int id, TypedValue value) throws NotFoundException {
+ public InputStream openRawResource(@RawRes int id, TypedValue value)
+ throws NotFoundException {
getValue(id, value, true);
try {
@@ -1270,7 +1290,8 @@ public class Resources {
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
*
*/
- public AssetFileDescriptor openRawResourceFd(int id) throws NotFoundException {
+ public AssetFileDescriptor openRawResourceFd(@RawRes int id)
+ throws NotFoundException {
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
@@ -1315,7 +1336,7 @@ public class Resources {
* @throws NotFoundException Throws NotFoundException if the given ID does not exist.
*
*/
- public void getValue(int id, TypedValue outValue, boolean resolveRefs)
+ public void getValue(@AnyRes int id, TypedValue outValue, boolean resolveRefs)
throws NotFoundException {
boolean found = mAssets.getResourceValue(id, 0, outValue, resolveRefs);
if (found) {
@@ -1338,8 +1359,8 @@ public class Resources {
* not exist.
* @see #getValue(String, TypedValue, boolean)
*/
- public void getValueForDensity(int id, int density, TypedValue outValue, boolean resolveRefs)
- throws NotFoundException {
+ public void getValueForDensity(@AnyRes int id, int density, TypedValue outValue,
+ boolean resolveRefs) throws NotFoundException {
boolean found = mAssets.getResourceValue(id, density, outValue, resolveRefs);
if (found) {
return;
@@ -1698,7 +1719,7 @@ public class Resources {
* @throws NotFoundException Throws NotFoundException if the given ID
* does not exist.
*/
- public Drawable getDrawable(int id) throws NotFoundException {
+ public Drawable getDrawable(@DrawableRes int id) throws NotFoundException {
return Resources.this.getDrawable(id, this);
}
@@ -2103,7 +2124,7 @@ public class Resources {
*
* @hide
*/
- public static boolean resourceHasPackage(int resid) {
+ public static boolean resourceHasPackage(@AnyRes int resid) {
return (resid >>> 24) != 0;
}
@@ -2121,7 +2142,7 @@ public class Resources {
* @see #getResourceTypeName
* @see #getResourceEntryName
*/
- public String getResourceName(int resid) throws NotFoundException {
+ public String getResourceName(@AnyRes int resid) throws NotFoundException {
String str = mAssets.getResourceName(resid);
if (str != null) return str;
throw new NotFoundException("Unable to find resource ID #0x"
@@ -2140,7 +2161,7 @@ public class Resources {
*
* @see #getResourceName
*/
- public String getResourcePackageName(int resid) throws NotFoundException {
+ public String getResourcePackageName(@AnyRes int resid) throws NotFoundException {
String str = mAssets.getResourcePackageName(resid);
if (str != null) return str;
throw new NotFoundException("Unable to find resource ID #0x"
@@ -2159,7 +2180,7 @@ public class Resources {
*
* @see #getResourceName
*/
- public String getResourceTypeName(int resid) throws NotFoundException {
+ public String getResourceTypeName(@AnyRes int resid) throws NotFoundException {
String str = mAssets.getResourceTypeName(resid);
if (str != null) return str;
throw new NotFoundException("Unable to find resource ID #0x"
@@ -2178,7 +2199,7 @@ public class Resources {
*
* @see #getResourceName
*/
- public String getResourceEntryName(int resid) throws NotFoundException {
+ public String getResourceEntryName(@AnyRes int resid) throws NotFoundException {
String str = mAssets.getResourceEntryName(resid);
if (str != null) return str;
throw new NotFoundException("Unable to find resource ID #0x"
diff --git a/core/java/android/content/res/TypedArray.java b/core/java/android/content/res/TypedArray.java
index f15b6b9..3d43304 100644
--- a/core/java/android/content/res/TypedArray.java
+++ b/core/java/android/content/res/TypedArray.java
@@ -16,6 +16,7 @@
package android.content.res;
+import android.annotation.AnyRes;
import android.annotation.Nullable;
import android.graphics.drawable.Drawable;
import android.os.StrictMode;
@@ -786,6 +787,7 @@ public class TypedArray {
* @return Attribute resource identifier, or defValue if not defined.
* @throws RuntimeException if the TypedArray has already been recycled.
*/
+ @AnyRes
public int getResourceId(int index, int defValue) {
if (mRecycled) {
throw new RuntimeException("Cannot make calls to a recycled instance!");
diff --git a/core/java/android/gesture/GestureLibraries.java b/core/java/android/gesture/GestureLibraries.java
index 6d6c156..611d9ab 100644
--- a/core/java/android/gesture/GestureLibraries.java
+++ b/core/java/android/gesture/GestureLibraries.java
@@ -16,6 +16,7 @@
package android.gesture;
+import android.annotation.RawRes;
import android.util.Log;
import static android.gesture.GestureConstants.*;
import android.content.Context;
@@ -44,7 +45,7 @@ public final class GestureLibraries {
return fromFile(context.getFileStreamPath(name));
}
- public static GestureLibrary fromRawResource(Context context, int resourceId) {
+ public static GestureLibrary fromRawResource(Context context, @RawRes int resourceId) {
return new ResourceGestureLibrary(context, resourceId);
}
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index f218b65..481fc2f 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -19,6 +19,7 @@ package android.inputmethodservice;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+import android.annotation.DrawableRes;
import android.app.ActivityManager;
import android.app.Dialog;
import android.content.Context;
@@ -1178,7 +1179,7 @@ public class InputMethodService extends AbstractInputMethodService {
return isExtractViewShown() ? View.GONE : View.INVISIBLE;
}
- public void showStatusIcon(int iconResId) {
+ public void showStatusIcon(@DrawableRes int iconResId) {
mStatusIcon = iconResId;
mImm.showStatusIcon(mToken, getPackageName(), iconResId);
}
diff --git a/core/java/android/inputmethodservice/Keyboard.java b/core/java/android/inputmethodservice/Keyboard.java
index 4fe54c0..45f1889 100644
--- a/core/java/android/inputmethodservice/Keyboard.java
+++ b/core/java/android/inputmethodservice/Keyboard.java
@@ -18,6 +18,7 @@ package android.inputmethodservice;
import org.xmlpull.v1.XmlPullParserException;
+import android.annotation.XmlRes;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -519,7 +520,8 @@ public class Keyboard {
* @param width sets width of keyboard
* @param height sets height of keyboard
*/
- public Keyboard(Context context, int xmlLayoutResId, int modeId, int width, int height) {
+ public Keyboard(Context context, @XmlRes int xmlLayoutResId, int modeId, int width,
+ int height) {
mDisplayWidth = width;
mDisplayHeight = height;
@@ -540,7 +542,7 @@ public class Keyboard {
* @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
* @param modeId keyboard mode identifier
*/
- public Keyboard(Context context, int xmlLayoutResId, int modeId) {
+ public Keyboard(Context context, @XmlRes int xmlLayoutResId, int modeId) {
DisplayMetrics dm = context.getResources().getDisplayMetrics();
mDisplayWidth = dm.widthPixels;
mDisplayHeight = dm.heightPixels;
diff --git a/core/java/android/preference/DialogPreference.java b/core/java/android/preference/DialogPreference.java
index b65eac7..1b226c1 100644
--- a/core/java/android/preference/DialogPreference.java
+++ b/core/java/android/preference/DialogPreference.java
@@ -17,6 +17,8 @@
package android.preference;
+import android.annotation.DrawableRes;
+import android.annotation.StringRes;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
@@ -168,7 +170,7 @@ public abstract class DialogPreference extends Preference implements
*
* @param dialogIconRes The icon, as a resource ID.
*/
- public void setDialogIcon(int dialogIconRes) {
+ public void setDialogIcon(@DrawableRes int dialogIconRes) {
mDialogIcon = getContext().getDrawable(dialogIconRes);
}
@@ -194,7 +196,7 @@ public abstract class DialogPreference extends Preference implements
* @see #setPositiveButtonText(CharSequence)
* @param positiveButtonTextResId The positive button text as a resource.
*/
- public void setPositiveButtonText(int positiveButtonTextResId) {
+ public void setPositiveButtonText(@StringRes int positiveButtonTextResId) {
setPositiveButtonText(getContext().getString(positiveButtonTextResId));
}
@@ -222,7 +224,7 @@ public abstract class DialogPreference extends Preference implements
* @see #setNegativeButtonText(CharSequence)
* @param negativeButtonTextResId The negative button text as a resource.
*/
- public void setNegativeButtonText(int negativeButtonTextResId) {
+ public void setNegativeButtonText(@StringRes int negativeButtonTextResId) {
setNegativeButtonText(getContext().getString(negativeButtonTextResId));
}
diff --git a/core/java/android/preference/GenericInflater.java b/core/java/android/preference/GenericInflater.java
index 7de7d1c..c84dbf1 100644
--- a/core/java/android/preference/GenericInflater.java
+++ b/core/java/android/preference/GenericInflater.java
@@ -23,6 +23,8 @@ import java.util.HashMap;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.annotation.AnyRes;
+import android.annotation.XmlRes;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
@@ -216,7 +218,7 @@ abstract class GenericInflater<T, P extends GenericInflater.Parent> {
* this is the root item; otherwise it is the root of the inflated
* XML file.
*/
- public T inflate(int resource, P root) {
+ public T inflate(@XmlRes int resource, P root) {
return inflate(resource, root, root != null);
}
@@ -256,7 +258,7 @@ abstract class GenericInflater<T, P extends GenericInflater.Parent> {
* attachToRoot is true, this is root; otherwise it is the root of
* the inflated XML file.
*/
- public T inflate(int resource, P root, boolean attachToRoot) {
+ public T inflate(@XmlRes int resource, P root, boolean attachToRoot) {
if (DEBUG) System.out.println("INFLATING from resource: " + resource);
XmlResourceParser parser = getContext().getResources().getXml(resource);
try {
diff --git a/core/java/android/preference/ListPreference.java b/core/java/android/preference/ListPreference.java
index 9482a72..2700373 100644
--- a/core/java/android/preference/ListPreference.java
+++ b/core/java/android/preference/ListPreference.java
@@ -16,6 +16,7 @@
package android.preference;
+import android.annotation.ArrayRes;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
@@ -91,7 +92,7 @@ public class ListPreference extends DialogPreference {
* @see #setEntries(CharSequence[])
* @param entriesResId The entries array as a resource.
*/
- public void setEntries(int entriesResId) {
+ public void setEntries(@ArrayRes int entriesResId) {
setEntries(getContext().getResources().getTextArray(entriesResId));
}
@@ -119,7 +120,7 @@ public class ListPreference extends DialogPreference {
* @see #setEntryValues(CharSequence[])
* @param entryValuesResId The entry values array as a resource.
*/
- public void setEntryValues(int entryValuesResId) {
+ public void setEntryValues(@ArrayRes int entryValuesResId) {
setEntryValues(getContext().getResources().getTextArray(entryValuesResId));
}
diff --git a/core/java/android/preference/MultiCheckPreference.java b/core/java/android/preference/MultiCheckPreference.java
index 57c906d..c1260a4 100644
--- a/core/java/android/preference/MultiCheckPreference.java
+++ b/core/java/android/preference/MultiCheckPreference.java
@@ -18,6 +18,7 @@ package android.preference;
import java.util.Arrays;
+import android.annotation.ArrayRes;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
@@ -96,7 +97,7 @@ public class MultiCheckPreference extends DialogPreference {
* @see #setEntries(CharSequence[])
* @param entriesResId The entries array as a resource.
*/
- public void setEntries(int entriesResId) {
+ public void setEntries(@ArrayRes int entriesResId) {
setEntries(getContext().getResources().getTextArray(entriesResId));
}
@@ -126,7 +127,7 @@ public class MultiCheckPreference extends DialogPreference {
* @see #setEntryValues(CharSequence[])
* @param entryValuesResId The entry values array as a resource.
*/
- public void setEntryValues(int entryValuesResId) {
+ public void setEntryValues(@ArrayRes int entryValuesResId) {
setEntryValuesCS(getContext().getResources().getTextArray(entryValuesResId));
}
diff --git a/core/java/android/preference/MultiSelectListPreference.java b/core/java/android/preference/MultiSelectListPreference.java
index 6c4c20f..138bd87 100644
--- a/core/java/android/preference/MultiSelectListPreference.java
+++ b/core/java/android/preference/MultiSelectListPreference.java
@@ -16,6 +16,7 @@
package android.preference;
+import android.annotation.ArrayRes;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
@@ -87,7 +88,7 @@ public class MultiSelectListPreference extends DialogPreference {
* @see #setEntries(CharSequence[])
* @param entriesResId The entries array as a resource.
*/
- public void setEntries(int entriesResId) {
+ public void setEntries(@ArrayRes int entriesResId) {
setEntries(getContext().getResources().getTextArray(entriesResId));
}
@@ -115,7 +116,7 @@ public class MultiSelectListPreference extends DialogPreference {
* @see #setEntryValues(CharSequence[])
* @param entryValuesResId The entry values array as a resource.
*/
- public void setEntryValues(int entryValuesResId) {
+ public void setEntryValues(@ArrayRes int entryValuesResId) {
setEntryValues(getContext().getResources().getTextArray(entryValuesResId));
}
diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java
index 0224c73..78928b2 100644
--- a/core/java/android/preference/Preference.java
+++ b/core/java/android/preference/Preference.java
@@ -18,6 +18,9 @@ package android.preference;
import com.android.internal.util.CharSequences;
+import android.annotation.DrawableRes;
+import android.annotation.LayoutRes;
+import android.annotation.StringRes;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -424,7 +427,7 @@ public class Preference implements Comparable<Preference> {
* a {@link View}.
* @see #setWidgetLayoutResource(int)
*/
- public void setLayoutResource(int layoutResId) {
+ public void setLayoutResource(@LayoutRes int layoutResId) {
if (layoutResId != mLayoutResId) {
// Layout changed
mCanRecycleLayout = false;
@@ -438,6 +441,7 @@ public class Preference implements Comparable<Preference> {
*
* @return The layout resource ID.
*/
+ @LayoutRes
public int getLayoutResource() {
return mLayoutResId;
}
@@ -452,7 +456,7 @@ public class Preference implements Comparable<Preference> {
* main layout.
* @see #setLayoutResource(int)
*/
- public void setWidgetLayoutResource(int widgetLayoutResId) {
+ public void setWidgetLayoutResource(@LayoutRes int widgetLayoutResId) {
if (widgetLayoutResId != mWidgetLayoutResId) {
// Layout changed
mCanRecycleLayout = false;
@@ -465,6 +469,7 @@ public class Preference implements Comparable<Preference> {
*
* @return The layout resource ID.
*/
+ @LayoutRes
public int getWidgetLayoutResource() {
return mWidgetLayoutResId;
}
@@ -648,7 +653,7 @@ public class Preference implements Comparable<Preference> {
* @see #setTitle(CharSequence)
* @param titleResId The title as a resource ID.
*/
- public void setTitle(int titleResId) {
+ public void setTitle(@StringRes int titleResId) {
setTitle(mContext.getString(titleResId));
mTitleRes = titleResId;
}
@@ -660,6 +665,7 @@ public class Preference implements Comparable<Preference> {
* @return The title resource.
* @see #setTitle(int)
*/
+ @StringRes
public int getTitleRes() {
return mTitleRes;
}
@@ -696,7 +702,7 @@ public class Preference implements Comparable<Preference> {
* @see #setIcon(Drawable)
* @param iconResId The icon as a resource ID.
*/
- public void setIcon(int iconResId) {
+ public void setIcon(@DrawableRes int iconResId) {
mIconResId = iconResId;
setIcon(mContext.getDrawable(iconResId));
}
@@ -739,7 +745,7 @@ public class Preference implements Comparable<Preference> {
* @see #setSummary(CharSequence)
* @param summaryResId The summary as a resource.
*/
- public void setSummary(int summaryResId) {
+ public void setSummary(@StringRes int summaryResId) {
setSummary(mContext.getString(summaryResId));
}
diff --git a/core/java/android/preference/PreferenceActivity.java b/core/java/android/preference/PreferenceActivity.java
index 04cd7d5..0d80c0d 100644
--- a/core/java/android/preference/PreferenceActivity.java
+++ b/core/java/android/preference/PreferenceActivity.java
@@ -16,6 +16,8 @@
package android.preference;
+import android.annotation.StringRes;
+import android.annotation.XmlRes;
import android.app.Fragment;
import android.app.FragmentBreadCrumbs;
import android.app.FragmentManager;
@@ -337,6 +339,7 @@ public abstract class PreferenceActivity extends ListActivity implements
* Resource ID of title of the header that is shown to the user.
* @attr ref android.R.styleable#PreferenceHeader_title
*/
+ @StringRes
public int titleRes;
/**
@@ -349,6 +352,7 @@ public abstract class PreferenceActivity extends ListActivity implements
* Resource ID of optional summary describing what this header controls.
* @attr ref android.R.styleable#PreferenceHeader_summary
*/
+ @StringRes
public int summaryRes;
/**
@@ -361,6 +365,7 @@ public abstract class PreferenceActivity extends ListActivity implements
* Resource ID of optional text to show as the title in the bread crumb.
* @attr ref android.R.styleable#PreferenceHeader_breadCrumbTitle
*/
+ @StringRes
public int breadCrumbTitleRes;
/**
@@ -373,6 +378,7 @@ public abstract class PreferenceActivity extends ListActivity implements
* Resource ID of optional text to show as the short title in the bread crumb.
* @attr ref android.R.styleable#PreferenceHeader_breadCrumbShortTitle
*/
+ @StringRes
public int breadCrumbShortTitleRes;
/**
@@ -797,7 +803,7 @@ public abstract class PreferenceActivity extends ListActivity implements
* @param resid The XML resource to load and parse.
* @param target The list in which the parsed headers should be placed.
*/
- public void loadHeadersFromResource(int resid, List<Header> target) {
+ public void loadHeadersFromResource(@XmlRes int resid, List<Header> target) {
XmlResourceParser parser = null;
try {
parser = getResources().getXml(resid);
@@ -1086,7 +1092,7 @@ public abstract class PreferenceActivity extends ListActivity implements
* fragment.
*/
public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
- int titleRes, int shortTitleRes) {
+ @StringRes int titleRes, int shortTitleRes) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, getClass());
intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentName);
@@ -1124,7 +1130,8 @@ public abstract class PreferenceActivity extends ListActivity implements
* this set of preferences.
*/
public void startWithFragment(String fragmentName, Bundle args,
- Fragment resultTo, int resultRequestCode, int titleRes, int shortTitleRes) {
+ Fragment resultTo, int resultRequestCode, @StringRes int titleRes,
+ @StringRes int shortTitleRes) {
Intent intent = onBuildStartFragmentIntent(fragmentName, args, titleRes, shortTitleRes);
if (resultTo == null) {
startActivity(intent);
@@ -1343,9 +1350,9 @@ public abstract class PreferenceActivity extends ListActivity implements
* preference panel is done. The launched panel must use
* {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
* @param resultRequestCode If resultTo is non-null, this is the caller's
- * request code to be received with the resut.
+ * request code to be received with the result.
*/
- public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
+ public void startPreferencePanel(String fragmentClass, Bundle args, @StringRes int titleRes,
CharSequence titleText, Fragment resultTo, int resultRequestCode) {
if (mSinglePane) {
startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleRes, 0);
diff --git a/core/java/android/preference/PreferenceManager.java b/core/java/android/preference/PreferenceManager.java
index 0a0e625..55ee77a 100644
--- a/core/java/android/preference/PreferenceManager.java
+++ b/core/java/android/preference/PreferenceManager.java
@@ -16,6 +16,7 @@
package android.preference;
+import android.annotation.XmlRes;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
@@ -263,7 +264,7 @@ public class PreferenceManager {
* root).
* @hide
*/
- public PreferenceScreen inflateFromResource(Context context, int resId,
+ public PreferenceScreen inflateFromResource(Context context, @XmlRes int resId,
PreferenceScreen rootPreferences) {
// Block commits
setNoCommit(true);
@@ -438,7 +439,7 @@ public class PreferenceManager {
* and clear it followed by a call to this method with this
* parameter set to true.
*/
- public static void setDefaultValues(Context context, int resId, boolean readAgain) {
+ public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain) {
// Use the default shared preferences name and mode
setDefaultValues(context, getDefaultSharedPreferencesName(context),
diff --git a/core/java/android/preference/SwitchPreference.java b/core/java/android/preference/SwitchPreference.java
index 53b5aad..9c3cefc 100644
--- a/core/java/android/preference/SwitchPreference.java
+++ b/core/java/android/preference/SwitchPreference.java
@@ -16,6 +16,7 @@
package android.preference;
+import android.annotation.StringRes;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
@@ -169,7 +170,7 @@ public class SwitchPreference extends TwoStatePreference {
*
* @param resId The text as a string resource ID
*/
- public void setSwitchTextOn(int resId) {
+ public void setSwitchTextOn(@StringRes int resId) {
setSwitchTextOn(getContext().getString(resId));
}
@@ -179,7 +180,7 @@ public class SwitchPreference extends TwoStatePreference {
*
* @param resId The text as a string resource ID
*/
- public void setSwitchTextOff(int resId) {
+ public void setSwitchTextOff(@StringRes int resId) {
setSwitchTextOff(getContext().getString(resId));
}
diff --git a/core/java/android/preference/TwoStatePreference.java b/core/java/android/preference/TwoStatePreference.java
index 3823b27..7037aca 100644
--- a/core/java/android/preference/TwoStatePreference.java
+++ b/core/java/android/preference/TwoStatePreference.java
@@ -16,6 +16,7 @@
package android.preference;
+import android.annotation.StringRes;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
@@ -116,7 +117,7 @@ public abstract class TwoStatePreference extends Preference {
* @see #setSummaryOn(CharSequence)
* @param summaryResId The summary as a resource.
*/
- public void setSummaryOn(int summaryResId) {
+ public void setSummaryOn(@StringRes int summaryResId) {
setSummaryOn(getContext().getString(summaryResId));
}
@@ -144,7 +145,7 @@ public abstract class TwoStatePreference extends Preference {
* @see #setSummaryOff(CharSequence)
* @param summaryResId The summary as a resource.
*/
- public void setSummaryOff(int summaryResId) {
+ public void setSummaryOff(@StringRes int summaryResId) {
setSummaryOff(getContext().getString(summaryResId));
}
diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java
index d410622..df4d7e0 100644
--- a/core/java/android/service/dreams/DreamService.java
+++ b/core/java/android/service/dreams/DreamService.java
@@ -18,6 +18,8 @@ package android.service.dreams;
import java.io.FileDescriptor;
import java.io.PrintWriter;
+import android.annotation.IdRes;
+import android.annotation.LayoutRes;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
@@ -383,7 +385,7 @@ public class DreamService extends Service implements Window.Callback {
* @see #setContentView(android.view.View)
* @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
- public void setContentView(int layoutResID) {
+ public void setContentView(@LayoutRes int layoutResID) {
getWindow().setContentView(layoutResID);
}
@@ -444,7 +446,7 @@ public class DreamService extends Service implements Window.Callback {
* @return The view if found or null otherwise.
*/
@Nullable
- public View findViewById(int id) {
+ public View findViewById(@IdRes int id) {
return getWindow().findViewById(id);
}
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index 06e9ce0..f0ad951 100644
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -15,6 +15,7 @@
*/
package android.speech.tts;
+import android.annotation.RawRes;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.ComponentName;
@@ -884,7 +885,7 @@ public class TextToSpeech {
*
* @return Code indicating success or failure. See {@link #ERROR} and {@link #SUCCESS}.
*/
- public int addSpeech(String text, String packagename, int resourceId) {
+ public int addSpeech(String text, String packagename, @RawRes int resourceId) {
synchronized (mStartLock) {
mUtterances.put(text, makeResourceUri(packagename, resourceId));
return SUCCESS;
@@ -993,7 +994,7 @@ public class TextToSpeech {
*
* @return Code indicating success or failure. See {@link #ERROR} and {@link #SUCCESS}.
*/
- public int addEarcon(String earcon, String packagename, int resourceId) {
+ public int addEarcon(String earcon, String packagename, @RawRes int resourceId) {
synchronized(mStartLock) {
mEarcons.put(earcon, makeResourceUri(packagename, resourceId));
return SUCCESS;
diff --git a/core/java/android/text/style/ImageSpan.java b/core/java/android/text/style/ImageSpan.java
index 3d6f8e6..856dd0b 100644
--- a/core/java/android/text/style/ImageSpan.java
+++ b/core/java/android/text/style/ImageSpan.java
@@ -16,6 +16,7 @@
package android.text.style;
+import android.annotation.DrawableRes;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -110,7 +111,7 @@ public class ImageSpan extends DynamicDrawableSpan {
mSource = uri.toString();
}
- public ImageSpan(Context context, int resourceId) {
+ public ImageSpan(Context context, @DrawableRes int resourceId) {
this(context, resourceId, ALIGN_BOTTOM);
}
@@ -118,7 +119,7 @@ public class ImageSpan extends DynamicDrawableSpan {
* @param verticalAlignment one of {@link DynamicDrawableSpan#ALIGN_BOTTOM} or
* {@link DynamicDrawableSpan#ALIGN_BASELINE}.
*/
- public ImageSpan(Context context, int resourceId, int verticalAlignment) {
+ public ImageSpan(Context context, @DrawableRes int resourceId, int verticalAlignment) {
super(verticalAlignment);
mContext = context;
mResourceId = resourceId;
diff --git a/core/java/android/util/TypedValue.java b/core/java/android/util/TypedValue.java
index 74d4245..98aaa81 100644
--- a/core/java/android/util/TypedValue.java
+++ b/core/java/android/util/TypedValue.java
@@ -16,6 +16,8 @@
package android.util;
+import android.annotation.AnyRes;
+
/**
* Container for a dynamically typed data value. Primarily used with
* {@link android.content.res.Resources} for holding resource values.
@@ -178,6 +180,7 @@ public class TypedValue {
public int assetCookie;
/** If Value came from a resource, this holds the corresponding resource id. */
+ @AnyRes
public int resourceId;
/** If Value came from a resource, these are the configurations for which
diff --git a/core/java/android/view/ActionMode.java b/core/java/android/view/ActionMode.java
index ae4b60f..a018138 100644
--- a/core/java/android/view/ActionMode.java
+++ b/core/java/android/view/ActionMode.java
@@ -17,6 +17,8 @@
package android.view;
+import android.annotation.StringRes;
+
/**
* Represents a contextual mode of the user interface. Action modes can be used to provide
* alternative interaction modes and replace parts of the normal UI until finished.
@@ -93,7 +95,7 @@ public abstract class ActionMode {
* @see #setTitle(CharSequence)
* @see #setCustomView(View)
*/
- public abstract void setTitle(int resId);
+ public abstract void setTitle(@StringRes int resId);
/**
* Set the subtitle of the action mode. This method will have no visible effect if
@@ -115,7 +117,7 @@ public abstract class ActionMode {
* @see #setSubtitle(CharSequence)
* @see #setCustomView(View)
*/
- public abstract void setSubtitle(int resId);
+ public abstract void setSubtitle(@StringRes int resId);
/**
* Set whether or not the title/subtitle display for this action mode
diff --git a/core/java/android/view/ContextMenu.java b/core/java/android/view/ContextMenu.java
index decabcb..85fe421 100644
--- a/core/java/android/view/ContextMenu.java
+++ b/core/java/android/view/ContextMenu.java
@@ -16,6 +16,8 @@
package android.view;
+import android.annotation.DrawableRes;
+import android.annotation.StringRes;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.widget.AdapterView;
@@ -44,7 +46,7 @@ public interface ContextMenu extends Menu {
* @param titleRes The string resource identifier used for the title.
* @return This ContextMenu so additional setters can be called.
*/
- public ContextMenu setHeaderTitle(int titleRes);
+ public ContextMenu setHeaderTitle(@StringRes int titleRes);
/**
* Sets the context menu header's title to the title given in <var>title</var>.
@@ -61,7 +63,7 @@ public interface ContextMenu extends Menu {
* @param iconRes The resource identifier used for the icon.
* @return This ContextMenu so additional setters can be called.
*/
- public ContextMenu setHeaderIcon(int iconRes);
+ public ContextMenu setHeaderIcon(@DrawableRes int iconRes);
/**
* Sets the context menu header's icon to the icon given in <var>icon</var>
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java
index a5225cb..1014573 100644
--- a/core/java/android/view/LayoutInflater.java
+++ b/core/java/android/view/LayoutInflater.java
@@ -21,6 +21,7 @@ import com.android.internal.R;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.annotation.LayoutRes;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Resources;
@@ -369,7 +370,7 @@ public abstract class LayoutInflater {
* this is the root View; otherwise it is the root of the inflated
* XML file.
*/
- public View inflate(int resource, @Nullable ViewGroup root) {
+ public View inflate(@LayoutRes int resource, @Nullable ViewGroup root) {
return inflate(resource, root, root != null);
}
@@ -410,7 +411,7 @@ public abstract class LayoutInflater {
* attachToRoot is true, this is root; otherwise it is the root of
* the inflated XML file.
*/
- public View inflate(int resource, @Nullable ViewGroup root, boolean attachToRoot) {
+ public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot) {
final Resources res = getContext().getResources();
if (DEBUG) {
Log.d(TAG, "INFLATING from resource: \"" + res.getResourceName(resource) + "\" ("
diff --git a/core/java/android/view/Menu.java b/core/java/android/view/Menu.java
index 7157bc5..0c2e9cf 100644
--- a/core/java/android/view/Menu.java
+++ b/core/java/android/view/Menu.java
@@ -16,6 +16,7 @@
package android.view;
+import android.annotation.StringRes;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
@@ -148,7 +149,7 @@ public interface Menu {
* @param titleRes Resource identifier of title string.
* @return The newly added menu item.
*/
- public MenuItem add(int titleRes);
+ public MenuItem add(@StringRes int titleRes);
/**
* Add a new item to the menu. This item displays the given title for its
@@ -182,7 +183,7 @@ public interface Menu {
* @param titleRes Resource identifier of title string.
* @return The newly added menu item.
*/
- public MenuItem add(int groupId, int itemId, int order, int titleRes);
+ public MenuItem add(int groupId, int itemId, int order, @StringRes int titleRes);
/**
* Add a new sub-menu to the menu. This item displays the given title for
@@ -202,7 +203,7 @@ public interface Menu {
* @param titleRes Resource identifier of title string.
* @return The newly added sub-menu
*/
- SubMenu addSubMenu(final int titleRes);
+ SubMenu addSubMenu(@StringRes final int titleRes);
/**
* Add a new sub-menu to the menu. This item displays the given
@@ -239,7 +240,7 @@ public interface Menu {
* @param titleRes Resource identifier of title string.
* @return The newly added sub-menu
*/
- SubMenu addSubMenu(int groupId, int itemId, int order, int titleRes);
+ SubMenu addSubMenu(int groupId, int itemId, int order, @StringRes int titleRes);
/**
* Add a group of menu items corresponding to actions that can be performed
diff --git a/core/java/android/view/MenuInflater.java b/core/java/android/view/MenuInflater.java
index 5811c17..3492aa0 100644
--- a/core/java/android/view/MenuInflater.java
+++ b/core/java/android/view/MenuInflater.java
@@ -21,6 +21,7 @@ import com.android.internal.view.menu.MenuItemImpl;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.annotation.MenuRes;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
@@ -101,7 +102,7 @@ public class MenuInflater {
* @param menu The Menu to inflate into. The items and submenus will be
* added to this Menu.
*/
- public void inflate(int menuRes, Menu menu) {
+ public void inflate(@MenuRes int menuRes, Menu menu) {
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
diff --git a/core/java/android/view/MenuItem.java b/core/java/android/view/MenuItem.java
index e706c9c..9e8b97e 100644
--- a/core/java/android/view/MenuItem.java
+++ b/core/java/android/view/MenuItem.java
@@ -16,6 +16,9 @@
package android.view;
+import android.annotation.DrawableRes;
+import android.annotation.LayoutRes;
+import android.annotation.StringRes;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
@@ -165,7 +168,7 @@ public interface MenuItem {
* @see #setTitleCondensed(CharSequence)
*/
- public MenuItem setTitle(int title);
+ public MenuItem setTitle(@StringRes int title);
/**
* Retrieve the current title of the item.
@@ -214,7 +217,7 @@ public interface MenuItem {
* @param iconRes The new icon (as a resource ID) to be displayed.
* @return This Item so additional setters can be called.
*/
- public MenuItem setIcon(int iconRes);
+ public MenuItem setIcon(@DrawableRes int iconRes);
/**
* Returns the icon for this item as a Drawable (getting it from resources if it hasn't been
@@ -511,7 +514,7 @@ public interface MenuItem {
*
* @see #setShowAsAction(int)
*/
- public MenuItem setActionView(int resId);
+ public MenuItem setActionView(@LayoutRes int resId);
/**
* Returns the currently set action view for this menu item.
diff --git a/core/java/android/view/PointerIcon.java b/core/java/android/view/PointerIcon.java
index 7dcad68..cf35ce5 100644
--- a/core/java/android/view/PointerIcon.java
+++ b/core/java/android/view/PointerIcon.java
@@ -18,6 +18,7 @@ package android.view;
import com.android.internal.util.XmlUtils;
+import android.annotation.XmlRes;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -192,7 +193,7 @@ public final class PointerIcon implements Parcelable {
* @throws Resources.NotFoundException if the resource was not found or the drawable
* linked in the resource was not found.
*/
- public static PointerIcon loadCustomIcon(Resources resources, int resourceId) {
+ public static PointerIcon loadCustomIcon(Resources resources, @XmlRes int resourceId) {
if (resources == null) {
throw new IllegalArgumentException("resources must not be null");
}
@@ -373,7 +374,7 @@ public final class PointerIcon implements Parcelable {
return true;
}
- private void loadResource(Context context, Resources resources, int resourceId) {
+ private void loadResource(Context context, Resources resources, @XmlRes int resourceId) {
final XmlResourceParser parser = resources.getXml(resourceId);
final int bitmapRes;
final float hotSpotX;
diff --git a/core/java/android/view/SubMenu.java b/core/java/android/view/SubMenu.java
index 196a183..38662b0 100644
--- a/core/java/android/view/SubMenu.java
+++ b/core/java/android/view/SubMenu.java
@@ -16,6 +16,8 @@
package android.view;
+import android.annotation.DrawableRes;
+import android.annotation.StringRes;
import android.graphics.drawable.Drawable;
/**
@@ -38,7 +40,7 @@ public interface SubMenu extends Menu {
* @param titleRes The string resource identifier used for the title.
* @return This SubMenu so additional setters can be called.
*/
- public SubMenu setHeaderTitle(int titleRes);
+ public SubMenu setHeaderTitle(@StringRes int titleRes);
/**
* Sets the submenu header's title to the title given in <var>title</var>.
@@ -55,7 +57,7 @@ public interface SubMenu extends Menu {
* @param iconRes The resource identifier used for the icon.
* @return This SubMenu so additional setters can be called.
*/
- public SubMenu setHeaderIcon(int iconRes);
+ public SubMenu setHeaderIcon(@DrawableRes int iconRes);
/**
* Sets the submenu header's icon to the icon given in <var>icon</var>
@@ -88,7 +90,7 @@ public interface SubMenu extends Menu {
* @param iconRes The new icon (as a resource ID) to be displayed.
* @return This SubMenu so additional setters can be called.
*/
- public SubMenu setIcon(int iconRes);
+ public SubMenu setIcon(@DrawableRes int iconRes);
/**
* Change the icon associated with this submenu's item in its parent menu.
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ad5d651..f99d2d5 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -18,6 +18,8 @@ package android.view;
import android.animation.AnimatorInflater;
import android.animation.StateListAnimator;
+import android.annotation.DrawableRes;
+import android.annotation.IdRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -1593,6 +1595,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #setId(int)
* @see #getId()
*/
+ @IdRes
@ViewDebug.ExportedProperty(resolveId = true)
int mID = NO_ID;
@@ -6062,7 +6065,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @param id The labeled view id.
*/
@RemotableViewMethod
- public void setLabelFor(int id) {
+ public void setLabelFor(@IdRes int id) {
if (mLabelForId == id) {
return;
}
@@ -16242,7 +16245,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @attr ref android.R.styleable#View_background
*/
@RemotableViewMethod
- public void setBackgroundResource(int resid) {
+ public void setBackgroundResource(@DrawableRes int resid) {
if (resid != 0 && resid == mBackgroundResource) {
return;
}
@@ -17070,7 +17073,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @param id the id of the view to be found
* @return the view of the specified id, null if cannot be found
*/
- protected View findViewTraversal(int id) {
+ protected View findViewTraversal(@IdRes int id) {
if (id == mID) {
return this;
}
@@ -17110,7 +17113,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @return The view that has the given id in the hierarchy or null
*/
@Nullable
- public final View findViewById(int id) {
+ public final View findViewById(@IdRes int id) {
if (id < 0) {
return null;
}
@@ -17225,7 +17228,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*
* @attr ref android.R.styleable#View_id
*/
- public void setId(int id) {
+ public void setId(@IdRes int id) {
mID = id;
if (mID == View.NO_ID && mLabelForId != View.NO_ID) {
mID = generateViewId();
@@ -17265,6 +17268,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* @see #findViewById(int)
* @attr ref android.R.styleable#View_id
*/
+ @IdRes
@ViewDebug.CapturedViewProperty
public int getId() {
return mID;
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 504a758..a49d8c3 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -17,6 +17,7 @@
package android.view;
import android.animation.LayoutTransition;
+import android.annotation.IdRes;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
@@ -3612,7 +3613,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
* {@hide}
*/
@Override
- protected View findViewTraversal(int id) {
+ protected View findViewTraversal(@IdRes int id) {
if (id == mID) {
return this;
}
diff --git a/core/java/android/view/ViewStub.java b/core/java/android/view/ViewStub.java
index 9f9ed5b..ec852e8 100644
--- a/core/java/android/view/ViewStub.java
+++ b/core/java/android/view/ViewStub.java
@@ -16,6 +16,8 @@
package android.view;
+import android.annotation.IdRes;
+import android.annotation.LayoutRes;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
@@ -87,7 +89,7 @@ public final class ViewStub extends View {
* @param context The application's environment.
* @param layoutResource The reference to a layout resource that will be inflated.
*/
- public ViewStub(Context context, int layoutResource) {
+ public ViewStub(Context context, @LayoutRes int layoutResource) {
this(context, null);
mLayoutResource = layoutResource;
@@ -125,6 +127,7 @@ public final class ViewStub extends View {
* @see #setInflatedId(int)
* @attr ref android.R.styleable#ViewStub_inflatedId
*/
+ @IdRes
public int getInflatedId() {
return mInflatedId;
}
@@ -140,7 +143,7 @@ public final class ViewStub extends View {
* @attr ref android.R.styleable#ViewStub_inflatedId
*/
@android.view.RemotableViewMethod
- public void setInflatedId(int inflatedId) {
+ public void setInflatedId(@IdRes int inflatedId) {
mInflatedId = inflatedId;
}
@@ -156,6 +159,7 @@ public final class ViewStub extends View {
* @see #inflate()
* @attr ref android.R.styleable#ViewStub_layout
*/
+ @LayoutRes
public int getLayoutResource() {
return mLayoutResource;
}
@@ -173,7 +177,7 @@ public final class ViewStub extends View {
* @attr ref android.R.styleable#ViewStub_layout
*/
@android.view.RemotableViewMethod
- public void setLayoutResource(int layoutResource) {
+ public void setLayoutResource(@LayoutRes int layoutResource) {
mLayoutResource = layoutResource;
}
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index 8964862..e332135 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -16,6 +16,9 @@
package android.view;
+import android.annotation.DrawableRes;
+import android.annotation.IdRes;
+import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
@@ -985,7 +988,7 @@ public abstract class Window {
* @return The view if found or null otherwise.
*/
@Nullable
- public View findViewById(int id) {
+ public View findViewById(@IdRes int id) {
return getDecorView().findViewById(id);
}
@@ -998,7 +1001,7 @@ public abstract class Window {
* @param layoutResID Resource ID to be inflated.
* @see #setContentView(View, android.view.ViewGroup.LayoutParams)
*/
- public abstract void setContentView(int layoutResID);
+ public abstract void setContentView(@LayoutRes int layoutResID);
/**
* Convenience for
@@ -1128,7 +1131,7 @@ public abstract class Window {
* @param resId The resource identifier of a drawable resource which will
* be installed as the new background.
*/
- public void setBackgroundDrawableResource(int resId) {
+ public void setBackgroundDrawableResource(@DrawableRes int resId) {
setBackgroundDrawable(mContext.getDrawable(resId));
}
@@ -1144,7 +1147,7 @@ public abstract class Window {
/**
* Set the value for a drawable feature of this window, from a resource
- * identifier. You must have called requestFeauture(featureId) before
+ * identifier. You must have called requestFeature(featureId) before
* calling this function.
*
* @see android.content.res.Resources#getDrawable(int)
@@ -1153,7 +1156,7 @@ public abstract class Window {
* constant by Window.
* @param resId Resource identifier of the desired image.
*/
- public abstract void setFeatureDrawableResource(int featureId, int resId);
+ public abstract void setFeatureDrawableResource(int featureId, @DrawableRes int resId);
/**
* Set the value for a drawable feature of this window, from a URI. You
@@ -1423,7 +1426,7 @@ public abstract class Window {
*
* @param resId resource ID of a drawable to set
*/
- public void setIcon(int resId) { }
+ public void setIcon(@DrawableRes int resId) { }
/**
* Set the default icon for this window.
@@ -1432,7 +1435,7 @@ public abstract class Window {
*
* @hide
*/
- public void setDefaultIcon(int resId) { }
+ public void setDefaultIcon(@DrawableRes int resId) { }
/**
* Set the logo for this window. A logo is often shown in place of an
@@ -1441,7 +1444,7 @@ public abstract class Window {
*
* @param resId resource ID of a drawable to set
*/
- public void setLogo(int resId) { }
+ public void setLogo(@DrawableRes int resId) { }
/**
* Set the default logo for this window.
@@ -1450,7 +1453,7 @@ public abstract class Window {
*
* @hide
*/
- public void setDefaultLogo(int resId) { }
+ public void setDefaultLogo(@DrawableRes int resId) { }
/**
* Set focus locally. The window should have the
diff --git a/core/java/android/view/animation/AnimationUtils.java b/core/java/android/view/animation/AnimationUtils.java
index 606c83e..4d1209a 100644
--- a/core/java/android/view/animation/AnimationUtils.java
+++ b/core/java/android/view/animation/AnimationUtils.java
@@ -19,6 +19,8 @@ package android.view.animation;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.annotation.AnimRes;
+import android.annotation.InterpolatorRes;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
@@ -65,7 +67,7 @@ public class AnimationUtils {
* @return The animation object reference by the specified id
* @throws NotFoundException when the animation cannot be loaded
*/
- public static Animation loadAnimation(Context context, int id)
+ public static Animation loadAnimation(Context context, @AnimRes int id)
throws NotFoundException {
XmlResourceParser parser = null;
@@ -143,7 +145,7 @@ public class AnimationUtils {
* @return The animation object reference by the specified id
* @throws NotFoundException when the layout animation controller cannot be loaded
*/
- public static LayoutAnimationController loadLayoutAnimation(Context context, int id)
+ public static LayoutAnimationController loadLayoutAnimation(Context context, @AnimRes int id)
throws NotFoundException {
XmlResourceParser parser = null;
@@ -266,7 +268,8 @@ public class AnimationUtils {
* @return The animation object reference by the specified id
* @throws NotFoundException
*/
- public static Interpolator loadInterpolator(Context context, int id) throws NotFoundException {
+ public static Interpolator loadInterpolator(Context context, @InterpolatorRes int id)
+ throws NotFoundException {
XmlResourceParser parser = null;
try {
parser = context.getResources().getAnimation(id);
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index e87a117..164283d 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -16,6 +16,7 @@
package android.widget;
+import android.annotation.DrawableRes;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
@@ -2712,7 +2713,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
*
* @attr ref android.R.styleable#AbsListView_listSelector
*/
- public void setSelector(int resID) {
+ public void setSelector(@DrawableRes int resID) {
setSelector(getContext().getDrawable(resID));
}
diff --git a/core/java/android/widget/ActivityChooserView.java b/core/java/android/widget/ActivityChooserView.java
index f9af2f9..f34ad71 100644
--- a/core/java/android/widget/ActivityChooserView.java
+++ b/core/java/android/widget/ActivityChooserView.java
@@ -18,6 +18,7 @@ package android.widget;
import com.android.internal.R;
+import android.annotation.StringRes;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -334,7 +335,7 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod
*
* @param resourceId The content description resource id.
*/
- public void setExpandActivityOverflowButtonContentDescription(int resourceId) {
+ public void setExpandActivityOverflowButtonContentDescription(@StringRes int resourceId) {
CharSequence contentDescription = mContext.getString(resourceId);
mExpandActivityOverflowButtonImage.setContentDescription(contentDescription);
}
@@ -514,7 +515,7 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod
*
* @param resourceId The resource id.
*/
- public void setDefaultActionButtonContentDescription(int resourceId) {
+ public void setDefaultActionButtonContentDescription(@StringRes int resourceId) {
mDefaultActionButtonContentDescription = resourceId;
}
diff --git a/core/java/android/widget/ArrayAdapter.java b/core/java/android/widget/ArrayAdapter.java
index aff5e29..89e508f 100644
--- a/core/java/android/widget/ArrayAdapter.java
+++ b/core/java/android/widget/ArrayAdapter.java
@@ -16,6 +16,9 @@
package android.widget;
+import android.annotation.ArrayRes;
+import android.annotation.IdRes;
+import android.annotation.LayoutRes;
import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
@@ -106,7 +109,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable,
* @param resource The resource ID for a layout file containing a TextView to use when
* instantiating views.
*/
- public ArrayAdapter(Context context, int resource) {
+ public ArrayAdapter(Context context, @LayoutRes int resource) {
this(context, resource, 0, new ArrayList<T>());
}
@@ -118,7 +121,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable,
* instantiating views.
* @param textViewResourceId The id of the TextView within the layout resource to be populated
*/
- public ArrayAdapter(Context context, int resource, int textViewResourceId) {
+ public ArrayAdapter(Context context, @LayoutRes int resource, @IdRes int textViewResourceId) {
this(context, resource, textViewResourceId, new ArrayList<T>());
}
@@ -130,7 +133,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable,
* instantiating views.
* @param objects The objects to represent in the ListView.
*/
- public ArrayAdapter(Context context, int resource, T[] objects) {
+ public ArrayAdapter(Context context, @LayoutRes int resource, T[] objects) {
this(context, resource, 0, Arrays.asList(objects));
}
@@ -143,7 +146,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable,
* @param textViewResourceId The id of the TextView within the layout resource to be populated
* @param objects The objects to represent in the ListView.
*/
- public ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects) {
+ public ArrayAdapter(Context context, @LayoutRes int resource, @IdRes int textViewResourceId, T[] objects) {
this(context, resource, textViewResourceId, Arrays.asList(objects));
}
@@ -155,7 +158,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable,
* instantiating views.
* @param objects The objects to represent in the ListView.
*/
- public ArrayAdapter(Context context, int resource, List<T> objects) {
+ public ArrayAdapter(Context context, @LayoutRes int resource, List<T> objects) {
this(context, resource, 0, objects);
}
@@ -405,7 +408,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable,
* @param resource the layout resource defining the drop down views
* @see #getDropDownView(int, android.view.View, android.view.ViewGroup)
*/
- public void setDropDownViewResource(int resource) {
+ public void setDropDownViewResource(@LayoutRes int resource) {
this.mDropDownResource = resource;
}
@@ -457,7 +460,7 @@ public class ArrayAdapter<T> extends BaseAdapter implements Filterable,
* @return An ArrayAdapter<CharSequence>.
*/
public static ArrayAdapter<CharSequence> createFromResource(Context context,
- int textArrayResId, int textViewResId) {
+ @ArrayRes int textArrayResId, @LayoutRes int textViewResId) {
CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
return new ArrayAdapter<CharSequence>(context, textViewResId, strings);
}
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index e6392b9..01767d5 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -16,6 +16,7 @@
package android.widget;
+import android.annotation.DrawableRes;
import android.content.Context;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
@@ -356,7 +357,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
*
* @attr ref android.R.styleable#PopupWindow_popupBackground
*/
- public void setDropDownBackgroundResource(int id) {
+ public void setDropDownBackgroundResource(@DrawableRes int id) {
mPopup.setBackgroundDrawable(getContext().getDrawable(id));
}
diff --git a/core/java/android/widget/CalendarView.java b/core/java/android/widget/CalendarView.java
index 5e43916..47fb8a7 100644
--- a/core/java/android/widget/CalendarView.java
+++ b/core/java/android/widget/CalendarView.java
@@ -16,6 +16,7 @@
package android.widget;
+import android.annotation.DrawableRes;
import android.annotation.Widget;
import android.content.Context;
import android.content.res.Configuration;
@@ -253,7 +254,7 @@ public class CalendarView extends FrameLayout {
*
* @attr ref android.R.styleable#CalendarView_selectedDateVerticalBar
*/
- public void setSelectedDateVerticalBar(int resourceId) {
+ public void setSelectedDateVerticalBar(@DrawableRes int resourceId) {
mDelegate.setSelectedDateVerticalBar(resourceId);
}
diff --git a/core/java/android/widget/CheckedTextView.java b/core/java/android/widget/CheckedTextView.java
index 344d00a..84f0ee5 100644
--- a/core/java/android/widget/CheckedTextView.java
+++ b/core/java/android/widget/CheckedTextView.java
@@ -18,6 +18,7 @@ package android.widget;
import com.android.internal.R;
+import android.annotation.DrawableRes;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.ColorStateList;
@@ -32,7 +33,6 @@ import android.view.ViewDebug;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
-
/**
* An extension to TextView that supports the {@link android.widget.Checkable} interface.
* This is useful when used in a {@link android.widget.ListView ListView} where the it's
@@ -141,7 +141,7 @@ public class CheckedTextView extends TextView implements Checkable {
*
* @attr ref android.R.styleable#CheckedTextView_checkMark
*/
- public void setCheckMarkDrawable(int resid) {
+ public void setCheckMarkDrawable(@DrawableRes int resid) {
if (resid != 0 && resid == mCheckMarkResource) {
return;
}
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java
index f2afeeb..dbf82b6 100644
--- a/core/java/android/widget/CompoundButton.java
+++ b/core/java/android/widget/CompoundButton.java
@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.graphics.PorterDuff;
import com.android.internal.R;
+import android.annotation.DrawableRes;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
diff --git a/core/java/android/widget/ImageSwitcher.java b/core/java/android/widget/ImageSwitcher.java
index 80e908a..81636a7 100644
--- a/core/java/android/widget/ImageSwitcher.java
+++ b/core/java/android/widget/ImageSwitcher.java
@@ -16,6 +16,7 @@
package android.widget;
+import android.annotation.DrawableRes;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@@ -23,7 +24,6 @@ import android.util.AttributeSet;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
-
public class ImageSwitcher extends ViewSwitcher
{
public ImageSwitcher(Context context)
@@ -35,7 +35,7 @@ public class ImageSwitcher extends ViewSwitcher
super(context, attrs);
}
- public void setImageResource(int resid)
+ public void setImageResource(@DrawableRes int resid)
{
ImageView image = (ImageView)this.getNextView();
image.setImageResource(resid);
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index dd9bdb6..9831dca 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -16,6 +16,7 @@
package android.widget;
+import android.annotation.DrawableRes;
import android.annotation.Nullable;
import android.content.ContentResolver;
import android.content.Context;
@@ -387,7 +388,7 @@ public class ImageView extends View {
* @attr ref android.R.styleable#ImageView_src
*/
@android.view.RemotableViewMethod
- public void setImageResource(int resId) {
+ public void setImageResource(@DrawableRes int resId) {
// The resource configuration may have changed, so we should always
// try to load the resource even if the resId hasn't changed.
final int oldWidth = mDrawableWidth;
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index 0aaef6d..f9c7faa 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -21,6 +21,7 @@ import com.android.internal.R;
import com.android.internal.util.Predicate;
import com.google.android.collect.Lists;
+import android.annotation.IdRes;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
@@ -3630,7 +3631,7 @@ public class ListView extends AbsListView {
* First look in our children, then in any header and footer views that may be scrolled off.
*/
@Override
- protected View findViewTraversal(int id) {
+ protected View findViewTraversal(@IdRes int id) {
View v;
v = super.findViewTraversal(id);
if (v == null) {
diff --git a/core/java/android/widget/PopupMenu.java b/core/java/android/widget/PopupMenu.java
index 06ac1c3..1507dfb 100644
--- a/core/java/android/widget/PopupMenu.java
+++ b/core/java/android/widget/PopupMenu.java
@@ -22,6 +22,7 @@ import com.android.internal.view.menu.MenuPopupHelper;
import com.android.internal.view.menu.MenuPresenter;
import com.android.internal.view.menu.SubMenuBuilder;
+import android.annotation.MenuRes;
import android.content.Context;
import android.view.Gravity;
import android.view.Menu;
@@ -205,7 +206,7 @@ public class PopupMenu implements MenuBuilder.Callback, MenuPresenter.Callback {
* popupMenu.getMenuInflater().inflate(menuRes, popupMenu.getMenu()).
* @param menuRes Menu resource to inflate
*/
- public void inflate(int menuRes) {
+ public void inflate(@MenuRes int menuRes) {
getMenuInflater().inflate(menuRes, mMenu);
}
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index 5b0745e..406a274 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -21,6 +21,7 @@ import android.graphics.PorterDuff;
import com.android.internal.R;
+import android.annotation.InterpolatorRes;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
@@ -1508,7 +1509,7 @@ public class ProgressBar extends View {
* @param context The application environment
* @param resID The resource identifier of the interpolator to load
*/
- public void setInterpolator(Context context, int resID) {
+ public void setInterpolator(Context context, @InterpolatorRes int resID) {
setInterpolator(AnimationUtils.loadInterpolator(context, resID));
}
diff --git a/core/java/android/widget/RadioGroup.java b/core/java/android/widget/RadioGroup.java
index f04bb3d..6586d11 100644
--- a/core/java/android/widget/RadioGroup.java
+++ b/core/java/android/widget/RadioGroup.java
@@ -18,6 +18,7 @@ package android.widget;
import com.android.internal.R;
+import android.annotation.IdRes;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
@@ -151,7 +152,7 @@ public class RadioGroup extends LinearLayout {
* @see #getCheckedRadioButtonId()
* @see #clearCheck()
*/
- public void check(int id) {
+ public void check(@IdRes int id) {
// don't even bother
if (id != -1 && (id == mCheckedId)) {
return;
@@ -168,7 +169,7 @@ public class RadioGroup extends LinearLayout {
setCheckedId(id);
}
- private void setCheckedId(int id) {
+ private void setCheckedId(@IdRes int id) {
mCheckedId = id;
if (mOnCheckedChangeListener != null) {
mOnCheckedChangeListener.onCheckedChanged(this, mCheckedId);
@@ -193,6 +194,7 @@ public class RadioGroup extends LinearLayout {
*
* @attr ref android.R.styleable#RadioGroup_checkedButton
*/
+ @IdRes
public int getCheckedRadioButtonId() {
return mCheckedId;
}
@@ -331,7 +333,7 @@ public class RadioGroup extends LinearLayout {
* @param group the group in which the checked radio button has changed
* @param checkedId the unique identifier of the newly checked radio button
*/
- public void onCheckedChanged(RadioGroup group, int checkedId);
+ public void onCheckedChanged(RadioGroup group, @IdRes int checkedId);
}
private class CheckedStateTracker implements CompoundButton.OnCheckedChangeListener {
diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java
index 6ee2b4c..f0bc303 100644
--- a/core/java/android/widget/Spinner.java
+++ b/core/java/android/widget/Spinner.java
@@ -18,6 +18,7 @@ package android.widget;
import com.android.internal.R;
+import android.annotation.DrawableRes;
import android.annotation.Nullable;
import android.annotation.Widget;
import android.app.AlertDialog;
@@ -46,7 +47,6 @@ import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ListPopupWindow.ForwardingListener;
import android.widget.PopupWindow.OnDismissListener;
-
/**
* A view that displays one child at a time and lets the user pick among them.
* The items in the Spinner come from the {@link Adapter} associated with
@@ -331,7 +331,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
*
* @attr ref android.R.styleable#Spinner_popupBackground
*/
- public void setPopupBackgroundResource(int resId) {
+ public void setPopupBackgroundResource(@DrawableRes int resId) {
setPopupBackgroundDrawable(getPopupContext().getDrawable(resId));
}
diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java
index b959ddc..ce1834e 100644
--- a/core/java/android/widget/Switch.java
+++ b/core/java/android/widget/Switch.java
@@ -17,7 +17,9 @@
package android.widget;
import android.animation.ObjectAnimator;
+import android.annotation.DrawableRes;
import android.annotation.Nullable;
+import android.annotation.StyleRes;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
@@ -263,7 +265,7 @@ public class Switch extends CompoundButton {
*
* @attr ref android.R.styleable#Switch_switchTextAppearance
*/
- public void setSwitchTextAppearance(Context context, int resid) {
+ public void setSwitchTextAppearance(Context context, @StyleRes int resid) {
TypedArray appearance =
context.obtainStyledAttributes(resid,
com.android.internal.R.styleable.TextAppearance);
@@ -471,7 +473,7 @@ public class Switch extends CompoundButton {
*
* @attr ref android.R.styleable#Switch_track
*/
- public void setTrackResource(int resId) {
+ public void setTrackResource(@DrawableRes int resId) {
setTrackDrawable(getContext().getDrawable(resId));
}
@@ -593,7 +595,7 @@ public class Switch extends CompoundButton {
*
* @attr ref android.R.styleable#Switch_thumb
*/
- public void setThumbResource(int resId) {
+ public void setThumbResource(@DrawableRes int resId) {
setThumbDrawable(getContext().getDrawable(resId));
}
diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java
index 88ecb13..f90a0a7 100644
--- a/core/java/android/widget/TabWidget.java
+++ b/core/java/android/widget/TabWidget.java
@@ -17,6 +17,7 @@
package android.widget;
import android.R;
+import android.annotation.DrawableRes;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -244,7 +245,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
* @param resId the resource identifier of the drawable to use as a
* divider.
*/
- public void setDividerDrawable(int resId) {
+ public void setDividerDrawable(@DrawableRes int resId) {
setDividerDrawable(mContext.getDrawable(resId));
}
@@ -265,7 +266,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
* @param resId the resource identifier of the drawable to use as the
* left strip drawable
*/
- public void setLeftStripDrawable(int resId) {
+ public void setLeftStripDrawable(@DrawableRes int resId) {
setLeftStripDrawable(mContext.getDrawable(resId));
}
@@ -286,7 +287,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
* @param resId the resource identifier of the drawable to use as the
* right strip drawable
*/
- public void setRightStripDrawable(int resId) {
+ public void setRightStripDrawable(@DrawableRes int resId) {
setRightStripDrawable(mContext.getDrawable(resId));
}
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 848c1c0..f33ef75 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -17,8 +17,12 @@
package android.widget;
import android.R;
+import android.annotation.DrawableRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.StringRes;
+import android.annotation.StyleRes;
+import android.annotation.XmlRes;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
@@ -2173,7 +2177,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* @attr ref android.R.styleable#TextView_drawableBottom
*/
@android.view.RemotableViewMethod
- public void setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) {
+ public void setCompoundDrawablesWithIntrinsicBounds(@DrawableRes int left,
+ @DrawableRes int top, @DrawableRes int right, @DrawableRes int bottom) {
final Context context = getContext();
setCompoundDrawablesWithIntrinsicBounds(left != 0 ? context.getDrawable(left) : null,
top != 0 ? context.getDrawable(top) : null,
@@ -2374,8 +2379,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* @attr ref android.R.styleable#TextView_drawableBottom
*/
@android.view.RemotableViewMethod
- public void setCompoundDrawablesRelativeWithIntrinsicBounds(int start, int top, int end,
- int bottom) {
+ public void setCompoundDrawablesRelativeWithIntrinsicBounds(@DrawableRes int start,
+ @DrawableRes int top, @DrawableRes int end, @DrawableRes int bottom) {
final Context context = getContext();
setCompoundDrawablesRelativeWithIntrinsicBounds(
start != 0 ? context.getDrawable(start) : null,
@@ -2643,7 +2648,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* Sets the text color, size, style, hint color, and highlight color
* from the specified TextAppearance resource.
*/
- public void setTextAppearance(Context context, int resid) {
+ public void setTextAppearance(Context context, @StyleRes int resid) {
TypedArray appearance =
context.obtainStyledAttributes(resid,
com.android.internal.R.styleable.TextAppearance);
@@ -4267,11 +4272,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
@android.view.RemotableViewMethod
- public final void setText(int resid) {
+ public final void setText(@StringRes int resid) {
setText(getContext().getResources().getText(resid));
}
- public final void setText(int resid, BufferType type) {
+ public final void setText(@StringRes int resid, BufferType type) {
setText(getContext().getResources().getText(resid), type);
}
@@ -4307,7 +4312,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* @attr ref android.R.styleable#TextView_hint
*/
@android.view.RemotableViewMethod
- public final void setHint(int resid) {
+ public final void setHint(@StringRes int resid) {
setHint(getContext().getResources().getText(resid));
}
@@ -4711,7 +4716,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* @see EditorInfo#extras
* @attr ref android.R.styleable#TextView_editorExtras
*/
- public void setInputExtras(int xmlResId) throws XmlPullParserException, IOException {
+ public void setInputExtras(@XmlRes int xmlResId) throws XmlPullParserException, IOException {
createEditorIfNeeded();
XmlResourceParser parser = getResources().getXml(xmlResId);
mEditor.createInputContentTypeIfNeeded();
diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java
index be4cdc1..207f675 100644
--- a/core/java/android/widget/Toast.java
+++ b/core/java/android/widget/Toast.java
@@ -17,6 +17,7 @@
package android.widget;
import android.annotation.IntDef;
+import android.annotation.StringRes;
import android.app.INotificationManager;
import android.app.ITransientNotification;
import android.content.Context;
@@ -280,7 +281,7 @@ public class Toast {
*
* @throws Resources.NotFoundException if the resource can't be found.
*/
- public static Toast makeText(Context context, int resId, @Duration int duration)
+ public static Toast makeText(Context context, @StringRes int resId, @Duration int duration)
throws Resources.NotFoundException {
return makeText(context, context.getResources().getText(resId), duration);
}
@@ -289,7 +290,7 @@ public class Toast {
* Update the text in a Toast that was previously created using one of the makeText() methods.
* @param resId The new text for the Toast.
*/
- public void setText(int resId) {
+ public void setText(@StringRes int resId) {
setText(mContext.getText(resId));
}