summaryrefslogtreecommitdiffstats
path: root/core/java/android/content/res
diff options
context:
space:
mode:
authorMitsuru Oshima <oshima@google.com>2009-07-08 15:59:16 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-07-08 15:59:16 -0700
commitc3f60ddaeadb69c1e85198e609e575f55ecc28ac (patch)
treea865ed6aed999a7ab3076478ea079e447439ce23 /core/java/android/content/res
parent2291616d846dcc7ed81ac534ff45962e6056ad12 (diff)
parent1ecf5d28817f0a051e77488380dcd5bc622ea169 (diff)
downloadframeworks_base-c3f60ddaeadb69c1e85198e609e575f55ecc28ac.zip
frameworks_base-c3f60ddaeadb69c1e85198e609e575f55ecc28ac.tar.gz
frameworks_base-c3f60ddaeadb69c1e85198e609e575f55ecc28ac.tar.bz2
am 1ecf5d28: Re-implementation of large screen support using window manager. * added background filler surface to fill the outer rim. Using the same layer as dim surface because they never co-exists (in the same window) * clean up the obsolete code in Compatibilt
Merge commit '1ecf5d28817f0a051e77488380dcd5bc622ea169' * commit '1ecf5d28817f0a051e77488380dcd5bc622ea169': Re-implementation of large screen support using window manager.
Diffstat (limited to 'core/java/android/content/res')
-rw-r--r--core/java/android/content/res/CompatibilityInfo.java244
1 files changed, 45 insertions, 199 deletions
diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java
index dfe304d..ebe556e 100644
--- a/core/java/android/content/res/CompatibilityInfo.java
+++ b/core/java/android/content/res/CompatibilityInfo.java
@@ -51,18 +51,6 @@ public class CompatibilityInfo {
public static final int DEFAULT_PORTRAIT_HEIGHT = 480;
/**
- * The x-shift mode that controls the position of the content or the window under
- * compatibility mode.
- * {@see getTranslator}
- * {@see Translator#mShiftMode}
- */
- private static final int X_SHIFT_NONE = 0;
- private static final int X_SHIFT_CONTENT = 1;
- private static final int X_SHIFT_AND_CLIP_CONTENT = 2;
- private static final int X_SHIFT_WINDOW = 3;
-
-
- /**
* A compatibility flags
*/
private int mCompatibilityFlags;
@@ -106,20 +94,6 @@ public class CompatibilityInfo {
*/
public final int appFlags;
- /**
- * Window size in Compatibility Mode, in real pixels. This is updated by
- * {@link DisplayMetrics#updateMetrics}.
- */
- private int mWidth;
- private int mHeight;
-
- /**
- * The x offset to center the window content. In X_SHIFT_WINDOW mode, the offset is added
- * to the window's layout. In X_SHIFT_CONTENT/X_SHIFT_AND_CLIP_CONTENT mode, the offset
- * is used to translate the Canvas.
- */
- private int mXOffset;
-
public CompatibilityInfo(ApplicationInfo appInfo) {
appFlags = appInfo.flags;
@@ -153,6 +127,7 @@ public class CompatibilityInfo {
applicationScale =
DisplayMetrics.DEVICE_DENSITY / (float) DisplayMetrics.DEFAULT_DENSITY;
}
+
applicationInvertedScale = 1.0f / applicationScale;
if (applicationScale != 1.0f) {
mCompatibilityFlags |= SCALING_REQUIRED;
@@ -181,23 +156,10 @@ public class CompatibilityInfo {
public CompatibilityInfo copy() {
CompatibilityInfo info = new CompatibilityInfo(appFlags, mCompatibilityFlags,
applicationScale, applicationInvertedScale);
- info.setVisibleRect(mXOffset, mWidth, mHeight);
return info;
}
/**
- * Sets the application's visible rect in compatibility mode.
- * @param xOffset the application's x offset that is added to center the content.
- * @param widthPixels the application's width in real pixels on the screen.
- * @param heightPixels the application's height in real pixels on the screen.
- */
- public void setVisibleRect(int xOffset, int widthPixels, int heightPixels) {
- this.mXOffset = xOffset;
- mWidth = widthPixels;
- mHeight = heightPixels;
- }
-
- /**
* Sets expandable bit in the compatibility flag.
*/
public void setExpandable(boolean expandable) {
@@ -222,6 +184,10 @@ public class CompatibilityInfo {
return (mCompatibilityFlags & SCALING_REQUIRED) != 0;
}
+ public boolean supportsScreen() {
+ return (mCompatibilityFlags & CompatibilityInfo.EXPANDABLE) != 0;
+ }
+
@Override
public String toString() {
return "CompatibilityInfo{scale=" + applicationScale +
@@ -231,21 +197,6 @@ public class CompatibilityInfo {
/**
* Returns the translator which can translate the coordinates of the window.
* There are five different types of Translator.
- *
- * 1) {@link CompatibilityInfo#X_SHIFT_AND_CLIP_CONTENT}
- * Shift and clip the content of the window at drawing time. Used for activities'
- * main window (with no gravity).
- * 2) {@link CompatibilityInfo#X_SHIFT_CONTENT}
- * Shift the content of the window at drawing time. Used for windows that is created by
- * an application and expected to be aligned with the application window.
- * 3) {@link CompatibilityInfo#X_SHIFT_WINDOW}
- * Create the window with adjusted x- coordinates. This is typically used
- * in popup window, where it has to be placed relative to main window.
- * 4) {@link CompatibilityInfo#X_SHIFT_NONE}
- * No adjustment required, such as dialog.
- * 5) Same as X_SHIFT_WINDOW, but no scaling. This is used by {@link SurfaceView}, which
- * does not require scaling, but its window's location has to be adjusted.
- *
* @param params the window's parameter
*/
public Translator getTranslator(WindowManager.LayoutParams params) {
@@ -254,35 +205,11 @@ public class CompatibilityInfo {
if (DBG) Log.d(TAG, "no translation required");
return null;
}
-
- if ((mCompatibilityFlags & CompatibilityInfo.EXPANDABLE) == 0) {
- if ((params.flags & WindowManager.LayoutParams.FLAG_NO_COMPATIBILITY_SCALING) != 0) {
- if (DBG) Log.d(TAG, "translation for surface view selected");
- return new Translator(X_SHIFT_WINDOW, false, 1.0f, 1.0f);
- } else {
- int shiftMode;
- if (params.gravity == Gravity.NO_GRAVITY) {
- // For Regular Application window
- shiftMode = X_SHIFT_AND_CLIP_CONTENT;
- if (DBG) Log.d(TAG, "shift and clip translator");
- } else if (params.width == WindowManager.LayoutParams.FILL_PARENT) {
- // For Regular Application window
- shiftMode = X_SHIFT_CONTENT;
- if (DBG) Log.d(TAG, "shift content translator");
- } else if ((params.gravity & Gravity.LEFT) != 0 && params.x > 0) {
- shiftMode = X_SHIFT_WINDOW;
- if (DBG) Log.d(TAG, "shift window translator");
- } else {
- shiftMode = X_SHIFT_NONE;
- if (DBG) Log.d(TAG, "no content/window translator");
- }
- return new Translator(shiftMode);
- }
- } else if (isScalingRequired()) {
- return new Translator();
- } else {
+ if (!isScalingRequired() ||
+ (params.flags & WindowManager.LayoutParams.FLAG_NO_COMPATIBILITY_SCALING) != 0) {
return null;
}
+ return new Translator();
}
/**
@@ -290,97 +217,48 @@ public class CompatibilityInfo {
* @hide
*/
public class Translator {
- final private int mShiftMode;
- final public boolean scalingRequired;
final public float applicationScale;
final public float applicationInvertedScale;
private Rect mContentInsetsBuffer = null;
- private Rect mVisibleInsets = null;
+ private Rect mVisibleInsetsBuffer = null;
- Translator(int shiftMode, boolean scalingRequired, float applicationScale,
- float applicationInvertedScale) {
- mShiftMode = shiftMode;
- this.scalingRequired = scalingRequired;
+ Translator(float applicationScale, float applicationInvertedScale) {
this.applicationScale = applicationScale;
this.applicationInvertedScale = applicationInvertedScale;
}
- Translator(int shiftMode) {
- this(shiftMode,
- isScalingRequired(),
- CompatibilityInfo.this.applicationScale,
- CompatibilityInfo.this.applicationInvertedScale);
- }
-
Translator() {
- this(X_SHIFT_NONE);
+ this(CompatibilityInfo.this.applicationScale,
+ CompatibilityInfo.this.applicationInvertedScale);
}
/**
* Translate the screen rect to the application frame.
*/
public void translateRectInScreenToAppWinFrame(Rect rect) {
- if (rect.isEmpty()) return; // skip if the window size is empty.
- switch (mShiftMode) {
- case X_SHIFT_AND_CLIP_CONTENT:
- rect.intersect(0, 0, mWidth, mHeight);
- break;
- case X_SHIFT_CONTENT:
- rect.intersect(0, 0, mWidth + mXOffset, mHeight);
- break;
- case X_SHIFT_WINDOW:
- case X_SHIFT_NONE:
- break;
- }
- if (scalingRequired) {
- rect.scale(applicationInvertedScale);
- }
+ rect.scale(applicationInvertedScale);
}
/**
* Translate the region in window to screen.
*/
public void translateRegionInWindowToScreen(Region transparentRegion) {
- switch (mShiftMode) {
- case X_SHIFT_AND_CLIP_CONTENT:
- case X_SHIFT_CONTENT:
- transparentRegion.scale(applicationScale);
- transparentRegion.translate(mXOffset, 0);
- break;
- case X_SHIFT_WINDOW:
- case X_SHIFT_NONE:
- transparentRegion.scale(applicationScale);
- }
+ transparentRegion.scale(applicationScale);
}
/**
* Apply translation to the canvas that is necessary to draw the content.
*/
public void translateCanvas(Canvas canvas) {
- if (mShiftMode == X_SHIFT_CONTENT ||
- mShiftMode == X_SHIFT_AND_CLIP_CONTENT) {
- // TODO: clear outside when rotation is changed.
-
- // Translate x-offset only when the content is shifted.
- canvas.translate(mXOffset, 0);
- }
- if (scalingRequired) {
- canvas.scale(applicationScale, applicationScale);
- }
+ canvas.scale(applicationScale, applicationScale);
}
/**
* Translate the motion event captured on screen to the application's window.
*/
public void translateEventInScreenToAppWindow(MotionEvent event) {
- if (mShiftMode == X_SHIFT_CONTENT ||
- mShiftMode == X_SHIFT_AND_CLIP_CONTENT) {
- event.translate(-mXOffset, 0);
- }
- if (scalingRequired) {
- event.scale(applicationInvertedScale);
- }
+ event.scale(applicationInvertedScale);
}
/**
@@ -388,62 +266,21 @@ public class CompatibilityInfo {
* Screen's view.
*/
public void translateWindowLayout(WindowManager.LayoutParams params) {
- switch (mShiftMode) {
- case X_SHIFT_NONE:
- case X_SHIFT_AND_CLIP_CONTENT:
- case X_SHIFT_CONTENT:
- params.scale(applicationScale);
- break;
- case X_SHIFT_WINDOW:
- params.scale(applicationScale);
- params.x += mXOffset;
- break;
- }
+ params.scale(applicationScale);
}
/**
* Translate a Rect in application's window to screen.
*/
public void translateRectInAppWindowToScreen(Rect rect) {
- // TODO Auto-generated method stub
- if (scalingRequired) {
- rect.scale(applicationScale);
- }
- switch(mShiftMode) {
- case X_SHIFT_NONE:
- case X_SHIFT_WINDOW:
- break;
- case X_SHIFT_CONTENT:
- case X_SHIFT_AND_CLIP_CONTENT:
- rect.offset(mXOffset, 0);
- break;
- }
+ rect.scale(applicationScale);
}
/**
* Translate a Rect in screen coordinates into the app window's coordinates.
*/
public void translateRectInScreenToAppWindow(Rect rect) {
- switch (mShiftMode) {
- case X_SHIFT_NONE:
- case X_SHIFT_WINDOW:
- break;
- case X_SHIFT_CONTENT: {
- rect.intersects(mXOffset, 0, rect.right, rect.bottom);
- int dx = Math.min(mXOffset, rect.left);
- rect.offset(-dx, 0);
- break;
- }
- case X_SHIFT_AND_CLIP_CONTENT: {
- rect.intersects(mXOffset, 0, mWidth + mXOffset, mHeight);
- int dx = Math.min(mXOffset, rect.left);
- rect.offset(-dx, 0);
- break;
- }
- }
- if (scalingRequired) {
- rect.scale(applicationInvertedScale);
- }
+ rect.scale(applicationInvertedScale);
}
/**
@@ -451,19 +288,7 @@ public class CompatibilityInfo {
* @param params
*/
public void translateLayoutParamsInAppWindowToScreen(LayoutParams params) {
- if (scalingRequired) {
- params.scale(applicationScale);
- }
- switch (mShiftMode) {
- // the window location on these mode does not require adjustmenet.
- case X_SHIFT_NONE:
- case X_SHIFT_WINDOW:
- break;
- case X_SHIFT_CONTENT:
- case X_SHIFT_AND_CLIP_CONTENT:
- params.x += mXOffset;
- break;
- }
+ params.scale(applicationScale);
}
/**
@@ -482,10 +307,31 @@ public class CompatibilityInfo {
* the internal buffer for content insets to avoid extra object allocation.
*/
public Rect getTranslatedVisbileInsets(Rect visibleInsets) {
- if (mVisibleInsets == null) mVisibleInsets = new Rect();
- mVisibleInsets.set(visibleInsets);
- translateRectInAppWindowToScreen(mVisibleInsets);
- return mVisibleInsets;
+ if (mVisibleInsetsBuffer == null) mVisibleInsetsBuffer = new Rect();
+ mVisibleInsetsBuffer.set(visibleInsets);
+ translateRectInAppWindowToScreen(mVisibleInsetsBuffer);
+ return mVisibleInsetsBuffer;
+ }
+ }
+
+ /**
+ * Returns the frame Rect for applications runs under compatibility mode.
+ *
+ * @param dm the display metrics used to compute the frame size.
+ * @param orientation the orientation of the screen.
+ * @param outRect the output parameter which will contain the result.
+ */
+ public static void updateCompatibleScreenFrame(DisplayMetrics dm, int orientation,
+ Rect outRect) {
+ int width = dm.widthPixels;
+ int portraitHeight = (int) (DEFAULT_PORTRAIT_HEIGHT * dm.density);
+ int portraitWidth = (int) (DEFAULT_PORTRAIT_WIDTH * dm.density);
+ if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ int xOffset = (width - portraitHeight) / 2 ;
+ outRect.set(xOffset, 0, xOffset + portraitHeight, portraitWidth);
+ } else {
+ int xOffset = (width - portraitWidth) / 2 ;
+ outRect.set(xOffset, 0, xOffset + portraitWidth, portraitHeight);
}
}
}