Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3fbad7a authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8022168 from bfd37d65 to sc-v2-release

Change-Id: I3c283d348d49193e13d742c1fac24fbabd7055ca
parents 2353ccd1 bfd37d65
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  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.
  -->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:gravity="bottom"
    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/ActionPrimaryButton"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/screensaver_settings_dream_start"/>

</LinearLayout>
+2 −2
Original line number Diff line number Diff line
@@ -3210,6 +3210,8 @@
    <string name="screensaver_settings_when_to_dream">When to start</string>
    <!-- Dream settings screen, action label, current selected screen saver -->
    <string name="screensaver_settings_current">Current screen saver</string>
    <!-- Dream settings screen, button label to start dreaming [CHAR LIMIT=30] -->
    <string name="screensaver_settings_dream_start">Start now</string>
    <!-- Dream settings screen, button label for settings for a specific screensaver -->
    <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 -->
@@ -13531,8 +13533,6 @@
    <string name="adaptive_brightness_main_switch_title">Use adaptive brightness</string>
    <!-- Title for wifi calling main switch preferences. [CHAR LIMIT=50] -->
    <string name="wifi_calling_main_switch_title">Use Wi‑Fi calling</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]-->
    <string name="default_see_all_apps_title">See all apps</string>
+8 −5
Original line number Diff line number Diff line
@@ -19,11 +19,6 @@
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    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
        android:key="current_screensaver"
        android:title="@string/screensaver_settings_current"
@@ -35,4 +30,12 @@
        android:title="@string/screensaver_settings_when_to_dream"
        android:fragment="com.android.settings.dream.WhenToDreamPicker" />

    <PreferenceCategory>
        <com.android.settingslib.widget.LayoutPreference
            android:key="dream_start_now_button_container"
            android:layout="@layout/dream_start_button"
            android:selectable="false"
            settings:controller="com.android.settings.dream.StartNowPreferenceController" />
    </PreferenceCategory>

</PreferenceScreen>
+18 −22
Original line number Diff line number Diff line
@@ -17,20 +17,23 @@
package com.android.settings.dream;

import android.content.Context;
import android.widget.Button;

import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.widget.LayoutPreference;

/**
 * Controller that used to enable screen saver
 */
public class StartNowPreferenceController extends SettingsMainSwitchPreferenceController {
public class StartNowPreferenceController extends BasePreferenceController {

    private final DreamBackend mBackend;
    private final MetricsFeatureProvider mMetricsFeatureProvider;
@@ -47,30 +50,23 @@ public class StartNowPreferenceController extends SettingsMainSwitchPreferenceCo
    }

    @Override
    public void updateState(Preference preference) {
        mSwitchPreference.setChecked(false);
        mSwitchPreference.setEnabled(mBackend.getWhenToDreamSetting() != DreamBackend.NEVER);
    }

    @Override
    public boolean isChecked() {
        return false;
    }
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);

    @Override
    public boolean setChecked(boolean isChecked) {
        if (isChecked) {
            if (mSwitchPreference != null) {
                mMetricsFeatureProvider.logClickedPreference(mSwitchPreference,
                        mSwitchPreference.getExtras().getInt(DashboardFragment.CATEGORY));
            }
        final LayoutPreference pref = screen.findPreference(getPreferenceKey());
        final Button startButton = pref.findViewById(R.id.dream_start_now_button);
        startButton.setOnClickListener(v -> {
            mMetricsFeatureProvider.logClickedPreference(pref,
                    pref.getExtras().getInt(DashboardFragment.CATEGORY));
            mBackend.startDreaming();
        }
        return true;
        });
    }

    @Override
    public int getSliceHighlightMenuRes() {
        return R.string.menu_key_display;
    public void updateState(Preference preference) {
        super.updateState(preference);
        final Button startButton = ((LayoutPreference) preference)
                .findViewById(R.id.dream_start_now_button);
        startButton.setEnabled(mBackend.getWhenToDreamSetting() != DreamBackend.NEVER);
    }
}
+14 −18
Original line number Diff line number Diff line
@@ -16,17 +16,18 @@

package com.android.settings.dream;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.widget.Button;

import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.widget.MainSwitchPreference;
import com.android.settingslib.widget.LayoutPreference;

import org.junit.Before;
import org.junit.Test;
@@ -46,7 +47,9 @@ public class StartNowPreferenceControllerTest {
    @Mock
    private PreferenceScreen mScreen;
    @Mock
    private MainSwitchPreference mPref;
    private LayoutPreference mLayoutPref;
    @Mock
    private Button mButton;
    @Mock
    private DreamBackend mBackend;

@@ -56,36 +59,29 @@ public class StartNowPreferenceControllerTest {

        mContext = spy(RuntimeEnvironment.application);
        mController = new StartNowPreferenceController(mContext, "key");
        mPref = mock(MainSwitchPreference.class);
        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPref);
        when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mLayoutPref);
        when(mLayoutPref.findViewById(R.id.dream_start_now_button)).thenReturn(mButton);

        ReflectionHelpers.setField(mController, "mBackend", mBackend);
    }

    @Test
    public void displayPreference_shouldAddOnSwitchChangeListener() {
        mController.displayPreference(mScreen);

        verify(mPref).addOnSwitchChangeListener(mController);
    }

    @Test
    public void updateState_neverDreaming_preferenceShouldDidabled() {
    public void updateState_neverDreaming_buttonShouldDidabled() {
        when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.NEVER);
        mController.displayPreference(mScreen);

        mController.updateState(mPref);
        mController.updateState(mLayoutPref);

        verify(mPref).setEnabled(false);
        verify(mButton).setEnabled(false);
    }

    @Test
    public void updateState_dreamIsAvailable_preferenceShouldEnabled() {
    public void updateState_dreamIsAvailable_buttonShouldEnabled() {
        when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.EITHER);
        mController.displayPreference(mScreen);

        mController.updateState(mPref);
        mController.updateState(mLayoutPref);

        verify(mPref).setEnabled(true);
        verify(mButton).setEnabled(true);
    }
}