summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLikai Ding <likaid@codeaurora.org>2013-08-20 14:48:29 +0800
committeremancebo <emancebo@cyngn.com>2014-09-04 10:40:18 -0700
commit9afea3e975a6e913a95b885fe8e2a0199fe91f0c (patch)
tree2d41e0bc7dbd85f523aacfb28000ded557b3f0b2 /src
parent3a90696f1ed0609449ca9adc02c931970cefd988 (diff)
downloadandroid_packages_apps_Gallery2-9afea3e975a6e913a95b885fe8e2a0199fe91f0c.tar.gz
android_packages_apps_Gallery2-9afea3e975a6e913a95b885fe8e2a0199fe91f0c.tar.bz2
android_packages_apps_Gallery2-9afea3e975a6e913a95b885fe8e2a0199fe91f0c.zip
Gallery2: add some video features
(cherry picked files from commit id 990c6d43ea7c184846e19d41bef0d93aee4e581b) Change-Id: Ifdcc4e9ab14d1f8b273faa97f0f66ba2f4034bea
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com/qcom/gallery3d/ext/IContrllerOverlayExt.java51
-rwxr-xr-xsrc/com/qcom/gallery3d/ext/IMovieList.java46
-rwxr-xr-xsrc/com/qcom/gallery3d/ext/IMovieListLoader.java50
-rwxr-xr-xsrc/com/qcom/gallery3d/ext/MovieList.java70
-rwxr-xr-xsrc/com/qcom/gallery3d/ext/MovieListLoader.java201
-rwxr-xr-xsrc/com/qcom/gallery3d/video/IControllerRewindAndForward.java35
-rwxr-xr-xsrc/com/qcom/gallery3d/video/MovieListHooker.java116
-rwxr-xr-xsrc/com/qcom/gallery3d/video/ScreenModeManager.java117
-rwxr-xr-xsrc/com/qcom/gallery3d/video/StepOptionDialogFragment.java83
-rwxr-xr-xsrc/com/qcom/gallery3d/video/StepOptionSettingsHooker.java41
-rwxr-xr-xsrc/com/qcom/gallery3d/video/VideoSettingsActivity.java182
11 files changed, 992 insertions, 0 deletions
diff --git a/src/com/qcom/gallery3d/ext/IContrllerOverlayExt.java b/src/com/qcom/gallery3d/ext/IContrllerOverlayExt.java
new file mode 100755
index 000000000..134d208df
--- /dev/null
+++ b/src/com/qcom/gallery3d/ext/IContrllerOverlayExt.java
@@ -0,0 +1,51 @@
+package com.qcom.gallery3d.ext;
+/**
+ * Controller overlay extension interface.
+ */
+public interface IContrllerOverlayExt {
+ /**
+ * Show buffering state.
+ * @param fullBuffer
+ * @param percent
+ */
+ void showBuffering(boolean fullBuffer, int percent);
+ /**
+ * Clear buffering state.
+ */
+ void clearBuffering();
+ /**
+ * Show re-connecting state.
+ * @param times
+ */
+ void showReconnecting(int times);
+ /**
+ * Show re-connecting error for connecting fail error.
+ */
+ void showReconnectingError();
+ /**
+ * Show playing info or not.
+ * @param liveStreaming true means showing playing info, otherwise doesn't show playing info.
+ */
+ void setPlayingInfo(boolean liveStreaming);
+ /**
+ * Indicates whether current video can be paused or not.
+ * @param canPause
+ */
+ void setCanPause(boolean canPause);
+ /**
+ * Indicates whether thumb can be scrubbed or not.
+ * @param enable
+ */
+ void setCanScrubbing(boolean enable);
+ /**
+ * Always show bottmon panel or not.
+ * @param alwaysShow
+ * @param foreShow
+ */
+ void setBottomPanel(boolean alwaysShow, boolean foreShow);
+ /**
+ * Is playing end or not.
+ * @return
+ */
+ boolean isPlayingEnd();
+}
diff --git a/src/com/qcom/gallery3d/ext/IMovieList.java b/src/com/qcom/gallery3d/ext/IMovieList.java
new file mode 100755
index 000000000..f58aab059
--- /dev/null
+++ b/src/com/qcom/gallery3d/ext/IMovieList.java
@@ -0,0 +1,46 @@
+package com.qcom.gallery3d.ext;
+/**
+ * Movie list extension interface
+ */
+public interface IMovieList {
+ /**
+ * Add movie item to list.
+ * @param item
+ */
+ void add(IMovieItem item);
+ /**
+ * Get the item index of list
+ * @param item
+ * @return
+ */
+ int index(IMovieItem item);
+ /**
+ *
+ * @return list size
+ */
+ int size();
+ /**
+ *
+ * @param item
+ * @return next item of current item
+ */
+ IMovieItem getNext(IMovieItem item);
+ /**
+ *
+ * @param item
+ * @return previous item of current item
+ */
+ IMovieItem getPrevious(IMovieItem item);
+ /**
+ * Is first item in list
+ * @param item
+ * @return
+ */
+ boolean isFirst(IMovieItem item);
+ /**
+ * Is last item in list.
+ * @param item
+ * @return
+ */
+ boolean isLast(IMovieItem item);
+} \ No newline at end of file
diff --git a/src/com/qcom/gallery3d/ext/IMovieListLoader.java b/src/com/qcom/gallery3d/ext/IMovieListLoader.java
new file mode 100755
index 000000000..06b2f769e
--- /dev/null
+++ b/src/com/qcom/gallery3d/ext/IMovieListLoader.java
@@ -0,0 +1,50 @@
+package com.qcom.gallery3d.ext;
+
+import android.content.Context;
+import android.content.Intent;
+
+public interface IMovieListLoader {
+ /**
+ * Load all video list or not.[boolean]
+ * "yes" means load all videos in all storages.
+ * "false" means load videos located in current video's folder.
+ */
+ String EXTRA_ALL_VIDEO_FOLDER = "qcom.intent.extra.ALL_VIDEO_FOLDER";
+ /**
+ * Video list order by column name.[String]
+ */
+ String EXTRA_ORDERBY = "qcom.intent.extra.VIDEO_LIST_ORDERBY";
+ /**
+ * Enable video list or not.[boolean]
+ */
+ String EXTRA_ENABLE_VIDEO_LIST = "qcom.intent.extra.ENABLE_VIDEO_LIST";
+ /**
+ * Loader listener interface
+ */
+ public interface LoaderListener {
+ /**
+ * Will be called after movie list loaded.
+ * @param movieList
+ */
+ void onListLoaded(IMovieList movieList);
+ }
+ /**
+ * Build the movie list from current item.
+ * @param context
+ * @param intent
+ * @param l
+ * @param item
+ */
+ void fillVideoList(Context context, Intent intent, LoaderListener l, IMovieItem item);
+ /**
+ * enable video list or not.
+ * @param intent
+ * @return
+ */
+ boolean isEnabledVideoList(Intent intent);
+ /**
+ * Cancel current loading process.
+ */
+ void cancelList();
+
+}
diff --git a/src/com/qcom/gallery3d/ext/MovieList.java b/src/com/qcom/gallery3d/ext/MovieList.java
new file mode 100755
index 000000000..eeb7e8734
--- /dev/null
+++ b/src/com/qcom/gallery3d/ext/MovieList.java
@@ -0,0 +1,70 @@
+package com.qcom.gallery3d.ext;
+
+import java.util.ArrayList;
+
+public class MovieList implements IMovieList {
+ private static final String TAG = "MovieList";
+ private static final boolean LOG = true;
+
+ private final ArrayList<IMovieItem> mItems = new ArrayList<IMovieItem>();
+ private static final int UNKNOWN = -1;
+
+ @Override
+ public void add(IMovieItem item) {
+ if (LOG) {
+ QcomLog.v(TAG, "add(" + item + ")");
+ }
+ mItems.add(item);
+ }
+
+ @Override
+ public int index(IMovieItem item) {
+ int find = UNKNOWN;
+ int size = mItems.size();
+ for (int i = 0; i < size; i++) {
+ if (item == mItems.get(i)) {
+ find = i;
+ break;
+ }
+ }
+ if (LOG) {
+ QcomLog.v(TAG, "index(" + item + ") return " + find);
+ }
+ return find;
+ }
+
+ @Override
+ public int size() {
+ return mItems.size();
+ }
+
+ @Override
+ public IMovieItem getNext(IMovieItem item) {
+ IMovieItem next = null;
+ int find = index(item);
+ if (find >= 0 && find < size() - 1) {
+ next = mItems.get(++find);
+ }
+ return next;
+ }
+
+ @Override
+ public IMovieItem getPrevious(IMovieItem item) {
+ IMovieItem prev = null;
+ int find = index(item);
+ if (find > 0 && find < size()) {
+ prev = mItems.get(--find);
+ }
+ return prev;
+ }
+
+ @Override
+ public boolean isFirst(IMovieItem item) {
+ return getPrevious(item) == null;
+ }
+
+ @Override
+ public boolean isLast(IMovieItem item) {
+ return getNext(item) == null;
+ }
+} \ No newline at end of file
diff --git a/src/com/qcom/gallery3d/ext/MovieListLoader.java b/src/com/qcom/gallery3d/ext/MovieListLoader.java
new file mode 100755
index 000000000..655beee83
--- /dev/null
+++ b/src/com/qcom/gallery3d/ext/MovieListLoader.java
@@ -0,0 +1,201 @@
+package com.qcom.gallery3d.ext;
+
+import android.content.ContentResolver;
+import android.content.ContentUris;
+import android.content.Context;
+import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteException;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.provider.MediaStore;
+import android.provider.OpenableColumns;
+/**
+ * Movie list loader class. It will load videos from MediaProvider database.
+ * If MoviePlayer starting activity doesn't set any thing, default OrderBy will be used.
+ * Default OrderBy: MediaStore.Video.Media.DATE_TAKEN + " DESC, " + MediaStore.Video.Media._ID + " DESC ";
+ */
+public class MovieListLoader implements IMovieListLoader {
+ private static final String TAG = "MovieListLoader";
+ private static final boolean LOG = true;
+
+ private MovieListFetcherTask mListTask;
+
+ @Override
+ public void fillVideoList(Context context, Intent intent, LoaderListener l, IMovieItem item) {
+ boolean fetechAll = false;
+ if (intent.hasExtra(EXTRA_ALL_VIDEO_FOLDER)) {
+ fetechAll = intent.getBooleanExtra(EXTRA_ALL_VIDEO_FOLDER, false);
+ }
+ //default order by
+ String orderBy = MediaStore.Video.Media.DATE_TAKEN + " DESC, " + MediaStore.Video.Media._ID + " DESC ";
+ if (intent.hasExtra(EXTRA_ORDERBY)) {
+ orderBy = intent.getStringExtra(EXTRA_ORDERBY);
+ }
+ cancelList();
+ mListTask = new MovieListFetcherTask(context, fetechAll, l, orderBy);
+ mListTask.execute(item);
+ if (LOG) {
+ QcomLog.v(TAG, "fillVideoList() fetechAll=" + fetechAll + ", orderBy=" + orderBy);
+ }
+ }
+
+ @Override
+ public boolean isEnabledVideoList(Intent intent) {
+ boolean enable = true;
+ if (intent != null && intent.hasExtra(EXTRA_ENABLE_VIDEO_LIST)) {
+ enable = intent.getBooleanExtra(EXTRA_ENABLE_VIDEO_LIST, true);
+ }
+ if (LOG) {
+ QcomLog.v(TAG, "isEnabledVideoList() return " + enable);
+ }
+ return enable;
+ }
+
+ @Override
+ public void cancelList() {
+ if (mListTask != null) {
+ mListTask.cancel(true);
+ }
+ }
+
+ private class MovieListFetcherTask extends AsyncTask<IMovieItem, Void, IMovieList> {
+ private static final String TAG = "MovieListFetcherTask";
+ private static final boolean LOG = true;
+
+ // TODO comments by sunlei
+// public static final String COLUMN_STEREO_TYPE = MediaStore.Video.Media.STEREO_TYPE;
+// public static final String COLUMN_STEREO_TYPE = "STEREO_TYPE";
+
+ private final ContentResolver mCr;
+ private final LoaderListener mFetecherListener;
+ private final boolean mFetechAll;
+ private final String mOrderBy;
+
+ public MovieListFetcherTask(Context context, boolean fetechAll, LoaderListener l, String orderBy) {
+ mCr = context.getContentResolver();
+ mFetecherListener = l;
+ mFetechAll = fetechAll;
+ mOrderBy = orderBy;
+ if (LOG) {
+ QcomLog.v(TAG, "MovieListFetcherTask() fetechAll=" + fetechAll + ", orderBy=" + orderBy);
+ }
+ }
+
+ @Override
+ protected void onPostExecute(IMovieList params) {
+ if (LOG) {
+ QcomLog.v(TAG, "onPostExecute() isCancelled()=" + isCancelled());
+ }
+ if (isCancelled()) {
+ return;
+ }
+ if (mFetecherListener != null) {
+ mFetecherListener.onListLoaded(params);
+ }
+ }
+
+ @Override
+ protected IMovieList doInBackground(IMovieItem... params) {
+ if (LOG) {
+ QcomLog.v(TAG, "doInBackground() begin");
+ }
+ if (params[0] == null) {
+ return null;
+ }
+ IMovieList movieList = null;
+ Uri uri = params[0].getUri();
+ String mime = params[0].getMimeType();
+ if (mFetechAll) { //get all list
+ if (MovieUtils.isLocalFile(uri, mime)) {
+ String uristr = String.valueOf(uri);
+ if (uristr.toLowerCase().startsWith("content://media")) {
+ //from gallery, gallery3D, videoplayer
+ long curId = Long.parseLong(uri.getPathSegments().get(3));
+ movieList = fillUriList(null, null, curId, params[0]);
+ }
+ }
+ } else { //get current list
+ if (MovieUtils.isLocalFile(uri, mime)) {
+ String uristr = String.valueOf(uri);
+ if (uristr.toLowerCase().startsWith("content://media")) {
+ Cursor cursor = mCr.query(uri,
+ new String[]{MediaStore.Video.Media.BUCKET_ID},
+ null, null, null);
+ long bucketId = -1;
+ if (cursor != null) {
+ if (cursor.moveToFirst()) {
+ bucketId = cursor.getLong(0);
+ }
+ cursor.close();
+ }
+ long curId = Long.parseLong(uri.getPathSegments().get(3));
+ movieList = fillUriList(MediaStore.Video.Media.BUCKET_ID + "=? ",
+ new String[]{String.valueOf(bucketId)}, curId, params[0]);
+ } else if (uristr.toLowerCase().startsWith("file://")) {
+ String data = Uri.decode(uri.toString());
+ data = data.replaceAll("'", "''");
+ String where = "_data LIKE '%" + data.replaceFirst("file:///", "") + "'";
+ Cursor cursor = mCr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
+ new String[]{"_id", MediaStore.Video.Media.BUCKET_ID},
+ where, null, null);
+ long bucketId = -1;
+ long curId = -1;
+ if (cursor != null) {
+ if (cursor.moveToFirst()) {
+ curId = cursor.getLong(0);
+ bucketId = cursor.getLong(1);
+ }
+ cursor.close();
+ }
+ movieList = fillUriList(MediaStore.Video.Media.BUCKET_ID + "=? ",
+ new String[]{String.valueOf(bucketId)}, curId, params[0]);
+ }
+ }
+ }
+ if (LOG) {
+ QcomLog.v(TAG, "doInBackground() done return " + movieList);
+ }
+ return movieList;
+ }
+
+ private IMovieList fillUriList(String where, String[] whereArgs, long curId, IMovieItem current) {
+ IMovieList movieList = null;
+ Cursor cursor = null;
+ try {
+ cursor = mCr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
+ new String[]{"_id", "mime_type", OpenableColumns.DISPLAY_NAME},
+ where,
+ whereArgs,
+ mOrderBy);
+ boolean find = false;
+ if (cursor != null && cursor.getCount() > 0) {
+ movieList = new MovieList();
+ while (cursor.moveToNext()) {
+ long id = cursor.getLong(0);
+ if (!find && id == curId) {
+ find = true;
+ movieList.add(current);
+ continue;
+ }
+ Uri uri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id);
+ String mimeType = cursor.getString(1);
+ String title = cursor.getString(2);
+
+ movieList.add(new MovieItem(uri, mimeType, title));
+ }
+ }
+ } catch (final SQLiteException e) {
+ e.printStackTrace();
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+ if (LOG) {
+ QcomLog.v(TAG, "fillUriList() cursor=" + cursor + ", return " + movieList);
+ }
+ return movieList;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/qcom/gallery3d/video/IControllerRewindAndForward.java b/src/com/qcom/gallery3d/video/IControllerRewindAndForward.java
new file mode 100755
index 000000000..39316b165
--- /dev/null
+++ b/src/com/qcom/gallery3d/video/IControllerRewindAndForward.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.qcom.gallery3d.video;
+
+import com.android.gallery3d.app.ControllerOverlay;
+import com.android.gallery3d.app.ControllerOverlay.Listener;
+
+///M: for CU rewind and forward
+public interface IControllerRewindAndForward extends ControllerOverlay {
+
+ interface IRewindAndForwardListener extends Listener {
+ void onStopVideo();
+ void onRewind();
+ void onForward();
+ }
+
+ boolean getPlayPauseEanbled();
+ boolean getTimeBarEanbled();
+ void setIListener(IRewindAndForwardListener listener);
+ void showControllerButtonsView(boolean canStop, boolean canRewind, boolean canForward);
+}
diff --git a/src/com/qcom/gallery3d/video/MovieListHooker.java b/src/com/qcom/gallery3d/video/MovieListHooker.java
new file mode 100755
index 000000000..8a5c487af
--- /dev/null
+++ b/src/com/qcom/gallery3d/video/MovieListHooker.java
@@ -0,0 +1,116 @@
+package com.qcom.gallery3d.video;
+
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import com.android.gallery3d.R;
+import com.qcom.gallery3d.ext.IMovieItem;
+import com.qcom.gallery3d.ext.IMovieList;
+import com.qcom.gallery3d.ext.IMovieListLoader;
+import com.qcom.gallery3d.ext.IMovieListLoader.LoaderListener;
+import com.qcom.gallery3d.ext.MovieListLoader;
+import com.qcom.gallery3d.ext.QcomLog;
+
+public class MovieListHooker extends MovieHooker implements LoaderListener {
+ private static final String TAG = "MovieListHooker";
+ private static final boolean LOG = true;
+
+ private static final int MENU_NEXT = 1;
+ private static final int MENU_PREVIOUS = 2;
+
+ private MenuItem mMenuNext;
+ private MenuItem mMenuPrevious;
+
+ private IMovieListLoader mMovieLoader;
+ private IMovieList mMovieList;
+
+ @Override
+ public void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mMovieLoader = new MovieListLoader();
+ mMovieLoader.fillVideoList(getContext(), getIntent(), this, getMovieItem());
+ }
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ mMovieLoader.cancelList();
+ }
+ @Override
+ public boolean onCreateOptionsMenu(final Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ if (mMovieList != null) { //list should be filled
+ if (mMovieLoader != null && mMovieLoader.isEnabledVideoList(getIntent())) {
+ mMenuPrevious = menu.add(0, getMenuActivityId(MENU_PREVIOUS), 0, R.string.previous);
+ mMenuNext = menu.add(0, getMenuActivityId(MENU_NEXT), 0, R.string.next);
+ }
+ }
+ return true;
+ }
+ @Override
+ public boolean onPrepareOptionsMenu(final Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ updatePrevNext();
+ return true;
+ }
+ @Override
+ public boolean onOptionsItemSelected(final MenuItem item) {
+ super.onOptionsItemSelected(item);
+ switch(getMenuOriginalId(item.getItemId())) {
+ case MENU_PREVIOUS:
+ if (mMovieList == null) {
+ return false;
+ }
+ getPlayer().startNextVideo(mMovieList.getPrevious(getMovieItem()));
+ return true;
+ case MENU_NEXT:
+ if (mMovieList == null) {
+ return false;
+ }
+ getPlayer().startNextVideo(mMovieList.getNext(getMovieItem()));
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ @Override
+ public void onMovieItemChanged(final IMovieItem item) {
+ super.onMovieItemChanged(item);
+ updatePrevNext();
+ }
+
+ private void updatePrevNext() {
+ if (LOG) {
+ QcomLog.v(TAG, "updatePrevNext()");
+ }
+ if (mMovieList != null && mMenuPrevious != null && mMenuNext != null) {
+ if (mMovieList.isFirst(getMovieItem()) && mMovieList.isLast(getMovieItem())) { //only one movie
+ mMenuNext.setVisible(false);
+ mMenuPrevious.setVisible(false);
+ } else {
+ mMenuNext.setVisible(true);
+ mMenuPrevious.setVisible(true);
+ }
+ if (mMovieList.isFirst(getMovieItem())) {
+ mMenuPrevious.setEnabled(false);
+ } else {
+ mMenuPrevious.setEnabled(true);
+ }
+ if (mMovieList.isLast(getMovieItem())) {
+ mMenuNext.setEnabled(false);
+ } else {
+ mMenuNext.setEnabled(true);
+ }
+ }
+ }
+
+ @Override
+ public void onListLoaded(final IMovieList movieList) {
+ mMovieList = movieList;
+ getContext().invalidateOptionsMenu();
+ if (LOG) {
+ QcomLog.v(TAG, "onListLoaded() " + (mMovieList != null ? mMovieList.size() : "null"));
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/qcom/gallery3d/video/ScreenModeManager.java b/src/com/qcom/gallery3d/video/ScreenModeManager.java
new file mode 100755
index 000000000..73f60520a
--- /dev/null
+++ b/src/com/qcom/gallery3d/video/ScreenModeManager.java
@@ -0,0 +1,117 @@
+package com.qcom.gallery3d.video;
+
+import com.qcom.gallery3d.ext.QcomLog;
+
+import java.util.ArrayList;
+
+public class ScreenModeManager {
+ private static final String TAG = "ScreenModeManager";
+ private static final boolean LOG = true;
+ //support screen mode.
+ public static final int SCREENMODE_BIGSCREEN = 1;
+ public static final int SCREENMODE_FULLSCREEN = 2;
+ public static final int SCREENMODE_CROPSCREEN = 4;
+ public static final int SCREENMODE_ALL = 7;
+
+ private int mScreenMode = SCREENMODE_BIGSCREEN;
+ private int mScreenModes = SCREENMODE_ALL;
+
+ /**
+ * Enable specified screen mode list.
+ * The screen mode's value determines the order of being shown.
+ * <br>you can enable three screen modes by setting screenModes =
+ * {@link #SCREENMODE_BIGSCREEN} |
+ * {@link #SCREENMODE_FULLSCREEN} |
+ * {@link #SCREENMODE_CROPSCREEN} or
+ * just enable two screen modes by setting screenModes =
+ * {@link #SCREENMODE_BIGSCREEN} |
+ * {@link #SCREENMODE_CROPSCREEN}.
+ * <br>If current screen mode is the last one of the ordered list,
+ * then the next screen mode will be the first one of the ordered list.
+ * @param screenModes enabled screen mode list.
+ */
+ public void setScreenModes(final int screenModes) {
+ mScreenModes = (SCREENMODE_BIGSCREEN & screenModes)
+ | (SCREENMODE_FULLSCREEN & screenModes)
+ | (SCREENMODE_CROPSCREEN & screenModes);
+ if ((screenModes & SCREENMODE_ALL) == 0) {
+ mScreenModes = SCREENMODE_ALL;
+ QcomLog.w(TAG, "wrong screenModes=" + screenModes + ". use default value " + SCREENMODE_ALL);
+ }
+ if (LOG) {
+ QcomLog.v(TAG, "enableScreenMode(" + screenModes + ") mScreenModes=" + mScreenModes);
+ }
+ }
+
+ /**
+ * Get the all screen modes of media controller.
+ * <br><b>Note:</b> it is not the video's current screen mode.
+ * @return the current screen modes.
+ */
+ public int getScreenModes() {
+ return mScreenModes;
+ }
+
+ public void setScreenMode(final int curScreenMode) {
+ if (LOG) {
+ QcomLog.v(TAG, "setScreenMode(" + curScreenMode + ")");
+ }
+ mScreenMode = curScreenMode;
+ for (final ScreenModeListener listener : mListeners) {
+ listener.onScreenModeChanged(curScreenMode);
+ }
+ }
+
+ public int getScreenMode() {
+ if (LOG) {
+ QcomLog.v(TAG, "getScreenMode() return " + mScreenMode);
+ }
+ return mScreenMode;
+ }
+
+ public int getNextScreenMode() {
+ int mode = getScreenMode();
+ mode <<= 1;
+ if ((mode & mScreenModes) == 0) {
+ //not exist, find the right one
+ if (mode > mScreenModes) {
+ mode = 1;
+ }
+ while ((mode & mScreenModes) == 0) {
+ mode <<= 1;
+ if (mode > mScreenModes) {
+ throw new RuntimeException("wrong screen mode = " + mScreenModes);
+ }
+ }
+ }
+ if (LOG) {
+ QcomLog.v(TAG, "getNextScreenMode() = " + mode);
+ }
+ return mode;
+ }
+
+ private final ArrayList<ScreenModeListener> mListeners = new ArrayList<ScreenModeListener>();
+ public void addListener(final ScreenModeListener l) {
+ if (!mListeners.contains(l)) {
+ mListeners.add(l);
+ }
+ if (LOG) {
+ QcomLog.v(TAG, "addListener(" + l + ")");
+ }
+ }
+
+ public void removeListener(final ScreenModeListener l) {
+ mListeners.remove(l);
+ if (LOG) {
+ QcomLog.v(TAG, "removeListener(" + l + ")");
+ }
+ }
+
+ public void clear() {
+ mListeners.clear();
+ }
+
+ public interface ScreenModeListener {
+ void onScreenModeChanged(int newMode);
+ }
+}
diff --git a/src/com/qcom/gallery3d/video/StepOptionDialogFragment.java b/src/com/qcom/gallery3d/video/StepOptionDialogFragment.java
new file mode 100755
index 000000000..0daed55f6
--- /dev/null
+++ b/src/com/qcom/gallery3d/video/StepOptionDialogFragment.java
@@ -0,0 +1,83 @@
+package com.qcom.gallery3d.video;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+/** M: use DialogFragment to show Dialog */
+public class StepOptionDialogFragment extends DialogFragment implements
+ DialogInterface.OnClickListener{
+
+ private static final String KEY_ITEM_ARRAY = "itemArray";
+ private static final String KEY_TITLE = "title";
+ private static final String KEY_DEFAULT_SELECT = "nowSelect";
+ private DialogInterface.OnClickListener mClickListener = null;
+
+ /**
+ * M: create a instance of SelectDialogFragment
+ *
+ * @param itemArrayID
+ * the resource id array of strings that show in list
+ * @param sufffixArray
+ * the suffix array at the right of list item
+ * @param titleID
+ * the resource id of title string
+ * @param nowSelect
+ * the current select item index
+ * @return the instance of SelectDialogFragment
+ */
+ public static StepOptionDialogFragment newInstance(int[] itemArrayID,
+ int titleID, int nowSelect) {
+ StepOptionDialogFragment frag = new StepOptionDialogFragment();
+ Bundle args = new Bundle();
+ args.putIntArray(KEY_ITEM_ARRAY, itemArrayID);
+ args.putInt(KEY_TITLE, titleID);
+ args.putInt(KEY_DEFAULT_SELECT, nowSelect);
+ frag.setArguments(args);
+ return frag;
+ }
+
+ @Override
+ /**
+ * M: create a select dialog
+ */
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ Bundle args = getArguments();
+ final String title = getString(args.getInt(KEY_TITLE));
+ final int[] itemArrayID = args.getIntArray(KEY_ITEM_ARRAY);
+ int arraySize = itemArrayID.length;
+ CharSequence[] itemArray = new CharSequence[arraySize];
+ for (int i = 0; i < arraySize; i++) {
+ itemArray[i] = getString(itemArrayID[i]);
+ }
+
+ AlertDialog.Builder builder = null;
+ int nowSelect = args.getInt(KEY_DEFAULT_SELECT);
+ builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(title).setSingleChoiceItems(itemArray, nowSelect, this)
+ .setNegativeButton(getString(android.R.string.cancel), null);
+ return builder.create();
+ }
+
+ @Override
+ /**
+ * M: the process of select an item
+ */
+ public void onClick(DialogInterface arg0, int arg1) {
+ if (null != mClickListener) {
+ mClickListener.onClick(arg0, arg1);
+ }
+ }
+
+ /**
+ * M: set listener of click items
+ *
+ * @param listener
+ * the listener to be set
+ */
+ public void setOnClickListener(DialogInterface.OnClickListener listener) {
+ mClickListener = listener;
+ }
+} \ No newline at end of file
diff --git a/src/com/qcom/gallery3d/video/StepOptionSettingsHooker.java b/src/com/qcom/gallery3d/video/StepOptionSettingsHooker.java
new file mode 100755
index 000000000..ecc29670c
--- /dev/null
+++ b/src/com/qcom/gallery3d/video/StepOptionSettingsHooker.java
@@ -0,0 +1,41 @@
+package com.qcom.gallery3d.video;
+
+import android.content.Intent;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.app.MovieActivity;
+import com.qcom.gallery3d.ext.ActivityHooker;
+import com.qcom.gallery3d.video.VideoSettingsActivity;
+
+public class StepOptionSettingsHooker extends ActivityHooker {
+ private static final int MENU_STEP_OPTION_SETTING = 1;
+ private MenuItem mMenuStepOption;
+
+ @Override
+ public boolean onCreateOptionsMenu(final Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ mMenuStepOption = menu.add(0, getMenuActivityId(MENU_STEP_OPTION_SETTING), 0, R.string.settings);
+ return true;
+ }
+ @Override
+ public boolean onPrepareOptionsMenu(final Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ return true;
+ }
+ @Override
+ public boolean onOptionsItemSelected(final MenuItem item) {
+ super.onOptionsItemSelected(item);
+ switch(getMenuOriginalId(item.getItemId())) {
+ case MENU_STEP_OPTION_SETTING:
+ //start activity
+ Intent mIntent = new Intent();
+ mIntent.setClass(getContext(), VideoSettingsActivity.class);
+ getContext().startActivity(mIntent);
+ return true;
+ default:
+ return false;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/qcom/gallery3d/video/VideoSettingsActivity.java b/src/com/qcom/gallery3d/video/VideoSettingsActivity.java
new file mode 100755
index 000000000..98d5539fb
--- /dev/null
+++ b/src/com/qcom/gallery3d/video/VideoSettingsActivity.java
@@ -0,0 +1,182 @@
+package com.qcom.gallery3d.video;
+
+import android.app.ListActivity;
+
+import android.app.ActionBar;
+import android.app.Activity;
+import android.app.DialogFragment;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.text.TextUtils;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.SimpleAdapter;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import com.android.gallery3d.R;
+
+public class VideoSettingsActivity extends ListActivity {
+ private String OPTION_NAME = "option_name";
+ private String OPTION_DESC = "option_desc";
+ private String DIALOG_TAG_SELECT_STEP_OPTION = "step_option_dialog";
+ private static int[] sStepOptionArray = null;
+ private static final int STEP_OPTION_THREE_SECOND = 0;
+ private static final int STEP_OPTION_SIX_SECOND = 1;
+ private static final String SELECTED_STEP_OPTION = "selected_step_option";
+ private static final String VIDEO_PLAYER_DATA = "video_player_data";
+ private int mSelectedStepOption = -1;
+ private SharedPreferences mPrefs = null;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ ActionBar actionBar = getActionBar();
+ actionBar.setDisplayHomeAsUpEnabled(true);
+ actionBar.setTitle(getResources().getString(R.string.settings));
+ setContentView(R.layout.setting_list);
+ ArrayList<HashMap<String, Object>> arrlist = new ArrayList<HashMap<String, Object>>(1);
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ map.put(OPTION_NAME, getString(R.string.setp_option_name));
+ map.put(OPTION_DESC, getString(R.string.step_option_desc));
+ arrlist.add(map);
+ SimpleAdapter adapter = new SimpleAdapter(this, arrlist, android.R.layout.simple_expandable_list_item_2,
+ new String[] { OPTION_NAME, OPTION_DESC }, new int[] {
+ android.R.id.text1, android.R.id.text2});
+ setListAdapter(adapter);
+ restoreStepOptionSettings();
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ storeStepOptionSettings();
+ super.onSaveInstanceState(outState);
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ super.onRestoreInstanceState(savedInstanceState);
+ restoreDialogFragment();
+ restoreStepOptionSettings();
+ }
+
+
+
+ @Override
+ protected void onDestroy() {
+ // TODO Auto-generated method stub
+ storeStepOptionSettings();
+ super.onDestroy();
+ }
+
+ @Override
+ protected void onListItemClick(ListView arg0, View arg1, int arg2, long arg3) {
+ switch (arg2) {
+ case 0:
+ DialogFragment newFragment = null;
+ FragmentManager fragmentManager = getFragmentManager();
+ removeOldFragmentByTag(DIALOG_TAG_SELECT_STEP_OPTION);
+ newFragment = StepOptionDialogFragment.newInstance(getStepOptionIDArray(),
+ R.string.setp_option_name, mSelectedStepOption);
+ ((StepOptionDialogFragment) newFragment).setOnClickListener(mStepOptionSelectedListener);
+ newFragment.show(fragmentManager, DIALOG_TAG_SELECT_STEP_OPTION);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private int[] getStepOptionIDArray() {
+ int[] stepOptionIDArray = new int[2];
+ stepOptionIDArray[STEP_OPTION_THREE_SECOND] = R.string.setp_option_three_second;
+ stepOptionIDArray[STEP_OPTION_SIX_SECOND] = R.string.setp_option_six_second;
+ sStepOptionArray = new int[2];
+ sStepOptionArray[0] = STEP_OPTION_THREE_SECOND;
+ sStepOptionArray[1] = STEP_OPTION_SIX_SECOND;
+ return stepOptionIDArray;
+ }
+
+ private DialogInterface.OnClickListener mStepOptionSelectedListener = new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int whichItemSelect) {
+ setSelectedStepOption(whichItemSelect);
+ dialog.dismiss();
+ }
+ };
+
+ public void setSelectedStepOption(int which) {
+ mSelectedStepOption = getSelectedStepOption(which);
+ }
+
+ static int getSelectedStepOption(int which) {
+ return sStepOptionArray[which];
+ }
+
+ /**
+ * remove old DialogFragment
+ *
+ * @param tag
+ * the tag of DialogFragment to be removed
+ */
+ private void removeOldFragmentByTag(String tag) {
+ FragmentManager fragmentManager = getFragmentManager();
+ DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(tag);
+ if (null != oldFragment) {
+ oldFragment.dismissAllowingStateLoss();
+ }
+ }
+
+ private void restoreDialogFragment() {
+ FragmentManager fragmentManager = getFragmentManager();
+ Fragment fragment = fragmentManager.findFragmentByTag(DIALOG_TAG_SELECT_STEP_OPTION);
+ if (null != fragment) {
+ ((StepOptionDialogFragment) fragment).setOnClickListener(mStepOptionSelectedListener);
+ }
+ }
+
+ private void storeStepOptionSettings() {
+ if (null == mPrefs) {
+ mPrefs = getSharedPreferences(VIDEO_PLAYER_DATA, 0);
+ }
+ SharedPreferences.Editor ed = mPrefs.edit();
+ ed.clear();
+ ed.putInt(SELECTED_STEP_OPTION, mSelectedStepOption);
+ ed.commit();
+ }
+
+ private void restoreStepOptionSettings() {
+ if (null == mPrefs) {
+ mPrefs = getSharedPreferences(VIDEO_PLAYER_DATA, 0);
+ }
+ mSelectedStepOption = mPrefs.getInt(SELECTED_STEP_OPTION, STEP_OPTION_THREE_SECOND);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ // The user clicked on the Messaging icon in the action bar. Take them back from
+ // wherever they came from
+ finish();
+ return true;
+ }
+ return false;
+ }
+}