Skip to content

Commit

Permalink
Fixed removing highlight on < v21 devices (#502)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
poisdeux authored and SyncedSynapse committed Jan 16, 2018
1 parent a11fcc9 commit 5f734bb
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions app/src/main/java/org/xbmc/kore/ui/widgets/HighlightButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

public class HighlightButton extends AppCompatImageButton {

private int highlightColorFilter;
private int highlightColor;
private int defaultColor;

private boolean highlight;

Expand All @@ -49,9 +50,9 @@ public HighlightButton(Context context, AttributeSet attrs, int defStyle) {

public void setHighlight(boolean highlight) {
if (highlight) {
setColorFilter(highlightColorFilter);
setColorFilter(highlightColor);
} else {
clearColorFilter();
setColorFilter(defaultColor);
}
this.highlight = highlight;
}
Expand All @@ -62,10 +63,13 @@ public boolean isHighlighted() {

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();
}
}
Expand All @@ -81,19 +85,13 @@ private void fixThemeColorForPreLollipop(Context context) {
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);
}
}
});
Expand Down

0 comments on commit 5f734bb

Please sign in to comment.