Notification slider changes.
Bug: 27558254 Change-Id: I15635ae19e82a57d6e6fcb2f8f946f31bebf5d0f
This commit is contained in:
@@ -20,10 +20,16 @@ import com.android.settings.R;
|
||||
import com.android.settings.SeekBarPreference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* A slider preference that controls notification importance.
|
||||
@@ -34,12 +40,23 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
||||
|
||||
private Callback mCallback;
|
||||
private int mMinProgress;
|
||||
private boolean mSystemApp;
|
||||
private TextView mSummaryTextView;
|
||||
private String mSummary;
|
||||
private SeekBar mSeekBar;
|
||||
private ColorStateList mActiveSliderTint;
|
||||
private ColorStateList mInactiveSliderTint;
|
||||
private boolean mAutoOn;
|
||||
private Handler mHandler;
|
||||
|
||||
public ImportanceSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
setLayoutResource(R.layout.preference_importance_slider);
|
||||
mActiveSliderTint = ColorStateList.valueOf(
|
||||
context.getColor(R.color.importance_slider_color));
|
||||
mInactiveSliderTint = ColorStateList.valueOf(
|
||||
context.getColor(R.color.importance_disabled_slider_color));
|
||||
mHandler = new Handler();
|
||||
}
|
||||
|
||||
public ImportanceSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
@@ -63,20 +80,67 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void setSystemApp(boolean systemApp) {
|
||||
mSystemApp = systemApp;
|
||||
@Override
|
||||
public void setProgress(int progress) {
|
||||
mSummary = getProgressSummary(progress);
|
||||
super.setProgress(progress);
|
||||
}
|
||||
|
||||
public void setAutoOn(boolean autoOn) {
|
||||
mAutoOn = autoOn;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
if (mSystemApp) {
|
||||
((ImageView) view.findViewById(R.id.low_importance)).getDrawable().setTint(
|
||||
getContext().getColor(R.color.importance_disabled_tint));
|
||||
mSummaryTextView = (TextView) view.findViewById(com.android.internal.R.id.summary);
|
||||
mSeekBar = (SeekBar) view.findViewById(
|
||||
com.android.internal.R.id.seekbar);
|
||||
|
||||
final ImageView autoButton = (ImageView) view.findViewById(R.id.auto_importance);
|
||||
applyAutoUi(autoButton);
|
||||
autoButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
applyAuto(autoButton);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void applyAuto(ImageView autoButton) {
|
||||
mAutoOn = !mAutoOn;
|
||||
if (!mAutoOn) {
|
||||
setProgress(NotificationListenerService.Ranking.IMPORTANCE_DEFAULT);
|
||||
mCallback.onImportanceChanged(
|
||||
NotificationListenerService.Ranking.IMPORTANCE_DEFAULT, true);
|
||||
} else {
|
||||
mCallback.onImportanceChanged(
|
||||
NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED, true);
|
||||
}
|
||||
view.setDividerAllowedAbove(false);
|
||||
view.setDividerAllowedBelow(false);
|
||||
applyAutoUi(autoButton);
|
||||
}
|
||||
|
||||
private void applyAutoUi(ImageView autoButton) {
|
||||
mSeekBar.setEnabled(!mAutoOn);
|
||||
|
||||
final ColorStateList tint = mAutoOn ? mInactiveSliderTint : mActiveSliderTint;
|
||||
Drawable icon = autoButton.getDrawable().mutate();
|
||||
icon.setTintList(tint);
|
||||
autoButton.setImageDrawable(icon);
|
||||
mSeekBar.setProgressTintList(tint);
|
||||
mSeekBar.setThumbTintList(tint);
|
||||
|
||||
if (mAutoOn) {
|
||||
mSummary = getProgressSummary(
|
||||
NotificationListenerService.Ranking.IMPORTANCE_UNSPECIFIED);
|
||||
}
|
||||
mSummaryTextView.setText(mSummary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mSummary;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,12 +150,49 @@ public class ImportanceSeekBarPreference extends SeekBarPreference implements
|
||||
seekBar.setProgress(mMinProgress);
|
||||
progress = mMinProgress;
|
||||
}
|
||||
if (fromTouch) {
|
||||
mCallback.onImportanceChanged(progress);
|
||||
if (mSummaryTextView != null) {
|
||||
mSummary = getProgressSummary(progress);
|
||||
mSummaryTextView.setText(mSummary);
|
||||
}
|
||||
mCallback.onImportanceChanged(progress, fromTouch);
|
||||
}
|
||||
|
||||
private String getProgressSummary(int progress) {
|
||||
switch (progress) {
|
||||
case NotificationListenerService.Ranking.IMPORTANCE_NONE:
|
||||
return getContext().getString(R.string.notification_importance_blocked);
|
||||
case NotificationListenerService.Ranking.IMPORTANCE_MIN:
|
||||
return getContext().getString(R.string.notification_importance_min);
|
||||
case NotificationListenerService.Ranking.IMPORTANCE_LOW:
|
||||
return getContext().getString(R.string.notification_importance_low);
|
||||
case NotificationListenerService.Ranking.IMPORTANCE_DEFAULT:
|
||||
return getContext().getString(R.string.notification_importance_default);
|
||||
case NotificationListenerService.Ranking.IMPORTANCE_HIGH:
|
||||
return getContext().getString(R.string.notification_importance_high);
|
||||
case NotificationListenerService.Ranking.IMPORTANCE_MAX:
|
||||
return getContext().getString(R.string.notification_importance_max);
|
||||
default:
|
||||
return getContext().getString(R.string.notification_importance_unspecified);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyChanged() {
|
||||
mHandler.post(mNotifyChanged);
|
||||
}
|
||||
|
||||
private void postNotifyChanged() {
|
||||
super.notifyChanged();
|
||||
}
|
||||
|
||||
private final Runnable mNotifyChanged = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
postNotifyChanged();
|
||||
}
|
||||
};
|
||||
|
||||
public interface Callback {
|
||||
void onImportanceChanged(int progress);
|
||||
void onImportanceChanged(int progress, boolean fromTouch);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user