From dde331cebd87982faded6818ad5f9927ff994c96 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Fri, 3 Aug 2012 14:01:57 -0700 Subject: We can now (kind-of) change screen density on the fly. Preloaded drawables now have a density associated with them, so we can load the correct drawable if we are using a different density. Window manager now formally keeps track of the density for each screen, allowing it to be overridden like you can already do with size, and relies on this density to drive itself internally and the configurations it reports. There are a new set of Bitmap constructors where you provide a DisplayMetrics so they can be constructed with the correct density. (This will be for when you can have different windows in the same app running at different densities.) ActivityThread now watches for density changes, and pushes them to the DENSITY_DEVICE and Bitmap global density values for that process. A new am command allows you to change the density. --- cmds/am/src/com/android/commands/am/Am.java | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'cmds/am') diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java index f42fd2a..a79eb14 100644 --- a/cmds/am/src/com/android/commands/am/Am.java +++ b/cmds/am/src/com/android/commands/am/Am.java @@ -133,6 +133,8 @@ public class Am { runScreenCompat(); } else if (op.equals("display-size")) { runDisplaySize(); + } else if (op.equals("display-density")) { + runDisplayDensity(); } else if (op.equals("to-uri")) { runToUri(false); } else if (op.equals("to-intent-uri")) { @@ -1127,6 +1129,44 @@ public class Am { } } + private void runDisplayDensity() throws Exception { + String densityStr = nextArgRequired(); + int density; + if ("reset".equals(densityStr)) { + density = -1; + } else { + try { + density = Integer.parseInt(densityStr); + } catch (NumberFormatException e) { + System.err.println("Error: bad number " + e); + showUsage(); + return; + } + if (density < 72) { + System.err.println("Error: density must be >= 72"); + showUsage(); + return; + } + } + + IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.checkService( + Context.WINDOW_SERVICE)); + if (wm == null) { + System.err.println(NO_SYSTEM_ERROR_CODE); + throw new AndroidException("Can't connect to window manager; is the system running?"); + } + + try { + if (density > 0) { + // TODO(multidisplay): For now Configuration only applies to main screen. + wm.setForcedDisplayDensity(Display.DEFAULT_DISPLAY, density); + } else { + wm.clearForcedDisplayDensity(Display.DEFAULT_DISPLAY); + } + } catch (RemoteException e) { + } + } + private void runToUri(boolean intentScheme) throws Exception { Intent intent = makeIntent(); System.out.println(intent.toUri(intentScheme ? Intent.URI_INTENT_SCHEME : 0)); @@ -1301,6 +1341,7 @@ public class Am { " am monitor [--gdb ]\n" + " am screen-compat [on|off] \n" + " am display-size [reset|MxN]\n" + + " am display-density [reset|DENSITY]\n" + " am to-uri [INTENT]\n" + " am to-intent-uri [INTENT]\n" + "\n" + @@ -1355,6 +1396,8 @@ public class Am { "\n" + "am display-size: override display size.\n" + "\n" + + "am display-density: override display density.\n" + + "\n" + "am to-uri: print the given Intent specification as a URI.\n" + "\n" + "am to-intent-uri: print the given Intent specification as an intent: URI.\n" + -- cgit v1.1