summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/gallery3d/app/CommonControllerOverlay.java16
-rw-r--r--src/com/android/gallery3d/app/ControllerOverlay.java6
-rw-r--r--src/com/android/gallery3d/app/MovieActivity.java93
-rw-r--r--src/com/android/gallery3d/app/MovieControllerOverlay.java796
-rwxr-xr-xsrc/com/android/gallery3d/app/MoviePlayer.java323
-rwxr-xr-x[-rw-r--r--]src/com/android/gallery3d/app/TimeBar.java308
-rw-r--r--src/com/android/gallery3d/app/TrimControllerOverlay.java10
7 files changed, 1466 insertions, 86 deletions
diff --git a/src/com/android/gallery3d/app/CommonControllerOverlay.java b/src/com/android/gallery3d/app/CommonControllerOverlay.java
index 9adb4e7a8..7a553e906 100644
--- a/src/com/android/gallery3d/app/CommonControllerOverlay.java
+++ b/src/com/android/gallery3d/app/CommonControllerOverlay.java
@@ -47,10 +47,13 @@ public abstract class CommonControllerOverlay extends FrameLayout implements
PAUSED,
ENDED,
ERROR,
- LOADING
+ LOADING,
+ BUFFERING,
+ RETRY_CONNECTING,
+ RETRY_CONNECTING_ERROR
}
- private static final float ERROR_MESSAGE_RELATIVE_PADDING = 1.0f / 6;
+ protected static final float ERROR_MESSAGE_RELATIVE_PADDING = 1.0f / 6;
protected Listener mListener;
@@ -96,13 +99,9 @@ public abstract class CommonControllerOverlay extends FrameLayout implements
ProgressBar spinner = new ProgressBar(context);
spinner.setIndeterminate(true);
mLoadingView.addView(spinner, wrapContent);
- TextView loadingText = createOverlayTextView(context);
- loadingText.setText(R.string.loading_video);
- mLoadingView.addView(loadingText, wrapContent);
addView(mLoadingView, wrapContent);
mPlayPauseReplayView = new ImageView(context);
- mPlayPauseReplayView.setImageResource(R.drawable.ic_vidcontrol_play);
mPlayPauseReplayView.setContentDescription(
context.getResources().getString(R.string.accessibility_play_video));
mPlayPauseReplayView.setBackgroundResource(R.drawable.bg_vidcontrol);
@@ -119,7 +118,6 @@ public abstract class CommonControllerOverlay extends FrameLayout implements
new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
setLayoutParams(params);
- hide();
}
abstract protected void createTimeBar(Context context);
@@ -252,7 +250,7 @@ public abstract class CommonControllerOverlay extends FrameLayout implements
// | Navigation Bar | insets.bottom
// +-----------------+/
// Please see View.fitSystemWindows() for more details.
- private final Rect mWindowInsets = new Rect();
+ protected final Rect mWindowInsets = new Rect();
@Override
protected boolean fitSystemWindows(Rect insets) {
@@ -290,7 +288,7 @@ public abstract class CommonControllerOverlay extends FrameLayout implements
}
}
- private void layoutCenteredView(View view, int l, int t, int r, int b) {
+ protected void layoutCenteredView(View view, int l, int t, int r, int b) {
int cw = view.getMeasuredWidth();
int ch = view.getMeasuredHeight();
int cl = (r - l - cw) / 2;
diff --git a/src/com/android/gallery3d/app/ControllerOverlay.java b/src/com/android/gallery3d/app/ControllerOverlay.java
index 36eda6257..6f049da2d 100644
--- a/src/com/android/gallery3d/app/ControllerOverlay.java
+++ b/src/com/android/gallery3d/app/ControllerOverlay.java
@@ -55,4 +55,10 @@ public interface ControllerOverlay {
void setTimes(int currentTime, int totalTime,
int trimStartTime, int trimEndTime);
+
+ //set view enabled (play/pause asynchronous processing)
+ void setViewEnabled(boolean isEnabled);
+
+ //view from disable to resume (play/pause asynchronous processing)
+ void setPlayPauseReplayResume();
}
diff --git a/src/com/android/gallery3d/app/MovieActivity.java b/src/com/android/gallery3d/app/MovieActivity.java
index 6577fe271..7fb5954d3 100644
--- a/src/com/android/gallery3d/app/MovieActivity.java
+++ b/src/com/android/gallery3d/app/MovieActivity.java
@@ -30,6 +30,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.res.Configuration;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
@@ -65,8 +66,9 @@ import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.ui.Knob;
import org.codeaurora.gallery3d.ext.IActivityHooker;
-import org.codeaurora.gallery3d.ext.MovieItem;
import org.codeaurora.gallery3d.ext.IMovieItem;
+import org.codeaurora.gallery3d.ext.MovieItem;
+import org.codeaurora.gallery3d.ext.MovieUtils;
import org.codeaurora.gallery3d.video.ExtensionHelper;
import org.codeaurora.gallery3d.video.MovieTitleHelper;
@@ -79,20 +81,21 @@ import org.codeaurora.gallery3d.video.MovieTitleHelper;
*/
public class MovieActivity extends Activity {
@SuppressWarnings("unused")
- private static final String TAG = "MovieActivity";
+ private static final String TAG = "MovieActivity";
private static final boolean LOG = true;
- public static final String KEY_LOGO_BITMAP = "logo-bitmap";
- public static final String KEY_TREAT_UP_AS_BACK = "treat-up-as-back";
- private static final String VIDEO_SDP_MIME_TYPE = "application/sdp";
- private static final String VIDEO_SDP_TITLE = "rtsp://";
- private static final String VIDEO_FILE_SCHEMA = "file";
- private static final String VIDEO_MIME_TYPE = "video/*";
+ public static final String KEY_LOGO_BITMAP = "logo-bitmap";
+ public static final String KEY_TREAT_UP_AS_BACK = "treat-up-as-back";
+ private static final String VIDEO_SDP_MIME_TYPE = "application/sdp";
+ private static final String VIDEO_SDP_TITLE = "rtsp://";
+ private static final String VIDEO_FILE_SCHEMA = "file";
+ private static final String VIDEO_MIME_TYPE = "video/*";
+ private static final String SHARE_HISTORY_FILE = "video_share_history_file";
private MoviePlayer mPlayer;
- private boolean mFinishOnCompletion;
- private Uri mUri;
+ private boolean mFinishOnCompletion;
+ private Uri mUri;
- private static final short BASSBOOST_MAX_STRENGTH = 1000;
+ private static final short BASSBOOST_MAX_STRENGTH = 1000;
private static final short VIRTUALIZER_MAX_STRENGTH = 1000;
private boolean mIsHeadsetOn = false;
@@ -104,17 +107,19 @@ public class MovieActivity extends Activity {
global_enabled, bb_strength, virt_strength
};
- private BassBoost mBassBoostEffect;
+ private BassBoost mBassBoostEffect;
private Virtualizer mVirtualizerEffect;
private AlertDialog mEffectDialog;
- private Switch mSwitch;
- private Knob mBassBoostKnob;
- private Knob mVirtualizerKnob;
-
- private IMovieItem mMovieItem;
- private IActivityHooker mMovieHooker;
- private KeyguardManager mKeyguardManager;
- private boolean mResumed = false;
+ private Switch mSwitch;
+ private Knob mBassBoostKnob;
+ private Knob mVirtualizerKnob;
+
+ private ShareActionProvider mShareProvider;
+ private IMovieItem mMovieItem;
+ private IActivityHooker mMovieHooker;
+ private KeyguardManager mKeyguardManager;
+
+ private boolean mResumed = false;
private boolean mControlResumed = false;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -285,17 +290,14 @@ public class MovieActivity extends Activity {
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.movie, menu);
-
- // Document says EXTRA_STREAM should be a content: Uri
- // So, we only share the video if it's "content:".
- MenuItem shareItem = menu.findItem(R.id.action_share);
- if (ContentResolver.SCHEME_CONTENT.equals(mUri.getScheme())) {
- shareItem.setVisible(true);
- ((ShareActionProvider) shareItem.getActionProvider())
- .setShareIntent(createShareIntent());
- } else {
- shareItem.setVisible(false);
+ MenuItem shareMenu = menu.findItem(R.id.action_share);
+ ShareActionProvider provider = (ShareActionProvider) shareMenu.getActionProvider();
+ mShareProvider = provider;
+ if (mShareProvider != null) {
+ // share provider is singleton, we should refresh our history file.
+ mShareProvider.setShareHistoryFileName(SHARE_HISTORY_FILE);
}
+ refreshShareProvider(mMovieItem);
final MenuItem mi = menu.add(R.string.audio_effects);
mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@@ -549,6 +551,15 @@ public class MovieActivity extends Activity {
}
@Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ||
+ this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
+ mPlayer.setDefaultScreenMode();
+ }
+ }
+
+ @Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mPlayer.onSaveInstanceState(outState);
@@ -657,6 +668,28 @@ public class MovieActivity extends Activity {
return locked;
}
+ public void refreshMovieInfo(IMovieItem info) {
+ mMovieItem = info;
+ setActionBarTitle(info.getTitle());
+ refreshShareProvider(info);
+ mMovieHooker.setParameter(null, mMovieItem);
+ }
+
+ private void refreshShareProvider(IMovieItem info) {
+ // we only share the video if it's "content:".
+ if (mShareProvider != null) {
+ Intent intent = new Intent(Intent.ACTION_SEND);
+ if (MovieUtils.isLocalFile(info.getUri(), info.getMimeType())) {
+ intent.setType("video/*");
+ intent.putExtra(Intent.EXTRA_STREAM, info.getUri());
+ } else {
+ intent.setType("text/plain");
+ intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(info.getUri()));
+ }
+ mShareProvider.setShareIntent(intent);
+ }
+ }
+
private void enhanceActionBar() {
final IMovieItem movieItem = mMovieItem;// remember original item
final Uri uri = mMovieItem.getUri();
diff --git a/src/com/android/gallery3d/app/MovieControllerOverlay.java b/src/com/android/gallery3d/app/MovieControllerOverlay.java
index f01e619c6..8c69a3136 100644
--- a/src/com/android/gallery3d/app/MovieControllerOverlay.java
+++ b/src/com/android/gallery3d/app/MovieControllerOverlay.java
@@ -17,14 +17,39 @@
package com.android.gallery3d.app;
import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.graphics.Rect;
import android.os.Handler;
+import android.util.DisplayMetrics;
+import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.ImageView.ScaleType;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
import com.android.gallery3d.R;
+import com.android.gallery3d.app.CommonControllerOverlay.State;
+import org.codeaurora.gallery3d.ext.IContrllerOverlayExt;
+import org.codeaurora.gallery3d.video.IControllerRewindAndForward;
+import org.codeaurora.gallery3d.video.IControllerRewindAndForward.IRewindAndForwardListener;
+import org.codeaurora.gallery3d.video.ExtensionHelper;
+import org.codeaurora.gallery3d.video.ScreenModeManager;
+import org.codeaurora.gallery3d.video.ScreenModeManager.ScreenModeListener;
+
/**
* The playback controller for the Movie Player.
@@ -32,15 +57,25 @@ import com.android.gallery3d.R;
public class MovieControllerOverlay extends CommonControllerOverlay implements
AnimationListener {
+ private static final String TAG = "Gallery3D/MovieControllerOverlay";
+ private static final boolean LOG = true;
+
+ private ScreenModeManager mScreenModeManager;
+ private ScreenModeExt mScreenModeExt = new ScreenModeExt();
+ private ControllerRewindAndForwardExt mControllerRewindAndForwardExt = new ControllerRewindAndForwardExt();
+ private OverlayExtension mOverlayExt = new OverlayExtension();
private boolean hidden;
private final Handler handler;
private final Runnable startHidingRunnable;
private final Animation hideAnimation;
+ private boolean enableRewindAndForward = false;
+ private Context mContext;
+
public MovieControllerOverlay(Context context) {
super(context);
-
+ mContext = context;
handler = new Handler();
startHidingRunnable = new Runnable() {
@Override
@@ -52,9 +87,62 @@ public class MovieControllerOverlay extends CommonControllerOverlay implements
hideAnimation = AnimationUtils.loadAnimation(context, R.anim.player_out);
hideAnimation.setAnimationListener(this);
+ enableRewindAndForward = true;
+ Log.v(TAG, "enableRewindAndForward is " + enableRewindAndForward);
+ mControllerRewindAndForwardExt.init(context);
+ mScreenModeExt.init(context, mTimeBar);
+ mBackground.setClickable(true);
hide();
}
+ public void showPlaying() {
+ if (!mOverlayExt.handleShowPlaying()) {
+ mState = State.PLAYING;
+ showMainView(mPlayPauseReplayView);
+ }
+ if (LOG) {
+ Log.v(TAG, "showPlaying() state=" + mState);
+ }
+ }
+
+ public void showPaused() {
+ if (!mOverlayExt.handleShowPaused()) {
+ mState = State.PAUSED;
+ showMainView(mPlayPauseReplayView);
+ }
+ if (LOG) {
+ Log.v(TAG, "showPaused() state=" + mState);
+ }
+ }
+
+ public void showEnded() {
+ mOverlayExt.onShowEnded();
+ mState = State.ENDED;
+ showMainView(mPlayPauseReplayView);
+ if (LOG) {
+ Log.v(TAG, "showEnded() state=" + mState);
+ }
+ }
+
+ public void showLoading() {
+ mOverlayExt.onShowLoading();
+ mState = State.LOADING;
+ showMainView(mLoadingView);
+ if (LOG) {
+ Log.v(TAG, "showLoading() state=" + mState);
+ }
+ }
+
+ public void showErrorMessage(String message) {
+ mOverlayExt.onShowErrorMessage(message);
+ mState = State.ERROR;
+ int padding = (int) (getMeasuredWidth() * ERROR_MESSAGE_RELATIVE_PADDING);
+ mErrorView.setPadding(padding, mErrorView.getPaddingTop(), padding,
+ mErrorView.getPaddingBottom());
+ mErrorView.setText(message);
+ showMainView(mErrorView);
+ }
+
@Override
protected void createTimeBar(Context context) {
mTimeBar = new TimeBar(context, this);
@@ -64,18 +152,44 @@ public class MovieControllerOverlay extends CommonControllerOverlay implements
public void hide() {
boolean wasHidden = hidden;
hidden = true;
- super.hide();
+ mPlayPauseReplayView.setVisibility(View.INVISIBLE);
+ mLoadingView.setVisibility(View.INVISIBLE);
+ if (!mOverlayExt.handleHide()) {
+ setVisibility(View.INVISIBLE);
+ }
+ mBackground.setVisibility(View.INVISIBLE);
+ mTimeBar.setVisibility(View.INVISIBLE);
+ mScreenModeExt.onHide();
+ if (enableRewindAndForward) {
+ mControllerRewindAndForwardExt.onHide();
+ }
+ setFocusable(true);
+ requestFocus();
if (mListener != null && wasHidden != hidden) {
mListener.onHidden();
}
}
+ private void showMainView(View view) {
+ mMainView = view;
+ mErrorView.setVisibility(mMainView == mErrorView ? View.VISIBLE
+ : View.INVISIBLE);
+ mLoadingView.setVisibility(mMainView == mLoadingView ? View.VISIBLE
+ : View.INVISIBLE);
+ mPlayPauseReplayView
+ .setVisibility(mMainView == mPlayPauseReplayView ? View.VISIBLE
+ : View.INVISIBLE);
+ mOverlayExt.onShowMainView(view);
+ show();
+ }
@Override
public void show() {
boolean wasHidden = hidden;
hidden = false;
- super.show();
+ updateViews();
+ setVisibility(View.VISIBLE);
+ setFocusable(false);
if (mListener != null && wasHidden != hidden) {
mListener.onShown();
}
@@ -90,8 +204,14 @@ public class MovieControllerOverlay extends CommonControllerOverlay implements
}
private void startHiding() {
- startHideAnimation(mBackground);
- startHideAnimation(mTimeBar);
+ if (mOverlayExt.canHidePanel()) {
+ startHideAnimation(mBackground);
+ startHideAnimation(mTimeBar);
+ mScreenModeExt.onStartHiding();
+ if (enableRewindAndForward) {
+ mControllerRewindAndForwardExt.onStartHiding();
+ }
+ }
startHideAnimation(mPlayPauseReplayView);
}
@@ -103,8 +223,14 @@ public class MovieControllerOverlay extends CommonControllerOverlay implements
private void cancelHiding() {
handler.removeCallbacks(startHidingRunnable);
- mBackground.setAnimation(null);
- mTimeBar.setAnimation(null);
+ if (mOverlayExt.canHidePanel()) {
+ mBackground.setAnimation(null);
+ mTimeBar.setAnimation(null);
+ mScreenModeExt.onCancelHiding();
+ if (enableRewindAndForward) {
+ mControllerRewindAndForwardExt.onCancelHiding();
+ }
+ }
mPlayPauseReplayView.setAnimation(null);
}
@@ -123,6 +249,61 @@ public class MovieControllerOverlay extends CommonControllerOverlay implements
hide();
}
+ public void onClick(View view) {
+ if (LOG) {
+ Log.v(TAG, "onClick(" + view + ") listener=" + mListener
+ + ", state=" + mState + ", canReplay=" + mCanReplay);
+ }
+ if (mListener != null) {
+ if (view == mPlayPauseReplayView) {
+ if (mState == State.ENDED) {
+ if (mCanReplay) {
+ mListener.onReplay();
+ }
+ } else if (mState == State.PAUSED || mState == State.PLAYING) {
+ mListener.onPlayPause();
+ // set view disabled (play/pause asynchronous processing)
+ setViewEnabled(true);
+ }
+ }
+ } else {
+ mScreenModeExt.onClick(view);
+ if (enableRewindAndForward) {
+ mControllerRewindAndForwardExt.onClick(view);
+ }
+ }
+ }
+
+ /*
+ * set view enable (non-Javadoc)
+ * @see com.android.gallery3d.app.ControllerOverlay#setViewEnabled(boolean)
+ */
+ @Override
+ public void setViewEnabled(boolean isEnabled) {
+ if (mListener.onIsRTSP()) {
+ Log.v(TAG, "setViewEnabled is " + isEnabled);
+ mOverlayExt.setCanScrubbing(isEnabled);
+ mPlayPauseReplayView.setEnabled(isEnabled);
+ if (enableRewindAndForward) {
+ mControllerRewindAndForwardExt.setViewEnabled(isEnabled);
+ }
+ }
+ }
+
+ /*
+ * set play pause button from disable to normal (non-Javadoc)
+ * @see
+ * com.android.gallery3d.app.ControllerOverlay#setPlayPauseReplayResume(
+ * void)
+ */
+ @Override
+ public void setPlayPauseReplayResume() {
+ if (mListener.onIsRTSP()) {
+ Log.v(TAG, "setPlayPauseReplayResume is enabled is true");
+ mPlayPauseReplayView.setEnabled(true);
+ }
+ }
+
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (hidden) {
@@ -144,7 +325,10 @@ public class MovieControllerOverlay extends CommonControllerOverlay implements
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
cancelHiding();
- if (mState == State.PLAYING || mState == State.PAUSED) {
+ // you can click play or pause when view is resumed
+ // play/pause asynchronous processing
+ if ((mState == State.PLAYING || mState == State.PAUSED)
+ && mOverlayExt.mEnableScrubbing) {
mListener.onPlayPause();
}
break;
@@ -156,11 +340,71 @@ public class MovieControllerOverlay extends CommonControllerOverlay implements
}
@Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ int width = ((MovieActivity) mContext).getWindowManager().getDefaultDisplay().getWidth();
+ Rect insets = mWindowInsets;
+ int pl = insets.left; // the left paddings
+ int pr = insets.right;
+ int pt = insets.top;
+ int pb = insets.bottom;
+
+ int h = bottom - top;
+ int w = right - left;
+ boolean error = mErrorView.getVisibility() == View.VISIBLE;
+
+ int y = h - pb;
+ // Put both TimeBar and Background just above the bottom system
+ // component.
+ // But extend the background to the width of the screen, since we don't
+ // care if it will be covered by a system component and it looks better.
+
+ // Needed, otherwise the framework will not re-layout in case only the
+ // padding is changed
+ if (enableRewindAndForward) {
+ mBackground.layout(0, y - mTimeBar.getPreferredHeight() - 80, w, y);
+ mTimeBar.layout(pl, y - mTimeBar.getPreferredHeight() - 80, w - pr,
+ y - mTimeBar.getBarHeight());
+ mControllerRewindAndForwardExt.onLayout(0, width, y);
+ } else {
+ mBackground.layout(0, y - mTimeBar.getBarHeight(), w, y);
+ mTimeBar.layout(pl, y - mTimeBar.getPreferredHeight(),
+ w - pr - mScreenModeExt.getAddedRightPadding(), y);
+ }
+ mScreenModeExt.onLayout(w, pr, y);
+ // Put the play/pause/next/ previous button in the center of the screen
+ layoutCenteredView(mPlayPauseReplayView, 0, 0, w, h);
+
+ if (mMainView != null) {
+ layoutCenteredView(mMainView, 0, 0, w, h);
+ }
+ }
+
+ @Override
protected void updateViews() {
if (hidden) {
return;
}
- super.updateViews();
+ mBackground.setVisibility(View.VISIBLE);
+ mTimeBar.setVisibility(View.VISIBLE);
+ mPlayPauseReplayView.setImageResource(
+ mState == State.PAUSED ? R.drawable.videoplayer_play :
+ mState == State.PLAYING ? R.drawable.videoplayer_pause :
+ R.drawable.videoplayer_reload);
+ mScreenModeExt.onShow();
+ if (enableRewindAndForward) {
+ mControllerRewindAndForwardExt.onShow();
+ }
+ if (!mOverlayExt.handleUpdateViews()) {
+ mPlayPauseReplayView.setVisibility(
+ (mState != State.LOADING && mState != State.ERROR &&
+ !(mState == State.ENDED && !mCanReplay))
+ ? View.VISIBLE : View.GONE);
+ }
+ requestLayout();
+ if (LOG) {
+ Log.v(TAG, "updateViews() state=" + mState + ", canReplay="
+ + mCanReplay);
+ }
}
// TimeBar listener
@@ -182,4 +426,538 @@ public class MovieControllerOverlay extends CommonControllerOverlay implements
maybeStartHiding();
super.onScrubbingEnd(time, trimStartTime, trimEndTime);
}
+
+ public void setScreenModeManager(ScreenModeManager manager) {
+ mScreenModeManager = manager;
+ if (mScreenModeManager != null) {
+ mScreenModeManager.addListener(mScreenModeExt);
+ }
+ if (LOG) {
+ Log.v(TAG, "setScreenModeManager(" + manager + ")");
+ }
+ }
+
+ public void setDefaultScreenMode() {
+ mScreenModeManager.setScreenMode(ScreenModeManager.SCREENMODE_BIGSCREEN);
+ }
+
+ public IContrllerOverlayExt getOverlayExt() {
+ return mOverlayExt;
+ }
+
+ public IControllerRewindAndForward getControllerRewindAndForwardExt() {
+ if (enableRewindAndForward) {
+ return mControllerRewindAndForwardExt;
+ }
+ return null;
+ }
+
+ private class OverlayExtension implements IContrllerOverlayExt {
+ private State mLastState;
+ private String mPlayingInfo;
+ // for pause feature
+ private boolean mCanPause = true;
+ private boolean mEnableScrubbing = false;
+ // for only audio feature
+ private boolean mAlwaysShowBottom;
+
+ @Override
+ public void showBuffering(boolean fullBuffer, int percent) {
+ if (LOG) {
+ Log.v(TAG, "showBuffering(" + fullBuffer + ", " + percent
+ + ") " + "lastState=" + mLastState + ", state=" + mState);
+ }
+ if (fullBuffer) {
+ // do not show text and loading
+ mTimeBar.setSecondaryProgress(percent);
+ return;
+ }
+ if (mState == State.PAUSED || mState == State.PLAYING) {
+ mLastState = mState;
+ }
+ if (percent >= 0 && percent < 100) { // valid value
+ mState = State.BUFFERING;
+ String text = "media controller buffering";
+ mTimeBar.setInfo(text);
+ showMainView(mLoadingView);
+ } else if (percent == 100) {
+ mState = mLastState;
+ mTimeBar.setInfo(null);
+ showMainView(mPlayPauseReplayView);// restore play pause state
+ } else { // here to restore old state
+ mState = mLastState;
+ mTimeBar.setInfo(null);
+ }
+ }
+
+ // set buffer percent to unknown value
+ public void clearBuffering() {
+ if (LOG) {
+ Log.v(TAG, "clearBuffering()");
+ }
+ mTimeBar.setSecondaryProgress(TimeBar.UNKNOWN);
+ showBuffering(false, TimeBar.UNKNOWN);
+ }
+
+ public void showReconnecting(int times) {
+ clearBuffering();
+ mState = State.RETRY_CONNECTING;
+ int msgId = R.string.videoview_error_text_cannot_connect_retry;
+ String text = getResources().getString(msgId, times);
+ mTimeBar.setInfo(text);
+ showMainView(mLoadingView);
+ if (LOG) {
+ Log.v(TAG, "showReconnecting(" + times + ")");
+ }
+ }
+
+ public void showReconnectingError() {
+ clearBuffering();
+ mState = State.RETRY_CONNECTING_ERROR;
+
+ String text = "can not connect to server";
+ mTimeBar.setInfo(text);
+ showMainView(mPlayPauseReplayView);
+ if (LOG) {
+ Log.v(TAG, "showReconnectingError()");
+ }
+ }
+
+ public void setPlayingInfo(boolean liveStreaming) {
+ int msgId;
+ // TODO
+ if (liveStreaming) {
+ msgId = R.string.media_controller_live;
+ } else {
+ msgId = R.string.media_controller_playing;
+ }
+ mPlayingInfo = getResources().getString(msgId);
+ if (LOG) {
+ Log.v(TAG, "setPlayingInfo(" + liveStreaming
+ + ") playingInfo=" + mPlayingInfo);
+ }
+ }
+
+ public void setCanPause(boolean canPause) {
+ this.mCanPause = canPause;
+ if (LOG) {
+ Log.v(TAG, "setCanPause(" + canPause + ")");
+ }
+ }
+
+ public void setCanScrubbing(boolean enable) {
+ mEnableScrubbing = enable;
+ mTimeBar.setScrubbing(enable);
+ if (LOG) {
+ Log.v(TAG, "setCanScrubbing(" + enable + ")");
+ }
+ }
+
+ public void setBottomPanel(boolean alwaysShow, boolean foreShow) {
+ mAlwaysShowBottom = alwaysShow;
+ if (!alwaysShow) { // clear background
+ setBackgroundDrawable(null);
+ setBackgroundColor(Color.TRANSPARENT);
+ } else {
+ setBackgroundResource(R.drawable.media_default_bkg);
+ if (foreShow) {
+ setVisibility(View.VISIBLE);
+ }
+ }
+ if (LOG) {
+ Log.v(TAG, "setBottomPanel(" + alwaysShow + ", " + foreShow
+ + ")");
+ }
+ }
+
+ public boolean isPlayingEnd() {
+ if (LOG) {
+ Log.v(TAG, "isPlayingEnd() state=" + mState);
+ }
+ boolean end = false;
+ if (State.ENDED == mState || State.ERROR == mState
+ || State.RETRY_CONNECTING_ERROR == mState) {
+ end = true;
+ }
+ return end;
+ }
+
+ public boolean handleShowPlaying() {
+ if (mState == State.BUFFERING) {
+ mLastState = State.PLAYING;
+ return true;
+ }
+ return false;
+ }
+
+ public boolean handleShowPaused() {
+ mTimeBar.setInfo(null);
+ if (mState == State.BUFFERING) {
+ mLastState = State.PAUSED;
+ return true;
+ }
+ return false;
+ }
+
+ public void onShowLoading() {
+ // TODO
+ int msgId = R.string.media_controller_connecting;
+ String text = getResources().getString(msgId);
+ mTimeBar.setInfo(text);
+ }
+
+ public void onShowEnded() {
+ clearBuffering();
+ mTimeBar.setInfo(null);
+ }
+
+ public void onShowErrorMessage(String message) {
+ clearBuffering();
+ }
+
+ public boolean handleUpdateViews() {
+ mPlayPauseReplayView
+ .setVisibility((mState != State.LOADING
+ && mState != State.ERROR
+ && mState != State.BUFFERING
+ && mState != State.RETRY_CONNECTING && !(mState != State.ENDED
+ && mState != State.RETRY_CONNECTING_ERROR && !mCanPause))
+ // for live streaming
+ ? View.VISIBLE
+ : View.GONE);
+
+ if (mPlayingInfo != null && mState == State.PLAYING) {
+ mTimeBar.setInfo(mPlayingInfo);
+ }
+ return true;
+ }
+
+ public boolean handleHide() {
+ return mAlwaysShowBottom;
+ }
+
+ public void onShowMainView(View view) {
+ if (LOG) {
+ Log.v(TAG, "showMainView(" + view + ") errorView="
+ + mErrorView + ", loadingView=" + mLoadingView
+ + ", playPauseReplayView=" + mPlayPauseReplayView);
+ Log.v(TAG, "showMainView() enableScrubbing="
+ + mEnableScrubbing + ", state=" + mState);
+ }
+ if (mEnableScrubbing
+ && (mState == State.PAUSED || mState == State.PLAYING)) {
+ mTimeBar.setScrubbing(true);
+ } else {
+ mTimeBar.setScrubbing(false);
+ }
+ }
+
+ public boolean canHidePanel() {
+ return !mAlwaysShowBottom;
+ }
+ };
+
+ class ScreenModeExt implements View.OnClickListener, ScreenModeListener {
+ // for screen mode feature
+ private ImageView mScreenView;
+ private int mScreenPadding;
+ private int mScreenWidth;
+
+ private static final int MARGIN = 10; // dip
+ private ViewGroup mParent;
+ private ImageView mSeprator;
+
+ void init(Context context, View myTimeBar) {
+ DisplayMetrics metrics = context.getResources().getDisplayMetrics();
+ int padding = (int) (metrics.density * MARGIN);
+ myTimeBar.setPadding(padding, 0, padding, 0);
+
+ LayoutParams wrapContent =
+ new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
+ // add screenView
+ mScreenView = new ImageView(context);
+ // default next screen mode
+ mScreenView.setImageResource(R.drawable.ic_media_fullscreen);
+ mScreenView.setScaleType(ScaleType.CENTER);
+ mScreenView.setFocusable(true);
+ mScreenView.setClickable(true);
+ mScreenView.setOnClickListener(this);
+ addView(mScreenView, wrapContent);
+
+ if (enableRewindAndForward) {
+ Log.v(TAG, "ScreenModeExt enableRewindAndForward");
+ mSeprator = new ImageView(context);
+ // default next screen mode
+ mSeprator.setImageResource(R.drawable.ic_separator_line);
+ mSeprator.setScaleType(ScaleType.CENTER);
+ mSeprator.setFocusable(true);
+ mSeprator.setClickable(true);
+ mSeprator.setOnClickListener(this);
+ addView(mSeprator, wrapContent);
+
+ } else {
+ Log.v(TAG, "ScreenModeExt unenableRewindAndForward");
+ }
+
+ // for screen layout
+ Bitmap screenButton = BitmapFactory.decodeResource(context.getResources(),
+ R.drawable.ic_media_bigscreen);
+ mScreenWidth = screenButton.getWidth();
+ mScreenPadding = (int) (metrics.density * MARGIN);
+ screenButton.recycle();
+ }
+
+ private void updateScreenModeDrawable() {
+ int screenMode = mScreenModeManager.getNextScreenMode();
+ if (screenMode == ScreenModeManager.SCREENMODE_BIGSCREEN) {
+ mScreenView.setImageResource(R.drawable.ic_media_bigscreen);
+ } else if (screenMode == ScreenModeManager.SCREENMODE_FULLSCREEN) {
+ mScreenView.setImageResource(R.drawable.ic_media_fullscreen);
+ } else {
+ mScreenView.setImageResource(R.drawable.ic_media_cropscreen);
+ }
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == mScreenView && mScreenModeManager != null) {
+ mScreenModeManager.setScreenMode(mScreenModeManager
+ .getNextScreenMode());
+ show();
+ }
+ }
+
+ public void onStartHiding() {
+ startHideAnimation(mScreenView);
+ }
+
+ public void onCancelHiding() {
+ mScreenView.setAnimation(null);
+ }
+
+ public void onHide() {
+ mScreenView.setVisibility(View.INVISIBLE);
+ if (enableRewindAndForward) {
+ mSeprator.setVisibility(View.INVISIBLE);
+ }
+ }
+
+ public void onShow() {
+ mScreenView.setVisibility(View.VISIBLE);
+ if (enableRewindAndForward) {
+ mSeprator.setVisibility(View.VISIBLE);
+ }
+ }
+
+ public void onLayout(int width, int paddingRight, int yPosition) {
+ // layout screen view position
+ int sw = getAddedRightPadding();
+ mScreenView.layout(width - paddingRight - sw, yPosition
+ - mTimeBar.getPreferredHeight(), width - paddingRight,
+ yPosition);
+ if (enableRewindAndForward) {
+ mSeprator.layout(width - paddingRight - sw - 22, yPosition
+ - mTimeBar.getPreferredHeight(), width - paddingRight - sw - 20,
+ yPosition);
+ }
+ }
+
+ public int getAddedRightPadding() {
+ return mScreenPadding * 2 + mScreenWidth;
+ }
+
+ @Override
+ public void onScreenModeChanged(int newMode) {
+ updateScreenModeDrawable();
+ }
+ }
+
+ class ControllerRewindAndForwardExt implements View.OnClickListener,
+ IControllerRewindAndForward {
+ private LinearLayout mContollerButtons;
+ private ImageView mStop;
+ private ImageView mForward;
+ private ImageView mRewind;
+ private IRewindAndForwardListener mListenerForRewind;
+ private int mButtonWidth;
+ private static final int BUTTON_PADDING = 40;
+ private int mTimeBarHeight = 0;
+
+ void init(Context context) {
+ Log.v(TAG, "ControllerRewindAndForwardExt init");
+ mTimeBarHeight = mTimeBar.getPreferredHeight();
+ Bitmap button = BitmapFactory.decodeResource(context.getResources(),
+ R.drawable.ic_menu_forward);
+ mButtonWidth = button.getWidth();
+ button.recycle();
+
+ mContollerButtons = new LinearLayout(context);
+ LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams(
+ getAddedRightPadding(), mTimeBarHeight);
+ mContollerButtons.setHorizontalGravity(LinearLayout.HORIZONTAL);
+ mContollerButtons.setVisibility(View.VISIBLE);
+ mContollerButtons.setGravity(Gravity.CENTER);
+
+ LinearLayout.LayoutParams buttonParam = new LinearLayout.LayoutParams(
+ mTimeBarHeight, mTimeBarHeight);
+ mRewind = new ImageView(context);
+ mRewind.setImageResource(R.drawable.icn_media_rewind);
+ mRewind.setScaleType(ScaleType.CENTER);
+ mRewind.setFocusable(true);
+ mRewind.setClickable(true);
+ mRewind.setOnClickListener(this);
+ mContollerButtons.addView(mRewind, buttonParam);
+
+ mStop = new ImageView(context);
+ mStop.setImageResource(R.drawable.icn_media_stop);
+ mStop.setScaleType(ScaleType.CENTER);
+ mStop.setFocusable(true);
+ mStop.setClickable(true);
+ mStop.setOnClickListener(this);
+ LinearLayout.LayoutParams stopLayoutParam = new LinearLayout.LayoutParams(
+ mTimeBarHeight, mTimeBarHeight);
+ stopLayoutParam.setMargins(BUTTON_PADDING, 0, BUTTON_PADDING, 0);
+ mContollerButtons.addView(mStop, stopLayoutParam);
+
+ mForward = new ImageView(context);
+ mForward.setImageResource(R.drawable.icn_media_forward);
+ mForward.setScaleType(ScaleType.CENTER);
+ mForward.setFocusable(true);
+ mForward.setClickable(true);
+ mForward.setOnClickListener(this);
+ mContollerButtons.addView(mForward, buttonParam);
+
+ addView(mContollerButtons, wrapContent);
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == mStop) {
+ Log.v(TAG, "ControllerRewindAndForwardExt onClick mStop");
+ mListenerForRewind.onStopVideo();
+ } else if (v == mRewind) {
+ Log.v(TAG, "ControllerRewindAndForwardExt onClick mRewind");
+ mListenerForRewind.onRewind();
+ } else if (v == mForward) {
+ Log.v(TAG, "ControllerRewindAndForwardExt onClick mForward");
+ mListenerForRewind.onForward();
+ }
+ }
+
+ public void onStartHiding() {
+ Log.v(TAG, "ControllerRewindAndForwardExt onStartHiding");
+ startHideAnimation(mContollerButtons);
+ }
+
+ public void onCancelHiding() {
+ Log.v(TAG, "ControllerRewindAndForwardExt onCancelHiding");
+ mContollerButtons.setAnimation(null);
+ }
+
+ public void onHide() {
+ Log.v(TAG, "ControllerRewindAndForwardExt onHide");
+ mContollerButtons.setVisibility(View.INVISIBLE);
+ }
+
+ public void onShow() {
+ Log.v(TAG, "ControllerRewindAndForwardExt onShow");
+ mContollerButtons.setVisibility(View.VISIBLE);
+ }
+
+ public void onLayout(int l, int r, int b) {
+ Log.v(TAG, "ControllerRewindAndForwardExt onLayout");
+ int cl = (r - l - getAddedRightPadding()) / 2;
+ int cr = cl + getAddedRightPadding();
+ mContollerButtons.layout(cl, b - mTimeBar.getPreferredHeight(), cr, b);
+ }
+
+ public int getAddedRightPadding() {
+ return mTimeBarHeight * 3 + BUTTON_PADDING * 2;
+ }
+
+ @Override
+ public void setIListener(IRewindAndForwardListener listener) {
+ Log.v(TAG, "ControllerRewindAndForwardExt setIListener " + listener);
+ mListenerForRewind = listener;
+ }
+
+ @Override
+ public void showControllerButtonsView(boolean canStop, boolean canRewind, boolean canForward) {
+ Log.v(TAG, "ControllerRewindAndForwardExt showControllerButtonsView " + canStop
+ + canRewind + canForward);
+ // show ui
+ mStop.setEnabled(canStop);
+ mRewind.setEnabled(canRewind);
+ mForward.setEnabled(canForward);
+ }
+
+ @Override
+ public void setListener(Listener listener) {
+ setListener(listener);
+ }
+
+ @Override
+ public boolean getPlayPauseEanbled() {
+ return mPlayPauseReplayView.isEnabled();
+ }
+
+ @Override
+ public boolean getTimeBarEanbled() {
+ return mTimeBar.getScrubbing();
+ }
+
+ @Override
+ public void setCanReplay(boolean canReplay) {
+ setCanReplay(canReplay);
+ }
+
+ @Override
+ public View getView() {
+ return mContollerButtons;
+ }
+
+ @Override
+ public void show() {
+ show();
+ }
+
+ @Override
+ public void showPlaying() {
+ showPlaying();
+ }
+
+ @Override
+ public void showPaused() {
+ showPaused();
+ }
+
+ @Override
+ public void showEnded() {
+ showEnded();
+ }
+
+ @Override
+ public void showLoading() {
+ showLoading();
+ }
+
+ @Override
+ public void showErrorMessage(String message) {
+ showErrorMessage(message);
+ }
+
+ public void setTimes(int currentTime, int totalTime, int trimStartTime, int trimEndTime) {
+ setTimes(currentTime, totalTime, 0, 0);
+ }
+
+ public void setPlayPauseReplayResume() {
+ }
+
+ public void setViewEnabled(boolean isEnabled) {
+ // TODO Auto-generated method stub
+ Log.v(TAG, "ControllerRewindAndForwardExt setViewEnabled is " + isEnabled);
+ mRewind.setEnabled(isEnabled);
+ mForward.setEnabled(isEnabled);
+ }
+ }
}
diff --git a/src/com/android/gallery3d/app/MoviePlayer.java b/src/com/android/gallery3d/app/MoviePlayer.java
index e632a826f..3afd32abf 100755
--- a/src/com/android/gallery3d/app/MoviePlayer.java
+++ b/src/com/android/gallery3d/app/MoviePlayer.java
@@ -27,6 +27,7 @@ import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnShowListener;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.SharedPreferences;
import android.graphics.Color;
import android.media.AudioManager;
import android.media.MediaPlayer;
@@ -50,11 +51,16 @@ import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.BlobCache;
import com.android.gallery3d.util.CacheManager;
import com.android.gallery3d.util.GalleryUtils;
+import org.codeaurora.gallery3d.ext.IContrllerOverlayExt;
import org.codeaurora.gallery3d.ext.IMoviePlayer;
import org.codeaurora.gallery3d.ext.IMovieItem;
import org.codeaurora.gallery3d.ext.MovieUtils;
import org.codeaurora.gallery3d.video.BookmarkEnhance;
import org.codeaurora.gallery3d.video.ExtensionHelper;
+import org.codeaurora.gallery3d.video.IControllerRewindAndForward;
+import org.codeaurora.gallery3d.video.IControllerRewindAndForward.IRewindAndForwardListener;
+import org.codeaurora.gallery3d.video.ScreenModeManager;
+import org.codeaurora.gallery3d.video.ScreenModeManager.ScreenModeListener;
import org.codeaurora.gallery3d.video.CodeauroraVideoView;
import java.io.ByteArrayInputStream;
@@ -69,10 +75,12 @@ public class MoviePlayer implements
ControllerOverlay.Listener,
MediaPlayer.OnInfoListener,
MediaPlayer.OnPreparedListener,
- MediaPlayer.OnSeekCompleteListener {
+ MediaPlayer.OnSeekCompleteListener,
+ MediaPlayer.OnVideoSizeChangedListener,
+ MediaPlayer.OnBufferingUpdateListener {
@SuppressWarnings("unused")
private static final String TAG = "MoviePlayer";
- private static final boolean LOG = false;
+ private static final boolean LOG = true;
private static final String KEY_VIDEO_POSITION = "video-position";
private static final String KEY_RESUMEABLE_TIME = "resumeable-timeout";
@@ -112,7 +120,6 @@ public class MoviePlayer implements
private final CodeauroraVideoView mVideoView;
private final View mRootView;
private final Bookmarker mBookmarker;
- private final Uri mUri;
private final Handler mHandler = new Handler();
private final AudioBecomingNoisyReceiver mAudioBecomingNoisyReceiver;
private final MovieControllerOverlay mController;
@@ -124,6 +131,7 @@ public class MoviePlayer implements
private boolean mCanResumed = false;
private boolean mFirstBePlayed = false;
private boolean mKeyguardLocked = false;
+ private boolean mIsOnlyAudio = false;
private int mLastSystemUiVis = 0;
// If the time bar is being dragged.
@@ -138,6 +146,10 @@ public class MoviePlayer implements
private MoviePlayerExtension mPlayerExt = new MoviePlayerExtension();
private RetryExtension mRetryExt = new RetryExtension();
private ServerTimeoutExtension mServerTimeoutExt = new ServerTimeoutExtension();
+ private ScreenModeExt mScreenModeExt = new ScreenModeExt();
+ private IContrllerOverlayExt mOverlayExt;
+ private IControllerRewindAndForward mControllerRewindAndForwardExt;
+ private IRewindAndForwardListener mRewindAndForwardListener = new ControllerRewindAndForwardExt();
private boolean mCanReplay;
private boolean mVideoCanSeek = false;
private boolean mVideoCanPause = false;
@@ -200,6 +212,9 @@ public class MoviePlayer implements
}
mKeyguardLocked = false;
mCanResumed = false;
+ } else if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) {
+ Log.v(TAG, "Intent.ACTION_SHUTDOWN received");
+ mActivityContext.finish();
}
}
};
@@ -211,17 +226,20 @@ public class MoviePlayer implements
mVideoView = (CodeauroraVideoView) rootView.findViewById(R.id.surface_view);
mBookmarker = new Bookmarker(movieActivity);
- mController = new MovieControllerOverlay(mContext);
+ mController = new MovieControllerOverlay(movieActivity);
((ViewGroup)rootView).addView(mController.getView());
mController.setListener(this);
mController.setCanReplay(canReplay);
init(movieActivity, info, canReplay);
- mUri = mMovieItem.getUri();
mVideoView.setOnErrorListener(this);
mVideoView.setOnCompletionListener(this);
- mVideoView.setVideoURI(mUri);
+
+ if (mVirtualizer != null) {
+ mVirtualizer.release();
+ mVirtualizer = null;
+ }
Intent ai = movieActivity.getIntent();
boolean virtualize = ai.getBooleanExtra(VIRTUALIZE_EXTRA, false);
@@ -276,6 +294,7 @@ public class MoviePlayer implements
final IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
+ filter.addAction(Intent.ACTION_SHUTDOWN);
mContext.registerReceiver(mReceiver, filter);
Intent i = new Intent(SERVICECMD);
@@ -285,8 +304,6 @@ public class MoviePlayer implements
if (savedInstance != null) { // this is a resumed activity
mVideoPosition = savedInstance.getInt(KEY_VIDEO_POSITION, 0);
mResumeableTime = savedInstance.getLong(KEY_RESUMEABLE_TIME, Long.MAX_VALUE);
- mVideoView.start();
- mVideoView.suspend();
onRestoreInstanceState(savedInstance);
mHasPaused = true;
} else {
@@ -299,6 +316,7 @@ public class MoviePlayer implements
doStartVideo(false, 0, 0);
}
}
+ mScreenModeExt.setScreenMode();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@@ -312,11 +330,17 @@ public class MoviePlayer implements
new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
+ boolean finish = (mActivityContext == null ? true : mActivityContext.isFinishing());
int diff = mLastSystemUiVis ^ visibility;
mLastSystemUiVis = visibility;
if ((diff & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
&& (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
mController.show();
+ mRootView.setBackgroundColor(Color.BLACK);
+ }
+
+ if (LOG) {
+ Log.v(TAG, "onSystemUiVisibilityChange(" + visibility + ") finishing()=" + finish);
}
}
});
@@ -388,6 +412,12 @@ public class MoviePlayer implements
dialog.show();
}
+ public void setDefaultScreenMode() {
+ addBackground();
+ mController.setDefaultScreenMode();
+ removeBackground();
+ }
+
public boolean onPause() {
if (LOG) {
Log.v(TAG, "onPause() isLiveStreaming()=" + isLiveStreaming());
@@ -427,14 +457,14 @@ public class MoviePlayer implements
mVideoLastDuration = duration > 0 ? duration : mVideoLastDuration;
mBookmarker.setBookmark(mMovieItem.getUri(), mVideoPosition, mVideoLastDuration);
long end1 = System.currentTimeMillis();
- // change suspend to release for sync paused and killed case
- mVideoView.stopPlayback();
+ mVideoView.suspend();
mResumeableTime = System.currentTimeMillis() + RESUMEABLE_TIMEOUT;
mVideoView.setResumed(false);// avoid start after surface created
// Workaround for last-seek frame difference
mVideoView.setVisibility(View.INVISIBLE);
long end2 = System.currentTimeMillis();
// TODO comments by sunlei
+ mOverlayExt.clearBuffering();
mServerTimeoutExt.recordDisconnectTime();
if (LOG) {
Log.v(TAG, "doOnPause() save video info consume:" + (end1 - start));
@@ -477,7 +507,8 @@ public class MoviePlayer implements
pauseVideo();
break;
default:
- doStartVideo(true, mVideoPosition, mVideoLastDuration);
+ mVideoView.seekTo(mVideoPosition);
+ mVideoView.resume();
pauseVideoMoreThanThreeMinutes();
break;
}
@@ -515,12 +546,16 @@ public class MoviePlayer implements
// second by mProgressChecker and also from places where the time bar needs
// to be updated immediately.
private int setProgress() {
- if (mDragging || !mShowing) {
+ if (mDragging || (!mShowing && !mIsOnlyAudio)) {
return 0;
}
int position = mVideoView.getCurrentPosition();
int duration = mVideoView.getDuration();
mController.setTimes(position, duration, 0, 0);
+ if (mControllerRewindAndForwardExt != null
+ && mControllerRewindAndForwardExt.getPlayPauseEanbled()) {
+ updateRewindAndForwardUI();
+ }
return position;
}
@@ -532,6 +567,7 @@ public class MoviePlayer implements
if ("http".equalsIgnoreCase(scheme) || "rtsp".equalsIgnoreCase(scheme)
|| "https".equalsIgnoreCase(scheme)) {
mController.showLoading();
+ mOverlayExt.setPlayingInfo(isLiveStreaming());
mHandler.removeCallbacks(mPlayingChecker);
mHandler.postDelayed(mPlayingChecker, 250);
} else {
@@ -548,14 +584,15 @@ public class MoviePlayer implements
}
if (start) {
mVideoView.start();
+ mVideoView.setVisibility(View.VISIBLE);
+ mActivityContext.initEffects(mVideoView.getAudioSessionId());
}
//we may start video from stopVideo,
//this case, we should reset canReplay flag according canReplay and loop
boolean loop = mPlayerExt.getLoop();
boolean canReplay = loop ? loop : mCanReplay;
mController.setCanReplay(canReplay);
- if (position > 0 && (mVideoCanSeek || mVideoView.canSeekBackward()
- || mVideoView.canSeekForward())) {
+ if (position > 0 && (mVideoCanSeek || mVideoView.canSeek())) {
mVideoView.seekTo(position);
}
if (enableFasten) {
@@ -603,6 +640,8 @@ public class MoviePlayer implements
mHandler.removeCallbacksAndMessages(null);
// VideoView will show an error dialog if we return false, so no need
// to show more message.
+ //M:resume controller
+ mController.setViewEnabled(true);
mController.showErrorMessage("");
return false;
}
@@ -635,9 +674,23 @@ public class MoviePlayer implements
@Override
public void onPlayPause() {
if (mVideoView.isPlaying()) {
- pauseVideo();
+ if (mVideoView.canPause()) {
+ pauseVideo();
+ //set view disabled(play/pause asynchronous processing)
+ mController.setViewEnabled(true);
+ if (mControllerRewindAndForwardExt != null) {
+ mControllerRewindAndForwardExt.showControllerButtonsView(mPlayerExt
+ .canStop(), false, false);
+ }
+ }
} else {
playVideo();
+ //set view disabled(play/pause asynchronous processing)
+ mController.setViewEnabled(true);
+ if (mControllerRewindAndForwardExt != null) {
+ mControllerRewindAndForwardExt.showControllerButtonsView(mPlayerExt
+ .canStop(), false, false);
+ }
}
}
@@ -648,14 +701,17 @@ public class MoviePlayer implements
@Override
public void onSeekMove(int time) {
- mVideoView.seekTo(time);
+ if (mVideoView.canSeek()) {
+ mVideoView.seekTo(time);
+ }
}
@Override
public void onSeekEnd(int time, int start, int end) {
mDragging = false;
- mVideoView.seekTo(time);
- setProgress();
+ if (mVideoView.canSeek()) {
+ mVideoView.seekTo(time);
+ }
}
@Override
@@ -665,6 +721,7 @@ public class MoviePlayer implements
@Override
public void onShown() {
+ addBackground();
mShowing = true;
setProgress();
showSystemUi(true);
@@ -674,6 +731,7 @@ public class MoviePlayer implements
public void onHidden() {
mShowing = false;
showSystemUi(false);
+ removeBackground();
}
@Override
@@ -681,7 +739,11 @@ public class MoviePlayer implements
if (LOG) {
Log.v(TAG, "onInfo() what:" + what + " extra:" + extra);
}
- if (what == MediaPlayer.MEDIA_INFO_METADATA_UPDATE && mServerTimeoutExt != null) {
+ if (what == MediaPlayer.MEDIA_INFO_NOT_SEEKABLE && mOverlayExt != null) {
+ boolean flag = (extra == 1);
+ mOverlayExt.setCanPause(flag);
+ mOverlayExt.setCanScrubbing(flag);
+ } else if (what == MediaPlayer.MEDIA_INFO_METADATA_UPDATE && mServerTimeoutExt != null) {
Log.e(TAG, "setServerTimeout " + extra);
mServerTimeoutExt.setTimeout(extra * 1000);
}
@@ -692,16 +754,29 @@ public class MoviePlayer implements
}
@Override
+ public void onBufferingUpdate(MediaPlayer mp, int percent) {
+ boolean fullBuffer = isFullBuffer();
+ mOverlayExt.showBuffering(fullBuffer, percent);
+ }
+
+ @Override
public void onPrepared(MediaPlayer mp) {
if (LOG) {
Log.v(TAG, "onPrepared(" + mp + ")");
}
+ if (!isLocalFile()) {
+ mOverlayExt.setPlayingInfo(isLiveStreaming());
+ }
getVideoInfo(mp);
boolean canPause = mVideoView.canPause();
- boolean canSeek = mVideoView.canSeekBackward() && mVideoView.canSeekForward();
+ boolean canSeek = mVideoView.canSeek();
+ mOverlayExt.setCanPause(canPause);
+ mOverlayExt.setCanScrubbing(canSeek);
+ mController.setPlayPauseReplayResume();
if (!canPause && !mVideoView.isTargetPlaying()) {
mVideoView.start();
}
+ updateRewindAndForwardUI();
if (LOG) {
Log.v(TAG, "onPrepared() canPause=" + canPause + ", canSeek=" + canSeek);
}
@@ -770,6 +845,19 @@ public class MoviePlayer implements
return isMediaKey(keyCode);
}
+ public void updateRewindAndForwardUI() {
+ Log.v(TAG, "updateRewindAndForwardUI");
+ Log.v(TAG, "updateRewindAndForwardUI== getCurrentPosition = " + mVideoView.getCurrentPosition());
+ Log.v(TAG, "updateRewindAndForwardUI==getDuration =" + mVideoView.getDuration());
+ if (mControllerRewindAndForwardExt != null) {
+ mControllerRewindAndForwardExt.showControllerButtonsView(mPlayerExt
+ .canStop(), mVideoView.canSeekBackward()
+ && mControllerRewindAndForwardExt.getTimeBarEanbled(), mVideoView
+ .canSeekForward()
+ && mControllerRewindAndForwardExt.getTimeBarEanbled());
+ }
+ }
+
private static boolean isMediaKey(int keyCode) {
return keyCode == KeyEvent.KEYCODE_HEADSETHOOK
|| keyCode == KeyEvent.KEYCODE_MEDIA_PREVIOUS
@@ -787,6 +875,20 @@ public class MoviePlayer implements
mVideoView.setOnInfoListener(this);
mVideoView.setOnPreparedListener(this);
+ mVideoView.setOnBufferingUpdateListener(this);
+ mVideoView.setOnVideoSizeChangedListener(this);
+ mRootView.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ mController.show();
+ return true;
+ }
+ });
+ mOverlayExt = mController.getOverlayExt();
+ mControllerRewindAndForwardExt = mController.getControllerRewindAndForwardExt();
+ if (mControllerRewindAndForwardExt != null) {
+ mControllerRewindAndForwardExt.setIListener(mRewindAndForwardListener);
+ }
}
// We want to pause when the headset is unplugged.
@@ -803,7 +905,7 @@ public class MoviePlayer implements
@Override
public void onReceive(Context context, Intent intent) {
- if (mVideoView.isPlaying()) pauseVideo();
+ if (mVideoView.isPlaying() && mVideoView.canPause()) pauseVideo();
}
}
@@ -881,6 +983,20 @@ public class MoviePlayer implements
return isLive;
}
+ public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
+ // reget the audio type
+ if (width != 0 && height != 0) {
+ mIsOnlyAudio = false;
+ } else {
+ mIsOnlyAudio = true;
+ }
+ mOverlayExt.setBottomPanel(mIsOnlyAudio, true);
+ if (LOG) {
+ Log.v(TAG, "onVideoSizeChanged(" + width + ", " + height + ") mIsOnlyAudio="
+ + mIsOnlyAudio);
+ }
+ }
+
public IMoviePlayer getMoviePlayerExt() {
return mPlayerExt;
}
@@ -920,6 +1036,7 @@ public class MoviePlayer implements
private void clearVideoInfo() {
mVideoPosition = 0;
mVideoLastDuration = 0;
+ mIsOnlyAudio = false;
if (mServerTimeoutExt != null) {
mServerTimeoutExt.clearServerInfo();
@@ -933,6 +1050,7 @@ public class MoviePlayer implements
outState.putInt(KEY_VIDEO_STREAMING_TYPE, mStreamingType);
outState.putString(KEY_VIDEO_STATE, String.valueOf(mTState));
mServerTimeoutExt.onSaveInstanceState(outState);
+ mScreenModeExt.onSaveInstanceState(outState);
mRetryExt.onSaveInstanceState(outState);
mPlayerExt.onSaveInstanceState(outState);
}
@@ -944,6 +1062,7 @@ public class MoviePlayer implements
mStreamingType = icicle.getInt(KEY_VIDEO_STREAMING_TYPE);
mTState = TState.valueOf(icicle.getString(KEY_VIDEO_STATE));
mServerTimeoutExt.onRestoreInstanceState(icicle);
+ mScreenModeExt.onRestoreInstanceState(icicle);
mRetryExt.onRestoreInstanceState(icicle);
mPlayerExt.onRestoreInstanceState(icicle);
}
@@ -971,6 +1090,26 @@ public class MoviePlayer implements
}
@Override
+ public void startNextVideo(IMovieItem item) {
+ IMovieItem next = item;
+ if (next != null && next != mMovieItem) {
+ int position = mVideoView.getCurrentPosition();
+ int duration = mVideoView.getDuration();
+ mBookmarker.setBookmark(mMovieItem.getUri(), position, duration);
+ mVideoView.stopPlayback();
+ mVideoView.setVisibility(View.INVISIBLE);
+ clearVideoInfo();
+ mMovieItem = next;
+ mActivityContext.refreshMovieInfo(mMovieItem);
+ doStartVideo(false, 0, 0);
+ mVideoView.setVisibility(View.VISIBLE);
+ } else {
+ Log.e(TAG, "Cannot play the next video! " + item);
+ }
+ mActivityContext.closeOptionsMenu();
+ }
+
+ @Override
public void onRestoreInstanceState(Bundle icicle) {
mIsLoop = icicle.getBoolean(KEY_VIDEO_IS_LOOP, false);
if (mIsLoop) {
@@ -999,6 +1138,7 @@ public class MoviePlayer implements
mFirstBePlayed = false;
mController.setCanReplay(true);
mController.showEnded();
+ mController.setViewEnabled(true);
setProgress();
}
@@ -1006,7 +1146,7 @@ public class MoviePlayer implements
public boolean canStop() {
boolean stopped = false;
if (mController != null) {
- //stopped = mOverlayExt.isPlayingEnd();
+ stopped = mOverlayExt.isPlayingEnd();
}
if (LOG) {
Log.v(TAG, "canStop() stopped=" + stopped);
@@ -1277,6 +1417,145 @@ public class MoviePlayer implements
mServerTimeout = timeout;
}
}
+
+ private class ScreenModeExt implements Restorable, ScreenModeListener {
+ private static final String KEY_VIDEO_SCREEN_MODE = "video_screen_mode";
+ private int mScreenMode = ScreenModeManager.SCREENMODE_BIGSCREEN;
+ private ScreenModeManager mScreenModeManager = new ScreenModeManager();
+
+ public void setScreenMode() {
+ mVideoView.setScreenModeManager(mScreenModeManager);
+ mController.setScreenModeManager(mScreenModeManager);
+ mScreenModeManager.addListener(this);
+ //notify all listener to change screen mode
+ mScreenModeManager.setScreenMode(mScreenMode);
+ if (LOG) {
+ Log.v(TAG, "setScreenMode() mScreenMode=" + mScreenMode);
+ }
+ }
+
+ @Override
+ public void onScreenModeChanged(int newMode) {
+ mScreenMode = newMode;// changed from controller
+ if (LOG) {
+ Log.v(TAG, "OnScreenModeClicked(" + newMode + ")");
+ }
+ }
+
+ @Override
+ public void onRestoreInstanceState(Bundle icicle) {
+ mScreenMode = icicle.getInt(KEY_VIDEO_SCREEN_MODE,
+ ScreenModeManager.SCREENMODE_BIGSCREEN);
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ outState.putInt(KEY_VIDEO_SCREEN_MODE, mScreenMode);
+ }
+ }
+
+ private class ControllerRewindAndForwardExt implements IRewindAndForwardListener {
+ @Override
+ public void onPlayPause() {
+ onPlayPause();
+ }
+
+ @Override
+ public void onSeekStart() {
+ onSeekStart();
+ }
+
+ @Override
+ public void onSeekMove(int time) {
+ onSeekMove(time);
+ }
+
+ @Override
+ public void onSeekEnd(int time, int trimStartTime, int trimEndTime) {
+ onSeekEnd(time, trimStartTime, trimEndTime);
+ }
+
+ @Override
+ public void onShown() {
+ onShown();
+ }
+
+ @Override
+ public void onHidden() {
+ onHidden();
+ }
+
+ @Override
+ public void onReplay() {
+ onReplay();
+ }
+
+ @Override
+ public boolean onIsRTSP() {
+ return false;
+ }
+
+ @Override
+ public void onStopVideo() {
+ Log.v(TAG, "ControllerRewindAndForwardExt onStopVideo()");
+ if (mPlayerExt.canStop()) {
+ mPlayerExt.stopVideo();
+ mControllerRewindAndForwardExt.showControllerButtonsView(false,
+ false, false);
+ }
+ }
+
+ @Override
+ public void onRewind() {
+ Log.v(TAG, "ControllerRewindAndForwardExt onRewind()");
+ if (mVideoView != null && mVideoView.canSeekBackward()) {
+ mControllerRewindAndForwardExt.showControllerButtonsView(mPlayerExt
+ .canStop(),
+ false, false);
+ int stepValue = getStepOptionValue();
+ int targetDuration = mVideoView.getCurrentPosition()
+ - stepValue < 0 ? 0 : mVideoView.getCurrentPosition()
+ - stepValue;
+ Log.v(TAG, "onRewind targetDuration " + targetDuration);
+ mVideoView.seekTo(targetDuration);
+ } else {
+ mControllerRewindAndForwardExt.showControllerButtonsView(mPlayerExt
+ .canStop(),
+ false, false);
+ }
+ }
+
+ @Override
+ public void onForward() {
+ Log.v(TAG, "ControllerRewindAndForwardExt onForward()");
+ if (mVideoView != null && mVideoView.canSeekForward()) {
+ mControllerRewindAndForwardExt.showControllerButtonsView(mPlayerExt
+ .canStop(),
+ false, false);
+ int stepValue = getStepOptionValue();
+ int targetDuration = mVideoView.getCurrentPosition()
+ + stepValue > mVideoView.getDuration() ? mVideoView
+ .getDuration() : mVideoView.getCurrentPosition()
+ + stepValue;
+ Log.v(TAG, "onForward targetDuration " + targetDuration);
+ mVideoView.seekTo(targetDuration);
+ } else {
+ mControllerRewindAndForwardExt.showControllerButtonsView(mPlayerExt
+ .canStop(),
+ false, false);
+ }
+ }
+ }
+
+ public int getStepOptionValue() {
+ final String slectedStepOption = "selected_step_option";
+ final String videoPlayerData = "video_player_data";
+ final int stepBase = 3000;
+ final int stepOptionThreeSeconds = 0;
+ SharedPreferences mPrefs = mContext.getSharedPreferences(
+ videoPlayerData, 0);
+ return (mPrefs.getInt(slectedStepOption, stepOptionThreeSeconds) + 1) * stepBase;
+ }
}
class Bookmarker {
diff --git a/src/com/android/gallery3d/app/TimeBar.java b/src/com/android/gallery3d/app/TimeBar.java
index 246346a56..1b9ac24ed 100644..100755
--- a/src/com/android/gallery3d/app/TimeBar.java
+++ b/src/com/android/gallery3d/app/TimeBar.java
@@ -23,6 +23,7 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.DisplayMetrics;
+import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
@@ -51,6 +52,10 @@ public class TimeBar extends View {
private static final int TEXT_SIZE_IN_DP = 14;
+ private static final String TAG = "Gallery3D/TimeBar";
+ private static final boolean LOG = true;
+ public static final int UNKNOWN = -1;
+
protected final Listener mListener;
// the bars we use for displaying the progress
@@ -71,6 +76,7 @@ public class TimeBar extends View {
protected boolean mScrubbing;
protected boolean mShowTimes;
protected boolean mShowScrubber;
+ private boolean mEnableScrubbing;
protected int mTotalTime;
protected int mCurrentTime;
@@ -78,6 +84,11 @@ public class TimeBar extends View {
protected final Rect mTimeBounds;
protected int mVPaddingInPx;
+ private int mLastShowTime = UNKNOWN;
+
+ private ITimeBarSecondaryProgressExt mSecondaryProgressExt = new TimeBarSecondaryProgressExtImpl();
+ private ITimeBarInfoExt mInfoExt = new TimeBarInfoExtImpl();
+ private ITimeBarLayoutExt mLayoutExt = new TimeBarLayoutExtImpl();
public TimeBar(Context context, Listener listener) {
super(context);
@@ -102,12 +113,14 @@ public class TimeBar extends View {
mTimeTextPaint.setTextAlign(Paint.Align.CENTER);
mTimeBounds = new Rect();
- mTimeTextPaint.getTextBounds("0:00:00", 0, 7, mTimeBounds);
mScrubber = BitmapFactory.decodeResource(getResources(), R.drawable.scrubber_knob);
mScrubberPadding = (int) (metrics.density * SCRUBBER_PADDING_IN_DP);
mVPaddingInPx = (int) (metrics.density * V_PADDING_IN_DP);
+ mLayoutExt.init(mScrubberPadding, mVPaddingInPx);
+ mInfoExt.init(textSizeInPx);
+ mSecondaryProgressExt.init();
}
private void update() {
@@ -115,7 +128,15 @@ public class TimeBar extends View {
if (mTotalTime > 0) {
mPlayedBar.right =
- mPlayedBar.left + (int) ((mProgressBar.width() * (long) mCurrentTime) / mTotalTime);
+ mPlayedBar.left
+ + (int) ((mProgressBar.width() * (long) mCurrentTime) / mTotalTime);
+ /*
+ * M: if duration is not accurate, here just adjust playedBar we
+ * also show the accurate position text to final user.
+ */
+ if (mPlayedBar.right > mProgressBar.right) {
+ mPlayedBar.right = mProgressBar.right;
+ }
} else {
mPlayedBar.right = mProgressBar.left;
}
@@ -123,6 +144,9 @@ public class TimeBar extends View {
if (!mScrubbing) {
mScrubberLeft = mPlayedBar.right - mScrubber.getWidth() / 2;
}
+ // update text bounds when layout changed or time changed
+ updateBounds();
+ mInfoExt.updateVisibleText(this, mProgressBar, mTimeBounds);
invalidate();
}
@@ -130,14 +154,16 @@ public class TimeBar extends View {
* @return the preferred height of this view, including invisible padding
*/
public int getPreferredHeight() {
- return mTimeBounds.height() + mVPaddingInPx + mScrubberPadding;
+ int preferredHeight = mTimeBounds.height() + mVPaddingInPx + mScrubberPadding;
+ return mLayoutExt.getPreferredHeight(preferredHeight, mTimeBounds);
}
/**
* @return the height of the time bar, excluding invisible padding
*/
public int getBarHeight() {
- return mTimeBounds.height() + mVPaddingInPx;
+ int barHeight = mTimeBounds.height() + mVPaddingInPx;
+ return mLayoutExt.getBarHeight(barHeight, mTimeBounds);
}
public void setTime(int currentTime, int totalTime,
@@ -146,7 +172,10 @@ public class TimeBar extends View {
return;
}
mCurrentTime = currentTime;
- mTotalTime = totalTime;
+ mTotalTime = Math.abs(totalTime);
+ if (totalTime <= 0) { /// M: disable scrubbing before mediaplayer ready.
+ setScrubbing(false);
+ }
update();
}
@@ -180,7 +209,8 @@ public class TimeBar extends View {
if (mShowTimes) {
margin += mTimeBounds.width();
}
- int progressY = (h + mScrubberPadding) / 2;
+ margin = mLayoutExt.getProgressMargin(margin);
+ int progressY = (h + mScrubberPadding) / 2 + mLayoutExt.getProgressOffset(mTimeBounds);
mScrubberTop = progressY - mScrubber.getHeight() / 2 + 1;
mProgressBar.set(
getPaddingLeft() + margin, progressY,
@@ -191,8 +221,10 @@ public class TimeBar extends View {
@Override
protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
// draw progress bars
canvas.drawRect(mProgressBar, mProgressPaint);
+ mSecondaryProgressExt.draw(canvas, mProgressBar);
canvas.drawRect(mPlayedBar, mPlayedPaint);
// draw scrubber and timers
@@ -202,20 +234,29 @@ public class TimeBar extends View {
if (mShowTimes) {
canvas.drawText(
stringForTime(mCurrentTime),
- mTimeBounds.width() / 2 + getPaddingLeft(),
- mTimeBounds.height() + mVPaddingInPx / 2 + mScrubberPadding + 1,
+ mTimeBounds.width() / 2 + getPaddingLeft(),
+ mTimeBounds.height() + mVPaddingInPx / 2 + mScrubberPadding + 1
+ + mLayoutExt.getTimeOffset(),
mTimeTextPaint);
canvas.drawText(
stringForTime(mTotalTime),
- getWidth() - getPaddingRight() - mTimeBounds.width() / 2,
- mTimeBounds.height() + mVPaddingInPx / 2 + mScrubberPadding + 1,
+ getWidth() - getPaddingRight() - mTimeBounds.width() / 2,
+ mTimeBounds.height() + mVPaddingInPx / 2 + mScrubberPadding + 1
+ + mLayoutExt.getTimeOffset(),
mTimeTextPaint);
}
+ mInfoExt.draw(canvas, mLayoutExt.getInfoBounds(this, mTimeBounds));
}
@Override
public boolean onTouchEvent(MotionEvent event) {
- if (mShowScrubber) {
+ if (LOG) {
+ Log.v(TAG, "onTouchEvent() showScrubber=" + mShowScrubber
+ + ", enableScrubbing=" + mEnableScrubbing + ", totalTime="
+ + mTotalTime + ", scrubbing=" + mScrubbing + ", event="
+ + event);
+ }
+ if (mShowScrubber && mEnableScrubbing) {
int x = (int) event.getX();
int y = (int) event.getY();
@@ -233,15 +274,19 @@ public class TimeBar extends View {
clampScrubber();
mCurrentTime = getScrubberTime();
mListener.onScrubbingMove(mCurrentTime);
+ update();
invalidate();
return true;
}
case MotionEvent.ACTION_CANCEL:
- case MotionEvent.ACTION_UP: {
- mListener.onScrubbingEnd(getScrubberTime(), 0, 0);
- mScrubbing = false;
- return true;
- }
+ case MotionEvent.ACTION_UP:
+ if (mScrubbing) {
+ mListener.onScrubbingEnd(getScrubberTime(), 0, 0);
+ mScrubbing = false;
+ update();
+ return true;
+ }
+ break;
}
}
return false;
@@ -263,4 +308,235 @@ public class TimeBar extends View {
mShowScrubber = canSeek;
}
+ private void updateBounds() {
+ int showTime = mTotalTime > mCurrentTime ? mTotalTime : mCurrentTime;
+ if (mLastShowTime == showTime) {
+ // do not need to recompute the bounds.
+ return;
+ }
+ String durationText = stringForTime(showTime);
+ int length = durationText.length();
+ mTimeTextPaint.getTextBounds(durationText, 0, length, mTimeBounds);
+ mLastShowTime = showTime;
+ if (LOG) {
+ Log.v(TAG, "updateBounds() durationText=" + durationText + ", timeBounds="
+ + mTimeBounds);
+ }
+ }
+
+ public void setScrubbing(boolean enable) {
+ if (LOG) {
+ Log.v(TAG, "setScrubbing(" + enable + ") scrubbing=" + mScrubbing);
+ }
+ mEnableScrubbing = enable;
+ if (mScrubbing) { // if it is scrubbing, change it to false
+ mListener.onScrubbingEnd(getScrubberTime(), 0, 0);
+ mScrubbing = false;
+ }
+ }
+
+ public boolean getScrubbing() {
+ if (LOG) {
+ Log.v(TAG, "mEnableScrubbing=" + mEnableScrubbing);
+ }
+ return mEnableScrubbing;
+ }
+
+ public void setInfo(String info) {
+ if (LOG) {
+ Log.v(TAG, "setInfo(" + info + ")");
+ }
+ mInfoExt.setInfo(info);
+ mInfoExt.updateVisibleText(this, mProgressBar, mTimeBounds);
+ invalidate();
+ }
+
+ public void setSecondaryProgress(int percent) {
+ if (LOG) {
+ Log.v(TAG, "setSecondaryProgress(" + percent + ")");
+ }
+ mSecondaryProgressExt.setSecondaryProgress(mProgressBar, percent);
+ invalidate();
+ }
+}
+
+interface ITimeBarInfoExt {
+ void init(float textSizeInPx);
+
+ void setInfo(String info);
+
+ void draw(Canvas canvas, Rect infoBounds);
+
+ void updateVisibleText(View parent, Rect progressBar, Rect timeBounds);
+}
+
+interface ITimeBarSecondaryProgressExt {
+ void init();
+
+ void setSecondaryProgress(Rect progressBar, int percent);
+
+ void draw(Canvas canvas, Rect progressBounds);
+}
+
+interface ITimeBarLayoutExt {
+ void init(int scrubberPadding, int vPaddingInPx);
+
+ int getPreferredHeight(int originalPreferredHeight, Rect timeBounds);
+
+ int getBarHeight(int originalBarHeight, Rect timeBounds);
+
+ int getProgressMargin(int originalMargin);
+
+ int getProgressOffset(Rect timeBounds);
+
+ int getTimeOffset();
+
+ Rect getInfoBounds(View parent, Rect timeBounds);
+}
+
+class TimeBarInfoExtImpl implements ITimeBarInfoExt {
+ private static final String TAG = "TimeBarInfoExtensionImpl";
+ private static final boolean LOG = true;
+ private static final String ELLIPSE = "...";
+
+ private Paint mInfoPaint;
+ private Rect mInfoBounds;
+ private String mInfoText;
+ private String mVisibleText;
+ private int mEllipseLength;
+
+ @Override
+ public void init(float textSizeInPx) {
+ mInfoPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ mInfoPaint.setColor(0xFFCECECE);
+ mInfoPaint.setTextSize(textSizeInPx);
+ mInfoPaint.setTextAlign(Paint.Align.CENTER);
+
+ mEllipseLength = (int) Math.ceil(mInfoPaint.measureText(ELLIPSE));
+ }
+
+ @Override
+ public void draw(Canvas canvas, Rect infoBounds) {
+ if (mInfoText != null && mVisibleText != null) {
+ canvas.drawText(mVisibleText, infoBounds.centerX(), infoBounds.centerY(), mInfoPaint);
+ }
+ }
+
+ @Override
+ public void setInfo(String info) {
+ mInfoText = info;
+ }
+
+ public void updateVisibleText(View parent, Rect progressBar, Rect timeBounds) {
+ if (mInfoText == null) {
+ mVisibleText = null;
+ return;
+ }
+ float tw = mInfoPaint.measureText(mInfoText);
+ float space = progressBar.width() - timeBounds.width() * 2 - parent.getPaddingLeft()
+ - parent.getPaddingRight();
+ if (tw > 0 && space > 0 && tw > space) {
+ // we need to cut the info text for visible
+ float originalNum = mInfoText.length();
+ int realNum = (int) ((space - mEllipseLength) * originalNum / tw);
+ if (LOG) {
+ Log.v(TAG, "updateVisibleText() infoText=" + mInfoText + " text width=" + tw
+ + ", space=" + space + ", originalNum=" + originalNum + ", realNum="
+ + realNum
+ + ", getPaddingLeft()=" + parent.getPaddingLeft() + ", getPaddingRight()="
+ + parent.getPaddingRight()
+ + ", progressBar=" + progressBar + ", timeBounds=" + timeBounds);
+ }
+ mVisibleText = mInfoText.substring(0, realNum) + ELLIPSE;
+ } else {
+ mVisibleText = mInfoText;
+ }
+ if (LOG) {
+ Log.v(TAG, "updateVisibleText() infoText=" + mInfoText + ", visibleText="
+ + mVisibleText
+ + ", text width=" + tw + ", space=" + space);
+ }
+ }
+}
+
+class TimeBarSecondaryProgressExtImpl implements ITimeBarSecondaryProgressExt {
+ private static final String TAG = "TimeBarSecondaryProgressExtensionImpl";
+ private static final boolean LOG = true;
+
+ private int mBufferPercent;
+ private Rect mSecondaryBar;
+ private Paint mSecondaryPaint;
+
+ @Override
+ public void init() {
+ mSecondaryBar = new Rect();
+ mSecondaryPaint = new Paint();
+ mSecondaryPaint.setColor(0xFF5CA0C5);
+ }
+
+ @Override
+ public void draw(Canvas canvas, Rect progressBounds) {
+ if (mBufferPercent >= 0) {
+ mSecondaryBar.set(progressBounds);
+ mSecondaryBar.right = mSecondaryBar.left
+ + (int) (mBufferPercent * progressBounds.width() / 100);
+ canvas.drawRect(mSecondaryBar, mSecondaryPaint);
+ }
+ if (LOG) {
+ Log.v(TAG, "draw() bufferPercent=" + mBufferPercent + ", secondaryBar="
+ + mSecondaryBar);
+ }
+ }
+
+ @Override
+ public void setSecondaryProgress(Rect progressBar, int percent) {
+ mBufferPercent = percent;
+ }
+}
+
+class TimeBarLayoutExtImpl implements ITimeBarLayoutExt {
+ private static final String TAG = "TimeBarLayoutExtensionImpl";
+ private static final boolean LOG = true;
+
+ private int mTextPadding;
+ private int mVPaddingInPx;
+
+ @Override
+ public void init(int scrubberPadding, int vPaddingInPx) {
+ mTextPadding = scrubberPadding / 2;
+ mVPaddingInPx = vPaddingInPx;
+ }
+
+ @Override
+ public int getPreferredHeight(int originalPreferredHeight, Rect timeBounds) {
+ return originalPreferredHeight + timeBounds.height() + mTextPadding;
+ }
+
+ @Override
+ public int getBarHeight(int originalBarHeight, Rect timeBounds) {
+ return originalBarHeight + timeBounds.height() + mTextPadding;
+ }
+
+ @Override
+ public int getProgressMargin(int originalMargin) {
+ return 0;
+ }
+
+ @Override
+ public int getProgressOffset(Rect timeBounds) {
+ return (timeBounds.height() + mTextPadding) / 2;
+ }
+
+ @Override
+ public int getTimeOffset() {
+ return mTextPadding - mVPaddingInPx / 2;
+ }
+
+ @Override
+ public Rect getInfoBounds(View parent, Rect timeBounds) {
+ Rect bounds = new Rect(parent.getPaddingLeft(), 0,
+ parent.getWidth() - parent.getPaddingRight(),
+ (timeBounds.height() + mTextPadding * 3 + 1) * 2);
+ return bounds;
+ }
}
diff --git a/src/com/android/gallery3d/app/TrimControllerOverlay.java b/src/com/android/gallery3d/app/TrimControllerOverlay.java
index cae016626..9d2e7aee1 100644
--- a/src/com/android/gallery3d/app/TrimControllerOverlay.java
+++ b/src/com/android/gallery3d/app/TrimControllerOverlay.java
@@ -108,4 +108,14 @@ public class TrimControllerOverlay extends CommonControllerOverlay {
}
return true;
}
+
+ @Override
+ public void setViewEnabled(boolean isEnabled) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void setPlayPauseReplayResume() {
+ // TODO Auto-generated method stub
+ }
}