Merge "Fix assist gesture settings summary" into oc-dr1-dev
am: 63e36128e6
Change-Id: I05d1d9129892ebf1049f771ebc2404bafee4d60a
This commit is contained in:
@@ -72,7 +72,8 @@ public class ManageAssist extends DashboardFragment {
|
|||||||
Lifecycle lifecycle) {
|
Lifecycle lifecycle) {
|
||||||
final List<PreferenceController> controllers = new ArrayList<>();
|
final List<PreferenceController> controllers = new ArrayList<>();
|
||||||
controllers.add(new DefaultAssistPreferenceController(context));
|
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 AssistContextPreferenceController(context, lifecycle));
|
||||||
controllers.add(new AssistScreenshotPreferenceController(context, lifecycle));
|
controllers.add(new AssistScreenshotPreferenceController(context, lifecycle));
|
||||||
controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle));
|
controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle));
|
||||||
|
@@ -21,7 +21,10 @@ import android.net.Uri;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
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.applications.assist.AssistSettingObserver;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
@@ -44,17 +47,26 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll
|
|||||||
private PreferenceScreen mScreen;
|
private PreferenceScreen mScreen;
|
||||||
private Preference mPreference;
|
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);
|
super(context, lifecycle);
|
||||||
mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
|
mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
|
||||||
mSettingObserver = new SettingObserver();
|
mSettingObserver = new SettingObserver();
|
||||||
mWasAvailable = isAvailable();
|
mWasAvailable = isAvailable();
|
||||||
mAssistGesturePrefKey = key;
|
mAssistGesturePrefKey = key;
|
||||||
|
mAssistOnly = assistOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return mFeatureProvider.isSupported(mContext);
|
if (mAssistOnly) {
|
||||||
|
return mFeatureProvider.isSupported(mContext);
|
||||||
|
} else {
|
||||||
|
return mFeatureProvider.isSensorAvailable(mContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,7 +99,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAvailable()) {
|
if (mFeatureProvider.isSupported(mContext)) {
|
||||||
if (mScreen.findPreference(getPreferenceKey()) == null) {
|
if (mScreen.findPreference(getPreferenceKey()) == null) {
|
||||||
mScreen.addPreference(mPreference);
|
mScreen.addPreference(mPreference);
|
||||||
}
|
}
|
||||||
@@ -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
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final boolean enabled = (boolean) newValue;
|
final boolean enabled = (boolean) newValue;
|
||||||
|
@@ -60,7 +60,8 @@ public class AssistGestureSettings extends DashboardFragment {
|
|||||||
private static List<PreferenceController> buildPreferenceControllers(Context context,
|
private static List<PreferenceController> buildPreferenceControllers(Context context,
|
||||||
Lifecycle lifecycle) {
|
Lifecycle lifecycle) {
|
||||||
final List<PreferenceController> controllers = new ArrayList<>();
|
final List<PreferenceController> 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()
|
controllers.addAll(FeatureFactory.getFactory(context).getAssistGestureFeatureProvider()
|
||||||
.getControllers(context, lifecycle));
|
.getControllers(context, lifecycle));
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.language;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -137,7 +138,8 @@ public class LanguageAndInputSettings extends DashboardFragment {
|
|||||||
|
|
||||||
controllers.add(gameControllerPreferenceController);
|
controllers.add(gameControllerPreferenceController);
|
||||||
// Gestures
|
// 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,
|
controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle,
|
||||||
KEY_SWIPE_DOWN));
|
KEY_SWIPE_DOWN));
|
||||||
controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST));
|
controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST));
|
||||||
@@ -172,16 +174,28 @@ public class LanguageAndInputSettings extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setListening(boolean listening) {
|
public void setListening(boolean listening) {
|
||||||
|
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||||
if (listening) {
|
if (listening) {
|
||||||
if (mFeatureProvider.isSupported(mContext)) {
|
if (mFeatureProvider.isSensorAvailable(mContext)) {
|
||||||
final int assistGestureEnabled = Settings.Secure.getInt(
|
final boolean assistGestureEnabled = Settings.Secure.getInt(
|
||||||
mContext.getContentResolver(), Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
|
contentResolver, Settings.Secure.ASSIST_GESTURE_ENABLED, 1) != 0;
|
||||||
mSummaryLoader.setSummary(this, mContext.getString(assistGestureEnabled == 0
|
final boolean assistGestureSilenceEnabled = Settings.Secure.getInt(
|
||||||
? R.string.language_input_gesture_summary_off
|
contentResolver, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED,
|
||||||
: R.string.language_input_gesture_summary_on_with_assist));
|
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 {
|
} else {
|
||||||
final String flattenComponent = Settings.Secure.getString(
|
final String flattenComponent = Settings.Secure.getString(
|
||||||
mContext.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
contentResolver, Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||||
if (!TextUtils.isEmpty(flattenComponent)) {
|
if (!TextUtils.isEmpty(flattenComponent)) {
|
||||||
final PackageManager packageManage = mContext.getPackageManager();
|
final PackageManager packageManage = mContext.getPackageManager();
|
||||||
final String pkg = ComponentName.unflattenFromString(flattenComponent)
|
final String pkg = ComponentName.unflattenFromString(flattenComponent)
|
||||||
|
@@ -16,12 +16,18 @@
|
|||||||
|
|
||||||
package com.android.settings.gestures;
|
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.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -32,11 +38,6 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
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)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class AssistGesturePreferenceControllerTest {
|
public class AssistGesturePreferenceControllerTest {
|
||||||
@@ -53,12 +54,13 @@ public class AssistGesturePreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
FakeFeatureFactory.setupForTest(mContext);
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||||
mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST);
|
mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isAvailable_whenSupported_shouldReturnTrue() {
|
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();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +75,7 @@ public class AssistGesturePreferenceControllerTest {
|
|||||||
// Set the setting to be enabled.
|
// Set the setting to be enabled.
|
||||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||||
Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 1);
|
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();
|
assertThat(mController.isSwitchPrefEnabled()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -83,7 +85,7 @@ public class AssistGesturePreferenceControllerTest {
|
|||||||
// Set the setting to be disabled.
|
// Set the setting to be disabled.
|
||||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||||
Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 0);
|
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();
|
assertThat(mController.isSwitchPrefEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
@@ -163,18 +163,29 @@ public class LanguageAndInputSettingsTest {
|
|||||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
|
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
|
||||||
when(featureFactory.assistGestureFeatureProvider.isSupported(any(Context.class)))
|
when(featureFactory.assistGestureFeatureProvider.isSupported(any(Context.class)))
|
||||||
.thenReturn(true);
|
.thenReturn(true);
|
||||||
|
when(featureFactory.assistGestureFeatureProvider.isSensorAvailable(any(Context.class)))
|
||||||
|
.thenReturn(true);
|
||||||
|
|
||||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||||
SummaryLoader.SummaryProvider provider = mFragment.SUMMARY_PROVIDER_FACTORY
|
SummaryLoader.SummaryProvider provider = mFragment.SUMMARY_PROVIDER_FACTORY
|
||||||
.createSummaryProvider(mActivity, loader);
|
.createSummaryProvider(mActivity, loader);
|
||||||
|
|
||||||
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
|
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
|
||||||
|
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 0);
|
||||||
provider.setListening(true);
|
provider.setListening(true);
|
||||||
verify(mActivity).getString(R.string.language_input_gesture_summary_off);
|
verify(mActivity).getString(R.string.language_input_gesture_summary_off);
|
||||||
|
|
||||||
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
|
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_ENABLED, 1);
|
||||||
|
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 0);
|
||||||
provider.setListening(true);
|
provider.setListening(true);
|
||||||
verify(mActivity).getString(R.string.language_input_gesture_summary_on_with_assist);
|
verify(mActivity).getString(
|
||||||
|
R.string.language_input_gesture_summary_on_with_assist);
|
||||||
|
|
||||||
|
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
|
||||||
|
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1);
|
||||||
|
provider.setListening(true);
|
||||||
|
verify(mActivity).getString(
|
||||||
|
R.string.language_input_gesture_summary_on_non_assist);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user