UI change in caption preferences in Settings

Move the switch after the caption preview and change the oreder of the
settings inside in caption preferences in Accessibility settings.

Reference link for screenshot:
https://drive.google.com/file/d/1EQLpfQFnJTwU1F8vLAOSHPYqSXKWL_ap/view?usp=sharing

Bug: 130755332
Test: Visual
Change-Id: Icb4dabdef71be165a21d1bde474872ee0bb35bfa
Merged-In: Icb4dabdef71be165a21d1bde474872ee0bb35bfa
(cherry picked from commit fd1f1c0f82)
This commit is contained in:
Kevin Chang
2019-05-23 14:30:23 +08:00
parent 3e9da03d0c
commit ef9cd2ac95
2 changed files with 45 additions and 64 deletions

View File

@@ -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"

View File

@@ -31,18 +31,17 @@ import androidx.preference.ListPreference;
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 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
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 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
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 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
private boolean mShowingCustom;
private final List<Preference> mPreferenceList = new ArrayList<>();
@Override
public int getMetricsCategory() {
return SettingsEnums.ACCESSIBILITY_CAPTION_PROPERTIES;
@@ -110,31 +111,18 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
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 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
}
}
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 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
(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 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
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 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
mWindowOpacity.setOnValueChangedListener(this);
mEdgeType.setOnValueChangedListener(this);
mSwitch.setOnPreferenceChangeListener(this);
mTypeface.setOnPreferenceChangeListener(this);
mFontSize.setOnPreferenceChangeListener(this);
mLocale.setOnPreferenceChangeListener(this);
@@ -338,6 +307,8 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
final String rawLocale = mCaptioningManager.getRawLocale();
mLocale.setValue(rawLocale == null ? "" : rawLocale);
mSwitch.setChecked(mCaptioningManager.isEnabled());
}
/**
@@ -431,16 +402,22 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
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;
}
}