diff options
author | 2016-05-20 18:38:01 -0700 | |
---|---|---|
committer | 2016-05-24 18:08:36 -0700 | |
commit | b40b0d20066aeb53ae69e57979a92c337d0100df (patch) | |
tree | 4b0f0ff889a0cb123029017744d124d5ae419ee6 | |
parent | ddc21c0fb19b0ec2365ac650e833f1980b0f35b2 (diff) |
Update color bar defaults to use theme attr colors
Previously the values were hardcoded. Now the default value
for left and middle are colorAccent. Also updated SummaryPreference
to not call LinearColorBar.setColors unless its own setColors is called.
BUG: 28760785
Change-Id: Id28e809e6b5f0f6508258c995d5dcfacbc9c8725
-rw-r--r-- | res/values/colors.xml | 3 | ||||
-rw-r--r-- | src/com/android/settings/SummaryPreference.java | 8 | ||||
-rw-r--r-- | src/com/android/settings/applications/LinearColorBar.java | 15 |
3 files changed, 15 insertions, 11 deletions
diff --git a/res/values/colors.xml b/res/values/colors.xml index 003eda9d0d8..ab04c24f9fa 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -98,9 +98,6 @@ <!-- Accent color that matches the settings launcher icon --> <color name="icon_accent">#ffabffec</color> - <color name="summary_default_start">#ff009587</color> - <color name="summary_default_end">#ffced7db</color> - <color name="importance_icon_tint">#8a000000</color> <color name="importance_disabled_tint">#4d000000</color> diff --git a/src/com/android/settings/SummaryPreference.java b/src/com/android/settings/SummaryPreference.java index 0943a2bd6a7..38449b1e03f 100644 --- a/src/com/android/settings/SummaryPreference.java +++ b/src/com/android/settings/SummaryPreference.java @@ -33,6 +33,7 @@ public class SummaryPreference extends Preference { private String mUnits; private int mLeft, mMiddle, mRight; + private boolean mColorsSet = false; private float mLeftRatio, mMiddleRatio, mRightRatio; private String mStartLabel; private String mEndLabel; @@ -40,8 +41,6 @@ public class SummaryPreference extends Preference { public SummaryPreference(Context context, AttributeSet attrs) { super(context, attrs); setLayoutResource(R.layout.settings_summary_preference); - mLeft = context.getColor(R.color.summary_default_start); - mRight = context.getColor(R.color.summary_default_end); } public void setAmount(String amount) { @@ -77,6 +76,7 @@ public class SummaryPreference extends Preference { mLeft = left; mMiddle = middle; mRight = right; + mColorsSet = true; notifyChanged(); } @@ -86,7 +86,9 @@ public class SummaryPreference extends Preference { LinearColorBar colorBar = (LinearColorBar) holder.itemView.findViewById(R.id.color_bar); colorBar.setRatios(mLeftRatio, mMiddleRatio, mRightRatio); - colorBar.setColors(mLeft, mMiddle, mRight); + if (mColorsSet) { + colorBar.setColors(mLeft, mMiddle, mRight); + } if (!TextUtils.isEmpty(mStartLabel) || !TextUtils.isEmpty(mEndLabel)) { holder.findViewById(R.id.label_bar).setVisibility(View.VISIBLE); diff --git a/src/com/android/settings/applications/LinearColorBar.java b/src/com/android/settings/applications/LinearColorBar.java index 158a6255e84..53b6ab6f6fe 100644 --- a/src/com/android/settings/applications/LinearColorBar.java +++ b/src/com/android/settings/applications/LinearColorBar.java @@ -4,6 +4,7 @@ package com.android.settings.applications; import android.content.Context; +import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.LinearGradient; import android.graphics.Paint; @@ -12,12 +13,12 @@ import android.graphics.Rect; import android.graphics.Shader; import android.util.AttributeSet; import android.util.DisplayMetrics; +import android.util.TypedValue; import android.view.MotionEvent; import android.widget.LinearLayout; public class LinearColorBar extends LinearLayout { - static final int LEFT_COLOR = 0xff009688; - static final int MIDDLE_COLOR = 0xff009688; + static final int RIGHT_COLOR = 0xffced7db; static final int GRAY_COLOR = 0xff555555; static final int WHITE_COLOR = 0xffffffff; @@ -26,8 +27,8 @@ public class LinearColorBar extends LinearLayout { private float mYellowRatio; private float mGreenRatio; - private int mLeftColor = LEFT_COLOR; - private int mMiddleColor = MIDDLE_COLOR; + private int mLeftColor; + private int mMiddleColor; private int mRightColor = RIGHT_COLOR; private boolean mShowIndicator = true; @@ -70,7 +71,11 @@ public class LinearColorBar extends LinearLayout { ? 2 : 1; mEdgeGradientPaint.setStrokeWidth(mLineWidth); mEdgeGradientPaint.setAntiAlias(true); - + + Resources.Theme theme = context.getTheme(); + TypedValue typedValue = new TypedValue(); + theme.resolveAttribute(android.R.attr.colorAccent, typedValue, true); + mLeftColor = mMiddleColor = context.getColor(typedValue.resourceId); } public void setOnRegionTappedListener(OnRegionTappedListener listener) { |