From 26f072c3ee4f2baecf4fd3f8ed829ed709055cf4 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Fri, 1 Apr 2011 16:23:18 -0700 Subject: [PATCH] Making StackView res-out and click feedback colors stylable Change-Id: Ia6241b1b66dc510b22bcf342d775f98eb7c86871 --- .../android/widget/AdapterViewAnimator.java | 17 ++++---- core/java/android/widget/StackView.java | 40 ++++++++++++++----- core/res/res/values/attrs.xml | 9 +++++ core/res/res/values/styles.xml | 5 +++ core/res/res/values/themes.xml | 4 +- 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java index 072992efef2b4..ca1effb258461 100644 --- a/core/java/android/widget/AdapterViewAnimator.java +++ b/core/java/android/widget/AdapterViewAnimator.java @@ -102,11 +102,6 @@ public abstract class AdapterViewAnimator extends AdapterView */ int mCurrentWindowStartUnbounded = 0; - /** - * Handler to post events to the main thread - */ - Handler mMainQueue; - /** * Listens for data changes from the adapter */ @@ -163,15 +158,18 @@ public abstract class AdapterViewAnimator extends AdapterView private static final int DEFAULT_ANIMATION_DURATION = 200; public AdapterViewAnimator(Context context) { - super(context); - initViewAnimator(); + this(context, null); } public AdapterViewAnimator(Context context, AttributeSet attrs) { - super(context, attrs); + this(context, attrs, 0); + } + + public AdapterViewAnimator(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes(attrs, - com.android.internal.R.styleable.AdapterViewAnimator); + com.android.internal.R.styleable.AdapterViewAnimator, defStyleAttr, 0); int resource = a.getResourceId( com.android.internal.R.styleable.AdapterViewAnimator_inAnimation, 0); if (resource > 0) { @@ -203,7 +201,6 @@ public abstract class AdapterViewAnimator extends AdapterView * Initialize this {@link AdapterViewAnimator} */ private void initViewAnimator() { - mMainQueue = new Handler(Looper.myLooper()); mPreviousViews = new ArrayList(); } diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java index 21c61bdf67ab9..ec4ef4b184b28 100644 --- a/core/java/android/widget/StackView.java +++ b/core/java/android/widget/StackView.java @@ -20,6 +20,7 @@ import java.lang.ref.WeakReference; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BlurMaskFilter; import android.graphics.Canvas; @@ -132,6 +133,8 @@ public class StackView extends AdapterViewAnimator { private int mMaximumVelocity; private VelocityTracker mVelocityTracker; private boolean mTransitionIsSetup = false; + private int mResOutColor; + private int mClickColor; private static HolographicHelper sHolographicHelper; private ImageView mHighlight; @@ -146,12 +149,24 @@ public class StackView extends AdapterViewAnimator { private final Rect stackInvalidateRect = new Rect(); public StackView(Context context) { - super(context); - initStackView(); + this(context, null); } public StackView(Context context, AttributeSet attrs) { - super(context, attrs); + this(context, attrs, com.android.internal.R.attr.stackViewStyle); + } + + public StackView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + TypedArray a = context.obtainStyledAttributes(attrs, + com.android.internal.R.styleable.StackView, defStyleAttr, 0); + + mResOutColor = a.getColor( + com.android.internal.R.styleable.StackView_resOutColor, 0); + mClickColor = a.getColor( + com.android.internal.R.styleable.StackView_clickColor, 0); + + a.recycle(); initStackView(); } @@ -357,7 +372,7 @@ public class StackView extends AdapterViewAnimator { private void setupStackSlider(View v, int mode) { mStackSlider.setMode(mode); if (v != null) { - mHighlight.setImageBitmap(sHolographicHelper.createOutline(v)); + mHighlight.setImageBitmap(sHolographicHelper.createResOutline(v, mResOutColor)); mHighlight.setRotation(v.getRotation()); mHighlight.setTranslationY(v.getTranslationY()); mHighlight.setTranslationX(v.getTranslationX()); @@ -429,8 +444,8 @@ public class StackView extends AdapterViewAnimator { if (!mClickFeedbackIsValid) { View v = getViewAtRelativeIndex(1); if (v != null) { - mClickFeedback.setImageBitmap(sHolographicHelper.createOutline(v, - HolographicHelper.CLICK_FEEDBACK)); + mClickFeedback.setImageBitmap( + sHolographicHelper.createClickOutline(v, mClickColor)); mClickFeedback.setTranslationX(v.getTranslationX()); mClickFeedback.setTranslationY(v.getTranslationY()); } @@ -1355,16 +1370,19 @@ public class StackView extends AdapterViewAnimator { mLargeBlurMaskFilter = new BlurMaskFilter(4 * mDensity, BlurMaskFilter.Blur.NORMAL); } - Bitmap createOutline(View v) { - return createOutline(v, RES_OUT); + Bitmap createClickOutline(View v, int color) { + return createOutline(v, CLICK_FEEDBACK, color); } - Bitmap createOutline(View v, int type) { + Bitmap createResOutline(View v, int color) { + return createOutline(v, RES_OUT, color); + } + + Bitmap createOutline(View v, int type, int color) { + mHolographicPaint.setColor(color); if (type == RES_OUT) { - mHolographicPaint.setColor(0xff6699ff); mBlurPaint.setMaskFilter(mSmallBlurMaskFilter); } else if (type == CLICK_FEEDBACK) { - mHolographicPaint.setColor(0x886699ff); mBlurPaint.setMaskFilter(mLargeBlurMaskFilter); } diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index c81f8c0e7e363..77e42f6ff826e 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -529,6 +529,8 @@ + + @@ -2489,6 +2491,13 @@ + + + + + + + diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index f7d3c3f9f1c55..f6a3979943f8d 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -1410,6 +1410,11 @@ 64dip + + diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml index b127747832871..fdeb229a7f16c 100644 --- a/core/res/res/values/themes.xml +++ b/core/res/res/values/themes.xml @@ -972,6 +972,7 @@ @android:style/Widget.Holo.QuickContactBadgeSmall.WindowLarge @android:style/Widget.Holo.ListPopupWindow @android:style/Widget.Holo.PopupMenu + @android:style/Widget.Holo.StackView @android:style/Preference.Holo.PreferenceScreen @@ -1255,7 +1256,8 @@ @android:style/Widget.Holo.QuickContactBadgeSmall.WindowLarge @android:style/Widget.Holo.Light.ListPopupWindow @android:style/Widget.Holo.Light.PopupMenu - + @android:style/Widget.Holo.StackView + @android:style/Preference.Holo.PreferenceScreen @android:style/Preference.Holo.Category