Skip to content

Commit

Permalink
Merge "Add resource type annotations to some APIs"
Browse files Browse the repository at this point in the history
  • Loading branch information
tnorbye authored and Android (Google) Code Review committed Mar 16, 2015
2 parents 716475d + 417ee5b commit da81fa5
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 29 deletions.
3 changes: 2 additions & 1 deletion core/java/android/preference/PreferenceFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package android.preference;

import android.annotation.Nullable;
import android.annotation.XmlRes;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
Expand Down Expand Up @@ -294,7 +295,7 @@ public void addPreferencesFromIntent(Intent intent) {
*
* @param preferencesResId The XML resource ID to inflate.
*/
public void addPreferencesFromResource(int preferencesResId) {
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
requirePreferenceManager();

setPreferenceScreen(mPreferenceManager.inflateFromResource(getActivity(),
Expand Down
2 changes: 1 addition & 1 deletion core/java/android/speech/tts/TextToSpeech.java
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ public int addSpeech(String text, String packagename, @RawRes int resourceId) {
*
* @return Code indicating success or failure. See {@link #ERROR} and {@link #SUCCESS}.
*/
public int addSpeech(CharSequence text, String packagename, int resourceId) {
public int addSpeech(CharSequence text, String packagename, @RawRes int resourceId) {
synchronized (mStartLock) {
mUtterances.put(text, makeResourceUri(packagename, resourceId));
return SUCCESS;
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/view/ContextThemeWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package android.view;

import android.annotation.StyleRes;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Configuration;
Expand All @@ -36,7 +37,7 @@ public ContextThemeWrapper() {
super(null);
}

public ContextThemeWrapper(Context base, int themeResId) {
public ContextThemeWrapper(Context base, @StyleRes int themeResId) {
super(base);
mThemeResource = themeResId;
}
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.annotation.FloatRange;
import android.annotation.IdRes;
import android.annotation.IntDef;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
Expand Down Expand Up @@ -18646,7 +18647,7 @@ private void checkForLongClick(int delayOffset) {
* layout_* parameters.
* @see LayoutInflater
*/
public static View inflate(Context context, int resource, ViewGroup root) {
public static View inflate(Context context, @LayoutRes int resource, ViewGroup root) {
LayoutInflater factory = LayoutInflater.from(context);
return factory.inflate(resource, root);
}
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/view/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StyleRes;
import android.annotation.SystemApi;
import android.content.Context;
import android.content.res.Configuration;
Expand Down Expand Up @@ -753,7 +754,7 @@ public void setFormat(int format) {
* 0 here will override the animations the window would
* normally retrieve from its theme.
*/
public void setWindowAnimations(int resId) {
public void setWindowAnimations(@StyleRes int resId) {
final WindowManager.LayoutParams attrs = getAttributes();
attrs.windowAnimations = resId;
dispatchWindowAttributesChanged(attrs);
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/view/animation/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package android.view.animation;

import android.annotation.ColorInt;
import android.annotation.InterpolatorRes;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.RectF;
Expand Down Expand Up @@ -388,7 +389,7 @@ public void run() {
* @param resID The resource identifier of the interpolator to load
* @attr ref android.R.styleable#Animation_interpolator
*/
public void setInterpolator(Context context, int resID) {
public void setInterpolator(Context context, @InterpolatorRes int resID) {
setInterpolator(AnimationUtils.loadInterpolator(context, resID));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package android.view.animation;

import android.annotation.AnimRes;
import android.annotation.InterpolatorRes;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
Expand Down Expand Up @@ -180,7 +182,7 @@ public void setOrder(int order) {
*
* @attr ref android.R.styleable#LayoutAnimation_animation
*/
public void setAnimation(Context context, int resourceID) {
public void setAnimation(Context context, @AnimRes int resourceID) {
setAnimation(AnimationUtils.loadAnimation(context, resourceID));
}

Expand Down Expand Up @@ -225,7 +227,7 @@ public Animation getAnimation() {
*
* @attr ref android.R.styleable#LayoutAnimation_interpolator
*/
public void setInterpolator(Context context, int resourceID) {
public void setInterpolator(Context context, @InterpolatorRes int resourceID) {
setInterpolator(AnimationUtils.loadInterpolator(context, resourceID));
}

Expand Down
3 changes: 2 additions & 1 deletion core/java/android/widget/ActionMenuView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package android.widget;

import android.annotation.StyleRes;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
Expand Down Expand Up @@ -86,7 +87,7 @@ public ActionMenuView(Context context, AttributeSet attrs) {
* @param resId theme used to inflate popup menus
* @see #getPopupTheme()
*/
public void setPopupTheme(int resId) {
public void setPopupTheme(@StyleRes int resId) {
if (mPopupTheme != resId) {
mPopupTheme = resId;
if (resId == 0) {
Expand Down
11 changes: 7 additions & 4 deletions core/java/android/widget/ArrayAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.annotation.ArrayRes;
import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.annotation.NonNull;
import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
Expand Down Expand Up @@ -133,7 +134,7 @@ public ArrayAdapter(Context context, @LayoutRes int resource, @IdRes int textVie
* instantiating views.
* @param objects The objects to represent in the ListView.
*/
public ArrayAdapter(Context context, @LayoutRes int resource, T[] objects) {
public ArrayAdapter(Context context, @LayoutRes int resource, @NonNull T[] objects) {
this(context, resource, 0, Arrays.asList(objects));
}

Expand All @@ -146,7 +147,8 @@ public ArrayAdapter(Context context, @LayoutRes int resource, T[] objects) {
* @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, @LayoutRes int resource, @IdRes int textViewResourceId, T[] objects) {
public ArrayAdapter(Context context, @LayoutRes int resource, @IdRes int textViewResourceId,
@NonNull T[] objects) {
this(context, resource, textViewResourceId, Arrays.asList(objects));
}

Expand All @@ -158,7 +160,7 @@ public ArrayAdapter(Context context, @LayoutRes int resource, @IdRes int textVie
* instantiating views.
* @param objects The objects to represent in the ListView.
*/
public ArrayAdapter(Context context, @LayoutRes int resource, List<T> objects) {
public ArrayAdapter(Context context, @LayoutRes int resource, @NonNull List<T> objects) {
this(context, resource, 0, objects);
}

Expand All @@ -171,7 +173,8 @@ public ArrayAdapter(Context context, @LayoutRes int resource, List<T> objects) {
* @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, List<T> objects) {
public ArrayAdapter(Context context, @LayoutRes int resource, @IdRes int textViewResourceId,
@NonNull List<T> objects) {
mContext = context;
mInflater = LayoutInflater.from(context);
mResource = mDropDownResource = resource;
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/widget/FastScroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.annotation.StyleRes;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
Expand Down Expand Up @@ -326,7 +327,7 @@ private void updateAppearance() {
refreshDrawablePressedState();
}

public void setStyle(int resId) {
public void setStyle(@StyleRes int resId) {
final Context context = mList.getContext();
final TypedArray ta = context.obtainStyledAttributes(null,
com.android.internal.R.styleable.FastScroll, android.R.attr.fastScrollStyle, resId);
Expand Down
4 changes: 3 additions & 1 deletion core/java/android/widget/SimpleAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package android.widget;

import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.content.Context;
import android.content.res.Resources;
import android.view.ContextThemeWrapper;
Expand Down Expand Up @@ -82,7 +84,7 @@ public class SimpleAdapter extends BaseAdapter implements Filterable, Spinner.Th
* in the from parameter.
*/
public SimpleAdapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
@LayoutRes int resource, String[] from, @IdRes int[] to) {
mData = data;
mResource = mDropDownResource = resource;
mFrom = from;
Expand Down
24 changes: 14 additions & 10 deletions core/java/android/widget/Toolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
package android.widget;

import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.MenuRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringRes;
import android.annotation.StyleRes;
import android.app.ActionBar;
import android.content.Context;
import android.content.res.ColorStateList;
Expand Down Expand Up @@ -296,7 +300,7 @@ public Toolbar(Context context, AttributeSet attrs, int defStyleAttr, int defSty
* @param resId theme used to inflate popup menus
* @see #getPopupTheme()
*/
public void setPopupTheme(int resId) {
public void setPopupTheme(@StyleRes int resId) {
if (mPopupTheme != resId) {
mPopupTheme = resId;
if (resId == 0) {
Expand Down Expand Up @@ -331,7 +335,7 @@ public void onRtlPropertiesChanged(@ResolvedLayoutDir int layoutDirection) {
*
* @param resId ID of a drawable resource
*/
public void setLogo(int resId) {
public void setLogo(@DrawableRes int resId) {
setLogo(getContext().getDrawable(resId));
}

Expand Down Expand Up @@ -481,7 +485,7 @@ public Drawable getLogo() {
*
* @param resId String resource id
*/
public void setLogoDescription(int resId) {
public void setLogoDescription(@StringRes int resId) {
setLogoDescription(getContext().getText(resId));
}

Expand Down Expand Up @@ -566,7 +570,7 @@ public CharSequence getTitle() {
*
* @param resId Resource ID of a string to set as the title
*/
public void setTitle(int resId) {
public void setTitle(@StringRes int resId) {
setTitle(getContext().getText(resId));
}

Expand Down Expand Up @@ -621,7 +625,7 @@ public CharSequence getSubtitle() {
*
* @param resId String resource ID
*/
public void setSubtitle(int resId) {
public void setSubtitle(@StringRes int resId) {
setSubtitle(getContext().getText(resId));
}

Expand Down Expand Up @@ -663,7 +667,7 @@ public void setSubtitle(CharSequence subtitle) {
* Sets the text color, size, style, hint color, and highlight color
* from the specified TextAppearance resource.
*/
public void setTitleTextAppearance(Context context, int resId) {
public void setTitleTextAppearance(Context context, @StyleRes int resId) {
mTitleTextAppearance = resId;
if (mTitleTextView != null) {
mTitleTextView.setTextAppearance(context, resId);
Expand All @@ -674,7 +678,7 @@ public void setTitleTextAppearance(Context context, int resId) {
* Sets the text color, size, style, hint color, and highlight color
* from the specified TextAppearance resource.
*/
public void setSubtitleTextAppearance(Context context, int resId) {
public void setSubtitleTextAppearance(Context context, @StyleRes int resId) {
mSubtitleTextAppearance = resId;
if (mSubtitleTextView != null) {
mSubtitleTextView.setTextAppearance(context, resId);
Expand Down Expand Up @@ -729,7 +733,7 @@ public CharSequence getNavigationContentDescription() {
*
* @attr ref android.R.styleable#Toolbar_navigationContentDescription
*/
public void setNavigationContentDescription(int resId) {
public void setNavigationContentDescription(@StringRes int resId) {
setNavigationContentDescription(resId != 0 ? getContext().getText(resId) : null);
}

Expand Down Expand Up @@ -766,7 +770,7 @@ public void setNavigationContentDescription(@Nullable CharSequence description)
*
* @attr ref android.R.styleable#Toolbar_navigationIcon
*/
public void setNavigationIcon(int resId) {
public void setNavigationIcon(@DrawableRes int resId) {
setNavigationIcon(getContext().getDrawable(resId));
}

Expand Down Expand Up @@ -972,7 +976,7 @@ private MenuInflater getMenuInflater() {
*
* @param resId ID of a menu resource to inflate
*/
public void inflateMenu(int resId) {
public void inflateMenu(@MenuRes int resId) {
getMenuInflater().inflate(resId, getMenu());
}

Expand Down
5 changes: 3 additions & 2 deletions core/java/android/widget/ViewAnimator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package android.widget;


import android.annotation.AnimRes;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
Expand Down Expand Up @@ -309,7 +310,7 @@ public void setOutAnimation(Animation outAnimation) {
* @see #getInAnimation()
* @see #setInAnimation(android.view.animation.Animation)
*/
public void setInAnimation(Context context, int resourceID) {
public void setInAnimation(Context context, @AnimRes int resourceID) {
setInAnimation(AnimationUtils.loadAnimation(context, resourceID));
}

Expand All @@ -322,7 +323,7 @@ public void setInAnimation(Context context, int resourceID) {
* @see #getOutAnimation()
* @see #setOutAnimation(android.view.animation.Animation)
*/
public void setOutAnimation(Context context, int resourceID) {
public void setOutAnimation(Context context, @AnimRes int resourceID) {
setOutAnimation(AnimationUtils.loadAnimation(context, resourceID));
}

Expand Down
3 changes: 2 additions & 1 deletion graphics/java/android/graphics/PorterDuffColorFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package android.graphics;

import android.annotation.ColorInt;
import android.annotation.NonNull;

/**
Expand All @@ -36,7 +37,7 @@ public class PorterDuffColorFilter extends ColorFilter {
* @see #setColor(int)
* @see #setMode(android.graphics.PorterDuff.Mode)
*/
public PorterDuffColorFilter(int color, @NonNull PorterDuff.Mode mode) {
public PorterDuffColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) {
mColor = color;
mMode = mode;
update();
Expand Down
2 changes: 1 addition & 1 deletion graphics/java/android/graphics/drawable/Drawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ public void setXfermode(Xfermode mode) {
* {@link #setTintList(ColorStateList) tint}.
* </p>
*/
public void setColorFilter(int color, @NonNull PorterDuff.Mode mode) {
public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) {
setColorFilter(new PorterDuffColorFilter(color, mode));
}

Expand Down

0 comments on commit da81fa5

Please sign in to comment.