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 {
private int highlightColorFilter;
private int highlightColor;
private int defaultColor;
private boolean highlight;
@ -49,9 +50,9 @@ public class HighlightButton extends AppCompatImageButton {
public void setHighlight(boolean highlight) {
if (highlight) {
setColorFilter(highlightColorFilter);
setColorFilter(highlightColor);
} else {
clearColorFilter();
setColorFilter(defaultColor);
}
this.highlight = highlight;
}
@ -62,10 +63,13 @@ public class HighlightButton extends AppCompatImageButton {
private void setStyle(Context context) {
if (!this.isInEditMode()) {
TypedArray styledAttributes =
context.getTheme().obtainStyledAttributes(new int[]{R.attr.colorAccent});
highlightColorFilter = styledAttributes.getColor(styledAttributes.getIndex(0),
context.getResources().getColor(R.color.accent_default));
TypedArray styledAttributes = context.getTheme()
.obtainStyledAttributes(new int[]{R.attr.colorAccent,
R.attr.defaultButtonColorFilter});
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();
}
}
@ -81,19 +85,13 @@ public class HighlightButton extends AppCompatImageButton {
if (Utils.isLollipopOrLater() || this.isInEditMode())
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() {
@Override
public void onGlobalLayout() {
if (highlight) {
setColorFilter(highlightColorFilter);
setColorFilter(highlightColor);
} else {
setColorFilter(colorFilter);
setColorFilter(defaultColor);
}
}
});