Update top of modes page
* Show blurb based on mode type. * Make the icon bigger and highlight it when mode is active. * Increase spacing between elements. Also eliminate some code duplication between header of mode page and header of icon picker. Fixes: 355415875 Test: manual Flag: android.app.modes_ui Change-Id: I7e788b9b5920cedb791d1571b19b37e65ece6d0b
This commit is contained in:
25
res/drawable/ic_zen_mode_icon_cookie.xml
Normal file
25
res/drawable/ic_zen_mode_icon_cookie.xml
Normal 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="136dp"
|
||||||
|
android:height="136dp"
|
||||||
|
android:tint="?android:attr/colorControlNormal"
|
||||||
|
android:viewportHeight="136"
|
||||||
|
android:viewportWidth="136">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M58.0961 4.18448C58.326 3.95917 58.441 3.84652 58.5407 3.75268C63.8544 -1.25089 72.1456 -1.25089 77.4593 3.75268C77.559 3.84652 77.674 3.95917 77.9039 4.18448C78.0419 4.31967 78.1109 4.38727 78.1765 4.44986C81.5767 7.69486 86.3948 8.98588 90.962 7.87573C91.0501 7.85432 91.1436 7.83027 91.3307 7.78218C91.6425 7.70204 91.7984 7.66196 91.9317 7.63052C99.0352 5.95417 106.216 10.0998 108.316 17.0898C108.355 17.2209 108.398 17.376 108.485 17.6861C108.537 17.8722 108.563 17.9652 108.588 18.0522C109.91 22.5626 113.437 26.0897 117.948 27.4118C118.035 27.4373 118.128 27.4633 118.314 27.5152C118.624 27.6017 118.779 27.6449 118.91 27.6843C125.9 29.7844 130.046 36.9648 128.369 44.0684C128.338 44.2016 128.298 44.3575 128.218 44.6693C128.17 44.8564 128.146 44.9499 128.124 45.038C127.014 49.6052 128.305 54.4233 131.55 57.8235C131.613 57.8891 131.68 57.9581 131.816 58.0961C132.041 58.326 132.153 58.441 132.247 58.5407C137.251 63.8544 137.251 72.1456 132.247 77.4593C132.153 77.559 132.041 77.674 131.816 77.9039C131.68 78.0419 131.613 78.1109 131.55 78.1765C128.305 81.5767 127.014 86.3948 128.124 90.962C128.146 91.0501 128.17 91.1436 128.218 91.3307C128.298 91.6425 128.338 91.7984 128.369 91.9316C130.046 99.0352 125.9 106.216 118.91 108.316C118.779 108.355 118.624 108.398 118.314 108.485C118.128 108.537 118.035 108.563 117.948 108.588C113.437 109.91 109.91 113.437 108.588 117.948C108.563 118.035 108.537 118.128 108.485 118.314C108.398 118.624 108.355 118.779 108.316 118.91C106.216 125.9 99.0352 130.046 91.9316 128.369C91.7984 128.338 91.6425 128.298 91.3307 128.218C91.1436 128.17 91.0501 128.146 90.962 128.124C86.3948 127.014 81.5767 128.305 78.1765 131.55C78.1109 131.613 78.0419 131.68 77.9039 131.816C77.674 132.041 77.559 132.153 77.4593 132.247C72.1456 137.251 63.8544 137.251 58.5407 132.247C58.441 132.153 58.326 132.041 58.0961 131.816C57.9581 131.68 57.8891 131.613 57.8235 131.55C54.4233 128.305 49.6052 127.014 45.038 128.124C44.9499 128.146 44.8564 128.17 44.6693 128.218C44.3575 128.298 44.2016 128.338 44.0684 128.369C36.9648 130.046 29.7844 125.9 27.6843 118.91C27.6449 118.779 27.6017 118.624 27.5152 118.314C27.4633 118.128 27.4373 118.035 27.4118 117.948C26.0897 113.437 22.5626 109.91 18.0522 108.588C17.9652 108.563 17.8722 108.537 17.6861 108.485C17.376 108.398 17.2209 108.355 17.0898 108.316C10.0998 106.216 5.95417 99.0352 7.63052 91.9317C7.66196 91.7984 7.70204 91.6425 7.78218 91.3307C7.83027 91.1436 7.85432 91.0501 7.87573 90.962C8.98588 86.3948 7.69486 81.5767 4.44986 78.1765C4.38727 78.1109 4.31967 78.0419 4.18448 77.9039C3.95917 77.674 3.84652 77.559 3.75268 77.4593C-1.25089 72.1456 -1.25089 63.8544 3.75268 58.5407C3.84652 58.441 3.95917 58.326 4.18448 58.0961C4.31967 57.9581 4.38727 57.8891 4.44986 57.8235C7.69486 54.4233 8.98588 49.6052 7.87573 45.038C7.85432 44.9499 7.83027 44.8564 7.78218 44.6693C7.70204 44.3575 7.66196 44.2016 7.63052 44.0683C5.95417 36.9648 10.0998 29.7844 17.0898 27.6843C17.2209 27.6449 17.376 27.6017 17.6861 27.5152C17.8722 27.4633 17.9652 27.4373 18.0522 27.4118C22.5626 26.0897 26.0897 22.5626 27.4118 18.0522C27.4373 17.9652 27.4633 17.8722 27.5152 17.6861C27.6017 17.376 27.6449 17.2209 27.6843 17.0898C29.7844 10.0998 36.9648 5.95417 44.0683 7.63052C44.2016 7.66196 44.3575 7.70204 44.6693 7.78218C44.8564 7.83027 44.9499 7.85432 45.038 7.87573C49.6052 8.98588 54.4233 7.69486 57.8235 4.44986C57.8891 4.38727 57.9581 4.31967 58.0961 4.18448Z" />
|
||||||
|
</vector>
|
@@ -18,7 +18,8 @@
|
|||||||
<FrameLayout
|
<FrameLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingVertical="8dp">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/activate_mode"
|
android:id="@+id/activate_mode"
|
||||||
|
@@ -503,6 +503,9 @@
|
|||||||
<dimen name="audio_streams_qrcode_preview_radius">30dp</dimen>
|
<dimen name="audio_streams_qrcode_preview_radius">30dp</dimen>
|
||||||
|
|
||||||
<!-- Zen Modes -->
|
<!-- Zen Modes -->
|
||||||
|
<dimen name="zen_mode_header_size">136dp</dimen>
|
||||||
|
<dimen name="zen_mode_header_inner_icon_size">64dp</dimen>
|
||||||
|
<dimen name="zen_mode_blurb_text_size">16sp</dimen>
|
||||||
<dimen name="zen_mode_icon_list_header_circle_diameter">90dp</dimen>
|
<dimen name="zen_mode_icon_list_header_circle_diameter">90dp</dimen>
|
||||||
<dimen name="zen_mode_icon_list_header_icon_size">48dp</dimen>
|
<dimen name="zen_mode_icon_list_header_icon_size">48dp</dimen>
|
||||||
<dimen name="zen_mode_icon_list_item_size">96dp</dimen>
|
<dimen name="zen_mode_icon_list_item_size">96dp</dimen>
|
||||||
|
@@ -9511,6 +9511,23 @@
|
|||||||
<!-- Priority Modes: Button to disable a mode [CHAR LIMIT=20] -->
|
<!-- Priority Modes: Button to disable a mode [CHAR LIMIT=20] -->
|
||||||
<string name="zen_mode_action_enable">Enable</string>
|
<string name="zen_mode_action_enable">Enable</string>
|
||||||
|
|
||||||
|
<!-- Priority Modes: Blurb for a mode that activates during a fixed time schedule (e.g. 9:00-17:00). [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="zen_mode_blurb_schedule_time">Set a mode that follows a regular schedule</string>
|
||||||
|
<!-- Priority Modes: Blurb for a mode that activates during calendar events. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="zen_mode_blurb_schedule_calendar">Set a mode to sync with calendar events and invite responses</string>
|
||||||
|
<!-- Priority Modes: Blurb for a mode of type BEDTIME. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="zen_mode_blurb_bedtime">Design a calming sleep routine. Set alarms, dim the screen, and block notifications.</string>
|
||||||
|
<!-- Priority Modes: Blurb for a mode of type DRIVING. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="zen_mode_blurb_driving">Prioritize safety on the road for a focused and distraction-free drive</string>
|
||||||
|
<!-- Priority Modes: Blurb for a mode of type IMMERSIVE. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="zen_mode_blurb_immersive">Block distractions or interruptions from your device to gain focus</string>
|
||||||
|
<!-- Priority Modes: Blurb for a mode of type THEATER. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="zen_mode_blurb_theater">Eliminate all distractions for a quiet environment</string>
|
||||||
|
<!-- Priority Modes: Blurb for a mode of type MANAGED. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="zen_mode_blurb_managed">Personalize device experiences and settings for different users</string>
|
||||||
|
<!-- Priority Modes: Blurb for modes that are not of a specific type (OTHER, UNKNOWN). [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="zen_mode_blurb_generic">Minimize interruptions by only allowing important people and apps to reach you</string>
|
||||||
|
|
||||||
<!-- Content description for help icon button [CHAR LIMIT=20] -->
|
<!-- Content description for help icon button [CHAR LIMIT=20] -->
|
||||||
<string name="warning_button_text">Warning</string>
|
<string name="warning_button_text">Warning</string>
|
||||||
|
|
||||||
|
@@ -23,11 +23,23 @@
|
|||||||
android:key="header"
|
android:key="header"
|
||||||
android:layout="@layout/settings_entity_header" />
|
android:layout="@layout/settings_entity_header" />
|
||||||
|
|
||||||
|
<com.android.settings.applications.SpacePreference
|
||||||
|
android:layout_height="16dp" />
|
||||||
|
|
||||||
|
<com.android.settings.notification.modes.ZenModeBlurbPreference
|
||||||
|
android:key="mode_blurb" />
|
||||||
|
|
||||||
|
<com.android.settings.applications.SpacePreference
|
||||||
|
android:layout_height="8dp" />
|
||||||
|
|
||||||
<com.android.settingslib.widget.LayoutPreference
|
<com.android.settingslib.widget.LayoutPreference
|
||||||
android:key="activate"
|
android:key="activate"
|
||||||
android:selectable="false"
|
android:selectable="false"
|
||||||
android:layout="@layout/modes_activation_button"/>
|
android:layout="@layout/modes_activation_button"/>
|
||||||
|
|
||||||
|
<com.android.settings.applications.SpacePreference
|
||||||
|
android:layout_height="16dp" />
|
||||||
|
|
||||||
<!-- automatic trigger section; preference changes programmatically depending on type -->
|
<!-- automatic trigger section; preference changes programmatically depending on type -->
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="zen_automatic_trigger_category"
|
android:key="zen_automatic_trigger_category"
|
||||||
|
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* 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 android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
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.notification.modes.ZenIconLoader;
|
||||||
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
import com.android.settingslib.widget.LayoutPreference;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
abstract class AbstractZenModeHeaderController extends AbstractZenModePreferenceController {
|
||||||
|
|
||||||
|
private final DashboardFragment mFragment;
|
||||||
|
private EntityHeaderController mHeaderController;
|
||||||
|
|
||||||
|
AbstractZenModeHeaderController(
|
||||||
|
@NonNull Context context,
|
||||||
|
@NonNull String key,
|
||||||
|
@NonNull DashboardFragment fragment) {
|
||||||
|
super(context, key);
|
||||||
|
mFragment = fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return Flags.modesApi() && Flags.modesUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateIcon(Preference preference, @NonNull ZenMode zenMode, int iconSizePx,
|
||||||
|
Function<Drawable, Drawable> modeIconStylist,
|
||||||
|
@Nullable Consumer<ImageView> iconViewCustomizer) {
|
||||||
|
if (mFragment == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
preference.setSelectable(false);
|
||||||
|
|
||||||
|
if (mHeaderController == null) {
|
||||||
|
final LayoutPreference pref = (LayoutPreference) preference;
|
||||||
|
mHeaderController = EntityHeaderController.newInstance(
|
||||||
|
mFragment.getActivity(),
|
||||||
|
mFragment,
|
||||||
|
pref.findViewById(R.id.entity_header));
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageView iconView = ((LayoutPreference) preference).findViewById(R.id.entity_header_icon);
|
||||||
|
if (iconView != null) {
|
||||||
|
if (iconViewCustomizer != null) {
|
||||||
|
iconViewCustomizer.accept(iconView);
|
||||||
|
}
|
||||||
|
ViewGroup.LayoutParams layoutParams = iconView.getLayoutParams();
|
||||||
|
if (layoutParams.width != iconSizePx || layoutParams.height != iconSizePx) {
|
||||||
|
layoutParams.width = iconSizePx;
|
||||||
|
layoutParams.height = iconSizePx;
|
||||||
|
iconView.setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureUtil.whenDone(
|
||||||
|
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
||||||
|
icon -> mHeaderController
|
||||||
|
.setIcon(modeIconStylist.apply(icon))
|
||||||
|
.done(/* rebindActions= */ false),
|
||||||
|
mContext.getMainExecutor());
|
||||||
|
}
|
||||||
|
}
|
@@ -63,9 +63,27 @@ class IconUtil {
|
|||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a variant of the supplied mode icon to be used as the header in the mode page. The
|
||||||
|
* inner icon is 64x64 dp and it's contained in a 12-sided-cookie of 136dp diameter. It's
|
||||||
|
* tinted with the "material secondary" color combination and the "selected" color variant
|
||||||
|
* should be used for modes currently active.
|
||||||
|
*/
|
||||||
|
static Drawable makeModeHeader(@NonNull Context context, Drawable modeIcon) {
|
||||||
|
return composeIcons(
|
||||||
|
checkNotNull(context.getDrawable(R.drawable.ic_zen_mode_icon_cookie)),
|
||||||
|
context.getColorStateList(R.color.modes_icon_selectable_background),
|
||||||
|
context.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.zen_mode_header_size),
|
||||||
|
modeIcon,
|
||||||
|
context.getColorStateList(R.color.modes_icon_selectable_icon),
|
||||||
|
context.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.zen_mode_header_inner_icon_size));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a variant of the supplied {@code icon} to be used as the header in the icon picker.
|
* Returns a variant of the supplied {@code icon} to be used as the header in the icon picker.
|
||||||
* The inner icon is 48x48dp and it's contained into a circle of diameter 90dp.
|
* The inner icon is 48x48dp and it's contained in a circle of diameter 90dp.
|
||||||
*/
|
*/
|
||||||
static Drawable makeIconPickerHeader(@NonNull Context context, Drawable icon) {
|
static Drawable makeIconPickerHeader(@NonNull Context context, Drawable icon) {
|
||||||
return composeIconCircle(
|
return composeIconCircle(
|
||||||
@@ -82,16 +100,16 @@ class IconUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a variant of the supplied {@code icon} to be used as an option in the icon picker.
|
* Returns a variant of the supplied {@code icon} to be used as an option in the icon picker.
|
||||||
* The inner icon is 36x36dp and it's contained into a circle of diameter 54dp. It's also set up
|
* The inner icon is 36x36dp and it's contained in a circle of diameter 54dp. It's also set up
|
||||||
* so that selection and pressed states are represented in the color.
|
* so that selection and pressed states are represented in the color.
|
||||||
*/
|
*/
|
||||||
static Drawable makeIconPickerItem(@NonNull Context context, @DrawableRes int iconResId) {
|
static Drawable makeIconPickerItem(@NonNull Context context, @DrawableRes int iconResId) {
|
||||||
return composeIconCircle(
|
return composeIconCircle(
|
||||||
context.getColorStateList(R.color.modes_icon_picker_item_background),
|
context.getColorStateList(R.color.modes_icon_selectable_background),
|
||||||
context.getResources().getDimensionPixelSize(
|
context.getResources().getDimensionPixelSize(
|
||||||
R.dimen.zen_mode_icon_list_item_circle_diameter),
|
R.dimen.zen_mode_icon_list_item_circle_diameter),
|
||||||
checkNotNull(context.getDrawable(iconResId)),
|
checkNotNull(context.getDrawable(iconResId)),
|
||||||
context.getColorStateList(R.color.modes_icon_picker_item_icon),
|
context.getColorStateList(R.color.modes_icon_selectable_icon),
|
||||||
context.getResources().getDimensionPixelSize(
|
context.getResources().getDimensionPixelSize(
|
||||||
R.dimen.zen_mode_icon_list_item_icon_size));
|
R.dimen.zen_mode_icon_list_item_icon_size));
|
||||||
}
|
}
|
||||||
@@ -164,18 +182,24 @@ class IconUtil {
|
|||||||
|
|
||||||
private static Drawable composeIconCircle(ColorStateList circleColor, @Px int circleDiameterPx,
|
private static Drawable composeIconCircle(ColorStateList circleColor, @Px int circleDiameterPx,
|
||||||
Drawable icon, ColorStateList iconColor, @Px int iconSizePx) {
|
Drawable icon, ColorStateList iconColor, @Px int iconSizePx) {
|
||||||
ShapeDrawable background = new ShapeDrawable(new OvalShape());
|
return composeIcons(new ShapeDrawable(new OvalShape()), circleColor, circleDiameterPx, icon,
|
||||||
background.setTintList(circleColor);
|
iconColor, iconSizePx);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Drawable composeIcons(Drawable outer, ColorStateList outerColor,
|
||||||
|
@Px int outerSizePx, Drawable icon, ColorStateList iconColor, @Px int iconSizePx) {
|
||||||
|
Drawable background = checkNotNull(outer.getConstantState()).newDrawable().mutate();
|
||||||
|
background.setTintList(outerColor);
|
||||||
Drawable foreground = checkNotNull(icon.getConstantState()).newDrawable().mutate();
|
Drawable foreground = checkNotNull(icon.getConstantState()).newDrawable().mutate();
|
||||||
foreground.setTintList(iconColor);
|
foreground.setTintList(iconColor);
|
||||||
|
|
||||||
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, foreground });
|
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, foreground });
|
||||||
|
|
||||||
layerDrawable.setLayerSize(0, circleDiameterPx, circleDiameterPx);
|
layerDrawable.setLayerSize(0, outerSizePx, outerSizePx);
|
||||||
layerDrawable.setLayerGravity(1, Gravity.CENTER);
|
layerDrawable.setLayerGravity(1, Gravity.CENTER);
|
||||||
layerDrawable.setLayerSize(1, iconSizePx, iconSizePx);
|
layerDrawable.setLayerSize(1, iconSizePx, iconSizePx);
|
||||||
|
|
||||||
layerDrawable.setBounds(0, 0, circleDiameterPx, circleDiameterPx);
|
layerDrawable.setBounds(0, 0, outerSizePx, outerSizePx);
|
||||||
return layerDrawable;
|
return layerDrawable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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 static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.widget.TopIntroPreference;
|
||||||
|
|
||||||
|
public class ZenModeBlurbPreference extends TopIntroPreference {
|
||||||
|
|
||||||
|
public ZenModeBlurbPreference(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZenModeBlurbPreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
|
super.onBindViewHolder(holder);
|
||||||
|
if (holder.findViewById(android.R.id.title) instanceof TextView textView) {
|
||||||
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
|
||||||
|
getContext().getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.zen_mode_blurb_text_size));
|
||||||
|
|
||||||
|
textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||||
|
|
||||||
|
ViewGroup.LayoutParams layoutParams = textView.getLayoutParams();
|
||||||
|
if (layoutParams.width != MATCH_PARENT) {
|
||||||
|
layoutParams.width = MATCH_PARENT;
|
||||||
|
textView.setLayoutParams(layoutParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* 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 static android.app.AutomaticZenRule.TYPE_BEDTIME;
|
||||||
|
import static android.app.AutomaticZenRule.TYPE_DRIVING;
|
||||||
|
import static android.app.AutomaticZenRule.TYPE_IMMERSIVE;
|
||||||
|
import static android.app.AutomaticZenRule.TYPE_MANAGED;
|
||||||
|
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_CALENDAR;
|
||||||
|
import static android.app.AutomaticZenRule.TYPE_SCHEDULE_TIME;
|
||||||
|
import static android.app.AutomaticZenRule.TYPE_THEATER;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.StringRes;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
|
|
||||||
|
class ZenModeBlurbPreferenceController extends AbstractZenModePreferenceController {
|
||||||
|
|
||||||
|
ZenModeBlurbPreferenceController(@NonNull Context context, @NonNull String key) {
|
||||||
|
super(context, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
||||||
|
preference.setTitle(getModeBlurb(zenMode));
|
||||||
|
}
|
||||||
|
|
||||||
|
@StringRes
|
||||||
|
@SuppressLint("SwitchIntDef")
|
||||||
|
private static int getModeBlurb(ZenMode mode) {
|
||||||
|
if (mode.isSystemOwned()) {
|
||||||
|
return switch (mode.getType()) {
|
||||||
|
case TYPE_SCHEDULE_TIME -> R.string.zen_mode_blurb_schedule_time;
|
||||||
|
case TYPE_SCHEDULE_CALENDAR -> R.string.zen_mode_blurb_schedule_calendar;
|
||||||
|
default -> R.string.zen_mode_blurb_generic; // Custom Manual
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return switch (mode.getType()) {
|
||||||
|
case TYPE_BEDTIME -> R.string.zen_mode_blurb_bedtime;
|
||||||
|
case TYPE_DRIVING -> R.string.zen_mode_blurb_driving;
|
||||||
|
case TYPE_IMMERSIVE -> R.string.zen_mode_blurb_immersive;
|
||||||
|
case TYPE_THEATER -> R.string.zen_mode_blurb_theater;
|
||||||
|
case TYPE_MANAGED -> R.string.zen_mode_blurb_managed;
|
||||||
|
default -> R.string.zen_mode_blurb_generic; // Including OTHER, UNKNOWN.
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -51,6 +51,7 @@ public class ZenModeFragment extends ZenModeFragmentBase {
|
|||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
List<AbstractPreferenceController> prefControllers = new ArrayList<>();
|
List<AbstractPreferenceController> prefControllers = new ArrayList<>();
|
||||||
prefControllers.add(new ZenModeHeaderController(context, "header", this));
|
prefControllers.add(new ZenModeHeaderController(context, "header", this));
|
||||||
|
prefControllers.add(new ZenModeBlurbPreferenceController(context, "mode_blurb"));
|
||||||
prefControllers.add(
|
prefControllers.add(
|
||||||
new ZenModeButtonPreferenceController(context, "activate", this, mBackend));
|
new ZenModeButtonPreferenceController(context, "activate", this, mBackend));
|
||||||
prefControllers.add(new ZenModePreferenceCategoryController(context, "modes_filters"));
|
prefControllers.add(new ZenModePreferenceCategoryController(context, "modes_filters"));
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import android.app.Flags;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -23,48 +22,22 @@ import androidx.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.widget.EntityHeaderController;
|
|
||||||
import com.android.settingslib.notification.modes.ZenIconLoader;
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
|
||||||
|
|
||||||
class ZenModeHeaderController extends AbstractZenModePreferenceController {
|
class ZenModeHeaderController extends AbstractZenModeHeaderController {
|
||||||
|
|
||||||
private final DashboardFragment mFragment;
|
|
||||||
private EntityHeaderController mHeaderController;
|
|
||||||
|
|
||||||
ZenModeHeaderController(
|
ZenModeHeaderController(
|
||||||
@NonNull Context context,
|
@NonNull Context context,
|
||||||
@NonNull String key,
|
@NonNull String key,
|
||||||
@NonNull DashboardFragment fragment) {
|
@NonNull DashboardFragment fragment) {
|
||||||
super(context, key);
|
super(context, key, fragment);
|
||||||
mFragment = fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAvailable() {
|
|
||||||
return Flags.modesApi();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
||||||
if (mFragment == null) {
|
updateIcon(preference, zenMode,
|
||||||
return;
|
mContext.getResources().getDimensionPixelSize(R.dimen.zen_mode_header_size),
|
||||||
}
|
icon -> IconUtil.makeModeHeader(mContext, icon),
|
||||||
preference.setSelectable(false);
|
iconView -> iconView.setSelected(zenMode.isActive()));
|
||||||
|
|
||||||
if (mHeaderController == null) {
|
|
||||||
final LayoutPreference pref = (LayoutPreference) preference;
|
|
||||||
mHeaderController = EntityHeaderController.newInstance(
|
|
||||||
mFragment.getActivity(),
|
|
||||||
mFragment,
|
|
||||||
pref.findViewById(R.id.entity_header));
|
|
||||||
}
|
|
||||||
|
|
||||||
FutureUtil.whenDone(
|
|
||||||
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
|
||||||
icon -> mHeaderController.setIcon(IconUtil.applyNormalTint(mContext, icon))
|
|
||||||
.done(/* rebindActions= */ false),
|
|
||||||
mContext.getMainExecutor());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,55 +17,28 @@
|
|||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.widget.EntityHeaderController;
|
|
||||||
import com.android.settingslib.notification.modes.ZenIconLoader;
|
|
||||||
import com.android.settingslib.notification.modes.ZenMode;
|
import com.android.settingslib.notification.modes.ZenMode;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
|
||||||
|
|
||||||
/** Controller used for displaying the currently-chosen icon at the top of the icon picker. */
|
/** Controller used for displaying the currently-chosen icon at the top of the icon picker. */
|
||||||
class ZenModeIconPickerIconPreferenceController extends AbstractZenModePreferenceController {
|
class ZenModeIconPickerIconPreferenceController extends AbstractZenModeHeaderController {
|
||||||
|
|
||||||
private final DashboardFragment mFragment;
|
|
||||||
private EntityHeaderController mHeaderController;
|
|
||||||
|
|
||||||
ZenModeIconPickerIconPreferenceController(@NonNull Context context, @NonNull String key,
|
ZenModeIconPickerIconPreferenceController(@NonNull Context context, @NonNull String key,
|
||||||
@NonNull DashboardFragment fragment) {
|
@NonNull DashboardFragment fragment) {
|
||||||
super(context, key);
|
super(context, key, fragment);
|
||||||
mFragment = fragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
void updateState(Preference preference, @NonNull ZenMode zenMode) {
|
||||||
preference.setSelectable(false);
|
updateIcon(preference, zenMode,
|
||||||
|
mContext.getResources().getDimensionPixelSize(
|
||||||
if (mHeaderController == null) {
|
R.dimen.zen_mode_icon_list_header_circle_diameter),
|
||||||
final LayoutPreference pref = (LayoutPreference) preference;
|
icon -> IconUtil.makeIconPickerHeader(mContext, icon),
|
||||||
mHeaderController = EntityHeaderController.newInstance(
|
null);
|
||||||
mFragment.getActivity(),
|
|
||||||
mFragment,
|
|
||||||
pref.findViewById(R.id.entity_header));
|
|
||||||
|
|
||||||
ImageView iconView = pref.findViewById(R.id.entity_header_icon);
|
|
||||||
ViewGroup.LayoutParams layoutParams = iconView.getLayoutParams();
|
|
||||||
int imageSizePx = iconView.getContext().getResources().getDimensionPixelSize(
|
|
||||||
R.dimen.zen_mode_icon_list_header_circle_diameter);
|
|
||||||
layoutParams.width = imageSizePx;
|
|
||||||
layoutParams.height = imageSizePx;
|
|
||||||
iconView.setLayoutParams(layoutParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
FutureUtil.whenDone(
|
|
||||||
zenMode.getIcon(mContext, ZenIconLoader.getInstance()),
|
|
||||||
icon -> mHeaderController.setIcon(IconUtil.makeIconPickerHeader(mContext, icon))
|
|
||||||
.done(/* rebindActions= */ false),
|
|
||||||
mContext.getMainExecutor());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user