OverlayDisplayWindowpublic final class OverlayDisplayWindow extends Object implements DumpUtils.DumpManages an overlay window on behalf of {@link OverlayDisplayAdapter}.
This object must only be accessed on the UI thread.
No locks are held by this object and locks must not be held while making called into it.
|
Fields Summary |
---|
private static final String | TAG | private static final boolean | DEBUG | private final float | INITIAL_SCALE | private final float | MIN_SCALE | private final float | MAX_SCALE | private final float | WINDOW_ALPHA | private final boolean | DISABLE_MOVE_AND_RESIZE | private final android.content.Context | mContext | private final String | mName | private final int | mWidth | private final int | mHeight | private final int | mDensityDpi | private final int | mGravity | private final boolean | mSecure | private final Listener | mListener | private String | mTitle | private final android.hardware.display.DisplayManager | mDisplayManager | private final android.view.WindowManager | mWindowManager | private final android.view.Display | mDefaultDisplay | private final android.view.DisplayInfo | mDefaultDisplayInfo | private android.view.View | mWindowContent | private WindowManager.LayoutParams | mWindowParams | private android.view.TextureView | mTextureView | private android.widget.TextView | mTitleTextView | private android.view.GestureDetector | mGestureDetector | private android.view.ScaleGestureDetector | mScaleGestureDetector | private boolean | mWindowVisible | private int | mWindowX | private int | mWindowY | private float | mWindowScale | private float | mLiveTranslationX | private float | mLiveTranslationY | private float | mLiveScale | private final DisplayManager.DisplayListener | mDisplayListener | private final android.view.TextureView.SurfaceTextureListener | mSurfaceTextureListener | private final View.OnTouchListener | mOnTouchListener | private final GestureDetector.OnGestureListener | mOnGestureListener | private final ScaleGestureDetector.OnScaleGestureListener | mOnScaleGestureListener |
Constructors Summary |
---|
public OverlayDisplayWindow(android.content.Context context, String name, int width, int height, int densityDpi, int gravity, boolean secure, Listener listener)
mContext = context;
mName = name;
mWidth = width;
mHeight = height;
mDensityDpi = densityDpi;
mGravity = gravity;
mSecure = secure;
mListener = listener;
mTitle = context.getResources().getString(
com.android.internal.R.string.display_manager_overlay_display_title,
mName, mWidth, mHeight, mDensityDpi);
if (secure) {
mTitle += context.getResources().getString(
com.android.internal.R.string.display_manager_overlay_display_secure_suffix);
}
mDisplayManager = (DisplayManager)context.getSystemService(
Context.DISPLAY_SERVICE);
mWindowManager = (WindowManager)context.getSystemService(
Context.WINDOW_SERVICE);
mDefaultDisplay = mWindowManager.getDefaultDisplay();
updateDefaultDisplayInfo();
createWindow();
|
Methods Summary |
---|
private void | clearLiveState()
mLiveTranslationX = 0f;
mLiveTranslationY = 0f;
mLiveScale = 1.0f;
| private void | createWindow()
LayoutInflater inflater = LayoutInflater.from(mContext);
mWindowContent = inflater.inflate(
com.android.internal.R.layout.overlay_display_window, null);
mWindowContent.setOnTouchListener(mOnTouchListener);
mTextureView = (TextureView)mWindowContent.findViewById(
com.android.internal.R.id.overlay_display_window_texture);
mTextureView.setPivotX(0);
mTextureView.setPivotY(0);
mTextureView.getLayoutParams().width = mWidth;
mTextureView.getLayoutParams().height = mHeight;
mTextureView.setOpaque(false);
mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
mTitleTextView = (TextView)mWindowContent.findViewById(
com.android.internal.R.id.overlay_display_window_title);
mTitleTextView.setText(mTitle);
mWindowParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY);
mWindowParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
if (mSecure) {
mWindowParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
}
if (DISABLE_MOVE_AND_RESIZE) {
mWindowParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
}
mWindowParams.privateFlags |=
WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
mWindowParams.alpha = WINDOW_ALPHA;
mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
mWindowParams.setTitle(mTitle);
mGestureDetector = new GestureDetector(mContext, mOnGestureListener);
mScaleGestureDetector = new ScaleGestureDetector(mContext, mOnScaleGestureListener);
// Set the initial position and scale.
// The position and scale will be clamped when the display is first shown.
mWindowX = (mGravity & Gravity.LEFT) == Gravity.LEFT ?
0 : mDefaultDisplayInfo.logicalWidth;
mWindowY = (mGravity & Gravity.TOP) == Gravity.TOP ?
0 : mDefaultDisplayInfo.logicalHeight;
mWindowScale = INITIAL_SCALE;
| public void | dismiss()
if (mWindowVisible) {
mDisplayManager.unregisterDisplayListener(mDisplayListener);
mWindowManager.removeView(mWindowContent);
mWindowVisible = false;
}
| public void | dump(java.io.PrintWriter pw)
pw.println("mWindowVisible=" + mWindowVisible);
pw.println("mWindowX=" + mWindowX);
pw.println("mWindowY=" + mWindowY);
pw.println("mWindowScale=" + mWindowScale);
pw.println("mWindowParams=" + mWindowParams);
if (mTextureView != null) {
pw.println("mTextureView.getScaleX()=" + mTextureView.getScaleX());
pw.println("mTextureView.getScaleY()=" + mTextureView.getScaleY());
}
pw.println("mLiveTranslationX=" + mLiveTranslationX);
pw.println("mLiveTranslationY=" + mLiveTranslationY);
pw.println("mLiveScale=" + mLiveScale);
| public void | relayout()
if (mWindowVisible) {
updateWindowParams();
mWindowManager.updateViewLayout(mWindowContent, mWindowParams);
}
| private void | saveWindowParams()
mWindowX = mWindowParams.x;
mWindowY = mWindowParams.y;
mWindowScale = mTextureView.getScaleX();
clearLiveState();
| public void | show()
if (!mWindowVisible) {
mDisplayManager.registerDisplayListener(mDisplayListener, null);
if (!updateDefaultDisplayInfo()) {
mDisplayManager.unregisterDisplayListener(mDisplayListener);
return;
}
clearLiveState();
updateWindowParams();
mWindowManager.addView(mWindowContent, mWindowParams);
mWindowVisible = true;
}
| private boolean | updateDefaultDisplayInfo()
if (!mDefaultDisplay.getDisplayInfo(mDefaultDisplayInfo)) {
Slog.w(TAG, "Cannot show overlay display because there is no "
+ "default display upon which to show it.");
return false;
}
return true;
| private void | updateWindowParams()
float scale = mWindowScale * mLiveScale;
scale = Math.min(scale, (float)mDefaultDisplayInfo.logicalWidth / mWidth);
scale = Math.min(scale, (float)mDefaultDisplayInfo.logicalHeight / mHeight);
scale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, scale));
float offsetScale = (scale / mWindowScale - 1.0f) * 0.5f;
int width = (int)(mWidth * scale);
int height = (int)(mHeight * scale);
int x = (int)(mWindowX + mLiveTranslationX - width * offsetScale);
int y = (int)(mWindowY + mLiveTranslationY - height * offsetScale);
x = Math.max(0, Math.min(x, mDefaultDisplayInfo.logicalWidth - width));
y = Math.max(0, Math.min(y, mDefaultDisplayInfo.logicalHeight - height));
if (DEBUG) {
Slog.d(TAG, "updateWindowParams: scale=" + scale
+ ", offsetScale=" + offsetScale
+ ", x=" + x + ", y=" + y
+ ", width=" + width + ", height=" + height);
}
mTextureView.setScaleX(scale);
mTextureView.setScaleY(scale);
mWindowParams.x = x;
mWindowParams.y = y;
mWindowParams.width = width;
mWindowParams.height = height;
|
|