Merge "Fix assist gesture settings summary" into oc-dr1-dev

am: 63e36128e6

Change-Id: I05d1d9129892ebf1049f771ebc2404bafee4d60a
This commit is contained in:
Kevin Chyn
2017-06-27 03:34:30 +00:00
committed by android-build-merger
6 changed files with 87 additions and 24 deletions

View File

@@ -72,7 +72,8 @@ public class ManageAssist extends DashboardFragment {
Lifecycle lifecycle) {
final List<PreferenceController> 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));

View File

@@ -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;
@@ -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() {
return mFeatureProvider.isSupported(mContext);
if (mAssistOnly) {
return mFeatureProvider.isSupported(mContext);
} else {
return mFeatureProvider.isSensorAvailable(mContext);
}
}
@Override
@@ -87,7 +99,7 @@ public class AssistGesturePreferenceController extends GesturePreferenceControll
return;
}
if (isAvailable()) {
if (mFeatureProvider.isSupported(mContext)) {
if (mScreen.findPreference(getPreferenceKey()) == null) {
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
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enabled = (boolean) newValue;

View File

@@ -60,7 +60,8 @@ public class AssistGestureSettings extends DashboardFragment {
private static List<PreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
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()
.getControllers(context, lifecycle));

View File

@@ -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;
@@ -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));
@@ -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)

View File

@@ -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;
@@ -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 {
@@ -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();
}
@@ -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();
}
@@ -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();
}

View File

@@ -163,18 +163,29 @@ public class LanguageAndInputSettingsTest {
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
when(featureFactory.assistGestureFeatureProvider.isSupported(any(Context.class)))
.thenReturn(true);
when(featureFactory.assistGestureFeatureProvider.isSensorAvailable(any(Context.class)))
.thenReturn(true);
final SummaryLoader loader = mock(SummaryLoader.class);
SummaryLoader.SummaryProvider provider = mFragment.SUMMARY_PROVIDER_FACTORY
.createSummaryProvider(mActivity, loader);
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_ENABLED, 0);
ShadowSecureSettings.putInt(null, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 0);
provider.setListening(true);
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_SILENCE_ALERTS_ENABLED, 0);
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