Merge "Remove ActivityManagerNative dependency for adjusting font scale"
This commit is contained in:
committed by
Android (Google) Code Review
commit
fcb84e6912
@@ -17,12 +17,11 @@
|
|||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityManagerNative;
|
import android.content.ContentResolver;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.provider.Settings;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -73,21 +72,19 @@ public class Display extends Activity implements View.OnClickListener {
|
|||||||
mDisplayMetrics.widthPixels = metrics.widthPixels;
|
mDisplayMetrics.widthPixels = metrics.widthPixels;
|
||||||
mDisplayMetrics.xdpi = metrics.xdpi;
|
mDisplayMetrics.xdpi = metrics.xdpi;
|
||||||
mDisplayMetrics.ydpi = metrics.ydpi;
|
mDisplayMetrics.ydpi = metrics.ydpi;
|
||||||
|
|
||||||
styledAttributes.recycle();
|
styledAttributes.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
try {
|
final ContentResolver resolver = getContentResolver();
|
||||||
mCurConfig.updateFrom(
|
mFontScale = Settings.System.getFloat(resolver, Settings.System.FONT_SCALE, 1.0f);
|
||||||
ActivityManagerNative.getDefault().getConfiguration());
|
|
||||||
} catch (RemoteException e) {
|
if (mFontScale < 1) {
|
||||||
}
|
|
||||||
if (mCurConfig.fontScale < 1) {
|
|
||||||
mFontSize.setSelection(0);
|
mFontSize.setSelection(0);
|
||||||
} else if (mCurConfig.fontScale > 1) {
|
} else if (mFontScale > 1) {
|
||||||
mFontSize.setSelection(2);
|
mFontSize.setSelection(2);
|
||||||
} else {
|
} else {
|
||||||
mFontSize.setSelection(1);
|
mFontSize.setSelection(1);
|
||||||
@@ -96,18 +93,14 @@ public class Display extends Activity implements View.OnClickListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateFontScale() {
|
private void updateFontScale() {
|
||||||
mDisplayMetrics.scaledDensity = mDisplayMetrics.density *
|
mDisplayMetrics.scaledDensity = mDisplayMetrics.density * mFontScale;
|
||||||
mCurConfig.fontScale;
|
|
||||||
|
|
||||||
float size = mTextSizeTyped.getDimension(mDisplayMetrics);
|
float size = mTextSizeTyped.getDimension(mDisplayMetrics);
|
||||||
mPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
|
mPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
try {
|
final ContentResolver resolver = getContentResolver();
|
||||||
ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig);
|
Settings.System.putFloat(resolver, Settings.System.FONT_SCALE, mFontScale);
|
||||||
} catch (RemoteException e) {
|
|
||||||
}
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,11 +109,11 @@ public class Display extends Activity implements View.OnClickListener {
|
|||||||
public void onItemSelected(android.widget.AdapterView av, View v,
|
public void onItemSelected(android.widget.AdapterView av, View v,
|
||||||
int position, long id) {
|
int position, long id) {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
mCurConfig.fontScale = .75f;
|
mFontScale = .75f;
|
||||||
} else if (position == 2) {
|
} else if (position == 2) {
|
||||||
mCurConfig.fontScale = 1.25f;
|
mFontScale = 1.25f;
|
||||||
} else {
|
} else {
|
||||||
mCurConfig.fontScale = 1.0f;
|
mFontScale = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFontScale();
|
updateFontScale();
|
||||||
@@ -134,5 +127,5 @@ public class Display extends Activity implements View.OnClickListener {
|
|||||||
private TextView mPreview;
|
private TextView mPreview;
|
||||||
private TypedValue mTextSizeTyped;
|
private TypedValue mTextSizeTyped;
|
||||||
private DisplayMetrics mDisplayMetrics;
|
private DisplayMetrics mDisplayMetrics;
|
||||||
private Configuration mCurConfig = new Configuration();
|
private float mFontScale = 1.0f;
|
||||||
}
|
}
|
||||||
|
@@ -88,8 +88,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private Preference mFontSizePref;
|
private Preference mFontSizePref;
|
||||||
|
|
||||||
private final Configuration mCurConfig = new Configuration();
|
|
||||||
|
|
||||||
private RestrictedListPreference mScreenTimeoutPreference;
|
private RestrictedListPreference mScreenTimeoutPreference;
|
||||||
private ListPreference mNightModePreference;
|
private ListPreference mNightModePreference;
|
||||||
private Preference mScreenSaverPreference;
|
private Preference mScreenSaverPreference;
|
||||||
@@ -411,11 +409,14 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateFontSizeSummary() {
|
private void updateFontSizeSummary() {
|
||||||
final Resources res = mFontSizePref.getContext().getResources();
|
final Context context = mFontSizePref.getContext();
|
||||||
|
final float currentScale = Settings.System.getFloat(context.getContentResolver(),
|
||||||
|
Settings.System.FONT_SCALE, 1.0f);
|
||||||
|
final Resources res = context.getResources();
|
||||||
final String[] entries = res.getStringArray(R.array.entries_font_size);
|
final String[] entries = res.getStringArray(R.array.entries_font_size);
|
||||||
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
|
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
|
||||||
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(
|
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(currentScale,
|
||||||
res.getConfiguration().fontScale, strEntryValues);
|
strEntryValues);
|
||||||
mFontSizePref.setSummary(entries[index]);
|
mFontSizePref.setSummary(entries[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,13 +17,11 @@
|
|||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
import android.app.ActivityManagerNative;
|
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -624,11 +622,13 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateFontSizeSummary(Preference pref) {
|
private void updateFontSizeSummary(Preference pref) {
|
||||||
|
final float currentScale = Settings.System.getFloat(getContext().getContentResolver(),
|
||||||
|
Settings.System.FONT_SCALE, 1.0f);
|
||||||
final Resources res = getContext().getResources();
|
final Resources res = getContext().getResources();
|
||||||
final String[] entries = res.getStringArray(R.array.entries_font_size);
|
final String[] entries = res.getStringArray(R.array.entries_font_size);
|
||||||
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
|
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
|
||||||
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(
|
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(currentScale,
|
||||||
res.getConfiguration().fontScale, strEntryValues);
|
strEntryValues);
|
||||||
pref.setSummary(entries[index]);
|
pref.setSummary(entries[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,12 +21,11 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.PreviewSeekBarPreferenceFragment;
|
import com.android.settings.PreviewSeekBarPreferenceFragment;
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.ActivityManagerNative;
|
import android.content.ContentResolver;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preference fragment used to control font size.
|
* Preference fragment used to control font size.
|
||||||
@@ -44,11 +43,13 @@ public class ToggleFontSizePreferenceFragment extends PreviewSeekBarPreferenceFr
|
|||||||
mPreviewSampleResIds = new int[]{R.layout.font_size_preview};
|
mPreviewSampleResIds = new int[]{R.layout.font_size_preview};
|
||||||
|
|
||||||
Resources res = getContext().getResources();
|
Resources res = getContext().getResources();
|
||||||
|
final ContentResolver resolver = getContext().getContentResolver();
|
||||||
// Mark the appropriate item in the preferences list.
|
// Mark the appropriate item in the preferences list.
|
||||||
final Configuration origConfig = res.getConfiguration();
|
|
||||||
mEntries = res.getStringArray(R.array.entries_font_size);
|
mEntries = res.getStringArray(R.array.entries_font_size);
|
||||||
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
|
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
|
||||||
mInitialIndex = fontSizeValueToIndex(origConfig.fontScale, strEntryValues);
|
final float currentScale =
|
||||||
|
Settings.System.getFloat(resolver, Settings.System.FONT_SCALE, 1.0f);
|
||||||
|
mInitialIndex = fontSizeValueToIndex(currentScale, strEntryValues);
|
||||||
mValues = new float[strEntryValues.length];
|
mValues = new float[strEntryValues.length];
|
||||||
for (int i = 0; i < strEntryValues.length; ++i) {
|
for (int i = 0; i < strEntryValues.length; ++i) {
|
||||||
mValues[i] = Float.parseFloat(strEntryValues[i]);
|
mValues[i] = Float.parseFloat(strEntryValues[i]);
|
||||||
@@ -64,17 +65,12 @@ public class ToggleFontSizePreferenceFragment extends PreviewSeekBarPreferenceFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persists the selected font size and sends a configuration change.
|
* Persists the selected font size.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void commit() {
|
protected void commit() {
|
||||||
Configuration config = getContext().getResources().getConfiguration();
|
final ContentResolver resolver = getContext().getContentResolver();
|
||||||
config.fontScale = mValues[mCurrentIndex];
|
Settings.System.putFloat(resolver, Settings.System.FONT_SCALE, mValues[mCurrentIndex]);
|
||||||
try {
|
|
||||||
ActivityManagerNative.getDefault().updatePersistentConfiguration(config);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.w(LOG_TAG, "Unable to save font size setting");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -98,4 +94,4 @@ public class ToggleFontSizePreferenceFragment extends PreviewSeekBarPreferenceFr
|
|||||||
return indices.length-1;
|
return indices.length-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user