From af88d809c0354ef2551050b2ea74cb85dc8ef056 Mon Sep 17 00:00:00 2001 From: p4r4n01d Date: Sat, 16 Nov 2013 13:47:34 +1100 Subject: Display Settings: Better font size control Use a SeekBar instead of a list/spinner to determine the font scaling. For consistency, an approximate size (small, normal, etc.) and the exact percentage are displayed. Show a preview of the selected font size immediately Ported from CM 10.2, squashed commits 46678 and 49167. Credit to Veeti Paaananen for the latter commit. Change-Id: I754d7fdcaf27c23dfccf9d56291956e70b23f63e --- src/com/android/settings/Display.java | 138 ------------------ src/com/android/settings/DisplaySettings.java | 51 +++---- src/com/android/settings/FontDialogPreference.java | 156 +++++++++++++++++++++ src/com/android/settings/IntervalSeekBar.java | 87 ++++++++++++ 4 files changed, 261 insertions(+), 171 deletions(-) delete mode 100644 src/com/android/settings/Display.java create mode 100644 src/com/android/settings/FontDialogPreference.java create mode 100644 src/com/android/settings/IntervalSeekBar.java (limited to 'src') diff --git a/src/com/android/settings/Display.java b/src/com/android/settings/Display.java deleted file mode 100644 index fa2931812..000000000 --- a/src/com/android/settings/Display.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings; - -import android.app.Activity; -import android.app.ActivityManagerNative; -import android.content.res.Configuration; -import android.content.res.Resources; -import android.content.res.TypedArray; -import android.os.Bundle; -import android.os.RemoteException; -import android.util.DisplayMetrics; -import android.util.TypedValue; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.Spinner; -import android.widget.TextView; - - -public class Display extends Activity implements View.OnClickListener { - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - - setContentView(R.layout.display); - - mFontSize = (Spinner) findViewById(R.id.fontSize); - mFontSize.setOnItemSelectedListener(mFontSizeChanged); - String[] states = new String[3]; - Resources r = getResources(); - states[0] = r.getString(R.string.small_font); - states[1] = r.getString(R.string.medium_font); - states[2] = r.getString(R.string.large_font); - ArrayAdapter adapter = new ArrayAdapter(this, - android.R.layout.simple_spinner_item, states); - adapter.setDropDownViewResource( - android.R.layout.simple_spinner_dropdown_item); - mFontSize.setAdapter(adapter); - - mPreview = (TextView) findViewById(R.id.preview); - mPreview.setText(r.getText(R.string.font_size_preview_text)); - - Button save = (Button) findViewById(R.id.save); - save.setText(r.getText(R.string.font_size_save)); - save.setOnClickListener(this); - - mTextSizeTyped = new TypedValue(); - TypedArray styledAttributes = - obtainStyledAttributes(android.R.styleable.TextView); - styledAttributes.getValue(android.R.styleable.TextView_textSize, - mTextSizeTyped); - - DisplayMetrics metrics = getResources().getDisplayMetrics(); - mDisplayMetrics = new DisplayMetrics(); - mDisplayMetrics.density = metrics.density; - mDisplayMetrics.heightPixels = metrics.heightPixels; - mDisplayMetrics.scaledDensity = metrics.scaledDensity; - mDisplayMetrics.widthPixels = metrics.widthPixels; - mDisplayMetrics.xdpi = metrics.xdpi; - mDisplayMetrics.ydpi = metrics.ydpi; - - styledAttributes.recycle(); - } - - @Override - public void onResume() { - super.onResume(); - try { - mCurConfig.updateFrom( - ActivityManagerNative.getDefault().getConfiguration()); - } catch (RemoteException e) { - } - if (mCurConfig.fontScale < 1) { - mFontSize.setSelection(0); - } else if (mCurConfig.fontScale > 1) { - mFontSize.setSelection(2); - } else { - mFontSize.setSelection(1); - } - updateFontScale(); - } - - private void updateFontScale() { - mDisplayMetrics.scaledDensity = mDisplayMetrics.density * - mCurConfig.fontScale; - - float size = mTextSizeTyped.getDimension(mDisplayMetrics); - mPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); - } - - public void onClick(View v) { - try { - ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig); - } catch (RemoteException e) { - } - finish(); - } - - private Spinner.OnItemSelectedListener mFontSizeChanged - = new Spinner.OnItemSelectedListener() { - public void onItemSelected(android.widget.AdapterView av, View v, - int position, long id) { - if (position == 0) { - mCurConfig.fontScale = .75f; - } else if (position == 2) { - mCurConfig.fontScale = 1.25f; - } else { - mCurConfig.fontScale = 1.0f; - } - - updateFontScale(); - } - - public void onNothingSelected(android.widget.AdapterView av) { - } - }; - - private Spinner mFontSize; - private TextView mPreview; - private TypedValue mTextSizeTyped; - private DisplayMetrics mDisplayMetrics; - private Configuration mCurConfig = new Configuration(); -} diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java index 01eed088c..66af45847 100644 --- a/src/com/android/settings/DisplaySettings.java +++ b/src/com/android/settings/DisplaySettings.java @@ -88,7 +88,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements private static final int DLG_GLOBAL_CHANGE_WARNING = 1; - private WarnedListPreference mFontSizePref; + private FontDialogPreference mFontSizePref; private final Configuration mCurConfig = new Configuration(); @@ -130,7 +130,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements disableUnusableTimeouts(mScreenTimeoutPreference); updateTimeoutPreferenceDescription(currentTimeout); - mFontSizePref = (WarnedListPreference) findPreference(KEY_FONT_SIZE); + mFontSizePref = (FontDialogPreference) findPreference(KEY_FONT_SIZE); mFontSizePref.setOnPreferenceChangeListener(this); mFontSizePref.setOnPreferenceClickListener(this); @@ -312,37 +312,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements screenTimeoutPreference.setEnabled(revisedEntries.size() > 0); } - int floatToIndex(float val) { - String[] indices = getResources().getStringArray(R.array.entryvalues_font_size); - float lastVal = Float.parseFloat(indices[0]); - for (int i=1; i mMax) { + float temp = mMax; + mMax = mMin; + mMin = temp; + } + + setMax(convertFloatToProgress(mMax)); + setProgressFloat(mDefault); + + seekBarType.recycle(); + } + + /* + * Converts from SeekBar units (which the SeekBar uses), to scale units + * (which are saved). + * This operation is the inverse of setFontScaling. + */ + public float getProgressFloat() { + return (getProgress() / mMultiplier) + mMin; + } + + /* + * Converts from scale units (which are saved), to SeekBar units + * (which the SeekBar uses). This also sets the SeekBar progress. + * This operation is the inverse of getProgressFloat. + */ + public void setProgressFloat(float progress) { + setProgress(convertFloatToProgress(progress)); + } + + private int convertFloatToProgress(float value) { + return Math.round((value - mMin) * mMultiplier); + } + + public float getMinimum() { + return mMin; + } + + public float getMaximum() { + return mMax; + } + + public float getDefault() { + return mDefault; + } + + public void setMaximum(float max) { + mMax = max; + setMax(convertFloatToProgress(mMax)); + } + + public void setMinimum(float min) { + mMin = min; + } +} -- cgit v1.2.3