diff --git a/res/values/strings.xml b/res/values/strings.xml index 11aa84cbd9f..c1afba6ce51 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4067,12 +4067,22 @@ Captions Magnification + + Magnify with triple-tap + + Magnify with button Zoom in on screen Tap 3 times to zoom - + + Tap a button to zoom + To zoom, quickly tap the screen 3 times with one finger.\n\n\nTo zoom temporarily, quickly tap the screen 3 times and hold down your finger on the third tap.\n\n\nYou can\'t zoom in on the keyboard and navigation bar. + + When magnification is turned on, use the Accessibility button at the bottom of the screen to quickly magnify.\n\nTo zoom, tap the Accessibility button, then tap anywhere on the screen.\n\n\nTo zoom temporarily, tap the Accessibility button, then touch & hold anywhere on the screen.\n\n\nYou can’t zoom in on the keyboard or navigation bar. + + The Accessibility button is set to %1$s. To use magnification, touch & hold the Accessibility button, then select magnification. Accessibility shortcut diff --git a/res/xml/accessibility_magnification_settings.xml b/res/xml/accessibility_magnification_settings.xml new file mode 100644 index 00000000000..0f3c1190839 --- /dev/null +++ b/res/xml/accessibility_magnification_settings.xml @@ -0,0 +1,26 @@ + + + + + + diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml index 5c67d6e7436..065ead127e1 100644 --- a/res/xml/accessibility_settings.xml +++ b/res/xml/accessibility_settings.xml @@ -51,9 +51,9 @@ android:title="@string/screen_zoom_title"/> + android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment" + android:key="magnification_preference_screen" + android:title="@string/accessibility_screen_magnification_title"/> + android:summary="@string/accessibility_preference_magnification_summary" /> getXmlResourcesToIndex(Context context, + boolean enabled) { + final SearchIndexableResource sir = new SearchIndexableResource(context); + sir.xmlResId = R.xml.accessibility_magnification_settings; + return Arrays.asList(sir); + } + }; +} diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java index 8f13e08fecd..19cde082815 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java @@ -20,29 +20,28 @@ import android.content.ContentResolver; import android.content.Context; import android.content.res.Resources; import android.graphics.Point; -import android.os.Bundle; -import android.provider.Settings; - import android.media.MediaPlayer; import android.media.MediaPlayer.OnPreparedListener; import android.net.Uri; +import android.os.Bundle; +import android.provider.Settings; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceViewHolder; import android.view.Display; -import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.WindowManager; import android.widget.ImageView; -import android.widget.MediaController; import android.widget.RelativeLayout.LayoutParams; +import android.widget.Switch; import android.widget.VideoView; + import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; -import com.android.settings.widget.ToggleSwitch; -import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener; +import com.android.settings.widget.SwitchBar; -public class ToggleScreenMagnificationPreferenceFragment extends ToggleFeaturePreferenceFragment { +public class ToggleScreenMagnificationPreferenceFragment extends + ToggleFeaturePreferenceFragment implements SwitchBar.OnSwitchChangeListener { protected class VideoPreference extends Preference { private ImageView mVideoBackgroundView; @@ -77,10 +76,15 @@ public class ToggleScreenMagnificationPreferenceFragment extends ToggleFeaturePr } }); - videoView.setVideoURI(Uri.parse(String.format("%s://%s/%s", - ContentResolver.SCHEME_ANDROID_RESOURCE, - getPrefContext().getPackageName(), - R.raw.accessibility_screen_magnification))); + // Resolve and set the video content + Bundle args = getArguments(); + if ((args != null) && args.containsKey( + AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID)) { + videoView.setVideoURI(Uri.parse(String.format("%s://%s/%s", + ContentResolver.SCHEME_ANDROID_RESOURCE, + getPrefContext().getPackageName(), + args.getInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID)))); + } // Make sure video controls (e.g. for pausing) are not displayed. videoView.setMediaController(null); @@ -112,6 +116,10 @@ public class ToggleScreenMagnificationPreferenceFragment extends ToggleFeaturePr } protected VideoPreference mVideoPreference; + protected Preference mConfigWarningPreference; + + private boolean mLaunchFromSuw = false; + private boolean mInitialSetting = false; @Override public void onCreate(Bundle savedInstanceState) { @@ -122,66 +130,100 @@ public class ToggleScreenMagnificationPreferenceFragment extends ToggleFeaturePr mVideoPreference.setPersistent(false); mVideoPreference.setLayoutResource(R.layout.magnification_video_preference); + mConfigWarningPreference = new Preference(getPrefContext()); + mConfigWarningPreference.setSelectable(false); + mConfigWarningPreference.setPersistent(false); + mConfigWarningPreference.setVisible(false); + mConfigWarningPreference.setIcon(R.drawable.ic_warning_24dp); + final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen(); preferenceScreen.setOrderingAsAdded(false); mVideoPreference.setOrder(0); mSummaryPreference.setOrder(1); + mConfigWarningPreference.setOrder(2); preferenceScreen.addPreference(mVideoPreference); - } - - @Override - protected void onPreferenceToggled(String preferenceKey, boolean enabled) { - // Do nothing. - } - - @Override - protected void onInstallSwitchBarToggleSwitch() { - super.onInstallSwitchBarToggleSwitch(); - mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { - @Override - public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { - mSwitchBar.setCheckedInternal(checked); - getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, checked); - onPreferenceToggled(mPreferenceKey, checked); - return false; - } - }); + preferenceScreen.addPreference(mConfigWarningPreference); } @Override public void onResume() { super.onResume(); - // Temporarily enable Magnification on this screen if it's disabled. - if (Settings.Secure.getInt(getContentResolver(), - Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 0) { - setMagnificationEnabled(1); - } - VideoView videoView = (VideoView) getView().findViewById(R.id.video); if (videoView != null) { videoView.start(); } - } - @Override - public void onPause() { - super.onPause(); - if (!mToggleSwitch.isChecked()) { - setMagnificationEnabled(0); - } - } - - private void setMagnificationEnabled(int enabled) { - Settings.Secure.putInt(getContentResolver(), - Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, enabled); + updateConfigurationWarningIfNeeded(); } @Override public int getMetricsCategory() { + // TODO: Distinguish between magnification modes return MetricsEvent.ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION; } + @Override + public void onSwitchChanged(Switch switchView, boolean isChecked) { + onPreferenceToggled(mPreferenceKey, isChecked); + } + + @Override + protected void onPreferenceToggled(String preferenceKey, boolean enabled) { + Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? 1 : 0); + updateConfigurationWarningIfNeeded(); + } + + @Override + protected void onInstallSwitchBarToggleSwitch() { + super.onInstallSwitchBarToggleSwitch(); + + mSwitchBar.setCheckedInternal( + Settings.Secure.getInt(getContentResolver(), mPreferenceKey, 0) == 1); + mSwitchBar.addOnSwitchChangeListener(this); + } + + @Override + protected void onRemoveSwitchBarToggleSwitch() { + super.onRemoveSwitchBarToggleSwitch(); + mSwitchBar.removeOnSwitchChangeListener(this); + } + + @Override + protected void onProcessArguments(Bundle arguments) { + super.onProcessArguments(arguments); + if (arguments == null) { + return; + } + + if (arguments.containsKey(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID)) { + mVideoPreference.setVisible(true); + final int resId = arguments.getInt( + AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID); + } else { + mVideoPreference.setVisible(false); + } + + if (arguments.containsKey(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW)) { + mLaunchFromSuw = arguments.getBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW); + } + + if (arguments.containsKey(AccessibilitySettings.EXTRA_CHECKED)) { + mInitialSetting = arguments.getBoolean(AccessibilitySettings.EXTRA_CHECKED); + } + } + + private void updateConfigurationWarningIfNeeded() { + final int warningRes = + MagnificationPreferenceFragment + .getConfigurationWarningStringResourceForSecureSettingsKey( + mPreferenceKey, getContentResolver()); + if (warningRes != -1) { + mConfigWarningPreference.setSummary(warningRes); + } + mConfigWarningPreference.setVisible(warningRes != -1); + } + private static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java index ab0790b798b..43381728676 100644 --- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java +++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragmentForSetupWizard.java @@ -24,14 +24,6 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; public class ToggleScreenMagnificationPreferenceFragmentForSetupWizard extends ToggleScreenMagnificationPreferenceFragment { - private boolean mToggleSwitchWasInitiallyChecked; - - @Override - protected void onProcessArguments(Bundle arguments) { - super.onProcessArguments(arguments); - mToggleSwitchWasInitiallyChecked = mToggleSwitch.isChecked(); - } - @Override public int getMetricsCategory() { return MetricsEvent.SUW_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION; @@ -40,12 +32,15 @@ public class ToggleScreenMagnificationPreferenceFragmentForSetupWizard @Override public void onStop() { // Log the final choice in value if it's different from the previous value. - if (mToggleSwitch.isChecked() != mToggleSwitchWasInitiallyChecked) { - mMetricsFeatureProvider.action(getContext(), - MetricsEvent.SUW_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION, - mToggleSwitch.isChecked()); + Bundle args = getArguments(); + if ((args != null) && args.containsKey(AccessibilitySettings.EXTRA_CHECKED)) { + if (mToggleSwitch.isChecked() != args.getBoolean(AccessibilitySettings.EXTRA_CHECKED)) { + // TODO: Distinguish between magnification modes + mMetricsFeatureProvider.action(getContext(), + MetricsEvent.SUW_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION, + mToggleSwitch.isChecked()); + } } - super.onStop(); } } diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index f88d83033c0..8b1983434d0 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -30,6 +30,7 @@ import com.android.settings.R; import com.android.settings.ScreenPinningSettings; import com.android.settings.SecuritySettings; import com.android.settings.accessibility.AccessibilitySettings; +import com.android.settings.accessibility.MagnificationPreferenceFragment; import com.android.settings.accounts.UserAndAccountDashboardFragment; import com.android.settings.applications.AdvancedAppSettings; import com.android.settings.applications.AppAndNotificationDashboardFragment; @@ -173,6 +174,8 @@ public final class SearchIndexableResources { TtsEnginePreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language); addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings, R.drawable.ic_settings_security); + addIndex(MagnificationPreferenceFragment.class, NO_DATA_RES_ID, + R.drawable.ic_settings_accessibility); } private SearchIndexableResources() {