summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2011-05-16 12:57:00 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-05-16 12:57:00 -0700
commitd90a2c4d4463085155444efb07eba2d6579b444a (patch)
tree32467c0ecbd3648b4f393d2234b8ad686cf69a3f /core/java/android
parente23639e0386735df50ad208078f638c38f662d42 (diff)
parent1e662c3294b740ff694ad98e4d9a366e1e4b5e62 (diff)
downloadframeworks_base-d90a2c4d4463085155444efb07eba2d6579b444a.zip
frameworks_base-d90a2c4d4463085155444efb07eba2d6579b444a.tar.gz
frameworks_base-d90a2c4d4463085155444efb07eba2d6579b444a.tar.bz2
am 1e662c32: Merge "DO NOT MERGE. Integrate from master: Rework display size access." into honeycomb-mr2
* commit '1e662c3294b740ff694ad98e4d9a366e1e4b5e62': DO NOT MERGE. Integrate from master: Rework display size access.
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/Activity.java12
-rw-r--r--core/java/android/app/backup/WallpaperBackupHelper.java7
-rw-r--r--core/java/android/view/Display.java118
-rw-r--r--core/java/android/view/IWindowManager.aidl4
-rwxr-xr-xcore/java/android/view/InputDevice.java4
-rw-r--r--core/java/android/view/KeyCharacterMap.java2
-rw-r--r--core/java/android/view/View.java2
-rw-r--r--core/java/android/view/ViewRoot.java5
8 files changed, 115 insertions, 39 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 6ba5c35..e3fb358 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -819,18 +819,6 @@ public class Activity extends ContextThemeWrapper
return mWindow != null ? mWindow.getCurrentFocus() : null;
}
- @Override
- public int getWallpaperDesiredMinimumWidth() {
- int width = super.getWallpaperDesiredMinimumWidth();
- return width <= 0 ? getWindowManager().getDefaultDisplay().getWidth() : width;
- }
-
- @Override
- public int getWallpaperDesiredMinimumHeight() {
- int height = super.getWallpaperDesiredMinimumHeight();
- return height <= 0 ? getWindowManager().getDefaultDisplay().getHeight() : height;
- }
-
/**
* Called when the activity is starting. This is where most initialization
* should go: calling {@link #setContentView(int)} to inflate the
diff --git a/core/java/android/app/backup/WallpaperBackupHelper.java b/core/java/android/app/backup/WallpaperBackupHelper.java
index 55368d6..0c034cf 100644
--- a/core/java/android/app/backup/WallpaperBackupHelper.java
+++ b/core/java/android/app/backup/WallpaperBackupHelper.java
@@ -19,6 +19,7 @@ package android.app.backup;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.BitmapFactory;
+import android.graphics.Point;
import android.os.ParcelFileDescriptor;
import android.util.Slog;
import android.view.Display;
@@ -70,8 +71,10 @@ public class WallpaperBackupHelper extends FileBackupHelperBase implements Backu
if (mDesiredMinWidth <= 0 || mDesiredMinHeight <= 0) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display d = wm.getDefaultDisplay();
- mDesiredMinWidth = d.getWidth();
- mDesiredMinHeight = d.getHeight();
+ Point size = new Point();
+ d.getSize(size);
+ mDesiredMinWidth = size.x;
+ mDesiredMinHeight = size.y;
}
if (DEBUG) {
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java
index 89767f2..0ea461b 100644
--- a/core/java/android/view/Display.java
+++ b/core/java/android/view/Display.java
@@ -16,10 +16,15 @@
package android.view;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
import android.util.DisplayMetrics;
+import android.util.Slog;
-public class Display
-{
+public class Display {
/**
* Specify the default Display
*/
@@ -35,10 +40,10 @@ public class Display
Display(int display) {
// initalize the statics when this class is first instansiated. This is
// done here instead of in the static block because Zygote
- synchronized (mStaticInit) {
- if (!mInitialized) {
+ synchronized (sStaticInit) {
+ if (!sInitialized) {
nativeClassInit();
- mInitialized = true;
+ sInitialized = true;
}
}
mDisplay = display;
@@ -60,29 +65,92 @@ public class Display
native static int getDisplayCount();
/**
- * Returns the raw width of the display, in pixels. Note that this
+ * Returns the raw size of the display, in pixels. Note that this
* should <em>not</em> generally be used for computing layouts, since
* a device will typically have screen decoration (such as a status bar)
* along the edges of the display that reduce the amount of application
* space available from the raw size returned here. This value is
* adjusted for you based on the current rotation of the display.
*/
- native public int getWidth();
+ public void getSize(Point outSize) {
+ try {
+ IWindowManager wm = getWindowManager();
+ if (wm != null) {
+ wm.getDisplaySize(outSize);
+ } else {
+ // This is just for boot-strapping, initializing the
+ // system process before the window manager is up.
+ outSize.y = getRealHeight();
+ }
+ } catch (RemoteException e) {
+ Slog.w("Display", "Unable to get display size", e);
+ }
+ }
/**
- * Returns the raw height of the display, in pixels. Note that this
- * should <em>not</em> generally be used for computing layouts, since
- * a device will typically have screen decoration (such as a status bar)
- * along the edges of the display that reduce the amount of application
- * space available from the raw size returned here. This value is
- * adjusted for you based on the current rotation of the display.
+ * This is just easier for some parts of the framework.
*/
- native public int getHeight();
+ public void getRectSize(Rect outSize) {
+ synchronized (mTmpPoint) {
+ getSize(mTmpPoint);
+ outSize.set(0, 0, mTmpPoint.x, mTmpPoint.y);
+ }
+ }
- /** @hide special for when we are faking the screen size. */
+ /**
+ * Return the maximum screen size dimension that will happen. This is
+ * mostly for wallpapers.
+ * @hide
+ */
+ public int getMaximumSizeDimension() {
+ try {
+ IWindowManager wm = getWindowManager();
+ return wm.getMaximumSizeDimension();
+ } catch (RemoteException e) {
+ Slog.w("Display", "Unable to get display maximum size dimension", e);
+ return 0;
+ }
+ }
+
+ /**
+ * @deprecated Use {@link #getSize(Point)} instead.
+ */
+ @Deprecated
+ public int getWidth() {
+ synchronized (mTmpPoint) {
+ long now = SystemClock.uptimeMillis();
+ if (now > (mLastGetTime+20)) {
+ getSize(mTmpPoint);
+ mLastGetTime = now;
+ }
+ return mTmpPoint.x;
+ }
+ }
+
+ /**
+ * @deprecated Use {@link #getSize(Point)} instead.
+ */
+ @Deprecated
+ public int getHeight() {
+ synchronized (mTmpPoint) {
+ long now = SystemClock.uptimeMillis();
+ if (now > (mLastGetTime+20)) {
+ getSize(mTmpPoint);
+ mLastGetTime = now;
+ }
+ return mTmpPoint.y;
+ }
+ }
+
+ /** @hide Returns the actual screen size, not including any decor. */
native public int getRealWidth();
- /** @hide special for when we are faking the screen size. */
+ /** @hide Returns the actual screen size, not including any decor. */
native public int getRealHeight();
+
+ /** @hide special for when we are faking the screen size. */
+ native public int getRawWidth();
+ /** @hide special for when we are faking the screen size. */
+ native public int getRawHeight();
/**
* Returns the rotation of the screen from its "natural" orientation.
@@ -144,6 +212,16 @@ public class Display
outMetrics.realHeightPixels = outMetrics.heightPixels;
}
+ static IWindowManager getWindowManager() {
+ synchronized (sStaticInit) {
+ if (sWindowManager == null) {
+ sWindowManager = IWindowManager.Stub.asInterface(
+ ServiceManager.getService("window"));
+ }
+ return sWindowManager;
+ }
+ }
+
/*
* We use a class initializer to allow the native code to cache some
* field offsets.
@@ -160,8 +238,12 @@ public class Display
private float mDpiX;
private float mDpiY;
- private static final Object mStaticInit = new Object();
- private static boolean mInitialized = false;
+ private final Point mTmpPoint = new Point();
+ private float mLastGetTime;
+
+ private static final Object sStaticInit = new Object();
+ private static boolean sInitialized = false;
+ private static IWindowManager sWindowManager;
/**
* Returns a display object which uses the metric's width/height instead.
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index dd8242a..0be02a6 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -21,6 +21,7 @@ import com.android.internal.view.IInputMethodClient;
import android.content.res.Configuration;
import android.graphics.Bitmap;
+import android.graphics.Point;
import android.view.IApplicationToken;
import android.view.IOnKeyguardExitResult;
import android.view.IRotationWatcher;
@@ -52,6 +53,9 @@ interface IWindowManager
in IInputContext inputContext);
boolean inputMethodClientHasFocus(IInputMethodClient client);
+ void getDisplaySize(out Point size);
+ int getMaximumSizeDimension();
+
// These can only be called when injecting events to your own window,
// or by holding the INJECT_EVENTS permission. These methods may block
// until pending input events are finished being dispatched even when 'sync' is false.
diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java
index 98d4eb9..8cb68f9 100755
--- a/core/java/android/view/InputDevice.java
+++ b/core/java/android/view/InputDevice.java
@@ -290,7 +290,7 @@ public final class InputDevice implements Parcelable {
* @return The input device or null if not found.
*/
public static InputDevice getDevice(int id) {
- IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
+ IWindowManager wm = Display.getWindowManager();
try {
return wm.getInputDevice(id);
} catch (RemoteException ex) {
@@ -304,7 +304,7 @@ public final class InputDevice implements Parcelable {
* @return The input device ids.
*/
public static int[] getDeviceIds() {
- IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
+ IWindowManager wm = Display.getWindowManager();
try {
return wm.getInputDeviceIds();
} catch (RemoteException ex) {
diff --git a/core/java/android/view/KeyCharacterMap.java b/core/java/android/view/KeyCharacterMap.java
index 3ff7fcd..885a75f 100644
--- a/core/java/android/view/KeyCharacterMap.java
+++ b/core/java/android/view/KeyCharacterMap.java
@@ -527,7 +527,7 @@ public class KeyCharacterMap {
*/
public static boolean[] deviceHasKeys(int[] keyCodes) {
boolean[] ret = new boolean[keyCodes.length];
- IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
+ IWindowManager wm = Display.getWindowManager();
try {
wm.hasKeys(keyCodes, ret);
} catch (RemoteException e) {
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 5a96efd..8e3e699 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -4855,7 +4855,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
return;
}
Display d = WindowManagerImpl.getDefault().getDefaultDisplay();
- outRect.set(0, 0, d.getWidth(), d.getHeight());
+ d.getRectSize(outRect);
}
/**
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index 7d6e18f..2ba28c6 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -255,9 +255,8 @@ public final class ViewRoot extends Handler implements ViewParent,
if (!mInitialized) {
try {
InputMethodManager imm = InputMethodManager.getInstance(mainLooper);
- sWindowSession = IWindowManager.Stub.asInterface(
- ServiceManager.getService("window"))
- .openSession(imm.getClient(), imm.getInputContext());
+ sWindowSession = Display.getWindowManager().openSession(
+ imm.getClient(), imm.getInputContext());
mInitialized = true;
} catch (RemoteException e) {
}