Remove toggle switch on accessibility preference fragment detach
BUG: 13169998 Change-Id: Id6bac95feb53fec7bb56e6af5c7f5e407e8eba55
This commit is contained in:
@@ -69,6 +69,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
|||||||
private CaptioningManager mCaptioningManager;
|
private CaptioningManager mCaptioningManager;
|
||||||
private SubtitleView mPreviewText;
|
private SubtitleView mPreviewText;
|
||||||
private View mPreviewWindow;
|
private View mPreviewWindow;
|
||||||
|
private ToggleSwitch mToggleSwitch;
|
||||||
|
|
||||||
// Standard options.
|
// Standard options.
|
||||||
private LocalePreference mLocale;
|
private LocalePreference mLocale;
|
||||||
@@ -124,13 +125,38 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
|||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
|
final boolean enabled = mCaptioningManager.isEnabled();
|
||||||
mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text);
|
mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text);
|
||||||
|
mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
|
||||||
|
final Context context = view.getContext();
|
||||||
|
final int padding = context.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.action_bar_switch_padding);
|
||||||
|
mToggleSwitch = new ToggleSwitch(context);
|
||||||
|
mToggleSwitch.setPaddingRelative(0, 0, padding, 0);
|
||||||
|
mToggleSwitch.setCheckedInternal(enabled);
|
||||||
|
|
||||||
mPreviewWindow = view.findViewById(R.id.preview_window);
|
mPreviewWindow = view.findViewById(R.id.preview_window);
|
||||||
|
|
||||||
installActionBarToggleSwitch();
|
getPreferenceScreen().setEnabled(enabled);
|
||||||
|
|
||||||
refreshPreviewText();
|
refreshPreviewText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
installActionBarToggleSwitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
removeActionBarToggleSwitch();
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshPreviewText() {
|
private void refreshPreviewText() {
|
||||||
final Context context = getActivity();
|
final Context context = getActivity();
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
@@ -176,39 +202,41 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void installActionBarToggleSwitch() {
|
protected void onInstallActionBarToggleSwitch() {
|
||||||
final Activity activity = getActivity();
|
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
||||||
final ToggleSwitch toggleSwitch = new ToggleSwitch(activity);
|
|
||||||
|
|
||||||
final int padding = getResources().getDimensionPixelSize(
|
|
||||||
R.dimen.action_bar_switch_padding);
|
|
||||||
toggleSwitch.setPaddingRelative(0, 0, padding, 0);
|
|
||||||
|
|
||||||
final ActionBar actionBar = activity.getActionBar();
|
|
||||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
||||||
|
|
||||||
final ActionBar.LayoutParams params = new ActionBar.LayoutParams(
|
|
||||||
ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT,
|
|
||||||
Gravity.CENTER_VERTICAL | Gravity.END);
|
|
||||||
actionBar.setCustomView(toggleSwitch, params);
|
|
||||||
|
|
||||||
final boolean enabled = mCaptioningManager.isEnabled();
|
|
||||||
getPreferenceScreen().setEnabled(enabled);
|
|
||||||
mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
|
|
||||||
toggleSwitch.setCheckedInternal(enabled);
|
|
||||||
toggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
||||||
toggleSwitch.setCheckedInternal(checked);
|
toggleSwitch.setCheckedInternal(checked);
|
||||||
Settings.Secure.putInt(getActivity().getContentResolver(),
|
Settings.Secure.putInt(getActivity().getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, checked ? 1 : 0);
|
Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, checked ? 1 : 0);
|
||||||
getPreferenceScreen().setEnabled(checked);
|
getPreferenceScreen().setEnabled(checked);
|
||||||
mPreviewText.setVisibility(checked ? View.VISIBLE : View.INVISIBLE);
|
if (mPreviewText != null) {
|
||||||
|
mPreviewText.setVisibility(checked ? View.VISIBLE : View.INVISIBLE);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void installActionBarToggleSwitch() {
|
||||||
|
final ActionBar ab = getActivity().getActionBar();
|
||||||
|
final ActionBar.LayoutParams params = new ActionBar.LayoutParams(
|
||||||
|
ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT,
|
||||||
|
Gravity.CENTER_VERTICAL | Gravity.END);
|
||||||
|
ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
ab.setCustomView(mToggleSwitch, params);
|
||||||
|
|
||||||
|
onInstallActionBarToggleSwitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeActionBarToggleSwitch() {
|
||||||
|
mToggleSwitch.setOnBeforeCheckedChangeListener(null);
|
||||||
|
|
||||||
|
final ActionBar ab = getActivity().getActionBar();
|
||||||
|
ab.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
ab.setCustomView(null);
|
||||||
|
}
|
||||||
|
|
||||||
private void initializeAllPreferences() {
|
private void initializeAllPreferences() {
|
||||||
mLocale = (LocalePreference) findPreference(PREF_LOCALE);
|
mLocale = (LocalePreference) findPreference(PREF_LOCALE);
|
||||||
mFontSize = (ListPreference) findPreference(PREF_FONT_SIZE);
|
mFontSize = (ListPreference) findPreference(PREF_FONT_SIZE);
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.accessibility;
|
|||||||
|
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
@@ -86,15 +87,28 @@ public abstract class ToggleFeaturePreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
onInstallActionBarToggleSwitch();
|
|
||||||
|
final Context context = view.getContext();
|
||||||
|
final int padding = context.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.action_bar_switch_padding);
|
||||||
|
mToggleSwitch = new ToggleSwitch(context);
|
||||||
|
mToggleSwitch.setPaddingRelative(0, 0, padding, 0);
|
||||||
|
|
||||||
onProcessArguments(getArguments());
|
onProcessArguments(getArguments());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onResume() {
|
||||||
getActivity().getActionBar().setCustomView(null);
|
super.onResume();
|
||||||
mToggleSwitch.setOnBeforeCheckedChangeListener(null);
|
|
||||||
super.onDestroyView();
|
installActionBarToggleSwitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
removeActionBarToggleSwitch();
|
||||||
|
|
||||||
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
|
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
|
||||||
@@ -108,21 +122,26 @@ public abstract class ToggleFeaturePreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void onInstallActionBarToggleSwitch() {
|
protected void onInstallActionBarToggleSwitch() {
|
||||||
mToggleSwitch = createAndAddActionBarToggleSwitch(getActivity());
|
// Implement this to set a checked listener.
|
||||||
}
|
}
|
||||||
|
|
||||||
private ToggleSwitch createAndAddActionBarToggleSwitch(Activity activity) {
|
private void installActionBarToggleSwitch() {
|
||||||
ToggleSwitch toggleSwitch = new ToggleSwitch(activity);
|
final ActionBar ab = getActivity().getActionBar();
|
||||||
final int padding = activity.getResources().getDimensionPixelSize(
|
final ActionBar.LayoutParams params = new ActionBar.LayoutParams(
|
||||||
R.dimen.action_bar_switch_padding);
|
ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT,
|
||||||
toggleSwitch.setPaddingRelative(0, 0, padding, 0);
|
Gravity.CENTER_VERTICAL | Gravity.END);
|
||||||
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
|
ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
ActionBar.DISPLAY_SHOW_CUSTOM);
|
ab.setCustomView(mToggleSwitch, params);
|
||||||
activity.getActionBar().setCustomView(toggleSwitch,
|
|
||||||
new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
|
onInstallActionBarToggleSwitch();
|
||||||
ActionBar.LayoutParams.WRAP_CONTENT,
|
}
|
||||||
Gravity.CENTER_VERTICAL | Gravity.END));
|
|
||||||
return toggleSwitch;
|
private void removeActionBarToggleSwitch() {
|
||||||
|
mToggleSwitch.setOnBeforeCheckedChangeListener(null);
|
||||||
|
|
||||||
|
final ActionBar ab = getActivity().getActionBar();
|
||||||
|
ab.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
ab.setCustomView(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
|
Reference in New Issue
Block a user