OSDN Git Service

DisplaySettings: remove the use of DefaultDensity and add a wider DPI range
authorJaap Jan Meijer <jjmeijer88@gmail.com>
Wed, 14 Sep 2016 19:28:40 +0000 (21:28 +0200)
committerJaap Jan Meijer <jjmeijer88@gmail.com>
Wed, 14 Sep 2016 19:34:21 +0000 (21:34 +0200)
Since we are setting the density in surfaceflinger DefaultDensity is not usable.
To allow more flexibility the density range is now wider and based on current density.

src/com/android/settings/DisplaySettings.java

index a434e97..3c85024 100644 (file)
@@ -208,25 +208,24 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
             if (UserHandle.myUserId() != UserHandle.USER_OWNER) {
                 interfacePrefs.removePreference(mLcdDensityPreference);
             } else {
-                int defaultDensity = getDefaultDensity();
                 int currentDensity = getCurrentDensity();
                 if (currentDensity < 10 || currentDensity >= 1000) {
-                    // Unsupported value, force default
-                    currentDensity = defaultDensity;
+                    // Unsupported value, force 160 DPI
+                    currentDensity = 160;
                 }
 
-                int factor = defaultDensity >= 480 ? 40 : 20;
-                int minimumDensity = defaultDensity - 4 * factor;
+                int factor = currentDensity >= 480 ? 40 : 20;
+                int minimumDensity = currentDensity - 5 * factor;
                 int currentIndex = -1;
-                String[] densityEntries = new String[7];
-                String[] densityValues = new String[7];
-                for (int idx = 0; idx < 7; ++idx) {
+                String[] densityEntries = new String[9];
+                String[] densityValues = new String[9];
+                if (minimumDensity < 60) {
+                    minimumDensity = 60;
+                }
+                for (int idx = 0; idx < 11; ++idx) {
                     int val = minimumDensity + factor * idx;
-                    int valueFormatResId = val == defaultDensity
-                            ? R.string.lcd_density_default_value_format
-                            : R.string.lcd_density_value_format;
 
-                    densityEntries[idx] = getString(valueFormatResId, val);
+                    densityEntries[idx] = getString(R.string.lcd_density_value_format, val);
                     densityValues[idx] = Integer.toString(val);
                     if (currentDensity == val) {
                         currentIndex = idx;
@@ -333,17 +332,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
         initPulse((PreferenceCategory) findPreference(KEY_CATEGORY_LIGHTS));
     }
 
-    private int getDefaultDensity() {
-        IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.checkService(
-                Context.WINDOW_SERVICE));
-        try {
-            return wm.getInitialDisplayDensity(Display.DEFAULT_DISPLAY);
-        } catch (RemoteException e) {
-            e.printStackTrace();
-        }
-        return DisplayMetrics.DENSITY_DEVICE;
-    }
-
     private int getCurrentDensity() {
         IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.checkService(
                 Context.WINDOW_SERVICE));
@@ -460,9 +448,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
     }
 
     private void updateLcdDensityPreferenceDescription(int currentDensity) {
-        final int summaryResId = currentDensity == getDefaultDensity()
-                ? R.string.lcd_density_default_value_format : R.string.lcd_density_value_format;
-        mLcdDensityPreference.setSummary(getString(summaryResId, currentDensity));
+        mLcdDensityPreference.setSummary(getString(R.string.lcd_density_value_format, currentDensity));
     }
 
     private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) {