Fixed removing highlight on < v21 devices (#502)

* It seems tinting is applied on pre-Lollipop devices using
     a color filter. HighlightButton used clearColorFilter to remove
     the highlight color and revert back to the original color. This
     caused an issue on < v21 devices as the View would loose its tint.
This commit is contained in:
Martijn Brekhof 2018-01-16 21:13:48 +01:00 committed by Synced Synapse
parent a11fcc93ae
commit 5f734bbd5c
1 changed files with 13 additions and 15 deletions

View File

@ -26,7 +26,8 @@ import org.xbmc.kore.utils.Utils;
public class HighlightButton extends AppCompatImageButton { public class HighlightButton extends AppCompatImageButton {
private int highlightColorFilter; private int highlightColor;
private int defaultColor;
private boolean highlight; private boolean highlight;
@ -49,9 +50,9 @@ public class HighlightButton extends AppCompatImageButton {
public void setHighlight(boolean highlight) { public void setHighlight(boolean highlight) {
if (highlight) { if (highlight) {
setColorFilter(highlightColorFilter); setColorFilter(highlightColor);
} else { } else {
clearColorFilter(); setColorFilter(defaultColor);
} }
this.highlight = highlight; this.highlight = highlight;
} }
@ -62,10 +63,13 @@ public class HighlightButton extends AppCompatImageButton {
private void setStyle(Context context) { private void setStyle(Context context) {
if (!this.isInEditMode()) { if (!this.isInEditMode()) {
TypedArray styledAttributes = TypedArray styledAttributes = context.getTheme()
context.getTheme().obtainStyledAttributes(new int[]{R.attr.colorAccent}); .obtainStyledAttributes(new int[]{R.attr.colorAccent,
highlightColorFilter = styledAttributes.getColor(styledAttributes.getIndex(0), R.attr.defaultButtonColorFilter});
context.getResources().getColor(R.color.accent_default)); highlightColor = styledAttributes.getColor(styledAttributes.getIndex(0),
context.getResources().getColor(R.color.accent_default));
defaultColor = styledAttributes.getColor(styledAttributes.getIndex(1),
context.getResources().getColor(R.color.white));
styledAttributes.recycle(); styledAttributes.recycle();
} }
} }
@ -81,19 +85,13 @@ public class HighlightButton extends AppCompatImageButton {
if (Utils.isLollipopOrLater() || this.isInEditMode()) if (Utils.isLollipopOrLater() || this.isInEditMode())
return; return;
TypedArray styledAttributes =
context.getTheme().obtainStyledAttributes(new int[]{R.attr.defaultButtonColorFilter});
final int colorFilter = styledAttributes.getColor(styledAttributes.getIndex(0),
context.getResources().getColor(R.color.white));
styledAttributes.recycle();
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override @Override
public void onGlobalLayout() { public void onGlobalLayout() {
if (highlight) { if (highlight) {
setColorFilter(highlightColorFilter); setColorFilter(highlightColor);
} else { } else {
setColorFilter(colorFilter); setColorFilter(defaultColor);
} }
} }
}); });