Merge "Fix assist gesture settings summary"

This commit is contained in:
TreeHugger Robot
2017-06-27 01:22:13 +00:00
committed by Android (Google) Code Review
6 changed files with 84 additions and 23 deletions

View File

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

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

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)