Add entry point of screen zoom to accessibility and font size to display.
Also removing large text preference.

Change-Id: I076664edf1d1afd69385e34f9300bf5c0788b3e7
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 364a2ea..5b85918 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3759,8 +3759,6 @@
     <string name="accessibility_global_gesture_preference_summary_off">Off</string>
     <!--  Description for the preference screen to enable the global geture taht turns on accessibility. [CHAR LIMIT=none] -->
     <string name="accessibility_global_gesture_preference_description">When this feature is turned on, you can quickly enable accessibility features in two steps:\n\nStep 1: Press and hold the power button until you hear a sound or feel a vibration.\n\nStep 2: Touch and hold two fingers until you hear audio confirmation.\n\nIf the device has multiple users, using this shortcut on the lock screen temporarily enables accessibility until the device is unlocked.</string>
-    <!-- Title for the accessibility preference to enable large text. [CHAR LIMIT=35] -->
-    <string name="accessibility_toggle_large_text_preference_title">Large text</string>
     <!-- Title for the accessibility preference to high contrast text. [CHAR LIMIT=35] -->
     <string name="accessibility_toggle_high_text_contrast_preference_title">High contrast text</string>
     <!-- Title for the accessibility preference to enable screen magnification. [CHAR LIMIT=35] -->
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 54a5a17..a59fbdc 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -43,17 +43,16 @@
             android:key="font_size_preference_screen"
             android:title="@string/title_font_size"/>
 
+        <com.android.settings.display.ScreenZoomPreference
+            android:key="screen_zoom"
+            android:title="@string/screen_zoom_title"/>
+
         <PreferenceScreen
             android:fragment="com.android.settings.accessibility.ToggleAutoclickPreferenceFragment"
             android:key="autoclick_preference_screen"
             android:title="@string/accessibility_autoclick_preference_title"/>
 
         <SwitchPreference
-                android:key="toggle_large_text_preference"
-                android:title="@string/accessibility_toggle_large_text_preference_title"
-                android:persistent="false"/>
-
-        <SwitchPreference
                 android:key="toggle_high_text_contrast_preference"
                 android:title="@string/accessibility_toggle_high_text_contrast_preference_title"
                 android:summary="@string/experimental_preference"
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index 1780765..0543ac1 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -91,14 +91,11 @@
                 android:summary="@string/tap_to_wake_summary"
                 android:persistent="false" />
 
-        <DropDownPreference
+        <PreferenceScreen
                 android:key="font_size"
                 android:title="@string/title_font_size"
-                settings:keywords="@string/keywords_display_font_size"
-                android:persistent="false"
-                android:summary="%s"
-                android:entries="@array/entries_font_size"
-                android:entryValues="@array/entryvalues_font_size" />
+                android:fragment="com.android.settings.accessibility.ToggleFontSizePreferenceFragment"
+                settings:keywords="@string/keywords_display_font_size" />
 
         <com.android.settings.display.ScreenZoomPreference
                 android:key="screen_zoom"
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index 31e8d89..5e7407b 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -17,7 +17,6 @@
 package com.android.settings;
 
 import android.app.Activity;
-import android.app.ActivityManagerNative;
 import android.app.UiModeManager;
 import android.app.admin.DevicePolicyManager;
 import android.content.ContentResolver;
@@ -29,7 +28,6 @@
 import android.hardware.SensorManager;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.RemoteException;
 import android.os.SystemProperties;
 import android.provider.SearchIndexableResource;
 import android.provider.Settings;
@@ -44,6 +42,7 @@
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.internal.view.RotationPolicy;
+import com.android.settings.accessibility.ToggleFontSizePreferenceFragment;
 import com.android.settings.dashboard.SummaryLoader;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
@@ -85,7 +84,7 @@
     private static final String KEY_CAMERA_DOUBLE_TAP_POWER_GESTURE
             = "camera_double_tap_power_gesture";
 
-    private DropDownPreference mFontSizePref;
+    private Preference mFontSizePref;
 
     private final Configuration mCurConfig = new Configuration();
 
@@ -121,8 +120,7 @@
 
         mScreenTimeoutPreference = (RestrictedListPreference) findPreference(KEY_SCREEN_TIMEOUT);
 
-        mFontSizePref = (DropDownPreference) findPreference(KEY_FONT_SIZE);
-        mFontSizePref.setOnPreferenceChangeListener(this);
+        mFontSizePref = findPreference(KEY_FONT_SIZE);
 
         if (isAutomaticBrightnessAvailable(getResources())) {
             mAutoBrightnessPreference = (SwitchPreference) findPreference(KEY_AUTO_BRIGHTNESS);
@@ -339,37 +337,6 @@
         }
     }
 
-    int floatToIndex(float val) {
-        String[] indices = getResources().getStringArray(R.array.entryvalues_font_size);
-        float lastVal = Float.parseFloat(indices[0]);
-        for (int i=1; i<indices.length; i++) {
-            float thisVal = Float.parseFloat(indices[i]);
-            if (val < (lastVal + (thisVal-lastVal)*.5f)) {
-                return i-1;
-            }
-            lastVal = thisVal;
-        }
-        return indices.length-1;
-    }
-
-    public void readFontSizePreference(ListPreference pref) {
-        try {
-            mCurConfig.updateFrom(ActivityManagerNative.getDefault().getConfiguration());
-        } catch (RemoteException e) {
-            Log.w(TAG, "Unable to retrieve font size");
-        }
-
-        // mark the appropriate item in the preferences list
-        int index = floatToIndex(mCurConfig.fontScale);
-        pref.setValueIndex(index);
-
-        // report the current size in the summary text
-        final Resources res = getResources();
-        String[] fontSizeNames = res.getStringArray(R.array.entries_font_size);
-        pref.setSummary(String.format(res.getString(R.string.summary_font_size),
-                fontSizeNames[index]));
-    }
-
     @Override
     public void onResume() {
         super.onResume();
@@ -384,7 +351,7 @@
     }
 
     private void updateState() {
-        readFontSizePreference(mFontSizePref);
+        updateFontSizeSummary();
         updateScreenSaverSummary();
 
         // Update auto brightness if it is available.
@@ -433,13 +400,13 @@
         }
     }
 
-    public void writeFontSizePreference(Object objValue) {
-        try {
-            mCurConfig.fontScale = Float.parseFloat(objValue.toString());
-            ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig);
-        } catch (RemoteException e) {
-            Log.w(TAG, "Unable to save font size");
-        }
+    private void updateFontSizeSummary() {
+        final Resources res = mFontSizePref.getContext().getResources();
+        final String[] entries = res.getStringArray(R.array.entries_font_size);
+        final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
+        final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(
+                res.getConfiguration().fontScale, strEntryValues);
+        mFontSizePref.setSummary(entries[index]);
     }
 
     @Override
@@ -454,9 +421,6 @@
                 Log.e(TAG, "could not persist screen timeout setting", e);
             }
         }
-        if (KEY_FONT_SIZE.equals(key)) {
-            writeFontSizePreference(objValue);
-        }
         if (preference == mAutoBrightnessPreference) {
             boolean auto = (Boolean) objValue;
             Settings.System.putInt(getContentResolver(), SCREEN_BRIGHTNESS_MODE,
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index 1ca32d8..5ce5cfc 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -71,15 +71,11 @@
 public class AccessibilitySettings extends SettingsPreferenceFragment implements DialogCreatable,
         Preference.OnPreferenceChangeListener, Indexable {
 
-    private static final float LARGE_FONT_SCALE = 1.3f;
-
     // Preference categories
     private static final String SERVICES_CATEGORY = "services_category";
     private static final String SYSTEM_CATEGORY = "system_category";
 
     // Preferences
-    private static final String TOGGLE_LARGE_TEXT_PREFERENCE =
-            "toggle_large_text_preference";
     private static final String TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE =
             "toggle_high_text_contrast_preference";
     private static final String TOGGLE_INVERSION_PREFERENCE =
@@ -127,8 +123,6 @@
 
     private final Map<String, String> mLongPressTimeoutValuetoTitleMap = new HashMap<>();
 
-    private final Configuration mCurConfig = new Configuration();
-
     private final Handler mHandler = new Handler();
 
     private final Runnable mUpdateRunnable = new Runnable() {
@@ -185,7 +179,6 @@
     private PreferenceCategory mServicesCategory;
     private PreferenceCategory mSystemsCategory;
 
-    private SwitchPreference mToggleLargeTextPreference;
     private SwitchPreference mToggleHighTextContrastPreference;
     private SwitchPreference mTogglePowerButtonEndsCallPreference;
     private SwitchPreference mToggleLockScreenRotationPreference;
@@ -274,10 +267,7 @@
 
     @Override
     public boolean onPreferenceTreeClick(Preference preference) {
-        if (mToggleLargeTextPreference == preference) {
-            handleToggleLargeTextPreferenceClick();
-            return true;
-        } else if (mToggleHighTextContrastPreference == preference) {
+        if (mToggleHighTextContrastPreference == preference) {
             handleToggleTextContrastPreferenceClick();
             return true;
         } else if (mTogglePowerButtonEndsCallPreference == preference) {
@@ -302,15 +292,6 @@
         return super.onPreferenceTreeClick(preference);
     }
 
-    private void handleToggleLargeTextPreferenceClick() {
-        try {
-            mCurConfig.fontScale = mToggleLargeTextPreference.isChecked() ? LARGE_FONT_SCALE : 1;
-            ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig);
-        } catch (RemoteException re) {
-            /* ignore */
-        }
-    }
-
     private void handleToggleTextContrastPreferenceClick() {
         Settings.Secure.putInt(getContentResolver(),
                 Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED,
@@ -368,10 +349,6 @@
         mServicesCategory = (PreferenceCategory) findPreference(SERVICES_CATEGORY);
         mSystemsCategory = (PreferenceCategory) findPreference(SYSTEM_CATEGORY);
 
-        // Large text.
-        mToggleLargeTextPreference =
-                (SwitchPreference) findPreference(TOGGLE_LARGE_TEXT_PREFERENCE);
-
         // Text contrast.
         mToggleHighTextContrastPreference =
                 (SwitchPreference) findPreference(TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE);
@@ -564,14 +541,6 @@
     }
 
     private void updateSystemPreferences() {
-        // Large text.
-        try {
-            mCurConfig.updateFrom(ActivityManagerNative.getDefault().getConfiguration());
-        } catch (RemoteException re) {
-            /* ignore */
-        }
-        mToggleLargeTextPreference.setChecked(mCurConfig.fontScale == LARGE_FONT_SCALE);
-
         // Text contrast.
         mToggleHighTextContrastPreference.setChecked(
                 Settings.Secure.getInt(getContentResolver(),
@@ -658,7 +627,7 @@
         final Resources res = getContext().getResources();
         final String[] entries = res.getStringArray(R.array.entries_font_size);
         final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
-        final int index = ToggleFontSizePreferenceFragment.floatToIndex(
+        final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(
                 res.getConfiguration().fontScale, strEntryValues);
         pref.setSummary(entries[index]);
     }
diff --git a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
index 052f6fb..eaab57d 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettingsForSetupWizard.java
@@ -188,7 +188,7 @@
         final Resources res = getContext().getResources();
         final String[] entries = res.getStringArray(R.array.entries_font_size);
         final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
-        final int index = ToggleFontSizePreferenceFragment.floatToIndex(
+        final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(
                 res.getConfiguration().fontScale, strEntryValues);
         pref.setSummary(entries[index]);
     }
diff --git a/src/com/android/settings/accessibility/ToggleFontSizePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFontSizePreferenceFragment.java
index 4a8cd32..1c5d8dc 100644
--- a/src/com/android/settings/accessibility/ToggleFontSizePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFontSizePreferenceFragment.java
@@ -48,7 +48,7 @@
         final Configuration origConfig = res.getConfiguration();
         mEntries = res.getStringArray(R.array.entries_font_size);
         final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
-        mInitialIndex = floatToIndex(origConfig.fontScale, strEntryValues);
+        mInitialIndex = fontSizeValueToIndex(origConfig.fontScale, strEntryValues);
         mValues = new float[strEntryValues.length];
         for (int i = 0; i < strEntryValues.length; ++i) {
             mValues[i] = Float.parseFloat(strEntryValues[i]);
@@ -86,7 +86,7 @@
      *  Utility function that returns the index in a string array with which the represented value is
      *  the closest to a given float value.
      */
-    static int floatToIndex(float val, String[] indices) {
+    public static int fontSizeValueToIndex(float val, String[] indices) {
         float lastVal = Float.parseFloat(indices[0]);
         for (int i=1; i<indices.length; i++) {
             float thisVal = Float.parseFloat(indices[i]);