Delete stuff related to removed "Conversations that can interrupt" settings

Bug: 226486181
Test: N/A, dead code removal only
Change-Id: I100db518880a7eee402af37f49e416ec61ff8486
This commit is contained in:
Matías Hernández
2023-03-14 16:53:53 +01:00
parent 2d53aabf74
commit 0882b04ed5
10 changed files with 0 additions and 761 deletions

View File

@@ -312,21 +312,6 @@ public class ZenModeBackend {
return R.string.zen_mode_from_no_conversations;
}
protected int getConversationSummary() {
int conversationType = getPriorityConversationSenders();
switch (conversationType) {
case NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE:
return R.string.zen_mode_from_all_conversations;
case NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT:
return R.string.zen_mode_from_important_conversations;
case NotificationManager.Policy.CONVERSATION_SENDERS_NONE:
return R.string.zen_mode_from_no_conversations;
default:
return R.string.zen_mode_from_no_conversations;
}
}
protected int getContactsCallsSummary(ZenPolicy policy) {
int peopleType = policy.getPriorityCallSenders();
switch (peopleType) {

View File

@@ -1,167 +0,0 @@
/*
* Copyright (C) 2020 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.zen;
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE;
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT;
import static android.app.NotificationManager.Policy.CONVERSATION_SENDERS_NONE;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.service.notification.ConversationChannelWrapper;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.LayoutPreference;
import java.util.ArrayList;
import java.util.List;
/**
* Updates the DND Settings conversations image resource based on the conversations channels.
*/
public class ZenModeConversationsImagePreferenceController
extends AbstractZenModePreferenceController {
private static final int MAX_CONVERSATIONS_SHOWN = 5;
private final int mIconSizePx;
private final int mIconOffsetPx;
private final ArrayList<Drawable> mConversationDrawables = new ArrayList<>();
private final NotificationBackend mNotificationBackend;
private ViewGroup mViewGroup;
private LayoutPreference mPreference;
public ZenModeConversationsImagePreferenceController(Context context, String key,
Lifecycle lifecycle, NotificationBackend notificationBackend) {
super(context, key, lifecycle);
mNotificationBackend = notificationBackend;
mIconSizePx =
mContext.getResources().getDimensionPixelSize(R.dimen.zen_conversations_icon_size);
mIconOffsetPx = mContext.getResources()
.getDimensionPixelSize(R.dimen.zen_conversations_icon_offset);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (LayoutPreference) screen.findPreference(KEY);
mViewGroup =
(ViewGroup) mPreference.findViewById(R.id.zen_mode_settings_senders_overlay_view);
loadConversations();
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public void updateState(Preference preference) {
loadConversations();
mViewGroup.removeAllViews();
final int conversationSenders = mBackend.getPriorityConversationSenders();
if (conversationSenders == CONVERSATION_SENDERS_ANYONE) {
mViewGroup.setContentDescription(
mContext.getResources().getString(R.string.zen_mode_from_all_conversations));
} else if (conversationSenders == CONVERSATION_SENDERS_IMPORTANT) {
mViewGroup.setContentDescription(
mContext.getResources().getString(
R.string.zen_mode_from_important_conversations));
} else {
mViewGroup.setContentDescription(null);
mViewGroup.setVisibility(View.GONE);
return;
}
final int numDrawablesToShow = Math.min(MAX_CONVERSATIONS_SHOWN,
mConversationDrawables.size());
for (int i = 0; i < numDrawablesToShow; i++) {
ImageView iv = new ImageView(mContext);
iv.setImageDrawable(mConversationDrawables.get(i));
iv.setLayoutParams(new ViewGroup.LayoutParams(mIconSizePx, mIconSizePx));
FrameLayout fl = new FrameLayout(mContext);
fl.addView(iv);
fl.setPadding((numDrawablesToShow - i - 1) * mIconOffsetPx, 0, 0, 0);
mViewGroup.addView(fl);
}
mViewGroup.setVisibility(numDrawablesToShow > 0 ? View.VISIBLE : View.GONE);
}
private void loadConversations() {
// Load conversations
new AsyncTask<Void, Void, Void>() {
private List<Drawable> mDrawables = new ArrayList<>();
@Override
protected Void doInBackground(Void... unused) {
mDrawables.clear();
final int conversationSenders = mBackend.getPriorityConversationSenders();
if (conversationSenders == CONVERSATION_SENDERS_NONE) {
return null;
}
ParceledListSlice<ConversationChannelWrapper> conversations =
mNotificationBackend.getConversations(
conversationSenders == CONVERSATION_SENDERS_IMPORTANT);
if (conversations != null) {
for (ConversationChannelWrapper conversation : conversations.getList()) {
if (!conversation.getNotificationChannel().isDemoted()) {
Drawable drawable = mNotificationBackend.getConversationDrawable(
mContext,
conversation.getShortcutInfo(),
conversation.getPkg(),
conversation.getUid(),
conversation.getNotificationChannel()
.isImportantConversation());
if (drawable != null) {
mDrawables.add(drawable);
}
}
}
}
return null;
}
@Override
protected void onPostExecute(Void unused) {
if (mContext == null) {
return;
}
mConversationDrawables.clear();
mConversationDrawables.addAll(mDrawables);
updateState(mPreference);
}
}.execute();
}
}

View File

@@ -1,73 +0,0 @@
/*
* Copyright (C) 2020 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.zen;
import android.app.NotificationManager;
import android.content.Context;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settingslib.core.lifecycle.Lifecycle;
/**
* Controls the summary for preference found at:
* Settings > Sound > Do Not Disturb > People > Conversations
*/
public class ZenModeConversationsPreferenceController extends AbstractZenModePreferenceController {
private final ZenModeBackend mBackend;
private Preference mPreference;
public ZenModeConversationsPreferenceController(Context context,
String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
mBackend = ZenModeBackend.getInstance(context);
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(KEY);
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
switch (getZenMode()) {
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
case Settings.Global.ZEN_MODE_ALARMS:
mPreference.setEnabled(false);
mPreference.setSummary(mBackend.getAlarmsTotalSilencePeopleSummary(
NotificationManager.Policy.PRIORITY_CATEGORY_CONVERSATIONS));
break;
default:
preference.setEnabled(true);
preference.setSummary(mBackend.getConversationSummary());
}
}
}

View File

@@ -1,76 +0,0 @@
/*
* Copyright (C) 2020 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.zen;
import android.app.settings.SettingsEnums;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
/**
* Settings > Sound > Do Not Disturb > Conversations
*/
@SearchIndexable
public class ZenModeConversationsSettings extends ZenModeSettingsBase {
private final NotificationBackend mNotificationBackend = new NotificationBackend();
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getSettingsLifecycle(), mNotificationBackend);
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, NotificationBackend notificationBackend) {
List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new ZenModeConversationsImagePreferenceController(context,
"zen_mode_conversations_image", lifecycle, notificationBackend));
controllers.add(new ZenModePriorityConversationsPreferenceController(context,
"zen_mode_conversations_radio_buttons", lifecycle, notificationBackend));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_conversations_settings;
}
@Override
public int getMetricsCategory() {
return SettingsEnums.DND_CONVERSATIONS;
}
/**
* For Search.
*/
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.zen_mode_conversations_settings) {
@Override
public List<AbstractPreferenceController> createPreferenceControllers(
Context context) {
return buildPreferenceControllers(context, null, null);
}
};
}

View File

@@ -1,219 +0,0 @@
/*
* Copyright (C) 2020 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.zen;
import android.app.NotificationManager;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.pm.ParceledListSlice;
import android.icu.text.MessageFormat;
import android.os.AsyncTask;
import android.service.notification.ConversationChannelWrapper;
import android.view.View;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.notification.app.ConversationListSettings;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* Options to choose the priority conversations that are allowed to bypass DND.
*/
public class ZenModePriorityConversationsPreferenceController
extends AbstractZenModePreferenceController {
private static final int UNSET = -1;
@VisibleForTesting static final String KEY_ALL = "conversations_all";
@VisibleForTesting static final String KEY_IMPORTANT = "conversations_important";
@VisibleForTesting static final String KEY_NONE = "conversations_none";
private final NotificationBackend mNotificationBackend;
private int mNumImportantConversations = UNSET;
private int mNumConversations = UNSET;
private PreferenceCategory mPreferenceCategory;
private List<SelectorWithWidgetPreference> mSelectorWithWidgetPreferences = new ArrayList<>();
private Context mPreferenceScreenContext;
public ZenModePriorityConversationsPreferenceController(Context context, String key,
Lifecycle lifecycle, NotificationBackend notificationBackend) {
super(context, key, lifecycle);
mNotificationBackend = notificationBackend;
}
@Override
public void displayPreference(PreferenceScreen screen) {
mPreferenceScreenContext = screen.getContext();
mPreferenceCategory = screen.findPreference(getPreferenceKey());
if (mPreferenceCategory.findPreference(KEY_ALL) == null) {
makeRadioPreference(KEY_ALL, R.string.zen_mode_from_all_conversations);
makeRadioPreference(KEY_IMPORTANT, R.string.zen_mode_from_important_conversations);
makeRadioPreference(KEY_NONE, R.string.zen_mode_from_no_conversations);
updateChannelCounts();
}
super.displayPreference(screen);
}
@Override
public void onResume() {
super.onResume();
updateChannelCounts();
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public void updateState(Preference preference) {
final int currSetting = mBackend.getPriorityConversationSenders();
for (SelectorWithWidgetPreference pref : mSelectorWithWidgetPreferences) {
pref.setChecked(keyToSetting(pref.getKey()) == currSetting);
pref.setSummary(getSummary(pref.getKey()));
}
}
private static int keyToSetting(String key) {
switch (key) {
case KEY_ALL:
return NotificationManager.Policy.CONVERSATION_SENDERS_ANYONE;
case KEY_IMPORTANT:
return NotificationManager.Policy.CONVERSATION_SENDERS_IMPORTANT;
default:
return NotificationManager.Policy.CONVERSATION_SENDERS_NONE;
}
}
private String getSummary(String key) {
int numConversations;
if (KEY_ALL.equals(key)) {
numConversations = mNumConversations;
} else if (KEY_IMPORTANT.equals(key)) {
numConversations = mNumImportantConversations;
} else {
return null;
}
if (numConversations == UNSET) {
return null;
} else {
MessageFormat msgFormat = new MessageFormat(
mContext.getString(R.string.zen_mode_conversations_count),
Locale.getDefault());
Map<String, Object> args = new HashMap<>();
args.put("count", numConversations);
return msgFormat.format(args);
}
}
private void updateChannelCounts() {
// Load conversations
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... unused) {
ParceledListSlice<ConversationChannelWrapper> allConversations =
mNotificationBackend.getConversations(false);
int numConversations = 0;
if (allConversations != null) {
for (ConversationChannelWrapper conversation : allConversations.getList()) {
if (!conversation.getNotificationChannel().isDemoted()) {
numConversations++;
}
}
}
mNumConversations = numConversations;
ParceledListSlice<ConversationChannelWrapper> impConversations =
mNotificationBackend.getConversations(true);
int numImportantConversations = 0;
if (impConversations != null) {
for (ConversationChannelWrapper conversation : impConversations.getList()) {
if (!conversation.getNotificationChannel().isDemoted()) {
numImportantConversations++;
}
}
}
mNumImportantConversations = numImportantConversations;
return null;
}
@Override
protected void onPostExecute(Void unused) {
if (mContext == null) {
return;
}
updateState(mPreferenceCategory);
}
}.execute();
}
private SelectorWithWidgetPreference makeRadioPreference(String key, int titleId) {
final SelectorWithWidgetPreference pref =
new SelectorWithWidgetPreference(mPreferenceCategory.getContext());
if (KEY_ALL.equals(key) || KEY_IMPORTANT.equals(key)) {
pref.setExtraWidgetOnClickListener(mConversationSettingsWidgetClickListener);
}
pref.setKey(key);
pref.setTitle(titleId);
pref.setOnClickListener(mRadioButtonClickListener);
mPreferenceCategory.addPreference(pref);
mSelectorWithWidgetPreferences.add(pref);
return pref;
}
private View.OnClickListener mConversationSettingsWidgetClickListener =
new View.OnClickListener() {
@Override
public void onClick(View v) {
new SubSettingLauncher(mPreferenceScreenContext)
.setDestination(ConversationListSettings.class.getName())
.setSourceMetricsCategory(SettingsEnums.DND_CONVERSATIONS)
.launch();
}
};
private SelectorWithWidgetPreference.OnClickListener mRadioButtonClickListener =
new SelectorWithWidgetPreference.OnClickListener() {
@Override
public void onRadioButtonClicked(SelectorWithWidgetPreference preference) {
int selectedConversationSetting = keyToSetting(preference.getKey());
if (selectedConversationSetting != mBackend.getPriorityConversationSenders()) {
mBackend.saveConversationSenders(selectedConversationSetting);
}
}
};
}