Loading res/drawable/ic_delete_x.xml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?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. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> <path android:fillColor="#FF000000" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/> </vector> res/layout/bubble_conversation_remove_button.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?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. --> <ImageButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button" android:layout_width="48dp" android:layout_height="48dp" android:background="?android:attr/selectableItemBackground" android:scaleType="centerInside" android:tint="?android:attr/textColorSecondary" android:src="@drawable/ic_delete_x"/> No newline at end of file res/xml/app_bubble_notification_settings.xml +8 −0 Original line number Diff line number Diff line Loading @@ -27,4 +27,12 @@ android:title="@string/notification_bubbles_title" settings:allowDividerBelow="false"/> <!-- Selected or excluded conversations get added here --> <PreferenceCategory android:title="@string/bubble_app_setting_selected_conversation_title" android:key="bubble_conversations" android:visibility="gone" settings:allowDividerAbove="false" settings:allowDividerBelow="false" /> </PreferenceScreen> src/com/android/settings/notification/AppBubbleListPreferenceController.java 0 → 100644 +154 −0 Original line number Diff line number Diff line /* * 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; import static android.app.NotificationChannel.DEFAULT_ALLOW_BUBBLE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; import android.annotation.Nullable; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.content.Context; import android.content.pm.ShortcutInfo; import android.graphics.drawable.Drawable; import android.service.notification.ConversationChannelWrapper; import android.view.View; import android.widget.ImageView; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; import com.android.settings.R; import com.android.settings.notification.app.AppConversationListPreferenceController; import com.android.settingslib.RestrictedLockUtils; import com.google.common.annotations.VisibleForTesting; import java.util.List; import java.util.stream.Collectors; /** * Displays a list of conversations that have either been selected or excluded from bubbling. */ public class AppBubbleListPreferenceController extends AppConversationListPreferenceController { private static final String KEY = "bubble_conversations"; public AppBubbleListPreferenceController(Context context, NotificationBackend backend) { super(context, backend); } @Override public void onResume(NotificationBackend.AppRow appRow, @Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group, Drawable conversationDrawable, ShortcutInfo conversationInfo, RestrictedLockUtils.EnforcedAdmin admin) { super.onResume(appRow, channel, group, conversationDrawable, conversationInfo, admin); // In case something changed in the foreground (e.g. via bubble button on notification) loadConversationsAndPopulate(); } @Override public String getPreferenceKey() { return KEY; } @Override public boolean isAvailable() { if (!super.isAvailable()) { return false; } if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_NONE) { return false; } return true; } @VisibleForTesting @Override public List<ConversationChannelWrapper> filterAndSortConversations( List<ConversationChannelWrapper> conversations) { return conversations.stream() .sorted(mConversationComparator) .filter((c) -> { if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_SELECTED) { return c.getNotificationChannel().canBubble(); } else if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_ALL) { return c.getNotificationChannel().getAllowBubbles() == 0; } return false; }) .collect(Collectors.toList()); } @Override protected int getTitleResId() { // TODO: possible to left align like mocks? return mAppRow.bubblePreference == BUBBLE_PREFERENCE_SELECTED ? R.string.bubble_app_setting_selected_conversation_title : R.string.bubble_app_setting_excluded_conversation_title; } @VisibleForTesting @Override public Preference createConversationPref(final ConversationChannelWrapper conversation) { final ConversationPreference pref = new ConversationPreference(mContext); populateConversationPreference(conversation, pref); pref.setOnClickListener((v) -> { conversation.getNotificationChannel().setAllowBubbles(DEFAULT_ALLOW_BUBBLE); mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, conversation.getNotificationChannel()); mPreference.removePreference(pref); if (mPreference.getPreferenceCount() == 0) { mPreference.setVisible(false); } }); return pref; } /** Simple preference with a 'x' button at the end. */ @VisibleForTesting public static class ConversationPreference extends Preference implements View.OnClickListener { View.OnClickListener mOnClickListener; ConversationPreference(Context context) { super(context); setWidgetLayoutResource(R.layout.bubble_conversation_remove_button); } @Override public void onBindViewHolder(final PreferenceViewHolder holder) { super.onBindViewHolder(holder); ImageView view = holder.itemView.findViewById(R.id.button); view.setOnClickListener(mOnClickListener); } public void setOnClickListener(View.OnClickListener listener) { mOnClickListener = listener; } @Override public void onClick(View v) { if (mOnClickListener != null) { mOnClickListener.onClick(v); } } } } src/com/android/settings/notification/app/AppBubbleNotificationSettings.java +7 −4 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.text.TextUtils; import android.util.Log; import com.android.settings.R; import com.android.settings.notification.AppBubbleListPreferenceController; import com.android.settings.notification.NotificationBackend; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.core.AbstractPreferenceController; Loading Loading @@ -56,18 +57,20 @@ public class AppBubbleNotificationSettings extends NotificationSettings implemen @Override protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { mControllers = getPreferenceControllers(context, this); mControllers = getPreferenceControllers(context, this, mDependentFieldListener); return new ArrayList<>(mControllers); } protected static List<NotificationPreferenceController> getPreferenceControllers( Context context, AppBubbleNotificationSettings fragment) { Context context, AppBubbleNotificationSettings fragment, DependentFieldListener listener) { List<NotificationPreferenceController> controllers = new ArrayList<>(); controllers.add(new HeaderPreferenceController(context, fragment)); controllers.add(new BubblePreferenceController(context, fragment != null ? fragment.getChildFragmentManager() : null, new NotificationBackend(), true /* isAppPage */)); new NotificationBackend(), true /* isAppPage */, listener)); controllers.add(new AppBubbleListPreferenceController(context, new NotificationBackend())); return controllers; } Loading Loading @@ -114,7 +117,7 @@ public class AppBubbleNotificationSettings extends NotificationSettings implemen public List<AbstractPreferenceController> createPreferenceControllers(Context context) { return new ArrayList<>(AppBubbleNotificationSettings.getPreferenceControllers( context, null)); context, null, null)); } }; } Loading
res/drawable/ic_delete_x.xml 0 → 100644 +25 −0 Original line number Diff line number Diff line <?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. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> <path android:fillColor="#FF000000" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/> </vector>
res/layout/bubble_conversation_remove_button.xml 0 → 100644 +24 −0 Original line number Diff line number Diff line <?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. --> <ImageButton xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button" android:layout_width="48dp" android:layout_height="48dp" android:background="?android:attr/selectableItemBackground" android:scaleType="centerInside" android:tint="?android:attr/textColorSecondary" android:src="@drawable/ic_delete_x"/> No newline at end of file
res/xml/app_bubble_notification_settings.xml +8 −0 Original line number Diff line number Diff line Loading @@ -27,4 +27,12 @@ android:title="@string/notification_bubbles_title" settings:allowDividerBelow="false"/> <!-- Selected or excluded conversations get added here --> <PreferenceCategory android:title="@string/bubble_app_setting_selected_conversation_title" android:key="bubble_conversations" android:visibility="gone" settings:allowDividerAbove="false" settings:allowDividerBelow="false" /> </PreferenceScreen>
src/com/android/settings/notification/AppBubbleListPreferenceController.java 0 → 100644 +154 −0 Original line number Diff line number Diff line /* * 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; import static android.app.NotificationChannel.DEFAULT_ALLOW_BUBBLE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_ALL; import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; import android.annotation.Nullable; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.content.Context; import android.content.pm.ShortcutInfo; import android.graphics.drawable.Drawable; import android.service.notification.ConversationChannelWrapper; import android.view.View; import android.widget.ImageView; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; import com.android.settings.R; import com.android.settings.notification.app.AppConversationListPreferenceController; import com.android.settingslib.RestrictedLockUtils; import com.google.common.annotations.VisibleForTesting; import java.util.List; import java.util.stream.Collectors; /** * Displays a list of conversations that have either been selected or excluded from bubbling. */ public class AppBubbleListPreferenceController extends AppConversationListPreferenceController { private static final String KEY = "bubble_conversations"; public AppBubbleListPreferenceController(Context context, NotificationBackend backend) { super(context, backend); } @Override public void onResume(NotificationBackend.AppRow appRow, @Nullable NotificationChannel channel, @Nullable NotificationChannelGroup group, Drawable conversationDrawable, ShortcutInfo conversationInfo, RestrictedLockUtils.EnforcedAdmin admin) { super.onResume(appRow, channel, group, conversationDrawable, conversationInfo, admin); // In case something changed in the foreground (e.g. via bubble button on notification) loadConversationsAndPopulate(); } @Override public String getPreferenceKey() { return KEY; } @Override public boolean isAvailable() { if (!super.isAvailable()) { return false; } if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_NONE) { return false; } return true; } @VisibleForTesting @Override public List<ConversationChannelWrapper> filterAndSortConversations( List<ConversationChannelWrapper> conversations) { return conversations.stream() .sorted(mConversationComparator) .filter((c) -> { if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_SELECTED) { return c.getNotificationChannel().canBubble(); } else if (mAppRow.bubblePreference == BUBBLE_PREFERENCE_ALL) { return c.getNotificationChannel().getAllowBubbles() == 0; } return false; }) .collect(Collectors.toList()); } @Override protected int getTitleResId() { // TODO: possible to left align like mocks? return mAppRow.bubblePreference == BUBBLE_PREFERENCE_SELECTED ? R.string.bubble_app_setting_selected_conversation_title : R.string.bubble_app_setting_excluded_conversation_title; } @VisibleForTesting @Override public Preference createConversationPref(final ConversationChannelWrapper conversation) { final ConversationPreference pref = new ConversationPreference(mContext); populateConversationPreference(conversation, pref); pref.setOnClickListener((v) -> { conversation.getNotificationChannel().setAllowBubbles(DEFAULT_ALLOW_BUBBLE); mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, conversation.getNotificationChannel()); mPreference.removePreference(pref); if (mPreference.getPreferenceCount() == 0) { mPreference.setVisible(false); } }); return pref; } /** Simple preference with a 'x' button at the end. */ @VisibleForTesting public static class ConversationPreference extends Preference implements View.OnClickListener { View.OnClickListener mOnClickListener; ConversationPreference(Context context) { super(context); setWidgetLayoutResource(R.layout.bubble_conversation_remove_button); } @Override public void onBindViewHolder(final PreferenceViewHolder holder) { super.onBindViewHolder(holder); ImageView view = holder.itemView.findViewById(R.id.button); view.setOnClickListener(mOnClickListener); } public void setOnClickListener(View.OnClickListener listener) { mOnClickListener = listener; } @Override public void onClick(View v) { if (mOnClickListener != null) { mOnClickListener.onClick(v); } } } }
src/com/android/settings/notification/app/AppBubbleNotificationSettings.java +7 −4 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.text.TextUtils; import android.util.Log; import com.android.settings.R; import com.android.settings.notification.AppBubbleListPreferenceController; import com.android.settings.notification.NotificationBackend; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.core.AbstractPreferenceController; Loading Loading @@ -56,18 +57,20 @@ public class AppBubbleNotificationSettings extends NotificationSettings implemen @Override protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { mControllers = getPreferenceControllers(context, this); mControllers = getPreferenceControllers(context, this, mDependentFieldListener); return new ArrayList<>(mControllers); } protected static List<NotificationPreferenceController> getPreferenceControllers( Context context, AppBubbleNotificationSettings fragment) { Context context, AppBubbleNotificationSettings fragment, DependentFieldListener listener) { List<NotificationPreferenceController> controllers = new ArrayList<>(); controllers.add(new HeaderPreferenceController(context, fragment)); controllers.add(new BubblePreferenceController(context, fragment != null ? fragment.getChildFragmentManager() : null, new NotificationBackend(), true /* isAppPage */)); new NotificationBackend(), true /* isAppPage */, listener)); controllers.add(new AppBubbleListPreferenceController(context, new NotificationBackend())); return controllers; } Loading Loading @@ -114,7 +117,7 @@ public class AppBubbleNotificationSettings extends NotificationSettings implemen public List<AbstractPreferenceController> createPreferenceControllers(Context context) { return new ArrayList<>(AppBubbleNotificationSettings.getPreferenceControllers( context, null)); context, null, null)); } }; }