diff --git a/res/xml/language_and_input.xml b/res/xml/language_and_input.xml
index d7fad7ee9f5..747d1b4fc41 100644
--- a/res/xml/language_and_input.xml
+++ b/res/xml/language_and_input.xml
@@ -20,13 +20,13 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="language_and_input_settings_screen"
android:title="@string/language_settings"
- settings:initialExpandedChildrenCount="3" >
+ settings:initialExpandedChildrenCount="3">
+ android:fragment="com.android.settings.localepicker.LocaleListEditor" />
+ android:fragment="com.android.settings.inputmethod.VirtualKeyboardFragment" />
+ android:fragment="com.android.settings.inputmethod.PhysicalKeyboardFragment" />
+ android:fragment="com.android.settings.inputmethod.SpellCheckersSettings" />
+ android:title="@string/user_dict_settings_title" />
+ android:dialogTitle="@string/pointer_speed" />
+ android:fragment="com.android.settings.tts.TextToSpeechSettings" />
-
-
-
-
-
+
diff --git a/src/com/android/settings/inputmethod/GameControllerPreferenceController.java b/src/com/android/settings/inputmethod/GameControllerPreferenceController.java
index 2ff19e6df8c..21dbee9509a 100644
--- a/src/com/android/settings/inputmethod/GameControllerPreferenceController.java
+++ b/src/com/android/settings/inputmethod/GameControllerPreferenceController.java
@@ -26,31 +26,23 @@ import androidx.preference.PreferenceScreen;
import android.text.TextUtils;
import android.view.InputDevice;
-import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.R;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
-import java.util.List;
-
-public class GameControllerPreferenceController extends AbstractPreferenceController
+public class GameControllerPreferenceController extends TogglePreferenceController
implements PreferenceControllerMixin, InputManager.InputDeviceListener, LifecycleObserver,
OnResume, OnPause {
- @VisibleForTesting
- static final String PREF_KEY = "vibrate_input_devices";
- private static final String CATEGORY_KEY = "game_controller_settings_category";
-
private final InputManager mIm;
- private PreferenceScreen mScreen;
- private Preference mCategory;
private Preference mPreference;
- public GameControllerPreferenceController(Context context) {
- super(context);
+ public GameControllerPreferenceController(Context context, String key) {
+ super(context, key);
mIm = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
}
@@ -67,85 +59,61 @@ public class GameControllerPreferenceController extends AbstractPreferenceContro
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- mScreen = screen;
- mCategory = screen.findPreference(CATEGORY_KEY);
- mPreference = screen.findPreference(PREF_KEY);
+ mPreference = screen.findPreference(getPreferenceKey());
}
@Override
- public boolean isAvailable() {
+ @AvailabilityStatus
+ public int getAvailabilityStatus() {
// If device explicitly wants to hide this, return early.
if (!mContext.getResources().getBoolean(R.bool.config_show_vibrate_input_devices)) {
- return false;
+ return DISABLED_UNSUPPORTED;
}
final int[] devices = mIm.getInputDeviceIds();
for (int deviceId : devices) {
InputDevice device = mIm.getInputDevice(deviceId);
if (device != null && !device.isVirtual() && device.getVibrator().hasVibrator()) {
- return true;
+ return AVAILABLE;
}
}
- return false;
- }
-
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (TextUtils.equals(PREF_KEY, preference.getKey())) {
- Settings.System.putInt(mContext.getContentResolver(),
- Settings.System.VIBRATE_INPUT_DEVICES,
- ((SwitchPreference) preference).isChecked() ? 1 : 0);
- return true;
- }
- return false;
- }
-
- @Override
- public String getPreferenceKey() {
- return CATEGORY_KEY;
+ return DISABLED_UNSUPPORTED;
}
@Override
public void updateState(Preference preference) {
+ super.updateState(preference);
if (preference == null) {
return;
}
- ((SwitchPreference) preference).setChecked(Settings.System.getInt(
- mContext.getContentResolver(),
- Settings.System.VIBRATE_INPUT_DEVICES, 1) > 0);
+ mPreference.setVisible(isAvailable());
}
@Override
- public void updateNonIndexableKeys(List keys) {
- if (!isAvailable()) {
- keys.add(CATEGORY_KEY);
- keys.add(PREF_KEY);
- }
+ public boolean isChecked() {
+ return Settings.System.getInt(
+ mContext.getContentResolver(),
+ Settings.System.VIBRATE_INPUT_DEVICES, 1) > 0;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ return Settings.System.putInt(mContext.getContentResolver(),
+ Settings.System.VIBRATE_INPUT_DEVICES, isChecked ? 1 : 0);
}
@Override
public void onInputDeviceAdded(int deviceId) {
- updateGameControllers();
+ updateState(mPreference);
}
@Override
public void onInputDeviceRemoved(int deviceId) {
- updateGameControllers();
+ updateState(mPreference);
}
@Override
public void onInputDeviceChanged(int deviceId) {
- updateGameControllers();
- }
-
- private void updateGameControllers() {
- if (isAvailable()) {
- mScreen.addPreference(mCategory);
- updateState(mPreference);
- } else {
- if (mCategory != null) {
- mScreen.removePreference(mCategory);
- }
- }
+ updateState(mPreference);
}
}
diff --git a/src/com/android/settings/language/LanguageAndInputSettings.java b/src/com/android/settings/language/LanguageAndInputSettings.java
index 118259aab4b..efa0396c4d9 100644
--- a/src/com/android/settings/language/LanguageAndInputSettings.java
+++ b/src/com/android/settings/language/LanguageAndInputSettings.java
@@ -35,7 +35,6 @@ import com.android.settings.R;
import com.android.settings.applications.defaultapps.DefaultAutofillPreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.inputmethod.GameControllerPreferenceController;
import com.android.settings.inputmethod.PhysicalKeyboardPreferenceController;
import com.android.settings.inputmethod.SpellCheckerPreferenceController;
import com.android.settings.inputmethod.VirtualKeyboardPreferenceController;
@@ -126,17 +125,6 @@ public class LanguageAndInputSettings extends DashboardFragment {
controllers.add(new DefaultAutofillPreferenceController(context));
controllers.add(new UserDictionaryPreferenceController(context));
- // Game Controller
- final GameControllerPreferenceController gameControllerPreferenceController
- = new GameControllerPreferenceController(context);
- if (lifecycle != null) {
- lifecycle.addObserver(gameControllerPreferenceController);
- }
- controllers.add(gameControllerPreferenceController);
- controllers.add(new PreferenceCategoryController(context,
- KEY_GAME_CONTROLLER_CATEGORY).setChildren(
- Arrays.asList(gameControllerPreferenceController)));
-
return controllers;
}
diff --git a/tests/robotests/src/com/android/settings/inputmethod/GameControllerPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/GameControllerPreferenceControllerTest.java
index bc4eca80ca3..1b78cb253df 100644
--- a/tests/robotests/src/com/android/settings/inputmethod/GameControllerPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/inputmethod/GameControllerPreferenceControllerTest.java
@@ -16,6 +16,9 @@
package com.android.settings.inputmethod;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
+import static com.android.settings.core.BasePreferenceController.DISABLED_UNSUPPORTED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -37,10 +40,6 @@ import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
@RunWith(SettingsRobolectricTestRunner.class)
public class GameControllerPreferenceControllerTest {
@@ -57,7 +56,7 @@ public class GameControllerPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mInputManager);
- mController = new GameControllerPreferenceController(mContext);
+ mController = new GameControllerPreferenceController(mContext, "test_key");
}
@Test
@@ -75,59 +74,59 @@ public class GameControllerPreferenceControllerTest {
}
@Test
- public void testIsAvailable_hasDeviceWithVibrator_shouldReturnTrue() {
- when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{1});
+ public void getAvailabilityStatus_hasDeviceWithVibrator_shouldReturnAvailable() {
+ when(mInputManager.getInputDeviceIds()).thenReturn(new int[] {1});
when(mInputManager.getInputDevice(1)).thenReturn(mInputDevice);
when(mInputDevice.isVirtual()).thenReturn(false);
when(mInputDevice.getVibrator().hasVibrator()).thenReturn(true);
- assertThat(mController.isAvailable()).isTrue();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
- public void testIsAvailable_hasNoVibratingDevice_shouldReturnFalse() {
- when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{1});
+ public void getAvailabilityStatus_hasNoVibratingDevice_shouldReturnDisabled() {
+ when(mInputManager.getInputDeviceIds()).thenReturn(new int[] {1});
when(mInputManager.getInputDevice(1)).thenReturn(mInputDevice);
when(mInputDevice.isVirtual()).thenReturn(false);
when(mInputDevice.getVibrator().hasVibrator()).thenReturn(false);
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
}
@Test
- public void testIsAvailable_hasNoPhysicalDevice_shouldReturnFalse() {
- when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{1});
+ public void getAvailabilityStatus_hasNoPhysicalDevice_shouldReturnDisabled() {
+ when(mInputManager.getInputDeviceIds()).thenReturn(new int[] {1});
when(mInputManager.getInputDevice(1)).thenReturn(mInputDevice);
when(mInputDevice.isVirtual()).thenReturn(true);
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
}
@Test
- public void testIsAvailable_hasNoDevice_shouldReturnFalse() {
- when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{});
+ public void getAvailabilityStatus_hasNoDevice_shouldReturnDisabled() {
+ when(mInputManager.getInputDeviceIds()).thenReturn(new int[] {});
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
}
@Test
@Config(qualifiers = "mcc999")
- public void testIsAvailable_ifDisabled_shouldReturnFalse() {
- mController = new GameControllerPreferenceController(mContext);
+ public void getAvailabilityStatus_ifDisabled_shouldReturnDisabled() {
+ mController = new GameControllerPreferenceController(mContext, "testkey");
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
}
@Test
- public void updateNonIndexableKeys_shouldIncludeCategoryAndPrefKeys() {
- when(mInputManager.getInputDeviceIds()).thenReturn(new int[]{});
+ public void setChecked_toEnabled_shouldSetToSettingsProvider() {
+ mController.setChecked(true);
+ assertThat(mController.isChecked()).isTrue();
+ }
- final List nonIndexables = new ArrayList<>();
- mController.updateNonIndexableKeys(nonIndexables);
-
- assertThat(mController.isAvailable()).isFalse();
- assertThat(nonIndexables).containsExactlyElementsIn(Arrays.asList(
- GameControllerPreferenceController.PREF_KEY,
- mController.getPreferenceKey()));
+ @Test
+ public void setChecked_toDisabled_shouldSetToSettingsProvider() {
+ mController.setChecked(true);
+ mController.setChecked(false);
+ assertThat(mController.isChecked()).isFalse();
}
}