Use MainSwitchPreference to replace the button style switches.
Fix: 177967926 Fix: 177968295 Fix: 177967925 Fix: 177968078 Test: Run robotest and apply the widget in Settings and see the ui Change-Id: Ie854de96e5495fa564fb8a097ed4547bbd2b10c5
This commit is contained in:
@@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2019 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/dark_ui_turn_on_button"
|
|
||||||
style="@style/ActionPrimaryButton"
|
|
||||||
android:layout_marginStart="@dimen/screen_margin_sides"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/dark_ui_turn_off_button"
|
|
||||||
style="@style/ActionSecondaryButton"
|
|
||||||
android:layout_marginStart="@dimen/screen_margin_sides"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2018 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/night_display_turn_on_button"
|
|
||||||
style="@style/ActionPrimaryButton"
|
|
||||||
android:layout_marginStart="@dimen/screen_margin_sides"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/night_display_turn_off_button"
|
|
||||||
style="@style/ActionSecondaryButton"
|
|
||||||
android:layout_marginStart="@dimen/screen_margin_sides"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@@ -1,55 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2017 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:text="@string/zen_mode_settings_summary"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="@dimen/screen_margin_sides"
|
|
||||||
android:layout_marginEnd="@dimen/description_margin_sides"
|
|
||||||
android:layout_marginTop="@dimen/zen_mode_settings_button_margin_vertical"/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/zen_mode_settings_turn_on_button"
|
|
||||||
style="@style/ActionPrimaryButton"
|
|
||||||
android:layout_marginStart="@dimen/screen_margin_sides"
|
|
||||||
android:layout_marginEnd="@dimen/description_margin_sides"
|
|
||||||
android:layout_marginTop="@dimen/zen_mode_settings_button_margin_vertical"
|
|
||||||
android:layout_marginBottom="@dimen/zen_mode_settings_button_margin_vertical"
|
|
||||||
android:text="@string/zen_mode_button_turn_on"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/zen_mode_settings_turn_off_button"
|
|
||||||
style="@style/ActionSecondaryButton"
|
|
||||||
android:layout_marginStart="@dimen/screen_margin_sides"
|
|
||||||
android:layout_marginEnd="@dimen/description_margin_sides"
|
|
||||||
android:layout_marginTop="@dimen/zen_mode_settings_button_margin_vertical"
|
|
||||||
android:layout_marginBottom="@dimen/zen_mode_settings_button_margin_vertical"
|
|
||||||
android:text="@string/zen_mode_button_turn_off"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@@ -12670,6 +12670,18 @@
|
|||||||
<string name="graphics_driver_main_switch_title" translatable="false">Use graphics driver preferences</string>
|
<string name="graphics_driver_main_switch_title" translatable="false">Use graphics driver preferences</string>
|
||||||
<!-- Do not translate. Title for battery saver main switch preferences. [CHAR LIMIT=50] -->
|
<!-- Do not translate. Title for battery saver main switch preferences. [CHAR LIMIT=50] -->
|
||||||
<string name="battery_saver_main_switch_title" translatable="false">Use battery saver</string>
|
<string name="battery_saver_main_switch_title" translatable="false">Use battery saver</string>
|
||||||
|
<!-- Do not translate. Title for Do Not Disturb main switch preferences. [CHAR LIMIT=50] -->
|
||||||
|
<string name="do_not_disturb_main_switch_title" translatable="false">Use Do Not Disturb</string>
|
||||||
|
<!-- Do not translate. Title for Dark theme main switch preferences. [CHAR LIMIT=50] -->
|
||||||
|
<string name="dark_theme_main_switch_title" translatable="false">Use Dark Theme</string>
|
||||||
|
<!-- Do not translate. Title for Night Light main switch preferences. [CHAR LIMIT=50] -->
|
||||||
|
<string name="night_light_main_switch_title" translatable="false">Use Night Light</string>
|
||||||
|
<!-- Do not translate. Title for NFC main switch preferences. [CHAR LIMIT=50] -->
|
||||||
|
<string name="nfc_main_switch_title" translatable="false">Use NFC</string>
|
||||||
|
<!-- Do not translate. Title for Adaptive Battery main switch preferences. [CHAR LIMIT=50] -->
|
||||||
|
<string name="adaptive_battery_main_switch_title" translatable="false">Use adaptive battery</string>
|
||||||
|
<!-- Do not translate. Title for adaptive brightness main switch preferences. [CHAR LIMIT=50] -->
|
||||||
|
<string name="adaptive_brightness_main_switch_title" translatable="false">Use adaptive brightness</string>
|
||||||
|
|
||||||
<!-- Default preference title for showing all apps on device [CHAR_LIMIT=50]-->
|
<!-- Default preference title for showing all apps on device [CHAR_LIMIT=50]-->
|
||||||
<string name="default_see_all_apps_title">See all apps</string>
|
<string name="default_see_all_apps_title">See all apps</string>
|
||||||
|
@@ -20,6 +20,12 @@
|
|||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
android:title="@string/auto_brightness_title">
|
android:title="@string/auto_brightness_title">
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
android:key="auto_brightness"
|
||||||
|
android:title="@string/adaptive_brightness_main_switch_title"
|
||||||
|
settings:keywords="@string/keywords_display_auto_brightness"
|
||||||
|
settings:controller="com.android.settings.display.AutoBrightnessDetailPreferenceController"/>
|
||||||
|
|
||||||
<com.android.settings.widget.VideoPreference
|
<com.android.settings.widget.VideoPreference
|
||||||
android:key="auto_brightness_video"
|
android:key="auto_brightness_video"
|
||||||
android:title="@string/summary_placeholder"
|
android:title="@string/summary_placeholder"
|
||||||
@@ -27,17 +33,6 @@
|
|||||||
settings:preview="@drawable/aab_brightness"
|
settings:preview="@drawable/aab_brightness"
|
||||||
settings:controller="com.android.settings.widget.VideoPreferenceController"/>
|
settings:controller="com.android.settings.widget.VideoPreferenceController"/>
|
||||||
|
|
||||||
<!-- Cross-listed item, if you change this, also change it in power_usage_summary.xml -->
|
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
|
||||||
android:key="auto_brightness"
|
|
||||||
android:title="@string/auto_brightness_title"
|
|
||||||
android:summary="@string/auto_brightness_summary"
|
|
||||||
settings:keywords="@string/keywords_display_auto_brightness"
|
|
||||||
settings:controller="com.android.settings.display.AutoBrightnessDetailPreferenceController"
|
|
||||||
settings:useAdminDisabledSummary="true"
|
|
||||||
settings:userRestriction="no_config_brightness"
|
|
||||||
settings:allowDividerAbove="true" />
|
|
||||||
|
|
||||||
<com.android.settingslib.widget.FooterPreference
|
<com.android.settingslib.widget.FooterPreference
|
||||||
android:key="auto_brightness_footer"
|
android:key="auto_brightness_footer"
|
||||||
android:title="@string/auto_brightness_description"
|
android:title="@string/auto_brightness_description"
|
||||||
|
@@ -20,6 +20,11 @@
|
|||||||
android:title="@string/dark_ui_mode"
|
android:title="@string/dark_ui_mode"
|
||||||
settings:keywords="@string/keywords_dark_ui_mode">
|
settings:keywords="@string/keywords_dark_ui_mode">
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
android:key="dark_ui_activated"
|
||||||
|
android:title="@string/dark_theme_main_switch_title"
|
||||||
|
settings:controller="com.android.settings.display.darkmode.DarkModeActivationPreferenceController"/>
|
||||||
|
|
||||||
<com.android.settingslib.widget.BannerMessagePreference
|
<com.android.settingslib.widget.BannerMessagePreference
|
||||||
android:key="dark_ui_location_off"
|
android:key="dark_ui_location_off"
|
||||||
android:title="@string/twilight_mode_location_off_dialog_message"
|
android:title="@string/twilight_mode_location_off_dialog_message"
|
||||||
@@ -50,12 +55,4 @@
|
|||||||
android:title="@string/night_display_end_time_title"
|
android:title="@string/night_display_end_time_title"
|
||||||
settings:searchable="false"/>
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<com.android.settingslib.widget.LayoutPreference
|
|
||||||
android:key="dark_ui_activated"
|
|
||||||
android:title="@string/dark_ui_title"
|
|
||||||
android:selectable="false"
|
|
||||||
android:layout="@layout/dark_ui_activation_button"
|
|
||||||
settings:allowDividerBelow="true"
|
|
||||||
settings:controller="com.android.settings.display.darkmode.DarkModeActivationPreferenceController"/>
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -19,18 +19,17 @@
|
|||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
android:title="@string/nfc_quick_toggle_title">
|
android:title="@string/nfc_quick_toggle_title">
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
android:key="toggle_nfc"
|
||||||
|
android:title="@string/nfc_main_switch_title"
|
||||||
|
settings:controller="com.android.settings.nfc.NfcPreferenceController"/>
|
||||||
|
|
||||||
<com.android.settingslib.widget.LayoutPreference
|
<com.android.settingslib.widget.LayoutPreference
|
||||||
android:key="nfc_detection_point"
|
android:key="nfc_detection_point"
|
||||||
android:selectable="false"
|
android:selectable="false"
|
||||||
android:layout="@layout/nfc_detection_point"
|
android:layout="@layout/nfc_detection_point"
|
||||||
settings:controller="com.android.settings.nfc.NfcDetectionPointController"/>
|
settings:controller="com.android.settings.nfc.NfcDetectionPointController"/>
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="toggle_nfc"
|
|
||||||
android:title="@string/nfc_quick_toggle_title"
|
|
||||||
android:summary="@string/nfc_quick_toggle_summary"
|
|
||||||
settings:controller="com.android.settings.nfc.NfcPreferenceController"/>
|
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="nfc_secure_settings"
|
android:key="nfc_secure_settings"
|
||||||
android:title="@string/nfc_secure_settings_title"
|
android:title="@string/nfc_secure_settings_title"
|
||||||
|
@@ -20,6 +20,11 @@
|
|||||||
android:title="@string/night_display_title"
|
android:title="@string/night_display_title"
|
||||||
settings:keywords="@string/keywords_display_night_display">
|
settings:keywords="@string/keywords_display_night_display">
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
android:key="night_display_activated"
|
||||||
|
android:title="@string/night_light_main_switch_title"
|
||||||
|
settings:controller="com.android.settings.display.NightDisplayActivationPreferenceController"/>
|
||||||
|
|
||||||
<com.android.settingslib.widget.BannerMessagePreference
|
<com.android.settingslib.widget.BannerMessagePreference
|
||||||
android:key="dark_ui_location_off"
|
android:key="dark_ui_location_off"
|
||||||
android:title="@string/twilight_mode_location_off_dialog_message"
|
android:title="@string/twilight_mode_location_off_dialog_message"
|
||||||
@@ -54,13 +59,4 @@
|
|||||||
settings:controller="com.android.settings.display.NightDisplayIntensityPreferenceController"
|
settings:controller="com.android.settings.display.NightDisplayIntensityPreferenceController"
|
||||||
settings:unavailableSliceSubtitle="@string/night_display_not_currently_on"/>
|
settings:unavailableSliceSubtitle="@string/night_display_not_currently_on"/>
|
||||||
|
|
||||||
<com.android.settingslib.widget.LayoutPreference
|
|
||||||
android:key="night_display_activated"
|
|
||||||
android:title="@string/night_display_title"
|
|
||||||
android:selectable="false"
|
|
||||||
android:layout="@layout/night_display_activation_button"
|
|
||||||
settings:allowDividerBelow="true"
|
|
||||||
settings:keywords="@string/keywords_display_night_display"
|
|
||||||
settings:controller="com.android.settings.display.NightDisplayActivationPreferenceController"/>
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -22,6 +22,11 @@
|
|||||||
android:title="@string/smart_battery_manager_title"
|
android:title="@string/smart_battery_manager_title"
|
||||||
settings:searchable="false">
|
settings:searchable="false">
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
android:key="smart_battery"
|
||||||
|
android:title="@string/adaptive_battery_main_switch_title"
|
||||||
|
settings:controller="com.android.settings.fuelgauge.SmartBatteryPreferenceController"/>
|
||||||
|
|
||||||
<com.android.settings.widget.VideoPreference
|
<com.android.settings.widget.VideoPreference
|
||||||
android:key="auto_awesome_battery"
|
android:key="auto_awesome_battery"
|
||||||
android:title="@string/summary_placeholder"
|
android:title="@string/summary_placeholder"
|
||||||
@@ -29,13 +34,6 @@
|
|||||||
settings:preview="@drawable/auto_awesome_battery"
|
settings:preview="@drawable/auto_awesome_battery"
|
||||||
settings:controller="com.android.settings.widget.VideoPreferenceController"/>
|
settings:controller="com.android.settings.widget.VideoPreferenceController"/>
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="smart_battery"
|
|
||||||
android:title="@string/smart_battery_title"
|
|
||||||
android:summary="@string/smart_battery_summary"
|
|
||||||
settings:controller="com.android.settings.fuelgauge.SmartBatteryPreferenceController"
|
|
||||||
settings:allowDividerAbove="true"/>
|
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="auto_restriction"
|
android:key="auto_restriction"
|
||||||
android:title="@string/battery_auto_restriction_title"
|
android:title="@string/battery_auto_restriction_title"
|
||||||
|
@@ -21,12 +21,9 @@
|
|||||||
android:title="@string/zen_mode_settings_title">
|
android:title="@string/zen_mode_settings_title">
|
||||||
|
|
||||||
<!-- Turn on DND button -->
|
<!-- Turn on DND button -->
|
||||||
<com.android.settingslib.widget.LayoutPreference
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
android:key="zen_mode_toggle"
|
android:key="zen_mode_toggle"
|
||||||
android:title="@string/zen_mode_settings_title"
|
android:title="@string/do_not_disturb_main_switch_title"
|
||||||
android:selectable="false"
|
|
||||||
android:layout="@layout/zen_mode_settings_button"
|
|
||||||
settings:allowDividerBelow="true"
|
|
||||||
settings:keywords="@string/keywords_zen_mode_settings"/>
|
settings:keywords="@string/keywords_zen_mode_settings"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
@@ -17,8 +17,18 @@
|
|||||||
package com.android.settings.display;
|
package com.android.settings.display;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
public class AutoBrightnessDetailPreferenceController extends AutoBrightnessPreferenceController {
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller that updates the adaptive brightness.
|
||||||
|
*/
|
||||||
|
public class AutoBrightnessDetailPreferenceController extends
|
||||||
|
AutoBrightnessPreferenceController implements OnMainSwitchChangeListener {
|
||||||
|
|
||||||
public AutoBrightnessDetailPreferenceController(Context context, String key) {
|
public AutoBrightnessDetailPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
@@ -36,4 +46,21 @@ public class AutoBrightnessDetailPreferenceController extends AutoBrightnessPref
|
|||||||
public boolean isPublicSlice() {
|
public boolean isPublicSlice() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
|
||||||
|
MainSwitchPreference pref = (MainSwitchPreference) screen.findPreference(
|
||||||
|
getPreferenceKey());
|
||||||
|
pref.addOnSwitchChangeListener(this);
|
||||||
|
pref.updateStatus(isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
|
if (isChecked != isChecked()) {
|
||||||
|
setChecked(isChecked);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,43 +16,30 @@
|
|||||||
|
|
||||||
package com.android.settings.display;
|
package com.android.settings.display;
|
||||||
|
|
||||||
import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.display.ColorDisplayManager;
|
import android.hardware.display.ColorDisplayManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.widget.Switch;
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
public class NightDisplayActivationPreferenceController extends TogglePreferenceController {
|
/**
|
||||||
|
* Controller that updates the night display.
|
||||||
|
*/
|
||||||
|
public class NightDisplayActivationPreferenceController extends
|
||||||
|
TogglePreferenceController implements OnMainSwitchChangeListener {
|
||||||
|
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
private ColorDisplayManager mColorDisplayManager;
|
private ColorDisplayManager mColorDisplayManager;
|
||||||
private NightDisplayTimeFormatter mTimeFormatter;
|
private NightDisplayTimeFormatter mTimeFormatter;
|
||||||
private LayoutPreference mPreference;
|
private MainSwitchPreference mPreference;
|
||||||
|
|
||||||
private Button mTurnOffButton;
|
|
||||||
private Button mTurnOnButton;
|
|
||||||
|
|
||||||
private final OnClickListener mListener = new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
mMetricsFeatureProvider.logClickedPreference(mPreference, getMetricsCategory());
|
|
||||||
mColorDisplayManager.setNightDisplayActivated(
|
|
||||||
!mColorDisplayManager.isNightDisplayActivated());
|
|
||||||
updateStateInternal(true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public NightDisplayActivationPreferenceController(Context context, String key) {
|
public NightDisplayActivationPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
@@ -64,7 +51,7 @@ public class NightDisplayActivationPreferenceController extends TogglePreference
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return ColorDisplayManager.isNightDisplayAvailable(mContext) ? AVAILABLE
|
return ColorDisplayManager.isNightDisplayAvailable(mContext) ? AVAILABLE_UNSEARCHABLE
|
||||||
: UNSUPPORTED_ON_DEVICE;
|
: UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,16 +69,24 @@ public class NightDisplayActivationPreferenceController extends TogglePreference
|
|||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
|
|
||||||
mPreference = screen.findPreference(getPreferenceKey());
|
mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
|
||||||
mTurnOnButton = mPreference.findViewById(R.id.night_display_turn_on_button);
|
mPreference.addOnSwitchChangeListener(this);
|
||||||
mTurnOnButton.setOnClickListener(mListener);
|
mPreference.updateStatus(mColorDisplayManager.isNightDisplayActivated());
|
||||||
mTurnOffButton = mPreference.findViewById(R.id.night_display_turn_off_button);
|
}
|
||||||
mTurnOffButton.setOnClickListener(mListener);
|
|
||||||
|
@Override
|
||||||
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
|
final boolean activated = mColorDisplayManager.isNightDisplayActivated();
|
||||||
|
if (isChecked != activated) {
|
||||||
|
// TODO(b/179017365): Create a controller which extends TogglePreferenceController to
|
||||||
|
// control the toggle preference.
|
||||||
|
setChecked(isChecked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void updateState(Preference preference) {
|
public final void updateState(Preference preference) {
|
||||||
updateStateInternal(false);
|
updateStateInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** FOR SLICES */
|
/** FOR SLICES */
|
||||||
@@ -111,46 +106,14 @@ public class NightDisplayActivationPreferenceController extends TogglePreference
|
|||||||
return mTimeFormatter.getAutoModeSummary(mContext, mColorDisplayManager);
|
return mTimeFormatter.getAutoModeSummary(mContext, mColorDisplayManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStateInternal(boolean selfChanged) {
|
private void updateStateInternal() {
|
||||||
if (mTurnOnButton == null || mTurnOffButton == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean isActivated = mColorDisplayManager.isNightDisplayActivated();
|
final boolean isActivated = mColorDisplayManager.isNightDisplayActivated();
|
||||||
final int autoMode = mColorDisplayManager.getNightDisplayAutoMode();
|
final int autoMode = mColorDisplayManager.getNightDisplayAutoMode();
|
||||||
|
|
||||||
String buttonText;
|
|
||||||
if (autoMode == ColorDisplayManager.AUTO_MODE_CUSTOM_TIME) {
|
if (autoMode == ColorDisplayManager.AUTO_MODE_CUSTOM_TIME) {
|
||||||
buttonText = mContext.getString(isActivated
|
|
||||||
? R.string.night_display_activation_off_custom
|
|
||||||
: R.string.night_display_activation_on_custom,
|
|
||||||
mTimeFormatter.getFormattedTimeString(isActivated
|
mTimeFormatter.getFormattedTimeString(isActivated
|
||||||
? mColorDisplayManager.getNightDisplayCustomStartTime()
|
? mColorDisplayManager.getNightDisplayCustomStartTime()
|
||||||
: mColorDisplayManager.getNightDisplayCustomEndTime()));
|
: mColorDisplayManager.getNightDisplayCustomEndTime());
|
||||||
} else if (autoMode == ColorDisplayManager.AUTO_MODE_TWILIGHT) {
|
|
||||||
buttonText = mContext.getString(isActivated
|
|
||||||
? R.string.night_display_activation_off_twilight
|
|
||||||
: R.string.night_display_activation_on_twilight);
|
|
||||||
} else {
|
|
||||||
buttonText = mContext.getString(isActivated
|
|
||||||
? R.string.night_display_activation_off_manual
|
|
||||||
: R.string.night_display_activation_on_manual);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isActivated) {
|
|
||||||
mTurnOnButton.setVisibility(View.GONE);
|
|
||||||
mTurnOffButton.setVisibility(View.VISIBLE);
|
|
||||||
mTurnOffButton.setText(buttonText);
|
|
||||||
if (selfChanged) {
|
|
||||||
mTurnOffButton.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mTurnOnButton.setVisibility(View.VISIBLE);
|
|
||||||
mTurnOffButton.setVisibility(View.GONE);
|
|
||||||
mTurnOnButton.setText(buttonText);
|
|
||||||
if (selfChanged) {
|
|
||||||
mTurnOnButton.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,8 +19,7 @@ import android.app.UiModeManager;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.view.View;
|
import android.widget.Switch;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -29,22 +28,22 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for activate/deactivate night mode button
|
* Controller for activate/deactivate night mode button
|
||||||
*/
|
*/
|
||||||
public class DarkModeActivationPreferenceController extends BasePreferenceController {
|
public class DarkModeActivationPreferenceController extends BasePreferenceController implements
|
||||||
|
OnMainSwitchChangeListener {
|
||||||
|
|
||||||
private final UiModeManager mUiModeManager;
|
private final UiModeManager mUiModeManager;
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
private PowerManager mPowerManager;
|
private PowerManager mPowerManager;
|
||||||
private Button mTurnOffButton;
|
|
||||||
private Button mTurnOnButton;
|
|
||||||
private TimeFormatter mFormat;
|
private TimeFormatter mFormat;
|
||||||
private LayoutPreference mPreference;
|
private MainSwitchPreference mPreference;
|
||||||
|
|
||||||
public DarkModeActivationPreferenceController(Context context, String preferenceKey) {
|
public DarkModeActivationPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
@@ -62,49 +61,9 @@ public class DarkModeActivationPreferenceController extends BasePreferenceContro
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void updateState(Preference preference) {
|
public final void updateState(Preference preference) {
|
||||||
|
|
||||||
final boolean batterySaver = mPowerManager.isPowerSaveMode();
|
|
||||||
if (batterySaver) {
|
|
||||||
mTurnOnButton.setVisibility(View.GONE);
|
|
||||||
mTurnOffButton.setVisibility(View.GONE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean active = (mContext.getResources().getConfiguration().uiMode
|
final boolean active = (mContext.getResources().getConfiguration().uiMode
|
||||||
& Configuration.UI_MODE_NIGHT_YES) != 0;
|
& Configuration.UI_MODE_NIGHT_YES) != 0;
|
||||||
updateNightMode(active);
|
mPreference.updateStatus(active);
|
||||||
}
|
|
||||||
|
|
||||||
private void updateNightMode(boolean active) {
|
|
||||||
final int mode = mUiModeManager.getNightMode();
|
|
||||||
String buttonText;
|
|
||||||
|
|
||||||
if (mode == UiModeManager.MODE_NIGHT_AUTO) {
|
|
||||||
buttonText = mContext.getString(active
|
|
||||||
? R.string.dark_ui_activation_off_auto
|
|
||||||
: R.string.dark_ui_activation_on_auto);
|
|
||||||
} else if (mode == UiModeManager.MODE_NIGHT_CUSTOM) {
|
|
||||||
final LocalTime time = active
|
|
||||||
? mUiModeManager.getCustomNightModeStart()
|
|
||||||
: mUiModeManager.getCustomNightModeEnd();
|
|
||||||
final String timeStr = mFormat.of(time);
|
|
||||||
buttonText = mContext.getString(active
|
|
||||||
? R.string.dark_ui_activation_off_custom
|
|
||||||
: R.string.dark_ui_activation_on_custom, timeStr);
|
|
||||||
} else {
|
|
||||||
buttonText = mContext.getString(active
|
|
||||||
? R.string.dark_ui_activation_off_manual
|
|
||||||
: R.string.dark_ui_activation_on_manual);
|
|
||||||
}
|
|
||||||
if (active) {
|
|
||||||
mTurnOnButton.setVisibility(View.GONE);
|
|
||||||
mTurnOffButton.setVisibility(View.VISIBLE);
|
|
||||||
mTurnOffButton.setText(buttonText);
|
|
||||||
} else {
|
|
||||||
mTurnOnButton.setVisibility(View.VISIBLE);
|
|
||||||
mTurnOffButton.setVisibility(View.GONE);
|
|
||||||
mTurnOnButton.setText(buttonText);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -132,26 +91,19 @@ public class DarkModeActivationPreferenceController extends BasePreferenceContro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final View.OnClickListener mListener = new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
mMetricsFeatureProvider.logClickedPreference(mPreference, getMetricsCategory());
|
mMetricsFeatureProvider.logClickedPreference(mPreference, getMetricsCategory());
|
||||||
final boolean active = (mContext.getResources().getConfiguration().uiMode
|
final boolean active = (mContext.getResources().getConfiguration().uiMode
|
||||||
& Configuration.UI_MODE_NIGHT_YES) != 0;
|
& Configuration.UI_MODE_NIGHT_YES) != 0;
|
||||||
mUiModeManager.setNightModeActivated(!active);
|
mUiModeManager.setNightModeActivated(!active);
|
||||||
updateNightMode(!active);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
|
mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
|
||||||
mPreference = screen.findPreference(getPreferenceKey());
|
mPreference.addOnSwitchChangeListener(this);
|
||||||
mTurnOnButton = mPreference.findViewById(R.id.dark_ui_turn_on_button);
|
|
||||||
mTurnOnButton.setOnClickListener(mListener);
|
|
||||||
mTurnOffButton = mPreference.findViewById(R.id.dark_ui_turn_off_button);
|
|
||||||
mTurnOffButton.setOnClickListener(mListener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -20,22 +20,27 @@ package com.android.settings.fuelgauge;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller to change and update the smart battery toggle
|
* Controller to change and update the smart battery toggle
|
||||||
*/
|
*/
|
||||||
public class SmartBatteryPreferenceController extends BasePreferenceController implements
|
public class SmartBatteryPreferenceController extends BasePreferenceController implements
|
||||||
Preference.OnPreferenceChangeListener {
|
OnMainSwitchChangeListener {
|
||||||
|
|
||||||
private static final String KEY_SMART_BATTERY = "smart_battery";
|
private static final String KEY_SMART_BATTERY = "smart_battery";
|
||||||
private static final int ON = 1;
|
private static final int ON = 1;
|
||||||
private static final int OFF = 0;
|
private static final int OFF = 0;
|
||||||
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
|
||||||
|
private MainSwitchPreference mPreference;
|
||||||
|
|
||||||
public SmartBatteryPreferenceController(Context context) {
|
public SmartBatteryPreferenceController(Context context) {
|
||||||
super(context, KEY_SMART_BATTERY);
|
super(context, KEY_SMART_BATTERY);
|
||||||
@@ -65,14 +70,19 @@ public class SmartBatteryPreferenceController extends BasePreferenceController i
|
|||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
final boolean smartBatteryOn = Settings.Global.getInt(mContext.getContentResolver(),
|
final boolean smartBatteryOn = Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON) == ON;
|
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON) == ON;
|
||||||
((SwitchPreference) preference).setChecked(smartBatteryOn);
|
((MainSwitchPreference) preference).updateStatus(smartBatteryOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
final boolean smartBatteryOn = (Boolean) newValue;
|
super.displayPreference(screen);
|
||||||
|
mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
|
||||||
|
mPreference.addOnSwitchChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, smartBatteryOn ? ON : OFF);
|
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, isChecked ? ON : OFF);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,16 +21,17 @@ import android.nfc.NfcAdapter;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NfcEnabler is a helper to manage the Nfc on/off checkbox preference. It turns on/off Nfc
|
* NfcEnabler is a helper to manage the Nfc on/off checkbox preference. It turns on/off Nfc
|
||||||
* and ensures the summary of the preference reflects the current state.
|
* and ensures the summary of the preference reflects the current state.
|
||||||
*/
|
*/
|
||||||
public class NfcEnabler extends BaseNfcEnabler {
|
public class NfcEnabler extends BaseNfcEnabler {
|
||||||
private final SwitchPreference mPreference;
|
private final MainSwitchPreference mPreference;
|
||||||
|
|
||||||
public NfcEnabler(Context context, SwitchPreference preference) {
|
public NfcEnabler(Context context, MainSwitchPreference preference) {
|
||||||
super(context);
|
super(context);
|
||||||
mPreference = preference;
|
mPreference = preference;
|
||||||
}
|
}
|
||||||
@@ -39,19 +40,19 @@ public class NfcEnabler extends BaseNfcEnabler {
|
|||||||
protected void handleNfcStateChanged(int newState) {
|
protected void handleNfcStateChanged(int newState) {
|
||||||
switch (newState) {
|
switch (newState) {
|
||||||
case NfcAdapter.STATE_OFF:
|
case NfcAdapter.STATE_OFF:
|
||||||
mPreference.setChecked(false);
|
mPreference.updateStatus(false);
|
||||||
mPreference.setEnabled(isToggleable());
|
mPreference.setEnabled(isToggleable());
|
||||||
break;
|
break;
|
||||||
case NfcAdapter.STATE_ON:
|
case NfcAdapter.STATE_ON:
|
||||||
mPreference.setChecked(true);
|
mPreference.updateStatus(true);
|
||||||
mPreference.setEnabled(true);
|
mPreference.setEnabled(true);
|
||||||
break;
|
break;
|
||||||
case NfcAdapter.STATE_TURNING_ON:
|
case NfcAdapter.STATE_TURNING_ON:
|
||||||
mPreference.setChecked(true);
|
mPreference.updateStatus(true);
|
||||||
mPreference.setEnabled(false);
|
mPreference.setEnabled(false);
|
||||||
break;
|
break;
|
||||||
case NfcAdapter.STATE_TURNING_OFF:
|
case NfcAdapter.STATE_TURNING_OFF:
|
||||||
mPreference.setChecked(false);
|
mPreference.updateStatus(false);
|
||||||
mPreference.setEnabled(false);
|
mPreference.setEnabled(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -23,24 +23,27 @@ import android.net.Uri;
|
|||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settings.slices.SliceBackgroundWorker;
|
import com.android.settings.slices.SliceBackgroundWorker;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class NfcPreferenceController extends TogglePreferenceController
|
public class NfcPreferenceController extends TogglePreferenceController
|
||||||
implements LifecycleObserver, OnResume, OnPause {
|
implements LifecycleObserver, OnResume, OnPause, OnMainSwitchChangeListener {
|
||||||
|
|
||||||
public static final String KEY_TOGGLE_NFC = "toggle_nfc";
|
public static final String KEY_TOGGLE_NFC = "toggle_nfc";
|
||||||
private final NfcAdapter mNfcAdapter;
|
private final NfcAdapter mNfcAdapter;
|
||||||
private NfcEnabler mNfcEnabler;
|
private NfcEnabler mNfcEnabler;
|
||||||
|
private MainSwitchPreference mPreference;
|
||||||
|
|
||||||
public NfcPreferenceController(Context context, String key) {
|
public NfcPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
@@ -55,10 +58,16 @@ public class NfcPreferenceController extends TogglePreferenceController
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final SwitchPreference switchPreference = screen.findPreference(getPreferenceKey());
|
mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
|
||||||
|
mPreference.addOnSwitchChangeListener(this);
|
||||||
mNfcEnabler = new NfcEnabler(mContext, switchPreference);
|
mNfcEnabler = new NfcEnabler(mContext, mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
|
if (isChecked != mNfcAdapter.isEnabled()) {
|
||||||
|
setChecked(isChecked);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -185,7 +194,7 @@ public class NfcPreferenceController extends TogglePreferenceController
|
|||||||
NO_EXTRA);
|
NO_EXTRA);
|
||||||
|
|
||||||
// Do nothing if state change is empty, or an intermediate step.
|
// Do nothing if state change is empty, or an intermediate step.
|
||||||
if ( (nfcStateExtra == NO_EXTRA)
|
if ((nfcStateExtra == NO_EXTRA)
|
||||||
|| (nfcStateExtra == NfcAdapter.STATE_TURNING_ON)
|
|| (nfcStateExtra == NfcAdapter.STATE_TURNING_ON)
|
||||||
|| (nfcStateExtra == NfcAdapter.STATE_TURNING_OFF)) {
|
|| (nfcStateExtra == NfcAdapter.STATE_TURNING_OFF)) {
|
||||||
Log.d(TAG, "Transitional update, dropping broadcast");
|
Log.d(TAG, "Transitional update, dropping broadcast");
|
||||||
|
@@ -72,16 +72,16 @@ public class BlockPreferenceController extends NotificationPreferenceController
|
|||||||
bar.setDisabledByAdmin(mAdmin);
|
bar.setDisabledByAdmin(mAdmin);
|
||||||
|
|
||||||
if (mChannel != null && !isChannelBlockable()) {
|
if (mChannel != null && !isChannelBlockable()) {
|
||||||
bar.setEnabled(false);
|
bar.setSwitchBarEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mChannelGroup != null && !isChannelGroupBlockable()) {
|
if (mChannelGroup != null && !isChannelGroupBlockable()) {
|
||||||
bar.setEnabled(false);
|
bar.setSwitchBarEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mChannel == null && mAppRow.systemApp
|
if (mChannel == null && mAppRow.systemApp
|
||||||
&& (!mAppRow.banned || mAppRow.lockedImportance)) {
|
&& (!mAppRow.banned || mAppRow.lockedImportance)) {
|
||||||
bar.setEnabled(false);
|
bar.setSwitchBarEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
|
@@ -16,37 +16,33 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.zen;
|
package com.android.settings.notification.zen;
|
||||||
|
|
||||||
import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED;
|
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.View;
|
import android.widget.Switch;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.notification.SettingsEnableZenModeDialog;
|
import com.android.settings.notification.SettingsEnableZenModeDialog;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController
|
public class ZenModeButtonPreferenceController extends AbstractZenModePreferenceController
|
||||||
implements PreferenceControllerMixin {
|
implements PreferenceControllerMixin, OnMainSwitchChangeListener {
|
||||||
|
|
||||||
|
private static final String TAG = "EnableZenModeButton";
|
||||||
|
|
||||||
public static final String KEY = "zen_mode_toggle";
|
public static final String KEY = "zen_mode_toggle";
|
||||||
|
|
||||||
private static final String TAG = "EnableZenModeButton";
|
|
||||||
private final FragmentManager mFragment;
|
private final FragmentManager mFragment;
|
||||||
|
|
||||||
// DND can also be toggled from QS. If DND wasn't toggled by this preference, don't
|
// DND can also be toggled from QS.
|
||||||
// reroute focus.
|
private MainSwitchPreference mPreference;
|
||||||
private boolean mRefocusButton = false;
|
|
||||||
private Button mZenButtonOn;
|
|
||||||
private Button mZenButtonOff;
|
|
||||||
|
|
||||||
public ZenModeButtonPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
|
public ZenModeButtonPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
|
||||||
fragment) {
|
fragment) {
|
||||||
@@ -64,26 +60,27 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference
|
|||||||
return KEY;
|
return KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey());
|
||||||
|
mPreference.addOnSwitchChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
|
if (isChecked) {
|
||||||
|
updateZenModeState(mPreference);
|
||||||
|
} else {
|
||||||
|
writeMetrics(mPreference, false);
|
||||||
|
mBackend.setZenMode(Settings.Global.ZEN_MODE_OFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
|
|
||||||
if (null == mZenButtonOn) {
|
|
||||||
mZenButtonOn = ((LayoutPreference) preference)
|
|
||||||
.findViewById(R.id.zen_mode_settings_turn_on_button);
|
|
||||||
updateZenButtonOnClickListener(preference);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null == mZenButtonOff) {
|
|
||||||
mZenButtonOff = ((LayoutPreference) preference)
|
|
||||||
.findViewById(R.id.zen_mode_settings_turn_off_button);
|
|
||||||
mZenButtonOff.setOnClickListener(v -> {
|
|
||||||
mRefocusButton = true;
|
|
||||||
writeMetrics(preference, false);
|
|
||||||
mBackend.setZenMode(Settings.Global.ZEN_MODE_OFF);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePreference(preference);
|
updatePreference(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,28 +89,15 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference
|
|||||||
case Settings.Global.ZEN_MODE_ALARMS:
|
case Settings.Global.ZEN_MODE_ALARMS:
|
||||||
case Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
|
case Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
|
||||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||||
mZenButtonOff.setVisibility(View.VISIBLE);
|
mPreference.updateStatus(true);
|
||||||
mZenButtonOn.setVisibility(View.GONE);
|
|
||||||
if (mRefocusButton) {
|
|
||||||
mRefocusButton = false;
|
|
||||||
mZenButtonOff.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Settings.Global.ZEN_MODE_OFF:
|
case Settings.Global.ZEN_MODE_OFF:
|
||||||
default:
|
default:
|
||||||
mZenButtonOff.setVisibility(View.GONE);
|
mPreference.updateStatus(false);
|
||||||
updateZenButtonOnClickListener(preference);
|
|
||||||
mZenButtonOn.setVisibility(View.VISIBLE);
|
|
||||||
if (mRefocusButton) {
|
|
||||||
mRefocusButton = false;
|
|
||||||
mZenButtonOn.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateZenButtonOnClickListener(Preference preference) {
|
private void updateZenModeState(Preference preference) {
|
||||||
mZenButtonOn.setOnClickListener(v -> {
|
|
||||||
mRefocusButton = true;
|
|
||||||
writeMetrics(preference, true);
|
writeMetrics(preference, true);
|
||||||
int zenDuration = getZenDuration();
|
int zenDuration = getZenDuration();
|
||||||
switch (zenDuration) {
|
switch (zenDuration) {
|
||||||
@@ -126,7 +110,6 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference
|
|||||||
default:
|
default:
|
||||||
mBackend.setZenModeForDuration(zenDuration);
|
mBackend.setZenModeForDuration(zenDuration);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeMetrics(Preference preference, boolean buttonOn) {
|
private void writeMetrics(Preference preference, boolean buttonOn) {
|
||||||
|
@@ -17,8 +17,11 @@
|
|||||||
package com.android.settings.widget;
|
package com.android.settings.widget;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import androidx.core.content.res.TypedArrayUtils;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
import androidx.preference.TwoStatePreference;
|
import androidx.preference.TwoStatePreference;
|
||||||
|
|
||||||
@@ -47,23 +50,23 @@ public class SettingsMainSwitchPreference extends TwoStatePreference {
|
|||||||
|
|
||||||
public SettingsMainSwitchPreference(Context context) {
|
public SettingsMainSwitchPreference(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
init();
|
init(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SettingsMainSwitchPreference(Context context, AttributeSet attrs) {
|
public SettingsMainSwitchPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
init();
|
init(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SettingsMainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
public SettingsMainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
init();
|
init(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SettingsMainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
public SettingsMainSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||||
int defStyleRes) {
|
int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
init();
|
init(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,8 +82,21 @@ public class SettingsMainSwitchPreference extends TwoStatePreference {
|
|||||||
registerListenerToSwitchBar();
|
registerListenerToSwitchBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init(Context context, AttributeSet attrs) {
|
||||||
setLayoutResource(R.layout.preference_widget_main_switch);
|
setLayoutResource(R.layout.preference_widget_main_switch);
|
||||||
|
|
||||||
|
if (attrs != null) {
|
||||||
|
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||||
|
androidx.preference.R.styleable.Preference, 0/*defStyleAttr*/,
|
||||||
|
0/*defStyleRes*/);
|
||||||
|
final CharSequence title = TypedArrayUtils.getText(a,
|
||||||
|
androidx.preference.R.styleable.Preference_title,
|
||||||
|
androidx.preference.R.styleable.Preference_android_title);
|
||||||
|
if (!TextUtils.isEmpty(title)) {
|
||||||
|
setTitle(title.toString());
|
||||||
|
}
|
||||||
|
a.recycle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,7 +169,7 @@ public class SettingsMainSwitchPreference extends TwoStatePreference {
|
|||||||
/**
|
/**
|
||||||
* Enable or disable the text and switch.
|
* Enable or disable the text and switch.
|
||||||
*/
|
*/
|
||||||
public void setEnabled(boolean enabled) {
|
public void setSwitchBarEnabled(boolean enabled) {
|
||||||
if (mMainSwitchBar != null) {
|
if (mMainSwitchBar != null) {
|
||||||
mMainSwitchBar.setEnabled(enabled);
|
mMainSwitchBar.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
@@ -21,13 +21,11 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.hardware.display.ColorDisplayManager;
|
import android.hardware.display.ColorDisplayManager;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -45,7 +43,7 @@ public class NightDisplayActivationPreferenceControllerTest {
|
|||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
private LayoutPreference mPreference;
|
private MainSwitchPreference mPreference;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ColorDisplayManager mColorDisplayManager;
|
private ColorDisplayManager mColorDisplayManager;
|
||||||
private NightDisplayActivationPreferenceController mPreferenceController;
|
private NightDisplayActivationPreferenceController mPreferenceController;
|
||||||
@@ -55,7 +53,7 @@ public class NightDisplayActivationPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class);
|
mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class);
|
||||||
mPreference = new LayoutPreference(mContext, R.layout.night_display_activation_button);
|
mPreference = new MainSwitchPreference(mContext);
|
||||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||||
mPreferenceController = new NightDisplayActivationPreferenceController(mContext,
|
mPreferenceController = new NightDisplayActivationPreferenceController(mContext,
|
||||||
"night_display_activation");
|
"night_display_activation");
|
||||||
@@ -104,9 +102,9 @@ public class NightDisplayActivationPreferenceControllerTest {
|
|||||||
public void onClick_activates() {
|
public void onClick_activates() {
|
||||||
mColorDisplayManager.setNightDisplayActivated(false);
|
mColorDisplayManager.setNightDisplayActivated(false);
|
||||||
|
|
||||||
final View view = mPreference.findViewById(R.id.night_display_turn_on_button);
|
final NightDisplayActivationPreferenceController controller =
|
||||||
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
|
new NightDisplayActivationPreferenceController(mContext, "night_display_activated");
|
||||||
view.performClick();
|
controller.onSwitchChanged(null, true);
|
||||||
|
|
||||||
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(true);
|
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(true);
|
||||||
}
|
}
|
||||||
@@ -115,9 +113,9 @@ public class NightDisplayActivationPreferenceControllerTest {
|
|||||||
public void onClick_deactivates() {
|
public void onClick_deactivates() {
|
||||||
mColorDisplayManager.setNightDisplayActivated(true);
|
mColorDisplayManager.setNightDisplayActivated(true);
|
||||||
|
|
||||||
final View view = mPreference.findViewById(R.id.night_display_turn_off_button);
|
final NightDisplayActivationPreferenceController controller =
|
||||||
assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
|
new NightDisplayActivationPreferenceController(mContext, "night_display_activated");
|
||||||
view.performClick();
|
controller.onSwitchChanged(null, false);
|
||||||
|
|
||||||
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(false);
|
assertThat(mColorDisplayManager.isNightDisplayActivated()).isEqualTo(false);
|
||||||
}
|
}
|
||||||
|
@@ -23,9 +23,8 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.eq;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.UiModeManager;
|
import android.app.UiModeManager;
|
||||||
@@ -33,13 +32,12 @@ import android.content.Context;
|
|||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -47,6 +45,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -54,25 +53,21 @@ import java.util.Locale;
|
|||||||
public class DarkModeActivationPreferenceControllerTest {
|
public class DarkModeActivationPreferenceControllerTest {
|
||||||
private DarkModeActivationPreferenceController mController;
|
private DarkModeActivationPreferenceController mController;
|
||||||
private String mPreferenceKey = "key";
|
private String mPreferenceKey = "key";
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private LayoutPreference mPreference;
|
private MainSwitchPreference mPreference;
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
@Mock
|
@Mock
|
||||||
private Resources res;
|
private Resources res;
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
|
||||||
private UiModeManager mService;
|
private UiModeManager mService;
|
||||||
@Mock
|
@Mock
|
||||||
private Button mTurnOffButton;
|
|
||||||
@Mock
|
|
||||||
private Button mTurnOnButton;
|
|
||||||
@Mock
|
|
||||||
private PowerManager mPM;
|
private PowerManager mPM;
|
||||||
@Mock
|
@Mock
|
||||||
private TimeFormatter mFormat;
|
private TimeFormatter mFormat;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private Configuration mConfigNightYes = new Configuration();
|
private Configuration mConfigNightYes = new Configuration();
|
||||||
private Configuration mConfigNightNo = new Configuration();
|
private Configuration mConfigNightNo = new Configuration();
|
||||||
private Locale mLocal = new Locale("ENG");
|
private Locale mLocal = new Locale("ENG");
|
||||||
@@ -80,16 +75,14 @@ public class DarkModeActivationPreferenceControllerTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
FakeFeatureFactory.setupForTest();
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mService = mock(UiModeManager.class);
|
mService = mock(UiModeManager.class);
|
||||||
when(mContext.getResources()).thenReturn(res);
|
when(mContext.getResources()).thenReturn(res);
|
||||||
when(res.getConfiguration()).thenReturn(mConfigNightNo);
|
when(res.getConfiguration()).thenReturn(mConfigNightNo);
|
||||||
when(mContext.getSystemService(UiModeManager.class)).thenReturn(mService);
|
when(mContext.getSystemService(UiModeManager.class)).thenReturn(mService);
|
||||||
when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM);
|
when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM);
|
||||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||||
when(mPreference.findViewById(
|
|
||||||
eq(R.id.dark_ui_turn_on_button))).thenReturn(mTurnOnButton);
|
|
||||||
when(mPreference.findViewById(
|
|
||||||
eq(R.id.dark_ui_turn_off_button))).thenReturn(mTurnOffButton);
|
|
||||||
when(mService.setNightModeActivated(anyBoolean())).thenReturn(true);
|
when(mService.setNightModeActivated(anyBoolean())).thenReturn(true);
|
||||||
when(mFormat.of(any())).thenReturn("10:00 AM");
|
when(mFormat.of(any())).thenReturn("10:00 AM");
|
||||||
when(mContext.getString(
|
when(mContext.getString(
|
||||||
@@ -124,66 +117,55 @@ public class DarkModeActivationPreferenceControllerTest {
|
|||||||
public void nightMode_toggleButton_offManual() {
|
public void nightMode_toggleButton_offManual() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
||||||
when(res.getConfiguration()).thenReturn(mConfigNightYes);
|
when(res.getConfiguration()).thenReturn(mConfigNightYes);
|
||||||
|
final MainSwitchPreference preference = new MainSwitchPreference(mContext);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
verify(mTurnOnButton).setVisibility(eq(View.GONE));
|
assertThat(preference.isChecked()).isFalse();
|
||||||
verify(mTurnOffButton).setVisibility(eq(View.VISIBLE));
|
|
||||||
verify(mTurnOffButton).setText(eq(mContext.getString(
|
|
||||||
R.string.dark_ui_activation_off_manual)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_toggleButton_offCustom() {
|
public void nightMode_toggleButton_offCustom() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||||
when(res.getConfiguration()).thenReturn(mConfigNightYes);
|
when(res.getConfiguration()).thenReturn(mConfigNightYes);
|
||||||
|
final MainSwitchPreference preference = new MainSwitchPreference(mContext);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(preference);
|
||||||
|
|
||||||
verify(mTurnOnButton).setVisibility(eq(View.GONE));
|
assertThat(preference.isChecked()).isFalse();
|
||||||
verify(mTurnOffButton).setVisibility(eq(View.VISIBLE));
|
|
||||||
verify(mTurnOffButton).setText(eq(mContext.getString(
|
|
||||||
R.string.dark_ui_activation_off_custom)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_toggleButton_onCustom() {
|
public void nightMode_toggleButton_onCustom() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||||
when(res.getConfiguration()).thenReturn(mConfigNightYes);
|
when(res.getConfiguration()).thenReturn(mConfigNightYes);
|
||||||
|
final MainSwitchPreference preference = new MainSwitchPreference(mContext);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(preference);
|
||||||
|
|
||||||
verify(mTurnOnButton).setVisibility(eq(View.GONE));
|
assertThat(preference.isChecked()).isFalse();
|
||||||
verify(mTurnOffButton).setVisibility(eq(View.VISIBLE));
|
|
||||||
verify(mTurnOffButton).setText(eq(mContext.getString(
|
|
||||||
R.string.dark_ui_activation_on_custom)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_toggleButton_onAutoWhenModeIsYes() {
|
public void nightMode_toggleButton_onAutoWhenModeIsYes() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
||||||
when(res.getConfiguration()).thenReturn(mConfigNightNo);
|
when(res.getConfiguration()).thenReturn(mConfigNightNo);
|
||||||
|
final MainSwitchPreference preference = new MainSwitchPreference(mContext, null);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(preference);
|
||||||
|
|
||||||
verify(mTurnOffButton).setVisibility(eq(View.GONE));
|
assertThat(preference.isChecked()).isFalse();
|
||||||
verify(mTurnOnButton).setVisibility(eq(View.VISIBLE));
|
|
||||||
verify(mTurnOnButton).setText(eq(mContext.getString(
|
|
||||||
R.string.dark_ui_activation_on_manual)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_toggleButton_onAutoWhenModeIsAuto() {
|
public void nightMode_toggleButton_onAutoWhenModeIsAuto() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_AUTO);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_AUTO);
|
||||||
when(res.getConfiguration()).thenReturn(mConfigNightNo);
|
when(res.getConfiguration()).thenReturn(mConfigNightNo);
|
||||||
|
final MainSwitchPreference preference = new MainSwitchPreference(mContext);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(preference);
|
||||||
|
|
||||||
verify(mTurnOffButton).setVisibility(eq(View.GONE));
|
assertThat(preference.isChecked()).isFalse();
|
||||||
verify(mTurnOnButton).setVisibility(eq(View.VISIBLE));
|
|
||||||
verify(mTurnOnButton).setText(eq(mContext.getString(
|
|
||||||
R.string.dark_ui_activation_on_auto)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -207,9 +189,10 @@ public class DarkModeActivationPreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void buttonVisisbility_hideButton_offWhenInPowerSaveMode() {
|
public void buttonVisisbility_hideButton_offWhenInPowerSaveMode() {
|
||||||
when(mPM.isPowerSaveMode()).thenReturn(true);
|
when(mPM.isPowerSaveMode()).thenReturn(true);
|
||||||
mController.updateState(mPreference);
|
final MainSwitchPreference preference = new MainSwitchPreference(mContext);
|
||||||
verify(mTurnOffButton).setVisibility(eq(View.GONE));
|
|
||||||
verify(mTurnOnButton).setVisibility(eq(View.GONE));
|
mController.updateState(preference);
|
||||||
|
assertThat(preference.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -21,12 +21,12 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -42,48 +42,50 @@ public class SmartBatteryPreferenceControllerTest {
|
|||||||
private static final int OFF = 0;
|
private static final int OFF = 0;
|
||||||
|
|
||||||
private SmartBatteryPreferenceController mController;
|
private SmartBatteryPreferenceController mController;
|
||||||
private SwitchPreference mPreference;
|
|
||||||
private ContentResolver mContentResolver;
|
private ContentResolver mContentResolver;
|
||||||
private FakeFeatureFactory mFeatureFactory;
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||||
mController = new SmartBatteryPreferenceController(RuntimeEnvironment.application);
|
mController = new SmartBatteryPreferenceController(RuntimeEnvironment.application);
|
||||||
mPreference = new SwitchPreference(RuntimeEnvironment.application);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_smartBatteryOn_preferenceChecked() {
|
public void testUpdateState_smartBatteryOn_preferenceChecked() {
|
||||||
putSmartBatteryValue(ON);
|
putSmartBatteryValue(ON);
|
||||||
|
final MainSwitchPreference preference = new MainSwitchPreference(mContext);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(preference);
|
||||||
|
|
||||||
assertThat(mPreference.isChecked()).isTrue();
|
assertThat(preference.isChecked()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_smartBatteryOff_preferenceUnchecked() {
|
public void testUpdateState_smartBatteryOff_preferenceUnchecked() {
|
||||||
putSmartBatteryValue(OFF);
|
putSmartBatteryValue(OFF);
|
||||||
|
final MainSwitchPreference preference = new MainSwitchPreference(mContext);
|
||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(preference);
|
||||||
|
|
||||||
assertThat(mPreference.isChecked()).isFalse();
|
assertThat(preference.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_checkPreference_smartBatteryOn() {
|
public void testUpdateState_checkPreference_smartBatteryOn() {
|
||||||
mController.onPreferenceChange(mPreference, true);
|
mController.onSwitchChanged(null, true);
|
||||||
|
|
||||||
assertThat(getSmartBatteryValue()).isEqualTo(ON);
|
assertThat(getSmartBatteryValue()).isEqualTo(ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateState_unCheckPreference_smartBatteryOff() {
|
public void testUpdateState_unCheckPreference_smartBatteryOff() {
|
||||||
mController.onPreferenceChange(mPreference, false);
|
mController.onSwitchChanged(null, false);
|
||||||
|
|
||||||
assertThat(getSmartBatteryValue()).isEqualTo(OFF);
|
assertThat(getSmartBatteryValue()).isEqualTo(OFF);
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,7 @@ import android.content.Context;
|
|||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.SwitchPreference;
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -40,7 +40,7 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
public class NfcEnablerTest {
|
public class NfcEnablerTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SwitchPreference mNfcPreference;
|
private MainSwitchPreference mNfcPreference;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private NfcEnabler mNfcEnabler;
|
private NfcEnabler mNfcEnabler;
|
||||||
|
@@ -31,11 +31,11 @@ import android.os.UserManager;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
|
|
||||||
import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker;
|
import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker;
|
||||||
import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker.NfcUpdateReceiver;
|
import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker.NfcUpdateReceiver;
|
||||||
import com.android.settings.testutils.shadow.ShadowNfcAdapter;
|
import com.android.settings.testutils.shadow.ShadowNfcAdapter;
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -63,7 +63,7 @@ public class NfcPreferenceControllerTest {
|
|||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SwitchPreference mNfcPreference;
|
private MainSwitchPreference mNfcPreference;
|
||||||
private NfcPreferenceController mNfcController;
|
private NfcPreferenceController mNfcController;
|
||||||
private ShadowNfcAdapter mShadowNfcAdapter;
|
private ShadowNfcAdapter mShadowNfcAdapter;
|
||||||
private NfcAdapter mNfcAdapter;
|
private NfcAdapter mNfcAdapter;
|
||||||
@@ -81,7 +81,7 @@ public class NfcPreferenceControllerTest {
|
|||||||
|
|
||||||
mNfcController = new NfcPreferenceController(mContext,
|
mNfcController = new NfcPreferenceController(mContext,
|
||||||
NfcPreferenceController.KEY_TOGGLE_NFC);
|
NfcPreferenceController.KEY_TOGGLE_NFC);
|
||||||
mNfcPreference = new SwitchPreference(RuntimeEnvironment.application);
|
mNfcPreference = new MainSwitchPreference(RuntimeEnvironment.application);
|
||||||
|
|
||||||
when(mScreen.findPreference(mNfcController.getPreferenceKey())).thenReturn(mNfcPreference);
|
when(mScreen.findPreference(mNfcController.getPreferenceKey())).thenReturn(mNfcPreference);
|
||||||
}
|
}
|
||||||
|
@@ -22,24 +22,21 @@ import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS;
|
|||||||
import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
|
import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS;
|
||||||
import static android.provider.Settings.Global.ZEN_MODE_OFF;
|
import static android.provider.Settings.Global.ZEN_MODE_OFF;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.notification.zen.ZenModeBackend;
|
|
||||||
import com.android.settings.notification.zen.ZenModeButtonPreferenceController;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -61,14 +58,10 @@ public class ZenModeButtonPreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private NotificationManager mNotificationManager;
|
private NotificationManager mNotificationManager;
|
||||||
@Mock
|
@Mock
|
||||||
private Preference mockPref;
|
private MainSwitchPreference mMockPref;
|
||||||
@Mock
|
@Mock
|
||||||
private NotificationManager.Policy mPolicy;
|
private NotificationManager.Policy mPolicy;
|
||||||
@Mock
|
@Mock
|
||||||
private Button mZenButtonOn;
|
|
||||||
@Mock
|
|
||||||
private Button mZenButtonOff;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
private ContentResolver mContentResolver;
|
private ContentResolver mContentResolver;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -85,67 +78,65 @@ public class ZenModeButtonPreferenceControllerTest {
|
|||||||
mock(FragmentManager.class));
|
mock(FragmentManager.class));
|
||||||
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
|
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
|
||||||
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
||||||
ReflectionHelpers.setField(mController, "mZenButtonOn", mZenButtonOn);
|
|
||||||
ReflectionHelpers.setField(mController, "mZenButtonOff", mZenButtonOff);
|
|
||||||
|
|
||||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
|
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
|
||||||
|
mMockPref);
|
||||||
mController.displayPreference(mPreferenceScreen);
|
mController.displayPreference(mPreferenceScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_TotalSilence() {
|
public void updateState_TotalSilence() {
|
||||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_NO_INTERRUPTIONS);
|
||||||
final Preference mockPref = mock(Preference.class);
|
final MainSwitchPreference pref = new MainSwitchPreference(mContext);
|
||||||
mController.updateState(mockPref);
|
|
||||||
|
|
||||||
verify(mZenButtonOn).setVisibility(View.GONE);
|
mController.updateState(pref);
|
||||||
verify(mZenButtonOff).setVisibility(View.VISIBLE);
|
|
||||||
|
assertThat(pref.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_AlarmsOnly() {
|
public void updateState_AlarmsOnly() {
|
||||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_ALARMS);
|
||||||
final Preference mockPref = mock(Preference.class);
|
final MainSwitchPreference pref = new MainSwitchPreference(mContext);
|
||||||
mController.updateState(mockPref);
|
|
||||||
|
|
||||||
verify(mZenButtonOn).setVisibility(View.GONE);
|
mController.updateState(pref);
|
||||||
verify(mZenButtonOff).setVisibility(View.VISIBLE);
|
|
||||||
|
assertThat(pref.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_Priority() {
|
public void updateState_Priority() {
|
||||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||||
final Preference mockPref = mock(Preference.class);
|
final MainSwitchPreference pref = new MainSwitchPreference(mContext);
|
||||||
mController.updateState(mockPref);
|
|
||||||
|
|
||||||
verify(mZenButtonOn).setVisibility(View.GONE);
|
mController.updateState(pref);
|
||||||
verify(mZenButtonOff).setVisibility(View.VISIBLE);
|
|
||||||
|
assertThat(pref.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_ZenOff() {
|
public void updateState_ZenOff() {
|
||||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
|
||||||
final Preference mockPref = mock(Preference.class);
|
final MainSwitchPreference pref = new MainSwitchPreference(mContext);
|
||||||
mController.updateState(mockPref);
|
|
||||||
|
|
||||||
verify(mZenButtonOn).setVisibility(View.VISIBLE);
|
mController.updateState(pref);
|
||||||
verify(mZenButtonOff).setVisibility(View.GONE);
|
|
||||||
|
assertThat(pref.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_otherUserChangedZen() {
|
public void updateState_otherUserChangedZen() {
|
||||||
final Preference mockPref = mock(Preference.class);
|
|
||||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
|
||||||
mController.updateState(mockPref);
|
final MainSwitchPreference pref = new MainSwitchPreference(mContext);
|
||||||
verify(mZenButtonOn).setVisibility(View.VISIBLE);
|
mController.updateState(pref);
|
||||||
verify(mZenButtonOff).setVisibility(View.GONE);
|
|
||||||
|
assertThat(pref.isChecked()).isFalse();
|
||||||
|
|
||||||
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
|
||||||
final int GUEST_USER_ID = 10;
|
final int GUEST_USER_ID = 10;
|
||||||
mController.mSettingObserver.onChange(false,
|
mController.mSettingObserver.onChange(false,
|
||||||
Settings.Global.getUriFor(Settings.Global.ZEN_MODE), GUEST_USER_ID);
|
Settings.Global.getUriFor(Settings.Global.ZEN_MODE), GUEST_USER_ID);
|
||||||
|
|
||||||
verify(mZenButtonOn).setVisibility(View.GONE);
|
assertThat(pref.isChecked()).isFalse();
|
||||||
verify(mZenButtonOff).setVisibility(View.VISIBLE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user