Merge "Remove show/hide API"
diff --git a/packages/MediaComponents/src/com/android/widget/MediaControlView2Impl.java b/packages/MediaComponents/src/com/android/widget/MediaControlView2Impl.java
index 688aadc..b4aaa79 100644
--- a/packages/MediaComponents/src/com/android/widget/MediaControlView2Impl.java
+++ b/packages/MediaComponents/src/com/android/widget/MediaControlView2Impl.java
@@ -56,7 +56,6 @@
private static final int MAX_PROGRESS = 1000;
private static final int DEFAULT_PROGRESS_UPDATE_TIME_MS = 1000;
- private static final int DEFAULT_TIMEOUT_MS = 2000;
private static final int REWIND_TIME_MS = 10000;
private static final int FORWARD_TIME_MS = 30000;
@@ -72,6 +71,8 @@
private TextView mTitleView;
private int mDuration;
private int mPrevState;
+ private int mCurrentVisibility;
+ private long mTimeout;
private long mPlaybackActions;
private boolean mShowing;
private boolean mDragging;
@@ -115,6 +116,9 @@
// Inflate MediaControlView2 from XML
View root = makeControllerView();
mInstance.addView(root);
+
+ // Set default timeout
+ mTimeout = 2000;
}
@Override
@@ -134,50 +138,8 @@
}
@Override
- public void show_impl() {
- mInstance.show(DEFAULT_TIMEOUT_MS);
- }
-
- @Override
- public void show_impl(long timeout) {
- if (!mShowing) {
- setProgress();
- if (mPlayPauseButton != null) {
- mPlayPauseButton.requestFocus();
- }
- disableUnsupportedButtons();
- mInstance.setVisibility(View.VISIBLE);
- mShowing = true;
- }
- // cause the progress bar to be updated even if mShowing
- // was already true. This happens, for example, if we're
- // paused with the progress bar showing the user hits play.
- mInstance.post(mShowProgress);
-
- if (timeout != 0 && !mAccessibilityManager.isTouchExplorationEnabled()) {
- mInstance.removeCallbacks(mFadeOut);
- mInstance.postDelayed(mFadeOut, timeout);
- }
- }
-
- @Override
public boolean isShowing_impl() {
- return mShowing;
- }
-
- @Override
- public void hide_impl() {
- if (mShowing) {
- try {
- mInstance.removeCallbacks(mShowProgress);
- // Remove existing call to mFadeOut to avoid from being called later.
- mInstance.removeCallbacks(mFadeOut);
- mInstance.setVisibility(View.GONE);
- } catch (IllegalArgumentException ex) {
- Log.w(TAG, "already removed");
- }
- mShowing = false;
- }
+ return (mInstance.getVisibility() == View.VISIBLE) ? true : false;
}
@Override
@@ -248,6 +210,46 @@
}
@Override
+ public void requestPlayButtonFocus_impl() {
+ if (mPlayPauseButton != null) {
+ mPlayPauseButton.requestFocus();
+ }
+ }
+
+ @Override
+ public void setTimeout_impl(long timeout) {
+ mTimeout = timeout;
+ }
+
+ @Override
+ public long getTimeout_impl() {
+ return mTimeout;
+ }
+
+ @Override
+ public void onVisibilityAggregated_impl(boolean invisible) {
+ int visibility = mInstance.getVisibility();
+ if (mCurrentVisibility != visibility) {
+ mInstance.setVisibility(visibility);
+ mCurrentVisibility = visibility;
+
+ if (visibility == View.VISIBLE) {
+ setProgress();
+ disableUnsupportedButtons();
+ // cause the progress bar to be updated even if mShowing
+ // was already true. This happens, for example, if we're
+ // paused with the progress bar showing the user hits play.
+ mInstance.post(mShowProgress);
+ resetFadeOutRunnable();
+ } else if (visibility == View.GONE) {
+ mInstance.removeCallbacks(mShowProgress);
+ // Remove existing call to mFadeOut to avoid from being called later.
+ mInstance.removeCallbacks(mFadeOut);
+ }
+ }
+ }
+
+ @Override
public void onAttachedToWindow_impl() {
mSuperProvider.onAttachedToWindow_impl();
}
@@ -270,7 +272,7 @@
// TODO: Should this function be removed?
@Override
public boolean onTrackballEvent_impl(MotionEvent ev) {
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ resetFadeOutRunnable();
return false;
}
@@ -483,7 +485,7 @@
@Override
public void run() {
if (isPlaying()) {
- mInstance.hide();
+ mInstance.setVisibility(View.GONE);
}
}
};
@@ -499,6 +501,13 @@
}
};
+ private void resetFadeOutRunnable() {
+ if (mTimeout != 0 && !mAccessibilityManager.isTouchExplorationEnabled()) {
+ mInstance.removeCallbacks(mFadeOut);
+ mInstance.postDelayed(mFadeOut, mTimeout);
+ }
+ }
+
private String stringForTime(int timeMs) {
int totalSeconds = timeMs / 1000;
@@ -572,9 +581,9 @@
if (!mSeekAvailable) {
return;
}
- mInstance.show(3600000);
mDragging = true;
+ mInstance.removeCallbacks(mFadeOut);
// By removing these pending progress messages we make sure
// that a) we won't update the progress while the user adjusts
@@ -622,7 +631,8 @@
mDragging = false;
setProgress();
- mInstance.show(DEFAULT_TIMEOUT_MS);
+
+ resetFadeOutRunnable();
// Ensure that progress is properly updated in the future,
// the call to show() does not guarantee this because it is a
@@ -635,7 +645,7 @@
@Override
public void onClick(View v) {
togglePausePlayState();
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ resetFadeOutRunnable();
}
};
@@ -646,7 +656,7 @@
mControls.seekTo(pos);
setProgress();
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ resetFadeOutRunnable();
}
};
@@ -657,7 +667,7 @@
mControls.seekTo(pos);
setProgress();
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ resetFadeOutRunnable();
}
};
@@ -665,7 +675,7 @@
@Override
public void onClick(View v) {
mControls.skipToNext();
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ resetFadeOutRunnable();
}
};
@@ -673,7 +683,7 @@
@Override
public void onClick(View v) {
mControls.skipToPrevious();
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ resetFadeOutRunnable();
}
};
@@ -693,7 +703,7 @@
mController.sendCommand(MediaControlView2.COMMAND_HIDE_SUBTITLE, null, null);
mSubtitleIsEnabled = false;
}
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ resetFadeOutRunnable();
}
};
@@ -715,7 +725,7 @@
mController.sendCommand(MediaControlView2.COMMAND_SET_FULLSCREEN, args, null);
mIsFullScreen = isEnteringFullScreen;
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ resetFadeOutRunnable();
}
};
@@ -724,7 +734,7 @@
public void onClick(View v) {
mBasicControls.setVisibility(View.GONE);
mExtraControls.setVisibility(View.VISIBLE);
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ resetFadeOutRunnable();
}
};
@@ -733,6 +743,7 @@
public void onClick(View v) {
mBasicControls.setVisibility(View.VISIBLE);
mExtraControls.setVisibility(View.GONE);
+ resetFadeOutRunnable();
}
};
@@ -830,7 +841,7 @@
// TODO: Currently, we are just sending extras that came from session.
// Is it the right behavior?
mControls.sendCustomAction(actionString, action.getExtras());
- mInstance.show(DEFAULT_TIMEOUT_MS);
+ mInstance.setVisibility(View.VISIBLE);
}
});
mCustomButtons.addView(button);
diff --git a/packages/MediaComponents/src/com/android/widget/VideoView2Impl.java b/packages/MediaComponents/src/com/android/widget/VideoView2Impl.java
index 38ade41..a8864fc 100644
--- a/packages/MediaComponents/src/com/android/widget/VideoView2Impl.java
+++ b/packages/MediaComponents/src/com/android/widget/VideoView2Impl.java
@@ -452,7 +452,7 @@
+ ", mTargetState=" + mTargetState + ", " + view.toString());
}
if (mMediaControlView != null) {
- mMediaControlView.hide();
+ mMediaControlView.setVisibility(View.GONE);
}
}
@@ -674,9 +674,9 @@
private void toggleMediaControlViewVisibility() {
if (mMediaControlView.isShowing()) {
- mMediaControlView.hide();
+ mMediaControlView.setVisibility(View.GONE);
} else {
- mMediaControlView.show();
+ mMediaControlView.setVisibility(View.VISIBLE);
}
}
@@ -763,14 +763,17 @@
if (needToStart()) {
mMediaController.getTransportControls().play();
if (mMediaControlView != null) {
- mMediaControlView.show();
+ mMediaControlView.setVisibility(View.VISIBLE);
}
} else if (!(isInPlaybackState() && mMediaPlayer.isPlaying())
&& (seekToPosition != 0 || mMediaPlayer.getCurrentPosition() > 0)) {
if (mMediaControlView != null) {
// Show the media controls when we're paused into a video and
// make them stick.
- mMediaControlView.show(0);
+ long currTimeout = mMediaControlView.getTimeout();
+ mMediaControlView.setTimeout(0L);
+ mMediaControlView.setVisibility(View.VISIBLE);
+ mMediaControlView.setTimeout(currTimeout);
}
}
} else {
@@ -834,7 +837,7 @@
updatePlaybackState();
if (mMediaControlView != null) {
- mMediaControlView.hide();
+ mMediaControlView.setVisibility(View.GONE);
}
/* If an error handler has been supplied, use it and finish. */