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

Commit 48ea6abf authored by Jason Chang's avatar Jason Chang Committed by Automerger Merge Worker
Browse files

Merge changes from topic "OHM-newUI-Sys-Gesture" into sc-dev am: 5213fbce

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/14804130

Change-Id: Ia210213ae6504c7192186d59ff37877444bc8b9c
parents c9b0c596 5213fbce
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -11676,7 +11676,7 @@
    <string name="swipe_bottom_to_notifications_summary">Swipe down on the bottom edge of the screen to show your notifications.\nYou can\'t use one-handed mode when this feature is turned on.</string>
    <!-- Preference and settings suggestion title text for one handed [CHAR LIMIT=60] -->
    <string name="one_handed_title">One-Handed mode</string>
    <string name="one_handed_title">One-handed mode</string>
    <!-- Preference Switch for enabling one handed [CHAR LIMIT=60] -->
    <string name="one_handed_mode_enabled">Use one-handed mode</string>
    <!-- Preference Switch for app taps to exit one handed [CHAR LIMIT=60] -->
@@ -11691,6 +11691,19 @@
    <string name="one_handed_timeout_long">12 seconds</string>
    <!-- Search keywords for "One-Handed" settings [CHAR_LIMIT=NONE] -->
    <string name="keywords_one_handed">reachability</string>
    <!-- Category title for one handed swipe down [CHAR_LIMIT=60] -->
    <string name="one_handed_mode_swipe_down_category">Swipe down to</string>
    <!-- One-handed mode Intro Text [CHAR_LIMIT=NONE] -->
    <string name="one_handed_mode_intro_text">To use one handed mode, swipe down from the bottom edge of the screen. To use this feature, make sure gesture navigation is turned on in system navigation settings.</string>
    <!-- One-handed mode pull down screen into reach action title [CHAR_LIMIT=60] -->
    <string name="one_handed_action_pull_down_screen_title">Pull screen into reach</string>
    <!-- One-handed mode pull down screen into reach action title [CHAR_LIMIT=NONE] -->
    <string name="one_handed_action_pull_down_screen_summary">The top of the screen will move into reach of your thumb.</string>
    <!-- One-handed mode show notification action [CHAR_LIMIT=60] -->
    <string name="one_handed_action_show_notification_title">Show notifications</string>
    <!-- One-handed mode show notification action [CHAR_LIMIT=NONE] -->
    <string name="one_handed_action_show_notification_summary">Notification and settings will appear.</string>
    <!-- One-handed mode Intro text for gesture navigation [CHAR_LIMIT=NONE] -->
    <!-- Summary text for ambient display double tap [CHAR LIMIT=NONE]-->
    <string name="ambient_display_summary">To check time, notifications, and other info, double-tap your screen.</string>
+26 −17
Original line number Diff line number Diff line
@@ -21,12 +21,6 @@
    android:persistent="false"
    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
        android:key="one_handed_header"
        android:layout="@layout/one_handed_header"
@@ -35,16 +29,31 @@
        settings:allowDividerBelow="false"
        settings:searchable="false"/>

    <SwitchPreference
        android:key="gesture_app_taps_to_exit"
        android:title="@string/one_handed_app_taps_to_exit"
        settings:controller="com.android.settings.gestures.OneHandedAppTapsExitPreferenceController"/>
    <com.android.settingslib.widget.MainSwitchPreference
        android:key="gesture_one_handed_mode_enabled_main_switch"
        android:title="@string/one_handed_mode_enabled"
        settings:keywords="@string/keywords_one_handed"
        settings:controller="com.android.settings.gestures.OneHandedMainSwitchPreferenceController"/>

    <com.android.settingslib.widget.TopIntroPreference
        android:key="gesture_one_handed_mode_intro_text"
        android:title="@string/one_handed_mode_intro_text"/>

    <ListPreference
        android:key="gesture_one_handed_timeout"
        android:entries="@array/one_handed_timeout_title"
        android:entryValues="@array/one_handed_timeout_values"
        android:persistent="false"
        android:title="@string/one_handed_timeout_title"
        settings:controller="com.android.settings.gestures.OneHandedTimeoutPreferenceController"/>
    <PreferenceCategory
        android:key="gesture_one_handed_mode_swipe_down"
        android:title="@string/one_handed_mode_swipe_down_category">

        <com.android.settingslib.widget.RadioButtonPreference
            android:key="gesture_one_handed_action_pull_screen_down"
            android:title="@string/one_handed_action_pull_down_screen_title"
            android:summary="@string/one_handed_action_pull_down_screen_summary"
            settings:controller="com.android.settings.gestures.OneHandedActionPullDownPrefController"/>

        <com.android.settingslib.widget.RadioButtonPreference
            android:key="gesture_one_handed_action_show_notification"
            android:title="@string/one_handed_action_show_notification_title"
            android:summary="@string/one_handed_action_show_notification_summary"
            settings:controller="com.android.settings.gestures.OneHandedActionShowNotificationPrefController"/>

    </PreferenceCategory>
</PreferenceScreen>
+101 −0
Original line number Diff line number Diff line
/*
 * 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.gestures;

import android.content.Context;
import android.net.Uri;

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

import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.widget.RadioButtonPreference;

/**
 * The controller to handle one-handed mode pull screen into reach preference.
 **/
public class OneHandedActionPullDownPrefController extends BasePreferenceController
        implements OneHandedSettingsUtils.TogglesCallback, LifecycleObserver, OnStart, OnStop {

    private final OneHandedSettingsUtils mUtils;

    private Preference mPreference;

    public OneHandedActionPullDownPrefController(Context context, String key) {
        super(context, key);
        mUtils = new OneHandedSettingsUtils(context);
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        if (preference instanceof RadioButtonPreference) {
            ((RadioButtonPreference) preference).setChecked(
                    !OneHandedSettingsUtils.isSwipeDownNotificationEnabled(mContext));
        }
    }

    @Override
    public int getAvailabilityStatus() {
        return  (OneHandedSettingsUtils.isSupportOneHandedMode()
                && OneHandedSettingsUtils.canEnableController(mContext))
                ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
    }

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (!getPreferenceKey().equals(preference.getKey())) {
            return false;
        }
        OneHandedSettingsUtils.setSwipeDownNotificationEnabled(mContext, false);
        if (preference instanceof RadioButtonPreference) {
            ((RadioButtonPreference) preference).setChecked(true);
        }
        return true;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference = screen.findPreference(getPreferenceKey());
    }

    @Override
    public void onStart() {
        mUtils.registerToggleAwareObserver(this);
    }

    @Override
    public void onStop() {
        mUtils.unregisterToggleAwareObserver();
    }

    @Override
    public void onChange(Uri uri) {
        if (mPreference == null) {
            return;
        }
        if (uri.equals(OneHandedSettingsUtils.ONE_HANDED_MODE_ENABLED_URI)) {
            mPreference.setEnabled(OneHandedSettingsUtils.canEnableController(mContext));
        } else if (uri.equals(OneHandedSettingsUtils.SHOW_NOTIFICATION_ENABLED_URI)) {
            updateState(mPreference);
        }
    }
}
+101 −0
Original line number Diff line number Diff line
/*
 * 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.gestures;

import android.content.Context;
import android.net.Uri;

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

import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.widget.RadioButtonPreference;

/**
 * The controller to handle one-handed mode show notification preference.
 **/
public class OneHandedActionShowNotificationPrefController extends BasePreferenceController
        implements OneHandedSettingsUtils.TogglesCallback, LifecycleObserver, OnStart, OnStop {

    private final OneHandedSettingsUtils mUtils;

    private Preference mPreference;

    public OneHandedActionShowNotificationPrefController(Context context, String key) {
        super(context, key);
        mUtils = new OneHandedSettingsUtils(context);
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        if (preference instanceof RadioButtonPreference) {
            ((RadioButtonPreference) preference).setChecked(
                    OneHandedSettingsUtils.isSwipeDownNotificationEnabled(mContext));
        }
    }

    @Override
    public int getAvailabilityStatus() {
        return  (OneHandedSettingsUtils.isSupportOneHandedMode()
                && OneHandedSettingsUtils.canEnableController(mContext))
                ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
    }

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (!getPreferenceKey().equals(preference.getKey())) {
            return false;
        }
        OneHandedSettingsUtils.setSwipeDownNotificationEnabled(mContext, true);
        if (preference instanceof RadioButtonPreference) {
            ((RadioButtonPreference) preference).setChecked(true);
        }
        return true;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        super.displayPreference(screen);
        mPreference = screen.findPreference(getPreferenceKey());
    }

    @Override
    public void onStart() {
        mUtils.registerToggleAwareObserver(this);
    }

    @Override
    public void onStop() {
        mUtils.unregisterToggleAwareObserver();
    }

    @Override
    public void onChange(Uri uri) {
        if (mPreference == null) {
            return;
        }
        if (uri.equals(OneHandedSettingsUtils.ONE_HANDED_MODE_ENABLED_URI)) {
            mPreference.setEnabled(OneHandedSettingsUtils.canEnableController(mContext));
        } else if (uri.equals(OneHandedSettingsUtils.SHOW_NOTIFICATION_ENABLED_URI)) {
            updateState(mPreference);
        }
    }
}
+7 −19
Original line number Diff line number Diff line
@@ -19,37 +19,25 @@ package com.android.settings.gestures;
import android.content.Context;

import com.android.settings.R;
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
import com.android.settings.core.BasePreferenceController;

/**
 * The controller to handle one-handed mode enable or disable state.
 **/
public class OneHandedEnablePreferenceController extends SettingsMainSwitchPreferenceController {
public class OneHandedEnablePreferenceController extends BasePreferenceController {

    public OneHandedEnablePreferenceController(Context context, String key) {
        super(context, key);
    public OneHandedEnablePreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, isChecked);
        OneHandedSettingsUtils.setSwipeDownNotificationEnabled(mContext, !isChecked);
        return true;
    }

    @Override
    public boolean isChecked() {
        return OneHandedSettingsUtils.isOneHandedModeEnabled(mContext);
        return OneHandedSettingsUtils.isSupportOneHandedMode() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
    }

    @Override
    public CharSequence getSummary() {
        return mContext.getText(
                isChecked() ? R.string.gesture_setting_on : R.string.gesture_setting_off);
                OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)
                        ? R.string.gesture_setting_on : R.string.gesture_setting_off);
    }
}
Loading