diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-14 00:20:39 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-12-14 00:20:39 +0000 |
commit | 19cd5b34fcbf8dbf6668f8a870ed634d6d639010 (patch) | |
tree | 406973339ec3c417236a25c3e8ad7faadcc8a3f5 | |
parent | 5b570a500b79f40b6a9d7b534bb9dc5b81ca3e4e (diff) | |
parent | e65d91df9bb6b4522ee09df54e886b7b4f42f182 (diff) | |
download | Settings-android14-qpr2-release.tar.gz |
Snap for 11216811 from e65d91df9bb6b4522ee09df54e886b7b4f42f182 to 24Q1-releaseandroid-14.0.0_r33android-14.0.0_r32android-14.0.0_r31android-14.0.0_r30android-14.0.0_r29android14-qpr2-s3-releaseandroid14-qpr2-s2-releaseandroid14-qpr2-s1-releaseandroid14-qpr2-release
Change-Id: I1866019c3aae0214151612c8fdba8e6976bd6e02
-rw-r--r-- | res/drawable/ic_qc_ui_mode_auto.xml | 26 | ||||
-rw-r--r-- | res/drawable/ic_qc_ui_mode_day.xml | 26 | ||||
-rw-r--r-- | res/drawable/ic_qc_ui_mode_night.xml | 26 | ||||
-rw-r--r-- | res/values/overlayable.xml | 4 | ||||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/android/car/settings/qc/SettingsQCRegistry.java | 7 | ||||
-rw-r--r-- | src/com/android/car/settings/qc/ThemeToggle.java | 124 | ||||
-rw-r--r-- | src/com/android/car/settings/qc/ThemeToggleWorker.java | 74 |
8 files changed, 289 insertions, 0 deletions
diff --git a/res/drawable/ic_qc_ui_mode_auto.xml b/res/drawable/ic_qc_ui_mode_auto.xml new file mode 100644 index 000000000..715400561 --- /dev/null +++ b/res/drawable/ic_qc_ui_mode_auto.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2023 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="@dimen/icon_size" + android:height="@dimen/icon_size" + android:viewportHeight="48.0" + android:viewportWidth="48.0"> + <path + android:fillColor="@color/qc_default_icon_color" + android:pathData="M15.5,32.75H18.25L20.1,27.3H28.05L29.95,32.75H32.6L25.25,13.15H22.85ZM20.85,24.9 L23.9,16.75H24.15L27.25,24.9ZM24.05,46.55 L17.3,40H8V30.7L1.3,24L8,17.3V8H17.3L24.05,1.3L30.7,8H40V17.3L46.7,24L40,30.7V40H30.7ZM24.05,23.95ZM24.05,42.35 L29.45,37H37V29.45L42.45,24L37,18.55V11H29.45L24.05,5.55L18.55,11H11V18.55L5.55,24L11,29.45V37H18.5Z"/> +</vector> diff --git a/res/drawable/ic_qc_ui_mode_day.xml b/res/drawable/ic_qc_ui_mode_day.xml new file mode 100644 index 000000000..7dabede1b --- /dev/null +++ b/res/drawable/ic_qc_ui_mode_day.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2023 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="@dimen/icon_size" + android:height="@dimen/icon_size" + android:viewportHeight="48.0" + android:viewportWidth="48.0"> + <path + android:fillColor="@color/qc_default_icon_color" + android:pathData="M24,31Q26.9,31 28.95,28.95Q31,26.9 31,24Q31,21.1 28.95,19.05Q26.9,17 24,17Q21.1,17 19.05,19.05Q17,21.1 17,24Q17,26.9 19.05,28.95Q21.1,31 24,31ZM24,34Q19.85,34 16.925,31.075Q14,28.15 14,24Q14,19.85 16.925,16.925Q19.85,14 24,14Q28.15,14 31.075,16.925Q34,19.85 34,24Q34,28.15 31.075,31.075Q28.15,34 24,34ZM3.5,25.5Q2.85,25.5 2.425,25.075Q2,24.65 2,24Q2,23.35 2.425,22.925Q2.85,22.5 3.5,22.5H8.5Q9.15,22.5 9.575,22.925Q10,23.35 10,24Q10,24.65 9.575,25.075Q9.15,25.5 8.5,25.5ZM39.5,25.5Q38.85,25.5 38.425,25.075Q38,24.65 38,24Q38,23.35 38.425,22.925Q38.85,22.5 39.5,22.5H44.5Q45.15,22.5 45.575,22.925Q46,23.35 46,24Q46,24.65 45.575,25.075Q45.15,25.5 44.5,25.5ZM24,10Q23.35,10 22.925,9.575Q22.5,9.15 22.5,8.5V3.5Q22.5,2.85 22.925,2.425Q23.35,2 24,2Q24.65,2 25.075,2.425Q25.5,2.85 25.5,3.5V8.5Q25.5,9.15 25.075,9.575Q24.65,10 24,10ZM24,46Q23.35,46 22.925,45.575Q22.5,45.15 22.5,44.5V39.5Q22.5,38.85 22.925,38.425Q23.35,38 24,38Q24.65,38 25.075,38.425Q25.5,38.85 25.5,39.5V44.5Q25.5,45.15 25.075,45.575Q24.65,46 24,46ZM12,14.1 L9.15,11.3Q8.7,10.85 8.725,10.225Q8.75,9.6 9.15,9.15Q9.6,8.7 10.225,8.7Q10.85,8.7 11.3,9.15L14.1,12Q14.5,12.45 14.5,13.05Q14.5,13.65 14.1,14.05Q13.7,14.5 13.075,14.5Q12.45,14.5 12,14.1ZM36.7,38.85 L33.9,36Q33.5,35.55 33.5,34.925Q33.5,34.3 33.95,33.9Q34.35,33.45 34.95,33.45Q35.55,33.45 36,33.9L38.85,36.7Q39.3,37.15 39.275,37.775Q39.25,38.4 38.85,38.85Q38.4,39.3 37.775,39.3Q37.15,39.3 36.7,38.85ZM33.9,14.1Q33.45,13.65 33.45,13.05Q33.45,12.45 33.9,12L36.7,9.15Q37.15,8.7 37.775,8.725Q38.4,8.75 38.85,9.15Q39.3,9.6 39.3,10.225Q39.3,10.85 38.85,11.3L36,14.1Q35.6,14.5 34.975,14.5Q34.35,14.5 33.9,14.1ZM9.15,38.85Q8.7,38.4 8.7,37.775Q8.7,37.15 9.15,36.7L12,33.9Q12.45,33.45 13.05,33.45Q13.65,33.45 14.1,33.9Q14.55,34.35 14.55,34.95Q14.55,35.55 14.1,36L11.3,38.85Q10.85,39.3 10.225,39.275Q9.6,39.25 9.15,38.85ZM24,24Q24,24 24,24Q24,24 24,24Q24,24 24,24Q24,24 24,24Q24,24 24,24Q24,24 24,24Q24,24 24,24Q24,24 24,24Z"/> +</vector> diff --git a/res/drawable/ic_qc_ui_mode_night.xml b/res/drawable/ic_qc_ui_mode_night.xml new file mode 100644 index 000000000..3dc615df3 --- /dev/null +++ b/res/drawable/ic_qc_ui_mode_night.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2023 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="@dimen/icon_size" + android:height="@dimen/icon_size" + android:viewportHeight="48.0" + android:viewportWidth="48.0"> + <path + android:fillColor="@color/qc_default_icon_color" + android:pathData="M24,42Q16.5,42 11.25,36.75Q6,31.5 6,24Q6,16.5 11.25,11.25Q16.5,6 24,6Q24.4,6 24.85,6.025Q25.3,6.05 26,6.1Q24.2,7.7 23.2,10.05Q22.2,12.4 22.2,15Q22.2,19.5 25.35,22.65Q28.5,25.8 33,25.8Q35.6,25.8 37.95,24.875Q40.3,23.95 41.9,22.3Q41.95,22.9 41.975,23.275Q42,23.65 42,24Q42,31.5 36.75,36.75Q31.5,42 24,42ZM24,39Q29.45,39 33.5,35.625Q37.55,32.25 38.55,27.7Q37.3,28.25 35.875,28.525Q34.45,28.8 33,28.8Q27.25,28.8 23.225,24.775Q19.2,20.75 19.2,15Q19.2,13.8 19.45,12.425Q19.7,11.05 20.35,9.3Q15.45,10.65 12.225,14.775Q9,18.9 9,24Q9,30.25 13.375,34.625Q17.75,39 24,39ZM23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Q23.8,24.15 23.8,24.15Z"/> +</vector> diff --git a/res/values/overlayable.xml b/res/values/overlayable.xml index 2f9000e2d..8f6da9ebb 100644 --- a/res/values/overlayable.xml +++ b/res/values/overlayable.xml @@ -350,6 +350,9 @@ REGENERATE USING packages/apps/Car/libs/tools/rro/generate-overlayable.py <item type="drawable" name="ic_qc_brightness"/> <item type="drawable" name="ic_qc_hotspot"/> <item type="drawable" name="ic_qc_mobile_data"/> + <item type="drawable" name="ic_qc_ui_mode_auto"/> + <item type="drawable" name="ic_qc_ui_mode_day"/> + <item type="drawable" name="ic_qc_ui_mode_night"/> <item type="drawable" name="ic_qc_wifi_disabled"/> <item type="drawable" name="ic_qc_wifi_disconnected"/> <item type="drawable" name="ic_qc_wifi_level_0"/> @@ -1229,6 +1232,7 @@ REGENERATE USING packages/apps/Car/libs/tools/rro/generate-overlayable.py <item type="string" name="qc_bluetooth_off_devices_info"/> <item type="string" name="qc_bluetooth_on_no_devices_info"/> <item type="string" name="qc_display_brightness"/> + <item type="string" name="qc_ui_mode_title"/> <item type="string" name="really_remove_account_message"/> <item type="string" name="really_remove_account_title"/> <item type="string" name="regulatory_info_text"/> diff --git a/res/values/strings.xml b/res/values/strings.xml index 3c7be1137..5e67c9c54 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1845,6 +1845,8 @@ <string name="qc_bluetooth_off_devices_info">To see your devices, turn on Bluetooth</string> <!-- Informational text to be shown when bluetooth devices can't be shown in quick controls because no devices are paired [CHAR LIMIT=75] --> <string name="qc_bluetooth_on_no_devices_info">To pair a device, open Bluetooth settings</string> + <!-- UI Mode quick control, control name to change display UI mode (auto/day/night) [CHAR LIMIT=40] --> + <string name="qc_ui_mode_title">Theme</string> <!-- Device Policy Management --><skip/> <!-- Device admin add activity title --> diff --git a/src/com/android/car/settings/qc/SettingsQCRegistry.java b/src/com/android/car/settings/qc/SettingsQCRegistry.java index 89a2d8214..bd305fcda 100644 --- a/src/com/android/car/settings/qc/SettingsQCRegistry.java +++ b/src/com/android/car/settings/qc/SettingsQCRegistry.java @@ -103,6 +103,12 @@ public class SettingsQCRegistry { .appendPath("adaptive_brightness_switch") .build(); + public static final Uri THEME_TOGGLE_URI = new Uri.Builder() + .scheme(ContentResolver.SCHEME_CONTENT) + .authority(AUTHORITY) + .appendPath("theme_toggle") + .build(); + public static final Uri MEDIA_VOLUME_SLIDER_URI = new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority(AUTHORITY) @@ -146,6 +152,7 @@ public class SettingsQCRegistry { map.put(BRIGHTNESS_SLIDER_URI, BrightnessSlider.class); map.put(BRIGHTNESS_SLIDER_WITH_ICON_URI, BrightnessSliderWithIcon.class); map.put(ADAPTIVE_BRIGHTNESS_SWITCH_URI, AdaptiveBrightnessSwitch.class); + map.put(THEME_TOGGLE_URI, ThemeToggle.class); map.put(MEDIA_VOLUME_SLIDER_URI, MediaVolumeSlider.class); map.put(MEDIA_VOLUME_SLIDER_WITHOUT_ICON_URI, MediaVolumeSliderWithoutIcon.class); map.put(CALL_VOLUME_SLIDER_URI, CallVolumeSlider.class); diff --git a/src/com/android/car/settings/qc/ThemeToggle.java b/src/com/android/car/settings/qc/ThemeToggle.java new file mode 100644 index 000000000..63454f4cc --- /dev/null +++ b/src/com/android/car/settings/qc/ThemeToggle.java @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2023 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.car.settings.qc; + +import static android.car.settings.CarSettings.Global.FORCED_DAY_NIGHT_MODE; + +import static com.android.car.qc.QCItem.QC_TYPE_ACTION_TOGGLE; + +import android.app.PendingIntent; +import android.car.feature.Flags; +import android.content.Context; +import android.content.Intent; +import android.graphics.drawable.Icon; +import android.net.Uri; +import android.os.Bundle; +import android.provider.Settings; + +import com.android.car.qc.QCActionItem; +import com.android.car.qc.QCItem; +import com.android.car.qc.QCList; +import com.android.car.qc.QCRow; +import com.android.car.settings.R; + +/** + * QC Item to control the day/night theme mode. + */ +public final class ThemeToggle extends SettingsQCItem { + static final String EXTRA_BUTTON_TYPE = "THEME_MODE_EXTRA_BUTTON_TYPE"; + static final int FORCED_SENSOR_MODE = 0; + static final int FORCED_DAY_MODE = 1; + static final int FORCED_NIGHT_MODE = 2; + + public ThemeToggle(Context context) { + super(context); + } + + @Override + QCItem getQCItem() { + if (!Flags.carNightGlobalSetting()) { + return null; + } + QCList.Builder listBuilder = new QCList.Builder(); + listBuilder.addRow(new QCRow.Builder() + .setTitle(getContext().getString(R.string.qc_ui_mode_title)) + .addEndItem(createThemeToggleButton(FORCED_SENSOR_MODE)) + .addEndItem(createThemeToggleButton(FORCED_DAY_MODE)) + .addEndItem(createThemeToggleButton(FORCED_NIGHT_MODE)) + .build()); + + return listBuilder.build(); + } + + @Override + Uri getUri() { + return SettingsQCRegistry.THEME_TOGGLE_URI; + } + + @Override + void onNotifyChange(Intent intent) { + int buttonType = intent.getIntExtra(EXTRA_BUTTON_TYPE, -1); + if (buttonType == -1) return; + + if (!(buttonType == getForcedDayNightModeSetting())) { + setForcedDayNightModeSetting(buttonType); + } + } + + @Override + Class getBackgroundWorkerClass() { + if (!Flags.carNightGlobalSetting()) { + return null; + } + return ThemeToggleWorker.class; + } + + private QCActionItem createThemeToggleButton(int mode) { + Bundle extras = new Bundle(); + extras.putInt(EXTRA_BUTTON_TYPE, mode); + PendingIntent action = getBroadcastIntent(extras, mode); + boolean isSelected = getForcedDayNightModeSetting() == mode; + + return new QCActionItem.Builder(QC_TYPE_ACTION_TOGGLE) + .setAction(action) + .setIcon(getThemeModeIcon(mode)) + .setChecked(isSelected) + .setClickable(!isSelected) + .build(); + } + + private int getForcedDayNightModeSetting() { + return Settings.Global.getInt(getContext().getContentResolver(), + FORCED_DAY_NIGHT_MODE, FORCED_SENSOR_MODE); + } + + private void setForcedDayNightModeSetting(int mode) { + Settings.Global.putInt(getContext().getContentResolver(), FORCED_DAY_NIGHT_MODE, mode); + } + + private Icon getThemeModeIcon(int mode) { + switch(mode) { + case FORCED_SENSOR_MODE: + return Icon.createWithResource(getContext(), R.drawable.ic_qc_ui_mode_auto); + case FORCED_DAY_MODE: + return Icon.createWithResource(getContext(), R.drawable.ic_qc_ui_mode_day); + case FORCED_NIGHT_MODE: + return Icon.createWithResource(getContext(), R.drawable.ic_qc_ui_mode_night); + } + return null; + } +} diff --git a/src/com/android/car/settings/qc/ThemeToggleWorker.java b/src/com/android/car/settings/qc/ThemeToggleWorker.java new file mode 100644 index 000000000..c109f6703 --- /dev/null +++ b/src/com/android/car/settings/qc/ThemeToggleWorker.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2023 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.car.settings.qc; + +import static android.car.settings.CarSettings.Global.FORCED_DAY_NIGHT_MODE; + +import android.content.Context; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.Handler; +import android.os.Looper; +import android.provider.Settings; + +import java.io.IOException; + +/** + * Background worker for the {@link ThemeToggle} QCItem. + */ +public final class ThemeToggleWorker extends SettingsQCBackgroundWorker<ThemeToggle> { + private boolean mContentObserverRegistered; + private final ContentObserver mForcedNightModeObserver = + new ContentObserver(new Handler(Looper.getMainLooper())) { + @Override + public void onChange(boolean selfChange) { + notifyQCItemChange(); + } + }; + + public ThemeToggleWorker(Context context, Uri uri) { + super(context, uri); + } + + @Override + protected void onQCItemSubscribe() { + if (!mContentObserverRegistered) { + getContext().getContentResolver().registerContentObserver( + Settings.Global.getUriFor(FORCED_DAY_NIGHT_MODE), + false /* notifyForDescendants */, + mForcedNightModeObserver); + mContentObserverRegistered = true; + } + } + + @Override + protected void onQCItemUnsubscribe() { + unregisterContentObserver(); + } + + @Override + public void close() throws IOException { + unregisterContentObserver(); + } + + private void unregisterContentObserver() { + if (mContentObserverRegistered) { + getContext().getContentResolver().unregisterContentObserver(mForcedNightModeObserver); + mContentObserverRegistered = false; + } + } +} |