Merge "Fix 5158468: Update floating window size when the anchor view size changes."

This commit is contained in:
Chih-Chung Chang
2011-09-28 04:48:06 -07:00
committed by Android (Google) Code Review
2 changed files with 52 additions and 26 deletions

View File

@@ -75,6 +75,7 @@ public class MediaController extends FrameLayout {
private WindowManager mWindowManager; private WindowManager mWindowManager;
private Window mWindow; private Window mWindow;
private View mDecor; private View mDecor;
private WindowManager.LayoutParams mDecorLayoutParams;
private ProgressBar mProgress; private ProgressBar mProgress;
private TextView mEndTime, mCurrentTime; private TextView mEndTime, mCurrentTime;
private boolean mShowing; private boolean mShowing;
@@ -120,6 +121,7 @@ public class MediaController extends FrameLayout {
mContext = context; mContext = context;
mUseFastForward = true; mUseFastForward = true;
initFloatingWindow(); initFloatingWindow();
initFloatingWindowLayout();
} }
private void initFloatingWindow() { private void initFloatingWindow() {
@@ -142,6 +144,48 @@ public class MediaController extends FrameLayout {
requestFocus(); requestFocus();
} }
// Allocate and initialize the static parts of mDecorLayoutParams. Must
// also call updateFloatingWindowLayout() to fill in the dynamic parts
// (y and width) before mDecorLayoutParams can be used.
private void initFloatingWindowLayout() {
mDecorLayoutParams = new WindowManager.LayoutParams();
WindowManager.LayoutParams p = mDecorLayoutParams;
p.gravity = Gravity.TOP;
p.height = LayoutParams.WRAP_CONTENT;
p.x = 0;
p.format = PixelFormat.TRANSLUCENT;
p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
p.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
p.token = null;
p.windowAnimations = 0; // android.R.style.DropDownAnimationDown;
}
// Update the dynamic parts of mDecorLayoutParams
// Must be called with mAnchor != NULL.
private void updateFloatingWindowLayout() {
int [] anchorPos = new int[2];
mAnchor.getLocationOnScreen(anchorPos);
WindowManager.LayoutParams p = mDecorLayoutParams;
p.width = mAnchor.getWidth();
p.y = anchorPos[1] + mAnchor.getHeight();
}
// This is called whenever mAnchor's layout bound changes
private OnLayoutChangeListener mLayoutChangeListener =
new OnLayoutChangeListener() {
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight,
int oldBottom) {
updateFloatingWindowLayout();
if (mShowing) {
mWindowManager.updateViewLayout(mDecor, mDecorLayoutParams);
}
}
};
private OnTouchListener mTouchListener = new OnTouchListener() { private OnTouchListener mTouchListener = new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getAction() == MotionEvent.ACTION_DOWN) {
@@ -164,7 +208,13 @@ public class MediaController extends FrameLayout {
* @param view The view to which to anchor the controller when it is visible. * @param view The view to which to anchor the controller when it is visible.
*/ */
public void setAnchorView(View view) { public void setAnchorView(View view) {
if (mAnchor != null) {
mAnchor.removeOnLayoutChangeListener(mLayoutChangeListener);
}
mAnchor = view; mAnchor = view;
if (mAnchor != null) {
mAnchor.addOnLayoutChangeListener(mLayoutChangeListener);
}
FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
@@ -279,31 +329,14 @@ public class MediaController extends FrameLayout {
* the controller until hide() is called. * the controller until hide() is called.
*/ */
public void show(int timeout) { public void show(int timeout) {
if (!mShowing && mAnchor != null) { if (!mShowing && mAnchor != null) {
setProgress(); setProgress();
if (mPauseButton != null) { if (mPauseButton != null) {
mPauseButton.requestFocus(); mPauseButton.requestFocus();
} }
disableUnsupportedButtons(); disableUnsupportedButtons();
updateFloatingWindowLayout();
int [] anchorpos = new int[2]; mWindowManager.addView(mDecor, mDecorLayoutParams);
mAnchor.getLocationOnScreen(anchorpos);
WindowManager.LayoutParams p = new WindowManager.LayoutParams();
p.gravity = Gravity.TOP;
p.width = mAnchor.getWidth();
p.height = LayoutParams.WRAP_CONTENT;
p.x = 0;
p.y = anchorpos[1] + mAnchor.getHeight() - p.height;
p.format = PixelFormat.TRANSLUCENT;
p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
p.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
p.token = null;
p.windowAnimations = 0; // android.R.style.DropDownAnimationDown;
mWindowManager.addView(mDecor, p);
mShowing = true; mShowing = true;
} }
updatePausePlay(); updatePausePlay();

View File

@@ -456,13 +456,6 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
seekTo(mSeekWhenPrepared); seekTo(mSeekWhenPrepared);
} }
start(); start();
if (mMediaController != null) {
if (mMediaController.isShowing()) {
// ensure the controller will get repositioned later
mMediaController.hide();
}
mMediaController.show();
}
} }
} }