Merge "Add footer preference into caption preferences" into qt-r1-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 7301411..77c4e41 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4883,6 +4883,8 @@
<string name="accessibility_tutorial_dialog_button">Got it</string>
<!-- Summary text appearing on the accessibility preference screen to enable screen magnification from the nav bar when the feature is enabled, but the accessibility button is not configured correctly for the feature to be used [CHAR LIMIT=none] -->
<string name="accessibility_screen_magnification_navbar_configuration_warning">The Accessibility button is set to <xliff:g id="service" example="Select to Speak">%1$s</xliff:g>. To use magnification, touch & hold the Accessibility button, then select magnification.</string>
+ <!-- Summary text appearing on the accessibility preference screen to enable screen magnification from the nav bar when the feature is enabled, but the accessibility button is not configured correctly for the feature to be used [CHAR LIMIT=none] -->
+ <string name="accessibility_screen_magnification_gesture_navigation_warning">The accessibility gesture is set to the <xliff:g id="service" example="Select to Speak">%1$s</xliff:g>. To use magnification, swipe up with two fingers from the bottom of the screen and hold. Then select magnification.</string>
<!-- Title for the preference to configure the accessibility shortcut, which uses the volume keys. [CHAR LIMIT=35] -->
<string name="accessibility_global_gesture_preference_title">Volume key shortcut</string>
<!-- Title for the preference to choose the service that is turned on and off by the accessibility shortcut. [CHAR LIMIT=35] -->
diff --git a/res/xml/captioning_settings.xml b/res/xml/captioning_settings.xml
index 766d88f..d8dabdc 100644
--- a/res/xml/captioning_settings.xml
+++ b/res/xml/captioning_settings.xml
@@ -30,10 +30,9 @@
<PreferenceCategory
android:key="standard"
android:title="@string/captioning_standard_options_title" >
- <com.android.settings.accessibility.LocalePreference
- android:key="captioning_locale"
- android:summary="%s"
- android:title="@string/captioning_locale" />
+ <SwitchPreference
+ android:key="captioning_preference_switch"
+ android:title="@string/accessibility_caption_master_switch_title" />
<ListPreference
android:entries="@array/captioning_font_size_selector_titles"
@@ -45,6 +44,11 @@
<com.android.settings.accessibility.PresetPreference
android:key="captioning_preset"
android:title="@string/captioning_preset" />
+
+ <com.android.settings.accessibility.LocalePreference
+ android:key="captioning_locale"
+ android:summary="%s"
+ android:title="@string/captioning_locale" />
</PreferenceCategory>
<PreferenceCategory
android:key="custom"
diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
index bddca9c..9c344df 100644
--- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
+++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
@@ -31,18 +31,17 @@
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceChangeListener;
import androidx.preference.PreferenceCategory;
+import androidx.preference.SwitchPreference;
import com.android.internal.widget.SubtitleView;
import com.android.settings.R;
-import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
-import com.android.settings.widget.SwitchBar;
-import com.android.settings.widget.ToggleSwitch;
-import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
import com.android.settingslib.accessibility.AccessibilityUtils;
import com.android.settingslib.widget.LayoutPreference;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
/**
@@ -63,6 +62,7 @@
private static final String PREF_TYPEFACE = "captioning_typeface";
private static final String PREF_LOCALE = "captioning_locale";
private static final String PREF_PRESET = "captioning_preset";
+ private static final String PREF_SWITCH = "captioning_preference_switch";
private static final String PREF_CUSTOM = "custom";
/** WebVtt specifies line height as 5.3% of the viewport height. */
@@ -72,10 +72,9 @@
private SubtitleView mPreviewText;
private View mPreviewWindow;
private View mPreviewViewport;
- private SwitchBar mSwitchBar;
- private ToggleSwitch mToggleSwitch;
// Standard options.
+ private SwitchPreference mSwitch;
private LocalePreference mLocale;
private ListPreference mFontSize;
private PresetPreference mPreset;
@@ -94,6 +93,8 @@
private boolean mShowingCustom;
+ private final List<Preference> mPreferenceList = new ArrayList<>();
+
@Override
public int getMetricsCategory() {
return SettingsEnums.ACCESSIBILITY_CAPTION_PROPERTIES;
@@ -110,31 +111,18 @@
updateAllPreferences();
refreshShowingCustom();
installUpdateListeners();
- }
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
-
- final boolean enabled = mCaptioningManager.isEnabled();
- SettingsActivity activity = (SettingsActivity) getActivity();
- mSwitchBar = activity.getSwitchBar();
- mSwitchBar.setSwitchBarText(R.string.accessibility_caption_master_switch_title,
- R.string.accessibility_caption_master_switch_title);
- mSwitchBar.setCheckedInternal(enabled);
- mToggleSwitch = mSwitchBar.getSwitch();
-
- getPreferenceScreen().setEnabled(enabled);
-
refreshPreviewText();
-
- installSwitchBarToggleSwitch();
}
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- removeSwitchBarToggleSwitch();
+ private void setPreferenceViewEnabled(boolean enabled) {
+ for (Preference preference : mPreferenceList) {
+ preference.setEnabled(enabled);
+ }
+ }
+
+ private void refreshPreferenceViewEnabled(boolean enabled) {
+ setPreferenceViewEnabled(enabled);
+ mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
}
private void refreshPreviewText() {
@@ -196,38 +184,10 @@
}
}
- protected void onInstallSwitchBarToggleSwitch() {
- mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
- @Override
- public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
- mSwitchBar.setCheckedInternal(checked);
- Settings.Secure.putInt(getActivity().getContentResolver(),
- Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, checked ? 1 : 0);
- getPreferenceScreen().setEnabled(checked);
- if (mPreviewText != null) {
- mPreviewText.setVisibility(checked ? View.VISIBLE : View.INVISIBLE);
- }
- return false;
- }
- });
- }
-
- private void installSwitchBarToggleSwitch() {
- onInstallSwitchBarToggleSwitch();
- mSwitchBar.show();
- }
-
- private void removeSwitchBarToggleSwitch() {
- mSwitchBar.hide();
- mToggleSwitch.setOnBeforeCheckedChangeListener(null);
- }
-
private void initializeAllPreferences() {
final LayoutPreference captionPreview = findPreference(PREF_CAPTION_PREVIEW);
- final boolean enabled = mCaptioningManager.isEnabled();
mPreviewText = captionPreview.findViewById(R.id.preview_text);
- mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
mPreviewWindow = captionPreview.findViewById(R.id.preview_window);
@@ -236,9 +196,6 @@
(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom)
-> refreshPreviewText());
- mLocale = (LocalePreference) findPreference(PREF_LOCALE);
- mFontSize = (ListPreference) findPreference(PREF_FONT_SIZE);
-
final Resources res = getResources();
final int[] presetValues = res.getIntArray(R.array.captioning_preset_selector_values);
final String[] presetTitles = res.getStringArray(R.array.captioning_preset_selector_titles);
@@ -246,6 +203,17 @@
mPreset.setValues(presetValues);
mPreset.setTitles(presetTitles);
+ mSwitch = (SwitchPreference) findPreference(PREF_SWITCH);
+ mLocale = (LocalePreference) findPreference(PREF_LOCALE);
+ mFontSize = (ListPreference) findPreference(PREF_FONT_SIZE);
+
+ // Initialize the preference list
+ mPreferenceList.add(mLocale);
+ mPreferenceList.add(mFontSize);
+ mPreferenceList.add(mPreset);
+
+ refreshPreferenceViewEnabled(mCaptioningManager.isEnabled());
+
mCustom = (PreferenceCategory) findPreference(PREF_CUSTOM);
mShowingCustom = true;
@@ -304,6 +272,7 @@
mWindowOpacity.setOnValueChangedListener(this);
mEdgeType.setOnValueChangedListener(this);
+ mSwitch.setOnPreferenceChangeListener(this);
mTypeface.setOnPreferenceChangeListener(this);
mFontSize.setOnPreferenceChangeListener(this);
mLocale.setOnPreferenceChangeListener(this);
@@ -338,6 +307,8 @@
final String rawLocale = mCaptioningManager.getRawLocale();
mLocale.setValue(rawLocale == null ? "" : rawLocale);
+
+ mSwitch.setChecked(mCaptioningManager.isEnabled());
}
/**
@@ -431,16 +402,22 @@
if (mTypeface == preference) {
Settings.Secure.putString(
cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE, (String) value);
+ refreshPreviewText();
} else if (mFontSize == preference) {
Settings.Secure.putFloat(
cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_FONT_SCALE,
Float.parseFloat((String) value));
+ refreshPreviewText();
} else if (mLocale == preference) {
Settings.Secure.putString(
cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_LOCALE, (String) value);
+ refreshPreviewText();
+ } else if (mSwitch == preference) {
+ Settings.Secure.putInt(
+ cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, (boolean) value ? 1 : 0);
+ refreshPreferenceViewEnabled((boolean) value);
}
- refreshPreviewText();
return true;
}
}
diff --git a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
index c3cb34f..b96d2b7 100644
--- a/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/MagnificationPreferenceFragment.java
@@ -16,6 +16,8 @@
package com.android.settings.accessibility;
+import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
+
import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.settings.SettingsEnums;
import android.content.ComponentName;
@@ -132,9 +134,10 @@
if (info.getComponentName().equals(assignedComponentName)) {
final CharSequence assignedServiceName = info.getResolveInfo().loadLabel(
context.getPackageManager());
- return context.getString(
- R.string.accessibility_screen_magnification_navbar_configuration_warning,
- assignedServiceName);
+ final int messageId = isGestureNavigateEnabled(context)
+ ? R.string.accessibility_screen_magnification_gesture_navigation_warning
+ : R.string.accessibility_screen_magnification_navbar_configuration_warning;
+ return context.getString(messageId, assignedServiceName);
}
}
}
@@ -158,6 +161,12 @@
return res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
}
+ private static boolean isGestureNavigateEnabled(Context context) {
+ return context.getResources().getInteger(
+ com.android.internal.R.integer.config_navBarInteractionMode)
+ == NAV_BAR_MODE_GESTURAL;
+ }
+
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -173,4 +182,4 @@
return isApplicable(context.getResources());
}
};
-}
+}
\ No newline at end of file