Merge "Adding support for customize highlight region in preference" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1ea2f0e045
@@ -22,14 +22,7 @@
|
|||||||
android:key="pref_icon_badging"
|
android:key="pref_icon_badging"
|
||||||
android:title="@string/notification_dots_title"
|
android:title="@string/notification_dots_title"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:widgetLayout="@layout/notification_pref_warning" >
|
android:widgetLayout="@layout/notification_pref_warning" />
|
||||||
<intent android:action="android.settings.NOTIFICATION_SETTINGS">
|
|
||||||
<!-- This extra highlights the "Allow notification dots" field in Notification settings -->
|
|
||||||
<extra
|
|
||||||
android:name=":settings:fragment_args_key"
|
|
||||||
android:value="notification_badging" />
|
|
||||||
</intent>
|
|
||||||
</com.android.launcher3.settings.NotificationDotsPreference>
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_ENABLED(613)
|
LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_ENABLED(613)
|
||||||
|
|||||||
@@ -85,6 +85,12 @@ public class NotificationDotsPreference extends Preference
|
|||||||
Settings.Secure.getUriFor(NOTIFICATION_ENABLED_LISTENERS),
|
Settings.Secure.getUriFor(NOTIFICATION_ENABLED_LISTENERS),
|
||||||
false, mListenerListObserver);
|
false, mListenerListObserver);
|
||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
|
// Update intent
|
||||||
|
Bundle extras = new Bundle();
|
||||||
|
extras.putString(EXTRA_FRAGMENT_ARG_KEY, "notification_badging");
|
||||||
|
setIntent(new Intent("android.settings.NOTIFICATION_SETTINGS")
|
||||||
|
.putExtra(EXTRA_SHOW_FRAGMENT_ARGS, extras));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUI() {
|
private void updateUI() {
|
||||||
|
|||||||
@@ -24,16 +24,18 @@ import android.animation.ValueAnimator;
|
|||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.RectF;
|
||||||
import android.util.Property;
|
import android.util.Property;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.android.launcher3.util.Themes;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
|
import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
|
||||||
import androidx.recyclerview.widget.RecyclerView.State;
|
import androidx.recyclerview.widget.RecyclerView.State;
|
||||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||||
|
|
||||||
|
import com.android.launcher3.util.Themes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for highlighting a preference
|
* 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 Paint mPaint = new Paint();
|
||||||
private final RecyclerView mRv;
|
private final RecyclerView mRv;
|
||||||
private final int mIndex;
|
private final int mIndex;
|
||||||
|
private final Preference mPreference;
|
||||||
|
private final RectF mDrawRect = new RectF();
|
||||||
|
|
||||||
private boolean mHighLightStarted = false;
|
private boolean mHighLightStarted = false;
|
||||||
private int mHighlightColor = END_COLOR;
|
private int mHighlightColor = END_COLOR;
|
||||||
|
|
||||||
|
public PreferenceHighlighter(RecyclerView rv, int index, Preference preference) {
|
||||||
public PreferenceHighlighter(RecyclerView rv, int index) {
|
|
||||||
mRv = rv;
|
mRv = rv;
|
||||||
mIndex = index;
|
mIndex = index;
|
||||||
|
mPreference = preference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,7 +96,8 @@ public class PreferenceHighlighter extends ItemDecoration implements Runnable {
|
|||||||
if (!mHighLightStarted) {
|
if (!mHighLightStarted) {
|
||||||
// Start highlight
|
// Start highlight
|
||||||
int colorTo = setColorAlphaBound(Themes.getColorAccent(mRv.getContext()), 66);
|
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.setDuration(HIGHLIGHT_FADE_IN_DURATION);
|
||||||
anim.setRepeatMode(ValueAnimator.REVERSE);
|
anim.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
anim.setRepeatCount(4);
|
anim.setRepeatCount(4);
|
||||||
@@ -108,7 +113,11 @@ public class PreferenceHighlighter extends ItemDecoration implements Runnable {
|
|||||||
|
|
||||||
View view = holder.itemView;
|
View view = holder.itemView;
|
||||||
mPaint.setColor(mHighlightColor);
|
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() {
|
private void removeHighlight() {
|
||||||
@@ -124,4 +133,16 @@ public class PreferenceHighlighter extends ItemDecoration implements Runnable {
|
|||||||
});
|
});
|
||||||
anim.start();
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,7 +237,9 @@ public class SettingsActivity extends FragmentActivity
|
|||||||
RecyclerView list = getListView();
|
RecyclerView list = getListView();
|
||||||
PreferencePositionCallback callback = (PreferencePositionCallback) list.getAdapter();
|
PreferencePositionCallback callback = (PreferencePositionCallback) list.getAdapter();
|
||||||
int position = callback.getPreferenceAdapterPosition(mHighLightKey);
|
int position = callback.getPreferenceAdapterPosition(mHighLightKey);
|
||||||
return position >= 0 ? new PreferenceHighlighter(list, position) : null;
|
return position >= 0 ? new PreferenceHighlighter(
|
||||||
|
list, position, screen.findPreference(mHighLightKey))
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestAccessibilityFocus(@NonNull final RecyclerView rv) {
|
private void requestAccessibilityFocus(@NonNull final RecyclerView rv) {
|
||||||
|
|||||||
Reference in New Issue
Block a user