Merge "Separate long press timeout preference controller form accessibility"
This commit is contained in:
committed by
Android (Google) Code Review
commit
79cf1bb06c
@@ -114,7 +114,8 @@
|
|||||||
android:title="@string/accessibility_long_press_timeout_preference_title"
|
android:title="@string/accessibility_long_press_timeout_preference_title"
|
||||||
android:entries="@array/long_press_timeout_selector_titles"
|
android:entries="@array/long_press_timeout_selector_titles"
|
||||||
android:entryValues="@array/long_press_timeout_selector_values"
|
android:entryValues="@array/long_press_timeout_selector_values"
|
||||||
android:persistent="false"/>
|
android:persistent="false"
|
||||||
|
settings:controller="com.android.settings.accessibility.SelectLongPressTimeoutPreferenceController"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="accessibility_control_timeout_preference_fragment"
|
android:key="accessibility_control_timeout_preference_fragment"
|
||||||
|
@@ -40,7 +40,6 @@ import android.view.accessibility.AccessibilityManager;
|
|||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.preference.ListPreference;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -61,7 +60,6 @@ import com.android.settingslib.search.SearchIndexable;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -70,8 +68,7 @@ import java.util.Set;
|
|||||||
* Activity with the accessibility settings.
|
* Activity with the accessibility settings.
|
||||||
*/
|
*/
|
||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
public class AccessibilitySettings extends DashboardFragment implements
|
public class AccessibilitySettings extends DashboardFragment {
|
||||||
Preference.OnPreferenceChangeListener {
|
|
||||||
|
|
||||||
private static final String TAG = "AccessibilitySettings";
|
private static final String TAG = "AccessibilitySettings";
|
||||||
|
|
||||||
@@ -97,8 +94,6 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
private static final String TOGGLE_LARGE_POINTER_ICON =
|
private static final String TOGGLE_LARGE_POINTER_ICON =
|
||||||
"toggle_large_pointer_icon";
|
"toggle_large_pointer_icon";
|
||||||
private static final String TOGGLE_DISABLE_ANIMATIONS = "toggle_disable_animations";
|
private static final String TOGGLE_DISABLE_ANIMATIONS = "toggle_disable_animations";
|
||||||
private static final String SELECT_LONG_PRESS_TIMEOUT_PREFERENCE =
|
|
||||||
"select_long_press_timeout_preference";
|
|
||||||
private static final String HEARING_AID_PREFERENCE =
|
private static final String HEARING_AID_PREFERENCE =
|
||||||
"hearing_aid_preference";
|
"hearing_aid_preference";
|
||||||
private static final String DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN =
|
private static final String DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN =
|
||||||
@@ -133,8 +128,6 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
|
|
||||||
static final String RAMPING_RINGER_ENABLED = "ramping_ringer_enabled";
|
static final String RAMPING_RINGER_ENABLED = "ramping_ringer_enabled";
|
||||||
|
|
||||||
private final Map<String, String> mLongPressTimeoutValueToTitleMap = new HashMap<>();
|
|
||||||
|
|
||||||
private final Handler mHandler = new Handler();
|
private final Handler mHandler = new Handler();
|
||||||
|
|
||||||
private final Runnable mUpdateRunnable = new Runnable() {
|
private final Runnable mUpdateRunnable = new Runnable() {
|
||||||
@@ -183,7 +176,6 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
|
|
||||||
private SwitchPreference mToggleLargePointerIconPreference;
|
private SwitchPreference mToggleLargePointerIconPreference;
|
||||||
private SwitchPreference mToggleDisableAnimationsPreference;
|
private SwitchPreference mToggleDisableAnimationsPreference;
|
||||||
private ListPreference mSelectLongPressTimeoutPreference;
|
|
||||||
private Preference mDisplayMagnificationPreferenceScreen;
|
private Preference mDisplayMagnificationPreferenceScreen;
|
||||||
private Preference mDisplayDaltonizerPreferenceScreen;
|
private Preference mDisplayDaltonizerPreferenceScreen;
|
||||||
private Preference mHearingAidPreference;
|
private Preference mHearingAidPreference;
|
||||||
@@ -194,8 +186,6 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
private DarkUIPreferenceController mDarkUIPreferenceController;
|
private DarkUIPreferenceController mDarkUIPreferenceController;
|
||||||
private LiveCaptionPreferenceController mLiveCaptionPreferenceController;
|
private LiveCaptionPreferenceController mLiveCaptionPreferenceController;
|
||||||
|
|
||||||
private int mLongPressTimeoutDefault;
|
|
||||||
|
|
||||||
private DevicePolicyManager mDpm;
|
private DevicePolicyManager mDpm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -271,22 +261,6 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
if (mSelectLongPressTimeoutPreference == preference) {
|
|
||||||
handleLongPressTimeoutPreferenceChange((String) newValue);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleLongPressTimeoutPreferenceChange(String stringValue) {
|
|
||||||
Settings.Secure.putInt(getContentResolver(),
|
|
||||||
Settings.Secure.LONG_PRESS_TIMEOUT, Integer.parseInt(stringValue));
|
|
||||||
mSelectLongPressTimeoutPreference.setSummary(
|
|
||||||
mLongPressTimeoutValueToTitleMap.get(stringValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(Preference preference) {
|
public boolean onPreferenceTreeClick(Preference preference) {
|
||||||
if (mHearingAidPreferenceController.handlePreferenceTreeClick(preference)) {
|
if (mHearingAidPreferenceController.handlePreferenceTreeClick(preference)) {
|
||||||
@@ -344,22 +318,6 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
mToggleDisableAnimationsPreference =
|
mToggleDisableAnimationsPreference =
|
||||||
(SwitchPreference) findPreference(TOGGLE_DISABLE_ANIMATIONS);
|
(SwitchPreference) findPreference(TOGGLE_DISABLE_ANIMATIONS);
|
||||||
|
|
||||||
// Long press timeout.
|
|
||||||
mSelectLongPressTimeoutPreference =
|
|
||||||
(ListPreference) findPreference(SELECT_LONG_PRESS_TIMEOUT_PREFERENCE);
|
|
||||||
mSelectLongPressTimeoutPreference.setOnPreferenceChangeListener(this);
|
|
||||||
if (mLongPressTimeoutValueToTitleMap.size() == 0) {
|
|
||||||
String[] timeoutValues = getResources().getStringArray(
|
|
||||||
R.array.long_press_timeout_selector_values);
|
|
||||||
mLongPressTimeoutDefault = Integer.parseInt(timeoutValues[0]);
|
|
||||||
String[] timeoutTitles = getResources().getStringArray(
|
|
||||||
R.array.long_press_timeout_selector_titles);
|
|
||||||
final int timeoutValueCount = timeoutValues.length;
|
|
||||||
for (int i = 0; i < timeoutValueCount; i++) {
|
|
||||||
mLongPressTimeoutValueToTitleMap.put(timeoutValues[i], timeoutTitles[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hearing Aid.
|
// Hearing Aid.
|
||||||
mHearingAidPreference = findPreference(HEARING_AID_PREFERENCE);
|
mHearingAidPreference = findPreference(HEARING_AID_PREFERENCE);
|
||||||
mHearingAidPreferenceController.displayPreference(getPreferenceScreen());
|
mHearingAidPreferenceController.displayPreference(getPreferenceScreen());
|
||||||
@@ -590,13 +548,6 @@ public class AccessibilitySettings extends DashboardFragment implements
|
|||||||
// Dark Mode
|
// Dark Mode
|
||||||
mDarkUIPreferenceController.updateState(mDarkUIModePreference);
|
mDarkUIPreferenceController.updateState(mDarkUIModePreference);
|
||||||
|
|
||||||
// Long press timeout.
|
|
||||||
final int longPressTimeout = Settings.Secure.getInt(getContentResolver(),
|
|
||||||
Settings.Secure.LONG_PRESS_TIMEOUT, mLongPressTimeoutDefault);
|
|
||||||
String value = String.valueOf(longPressTimeout);
|
|
||||||
mSelectLongPressTimeoutPreference.setValue(value);
|
|
||||||
mSelectLongPressTimeoutPreference.setSummary(mLongPressTimeoutValueToTitleMap.get(value));
|
|
||||||
|
|
||||||
mHearingAidPreferenceController.updateState(mHearingAidPreference);
|
mHearingAidPreferenceController.updateState(mHearingAidPreference);
|
||||||
|
|
||||||
mLiveCaptionPreferenceController.updateState(mLiveCaptionPreference);
|
mLiveCaptionPreferenceController.updateState(mLiveCaptionPreference);
|
||||||
|
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.ListPreference;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SelectLongPressTimeoutPreferenceController extends BasePreferenceController implements
|
||||||
|
Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
|
private final Map<String, String> mLongPressTimeoutValueToTitleMap;
|
||||||
|
private int mLongPressTimeoutDefault;
|
||||||
|
|
||||||
|
public SelectLongPressTimeoutPreferenceController(Context context, String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mLongPressTimeoutValueToTitleMap = new HashMap<>();
|
||||||
|
initLongPressTimeoutValueToTitleMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object object) {
|
||||||
|
if (!(preference instanceof ListPreference)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final ListPreference listPreference = (ListPreference) preference;
|
||||||
|
final int newValue = Integer.parseInt((String) object);
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.LONG_PRESS_TIMEOUT, newValue);
|
||||||
|
updateState(listPreference);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
if (!(preference instanceof ListPreference)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ListPreference listPreference = (ListPreference) preference;
|
||||||
|
listPreference.setValue(getLongPressTimeoutValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
return mLongPressTimeoutValueToTitleMap.get(getLongPressTimeoutValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLongPressTimeoutValue() {
|
||||||
|
final int longPressTimeout = Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.LONG_PRESS_TIMEOUT, mLongPressTimeoutDefault);
|
||||||
|
return String.valueOf(longPressTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initLongPressTimeoutValueToTitleMap() {
|
||||||
|
if (mLongPressTimeoutValueToTitleMap.size() == 0) {
|
||||||
|
final String[] timeoutValues = mContext.getResources().getStringArray(
|
||||||
|
R.array.long_press_timeout_selector_values);
|
||||||
|
mLongPressTimeoutDefault = Integer.parseInt(timeoutValues[0]);
|
||||||
|
final String[] timeoutTitles = mContext.getResources().getStringArray(
|
||||||
|
R.array.long_press_timeout_selector_titles);
|
||||||
|
final int timeoutValueCount = timeoutValues.length;
|
||||||
|
for (int i = 0; i < timeoutValueCount; i++) {
|
||||||
|
mLongPressTimeoutValueToTitleMap.put(timeoutValues[i], timeoutTitles[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class SelectLongPressTimeoutPreferenceControllerTest {
|
||||||
|
private static final int VALID_VALUE = 1500;
|
||||||
|
private static final int INVALID_VALUE = 0;
|
||||||
|
private static final int DEFAULT_VALUE = 400;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private SelectLongPressTimeoutPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mController = new SelectLongPressTimeoutPreferenceController(mContext, "press_timeout");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_byDefault_shouldReturnAvailable() {
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_byDefault_shouldReturnShort() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.LONG_PRESS_TIMEOUT, DEFAULT_VALUE);
|
||||||
|
final String expected = "Short";
|
||||||
|
|
||||||
|
assertThat(mController.getSummary()).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_validValue_shouldReturnLong() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.LONG_PRESS_TIMEOUT, VALID_VALUE);
|
||||||
|
final String expected = "Long";
|
||||||
|
|
||||||
|
assertThat(mController.getSummary()).isEqualTo(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSummary_invalidValue_shouldReturnNull() {
|
||||||
|
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.LONG_PRESS_TIMEOUT, INVALID_VALUE);
|
||||||
|
|
||||||
|
assertThat(mController.getSummary()).isNull();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user