Adding Settings preference for single finger panning feature
Test: Locally tested on device + MagnificationOneFingerPanningPreferenceControllerTest Bug: 282039824 Change-Id: I1d1a649060cba862c8f333e6e76184fade2dcdce
This commit is contained in:
@@ -4760,6 +4760,14 @@
|
|||||||
<string name="accessibility_magnification_triple_tap_warning_negative_button">Cancel</string>
|
<string name="accessibility_magnification_triple_tap_warning_negative_button">Cancel</string>
|
||||||
<!-- Title for the accessibility preference screen to enable screen magnification settings. [CHAR LIMIT=35] -->
|
<!-- Title for the accessibility preference screen to enable screen magnification settings. [CHAR LIMIT=35] -->
|
||||||
<string name="accessibility_magnification_service_settings_title">Magnification settings</string>
|
<string name="accessibility_magnification_service_settings_title">Magnification settings</string>
|
||||||
|
<!-- Title for accessibility magnification preference where user can move the magnification area by dragging one finger instead of two. [CHAR LIMIT=60] -->
|
||||||
|
<string name="accessibility_magnification_one_finger_panning_title">One-finger panning</string>
|
||||||
|
<!-- Summary for accessibility magnification preference when one finger panning feature is turned on.
|
||||||
|
The feature when enabled allows user to move the magnification area by dragging one finger instead of two. [CHAR LIMIT=60] -->
|
||||||
|
<string name="accessibility_magnification_one_finger_panning_summary_on">Move the magnification area by dragging one finger.</string>
|
||||||
|
<!-- Summary for accessibility magnification preference when one finger panning feature is turned off.
|
||||||
|
The feature when disabled, allows user to move the magnification area by dragging two fingers instead of one. [CHAR LIMIT=60] -->
|
||||||
|
<string name="accessibility_magnification_one_finger_panning_summary_off">Move the magnification area by dragging two fingers.</string>
|
||||||
<!-- Title for the accessibility preference screen to enable navigation bar screen magnification. [CHAR LIMIT=35] -->
|
<!-- Title for the accessibility preference screen to enable navigation bar screen magnification. [CHAR LIMIT=35] -->
|
||||||
<string name="accessibility_screen_magnification_navbar_title">Magnify with shortcut</string>
|
<string name="accessibility_screen_magnification_navbar_title">Magnify with shortcut</string>
|
||||||
<!-- Summary for the accessibility magnification setting indicating both "Magnify with button" and "Magnify with triple-tap" are enabled [CHAR LIMIT=50] -->
|
<!-- Summary for the accessibility magnification setting indicating both "Magnify with button" and "Magnify with triple-tap" are enabled [CHAR LIMIT=50] -->
|
||||||
|
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 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.accessibility;
|
||||||
|
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.preference.TwoStatePreference;
|
||||||
|
|
||||||
|
import com.android.server.accessibility.Flags;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
|
||||||
|
public class MagnificationOneFingerPanningPreferenceController
|
||||||
|
extends TogglePreferenceController {
|
||||||
|
static final String PREF_KEY = Settings.Secure.ACCESSIBILITY_SINGLE_FINGER_PANNING_ENABLED;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private TwoStatePreference mSwitchPreference;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
final boolean mDefaultValue;
|
||||||
|
|
||||||
|
public MagnificationOneFingerPanningPreferenceController(Context context) {
|
||||||
|
super(context, PREF_KEY);
|
||||||
|
boolean defaultValue;
|
||||||
|
try {
|
||||||
|
defaultValue = context.getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_enable_a11y_magnification_single_panning);
|
||||||
|
} catch (Resources.NotFoundException e) {
|
||||||
|
defaultValue = false;
|
||||||
|
}
|
||||||
|
mDefaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return (Flags.enableMagnificationOneFingerPanningGesture())
|
||||||
|
? AVAILABLE : DISABLED_FOR_USER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChecked() {
|
||||||
|
return Settings.Secure.getInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
PREF_KEY,
|
||||||
|
(mDefaultValue) ? ON : OFF) == ON;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setChecked(boolean isChecked) {
|
||||||
|
var toReturn = Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
PREF_KEY,
|
||||||
|
(isChecked ? ON : OFF));
|
||||||
|
if (mSwitchPreference != null) {
|
||||||
|
refreshSummary(mSwitchPreference);
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
return (isChecked())
|
||||||
|
? mContext.getString(
|
||||||
|
R.string.accessibility_magnification_one_finger_panning_summary_on)
|
||||||
|
: mContext.getString(
|
||||||
|
R.string.accessibility_magnification_one_finger_panning_summary_off);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSliceHighlightMenuRes() {
|
||||||
|
return R.string.menu_key_accessibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mSwitchPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
refreshSummary(mSwitchPreference);
|
||||||
|
}
|
||||||
|
}
|
@@ -200,6 +200,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
|
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
|
||||||
generalCategory.addPreference(mSettingsPreference);
|
generalCategory.addPreference(mSettingsPreference);
|
||||||
|
|
||||||
|
addOneFingerPanningSetting(generalCategory);
|
||||||
final MagnificationModePreferenceController magnificationModePreferenceController =
|
final MagnificationModePreferenceController magnificationModePreferenceController =
|
||||||
new MagnificationModePreferenceController(getContext(),
|
new MagnificationModePreferenceController(getContext(),
|
||||||
MagnificationModePreferenceController.PREF_KEY);
|
MagnificationModePreferenceController.PREF_KEY);
|
||||||
@@ -283,6 +284,24 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
|||||||
addPreferenceController(alwaysOnPreferenceController);
|
addPreferenceController(alwaysOnPreferenceController);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addOneFingerPanningSetting(PreferenceCategory generalCategory) {
|
||||||
|
if (!Flags.enableMagnificationOneFingerPanningGesture()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var oneFingerPanningPreference = new SwitchPreferenceCompat(getPrefContext());
|
||||||
|
oneFingerPanningPreference.setTitle(
|
||||||
|
R.string.accessibility_magnification_one_finger_panning_title);
|
||||||
|
oneFingerPanningPreference.setKey(
|
||||||
|
MagnificationOneFingerPanningPreferenceController.PREF_KEY);
|
||||||
|
generalCategory.addPreference(oneFingerPanningPreference);
|
||||||
|
|
||||||
|
var oneFingerPanningPreferenceController =
|
||||||
|
new MagnificationOneFingerPanningPreferenceController(getContext());
|
||||||
|
oneFingerPanningPreferenceController.displayPreference(getPreferenceScreen());
|
||||||
|
addPreferenceController(oneFingerPanningPreferenceController);
|
||||||
|
}
|
||||||
|
|
||||||
private void addJoystickSetting(PreferenceCategory generalCategory) {
|
private void addJoystickSetting(PreferenceCategory generalCategory) {
|
||||||
if (!DeviceConfig.getBoolean(
|
if (!DeviceConfig.getBoolean(
|
||||||
DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
||||||
|
@@ -0,0 +1,187 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 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.accessibility;
|
||||||
|
|
||||||
|
import static com.android.server.accessibility.Flags.enableMagnificationOneFingerPanningGesture;
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||||
|
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.server.accessibility.Flags;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class MagnificationOneFingerPanningPreferenceControllerTest {
|
||||||
|
private static final String ONE_FINGER_PANNING_KEY =
|
||||||
|
Settings.Secure.ACCESSIBILITY_SINGLE_FINGER_PANNING_ENABLED;
|
||||||
|
|
||||||
|
@Rule public final SetFlagsRule mSetFlagsRule =
|
||||||
|
new SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT);
|
||||||
|
|
||||||
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
private final SwitchPreference mSwitchPreference = spy(new SwitchPreference(mContext));
|
||||||
|
private final MagnificationOneFingerPanningPreferenceController mController =
|
||||||
|
new MagnificationOneFingerPanningPreferenceController(mContext);
|
||||||
|
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
||||||
|
mScreen = preferenceManager.createPreferenceScreen(mContext);
|
||||||
|
mSwitchPreference.setKey(MagnificationOneFingerPanningPreferenceController.PREF_KEY);
|
||||||
|
mScreen.addPreference(mSwitchPreference);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void cleanup() {
|
||||||
|
// Can't use resetToDefaults as it NPE with
|
||||||
|
// "Cannot invoke "android.content.IContentProvider.call"
|
||||||
|
Settings.Secure.putInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
MagnificationOneFingerPanningPreferenceController.PREF_KEY,
|
||||||
|
(mController.mDefaultValue) ? ON : OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_defaultState_correctSummarySet() {
|
||||||
|
assertThat(mSwitchPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getString(
|
||||||
|
R.string.accessibility_magnification_one_finger_panning_summary_off));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_defaultState_disabled() {
|
||||||
|
int status = mController.getAvailabilityStatus();
|
||||||
|
|
||||||
|
assertThat(status).isEqualTo(DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_featureFlagEnabled_enabled() {
|
||||||
|
enableFlag();
|
||||||
|
|
||||||
|
int status = mController.getAvailabilityStatus();
|
||||||
|
|
||||||
|
assertThat(status).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isChecked_defaultState_returnFalse() {
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
assertThat(mSwitchPreference.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isChecked_settingsEnabled_returnTrue() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(), ONE_FINGER_PANNING_KEY, ON);
|
||||||
|
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isChecked_settingsDisabled_returnTrue() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(), ONE_FINGER_PANNING_KEY, OFF);
|
||||||
|
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setChecked_enabled_enabledSummarySet() {
|
||||||
|
mController.setChecked(true);
|
||||||
|
|
||||||
|
assertThat(mSwitchPreference.getSummary()).isEqualTo(enabledSummary());
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setChecked_disabled_disabledSummarySet() {
|
||||||
|
mController.setChecked(false);
|
||||||
|
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
assertThat(mSwitchPreference.getSummary()).isEqualTo(disabledSummary());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_disable_disableSummaryTextUsed() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(), ONE_FINGER_PANNING_KEY, OFF);
|
||||||
|
|
||||||
|
var summary = mController.getSummary();
|
||||||
|
|
||||||
|
assertThat(summary).isEqualTo(disabledSummary());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_enable_enabledSummaryTextUsed() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(), ONE_FINGER_PANNING_KEY, ON);
|
||||||
|
|
||||||
|
var summary = mController.getSummary();
|
||||||
|
|
||||||
|
assertThat(summary).isEqualTo(enabledSummary());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void performClick_switchDefaultState_shouldReturnTrue() {
|
||||||
|
enableFlag();
|
||||||
|
|
||||||
|
mSwitchPreference.performClick();
|
||||||
|
|
||||||
|
verify(mSwitchPreference).setChecked(true);
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
assertThat(mSwitchPreference.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableFlag() {
|
||||||
|
mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_ONE_FINGER_PANNING_GESTURE);
|
||||||
|
assertThat(enableMagnificationOneFingerPanningGesture()).isTrue();
|
||||||
|
// This ensures that preference change listeners are added correctly.
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String enabledSummary() {
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.accessibility_magnification_one_finger_panning_summary_on);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String disabledSummary() {
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.accessibility_magnification_one_finger_panning_summary_off);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user