Some minor additions (icons, sorting) to modes

Test: manually viewing pages
Flag: android.app.modes_ui
Fixes: 331429435
Fixes: 308819461
Bug: 322373473
Change-Id: I17e6df82e17a4cfadc2948258829746cdb5473db
This commit is contained in:
Julia Reynolds
2024-05-16 16:26:33 -04:00
parent 66b69fbbb8
commit b42553dccc
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"
android:title="@string/zen_modes_list_title" >
<!-- TODO: b/308819292 - implement page, delete this test preference -->
<Preference
android:key="zen_mode_test" />
<com.android.settingslib.widget.LayoutPreference
android:key="header"
android:layout="@layout/settings_entity_header" />
</PreferenceScreen>

View File

@@ -155,8 +155,8 @@ class ZenMode {
int iconResIdFromType = switch (mRule.getType()) {
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_SCHEDULE_TIME -> R.drawable.ic_do_not_disturb_on_24dp;
case AutomaticZenRule.TYPE_SCHEDULE_CALENDAR -> 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_modes_event;
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_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
// {@link AbstractZenModePreferenceController}.
List<AbstractPreferenceController> prefControllers = new ArrayList<>();
prefControllers.add(new ZenModeHeaderController(context, "header", this, mBackend));
return prefControllers;
}
@@ -55,19 +56,6 @@ public class ZenModeFragment extends ZenModeFragmentBase {
return;
}
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

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.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 leads to an individual mode's configuration page.
@@ -36,10 +40,8 @@ public class ZenModeListPreference extends RestrictedPreference {
ZenModeListPreference(Context context, ZenMode zenMode) {
super(context);
mContext = context;
mZenMode = zenMode;
setTitle(mZenMode.getRule().getName());
setSummary((mZenMode.isActive() ? "ACTIVE" : "inactive") + ": "
+ mZenMode.getRule().getTriggerDescription());
setZenMode(zenMode);
setKey(zenMode.getId());
}
@Override
@@ -60,6 +62,16 @@ public class ZenModeListPreference extends RestrictedPreference {
.setSourceMetricsCategory(SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION)
.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.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
@@ -77,7 +78,15 @@ class ZenModesBackend {
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;
}
@@ -105,10 +114,10 @@ class ZenModesBackend {
.setZenPolicy(ZenAdapters.notificationPolicyToZenPolicy(
mNotificationManager.getNotificationPolicy()))
.setDeviceEffects(null)
.setTriggerDescription(mContext.getString(R.string.zen_mode_settings_summary))
.setManualInvocationAllowed(true)
.setConfigurationActivity(null) // No further settings
.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY)
.setIconResId(com.android.internal.R.drawable.ic_zen_24dp)
.build();
return ZenMode.manualDndMode(manualDndRule,

View File

@@ -15,6 +15,7 @@
*/
package com.android.settings.notification.modes;
import android.app.AutomaticZenRule;
import android.app.Flags;
import android.content.Context;
@@ -26,6 +27,9 @@ import androidx.preference.PreferenceCategory;
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})
* 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.
PreferenceCategory category = (PreferenceCategory) preference;
// TODO: b/322373473 - This is not the right way to replace these preferences; we should
// follow something similar to what
// ZenModeAutomaticRulesPreferenceController does to change rules
// only as necessary and update them.
category.removeAll();
Map<String, ZenModeListPreference> originalPreferences = new HashMap<>();
for (int i = 0; i < category.getPreferenceCount(); i++) {
ZenModeListPreference pref = (ZenModeListPreference) category.getPreference(i);
originalPreferences.put(pref.getKey(), pref);
}
// Loop through each rule, either updating the existing rule or creating the rule's
// preference
for (ZenMode mode : mBackend.getModes()) {
Preference pref = new ZenModeListPreference(mContext, mode);
category.addPreference(pref);
if (originalPreferences.containsKey(mode.getId())) {
// 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);
}
}
}