Adding support for customize highlight region in preference
> Also fixing notification dots setting not getting highlighted Bug: 184747760 Test: Manual Change-Id: Ic9c2bfbb9750bed60afc14e824181f650c8cff33
This commit is contained in:
@@ -24,16 +24,18 @@ import android.animation.ValueAnimator;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.util.Property;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.launcher3.util.Themes;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
|
||||
import androidx.recyclerview.widget.RecyclerView.State;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
import com.android.launcher3.util.Themes;
|
||||
|
||||
/**
|
||||
* Utility class for highlighting a preference
|
||||
*/
|
||||
@@ -62,14 +64,16 @@ public class PreferenceHighlighter extends ItemDecoration implements Runnable {
|
||||
private final Paint mPaint = new Paint();
|
||||
private final RecyclerView mRv;
|
||||
private final int mIndex;
|
||||
private final Preference mPreference;
|
||||
private final RectF mDrawRect = new RectF();
|
||||
|
||||
private boolean mHighLightStarted = false;
|
||||
private int mHighlightColor = END_COLOR;
|
||||
|
||||
|
||||
public PreferenceHighlighter(RecyclerView rv, int index) {
|
||||
public PreferenceHighlighter(RecyclerView rv, int index, Preference preference) {
|
||||
mRv = rv;
|
||||
mIndex = index;
|
||||
mPreference = preference;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,7 +96,8 @@ public class PreferenceHighlighter extends ItemDecoration implements Runnable {
|
||||
if (!mHighLightStarted) {
|
||||
// Start highlight
|
||||
int colorTo = setColorAlphaBound(Themes.getColorAccent(mRv.getContext()), 66);
|
||||
ObjectAnimator anim = ObjectAnimator.ofArgb(this, HIGHLIGHT_COLOR, END_COLOR, colorTo);
|
||||
ObjectAnimator anim = ObjectAnimator.ofArgb(this, HIGHLIGHT_COLOR, END_COLOR,
|
||||
colorTo);
|
||||
anim.setDuration(HIGHLIGHT_FADE_IN_DURATION);
|
||||
anim.setRepeatMode(ValueAnimator.REVERSE);
|
||||
anim.setRepeatCount(4);
|
||||
@@ -108,7 +113,11 @@ public class PreferenceHighlighter extends ItemDecoration implements Runnable {
|
||||
|
||||
View view = holder.itemView;
|
||||
mPaint.setColor(mHighlightColor);
|
||||
c.drawRect(0, view.getY(), parent.getWidth(), view.getY() + view.getHeight(), mPaint);
|
||||
mDrawRect.set(0, view.getY(), parent.getWidth(), view.getY() + view.getHeight());
|
||||
if (mPreference instanceof HighlightDelegate) {
|
||||
((HighlightDelegate) mPreference).offsetHighlight(view, mDrawRect);
|
||||
}
|
||||
c.drawRect(mDrawRect, mPaint);
|
||||
}
|
||||
|
||||
private void removeHighlight() {
|
||||
@@ -124,4 +133,16 @@ public class PreferenceHighlighter extends ItemDecoration implements Runnable {
|
||||
});
|
||||
anim.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to be implemented by a preference to customize the highlight are
|
||||
*/
|
||||
public interface HighlightDelegate {
|
||||
|
||||
/**
|
||||
* Allows the preference to update the highlight area
|
||||
*/
|
||||
void offsetHighlight(View prefView, RectF bounds);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user