Merge "Use MainSwitchPreference on Bubbles, Screen Saver and One-Handed mode pages." into sc-dev
This commit is contained in:
@@ -1,38 +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:orientation="horizontal"
|
|
||||||
android:gravity="bottom"
|
|
||||||
android:paddingTop="4dp"
|
|
||||||
android:paddingStart="72dp"
|
|
||||||
android:paddingEnd="72dp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/dream_start_now_button"
|
|
||||||
style="@style/ActionSecondaryButton"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:text="@string/screensaver_settings_dream_start"
|
|
||||||
android:paddingEnd="8dp" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@@ -3122,8 +3122,6 @@
|
|||||||
<string name="screensaver_settings_when_to_dream">When to start</string>
|
<string name="screensaver_settings_when_to_dream">When to start</string>
|
||||||
<!-- Dream settings screen, action label, current selected screen saver -->
|
<!-- Dream settings screen, action label, current selected screen saver -->
|
||||||
<string name="screensaver_settings_current">Current screen saver</string>
|
<string name="screensaver_settings_current">Current screen saver</string>
|
||||||
<!-- Dream settings screen, button label to start dreaming -->
|
|
||||||
<string name="screensaver_settings_dream_start">Start now</string>
|
|
||||||
<!-- Dream settings screen, button label for settings for a specific screensaver -->
|
<!-- Dream settings screen, button label for settings for a specific screensaver -->
|
||||||
<string name="screensaver_settings_button">Settings</string>
|
<string name="screensaver_settings_button">Settings</string>
|
||||||
<!-- Sound & display settings screen, setting option name to change whether the screen adjusts automatically based on lighting conditions -->
|
<!-- Sound & display settings screen, setting option name to change whether the screen adjusts automatically based on lighting conditions -->
|
||||||
@@ -8746,10 +8744,6 @@
|
|||||||
|
|
||||||
<!-- Bubble feature settings: Description for toggle when bubbles are turned on in notification settings [CHAR LIMIT=100] -->
|
<!-- Bubble feature settings: Description for toggle when bubbles are turned on in notification settings [CHAR LIMIT=100] -->
|
||||||
<string name="notifications_bubble_setting_on_summary">On / Conversations can appear as floating icons</string>
|
<string name="notifications_bubble_setting_on_summary">On / Conversations can appear as floating icons</string>
|
||||||
<!-- Bubble feature settings: Title of the toggle to turn bubbles on and off [CHAR LIMIT=100] -->
|
|
||||||
<string name="notifications_bubble_setting_title">Allow apps to show bubbles</string>
|
|
||||||
<!-- Bubble feature settings: Description shown with the toggle to turn bubbles on and off [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="notifications_bubble_setting_description">Some conversations will appear as floating icons on top of other apps</string>
|
|
||||||
|
|
||||||
<!-- Bubble app settings: option allowing all conversations from an app to bubble if the app sends bubbles [CHAR LIMIT=60]-->
|
<!-- Bubble app settings: option allowing all conversations from an app to bubble if the app sends bubbles [CHAR LIMIT=60]-->
|
||||||
<string name="bubble_app_setting_all">All conversations can bubble</string>
|
<string name="bubble_app_setting_all">All conversations can bubble</string>
|
||||||
@@ -13232,6 +13226,10 @@
|
|||||||
<string name="adaptive_brightness_main_switch_title">Use adaptive brightness</string>
|
<string name="adaptive_brightness_main_switch_title">Use adaptive brightness</string>
|
||||||
<!-- Title for wifi calling main switch preferences. [CHAR LIMIT=50] -->
|
<!-- Title for wifi calling main switch preferences. [CHAR LIMIT=50] -->
|
||||||
<string name="wifi_calling_main_switch_title">Use Wi‑Fi calling</string>
|
<string name="wifi_calling_main_switch_title">Use Wi‑Fi calling</string>
|
||||||
|
<!-- Title for Bubbles main switch preferences. [CHAR LIMIT=50] -->
|
||||||
|
<string name="bubbles_main_switch_title">Use Bubbles</string>
|
||||||
|
<!-- Title for Screen saver main switch preferences. [CHAR LIMIT=50] -->
|
||||||
|
<string name="screen_saver_main_switch_title">Use screen saver</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>
|
||||||
|
@@ -18,6 +18,11 @@
|
|||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
android:title="@string/bubbles_app_toggle_title">
|
android:title="@string/bubbles_app_toggle_title">
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
android:key="global_notification_bubbles"
|
||||||
|
android:title="@string/bubbles_main_switch_title"
|
||||||
|
settings:controller="com.android.settings.notification.BubbleNotificationPreferenceController"/>
|
||||||
|
|
||||||
<com.android.settings.widget.VideoPreference
|
<com.android.settings.widget.VideoPreference
|
||||||
android:key="bubbles_illustration"
|
android:key="bubbles_illustration"
|
||||||
android:title="@string/summary_placeholder"
|
android:title="@string/summary_placeholder"
|
||||||
@@ -25,13 +30,4 @@
|
|||||||
settings:controller="com.android.settings.widget.VideoPreferenceController"
|
settings:controller="com.android.settings.widget.VideoPreferenceController"
|
||||||
android:persistent="false" />
|
android:persistent="false" />
|
||||||
|
|
||||||
<!-- Notification bubbles -->
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="global_notification_bubbles"
|
|
||||||
android:icon="@drawable/ic_create_bubble"
|
|
||||||
settings:allowDividerAbove="true"
|
|
||||||
android:title="@string/notifications_bubble_setting_title"
|
|
||||||
android:summary="@string/notifications_bubble_setting_description"
|
|
||||||
settings:controller="com.android.settings.notification.BubbleNotificationPreferenceController"/>
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
@@ -19,6 +19,11 @@
|
|||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
android:title="@string/screensaver_settings_title">
|
android:title="@string/screensaver_settings_title">
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
android:key="dream_start_now_button_container"
|
||||||
|
android:title="@string/screen_saver_main_switch_title"
|
||||||
|
settings:controller="com.android.settings.dream.StartNowPreferenceController"/>
|
||||||
|
|
||||||
<com.android.settings.widget.GearPreference
|
<com.android.settings.widget.GearPreference
|
||||||
android:key="current_screensaver"
|
android:key="current_screensaver"
|
||||||
android:title="@string/screensaver_settings_current"
|
android:title="@string/screensaver_settings_current"
|
||||||
@@ -30,14 +35,4 @@
|
|||||||
android:title="@string/screensaver_settings_when_to_dream"
|
android:title="@string/screensaver_settings_when_to_dream"
|
||||||
android:fragment="com.android.settings.dream.WhenToDreamPicker" />
|
android:fragment="com.android.settings.dream.WhenToDreamPicker" />
|
||||||
|
|
||||||
|
|
||||||
<!-- Layout preference doesn't obey allowDividerAbove, so put it in a PreferenceCategory -->
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="dream_start_now_category">
|
|
||||||
<com.android.settingslib.widget.LayoutPreference
|
|
||||||
android:key="dream_start_now_button_container"
|
|
||||||
android:selectable="false"
|
|
||||||
android:layout="@layout/dream_start_button" />
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -21,6 +21,12 @@
|
|||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/one_handed_title">
|
android:title="@string/one_handed_title">
|
||||||
|
|
||||||
|
<com.android.settingslib.widget.MainSwitchPreference
|
||||||
|
android:key="gesture_one_handed_mode_enabled"
|
||||||
|
android:title="@string/one_handed_mode_enabled"
|
||||||
|
settings:keywords="@string/keywords_one_handed"
|
||||||
|
settings:controller="com.android.settings.gestures.OneHandedEnablePreferenceController"/>
|
||||||
|
|
||||||
<com.android.settingslib.widget.LayoutPreference
|
<com.android.settingslib.widget.LayoutPreference
|
||||||
android:key="one_handed_header"
|
android:key="one_handed_header"
|
||||||
android:layout="@layout/one_handed_header"
|
android:layout="@layout/one_handed_header"
|
||||||
@@ -29,12 +35,6 @@
|
|||||||
settings:allowDividerBelow="false"
|
settings:allowDividerBelow="false"
|
||||||
settings:searchable="false"/>
|
settings:searchable="false"/>
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:key="gesture_one_handed_mode_enabled"
|
|
||||||
android:title="@string/one_handed_mode_enabled"
|
|
||||||
settings:keywords="@string/keywords_one_handed"
|
|
||||||
settings:controller="com.android.settings.gestures.OneHandedEnablePreferenceController"/>
|
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:key="gesture_app_taps_to_exit"
|
android:key="gesture_app_taps_to_exit"
|
||||||
android:title="@string/one_handed_app_taps_to_exit"
|
android:title="@string/one_handed_app_taps_to_exit"
|
||||||
|
@@ -129,9 +129,8 @@ public class DreamSettings extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
|
||||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
controllers.add(new WhenToDreamPreferenceController(context));
|
controllers.add(new WhenToDreamPreferenceController(context));
|
||||||
controllers.add(new StartNowPreferenceController(context));
|
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,63 +17,52 @@
|
|||||||
package com.android.settings.dream;
|
package com.android.settings.dream;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
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.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settingslib.dream.DreamBackend;
|
import com.android.settingslib.dream.DreamBackend;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
|
||||||
|
|
||||||
public class StartNowPreferenceController extends AbstractPreferenceController implements
|
/**
|
||||||
PreferenceControllerMixin {
|
* Controller that used to enable screen saver
|
||||||
|
*/
|
||||||
|
public class StartNowPreferenceController extends SettingsMainSwitchPreferenceController {
|
||||||
|
|
||||||
private static final String PREF_KEY = "dream_start_now_button_container";
|
|
||||||
private final DreamBackend mBackend;
|
private final DreamBackend mBackend;
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
public StartNowPreferenceController(Context context) {
|
public StartNowPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context);
|
super(context, preferenceKey);
|
||||||
|
|
||||||
mBackend = DreamBackend.getInstance(context);
|
mBackend = DreamBackend.getInstance(context);
|
||||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return true;
|
return AVAILABLE;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return PREF_KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
|
|
||||||
LayoutPreference pref = screen.findPreference(getPreferenceKey());
|
|
||||||
Button startButton = pref.findViewById(R.id.dream_start_now_button);
|
|
||||||
startButton.setOnClickListener(v -> {
|
|
||||||
mMetricsFeatureProvider.logClickedPreference(pref,
|
|
||||||
pref.getExtras().getInt(DashboardFragment.CATEGORY));
|
|
||||||
mBackend.startDreaming();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
super.updateState(preference);
|
mSwitchPreference.setChecked(false);
|
||||||
|
mSwitchPreference.setEnabled(mBackend.getWhenToDreamSetting() != DreamBackend.NEVER);
|
||||||
|
}
|
||||||
|
|
||||||
Button startButton = ((LayoutPreference) preference)
|
@Override
|
||||||
.findViewById(R.id.dream_start_now_button);
|
public boolean isChecked() {
|
||||||
startButton.setEnabled(mBackend.getWhenToDreamSetting() != DreamBackend.NEVER);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setChecked(boolean isChecked) {
|
||||||
|
if (isChecked) {
|
||||||
|
mMetricsFeatureProvider.logClickedPreference(mSwitchPreference,
|
||||||
|
mSwitchPreference.getExtras().getInt(DashboardFragment.CATEGORY));
|
||||||
|
mBackend.startDreaming();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,12 +20,12 @@ import android.content.Context;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The controller to handle one-handed mode enable or disable state.
|
* The controller to handle one-handed mode enable or disable state.
|
||||||
**/
|
**/
|
||||||
public class OneHandedEnablePreferenceController extends TogglePreferenceController {
|
public class OneHandedEnablePreferenceController extends SettingsMainSwitchPreferenceController {
|
||||||
|
|
||||||
public OneHandedEnablePreferenceController(Context context, String key) {
|
public OneHandedEnablePreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
|
@@ -30,8 +30,7 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
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;
|
||||||
@@ -40,9 +39,8 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
|||||||
* Feature level screen for bubbles, available through notification menu.
|
* Feature level screen for bubbles, available through notification menu.
|
||||||
* Allows user to turn bubbles on or off for the device.
|
* Allows user to turn bubbles on or off for the device.
|
||||||
*/
|
*/
|
||||||
public class BubbleNotificationPreferenceController extends TogglePreferenceController
|
public class BubbleNotificationPreferenceController extends
|
||||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
|
SettingsMainSwitchPreferenceController implements LifecycleObserver, OnResume, OnPause {
|
||||||
LifecycleObserver, OnResume, OnPause {
|
|
||||||
|
|
||||||
private static final String TAG = "BubbleNotifPrefContr";
|
private static final String TAG = "BubbleNotifPrefContr";
|
||||||
|
|
||||||
@@ -60,9 +58,8 @@ public class BubbleNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
@Override
|
@Override
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
Preference preference = screen.findPreference(getPreferenceKey());
|
if (mSwitchPreference != null) {
|
||||||
if (preference != null) {
|
mSettingObserver = new SettingObserver(mSwitchPreference);
|
||||||
mSettingObserver = new SettingObserver(preference);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,21 +83,22 @@ public class BubbleNotificationPreferenceController extends TogglePreferenceCont
|
|||||||
return am.isLowRamDevice() ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
|
return am.isLowRamDevice() ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSliceable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
NOTIFICATION_BUBBLES, ON) == ON;
|
NOTIFICATION_BUBBLES, ON) == ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
return Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
|
Settings.Global.putInt(mContext.getContentResolver(),
|
||||||
isChecked ? ON : OFF);
|
NOTIFICATION_BUBBLES, isChecked ? ON : OFF);
|
||||||
}
|
return true;
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSliceable() {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingObserver extends ContentObserver {
|
class SettingObserver extends ContentObserver {
|
||||||
|
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.widget;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference controller for MainSwitchPreference.
|
||||||
|
*/
|
||||||
|
public abstract class SettingsMainSwitchPreferenceController extends
|
||||||
|
TogglePreferenceController implements OnMainSwitchChangeListener {
|
||||||
|
|
||||||
|
protected MainSwitchPreference mSwitchPreference;
|
||||||
|
|
||||||
|
public SettingsMainSwitchPreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
final Preference pref = screen.findPreference(getPreferenceKey());
|
||||||
|
if (pref != null && pref instanceof MainSwitchPreference) {
|
||||||
|
mSwitchPreference = (MainSwitchPreference) pref;
|
||||||
|
mSwitchPreference.addOnSwitchChangeListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||||
|
mSwitchPreference.setChecked(isChecked);
|
||||||
|
setChecked(isChecked);
|
||||||
|
}
|
||||||
|
}
|
@@ -16,43 +16,37 @@
|
|||||||
|
|
||||||
package com.android.settings.dream;
|
package com.android.settings.dream;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settingslib.dream.DreamBackend;
|
import com.android.settingslib.dream.DreamBackend;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
|
||||||
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 org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class StartNowPreferenceControllerTest {
|
public class StartNowPreferenceControllerTest {
|
||||||
|
|
||||||
private StartNowPreferenceController mController;
|
private StartNowPreferenceController mController;
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
@Mock
|
@Mock
|
||||||
private LayoutPreference mLayoutPref;
|
private MainSwitchPreference mPref;
|
||||||
@Mock
|
|
||||||
private Button mButton;
|
|
||||||
@Mock
|
@Mock
|
||||||
private DreamBackend mBackend;
|
private DreamBackend mBackend;
|
||||||
|
|
||||||
@@ -60,36 +54,38 @@ public class StartNowPreferenceControllerTest {
|
|||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
mController = new StartNowPreferenceController(mContext);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mLayoutPref);
|
mController = new StartNowPreferenceController(mContext, "key");
|
||||||
when(mLayoutPref.findViewById(R.id.dream_start_now_button)).thenReturn(mButton);
|
mPref = mock(MainSwitchPreference.class);
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPref);
|
||||||
|
|
||||||
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setsOnClickListenerForStartNow() {
|
public void displayPreference_shouldAddOnSwitchChangeListener() {
|
||||||
ArgumentCaptor<OnClickListener> captor =
|
|
||||||
ArgumentCaptor.forClass(Button.OnClickListener.class);
|
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
verify(mButton).setOnClickListener(captor.capture());
|
|
||||||
assertThat(captor.getValue()).isNotNull();
|
verify(mPref).addOnSwitchChangeListener(mController);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buttonIsDisabledWhenNeverDreaming() {
|
public void updateState_neverDreaming_preferenceShouldDidabled() {
|
||||||
when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.NEVER);
|
when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.NEVER);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
mController.updateState(mLayoutPref);
|
mController.updateState(mPref);
|
||||||
verify(mButton).setEnabled(false);
|
|
||||||
|
verify(mPref).setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buttonIsEnabledWhenDreamIsAvailable() {
|
public void updateState_dreamIsAvailable_preferenceShouldEnabled() {
|
||||||
when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.EITHER);
|
when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.EITHER);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
mController.updateState(mLayoutPref);
|
mController.updateState(mPref);
|
||||||
verify(mButton).setEnabled(true);
|
|
||||||
|
verify(mPref).setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,17 +26,15 @@ import static com.android.settings.notification.BadgingNotificationPreferenceCon
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
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.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.TwoStatePreference;
|
|
||||||
|
import com.android.settingslib.widget.MainSwitchPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -57,7 +55,7 @@ public class BubbleNotificationPreferenceControllerTest {
|
|||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
private BubbleNotificationPreferenceController mController;
|
private BubbleNotificationPreferenceController mController;
|
||||||
private Preference mPreference;
|
private MainSwitchPreference mPreference;
|
||||||
|
|
||||||
private static final String KEY_NOTIFICATION_BUBBLES = "notification_bubbles";
|
private static final String KEY_NOTIFICATION_BUBBLES = "notification_bubbles";
|
||||||
|
|
||||||
@@ -67,9 +65,10 @@ public class BubbleNotificationPreferenceControllerTest {
|
|||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mController = new BubbleNotificationPreferenceController(mContext,
|
mController = new BubbleNotificationPreferenceController(mContext,
|
||||||
KEY_NOTIFICATION_BUBBLES);
|
KEY_NOTIFICATION_BUBBLES);
|
||||||
mPreference = new Preference(RuntimeEnvironment.application);
|
mPreference = new MainSwitchPreference(RuntimeEnvironment.application);
|
||||||
mPreference.setKey(mController.getPreferenceKey());
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
|
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -88,40 +87,35 @@ public class BubbleNotificationPreferenceControllerTest {
|
|||||||
assertEquals(AVAILABLE, mController.getAvailabilityStatus());
|
assertEquals(AVAILABLE, mController.getAvailabilityStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateState_settingIsOn_preferenceSetChecked() {
|
|
||||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
|
||||||
|
|
||||||
mController.updateState(preference);
|
|
||||||
|
|
||||||
verify(preference).setChecked(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateState_settingIsOff_preferenceSetUnchecked() {
|
public void updateState_settingIsOff_preferenceSetUnchecked() {
|
||||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
|
||||||
NOTIFICATION_BUBBLES, ON)).isEqualTo(OFF);
|
NOTIFICATION_BUBBLES, ON)).isEqualTo(OFF);
|
||||||
|
|
||||||
mController.updateState(preference);
|
mPreference.updateStatus(false);
|
||||||
|
|
||||||
verify(preference).setChecked(false);
|
assertThat(mPreference.isChecked()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_settingIsOff_shouldReturnFalse() {
|
public void onSwitchChanged_true_settingIsOff_flagShouldOn() {
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
mController.onSwitchChanged(null, true);
|
||||||
|
|
||||||
|
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
|
NOTIFICATION_BUBBLES, OFF)).isEqualTo(ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isChecked_settingIsOn_shouldReturnTrue() {
|
public void onSwitchChanged_false_settingIsOn_flagShouldOff() {
|
||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
||||||
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
mController.onSwitchChanged(null, false);
|
||||||
|
|
||||||
|
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
|
NOTIFICATION_BUBBLES, ON)).isEqualTo(OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -129,8 +123,8 @@ public class BubbleNotificationPreferenceControllerTest {
|
|||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
|
||||||
|
|
||||||
mController.setChecked(false);
|
mController.setChecked(false);
|
||||||
int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
|
int updatedValue = Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
NOTIFICATION_BUBBLES, -1);
|
NOTIFICATION_BUBBLES, ON);
|
||||||
|
|
||||||
assertThat(updatedValue).isEqualTo(OFF);
|
assertThat(updatedValue).isEqualTo(OFF);
|
||||||
}
|
}
|
||||||
@@ -140,8 +134,8 @@ public class BubbleNotificationPreferenceControllerTest {
|
|||||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
|
||||||
|
|
||||||
mController.setChecked(true);
|
mController.setChecked(true);
|
||||||
int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
|
int updatedValue = Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
NOTIFICATION_BUBBLES, -1);
|
NOTIFICATION_BUBBLES, OFF);
|
||||||
|
|
||||||
assertThat(updatedValue).isEqualTo(ON);
|
assertThat(updatedValue).isEqualTo(ON);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user