Merge "Some minor additions (icons, sorting) to modes" into main

This commit is contained in:
Julia Reynolds
2024-05-20 12:34:12 +00:00
committed by Android (Google) Code Review
9 changed files with 185 additions and 32 deletions

View File

@@ -0,0 +1,25 @@
<!--
Copyright (C) 2024 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="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path android:fillColor="@android:color/white"
android:pathData="M17.0,12.0l-5.0,0.0l0.0,5.0l5.0,0.0l0.0,-5.0zM16.0,1.0l0.0,2.0L8.0,3.0L8.0,1.0L6.0,1.0l0.0,2.0L5.0,3.0c-1.11,0.0 -1.9,0.9 -1.99,2.0L3.0,19.0c0.0,1.0 0.89,2.0 2.0,2.0l14.0,0.0c1.1,0.0 2.0,-0.9 2.0,-2.0L21.0,5.0c0.0,-1.1 -0.9,-2.0 -2.0,-2.0l-1.0,0.0L18.0,1.0l-2.0,0.0zm3.0,18.0L5.0,19.0L5.0,8.0l14.0,0.0l0.0,11.0z"/>
</vector>

View File

@@ -0,0 +1,26 @@
<!--
~ Copyright (C) 2024 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="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?android:attr/colorControlNormal">
<path android:fillColor="@android:color/white"
android:pathData="M612,668L668,612L520,464L520,280L440,280L440,496L612,668ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480ZM480,800Q613,800 706.5,706.5Q800,613 800,480Q800,347 706.5,253.5Q613,160 480,160Q347,160 253.5,253.5Q160,347 160,480Q160,613 253.5,706.5Q347,800 480,800Z"/>
</vector>

View File

@@ -18,8 +18,8 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/zen_modes_list_title" > android:title="@string/zen_modes_list_title" >
<!-- TODO: b/308819292 - implement page, delete this test preference --> <com.android.settingslib.widget.LayoutPreference
<Preference android:key="header"
android:key="zen_mode_test" /> android:layout="@layout/settings_entity_header" />
</PreferenceScreen> </PreferenceScreen>

View File

@@ -155,8 +155,8 @@ class ZenMode {
int iconResIdFromType = switch (mRule.getType()) { int iconResIdFromType = switch (mRule.getType()) {
case AutomaticZenRule.TYPE_UNKNOWN -> R.drawable.ic_do_not_disturb_on_24dp; case AutomaticZenRule.TYPE_UNKNOWN -> R.drawable.ic_do_not_disturb_on_24dp;
case AutomaticZenRule.TYPE_OTHER -> R.drawable.ic_do_not_disturb_on_24dp; case AutomaticZenRule.TYPE_OTHER -> R.drawable.ic_do_not_disturb_on_24dp;
case AutomaticZenRule.TYPE_SCHEDULE_TIME -> R.drawable.ic_do_not_disturb_on_24dp; case AutomaticZenRule.TYPE_SCHEDULE_TIME -> R.drawable.ic_modes_time;
case AutomaticZenRule.TYPE_SCHEDULE_CALENDAR -> R.drawable.ic_do_not_disturb_on_24dp; case AutomaticZenRule.TYPE_SCHEDULE_CALENDAR -> R.drawable.ic_modes_event;
case AutomaticZenRule.TYPE_BEDTIME -> R.drawable.ic_do_not_disturb_on_24dp; case AutomaticZenRule.TYPE_BEDTIME -> R.drawable.ic_do_not_disturb_on_24dp;
case AutomaticZenRule.TYPE_DRIVING -> R.drawable.ic_do_not_disturb_on_24dp; case AutomaticZenRule.TYPE_DRIVING -> R.drawable.ic_do_not_disturb_on_24dp;
case AutomaticZenRule.TYPE_IMMERSIVE -> R.drawable.ic_do_not_disturb_on_24dp; case AutomaticZenRule.TYPE_IMMERSIVE -> R.drawable.ic_do_not_disturb_on_24dp;

View File

@@ -41,6 +41,7 @@ public class ZenModeFragment extends ZenModeFragmentBase {
// TODO: fill in with all the elements of this page. Each should be an instance of // TODO: fill in with all the elements of this page. Each should be an instance of
// {@link AbstractZenModePreferenceController}. // {@link AbstractZenModePreferenceController}.
List<AbstractPreferenceController> prefControllers = new ArrayList<>(); List<AbstractPreferenceController> prefControllers = new ArrayList<>();
prefControllers.add(new ZenModeHeaderController(context, "header", this, mBackend));
return prefControllers; return prefControllers;
} }
@@ -55,19 +56,6 @@ public class ZenModeFragment extends ZenModeFragmentBase {
return; return;
} }
getActivity().setTitle(azr.getName()); getActivity().setTitle(azr.getName());
// TODO: b/308819292 - implement the real screen!
final PreferenceScreen screen = getPreferenceScreen();
if (screen == null) {
return;
}
Preference tmpPref = screen.findPreference("zen_mode_test");
if (tmpPref == null) {
return;
}
tmpPref.setTitle(azr.getTriggerDescription());
tmpPref.setSummary("active?: " + mode.isActive());
} }
@Override @Override

View File

@@ -0,0 +1,75 @@
/*
* Copyright (C) 2024 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.modes;
import android.app.Flags;
import android.content.Context;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.widget.LayoutPreference;
import java.util.concurrent.TimeUnit;
public class ZenModeHeaderController extends AbstractZenModePreferenceController {
private final DashboardFragment mFragment;
private EntityHeaderController mHeaderController;
ZenModeHeaderController(
@NonNull Context context,
@NonNull String key,
@NonNull DashboardFragment fragment,
@Nullable ZenModesBackend backend) {
super(context, key, backend);
mFragment = fragment;
}
@Override
public boolean isAvailable() {
return Flags.modesApi();
}
@Override
public void updateState(Preference preference) {
if (getAZR() == null || mFragment == null) {
return;
}
if (mHeaderController == null) {
final LayoutPreference pref = (LayoutPreference) preference;
mHeaderController = EntityHeaderController.newInstance(
mFragment.getActivity(),
mFragment,
pref.findViewById(R.id.entity_header));
}
Drawable icon = null;
try {
icon = getMode().getIcon(mContext).get(200, TimeUnit.MILLISECONDS);
} catch (Exception e) {
// no icon
}
mHeaderController.setIcon(icon)
.setLabel(getAZR().getName())
.done(false /* rebindActions */);
}
}

View File

@@ -25,6 +25,10 @@ import com.android.settings.core.SubSettingLauncher;
import com.android.settings.notification.zen.ZenModeSettings; import com.android.settings.notification.zen.ZenModeSettings;
import com.android.settingslib.RestrictedPreference; import com.android.settingslib.RestrictedPreference;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/** /**
* Preference representing a single mode item on the modes aggregator page. Clicking on this * Preference representing a single mode item on the modes aggregator page. Clicking on this
* preference leads to an individual mode's configuration page. * preference leads to an individual mode's configuration page.
@@ -36,10 +40,8 @@ public class ZenModeListPreference extends RestrictedPreference {
ZenModeListPreference(Context context, ZenMode zenMode) { ZenModeListPreference(Context context, ZenMode zenMode) {
super(context); super(context);
mContext = context; mContext = context;
mZenMode = zenMode; setZenMode(zenMode);
setTitle(mZenMode.getRule().getName()); setKey(zenMode.getId());
setSummary((mZenMode.isActive() ? "ACTIVE" : "inactive") + ": "
+ mZenMode.getRule().getTriggerDescription());
} }
@Override @Override
@@ -60,6 +62,16 @@ public class ZenModeListPreference extends RestrictedPreference {
.setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION) .setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION)
.launch(); .launch();
} }
}
public void setZenMode(ZenMode zenMode) {
mZenMode = zenMode;
setTitle(mZenMode.getRule().getName());
setSummary(mZenMode.getRule().getTriggerDescription());
try {
setIcon(mZenMode.getIcon(mContext).get(200, TimeUnit.MILLISECONDS));
} catch (Exception e) {
// no icon
}
} }
} }

View File

@@ -33,6 +33,7 @@ import com.android.settings.R;
import java.time.Duration; import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -77,7 +78,15 @@ class ZenModesBackend {
isRuleActive(ruleId, currentConfig))); isRuleActive(ruleId, currentConfig)));
} }
// TODO: b/331429435 - Sort modes. modes.sort((l, r) -> {
if (l.isManualDnd()) {
return -1;
} else if (r.isManualDnd()) {
return 1;
}
return l.getRule().getName().compareTo(r.getRule().getName());
});
return modes; return modes;
} }
@@ -105,10 +114,10 @@ class ZenModesBackend {
.setZenPolicy(ZenAdapters.notificationPolicyToZenPolicy( .setZenPolicy(ZenAdapters.notificationPolicyToZenPolicy(
mNotificationManager.getNotificationPolicy())) mNotificationManager.getNotificationPolicy()))
.setDeviceEffects(null) .setDeviceEffects(null)
.setTriggerDescription(mContext.getString(R.string.zen_mode_settings_summary))
.setManualInvocationAllowed(true) .setManualInvocationAllowed(true)
.setConfigurationActivity(null) // No further settings .setConfigurationActivity(null) // No further settings
.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY) .setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY)
.setIconResId(com.android.internal.R.drawable.ic_zen_24dp)
.build(); .build();
return ZenMode.manualDndMode(manualDndRule, return ZenMode.manualDndMode(manualDndRule,

View File

@@ -15,6 +15,7 @@
*/ */
package com.android.settings.notification.modes; package com.android.settings.notification.modes;
import android.app.AutomaticZenRule;
import android.app.Flags; import android.app.Flags;
import android.content.Context; import android.content.Context;
@@ -26,6 +27,9 @@ import androidx.preference.PreferenceCategory;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import java.util.HashMap;
import java.util.Map;
/** /**
* Controller for the PreferenceCategory on the modes aggregator page ({@link ZenModesListFragment}) * Controller for the PreferenceCategory on the modes aggregator page ({@link ZenModesListFragment})
* containing links to each individual mode. This is a central controller that populates and updates * containing links to each individual mode. This is a central controller that populates and updates
@@ -65,16 +69,30 @@ public class ZenModesListPreferenceController extends AbstractPreferenceControll
// category for each rule that exists. // category for each rule that exists.
PreferenceCategory category = (PreferenceCategory) preference; PreferenceCategory category = (PreferenceCategory) preference;
// TODO: b/322373473 - This is not the right way to replace these preferences; we should Map<String, ZenModeListPreference> originalPreferences = new HashMap<>();
// follow something similar to what for (int i = 0; i < category.getPreferenceCount(); i++) {
// ZenModeAutomaticRulesPreferenceController does to change rules ZenModeListPreference pref = (ZenModeListPreference) category.getPreference(i);
// only as necessary and update them. originalPreferences.put(pref.getKey(), pref);
category.removeAll(); }
// Loop through each rule, either updating the existing rule or creating the rule's
// preference
for (ZenMode mode : mBackend.getModes()) { for (ZenMode mode : mBackend.getModes()) {
Preference pref = new ZenModeListPreference(mContext, mode); if (originalPreferences.containsKey(mode.getId())) {
category.addPreference(pref); // existing rule; update its info if it's changed since the last display
AutomaticZenRule rule = mode.getRule();
originalPreferences.get(mode.getId()).setZenMode(mode);
} else {
// new rule; create a new ZenRulePreference & add it to the preference category
Preference pref = new ZenModeListPreference(mContext, mode);
category.addPreference(pref);
}
originalPreferences.remove(mode.getId());
}
// Remove preferences that no longer have a rule
for (String key : originalPreferences.keySet()) {
category.removePreferenceRecursively(key);
} }
} }
} }