blob: c110a8ccceacf109b9d7c1f840388264abffdf19 [file] [log] [blame]
Owen Linf9a0a432011-08-17 22:07:43 +08001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.gallery3d.app;
18
Yuli Huangfc869942012-06-29 18:59:17 +080019import android.annotation.TargetApi;
John Reck2abaaf72012-12-12 13:43:43 -080020import android.app.ActionBar.OnMenuVisibilityListener;
Owen Lin8bc5beb2011-11-17 15:26:56 +080021import android.app.Activity;
Ray Chen604f0532011-10-21 16:07:12 +080022import android.content.ActivityNotFoundException;
23import android.content.Context;
24import android.content.Intent;
Bobby Georgescua9948ef2012-09-11 17:02:03 -070025import android.content.pm.PackageManager;
John Reck4ea5c272013-01-18 16:00:45 -080026import android.content.res.Configuration;
Yuli Huang04ac0452012-03-20 16:37:05 +080027import android.graphics.Rect;
Ray Chen604f0532011-10-21 16:07:12 +080028import android.net.Uri;
Martijn Coenen33ef0372012-03-26 18:25:50 -070029import android.nfc.NfcAdapter;
John Reckddf02252012-09-26 11:37:23 -070030import android.nfc.NfcAdapter.CreateBeamUrisCallback;
31import android.nfc.NfcEvent;
Ray Chen604f0532011-10-21 16:07:12 +080032import android.os.Bundle;
33import android.os.Handler;
34import android.os.Message;
Bobby Georgescub27df462012-09-27 23:55:44 -070035import android.os.SystemClock;
John Reck2abaaf72012-12-12 13:43:43 -080036import android.view.Menu;
37import android.view.MenuItem;
Bobby Georgescua9948ef2012-09-11 17:02:03 -070038import android.widget.RelativeLayout;
Ray Chen604f0532011-10-21 16:07:12 +080039import android.widget.Toast;
40
Bobby Georgescu5bd00332012-10-24 12:09:38 -070041import com.android.camera.CameraActivity;
John Reckf85d9742012-10-24 11:11:51 -070042import com.android.camera.ProxyLauncher;
Owen Linf9a0a432011-08-17 22:07:43 +080043import com.android.gallery3d.R;
Yuli Huangfc869942012-06-29 18:59:17 +080044import com.android.gallery3d.common.ApiHelper;
Bobby Georgescuee899c02012-10-01 17:49:30 -070045import com.android.gallery3d.data.ComboAlbum;
Owen Linf9a0a432011-08-17 22:07:43 +080046import com.android.gallery3d.data.DataManager;
Chih-Chung Chang6b891c62012-06-07 20:09:13 +080047import com.android.gallery3d.data.FilterDeleteSet;
Bobby Georgescu45f089d2012-10-02 13:30:09 -070048import com.android.gallery3d.data.FilterSource;
George Mount4e091eb2012-10-09 21:02:42 -070049import com.android.gallery3d.data.LocalImage;
Owen Linf9a0a432011-08-17 22:07:43 +080050import com.android.gallery3d.data.MediaDetails;
51import com.android.gallery3d.data.MediaItem;
52import com.android.gallery3d.data.MediaObject;
George Mount4b4dbd22012-10-18 14:20:39 -070053import com.android.gallery3d.data.MediaObject.PanoramaSupportCallback;
Owen Linf9a0a432011-08-17 22:07:43 +080054import com.android.gallery3d.data.MediaSet;
Owen Linf9a0a432011-08-17 22:07:43 +080055import com.android.gallery3d.data.Path;
Wu-cheng Lia0ce6822012-08-22 19:15:35 +080056import com.android.gallery3d.data.SecureAlbum;
57import com.android.gallery3d.data.SecureSource;
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +080058import com.android.gallery3d.data.SnailAlbum;
59import com.android.gallery3d.data.SnailItem;
Chih-Chung Chang15b351a2012-03-15 16:38:45 +080060import com.android.gallery3d.data.SnailSource;
Ruben Brunk63926d22012-10-17 00:40:35 -070061import com.android.gallery3d.filtershow.FilterShowActivity;
Owen Linf9a0a432011-08-17 22:07:43 +080062import com.android.gallery3d.picasasource.PicasaSource;
Ray Chen4105e222011-08-24 11:40:04 +080063import com.android.gallery3d.ui.DetailsHelper;
64import com.android.gallery3d.ui.DetailsHelper.CloseListener;
65import com.android.gallery3d.ui.DetailsHelper.DetailsSource;
Owen Linf9a0a432011-08-17 22:07:43 +080066import com.android.gallery3d.ui.GLView;
Owen Linf9a0a432011-08-17 22:07:43 +080067import com.android.gallery3d.ui.MenuExecutor;
Owen Lin21a412c2012-04-20 18:42:22 +080068import com.android.gallery3d.ui.PhotoView;
Owen Linf9a0a432011-08-17 22:07:43 +080069import com.android.gallery3d.ui.SelectionManager;
70import com.android.gallery3d.ui.SynchronizedHandler;
Owen Linf9a0a432011-08-17 22:07:43 +080071import com.android.gallery3d.util.GalleryUtils;
72
Bobby Georgescucfa7fde2012-11-05 14:12:51 -080073public abstract class PhotoPage extends ActivityState implements
Your Name3c6a0612012-11-26 16:33:49 -080074 PhotoView.Listener, AppBridge.Server,
Bobby Georgescu3cf502a2012-10-01 15:50:11 -070075 PhotoPageBottomControls.Delegate, GalleryActionBar.OnAlbumModeSelectedListener {
Owen Linf9a0a432011-08-17 22:07:43 +080076 private static final String TAG = "PhotoPage";
77
78 private static final int MSG_HIDE_BARS = 1;
Chih-Chung Changbd141b52012-04-26 10:10:49 +080079 private static final int MSG_ON_FULL_SCREEN_CHANGED = 4;
Chih-Chung Chang61f94712012-05-02 20:05:16 +080080 private static final int MSG_UPDATE_ACTION_BAR = 5;
Yuli Huangbd7c0162012-05-15 22:36:59 +080081 private static final int MSG_UNFREEZE_GLROOT = 6;
Chih-Chung Change6251df2012-05-22 11:35:46 -070082 private static final int MSG_WANT_BARS = 7;
Bobby Georgescu3cf502a2012-10-01 15:50:11 -070083 private static final int MSG_REFRESH_BOTTOM_CONTROLS = 8;
84 private static final int MSG_ON_CAMERA_CENTER = 9;
Bobby Georgescuf4e22eb2012-10-02 18:34:08 -070085 private static final int MSG_ON_PICTURE_CENTER = 10;
George Mountf122d562012-10-09 17:50:33 -070086 private static final int MSG_REFRESH_IMAGE = 11;
Mangesh Ghiware423e45e2012-10-11 23:11:27 -070087 private static final int MSG_UPDATE_PHOTO_UI = 12;
Mangesh Ghiware825afb12012-10-10 18:37:24 -070088 private static final int MSG_UPDATE_PROGRESS = 13;
Mangesh Ghiware423e45e2012-10-11 23:11:27 -070089 private static final int MSG_UPDATE_DEFERRED = 14;
George Mount4b4dbd22012-10-18 14:20:39 -070090 private static final int MSG_UPDATE_SHARE_URI = 15;
91 private static final int MSG_UPDATE_PANORAMA_UI = 16;
Owen Lin6cf80742011-08-28 10:50:21 +080092
Owen Linf9a0a432011-08-17 22:07:43 +080093 private static final int HIDE_BARS_TIMEOUT = 3500;
Yuli Huangbd7c0162012-05-15 22:36:59 +080094 private static final int UNFREEZE_GLROOT_TIMEOUT = 250;
Owen Linf9a0a432011-08-17 22:07:43 +080095
96 private static final int REQUEST_SLIDESHOW = 1;
97 private static final int REQUEST_CROP = 2;
98 private static final int REQUEST_CROP_PICASA = 3;
Yuli Huangf50ce2b2012-05-02 00:50:56 +080099 private static final int REQUEST_EDIT = 4;
Chih-Chung Chang71cd89a2012-05-17 18:22:27 -0700100 private static final int REQUEST_PLAY_VIDEO = 5;
Teng-Hui Zhu3f1f1ba2012-08-24 14:50:37 -0700101 private static final int REQUEST_TRIM = 6;
Owen Linf9a0a432011-08-17 22:07:43 +0800102
103 public static final String KEY_MEDIA_SET_PATH = "media-set-path";
104 public static final String KEY_MEDIA_ITEM_PATH = "media-item-path";
105 public static final String KEY_INDEX_HINT = "index-hint";
Yuli Huang04ac0452012-03-20 16:37:05 +0800106 public static final String KEY_OPEN_ANIMATION_RECT = "open-animation-rect";
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800107 public static final String KEY_APP_BRIDGE = "app-bridge";
Yuli Huang54fe6202012-05-23 16:06:32 +0800108 public static final String KEY_TREAT_BACK_AS_UP = "treat-back-as-up";
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700109 public static final String KEY_START_IN_FILMSTRIP = "start-in-filmstrip";
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800110 public static final String KEY_RETURN_INDEX_HINT = "return-index-hint";
Wu-cheng Li23e595f2012-09-21 14:36:21 +0800111 public static final String KEY_SHOW_WHEN_LOCKED = "show_when_locked";
Bobby Georgescu45f089d2012-10-02 13:30:09 -0700112 public static final String KEY_IN_CAMERA_ROLL = "in_camera_roll";
Owen Linf9a0a432011-08-17 22:07:43 +0800113
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700114 public static final String KEY_ALBUMPAGE_TRANSITION = "albumpage-transition";
115 public static final int MSG_ALBUMPAGE_NONE = 0;
116 public static final int MSG_ALBUMPAGE_STARTED = 1;
117 public static final int MSG_ALBUMPAGE_RESUMED = 2;
118 public static final int MSG_ALBUMPAGE_PICKED = 4;
119
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700120 public static final String ACTION_NEXTGEN_EDIT = "action_nextgen_edit";
121
Owen Linf9a0a432011-08-17 22:07:43 +0800122 private GalleryApp mApplication;
123 private SelectionManager mSelectionManager;
124
125 private PhotoView mPhotoView;
126 private PhotoPage.Model mModel;
Ray Chen4105e222011-08-24 11:40:04 +0800127 private DetailsHelper mDetailsHelper;
Owen Linf9a0a432011-08-17 22:07:43 +0800128 private boolean mShowDetails;
129
130 // mMediaSet could be null if there is no KEY_MEDIA_SET_PATH supplied.
131 // E.g., viewing a photo in gmail attachment
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800132 private FilterDeleteSet mMediaSet;
Owen Linf9a0a432011-08-17 22:07:43 +0800133
Wu-cheng Lia0ce6822012-08-22 19:15:35 +0800134 // The mediaset used by camera launched from secure lock screen.
135 private SecureAlbum mSecureAlbum;
136
Owen Linf9a0a432011-08-17 22:07:43 +0800137 private int mCurrentIndex = 0;
138 private Handler mHandler;
Owen Lin113bfc72011-08-30 10:38:59 +0800139 private boolean mShowBars = true;
Chih-Chung Chang61f94712012-05-02 20:05:16 +0800140 private volatile boolean mActionBarAllowed = true;
Ray Chen8cab3e82012-03-20 16:32:57 +0800141 private GalleryActionBar mActionBar;
Owen Linf9a0a432011-08-17 22:07:43 +0800142 private boolean mIsMenuVisible;
John Reck8fe22ec2012-09-26 16:13:02 -0700143 private boolean mHaveImageEditor;
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700144 private PhotoPageBottomControls mBottomControls;
George Mountf122d562012-10-09 17:50:33 -0700145 private PhotoPageProgressBar mProgressBar;
Owen Linf9a0a432011-08-17 22:07:43 +0800146 private MediaItem mCurrentPhoto = null;
147 private MenuExecutor mMenuExecutor;
148 private boolean mIsActive;
Bobby Georgescuba65c372012-10-06 01:06:43 -0700149 private boolean mShowSpinner;
Ray Chen84c220f2012-03-06 17:24:28 +0800150 private String mSetPathString;
Chih-Chung Changb1e9fd82012-04-30 17:33:21 +0800151 // This is the original mSetPathString before adding the camera preview item.
152 private String mOriginalSetPathString;
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800153 private AppBridge mAppBridge;
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +0800154 private SnailItem mScreenNailItem;
155 private SnailAlbum mScreenNailSet;
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800156 private OrientationManager mOrientationManager;
Yuli Huang54fe6202012-05-23 16:06:32 +0800157 private boolean mTreatBackAsUp;
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700158 private boolean mStartInFilmstrip;
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -0700159 private boolean mHasCameraScreennailOrPlaceholder = false;
Bobby Georgescud81b2642012-10-07 16:25:54 -0700160 private boolean mRecenterCameraOnResume = true;
Chih-Chung Chang15b351a2012-03-15 16:38:45 +0800161
Doris Liua680a0c2012-10-18 15:01:35 -0700162 // These are only valid after the panorama callback
163 private boolean mIsPanorama;
164 private boolean mIsPanorama360;
165
Bobby Georgescub27df462012-09-27 23:55:44 -0700166 private long mCameraSwitchCutoff = 0;
167 private boolean mSkipUpdateCurrentPhoto = false;
168 private static final long CAMERA_SWITCH_CUTOFF_THRESHOLD_MS = 300;
169
George Mount4b4dbd22012-10-18 14:20:39 -0700170 private static final long DEFERRED_UPDATE_MS = 250;
Bobby Georgescue23a9d42012-10-10 10:49:51 -0700171 private boolean mDeferredUpdateWaiting = false;
172 private long mDeferUpdateUntil = Long.MAX_VALUE;
173
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800174 // The item that is deleted (but it can still be undeleted before commiting)
175 private Path mDeletePath;
176 private boolean mDeleteIsFocus; // whether the deleted item was in focus
177
John Reckddf02252012-09-26 11:37:23 -0700178 private Uri[] mNfcPushUris = new Uri[1];
Martijn Coenen33ef0372012-03-26 18:25:50 -0700179
Owen Lin2bb717f2012-07-13 17:23:05 +0800180 private final MyMenuVisibilityListener mMenuVisibilityListener =
181 new MyMenuVisibilityListener();
George Mountf122d562012-10-09 17:50:33 -0700182 private UpdateProgressListener mProgressListener;
Owen Lin2bb717f2012-07-13 17:23:05 +0800183
George Mount4b4dbd22012-10-18 14:20:39 -0700184 private final PanoramaSupportCallback mUpdatePanoramaMenuItemsCallback = new PanoramaSupportCallback() {
185 @Override
186 public void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama,
187 boolean isPanorama360) {
188 if (mediaObject == mCurrentPhoto) {
189 mHandler.obtainMessage(MSG_UPDATE_PANORAMA_UI, isPanorama360 ? 1 : 0, 0,
190 mediaObject).sendToTarget();
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700191 }
George Mount4b4dbd22012-10-18 14:20:39 -0700192 }
193 };
194
195 private final PanoramaSupportCallback mRefreshBottomControlsCallback = new PanoramaSupportCallback() {
196 @Override
197 public void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama,
198 boolean isPanorama360) {
199 if (mediaObject == mCurrentPhoto) {
Doris Liua680a0c2012-10-18 15:01:35 -0700200 mHandler.obtainMessage(MSG_REFRESH_BOTTOM_CONTROLS, isPanorama ? 1 : 0, isPanorama360 ? 1 : 0,
201 mediaObject).sendToTarget();
George Mount4b4dbd22012-10-18 14:20:39 -0700202 }
203 }
204 };
205
206 private final PanoramaSupportCallback mUpdateShareURICallback = new PanoramaSupportCallback() {
207 @Override
208 public void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama,
209 boolean isPanorama360) {
210 if (mediaObject == mCurrentPhoto) {
211 mHandler.obtainMessage(MSG_UPDATE_SHARE_URI, isPanorama360 ? 1 : 0, 0, mediaObject)
212 .sendToTarget();
213 }
214 }
215 };
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700216
Owen Linf9a0a432011-08-17 22:07:43 +0800217 public static interface Model extends PhotoView.Model {
218 public void resume();
219 public void pause();
220 public boolean isEmpty();
Owen Linf9a0a432011-08-17 22:07:43 +0800221 public void setCurrentPhoto(Path path, int indexHint);
222 }
223
224 private class MyMenuVisibilityListener implements OnMenuVisibilityListener {
Pin Ting06c64012012-05-03 08:26:17 +0800225 @Override
Owen Linf9a0a432011-08-17 22:07:43 +0800226 public void onMenuVisibilityChanged(boolean isVisible) {
227 mIsMenuVisible = isVisible;
228 refreshHidingMessage();
229 }
230 }
231
George Mountf122d562012-10-09 17:50:33 -0700232 private class UpdateProgressListener implements StitchingChangeListener {
233
234 @Override
George Mount4e091eb2012-10-09 21:02:42 -0700235 public void onStitchingResult(Uri uri) {
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700236 sendUpdate(uri, MSG_REFRESH_IMAGE);
George Mountf122d562012-10-09 17:50:33 -0700237 }
238
239 @Override
George Mount4e091eb2012-10-09 21:02:42 -0700240 public void onStitchingQueued(Uri uri) {
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700241 sendUpdate(uri, MSG_UPDATE_PROGRESS);
George Mountf122d562012-10-09 17:50:33 -0700242 }
243
244 @Override
George Mount4e091eb2012-10-09 21:02:42 -0700245 public void onStitchingProgress(Uri uri, final int progress) {
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700246 sendUpdate(uri, MSG_UPDATE_PROGRESS);
George Mountf122d562012-10-09 17:50:33 -0700247 }
248
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700249 private void sendUpdate(Uri uri, int message) {
George Mount4b4dbd22012-10-18 14:20:39 -0700250 MediaObject currentPhoto = mCurrentPhoto;
251 boolean isCurrentPhoto = currentPhoto instanceof LocalImage
252 && currentPhoto.getContentUri().equals(uri);
George Mountf122d562012-10-09 17:50:33 -0700253 if (isCurrentPhoto) {
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700254 mHandler.sendEmptyMessage(message);
George Mountf122d562012-10-09 17:50:33 -0700255 }
256 }
257 };
258
Bobby Georgescu915c2c52012-08-23 13:05:53 -0700259 @Override
260 protected int getBackgroundColorId() {
261 return R.color.photo_background;
262 }
263
Bobby Georgescuf4a707f2012-08-20 16:26:26 -0700264 private final GLView mRootPane = new GLView() {
Owen Linf9a0a432011-08-17 22:07:43 +0800265 @Override
Owen Linf9a0a432011-08-17 22:07:43 +0800266 protected void onLayout(
267 boolean changed, int left, int top, int right, int bottom) {
268 mPhotoView.layout(0, 0, right - left, bottom - top);
Owen Linf9a0a432011-08-17 22:07:43 +0800269 if (mShowDetails) {
Ray Chen8cab3e82012-03-20 16:32:57 +0800270 mDetailsHelper.layout(left, mActionBar.getHeight(), right, bottom);
Owen Linf9a0a432011-08-17 22:07:43 +0800271 }
272 }
273 };
274
275 @Override
276 public void onCreate(Bundle data, Bundle restoreState) {
Bobby Georgescu45c56f22012-08-26 23:47:19 -0700277 super.onCreate(data, restoreState);
Ray Chen8cab3e82012-03-20 16:32:57 +0800278 mActionBar = mActivity.getGalleryActionBar();
Owen Linf9a0a432011-08-17 22:07:43 +0800279 mSelectionManager = new SelectionManager(mActivity, false);
280 mMenuExecutor = new MenuExecutor(mActivity, mSelectionManager);
281
282 mPhotoView = new PhotoView(mActivity);
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800283 mPhotoView.setListener(this);
Owen Linf9a0a432011-08-17 22:07:43 +0800284 mRootPane.addComponent(mPhotoView);
Angus Kong83be4e02012-08-24 19:30:08 +0800285 mApplication = (GalleryApp) ((Activity) mActivity).getApplication();
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800286 mOrientationManager = mActivity.getOrientationManager();
Chih-Chung Chang2ef46ed2012-05-08 17:57:33 +0800287 mActivity.getGLRoot().setOrientationSource(mOrientationManager);
Owen Linf9a0a432011-08-17 22:07:43 +0800288
Bobby Georgescud3973782012-09-12 13:48:50 -0700289 mHandler = new SynchronizedHandler(mActivity.getGLRoot()) {
290 @Override
291 public void handleMessage(Message message) {
292 switch (message.what) {
293 case MSG_HIDE_BARS: {
294 hideBars();
295 break;
296 }
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700297 case MSG_REFRESH_BOTTOM_CONTROLS: {
George Mount4b4dbd22012-10-18 14:20:39 -0700298 if (mCurrentPhoto == message.obj && mBottomControls != null) {
Doris Liua680a0c2012-10-18 15:01:35 -0700299 mIsPanorama = message.arg1 == 1;
300 mIsPanorama360 = message.arg2 == 1;
301 mBottomControls.refresh();
George Mount4b4dbd22012-10-18 14:20:39 -0700302 }
Bobby Georgescud3973782012-09-12 13:48:50 -0700303 break;
304 }
Bobby Georgescud3973782012-09-12 13:48:50 -0700305 case MSG_ON_FULL_SCREEN_CHANGED: {
Bobby Georgescudb99a102012-12-04 23:50:02 -0800306 if (mAppBridge != null) {
307 mAppBridge.onFullScreenChanged(message.arg1 == 1);
308 }
Bobby Georgescud3973782012-09-12 13:48:50 -0700309 break;
310 }
311 case MSG_UPDATE_ACTION_BAR: {
312 updateBars();
313 break;
314 }
315 case MSG_WANT_BARS: {
316 wantBars();
317 break;
318 }
319 case MSG_UNFREEZE_GLROOT: {
320 mActivity.getGLRoot().unfreeze();
321 break;
322 }
Bobby Georgescue23a9d42012-10-10 10:49:51 -0700323 case MSG_UPDATE_DEFERRED: {
324 long nextUpdate = mDeferUpdateUntil - SystemClock.uptimeMillis();
325 if (nextUpdate <= 0) {
326 mDeferredUpdateWaiting = false;
327 updateUIForCurrentPhoto();
328 } else {
329 mHandler.sendEmptyMessageDelayed(MSG_UPDATE_DEFERRED, nextUpdate);
330 }
331 break;
332 }
Bobby Georgescub27df462012-09-27 23:55:44 -0700333 case MSG_ON_CAMERA_CENTER: {
334 mSkipUpdateCurrentPhoto = false;
Bobby Georgescubbc99312012-10-07 13:34:57 -0700335 boolean stayedOnCamera = false;
Bobby Georgescub27df462012-09-27 23:55:44 -0700336 if (!mPhotoView.getFilmMode()) {
Bobby Georgescubbc99312012-10-07 13:34:57 -0700337 stayedOnCamera = true;
Bobby Georgescub27df462012-09-27 23:55:44 -0700338 } else if (SystemClock.uptimeMillis() < mCameraSwitchCutoff &&
339 mMediaSet.getMediaItemCount() > 1) {
340 mPhotoView.switchToImage(1);
341 } else {
Bobby Georgescucc6ad822012-10-22 13:49:35 -0700342 if (mAppBridge != null) mPhotoView.setFilmMode(false);
Bobby Georgescubbc99312012-10-07 13:34:57 -0700343 stayedOnCamera = true;
Bobby Georgescub27df462012-09-27 23:55:44 -0700344 }
345
Bobby Georgescubbc99312012-10-07 13:34:57 -0700346 if (stayedOnCamera) {
Bobby Georgescu617551e2013-01-07 11:25:46 -0800347 if (mAppBridge == null && mMediaSet.getTotalMediaItemCount() > 1) {
Bobby Georgescu5bd00332012-10-24 12:09:38 -0700348 launchCamera();
Bobby Georgescucc6ad822012-10-22 13:49:35 -0700349 /* We got here by swiping from photo 1 to the
350 placeholder, so make it be the thing that
351 is in focus when the user presses back from
352 the camera app */
353 mPhotoView.switchToImage(1);
354 } else {
355 updateBars();
356 updateCurrentPhoto(mModel.getMediaItem(0));
357 }
Bobby Georgescub27df462012-09-27 23:55:44 -0700358 }
359 break;
360 }
Bobby Georgescuf4e22eb2012-10-02 18:34:08 -0700361 case MSG_ON_PICTURE_CENTER: {
Bobby Georgescue23a9d42012-10-10 10:49:51 -0700362 if (!mPhotoView.getFilmMode() && mCurrentPhoto != null
Bobby Georgescuf4e22eb2012-10-02 18:34:08 -0700363 && (mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0) {
364 mPhotoView.setFilmMode(true);
365 }
366 break;
367 }
George Mountf122d562012-10-09 17:50:33 -0700368 case MSG_REFRESH_IMAGE: {
Mangesh Ghiware423e45e2012-10-11 23:11:27 -0700369 final MediaItem photo = mCurrentPhoto;
370 mCurrentPhoto = null;
371 updateCurrentPhoto(photo);
372 break;
373 }
374 case MSG_UPDATE_PHOTO_UI: {
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700375 updateUIForCurrentPhoto();
376 break;
377 }
378 case MSG_UPDATE_PROGRESS: {
379 updateProgressBar();
George Mountf122d562012-10-09 17:50:33 -0700380 break;
381 }
George Mount4b4dbd22012-10-18 14:20:39 -0700382 case MSG_UPDATE_SHARE_URI: {
383 if (mCurrentPhoto == message.obj) {
384 boolean isPanorama360 = message.arg1 != 0;
385 Uri contentUri = mCurrentPhoto.getContentUri();
386 Intent panoramaIntent = null;
387 if (isPanorama360) {
388 panoramaIntent = createSharePanoramaIntent(contentUri);
389 }
390 Intent shareIntent = createShareIntent(mCurrentPhoto);
391
392 mActionBar.setShareIntents(panoramaIntent, shareIntent);
393 setNfcBeamPushUri(contentUri);
394 }
395 break;
396 }
397 case MSG_UPDATE_PANORAMA_UI: {
398 if (mCurrentPhoto == message.obj) {
399 boolean isPanorama360 = message.arg1 != 0;
400 updatePanoramaUI(isPanorama360);
401 }
402 break;
403 }
Bobby Georgescud3973782012-09-12 13:48:50 -0700404 default: throw new AssertionError(message.what);
405 }
406 }
407 };
408
Ray Chen84c220f2012-03-06 17:24:28 +0800409 mSetPathString = data.getString(KEY_MEDIA_SET_PATH);
Chih-Chung Changb1e9fd82012-04-30 17:33:21 +0800410 mOriginalSetPathString = mSetPathString;
John Reckddf02252012-09-26 11:37:23 -0700411 setupNfcBeamPush();
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700412 String itemPathString = data.getString(KEY_MEDIA_ITEM_PATH);
413 Path itemPath = itemPathString != null ?
414 Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) :
415 null;
Yuli Huang54fe6202012-05-23 16:06:32 +0800416 mTreatBackAsUp = data.getBoolean(KEY_TREAT_BACK_AS_UP, false);
Bobby Georgescu45f089d2012-10-02 13:30:09 -0700417 mStartInFilmstrip = data.getBoolean(KEY_START_IN_FILMSTRIP, false);
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -0700418 boolean inCameraRoll = data.getBoolean(KEY_IN_CAMERA_ROLL, false);
Bobby Georgescu45f089d2012-10-02 13:30:09 -0700419 mCurrentIndex = data.getInt(KEY_INDEX_HINT, 0);
Ray Chen84c220f2012-03-06 17:24:28 +0800420 if (mSetPathString != null) {
Bobby Georgescuba65c372012-10-06 01:06:43 -0700421 mShowSpinner = true;
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800422 mAppBridge = (AppBridge) data.getParcelable(KEY_APP_BRIDGE);
423 if (mAppBridge != null) {
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700424 mShowBars = false;
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -0700425 mHasCameraScreennailOrPlaceholder = true;
Chih-Chung Chang253c5ae2012-05-16 17:37:10 -0700426 mAppBridge.setServer(this);
Chih-Chung Chang15b351a2012-03-15 16:38:45 +0800427
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800428 // Get the ScreenNail from AppBridge and register it.
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +0800429 int id = SnailSource.newId();
Chih-Chung Changb29a27f2012-03-22 17:42:33 +0800430 Path screenNailSetPath = SnailSource.getSetPath(id);
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800431 Path screenNailItemPath = SnailSource.getItemPath(id);
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +0800432 mScreenNailSet = (SnailAlbum) mActivity.getDataManager()
433 .getMediaObject(screenNailSetPath);
434 mScreenNailItem = (SnailItem) mActivity.getDataManager()
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800435 .getMediaObject(screenNailItemPath);
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +0800436 mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail());
Chih-Chung Changb29a27f2012-03-22 17:42:33 +0800437
Wu-cheng Li23e595f2012-09-21 14:36:21 +0800438 if (data.getBoolean(KEY_SHOW_WHEN_LOCKED, false)) {
Wu-cheng Liefd480e2012-08-30 16:44:32 +0800439 // Set the flag to be on top of the lock screen.
440 mFlags |= FLAG_SHOW_WHEN_LOCKED;
Wu-cheng Lia0ce6822012-08-22 19:15:35 +0800441 }
442
George Mount4e091eb2012-10-09 21:02:42 -0700443 // Don't display "empty album" action item for capture intents.
Wu-cheng Li2c83c5f2012-10-09 14:44:31 +0800444 if (!mSetPathString.equals("/local/all/0")) {
445 // Check if the path is a secure album.
446 if (SecureSource.isSecurePath(mSetPathString)) {
447 mSecureAlbum = (SecureAlbum) mActivity.getDataManager()
448 .getMediaSet(mSetPathString);
449 mShowSpinner = false;
Wu-cheng Li2c83c5f2012-10-09 14:44:31 +0800450 }
Bobby Georgescuc7e3c762012-09-27 16:36:03 -0700451 mSetPathString = "/filter/empty/{"+mSetPathString+"}";
452 }
453
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +0800454 // Combine the original MediaSet with the one for ScreenNail
455 // from AppBridge.
Chih-Chung Changb29a27f2012-03-22 17:42:33 +0800456 mSetPathString = "/combo/item/{" + screenNailSetPath +
457 "," + mSetPathString + "}";
458
459 // Start from the screen nail.
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800460 itemPath = screenNailItemPath;
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -0700461 } else if (inCameraRoll && GalleryUtils.isCameraAvailable(mActivity)) {
Bobby Georgescu45f089d2012-10-02 13:30:09 -0700462 mSetPathString = "/combo/item/{" + FilterSource.FILTER_CAMERA_SHORTCUT +
463 "," + mSetPathString + "}";
464 mCurrentIndex++;
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -0700465 mHasCameraScreennailOrPlaceholder = true;
Chih-Chung Changb29a27f2012-03-22 17:42:33 +0800466 }
467
Chih-Chung Chang6118af92012-06-22 20:56:04 +0800468 MediaSet originalSet = mActivity.getDataManager()
469 .getMediaSet(mSetPathString);
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -0700470 if (mHasCameraScreennailOrPlaceholder && originalSet instanceof ComboAlbum) {
Bobby Georgescuee899c02012-10-01 17:49:30 -0700471 // Use the name of the camera album rather than the default
472 // ComboAlbum behavior
473 ((ComboAlbum) originalSet).useNameOfChild(1);
474 }
Chih-Chung Chang6118af92012-06-22 20:56:04 +0800475 mSelectionManager.setSourceMediaSet(originalSet);
Chih-Chung Chang6b891c62012-06-07 20:09:13 +0800476 mSetPathString = "/filter/delete/{" + mSetPathString + "}";
477 mMediaSet = (FilterDeleteSet) mActivity.getDataManager()
478 .getMediaSet(mSetPathString);
Owen Linf9a0a432011-08-17 22:07:43 +0800479 if (mMediaSet == null) {
Ray Chen84c220f2012-03-06 17:24:28 +0800480 Log.w(TAG, "failed to restore " + mSetPathString);
Owen Linf9a0a432011-08-17 22:07:43 +0800481 }
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700482 if (itemPath == null) {
Bobby Georgescu3eb2e642012-09-24 11:26:10 -0700483 int mediaItemCount = mMediaSet.getMediaItemCount();
484 if (mediaItemCount > 0) {
485 if (mCurrentIndex >= mediaItemCount) mCurrentIndex = 0;
Bobby Georgescud3973782012-09-12 13:48:50 -0700486 itemPath = mMediaSet.getMediaItem(mCurrentIndex, 1)
487 .get(0).getPath();
488 } else {
Bobby Georgescu3eb2e642012-09-24 11:26:10 -0700489 // Bail out, PhotoPage can't load on an empty album
Bobby Georgescud3973782012-09-12 13:48:50 -0700490 return;
491 }
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700492 }
Owen Linf9a0a432011-08-17 22:07:43 +0800493 PhotoDataAdapter pda = new PhotoDataAdapter(
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800494 mActivity, mPhotoView, mMediaSet, itemPath, mCurrentIndex,
Angus Kong43a80fd2012-05-17 12:47:26 -0700495 mAppBridge == null ? -1 : 0,
Wu-cheng Lidbb6acc2012-08-19 17:04:02 +0800496 mAppBridge == null ? false : mAppBridge.isPanorama(),
497 mAppBridge == null ? false : mAppBridge.isStaticCamera());
Owen Linf9a0a432011-08-17 22:07:43 +0800498 mModel = pda;
499 mPhotoView.setModel(mModel);
500
Owen Linf9a0a432011-08-17 22:07:43 +0800501 pda.setDataListener(new PhotoDataAdapter.DataListener() {
502
Owen Lin113bfc72011-08-30 10:38:59 +0800503 @Override
Owen Linf9a0a432011-08-17 22:07:43 +0800504 public void onPhotoChanged(int index, Path item) {
Bobby Georgescu00ccf352012-09-19 16:51:05 -0700505 int oldIndex = mCurrentIndex;
Owen Linf9a0a432011-08-17 22:07:43 +0800506 mCurrentIndex = index;
Bobby Georgescub27df462012-09-27 23:55:44 -0700507
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -0700508 if (mHasCameraScreennailOrPlaceholder) {
Bobby Georgescub27df462012-09-27 23:55:44 -0700509 if (mCurrentIndex > 0) {
Bobby Georgescub27df462012-09-27 23:55:44 -0700510 mSkipUpdateCurrentPhoto = false;
511 }
512
Bobby Georgescu00ccf352012-09-19 16:51:05 -0700513 if (oldIndex == 0 && mCurrentIndex > 0
514 && !mPhotoView.getFilmMode()) {
515 mPhotoView.setFilmMode(true);
Bobby Georgescub27df462012-09-27 23:55:44 -0700516 } else if (oldIndex == 2 && mCurrentIndex == 1) {
517 mCameraSwitchCutoff = SystemClock.uptimeMillis() +
518 CAMERA_SWITCH_CUTOFF_THRESHOLD_MS;
519 mPhotoView.stopScrolling();
Bobby Georgescubbc99312012-10-07 13:34:57 -0700520 } else if (oldIndex >= 1 && mCurrentIndex == 0) {
Bobby Georgescuf4e22eb2012-10-02 18:34:08 -0700521 mPhotoView.setWantPictureCenterCallbacks(true);
Bobby Georgescub27df462012-09-27 23:55:44 -0700522 mSkipUpdateCurrentPhoto = true;
Bobby Georgescu00ccf352012-09-19 16:51:05 -0700523 }
524 }
Bobby Georgescub27df462012-09-27 23:55:44 -0700525 if (!mSkipUpdateCurrentPhoto) {
526 if (item != null) {
527 MediaItem photo = mModel.getMediaItem(0);
528 if (photo != null) updateCurrentPhoto(photo);
529 }
530 updateBars();
531 }
Bobby Georgescu00ccf352012-09-19 16:51:05 -0700532 // Reset the timeout for the bars after a swipe
533 refreshHidingMessage();
Owen Linf9a0a432011-08-17 22:07:43 +0800534 }
535
536 @Override
Hung-ying Tyan05da3f52012-10-30 17:47:35 +0800537 public void onLoadingFinished(boolean loadingFailed) {
Owen Linf9a0a432011-08-17 22:07:43 +0800538 if (!mModel.isEmpty()) {
Owen Lin616a70f2012-05-07 16:35:53 +0800539 MediaItem photo = mModel.getMediaItem(0);
Owen Linf9a0a432011-08-17 22:07:43 +0800540 if (photo != null) updateCurrentPhoto(photo);
541 } else if (mIsActive) {
Chih-Chung Changc3704762012-06-27 13:40:06 +0800542 // We only want to finish the PhotoPage if there is no
543 // deletion that the user can undo.
544 if (mMediaSet.getNumberOfDeletions() == 0) {
545 mActivity.getStateManager().finishState(
546 PhotoPage.this);
547 }
Owen Linf9a0a432011-08-17 22:07:43 +0800548 }
549 }
550
Owen Linf9a0a432011-08-17 22:07:43 +0800551 @Override
552 public void onLoadingStarted() {
Owen Linf9a0a432011-08-17 22:07:43 +0800553 }
554 });
555 } else {
556 // Get default media set by the URI
557 MediaItem mediaItem = (MediaItem)
558 mActivity.getDataManager().getMediaObject(itemPath);
559 mModel = new SinglePhotoDataAdapter(mActivity, mPhotoView, mediaItem);
560 mPhotoView.setModel(mModel);
561 updateCurrentPhoto(mediaItem);
Bobby Georgescuba65c372012-10-06 01:06:43 -0700562 mShowSpinner = false;
Owen Linf9a0a432011-08-17 22:07:43 +0800563 }
Ray Chencf46a3a2011-09-14 16:46:32 +0800564
Bobby Georgescub265ebb2012-09-12 16:37:53 -0700565 mPhotoView.setFilmMode(mStartInFilmstrip && mMediaSet.getMediaItemCount() > 1);
George Mountf122d562012-10-09 17:50:33 -0700566 RelativeLayout galleryRoot = (RelativeLayout) ((Activity) mActivity)
567 .findViewById(mAppBridge != null ? R.id.content : R.id.gallery_root);
568 if (galleryRoot != null) {
569 if (mSecureAlbum == null) {
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700570 mBottomControls = new PhotoPageBottomControls(this, mActivity, galleryRoot);
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700571 }
George Mountf122d562012-10-09 17:50:33 -0700572 StitchingProgressManager progressManager = mApplication.getStitchingProgressManager();
573 if (progressManager != null) {
574 mProgressBar = new PhotoPageProgressBar(mActivity, galleryRoot);
575 mProgressListener = new UpdateProgressListener();
576 progressManager.addChangeListener(mProgressListener);
Wu-cheng Li294b9942012-10-13 15:07:27 +0800577 if (mSecureAlbum != null) {
578 progressManager.addChangeListener(mSecureAlbum);
579 }
George Mountf122d562012-10-09 17:50:33 -0700580 }
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700581 }
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700582 }
583
Sascha Haeberlinge3b50f12012-10-15 18:28:42 -0700584 @Override
Bobby Georgescuf4e22eb2012-10-02 18:34:08 -0700585 public void onPictureCenter(boolean isCamera) {
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -0700586 isCamera = isCamera || (mHasCameraScreennailOrPlaceholder && mAppBridge == null);
Bobby Georgescuf4e22eb2012-10-02 18:34:08 -0700587 mPhotoView.setWantPictureCenterCallbacks(false);
588 mHandler.removeMessages(MSG_ON_CAMERA_CENTER);
589 mHandler.removeMessages(MSG_ON_PICTURE_CENTER);
590 mHandler.sendEmptyMessage(isCamera ? MSG_ON_CAMERA_CENTER : MSG_ON_PICTURE_CENTER);
Bobby Georgescub27df462012-09-27 23:55:44 -0700591 }
592
Sascha Haeberlinge3b50f12012-10-15 18:28:42 -0700593 @Override
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700594 public boolean canDisplayBottomControls() {
Bobby Georgescu94958432012-10-23 20:52:26 -0700595 return mIsActive && !mPhotoView.canUndo();
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700596 }
597
Sascha Haeberlinge3b50f12012-10-15 18:28:42 -0700598 @Override
Doris Liua680a0c2012-10-18 15:01:35 -0700599 public boolean canDisplayBottomControl(int control) {
George Mount4b4dbd22012-10-18 14:20:39 -0700600 if (mCurrentPhoto == null) {
601 return false;
602 }
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700603 switch(control) {
604 case R.id.photopage_bottom_control_edit:
Bobby Georgescud2724f62012-10-06 15:22:03 -0700605 return mHaveImageEditor && mShowBars
Bobby Georgescuc02be7d2012-10-23 11:20:48 -0700606 && !mPhotoView.getFilmMode()
George Mount4b4dbd22012-10-18 14:20:39 -0700607 && (mCurrentPhoto.getSupportedOperations() & MediaItem.SUPPORT_EDIT) != 0
608 && mCurrentPhoto.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE;
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700609 case R.id.photopage_bottom_control_panorama:
Doris Liua680a0c2012-10-18 15:01:35 -0700610 return mIsPanorama;
611 case R.id.photopage_bottom_control_tiny_planet:
612 return mHaveImageEditor && mShowBars
Bobby Georgescuc02be7d2012-10-23 11:20:48 -0700613 && mIsPanorama360 && !mPhotoView.getFilmMode();
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700614 default:
615 return false;
616 }
617 }
618
Sascha Haeberlinge3b50f12012-10-15 18:28:42 -0700619 @Override
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700620 public void onBottomControlClicked(int control) {
621 switch(control) {
622 case R.id.photopage_bottom_control_edit:
623 launchPhotoEditor();
624 return;
625 case R.id.photopage_bottom_control_panorama:
Sascha Haeberlinge3b50f12012-10-15 18:28:42 -0700626 mActivity.getPanoramaViewHelper()
627 .showPanorama(mCurrentPhoto.getContentUri());
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700628 return;
Doris Liua680a0c2012-10-18 15:01:35 -0700629 case R.id.photopage_bottom_control_tiny_planet:
630 launchTinyPlanet();
631 return;
Bobby Georgescuf44499d2012-09-17 18:12:11 -0700632 default:
633 return;
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700634 }
Owen Linf9a0a432011-08-17 22:07:43 +0800635 }
636
Chih-Chung Chang67721732012-07-03 12:49:45 +0800637 @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
John Reckddf02252012-09-26 11:37:23 -0700638 private void setupNfcBeamPush() {
639 if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) return;
640
641 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mActivity);
642 if (adapter != null) {
John Reck2619f202012-10-02 13:38:22 -0700643 adapter.setBeamPushUris(null, mActivity);
John Reckddf02252012-09-26 11:37:23 -0700644 adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
645 @Override
646 public Uri[] createBeamUris(NfcEvent event) {
647 return mNfcPushUris;
648 }
649 }, mActivity);
Yuli Huangfc869942012-06-29 18:59:17 +0800650 }
651 }
652
John Reckddf02252012-09-26 11:37:23 -0700653 private void setNfcBeamPushUri(Uri uri) {
654 mNfcPushUris[0] = uri;
655 }
656
George Mount4b4dbd22012-10-18 14:20:39 -0700657 private static Intent createShareIntent(MediaObject mediaObject) {
658 int type = mediaObject.getMediaType();
Owen Linca181a62012-10-16 10:22:54 +0800659 return new Intent(Intent.ACTION_SEND)
660 .setType(MenuExecutor.getMimeType(type))
George Mount4b4dbd22012-10-18 14:20:39 -0700661 .putExtra(Intent.EXTRA_STREAM, mediaObject.getContentUri())
Owen Linca181a62012-10-16 10:22:54 +0800662 .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Mangesh Ghiware5172dee2012-09-27 21:05:41 -0700663 }
Owen Lin2bb717f2012-07-13 17:23:05 +0800664
George Mount4b4dbd22012-10-18 14:20:39 -0700665 private static Intent createSharePanoramaIntent(Uri contentUri) {
Owen Linca181a62012-10-16 10:22:54 +0800666 return new Intent(Intent.ACTION_SEND)
667 .setType(GalleryUtils.MIME_TYPE_PANORAMA360)
George Mount4b4dbd22012-10-18 14:20:39 -0700668 .putExtra(Intent.EXTRA_STREAM, contentUri)
Owen Linca181a62012-10-16 10:22:54 +0800669 .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Wu-cheng Lifb557192012-07-19 17:11:06 +0800670 }
671
Bobby Georgescu48129f32012-10-22 11:13:34 -0700672 private void overrideTransitionToEditor() {
673 ((Activity) mActivity).overridePendingTransition(android.R.anim.slide_in_left,
674 android.R.anim.fade_out);
675 }
676
Doris Liua680a0c2012-10-18 15:01:35 -0700677 private void launchTinyPlanet() {
678 // Deep link into tiny planet
679 MediaItem current = mModel.getMediaItem(0);
680 Intent intent = new Intent(FilterShowActivity.TINY_PLANET_ACTION);
681 intent.setClass(mActivity, FilterShowActivity.class);
682 intent.setDataAndType(current.getContentUri(), current.getMimeType())
683 .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Bobby Georgescua850a542012-10-23 15:40:06 -0700684 intent.putExtra(FilterShowActivity.LAUNCH_FULLSCREEN,
685 mActivity.isFullscreen());
Doris Liua680a0c2012-10-18 15:01:35 -0700686 mActivity.startActivityForResult(intent, REQUEST_EDIT);
Bobby Georgescu48129f32012-10-22 11:13:34 -0700687 overrideTransitionToEditor();
Doris Liua680a0c2012-10-18 15:01:35 -0700688 }
689
Bobby Georgescu5bd00332012-10-24 12:09:38 -0700690 private void launchCamera() {
Bobby Georgescu9ec5de92012-11-05 21:21:55 -0800691 Intent intent = new Intent(mActivity, CameraActivity.class)
692 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bobby Georgescu5bd00332012-10-24 12:09:38 -0700693 mRecenterCameraOnResume = false;
694 mActivity.startActivity(intent);
695 }
696
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700697 private void launchPhotoEditor() {
698 MediaItem current = mModel.getMediaItem(0);
Bobby Georgescu462923e2012-10-02 10:30:07 -0700699 if (current == null || (current.getSupportedOperations()
700 & MediaObject.SUPPORT_EDIT) == 0) {
701 return;
702 }
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700703
704 Intent intent = new Intent(ACTION_NEXTGEN_EDIT);
Owen Linb6692652012-10-04 11:26:30 +0800705
706 intent.setDataAndType(current.getContentUri(), current.getMimeType())
707 .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700708 if (mActivity.getPackageManager()
709 .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() == 0) {
710 intent.setAction(Intent.ACTION_EDIT);
711 }
Bobby Georgescua850a542012-10-23 15:40:06 -0700712 intent.putExtra(FilterShowActivity.LAUNCH_FULLSCREEN,
713 mActivity.isFullscreen());
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700714 ((Activity) mActivity).startActivityForResult(Intent.createChooser(intent, null),
715 REQUEST_EDIT);
Bobby Georgescu48129f32012-10-22 11:13:34 -0700716 overrideTransitionToEditor();
Bobby Georgescua9948ef2012-09-11 17:02:03 -0700717 }
718
Bobby Georgescue23a9d42012-10-10 10:49:51 -0700719 private void requestDeferredUpdate() {
720 mDeferUpdateUntil = SystemClock.uptimeMillis() + DEFERRED_UPDATE_MS;
721 if (!mDeferredUpdateWaiting) {
722 mDeferredUpdateWaiting = true;
723 mHandler.sendEmptyMessageDelayed(MSG_UPDATE_DEFERRED, DEFERRED_UPDATE_MS);
724 }
725 }
726
727 private void updateUIForCurrentPhoto() {
Owen Linf9a0a432011-08-17 22:07:43 +0800728 if (mCurrentPhoto == null) return;
Bobby Georgescuc7e3c762012-09-27 16:36:03 -0700729
730 // If by swiping or deletion the user ends up on an action item
731 // and zoomed in, zoom out so that the context of the action is
732 // more clear
Bobby Georgescue23a9d42012-10-10 10:49:51 -0700733 if ((mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0
Bobby Georgescuc7e3c762012-09-27 16:36:03 -0700734 && !mPhotoView.getFilmMode()) {
Bobby Georgescuf4e22eb2012-10-02 18:34:08 -0700735 mPhotoView.setWantPictureCenterCallbacks(true);
Bobby Georgescuc7e3c762012-09-27 16:36:03 -0700736 }
737
Owen Linf9a0a432011-08-17 22:07:43 +0800738 updateMenuOperations();
George Mount4b4dbd22012-10-18 14:20:39 -0700739 refreshBottomControlsWhenReady();
Owen Linf9a0a432011-08-17 22:07:43 +0800740 if (mShowDetails) {
Michael Kolb995c4562012-07-20 12:23:09 -0700741 mDetailsHelper.reloadDetails();
Owen Linf9a0a432011-08-17 22:07:43 +0800742 }
Wu-cheng Li898a2f42012-08-27 00:10:38 +0800743 if ((mSecureAlbum == null)
Bobby Georgescue23a9d42012-10-10 10:49:51 -0700744 && (mCurrentPhoto.getSupportedOperations() & MediaItem.SUPPORT_SHARE) != 0) {
George Mount4b4dbd22012-10-18 14:20:39 -0700745 mCurrentPhoto.getPanoramaSupport(mUpdateShareURICallback);
Bobby Georgescue23a9d42012-10-10 10:49:51 -0700746 }
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700747 updateProgressBar();
Bobby Georgescue23a9d42012-10-10 10:49:51 -0700748 }
749
750 private void updateCurrentPhoto(MediaItem photo) {
751 if (mCurrentPhoto == photo) return;
752 mCurrentPhoto = photo;
753 if (mPhotoView.getFilmMode()) {
754 requestDeferredUpdate();
755 } else {
756 updateUIForCurrentPhoto();
Chih-Chung Chang15b351a2012-03-15 16:38:45 +0800757 }
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700758 }
759
760 private void updateProgressBar() {
George Mount785a1f82012-10-10 16:59:45 -0700761 if (mProgressBar != null) {
762 mProgressBar.hideProgress();
763 StitchingProgressManager progressManager = mApplication.getStitchingProgressManager();
764 if (progressManager != null && mCurrentPhoto instanceof LocalImage) {
Mangesh Ghiware825afb12012-10-10 18:37:24 -0700765 Integer progress = progressManager.getProgress(mCurrentPhoto.getContentUri());
George Mount785a1f82012-10-10 16:59:45 -0700766 if (progress != null) {
767 mProgressBar.setProgress(progress);
768 }
George Mountf122d562012-10-09 17:50:33 -0700769 }
770 }
Owen Linf9a0a432011-08-17 22:07:43 +0800771 }
772
773 private void updateMenuOperations() {
Owen Lin24081fe2012-08-28 18:04:00 +0800774 Menu menu = mActionBar.getMenu();
775
776 // it could be null if onCreateActionBar has not been called yet
777 if (menu == null) return;
778
779 MenuItem item = menu.findItem(R.id.action_slideshow);
John Reck53fe9f72012-09-27 15:26:00 -0700780 if (item != null) {
781 item.setVisible((mSecureAlbum == null) && canDoSlideShow());
782 }
Chih-Chung Chang20662002011-11-18 18:04:10 +0800783 if (mCurrentPhoto == null) return;
Owen Lin24081fe2012-08-28 18:04:00 +0800784
Owen Linf9a0a432011-08-17 22:07:43 +0800785 int supportedOperations = mCurrentPhoto.getSupportedOperations();
Wu-cheng Li898a2f42012-08-27 00:10:38 +0800786 if (mSecureAlbum != null) {
Owen Lin24081fe2012-08-28 18:04:00 +0800787 supportedOperations &= MediaObject.SUPPORT_DELETE;
John Reck8fe22ec2012-09-26 16:13:02 -0700788 } else if (!mHaveImageEditor) {
Owen Linf9a0a432011-08-17 22:07:43 +0800789 supportedOperations &= ~MediaObject.SUPPORT_EDIT;
790 }
Owen Lin24081fe2012-08-28 18:04:00 +0800791 MenuExecutor.updateMenuOperation(menu, supportedOperations);
George Mount4b4dbd22012-10-18 14:20:39 -0700792 mCurrentPhoto.getPanoramaSupport(mUpdatePanoramaMenuItemsCallback);
Owen Linf9a0a432011-08-17 22:07:43 +0800793 }
794
Chih-Chung Chang20662002011-11-18 18:04:10 +0800795 private boolean canDoSlideShow() {
796 if (mMediaSet == null || mCurrentPhoto == null) {
797 return false;
798 }
799 if (mCurrentPhoto.getMediaType() != MediaObject.MEDIA_TYPE_IMAGE) {
800 return false;
801 }
Chih-Chung Chang20662002011-11-18 18:04:10 +0800802 return true;
803 }
804
Chih-Chung Chang61f94712012-05-02 20:05:16 +0800805 //////////////////////////////////////////////////////////////////////////
806 // Action Bar show/hide management
807 //////////////////////////////////////////////////////////////////////////
808
Owen Linf9a0a432011-08-17 22:07:43 +0800809 private void showBars() {
810 if (mShowBars) return;
811 mShowBars = true;
Chih-Chung Change6251df2012-05-22 11:35:46 -0700812 mOrientationManager.unlockOrientation();
Owen Linf9a0a432011-08-17 22:07:43 +0800813 mActionBar.show();
Chih-Chung Chang0b2486c2012-05-17 16:45:12 -0700814 mActivity.getGLRoot().setLightsOutMode(false);
Chih-Chung Chang61f94712012-05-02 20:05:16 +0800815 refreshHidingMessage();
George Mount4b4dbd22012-10-18 14:20:39 -0700816 refreshBottomControlsWhenReady();
Owen Linf9a0a432011-08-17 22:07:43 +0800817 }
818
819 private void hideBars() {
820 if (!mShowBars) return;
821 mShowBars = false;
822 mActionBar.hide();
Chih-Chung Chang0b2486c2012-05-17 16:45:12 -0700823 mActivity.getGLRoot().setLightsOutMode(true);
Chih-Chung Chang61f94712012-05-02 20:05:16 +0800824 mHandler.removeMessages(MSG_HIDE_BARS);
George Mount4b4dbd22012-10-18 14:20:39 -0700825 refreshBottomControlsWhenReady();
Owen Linf9a0a432011-08-17 22:07:43 +0800826 }
827
828 private void refreshHidingMessage() {
829 mHandler.removeMessages(MSG_HIDE_BARS);
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700830 if (!mIsMenuVisible && !mPhotoView.getFilmMode()) {
Owen Linf9a0a432011-08-17 22:07:43 +0800831 mHandler.sendEmptyMessageDelayed(MSG_HIDE_BARS, HIDE_BARS_TIMEOUT);
832 }
833 }
834
Chih-Chung Changaeb30622012-05-03 11:41:05 +0800835 private boolean canShowBars() {
836 // No bars if we are showing camera preview.
Bobby Georgescu56bdcb72012-09-19 15:14:53 -0700837 if (mAppBridge != null && mCurrentIndex == 0
838 && !mPhotoView.getFilmMode()) return false;
839
Chih-Chung Changaeb30622012-05-03 11:41:05 +0800840 // No bars if it's not allowed.
841 if (!mActionBarAllowed) return false;
Chih-Chung Changaeb30622012-05-03 11:41:05 +0800842
John Reck4ea5c272013-01-18 16:00:45 -0800843 Configuration config = mActivity.getResources().getConfiguration();
844 if (config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH) {
845 return false;
846 }
847
Chih-Chung Changaeb30622012-05-03 11:41:05 +0800848 return true;
849 }
850
Chih-Chung Change6251df2012-05-22 11:35:46 -0700851 private void wantBars() {
852 if (canShowBars()) showBars();
853 }
854
Chih-Chung Chang61f94712012-05-02 20:05:16 +0800855 private void toggleBars() {
Owen Linf9a0a432011-08-17 22:07:43 +0800856 if (mShowBars) {
857 hideBars();
Chih-Chung Changaeb30622012-05-03 11:41:05 +0800858 } else {
Chih-Chung Change6251df2012-05-22 11:35:46 -0700859 if (canShowBars()) showBars();
Owen Linf9a0a432011-08-17 22:07:43 +0800860 }
861 }
862
Chih-Chung Chang61f94712012-05-02 20:05:16 +0800863 private void updateBars() {
Chih-Chung Change6251df2012-05-22 11:35:46 -0700864 if (!canShowBars()) {
Chih-Chung Chang61f94712012-05-02 20:05:16 +0800865 hideBars();
866 }
Owen Linf9a0a432011-08-17 22:07:43 +0800867 }
868
Owen Linf9a0a432011-08-17 22:07:43 +0800869 @Override
870 protected void onBackPressed() {
871 if (mShowDetails) {
872 hideDetails();
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +0800873 } else if (mAppBridge == null || !switchWithCaptureAnimation(-1)) {
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800874 // We are leaving this page. Set the result now.
875 setResult();
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700876 if (mStartInFilmstrip && !mPhotoView.getFilmMode()) {
877 mPhotoView.setFilmMode(true);
878 } else if (mTreatBackAsUp) {
Yuli Huang54fe6202012-05-23 16:06:32 +0800879 onUpPressed();
880 } else {
881 super.onBackPressed();
882 }
Owen Linf9a0a432011-08-17 22:07:43 +0800883 }
884 }
885
Chih-Chung Changb1e9fd82012-04-30 17:33:21 +0800886 private void onUpPressed() {
Bobby Georgescu833f7752012-09-26 14:22:57 -0700887 if ((mStartInFilmstrip || mAppBridge != null)
888 && !mPhotoView.getFilmMode()) {
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700889 mPhotoView.setFilmMode(true);
890 return;
891 }
892
Chih-Chung Changb1e9fd82012-04-30 17:33:21 +0800893 if (mActivity.getStateManager().getStateCount() > 1) {
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700894 setResult();
Chih-Chung Changb1e9fd82012-04-30 17:33:21 +0800895 super.onBackPressed();
Chih-Chung Changba12eae2012-05-07 02:29:37 +0800896 return;
Chih-Chung Chang66ca8482012-05-04 21:54:01 +0800897 }
898
899 if (mOriginalSetPathString == null) return;
900
901 if (mAppBridge == null) {
Chih-Chung Changb1e9fd82012-04-30 17:33:21 +0800902 // We're in view mode so set up the stacks on our own.
903 Bundle data = new Bundle(getData());
904 data.putString(AlbumPage.KEY_MEDIA_PATH, mOriginalSetPathString);
905 data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH,
906 mActivity.getDataManager().getTopSetPath(
907 DataManager.INCLUDE_ALL));
908 mActivity.getStateManager().switchState(this, AlbumPage.class, data);
Chih-Chung Chang66ca8482012-05-04 21:54:01 +0800909 } else {
Bobby Georgescu833f7752012-09-26 14:22:57 -0700910 GalleryUtils.startGalleryActivity(mActivity);
Chih-Chung Changb1e9fd82012-04-30 17:33:21 +0800911 }
912 }
913
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800914 private void setResult() {
915 Intent result = null;
Bobby Georgescu7eea4d32012-09-06 17:14:02 -0700916 result = new Intent();
917 result.putExtra(KEY_RETURN_INDEX_HINT, mCurrentIndex);
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800918 setStateResult(Activity.RESULT_OK, result);
919 }
920
921 //////////////////////////////////////////////////////////////////////////
922 // AppBridge.Server interface
923 //////////////////////////////////////////////////////////////////////////
924
925 @Override
Chih-Chung Chang2ef46ed2012-05-08 17:57:33 +0800926 public void setCameraRelativeFrame(Rect frame) {
927 mPhotoView.setCameraRelativeFrame(frame);
Chih-Chung Changbd141b52012-04-26 10:10:49 +0800928 }
929
930 @Override
Chih-Chung Chang2c617382012-04-20 20:06:19 +0800931 public boolean switchWithCaptureAnimation(int offset) {
932 return mPhotoView.switchWithCaptureAnimation(offset);
933 }
934
Owen Linf9a0a432011-08-17 22:07:43 +0800935 @Override
Chih-Chung Chang65757942012-05-06 03:25:16 +0800936 public void setSwipingEnabled(boolean enabled) {
937 mPhotoView.setSwipingEnabled(enabled);
938 }
939
940 @Override
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +0800941 public void notifyScreenNailChanged() {
942 mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail());
943 mScreenNailSet.notifyChange();
944 }
945
946 @Override
Wu-cheng Lia0ce6822012-08-22 19:15:35 +0800947 public void addSecureAlbumItem(boolean isVideo, int id) {
948 mSecureAlbum.addMediaItem(isVideo, id);
949 }
950
951 @Override
Owen Linf9a0a432011-08-17 22:07:43 +0800952 protected boolean onCreateActionBar(Menu menu) {
Owen Linb21b8e52012-08-24 12:25:57 +0800953 mActionBar.createActionBarMenu(R.menu.photo, menu);
John Reck8fe22ec2012-09-26 16:13:02 -0700954 mHaveImageEditor = GalleryUtils.isEditorAvailable(mActivity, "image/*");
Owen Linf9a0a432011-08-17 22:07:43 +0800955 updateMenuOperations();
Bobby Georgescu3cf502a2012-10-01 15:50:11 -0700956 mActionBar.setTitle(mMediaSet != null ? mMediaSet.getName() : "");
Owen Linb21b8e52012-08-24 12:25:57 +0800957 return true;
Owen Linf9a0a432011-08-17 22:07:43 +0800958 }
959
Owen Lind759b7c2012-05-16 15:32:02 -0700960 private MenuExecutor.ProgressListener mConfirmDialogListener =
961 new MenuExecutor.ProgressListener() {
962 @Override
963 public void onProgressUpdate(int index) {}
964
965 @Override
966 public void onProgressComplete(int result) {}
967
968 @Override
969 public void onConfirmDialogShown() {
970 mHandler.removeMessages(MSG_HIDE_BARS);
971 }
972
973 @Override
974 public void onConfirmDialogDismissed(boolean confirmed) {
975 refreshHidingMessage();
976 }
Bobby Georgescuba50b942012-08-08 00:09:50 -0700977
978 @Override
979 public void onProgressStart() {}
Owen Lind759b7c2012-05-16 15:32:02 -0700980 };
981
Bobby Georgescu3cf502a2012-10-01 15:50:11 -0700982 private void switchToGrid() {
Bobby Georgescu55858262012-10-15 13:48:08 -0700983 if (mActivity.getStateManager().hasStateClass(AlbumPage.class)) {
Bobby Georgescu3cf502a2012-10-01 15:50:11 -0700984 onUpPressed();
985 } else {
986 if (mOriginalSetPathString == null) return;
George Mount4dd4d802012-10-19 14:57:51 -0700987 if (mProgressBar != null) {
988 updateCurrentPhoto(null);
989 mProgressBar.hideProgress();
990 }
Bobby Georgescu3cf502a2012-10-01 15:50:11 -0700991 Bundle data = new Bundle(getData());
992 data.putString(AlbumPage.KEY_MEDIA_PATH, mOriginalSetPathString);
993 data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH,
994 mActivity.getDataManager().getTopSetPath(
995 DataManager.INCLUDE_ALL));
996
997 // We only show cluster menu in the first AlbumPage in stack
998 // TODO: Enable this when running from the camera app
999 boolean inAlbum = mActivity.getStateManager().hasStateClass(AlbumPage.class);
1000 data.putBoolean(AlbumPage.KEY_SHOW_CLUSTER_MENU, !inAlbum
1001 && mAppBridge == null);
1002
1003 data.putBoolean(PhotoPage.KEY_APP_BRIDGE, mAppBridge != null);
1004
1005 // Account for live preview being first item
1006 mActivity.getTransitionStore().put(KEY_RETURN_INDEX_HINT,
1007 mAppBridge != null ? mCurrentIndex - 1 : mCurrentIndex);
1008
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -07001009 if (mHasCameraScreennailOrPlaceholder && mAppBridge != null) {
Bobby Georgescu55858262012-10-15 13:48:08 -07001010 mActivity.getStateManager().startState(AlbumPage.class, data);
1011 } else {
1012 mActivity.getStateManager().switchState(this, AlbumPage.class, data);
1013 }
Bobby Georgescu3cf502a2012-10-01 15:50:11 -07001014 }
1015 }
1016
Owen Linf9a0a432011-08-17 22:07:43 +08001017 @Override
1018 protected boolean onItemSelected(MenuItem item) {
Bobby Georgescud3973782012-09-12 13:48:50 -07001019 if (mModel == null) return true;
Owen Lind759b7c2012-05-16 15:32:02 -07001020 refreshHidingMessage();
Owen Lin616a70f2012-05-07 16:35:53 +08001021 MediaItem current = mModel.getMediaItem(0);
Owen Linf9a0a432011-08-17 22:07:43 +08001022
Doris Liu599bdd62012-11-12 15:17:36 -08001023 // This is a shield for monkey when it clicks the action bar
1024 // menu when transitioning from filmstrip to camera
1025 if (current instanceof SnailItem) return true;
1026 // TODO: We should check the current photo against the MediaItem
1027 // that the menu was initially created for. We need to fix this
1028 // after PhotoPage being refactored.
Owen Linf9a0a432011-08-17 22:07:43 +08001029 if (current == null) {
1030 // item is not ready, ignore
1031 return true;
1032 }
Owen Linf9a0a432011-08-17 22:07:43 +08001033 int currentIndex = mModel.getCurrentIndex();
1034 Path path = current.getPath();
1035
1036 DataManager manager = mActivity.getDataManager();
1037 int action = item.getItemId();
Ray Chen9a033b02012-05-15 11:22:21 +08001038 String confirmMsg = null;
Owen Linf9a0a432011-08-17 22:07:43 +08001039 switch (action) {
Ray Chen84c220f2012-03-06 17:24:28 +08001040 case android.R.id.home: {
Chih-Chung Changb1e9fd82012-04-30 17:33:21 +08001041 onUpPressed();
Ray Chen84c220f2012-03-06 17:24:28 +08001042 return true;
1043 }
Owen Linf9a0a432011-08-17 22:07:43 +08001044 case R.id.action_slideshow: {
1045 Bundle data = new Bundle();
Owen Lin6cf80742011-08-28 10:50:21 +08001046 data.putString(SlideshowPage.KEY_SET_PATH, mMediaSet.getPath().toString());
Ray Chen604f0532011-10-21 16:07:12 +08001047 data.putString(SlideshowPage.KEY_ITEM_PATH, path.toString());
Owen Linf9a0a432011-08-17 22:07:43 +08001048 data.putInt(SlideshowPage.KEY_PHOTO_INDEX, currentIndex);
1049 data.putBoolean(SlideshowPage.KEY_REPEAT, true);
1050 mActivity.getStateManager().startStateForResult(
1051 SlideshowPage.class, REQUEST_SLIDESHOW, data);
1052 return true;
1053 }
1054 case R.id.action_crop: {
Wu-cheng Li898a2f42012-08-27 00:10:38 +08001055 Activity activity = mActivity;
Ruben Brunk63926d22012-10-17 00:40:35 -07001056 Intent intent = new Intent(FilterShowActivity.CROP_ACTION);
1057 intent.setClass(activity, FilterShowActivity.class);
1058 intent.setDataAndType(manager.getContentUri(path), current.getMimeType())
1059 .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Owen Linf9a0a432011-08-17 22:07:43 +08001060 activity.startActivityForResult(intent, PicasaSource.isPicasaImage(current)
1061 ? REQUEST_CROP_PICASA
1062 : REQUEST_CROP);
1063 return true;
1064 }
Teng-Hui Zhu50ea2d22012-08-23 16:45:11 -07001065 case R.id.action_trim: {
Teng-Hui Zhu3f1f1ba2012-08-24 14:50:37 -07001066 Intent intent = new Intent(mActivity, TrimVideo.class);
1067 intent.setData(manager.getContentUri(path));
Teng-Hui Zhu15ff1b12012-09-23 15:02:56 -07001068 // We need the file path to wrap this into a RandomAccessFile.
1069 intent.putExtra(KEY_MEDIA_ITEM_PATH, current.getFilePath());
Teng-Hui Zhu3f1f1ba2012-08-24 14:50:37 -07001070 mActivity.startActivityForResult(intent, REQUEST_TRIM);
Teng-Hui Zhu50ea2d22012-08-23 16:45:11 -07001071 return true;
1072 }
Teng-Hui Zhu648b3392012-11-13 10:39:26 -08001073 case R.id.action_mute: {
1074 MuteVideo muteVideo = new MuteVideo(current,
1075 manager.getContentUri(path), mActivity);
1076 muteVideo.muteInBackground();
1077 return true;
1078 }
Yuli Huangf50ce2b2012-05-02 00:50:56 +08001079 case R.id.action_edit: {
Bobby Georgescua9948ef2012-09-11 17:02:03 -07001080 launchPhotoEditor();
Yuli Huangf50ce2b2012-05-02 00:50:56 +08001081 return true;
1082 }
Owen Linf9a0a432011-08-17 22:07:43 +08001083 case R.id.action_details: {
1084 if (mShowDetails) {
1085 hideDetails();
1086 } else {
Michael Kolb995c4562012-07-20 12:23:09 -07001087 showDetails();
Owen Linf9a0a432011-08-17 22:07:43 +08001088 }
1089 return true;
1090 }
Ray Chen67098d12012-04-05 17:25:43 +08001091 case R.id.action_delete:
Ray Chen9a033b02012-05-15 11:22:21 +08001092 confirmMsg = mActivity.getResources().getQuantityString(
1093 R.plurals.delete_selection, 1);
Owen Linf9a0a432011-08-17 22:07:43 +08001094 case R.id.action_setas:
Owen Linf9a0a432011-08-17 22:07:43 +08001095 case R.id.action_rotate_ccw:
1096 case R.id.action_rotate_cw:
1097 case R.id.action_show_on_map:
Owen Linf9a0a432011-08-17 22:07:43 +08001098 mSelectionManager.deSelectAll();
1099 mSelectionManager.toggle(path);
Owen Lind759b7c2012-05-16 15:32:02 -07001100 mMenuExecutor.onMenuClicked(item, confirmMsg, mConfirmDialogListener);
Owen Linf9a0a432011-08-17 22:07:43 +08001101 return true;
Owen Linf9a0a432011-08-17 22:07:43 +08001102 default :
1103 return false;
1104 }
1105 }
1106
1107 private void hideDetails() {
1108 mShowDetails = false;
Ray Chen4105e222011-08-24 11:40:04 +08001109 mDetailsHelper.hide();
Owen Linf9a0a432011-08-17 22:07:43 +08001110 }
1111
Michael Kolb995c4562012-07-20 12:23:09 -07001112 private void showDetails() {
Owen Linf9a0a432011-08-17 22:07:43 +08001113 mShowDetails = true;
Ray Chen4105e222011-08-24 11:40:04 +08001114 if (mDetailsHelper == null) {
1115 mDetailsHelper = new DetailsHelper(mActivity, mRootPane, new MyDetailsSource());
1116 mDetailsHelper.setCloseListener(new CloseListener() {
Pin Ting06c64012012-05-03 08:26:17 +08001117 @Override
Owen Linf9a0a432011-08-17 22:07:43 +08001118 public void onClose() {
1119 hideDetails();
1120 }
1121 });
Owen Linf9a0a432011-08-17 22:07:43 +08001122 }
Ray Chen4105e222011-08-24 11:40:04 +08001123 mDetailsHelper.show();
Owen Linf9a0a432011-08-17 22:07:43 +08001124 }
1125
Chih-Chung Changbd141b52012-04-26 10:10:49 +08001126 ////////////////////////////////////////////////////////////////////////////
1127 // Callbacks from PhotoView
1128 ////////////////////////////////////////////////////////////////////////////
1129 @Override
Owen Linf9a0a432011-08-17 22:07:43 +08001130 public void onSingleTapUp(int x, int y) {
Chih-Chung Changbd141b52012-04-26 10:10:49 +08001131 if (mAppBridge != null) {
1132 if (mAppBridge.onSingleTapUp(x, y)) return;
Wu-cheng Li014d9582012-04-18 17:10:02 +08001133 }
1134
Owen Lin616a70f2012-05-07 16:35:53 +08001135 MediaItem item = mModel.getMediaItem(0);
Wu-cheng Lib5dc5422012-04-30 18:36:22 +08001136 if (item == null || item == mScreenNailItem) {
1137 // item is not ready or it is camera preview, ignore
Owen Linf9a0a432011-08-17 22:07:43 +08001138 return;
1139 }
1140
Wu-cheng Li8868aa12012-09-24 18:32:59 +08001141 int supported = item.getSupportedOperations();
Angus Kong3935ca32012-11-01 15:08:44 +08001142 boolean playVideo = ((supported & MediaItem.SUPPORT_PLAY) != 0);
Wu-cheng Li8868aa12012-09-24 18:32:59 +08001143 boolean unlock = ((supported & MediaItem.SUPPORT_UNLOCK) != 0);
Bobby Georgescuc7e3c762012-09-27 16:36:03 -07001144 boolean goBack = ((supported & MediaItem.SUPPORT_BACK) != 0);
Bobby Georgescu45f089d2012-10-02 13:30:09 -07001145 boolean launchCamera = ((supported & MediaItem.SUPPORT_CAMERA_SHORTCUT) != 0);
Owen Linf9a0a432011-08-17 22:07:43 +08001146
1147 if (playVideo) {
1148 // determine if the point is at center (1/6) of the photo view.
1149 // (The position of the "play" icon is at center (1/6) of the photo)
1150 int w = mPhotoView.getWidth();
1151 int h = mPhotoView.getHeight();
1152 playVideo = (Math.abs(x - w / 2) * 12 <= w)
1153 && (Math.abs(y - h / 2) * 12 <= h);
1154 }
1155
1156 if (playVideo) {
Angus Kong3935ca32012-11-01 15:08:44 +08001157 if (mSecureAlbum == null) {
1158 playVideo(mActivity, item.getPlayUri(), item.getName());
1159 } else {
1160 mActivity.getStateManager().finishState(this);
1161 }
Bobby Georgescuc7e3c762012-09-27 16:36:03 -07001162 } else if (goBack) {
1163 onBackPressed();
Wu-cheng Li8868aa12012-09-24 18:32:59 +08001164 } else if (unlock) {
Wu-cheng Li6455ba92012-11-02 13:36:07 +08001165 Intent intent = new Intent(mActivity, Gallery.class);
1166 intent.putExtra(Gallery.KEY_DISMISS_KEYGUARD, true);
1167 mActivity.startActivity(intent);
Bobby Georgescu45f089d2012-10-02 13:30:09 -07001168 } else if (launchCamera) {
Bobby Georgescu5bd00332012-10-24 12:09:38 -07001169 launchCamera();
Owen Linf9a0a432011-08-17 22:07:43 +08001170 } else {
Chih-Chung Chang61f94712012-05-02 20:05:16 +08001171 toggleBars();
Owen Linf9a0a432011-08-17 22:07:43 +08001172 }
1173 }
1174
Chih-Chung Changbd141b52012-04-26 10:10:49 +08001175 @Override
Chih-Chung Chang61f94712012-05-02 20:05:16 +08001176 public void onActionBarAllowed(boolean allowed) {
1177 mActionBarAllowed = allowed;
1178 mHandler.sendEmptyMessage(MSG_UPDATE_ACTION_BAR);
1179 }
1180
1181 @Override
Chih-Chung Change6251df2012-05-22 11:35:46 -07001182 public void onActionBarWanted() {
1183 mHandler.sendEmptyMessage(MSG_WANT_BARS);
1184 }
1185
1186 @Override
Chih-Chung Changbd141b52012-04-26 10:10:49 +08001187 public void onFullScreenChanged(boolean full) {
1188 Message m = mHandler.obtainMessage(
1189 MSG_ON_FULL_SCREEN_CHANGED, full ? 1 : 0, 0);
1190 m.sendToTarget();
1191 }
1192
Chih-Chung Chang6b891c62012-06-07 20:09:13 +08001193 // How we do delete/undo:
1194 //
1195 // When the user choose to delete a media item, we just tell the
1196 // FilterDeleteSet to hide that item. If the user choose to undo it, we
1197 // again tell FilterDeleteSet not to hide it. If the user choose to commit
1198 // the deletion, we then actually delete the media item.
1199 @Override
1200 public void onDeleteImage(Path path, int offset) {
Chih-Chung Chang6118af92012-06-22 20:56:04 +08001201 onCommitDeleteImage(); // commit the previous deletion
Chih-Chung Chang6b891c62012-06-07 20:09:13 +08001202 mDeletePath = path;
1203 mDeleteIsFocus = (offset == 0);
Chih-Chung Chang6118af92012-06-22 20:56:04 +08001204 mMediaSet.addDeletion(path, mCurrentIndex + offset);
Chih-Chung Chang6b891c62012-06-07 20:09:13 +08001205 }
1206
1207 @Override
1208 public void onUndoDeleteImage() {
Chih-Chung Chang6118af92012-06-22 20:56:04 +08001209 if (mDeletePath == null) return;
Chih-Chung Chang6b891c62012-06-07 20:09:13 +08001210 // If the deletion was done on the focused item, we want the model to
1211 // focus on it when it is undeleted.
1212 if (mDeleteIsFocus) mModel.setFocusHintPath(mDeletePath);
Chih-Chung Chang6118af92012-06-22 20:56:04 +08001213 mMediaSet.removeDeletion(mDeletePath);
Chih-Chung Chang6b891c62012-06-07 20:09:13 +08001214 mDeletePath = null;
Chih-Chung Chang6b891c62012-06-07 20:09:13 +08001215 }
1216
1217 @Override
1218 public void onCommitDeleteImage() {
1219 if (mDeletePath == null) return;
Chih-Chung Chang6b891c62012-06-07 20:09:13 +08001220 mSelectionManager.deSelectAll();
1221 mSelectionManager.toggle(mDeletePath);
1222 mMenuExecutor.onMenuClicked(R.id.action_delete, null, true, false);
1223 mDeletePath = null;
1224 }
1225
Bobby Georgescud81b2642012-10-07 16:25:54 -07001226 public void playVideo(Activity activity, Uri uri, String title) {
Owen Linf9a0a432011-08-17 22:07:43 +08001227 try {
1228 Intent intent = new Intent(Intent.ACTION_VIEW)
Ray Chena3871052012-05-17 12:15:08 +08001229 .setDataAndType(uri, "video/*")
1230 .putExtra(Intent.EXTRA_TITLE, title)
1231 .putExtra(MovieActivity.KEY_TREAT_UP_AS_BACK, true);
Chih-Chung Chang71cd89a2012-05-17 18:22:27 -07001232 activity.startActivityForResult(intent, REQUEST_PLAY_VIDEO);
Owen Linf9a0a432011-08-17 22:07:43 +08001233 } catch (ActivityNotFoundException e) {
1234 Toast.makeText(activity, activity.getString(R.string.video_err),
1235 Toast.LENGTH_SHORT).show();
1236 }
1237 }
1238
Yuli Huangf50ce2b2012-05-02 00:50:56 +08001239 private void setCurrentPhotoByIntent(Intent intent) {
1240 if (intent == null) return;
1241 Path path = mApplication.getDataManager()
1242 .findPathByUri(intent.getData(), intent.getType());
1243 if (path != null) {
Doris Liu0addfc72012-10-17 16:15:51 -07001244 Path albumPath = mApplication.getDataManager().getDefaultSetOf(path);
1245 if (!albumPath.equalsIgnoreCase(mOriginalSetPathString)) {
1246 // If the edited image is stored in a different album, we need
1247 // to start a new activity state to show the new image
1248 Bundle data = new Bundle(getData());
1249 data.putString(KEY_MEDIA_SET_PATH, albumPath.toString());
1250 data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, path.toString());
Bobby Georgescucfa7fde2012-11-05 14:12:51 -08001251 mActivity.getStateManager().startState(SinglePhotoPage.class, data);
Doris Liu0addfc72012-10-17 16:15:51 -07001252 return;
1253 }
Yuli Huangf50ce2b2012-05-02 00:50:56 +08001254 mModel.setCurrentPhoto(path, mCurrentIndex);
1255 }
1256 }
1257
Owen Linf9a0a432011-08-17 22:07:43 +08001258 @Override
1259 protected void onStateResult(int requestCode, int resultCode, Intent data) {
John Reckf85d9742012-10-24 11:11:51 -07001260 if (resultCode == Activity.RESULT_CANCELED) {
1261 // This is a reset, not a canceled
1262 return;
1263 }
1264 if (resultCode == ProxyLauncher.RESULT_USER_CANCELED) {
1265 // Unmap reset vs. canceled
1266 resultCode = Activity.RESULT_CANCELED;
1267 }
1268 mRecenterCameraOnResume = false;
Owen Linf9a0a432011-08-17 22:07:43 +08001269 switch (requestCode) {
Yuli Huangf50ce2b2012-05-02 00:50:56 +08001270 case REQUEST_EDIT:
1271 setCurrentPhotoByIntent(data);
1272 break;
Owen Linf9a0a432011-08-17 22:07:43 +08001273 case REQUEST_CROP:
1274 if (resultCode == Activity.RESULT_OK) {
Yuli Huangf50ce2b2012-05-02 00:50:56 +08001275 setCurrentPhotoByIntent(data);
Owen Linf9a0a432011-08-17 22:07:43 +08001276 }
1277 break;
1278 case REQUEST_CROP_PICASA: {
Yuli Huangf50ce2b2012-05-02 00:50:56 +08001279 if (resultCode == Activity.RESULT_OK) {
1280 Context context = mActivity.getAndroidContext();
Yuli Huang88cc2ca2012-05-05 17:42:32 +08001281 String message = context.getString(R.string.crop_saved,
Ruben Brunk00d64dd2012-10-18 23:39:18 -07001282 context.getString(R.string.folder_edited_online_photos));
Yuli Huangf50ce2b2012-05-02 00:50:56 +08001283 Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
1284 }
Owen Linf9a0a432011-08-17 22:07:43 +08001285 break;
1286 }
1287 case REQUEST_SLIDESHOW: {
1288 if (data == null) break;
1289 String path = data.getStringExtra(SlideshowPage.KEY_ITEM_PATH);
1290 int index = data.getIntExtra(SlideshowPage.KEY_PHOTO_INDEX, 0);
1291 if (path != null) {
1292 mModel.setCurrentPhoto(Path.fromString(path), index);
1293 }
1294 }
1295 }
1296 }
1297
George Mount14d32892012-08-16 11:06:42 -07001298 @Override
Owen Linf9a0a432011-08-17 22:07:43 +08001299 public void onPause() {
Owen Lind759b7c2012-05-16 15:32:02 -07001300 super.onPause();
1301 mIsActive = false;
1302
Yuli Huangbd7c0162012-05-15 22:36:59 +08001303 mActivity.getGLRoot().unfreeze();
1304 mHandler.removeMessages(MSG_UNFREEZE_GLROOT);
Chih-Chung Chang253c5ae2012-05-16 17:37:10 -07001305
Ray Chen4105e222011-08-24 11:40:04 +08001306 DetailsHelper.pause();
Doris Liu4438a7c2012-10-08 16:31:00 -07001307 // Hide the detail dialog on exit
1308 if (mShowDetails) hideDetails();
Bobby Georgescud3973782012-09-12 13:48:50 -07001309 if (mModel != null) {
Bobby Georgescud3973782012-09-12 13:48:50 -07001310 mModel.pause();
1311 }
Owen Linf9a0a432011-08-17 22:07:43 +08001312 mPhotoView.pause();
Owen Linf9a0a432011-08-17 22:07:43 +08001313 mHandler.removeMessages(MSG_HIDE_BARS);
Bobby Georgescud2724f62012-10-06 15:22:03 -07001314 mHandler.removeMessages(MSG_REFRESH_BOTTOM_CONTROLS);
George Mount4b4dbd22012-10-18 14:20:39 -07001315 refreshBottomControlsWhenReady();
Owen Linf9a0a432011-08-17 22:07:43 +08001316 mActionBar.removeOnMenuVisibilityListener(mMenuVisibilityListener);
Bobby Georgescuba65c372012-10-06 01:06:43 -07001317 if (mShowSpinner) {
Bobby Georgescu9481d052012-10-02 16:28:20 -07001318 mActionBar.disableAlbumModeMenu(true);
1319 }
Chih-Chung Chang6b891c62012-06-07 20:09:13 +08001320 onCommitDeleteImage();
Chih-Chung Chang27859562011-09-08 11:51:11 +08001321 mMenuExecutor.pause();
Chih-Chung Chang6118af92012-06-22 20:56:04 +08001322 if (mMediaSet != null) mMediaSet.clearDeletion();
Owen Linf9a0a432011-08-17 22:07:43 +08001323 }
1324
1325 @Override
Yuli Huangbd7c0162012-05-15 22:36:59 +08001326 public void onCurrentImageUpdated() {
1327 mActivity.getGLRoot().unfreeze();
1328 }
1329
George Mountf122d562012-10-09 17:50:33 -07001330 @Override
Bobby Georgescu7eea4d32012-09-06 17:14:02 -07001331 public void onFilmModeChanged(boolean enabled) {
George Mount4b4dbd22012-10-18 14:20:39 -07001332 refreshBottomControlsWhenReady();
Bobby Georgescuc29588d2012-10-18 15:36:03 -07001333 if (mShowSpinner) {
1334 if (enabled) {
1335 mActionBar.enableAlbumModeMenu(
1336 GalleryActionBar.ALBUM_FILMSTRIP_MODE_SELECTED, this);
1337 } else {
1338 mActionBar.disableAlbumModeMenu(true);
1339 }
1340 }
Bobby Georgescu7eea4d32012-09-06 17:14:02 -07001341 if (enabled) {
1342 mHandler.removeMessages(MSG_HIDE_BARS);
1343 } else {
1344 refreshHidingMessage();
1345 }
1346 }
1347
1348 private void transitionFromAlbumPageIfNeeded() {
1349 TransitionStore transitions = mActivity.getTransitionStore();
1350
Bobby Georgescu7eea4d32012-09-06 17:14:02 -07001351 int albumPageTransition = transitions.get(
1352 KEY_ALBUMPAGE_TRANSITION, MSG_ALBUMPAGE_NONE);
1353
Bobby Georgescud81b2642012-10-07 16:25:54 -07001354 if (albumPageTransition == MSG_ALBUMPAGE_NONE && mAppBridge != null
1355 && mRecenterCameraOnResume) {
Bobby Georgescu00ccf352012-09-19 16:51:05 -07001356 // Generally, resuming the PhotoPage when in Camera should
1357 // reset to the capture mode to allow quick photo taking
1358 mCurrentIndex = 0;
1359 mPhotoView.resetToFirstPicture();
1360 } else {
1361 int resumeIndex = transitions.get(KEY_INDEX_HINT, -1);
1362 if (resumeIndex >= 0) {
Bobby Georgescu3ad7bbc2012-10-23 20:29:57 -07001363 if (mHasCameraScreennailOrPlaceholder) {
Bobby Georgescu76f18812012-10-07 23:06:05 -07001364 // Account for preview/placeholder being the first item
Bobby Georgescu00ccf352012-09-19 16:51:05 -07001365 resumeIndex++;
1366 }
1367 if (resumeIndex < mMediaSet.getMediaItemCount()) {
1368 mCurrentIndex = resumeIndex;
1369 mModel.moveTo(mCurrentIndex);
1370 }
1371 }
1372 }
1373
1374 if (albumPageTransition == MSG_ALBUMPAGE_RESUMED) {
1375 mPhotoView.setFilmMode(mStartInFilmstrip || mAppBridge != null);
1376 } else if (albumPageTransition == MSG_ALBUMPAGE_PICKED) {
1377 mPhotoView.setFilmMode(false);
Bobby Georgescu7eea4d32012-09-06 17:14:02 -07001378 }
Bobby Georgescu7eea4d32012-09-06 17:14:02 -07001379 }
1380
Yuli Huangbd7c0162012-05-15 22:36:59 +08001381 @Override
Owen Linf9a0a432011-08-17 22:07:43 +08001382 protected void onResume() {
1383 super.onResume();
Bobby Georgescu7eea4d32012-09-06 17:14:02 -07001384
Bobby Georgescud3973782012-09-12 13:48:50 -07001385 if (mModel == null) {
1386 mActivity.getStateManager().finishState(this);
1387 return;
1388 }
Bobby Georgescu7eea4d32012-09-06 17:14:02 -07001389 transitionFromAlbumPageIfNeeded();
1390
Owen Lind759b7c2012-05-16 15:32:02 -07001391 mActivity.getGLRoot().freeze();
Owen Linf9a0a432011-08-17 22:07:43 +08001392 mIsActive = true;
1393 setContentPane(mRootPane);
Yuli Huang04ac0452012-03-20 16:37:05 +08001394
Owen Linf9a0a432011-08-17 22:07:43 +08001395 mModel.resume();
1396 mPhotoView.resume();
Wu-cheng Li898a2f42012-08-27 00:10:38 +08001397 mActionBar.setDisplayOptions(
Bobby Georgescu3cf502a2012-10-01 15:50:11 -07001398 ((mSecureAlbum == null) && (mSetPathString != null)), false);
Owen Linf9a0a432011-08-17 22:07:43 +08001399 mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener);
George Mount4b4dbd22012-10-18 14:20:39 -07001400 refreshBottomControlsWhenReady();
Bobby Georgescuc29588d2012-10-18 15:36:03 -07001401 if (mShowSpinner && mPhotoView.getFilmMode()) {
Bobby Georgescu9481d052012-10-02 16:28:20 -07001402 mActionBar.enableAlbumModeMenu(
1403 GalleryActionBar.ALBUM_FILMSTRIP_MODE_SELECTED, this);
1404 }
Bobby Georgescu00ccf352012-09-19 16:51:05 -07001405 if (!mShowBars) {
1406 mActionBar.hide();
1407 mActivity.getGLRoot().setLightsOutMode(true);
Chih-Chung Changbd141b52012-04-26 10:10:49 +08001408 }
John Reck8fe22ec2012-09-26 16:13:02 -07001409 boolean haveImageEditor = GalleryUtils.isEditorAvailable(mActivity, "image/*");
1410 if (haveImageEditor != mHaveImageEditor) {
1411 mHaveImageEditor = haveImageEditor;
1412 updateMenuOperations();
1413 }
Bobby Georgescu00ccf352012-09-19 16:51:05 -07001414
Bobby Georgescud81b2642012-10-07 16:25:54 -07001415 mRecenterCameraOnResume = true;
Yuli Huangbd7c0162012-05-15 22:36:59 +08001416 mHandler.sendEmptyMessageDelayed(MSG_UNFREEZE_GLROOT, UNFREEZE_GLROOT_TIMEOUT);
Owen Linf9a0a432011-08-17 22:07:43 +08001417 }
1418
Chih-Chung Chang15b351a2012-03-15 16:38:45 +08001419 @Override
1420 protected void onDestroy() {
Chih-Chung Changbd141b52012-04-26 10:10:49 +08001421 if (mAppBridge != null) {
Chih-Chung Chang253c5ae2012-05-16 17:37:10 -07001422 mAppBridge.setServer(null);
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +08001423 mScreenNailItem.setScreenNail(null);
Chih-Chung Changbd141b52012-04-26 10:10:49 +08001424 mAppBridge.detachScreenNail();
1425 mAppBridge = null;
Chih-Chung Chang3b4a8ae2012-05-09 21:17:10 +08001426 mScreenNailSet = null;
1427 mScreenNailItem = null;
Chih-Chung Changb29a27f2012-03-22 17:42:33 +08001428 }
Chih-Chung Chang2ef46ed2012-05-08 17:57:33 +08001429 mActivity.getGLRoot().setOrientationSource(null);
Bobby Georgescuf44499d2012-09-17 18:12:11 -07001430 if (mBottomControls != null) mBottomControls.cleanup();
Chih-Chung Changaeb30622012-05-03 11:41:05 +08001431
1432 // Remove all pending messages.
1433 mHandler.removeCallbacksAndMessages(null);
Chih-Chung Chang15b351a2012-03-15 16:38:45 +08001434 super.onDestroy();
1435 }
1436
Owen Linf9a0a432011-08-17 22:07:43 +08001437 private class MyDetailsSource implements DetailsSource {
Owen Lin6cf80742011-08-28 10:50:21 +08001438
1439 @Override
Owen Linf9a0a432011-08-17 22:07:43 +08001440 public MediaDetails getDetails() {
Owen Lin616a70f2012-05-07 16:35:53 +08001441 return mModel.getMediaItem(0).getDetails();
Owen Linf9a0a432011-08-17 22:07:43 +08001442 }
Owen Lin6cf80742011-08-28 10:50:21 +08001443
1444 @Override
Owen Linf9a0a432011-08-17 22:07:43 +08001445 public int size() {
1446 return mMediaSet != null ? mMediaSet.getMediaItemCount() : 1;
1447 }
Owen Lin6cf80742011-08-28 10:50:21 +08001448
1449 @Override
Michael Kolb995c4562012-07-20 12:23:09 -07001450 public int setIndex() {
1451 return mModel.getCurrentIndex();
Ray Chen4105e222011-08-24 11:40:04 +08001452 }
Owen Linf9a0a432011-08-17 22:07:43 +08001453 }
Bobby Georgescu3cf502a2012-10-01 15:50:11 -07001454
1455 @Override
1456 public void onAlbumModeSelected(int mode) {
1457 if (mode == GalleryActionBar.ALBUM_GRID_MODE_SELECTED) {
1458 switchToGrid();
1459 }
1460 }
George Mount4b4dbd22012-10-18 14:20:39 -07001461
1462 @Override
1463 public void refreshBottomControlsWhenReady() {
1464 if (mBottomControls == null) {
1465 return;
1466 }
1467 MediaObject currentPhoto = mCurrentPhoto;
1468 if (currentPhoto == null) {
1469 mHandler.obtainMessage(MSG_REFRESH_BOTTOM_CONTROLS, 0, 0, currentPhoto).sendToTarget();
1470 } else {
1471 currentPhoto.getPanoramaSupport(mRefreshBottomControlsCallback);
1472 }
1473 }
1474
1475 private void updatePanoramaUI(boolean isPanorama360) {
1476 Menu menu = mActionBar.getMenu();
1477
1478 // it could be null if onCreateActionBar has not been called yet
1479 if (menu == null) {
1480 return;
1481 }
1482
1483 MenuExecutor.updateMenuForPanorama(menu, isPanorama360, isPanorama360);
1484
1485 if (isPanorama360) {
1486 MenuItem item = menu.findItem(R.id.action_share);
1487 if (item != null) {
1488 item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
1489 item.setTitle(mActivity.getResources().getString(R.string.share_as_photo));
1490 }
1491 } else if ((mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_SHARE) != 0) {
1492 MenuItem item = menu.findItem(R.id.action_share);
1493 if (item != null) {
1494 item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
1495 item.setTitle(mActivity.getResources().getString(R.string.share));
1496 }
1497 }
1498 }
Bobby Georgescu94958432012-10-23 20:52:26 -07001499
1500 @Override
1501 public void onUndoBarVisibilityChanged(boolean visible) {
1502 refreshBottomControlsWhenReady();
1503 }
Owen Linf9a0a432011-08-17 22:07:43 +08001504}