Remove ActivityManagerNative dependency for adjusting font scale
ActivityManagerService now holds a ContentObserver for Settings.System.FONT_SCALE, so it is no longer necessary to notify ActivityManagerNative of a configuration update involving the font scale directly. Bug:23033258 Change-Id: Ifd002bd25724b133e83a1285be2953019178c65a
This commit is contained in:
@@ -17,12 +17,11 @@
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.Settings;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
@@ -80,14 +79,12 @@ public class Display extends Activity implements View.OnClickListener {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
try {
|
||||
mCurConfig.updateFrom(
|
||||
ActivityManagerNative.getDefault().getConfiguration());
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
if (mCurConfig.fontScale < 1) {
|
||||
final ContentResolver resolver = getContentResolver();
|
||||
mFontScale = Settings.System.getFloat(resolver, Settings.System.FONT_SCALE, 1.0f);
|
||||
|
||||
if (mFontScale < 1) {
|
||||
mFontSize.setSelection(0);
|
||||
} else if (mCurConfig.fontScale > 1) {
|
||||
} else if (mFontScale > 1) {
|
||||
mFontSize.setSelection(2);
|
||||
} else {
|
||||
mFontSize.setSelection(1);
|
||||
@@ -96,18 +93,14 @@ public class Display extends Activity implements View.OnClickListener {
|
||||
}
|
||||
|
||||
private void updateFontScale() {
|
||||
mDisplayMetrics.scaledDensity = mDisplayMetrics.density *
|
||||
mCurConfig.fontScale;
|
||||
|
||||
mDisplayMetrics.scaledDensity = mDisplayMetrics.density * mFontScale;
|
||||
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) {
|
||||
}
|
||||
final ContentResolver resolver = getContentResolver();
|
||||
Settings.System.putFloat(resolver, Settings.System.FONT_SCALE, mFontScale);
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -116,11 +109,11 @@ public class Display extends Activity implements View.OnClickListener {
|
||||
public void onItemSelected(android.widget.AdapterView av, View v,
|
||||
int position, long id) {
|
||||
if (position == 0) {
|
||||
mCurConfig.fontScale = .75f;
|
||||
mFontScale = .75f;
|
||||
} else if (position == 2) {
|
||||
mCurConfig.fontScale = 1.25f;
|
||||
mFontScale = 1.25f;
|
||||
} else {
|
||||
mCurConfig.fontScale = 1.0f;
|
||||
mFontScale = 1.0f;
|
||||
}
|
||||
|
||||
updateFontScale();
|
||||
@@ -134,5 +127,5 @@ public class Display extends Activity implements View.OnClickListener {
|
||||
private TextView mPreview;
|
||||
private TypedValue mTextSizeTyped;
|
||||
private DisplayMetrics mDisplayMetrics;
|
||||
private Configuration mCurConfig = new Configuration();
|
||||
private float mFontScale = 1.0f;
|
||||
}
|
||||
|
@@ -86,8 +86,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
|
||||
private Preference mFontSizePref;
|
||||
|
||||
private final Configuration mCurConfig = new Configuration();
|
||||
|
||||
private RestrictedListPreference mScreenTimeoutPreference;
|
||||
private ListPreference mNightModePreference;
|
||||
private Preference mScreenSaverPreference;
|
||||
@@ -401,11 +399,14 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
|
||||
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[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
|
||||
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(
|
||||
res.getConfiguration().fontScale, strEntryValues);
|
||||
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(currentScale,
|
||||
strEntryValues);
|
||||
mFontSizePref.setSummary(entries[index]);
|
||||
}
|
||||
|
||||
|
@@ -17,13 +17,11 @@
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@@ -624,11 +622,13 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
|
||||
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 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);
|
||||
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(currentScale,
|
||||
strEntryValues);
|
||||
pref.setSummary(entries[index]);
|
||||
}
|
||||
|
||||
|
@@ -21,12 +21,11 @@ import com.android.settings.R;
|
||||
import com.android.settings.PreviewSeekBarPreferenceFragment;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.provider.Settings;
|
||||
|
||||
/**
|
||||
* Preference fragment used to control font size.
|
||||
@@ -44,11 +43,13 @@ public class ToggleFontSizePreferenceFragment extends PreviewSeekBarPreferenceFr
|
||||
mPreviewSampleResIds = new int[]{R.layout.font_size_preview};
|
||||
|
||||
Resources res = getContext().getResources();
|
||||
final ContentResolver resolver = getContext().getContentResolver();
|
||||
// Mark the appropriate item in the preferences list.
|
||||
final Configuration origConfig = res.getConfiguration();
|
||||
mEntries = res.getStringArray(R.array.entries_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];
|
||||
for (int i = 0; i < strEntryValues.length; ++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
|
||||
protected void commit() {
|
||||
Configuration config = getContext().getResources().getConfiguration();
|
||||
config.fontScale = mValues[mCurrentIndex];
|
||||
try {
|
||||
ActivityManagerNative.getDefault().updatePersistentConfiguration(config);
|
||||
} catch (RemoteException e) {
|
||||
Log.w(LOG_TAG, "Unable to save font size setting");
|
||||
}
|
||||
final ContentResolver resolver = getContext().getContentResolver();
|
||||
Settings.System.putFloat(resolver, Settings.System.FONT_SCALE, mValues[mCurrentIndex]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user