diff options
author | Alan Viverette <alanv@google.com> | 2015-04-29 23:53:18 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-04-29 23:53:19 +0000 |
commit | 0f1a3972c18371359c39e6789607621bf0989181 (patch) | |
tree | 630b0003ed303b007c153054bde6fa6be68631ec /core/java/android/content | |
parent | 8cc1d3dba4e06c47669c5b0c0d12b24ba70cd57a (diff) | |
parent | f601440e21f352f5e59dd27e6709c7137cd90090 (diff) | |
download | frameworks_base-0f1a3972c18371359c39e6789607621bf0989181.zip frameworks_base-0f1a3972c18371359c39e6789607621bf0989181.tar.gz frameworks_base-0f1a3972c18371359c39e6789607621bf0989181.tar.bz2 |
Merge "Stash modulation alpha until ColorStateList has resolved base color" into mnc-dev
Diffstat (limited to 'core/java/android/content')
-rw-r--r-- | core/java/android/content/res/ColorStateList.java | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/core/java/android/content/res/ColorStateList.java b/core/java/android/content/res/ColorStateList.java index fdafb04..14bfac5 100644 --- a/core/java/android/content/res/ColorStateList.java +++ b/core/java/android/content/res/ColorStateList.java @@ -271,7 +271,7 @@ public class ColorStateList implements Parcelable { final TypedArray a = Resources.obtainAttributes(r, theme, attrs, R.styleable.ColorStateListItem); final int[] themeAttrs = a.extractThemeAttrs(); - final int baseColor = a.getColor(R.styleable.ColorStateListItem_color, 0); + final int baseColor = a.getColor(R.styleable.ColorStateListItem_color, Color.MAGENTA); final float alphaMod = a.getFloat(R.styleable.ColorStateListItem_alpha, 1.0f); changingConfigurations |= a.getChangingConfigurations(); @@ -296,7 +296,9 @@ public class ColorStateList implements Parcelable { } stateSpec = StateSet.trimStateSet(stateSpec, j); - // Apply alpha modulation. + // Apply alpha modulation. If we couldn't resolve the color or + // alpha yet, the default values leave us enough information to + // modulate again during applyTheme(). final int color = modulateColorAlpha(baseColor, alphaMod); if (listSize == 0 || stateSpec.length == 0) { defaultColor = color; @@ -365,14 +367,31 @@ public class ColorStateList implements Parcelable { if (themeAttrsList[i] != null) { final TypedArray a = t.resolveAttributes(themeAttrsList[i], R.styleable.ColorStateListItem); + + final float defaultAlphaMod; + if (themeAttrsList[i][R.styleable.ColorStateListItem_color] != 0) { + // If the base color hasn't been resolved yet, the current + // color's alpha channel is either full-opacity (if we + // haven't resolved the alpha modulation yet) or + // pre-modulated. Either is okay as a default value. + defaultAlphaMod = Color.alpha(mColors[i]) / 255.0f; + } else { + // Otherwise, the only correct default value is 1. Even if + // nothing is resolved during this call, we can apply this + // multiple times without losing of information. + defaultAlphaMod = 1.0f; + } + final int baseColor = a.getColor( R.styleable.ColorStateListItem_color, mColors[i]); final float alphaMod = a.getFloat( - R.styleable.ColorStateListItem_alpha, 1.0f); - + R.styleable.ColorStateListItem_alpha, defaultAlphaMod); mColors[i] = modulateColorAlpha(baseColor, alphaMod); + + // Account for any configuration changes. mChangingConfigurations |= a.getChangingConfigurations(); + // Extract the theme attributes, if any. themeAttrsList[i] = a.extractThemeAttrs(themeAttrsList[i]); if (themeAttrsList[i] != null) { hasUnresolvedAttrs = true; |