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:
@@ -1,26 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<RelativeLayout android:id="@+id/zen_mode_settings_senders_overlay_view"
|
|
||||||
android:layout_centerInParent="true"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="@dimen/zen_conversations_image_margin_vertical"
|
|
||||||
android:layout_marginBottom="@dimen/zen_conversations_image_margin_vertical">
|
|
||||||
</RelativeLayout>
|
|
||||||
</RelativeLayout>
|
|
@@ -51,9 +51,6 @@
|
|||||||
<dimen name="conversation_icon_size">32dp</dimen>
|
<dimen name="conversation_icon_size">32dp</dimen>
|
||||||
|
|
||||||
<dimen name="zen_mode_settings_button_margin_vertical">24dp</dimen>
|
<dimen name="zen_mode_settings_button_margin_vertical">24dp</dimen>
|
||||||
<dimen name="zen_conversations_image_margin_vertical">24dp</dimen>
|
|
||||||
<dimen name="zen_conversations_icon_offset">32dp</dimen>
|
|
||||||
<dimen name="zen_conversations_icon_size">50dp</dimen>
|
|
||||||
<dimen name="zen_schedule_rule_checkbox_padding">7dp</dimen>
|
<dimen name="zen_schedule_rule_checkbox_padding">7dp</dimen>
|
||||||
<dimen name="zen_schedule_day_margin">17dp</dimen>
|
<dimen name="zen_schedule_day_margin">17dp</dimen>
|
||||||
|
|
||||||
|
@@ -8179,8 +8179,6 @@
|
|||||||
|
|
||||||
<!-- [CHAR LIMIT=120] Zen mode settings: Title for conversations settings page -->
|
<!-- [CHAR LIMIT=120] Zen mode settings: Title for conversations settings page -->
|
||||||
<string name="zen_mode_conversations_title">Conversations</string>
|
<string name="zen_mode_conversations_title">Conversations</string>
|
||||||
<!-- [CHAR LIMIT=120] Zen mode settings: Header for conversations settings page -->
|
|
||||||
<string name="zen_mode_conversations_section_title">Conversations that can interrupt</string>
|
|
||||||
<string name="zen_mode_from_all_conversations">All conversations</string>
|
<string name="zen_mode_from_all_conversations">All conversations</string>
|
||||||
<string name="zen_mode_from_important_conversations">Priority conversations</string>
|
<string name="zen_mode_from_important_conversations">Priority conversations</string>
|
||||||
<!-- [CHAR LIMIT=40] Version of the above for "priority conversations" when it is a non-first member of a list -->
|
<!-- [CHAR LIMIT=40] Version of the above for "priority conversations" when it is a non-first member of a list -->
|
||||||
|
@@ -1,31 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
<PreferenceScreen
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:key="zen_mode_conversations_settings"
|
|
||||||
android:title="@string/zen_mode_conversations_title">
|
|
||||||
<!-- Conversations -->
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="zen_mode_conversations_radio_buttons"
|
|
||||||
android:title="@string/zen_mode_conversations_section_title">
|
|
||||||
|
|
||||||
<!-- Senders image -->
|
|
||||||
<com.android.settingslib.widget.LayoutPreference
|
|
||||||
android:key="zen_mode_conversations_image"
|
|
||||||
android:layout="@layout/zen_mode_senders_overlay_image"
|
|
||||||
android:selectable="false"/>
|
|
||||||
</PreferenceCategory>
|
|
||||||
</PreferenceScreen>
|
|
@@ -312,21 +312,6 @@ public class ZenModeBackend {
|
|||||||
return R.string.zen_mode_from_no_conversations;
|
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) {
|
protected int getContactsCallsSummary(ZenPolicy policy) {
|
||||||
int peopleType = policy.getPriorityCallSenders();
|
int peopleType = policy.getPriorityCallSenders();
|
||||||
switch (peopleType) {
|
switch (peopleType) {
|
||||||
|
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@@ -1,149 +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 static com.android.settings.notification.zen.ZenModePriorityConversationsPreferenceController.KEY_ALL;
|
|
||||||
import static com.android.settings.notification.zen.ZenModePriorityConversationsPreferenceController.KEY_IMPORTANT;
|
|
||||||
import static com.android.settings.notification.zen.ZenModePriorityConversationsPreferenceController.KEY_NONE;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.any;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.reset;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceCategory;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.notification.NotificationBackend;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class ZenModePriorityConversationsPreferenceControllerTest {
|
|
||||||
|
|
||||||
private ZenModePriorityConversationsPreferenceController mController;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private ZenModeBackend mZenBackend;
|
|
||||||
@Mock
|
|
||||||
private PreferenceCategory mMockPrefCategory;
|
|
||||||
@Mock
|
|
||||||
private NotificationManager.Policy mPolicy;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mPreferenceScreen;
|
|
||||||
@Mock
|
|
||||||
private NotificationBackend mNotifBackend;
|
|
||||||
|
|
||||||
private List<SelectorWithWidgetPreference> mSelectorWithWidgetPreferences;
|
|
||||||
private ContentResolver mContentResolver;
|
|
||||||
private Context mContext;
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mController = new ZenModePriorityConversationsPreferenceController(
|
|
||||||
mContext, "test_key", mock(Lifecycle.class), mNotifBackend);
|
|
||||||
ReflectionHelpers.setField(mController, "mBackend", mZenBackend);
|
|
||||||
|
|
||||||
when(mMockPrefCategory.getContext()).thenReturn(mContext);
|
|
||||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
|
||||||
.thenReturn(mMockPrefCategory);
|
|
||||||
captureRadioButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void displayPreference_radioButtonsCreatedOnlyOnce() {
|
|
||||||
when(mMockPrefCategory.findPreference(any())).thenReturn(mock(Preference.class));
|
|
||||||
|
|
||||||
// radio buttons were already created, so don't re-create them
|
|
||||||
mController.displayPreference(mPreferenceScreen);
|
|
||||||
verify(mMockPrefCategory, never()).addPreference(any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void clickAllConversations() {
|
|
||||||
SelectorWithWidgetPreference allConversationsRb = getButton(KEY_ALL);
|
|
||||||
allConversationsRb.onClick();
|
|
||||||
|
|
||||||
verify(mZenBackend).saveConversationSenders(CONVERSATION_SENDERS_ANYONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void clickImportantConversations() {
|
|
||||||
SelectorWithWidgetPreference importantConversationsRb = getButton(KEY_IMPORTANT);
|
|
||||||
importantConversationsRb.onClick();
|
|
||||||
|
|
||||||
verify(mZenBackend).saveConversationSenders(CONVERSATION_SENDERS_IMPORTANT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void clickNoConversations() {
|
|
||||||
SelectorWithWidgetPreference noConversationsRb = getButton(KEY_NONE);
|
|
||||||
noConversationsRb.onClick();
|
|
||||||
|
|
||||||
verify(mZenBackend)
|
|
||||||
.saveConversationSenders(CONVERSATION_SENDERS_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void captureRadioButtons() {
|
|
||||||
ArgumentCaptor<SelectorWithWidgetPreference> rbCaptor =
|
|
||||||
ArgumentCaptor.forClass(SelectorWithWidgetPreference.class);
|
|
||||||
mController.displayPreference(mPreferenceScreen);
|
|
||||||
|
|
||||||
// verifies 3 buttons were added
|
|
||||||
verify(mMockPrefCategory, times(3)).addPreference(rbCaptor.capture());
|
|
||||||
mSelectorWithWidgetPreferences = rbCaptor.getAllValues();
|
|
||||||
assertThat(mSelectorWithWidgetPreferences.size()).isEqualTo(3);
|
|
||||||
|
|
||||||
reset(mMockPrefCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SelectorWithWidgetPreference getButton(String key) {
|
|
||||||
for (SelectorWithWidgetPreference pref : mSelectorWithWidgetPreferences) {
|
|
||||||
if (key.equals(pref.getKey())) {
|
|
||||||
return pref;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user