Loading src/com/android/settings/applications/assist/ManageAssist.java +2 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,8 @@ public class ManageAssist extends DashboardFragment { Lifecycle lifecycle) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new DefaultAssistPreferenceController(context)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, true /* assistOnly */)); controllers.add(new AssistContextPreferenceController(context, lifecycle)); controllers.add(new AssistScreenshotPreferenceController(context, lifecycle)); controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle)); Loading src/com/android/settings/gestures/AssistGesturePreferenceController.java +37 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,10 @@ import android.net.Uri; import android.provider.Settings; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.TwoStatePreference; import com.android.internal.annotations.VisibleForTesting; import com.android.settings.R; import com.android.settings.applications.assist.AssistSettingObserver; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.core.lifecycle.Lifecycle; Loading @@ -44,17 +47,26 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll private PreferenceScreen mScreen; private Preference mPreference; public AssistGesturePreferenceController(Context context, Lifecycle lifecycle, String key) { @VisibleForTesting boolean mAssistOnly; public AssistGesturePreferenceController(Context context, Lifecycle lifecycle, String key, boolean assistOnly) { super(context, lifecycle); mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider(); mSettingObserver = new SettingObserver(); mWasAvailable = isAvailable(); mAssistGesturePrefKey = key; mAssistOnly = assistOnly; } @Override public boolean isAvailable() { if (mAssistOnly) { return mFeatureProvider.isSupported(mContext); } else { return mFeatureProvider.isSensorAvailable(mContext); } } @Override Loading Loading @@ -87,7 +99,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll return; } if (isAvailable()) { if (mFeatureProvider.isSupported(mContext)) { if (mScreen.findPreference(getPreferenceKey()) == null) { mScreen.addPreference(mPreference); } Loading @@ -96,6 +108,28 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll } } @Override public void updateState(Preference preference) { boolean isEnabled = isSwitchPrefEnabled(); if (!mAssistOnly) { boolean assistGestureSilenceEnabled = Settings.Secure.getInt( mContext.getContentResolver(), Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0; isEnabled = isEnabled || assistGestureSilenceEnabled; } if (preference != null) { if (preference instanceof TwoStatePreference) { ((TwoStatePreference) preference).setChecked(isSwitchPrefEnabled()); } else { preference.setSummary(isEnabled ? R.string.gesture_setting_on : R.string.gesture_setting_off); } } } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean enabled = (boolean) newValue; Loading src/com/android/settings/gestures/AssistGestureSettings.java +2 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,8 @@ public class AssistGestureSettings extends DashboardFragment { private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, Lifecycle lifecycle) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.addAll(FeatureFactory.getFactory(context).getAssistGestureFeatureProvider() .getControllers(context, lifecycle)); Loading src/com/android/settings/language/LanguageAndInputSettings.java +22 −8 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.language; import android.app.Activity; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManager; import android.os.UserHandle; Loading Loading @@ -137,7 +138,8 @@ public class LanguageAndInputSettings extends DashboardFragment { controllers.add(gameControllerPreferenceController); // Gestures controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle, KEY_SWIPE_DOWN)); controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST)); Loading Loading @@ -172,16 +174,28 @@ public class LanguageAndInputSettings extends DashboardFragment { @Override public void setListening(boolean listening) { final ContentResolver contentResolver = mContext.getContentResolver(); if (listening) { if (mFeatureProvider.isSupported(mContext)) { final int assistGestureEnabled = Settings.Secure.getInt( mContext.getContentResolver(), Settings.Secure.ASSIST_GESTURE_ENABLED, 1); mSummaryLoader.setSummary(this, mContext.getString(assistGestureEnabled == 0 ? R.string.language_input_gesture_summary_off : R.string.language_input_gesture_summary_on_with_assist)); if (mFeatureProvider.isSensorAvailable(mContext)) { final boolean assistGestureEnabled = Settings.Secure.getInt( contentResolver, Settings.Secure.ASSIST_GESTURE_ENABLED, 1) != 0; final boolean assistGestureSilenceEnabled = Settings.Secure.getInt( contentResolver, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0; String summary; if (mFeatureProvider.isSupported(mContext) && assistGestureEnabled) { summary = mContext.getString( R.string.language_input_gesture_summary_on_with_assist); } else if (assistGestureSilenceEnabled) { summary = mContext.getString( R.string.language_input_gesture_summary_on_non_assist); } else { summary = mContext.getString(R.string.language_input_gesture_summary_off); } mSummaryLoader.setSummary(this, summary); } else { final String flattenComponent = Settings.Secure.getString( mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD); if (!TextUtils.isEmpty(flattenComponent)) { final PackageManager packageManage = mContext.getPackageManager(); final String pkg = ComponentName.unflattenFromString(flattenComponent) Loading tests/robotests/src/com/android/settings/gestures/AssistGesturePreferenceControllerTest.java +12 −10 Original line number Diff line number Diff line Loading @@ -16,12 +16,18 @@ package com.android.settings.gestures; import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; import android.content.Context; import android.provider.Settings; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; import org.junit.Test; Loading @@ -32,11 +38,6 @@ import org.mockito.MockitoAnnotations; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) public class AssistGesturePreferenceControllerTest { Loading @@ -53,12 +54,13 @@ public class AssistGesturePreferenceControllerTest { MockitoAnnotations.initMocks(this); FakeFeatureFactory.setupForTest(mContext); mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST); mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST, false); } @Test public void isAvailable_whenSupported_shouldReturnTrue() { when(mFactory.assistGestureFeatureProvider.isSupported(mContext)).thenReturn(true); mController.mAssistOnly = false; when(mFactory.assistGestureFeatureProvider.isSensorAvailable(mContext)).thenReturn(true); assertThat(mController.isAvailable()).isTrue(); } Loading @@ -73,7 +75,7 @@ public class AssistGesturePreferenceControllerTest { // Set the setting to be enabled. final Context context = ShadowApplication.getInstance().getApplicationContext(); Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 1); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false); assertThat(mController.isSwitchPrefEnabled()).isTrue(); } Loading @@ -83,7 +85,7 @@ public class AssistGesturePreferenceControllerTest { // Set the setting to be disabled. final Context context = ShadowApplication.getInstance().getApplicationContext(); Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 0); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false); assertThat(mController.isSwitchPrefEnabled()).isFalse(); } Loading Loading
src/com/android/settings/applications/assist/ManageAssist.java +2 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,8 @@ public class ManageAssist extends DashboardFragment { Lifecycle lifecycle) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new DefaultAssistPreferenceController(context)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, true /* assistOnly */)); controllers.add(new AssistContextPreferenceController(context, lifecycle)); controllers.add(new AssistScreenshotPreferenceController(context, lifecycle)); controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle)); Loading
src/com/android/settings/gestures/AssistGesturePreferenceController.java +37 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,10 @@ import android.net.Uri; import android.provider.Settings; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.TwoStatePreference; import com.android.internal.annotations.VisibleForTesting; import com.android.settings.R; import com.android.settings.applications.assist.AssistSettingObserver; import com.android.settings.overlay.FeatureFactory; import com.android.settingslib.core.lifecycle.Lifecycle; Loading @@ -44,17 +47,26 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll private PreferenceScreen mScreen; private Preference mPreference; public AssistGesturePreferenceController(Context context, Lifecycle lifecycle, String key) { @VisibleForTesting boolean mAssistOnly; public AssistGesturePreferenceController(Context context, Lifecycle lifecycle, String key, boolean assistOnly) { super(context, lifecycle); mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider(); mSettingObserver = new SettingObserver(); mWasAvailable = isAvailable(); mAssistGesturePrefKey = key; mAssistOnly = assistOnly; } @Override public boolean isAvailable() { if (mAssistOnly) { return mFeatureProvider.isSupported(mContext); } else { return mFeatureProvider.isSensorAvailable(mContext); } } @Override Loading Loading @@ -87,7 +99,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll return; } if (isAvailable()) { if (mFeatureProvider.isSupported(mContext)) { if (mScreen.findPreference(getPreferenceKey()) == null) { mScreen.addPreference(mPreference); } Loading @@ -96,6 +108,28 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll } } @Override public void updateState(Preference preference) { boolean isEnabled = isSwitchPrefEnabled(); if (!mAssistOnly) { boolean assistGestureSilenceEnabled = Settings.Secure.getInt( mContext.getContentResolver(), Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0; isEnabled = isEnabled || assistGestureSilenceEnabled; } if (preference != null) { if (preference instanceof TwoStatePreference) { ((TwoStatePreference) preference).setChecked(isSwitchPrefEnabled()); } else { preference.setSummary(isEnabled ? R.string.gesture_setting_on : R.string.gesture_setting_off); } } } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean enabled = (boolean) newValue; Loading
src/com/android/settings/gestures/AssistGestureSettings.java +2 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,8 @@ public class AssistGestureSettings extends DashboardFragment { private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, Lifecycle lifecycle) { final List<AbstractPreferenceController> controllers = new ArrayList<>(); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.addAll(FeatureFactory.getFactory(context).getAssistGestureFeatureProvider() .getControllers(context, lifecycle)); Loading
src/com/android/settings/language/LanguageAndInputSettings.java +22 −8 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.language; import android.app.Activity; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.pm.PackageManager; import android.os.UserHandle; Loading Loading @@ -137,7 +138,8 @@ public class LanguageAndInputSettings extends DashboardFragment { controllers.add(gameControllerPreferenceController); // Gestures controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST)); controllers.add(new AssistGesturePreferenceController(context, lifecycle, KEY_ASSIST, false /* assistOnly */)); controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle, KEY_SWIPE_DOWN)); controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST)); Loading Loading @@ -172,16 +174,28 @@ public class LanguageAndInputSettings extends DashboardFragment { @Override public void setListening(boolean listening) { final ContentResolver contentResolver = mContext.getContentResolver(); if (listening) { if (mFeatureProvider.isSupported(mContext)) { final int assistGestureEnabled = Settings.Secure.getInt( mContext.getContentResolver(), Settings.Secure.ASSIST_GESTURE_ENABLED, 1); mSummaryLoader.setSummary(this, mContext.getString(assistGestureEnabled == 0 ? R.string.language_input_gesture_summary_off : R.string.language_input_gesture_summary_on_with_assist)); if (mFeatureProvider.isSensorAvailable(mContext)) { final boolean assistGestureEnabled = Settings.Secure.getInt( contentResolver, Settings.Secure.ASSIST_GESTURE_ENABLED, 1) != 0; final boolean assistGestureSilenceEnabled = Settings.Secure.getInt( contentResolver, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0; String summary; if (mFeatureProvider.isSupported(mContext) && assistGestureEnabled) { summary = mContext.getString( R.string.language_input_gesture_summary_on_with_assist); } else if (assistGestureSilenceEnabled) { summary = mContext.getString( R.string.language_input_gesture_summary_on_non_assist); } else { summary = mContext.getString(R.string.language_input_gesture_summary_off); } mSummaryLoader.setSummary(this, summary); } else { final String flattenComponent = Settings.Secure.getString( mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD); if (!TextUtils.isEmpty(flattenComponent)) { final PackageManager packageManage = mContext.getPackageManager(); final String pkg = ComponentName.unflattenFromString(flattenComponent) Loading
tests/robotests/src/com/android/settings/gestures/AssistGesturePreferenceControllerTest.java +12 −10 Original line number Diff line number Diff line Loading @@ -16,12 +16,18 @@ package com.android.settings.gestures; import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; import android.content.Context; import android.provider.Settings; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.SettingsRobolectricTestRunner; import org.junit.Before; import org.junit.Test; Loading @@ -32,11 +38,6 @@ import org.mockito.MockitoAnnotations; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; import static android.provider.Settings.Secure.ASSIST_GESTURE_ENABLED; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @RunWith(SettingsRobolectricTestRunner.class) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) public class AssistGesturePreferenceControllerTest { Loading @@ -53,12 +54,13 @@ public class AssistGesturePreferenceControllerTest { MockitoAnnotations.initMocks(this); FakeFeatureFactory.setupForTest(mContext); mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST); mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST, false); } @Test public void isAvailable_whenSupported_shouldReturnTrue() { when(mFactory.assistGestureFeatureProvider.isSupported(mContext)).thenReturn(true); mController.mAssistOnly = false; when(mFactory.assistGestureFeatureProvider.isSensorAvailable(mContext)).thenReturn(true); assertThat(mController.isAvailable()).isTrue(); } Loading @@ -73,7 +75,7 @@ public class AssistGesturePreferenceControllerTest { // Set the setting to be enabled. final Context context = ShadowApplication.getInstance().getApplicationContext(); Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 1); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false); assertThat(mController.isSwitchPrefEnabled()).isTrue(); } Loading @@ -83,7 +85,7 @@ public class AssistGesturePreferenceControllerTest { // Set the setting to be disabled. final Context context = ShadowApplication.getInstance().getApplicationContext(); Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 0); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST); mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST, false); assertThat(mController.isSwitchPrefEnabled()).isFalse(); } Loading