Update design of channel pages.

Test: atest
Bug: 127796543
Change-Id: I4fabeafe2602c341554959303e67bc69c8817a8f
This commit is contained in:
Julia Reynolds
2019-03-07 10:44:01 -05:00
parent 7d7b09abeb
commit 4253be9191
19 changed files with 1257 additions and 95 deletions

View File

@@ -152,6 +152,10 @@ public class AppNotificationSettings extends NotificationSettingsBase {
context, mImportanceListener, mBackend));
mControllers.add(new ImportancePreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new MinImportancePreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new HighImportancePreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new SoundPreferenceController(context, this,
mImportanceListener, mBackend));
mControllers.add(new LightsPreferenceController(context, mBackend));

View File

@@ -94,9 +94,12 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new HeaderPreferenceController(context, this));
mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
mControllers.add(new ImportancePreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new MinImportancePreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new HighImportancePreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new AllowSoundPreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new SoundPreferenceController(context, this,

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import android.app.NotificationChannel;
import android.content.Context;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.RestrictedSwitchPreference;
import androidx.preference.Preference;
public class HighImportancePreferenceController extends NotificationPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
private static final String KEY_IMPORTANCE = "high_importance";
private NotificationSettingsBase.ImportanceListener mImportanceListener;
public HighImportancePreferenceController(Context context,
NotificationSettingsBase.ImportanceListener importanceListener,
NotificationBackend backend) {
super(context, backend);
mImportanceListener = importanceListener;
}
@Override
public String getPreferenceKey() {
return KEY_IMPORTANCE;
}
@Override
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null) {
return false;
}
if (isDefaultChannel()) {
return false;
}
return mChannel.getImportance() >= IMPORTANCE_DEFAULT;
}
@Override
public void updateState(Preference preference) {
if (mAppRow!= null && mChannel != null) {
preference.setEnabled(mAdmin == null && isChannelConfigurable());
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
pref.setChecked(mChannel.getImportance() >= IMPORTANCE_HIGH);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mChannel != null) {
final boolean checked = (boolean) newValue;
mChannel.setImportance(checked ? IMPORTANCE_HIGH : IMPORTANCE_DEFAULT);
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
saveChannel();
mImportanceListener.onImportanceChanged();
}
return true;
}
}

View File

@@ -0,0 +1,172 @@
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
import com.android.settingslib.R;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
public class ImportancePreference extends Preference {
boolean mIsBlockable = true;
boolean mIsConfigurable = true;
int mImportance;
ImageButton blockButton;
ImageButton silenceButton;
ImageButton alertButton;
ArrayMap<ImageButton, Integer> mImageButtons = new ArrayMap<>();
Context mContext;
public ImportancePreference(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context);
}
public ImportancePreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
public ImportancePreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public ImportancePreference(Context context) {
super(context);
init(context);
}
private void init(Context context) {
mContext = context;
setLayoutResource(R.layout.notif_importance_preference);
}
public void setImportance(int importance) {
mImportance = importance;
}
public void setBlockable(boolean blockable) {
mIsBlockable = blockable;
}
public void setConfigurable(boolean configurable) {
mIsConfigurable = configurable;
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
View blockView = holder.itemView.findViewById(R.id.block);
View alertView = holder.itemView.findViewById(R.id.alert);
View silenceView = holder.itemView.findViewById(R.id.silence);
if (!mIsBlockable) {
blockView.setVisibility(View.GONE);
if (mImportance == IMPORTANCE_NONE) {
mImportance = IMPORTANCE_LOW;
callChangeListener(IMPORTANCE_LOW);
}
}
blockButton = blockView.findViewById(R.id.block_icon);
silenceButton = silenceView.findViewById(R.id.silence_icon);
alertButton = alertView.findViewById(R.id.alert_icon);
mImageButtons.put(blockButton, mContext.getColor(R.color.notification_block_color));
mImageButtons.put(silenceButton, mContext.getColor(R.color.notification_silence_color));
mImageButtons.put(alertButton, mContext.getColor(R.color.notification_alert_color));
switch (mImportance) {
case IMPORTANCE_NONE:
colorizeImageButton(blockButton.getId());
if (!mIsConfigurable) {
alertView.setVisibility(View.GONE);
silenceView.setVisibility(View.GONE);
}
break;
case IMPORTANCE_MIN:
case IMPORTANCE_LOW:
colorizeImageButton(silenceButton.getId());
if (!mIsConfigurable) {
alertView.setVisibility(View.GONE);
blockView.setVisibility(View.GONE);
}
break;
case IMPORTANCE_HIGH:
default:
colorizeImageButton(alertButton.getId());
if (!mIsConfigurable) {
blockView.setVisibility(View.GONE);
silenceView.setVisibility(View.GONE);
}
break;
}
blockButton.setOnClickListener(v -> {
callChangeListener(IMPORTANCE_NONE);
colorizeImageButton(blockButton.getId());
});
silenceButton.setOnClickListener(v -> {
callChangeListener(IMPORTANCE_LOW);
colorizeImageButton(silenceButton.getId());
});
alertButton.setOnClickListener(v -> {
callChangeListener(IMPORTANCE_DEFAULT);
colorizeImageButton(alertButton.getId());
});
}
private void colorizeImageButton(int buttonId) {
if (mImageButtons != null) {
for (int i = 0; i < mImageButtons.size(); i++) {
final ImageButton imageButton = mImageButtons.keyAt(i);
final int color = mImageButtons.valueAt(i);
if (imageButton != null) {
LayerDrawable drawable = (LayerDrawable) imageButton.getDrawable();
Drawable foreground = drawable.findDrawableByLayerId(R.id.fore);
GradientDrawable background =
(GradientDrawable) drawable.findDrawableByLayerId(R.id.back);
if (buttonId == imageButton.getId()) {
foreground.setTint(Color.WHITE);
background.setColor(color);
} else {
foreground.setTint(color);
background.setColor(Color.TRANSPARENT);
}
}
}
}
}
}

View File

@@ -18,21 +18,15 @@ package com.android.settings.notification;
import static android.app.NotificationChannel.USER_LOCKED_SOUND;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.media.RingtoneManager;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.RestrictedListPreference;
import com.android.settings.core.PreferenceControllerMixin;
import androidx.preference.Preference;
public class ImportancePreferenceController extends NotificationPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
@@ -53,44 +47,33 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
@Override
public boolean isAvailable() {
if (!super.isAvailable()) {
if (mAppRow == null) {
return false;
}
if (mChannel == null) {
return false;
}
return !isDefaultChannel();
if (isDefaultChannel()) {
return false;
}
return true;
}
@Override
public void updateState(Preference preference) {
if (mAppRow!= null && mChannel != null) {
preference.setEnabled(mAdmin == null && isChannelConfigurable());
preference.setSummary(getImportanceSummary(mChannel));
int importances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1;
CharSequence[] entries = new CharSequence[importances];
CharSequence[] values = new CharSequence[importances];
int index = 0;
for (int i = IMPORTANCE_HIGH; i >= IMPORTANCE_MIN; i--) {
NotificationChannel channel = new NotificationChannel("", "", i);
entries[index] = getImportanceSummary(channel);
values[index] = String.valueOf(i);
index++;
}
RestrictedListPreference pref = (RestrictedListPreference) preference;
pref.setEntries(entries);
pref.setEntryValues(values);
pref.setValue(String.valueOf(mChannel.getImportance()));
ImportancePreference pref = (ImportancePreference) preference;
pref.setBlockable(isChannelBlockable());
pref.setConfigurable(isChannelConfigurable());
pref.setImportance(mChannel.getImportance());
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mChannel != null) {
final int importance = Integer.parseInt((String) newValue);
final int importance = (Integer) newValue;
// If you are moving from an importance level without sound to one with sound,
// but the sound you had selected was "Silence",
@@ -111,39 +94,4 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
}
return true;
}
protected String getImportanceSummary(NotificationChannel channel) {
String summary = "";
int importance = channel.getImportance();
switch (importance) {
case IMPORTANCE_UNSPECIFIED:
summary = mContext.getString(R.string.notification_importance_unspecified);
break;
case NotificationManager.IMPORTANCE_MIN:
summary = mContext.getString(R.string.notification_importance_min);
break;
case NotificationManager.IMPORTANCE_LOW:
summary = mContext.getString(R.string.notification_importance_low);
break;
case NotificationManager.IMPORTANCE_DEFAULT:
if (SoundPreferenceController.hasValidSound(channel)) {
summary = mContext.getString(R.string.notification_importance_default);
} else {
summary = mContext.getString(R.string.notification_importance_low);
}
break;
case NotificationManager.IMPORTANCE_HIGH:
case NotificationManager.IMPORTANCE_MAX:
if (SoundPreferenceController.hasValidSound(channel)) {
summary = mContext.getString(R.string.notification_importance_high);
} else {
summary = mContext.getString(R.string.notification_importance_high_silent);
}
break;
default:
return "";
}
return summary;
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_MIN;
import android.app.NotificationChannel;
import android.content.Context;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.RestrictedSwitchPreference;
import androidx.preference.Preference;
public class MinImportancePreferenceController extends NotificationPreferenceController
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
private static final String KEY_IMPORTANCE = "min_importance";
private NotificationSettingsBase.ImportanceListener mImportanceListener;
public MinImportancePreferenceController(Context context,
NotificationSettingsBase.ImportanceListener importanceListener,
NotificationBackend backend) {
super(context, backend);
mImportanceListener = importanceListener;
}
@Override
public String getPreferenceKey() {
return KEY_IMPORTANCE;
}
@Override
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mChannel == null) {
return false;
}
if (isDefaultChannel()) {
return false;
}
return mChannel.getImportance() <= IMPORTANCE_LOW;
}
@Override
public void updateState(Preference preference) {
if (mAppRow!= null && mChannel != null) {
preference.setEnabled(mAdmin == null && isChannelConfigurable());
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
pref.setChecked(mChannel.getImportance() == IMPORTANCE_MIN);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mChannel != null) {
final boolean checked = (boolean) newValue;
mChannel.setImportance(checked ? IMPORTANCE_MIN : IMPORTANCE_LOW);
mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
saveChannel();
mImportanceListener.onImportanceChanged();
}
return true;
}
}