Paramananda Pradhan | 9382a97 | 2014-12-14 17:27:31 +0530 | [diff] [blame] | 1 | /** |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 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 | |
| 17 | package com.android.gallery3d.app; |
| 18 | |
Yuli Huang | fc86994 | 2012-06-29 18:59:17 +0800 | [diff] [blame] | 19 | import android.annotation.TargetApi; |
John Reck | 2abaaf7 | 2012-12-12 13:43:43 -0800 | [diff] [blame] | 20 | import android.app.ActionBar.OnMenuVisibilityListener; |
Owen Lin | 8bc5beb | 2011-11-17 15:26:56 +0800 | [diff] [blame] | 21 | import android.app.Activity; |
Ray Chen | 604f053 | 2011-10-21 16:07:12 +0800 | [diff] [blame] | 22 | import android.content.ActivityNotFoundException; |
| 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 25 | import android.content.pm.PackageManager; |
Chao Zhang | 8724b7e | 2016-05-12 17:34:31 +0800 | [diff] [blame] | 26 | import android.content.pm.ResolveInfo; |
John Reck | 4ea5c27 | 2013-01-18 16:00:45 -0800 | [diff] [blame] | 27 | import android.content.res.Configuration; |
Yuli Huang | 04ac045 | 2012-03-20 16:37:05 +0800 | [diff] [blame] | 28 | import android.graphics.Rect; |
Ray Chen | 604f053 | 2011-10-21 16:07:12 +0800 | [diff] [blame] | 29 | import android.net.Uri; |
Martijn Coenen | 33ef037 | 2012-03-26 18:25:50 -0700 | [diff] [blame] | 30 | import android.nfc.NfcAdapter; |
John Reck | ddf0225 | 2012-09-26 11:37:23 -0700 | [diff] [blame] | 31 | import android.nfc.NfcAdapter.CreateBeamUrisCallback; |
| 32 | import android.nfc.NfcEvent; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 33 | import android.os.AsyncTask; |
Ray Chen | 604f053 | 2011-10-21 16:07:12 +0800 | [diff] [blame] | 34 | import android.os.Bundle; |
| 35 | import android.os.Handler; |
| 36 | import android.os.Message; |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 37 | import android.os.SystemClock; |
kaiyiz | ed2687a | 2014-10-15 10:10:13 +0800 | [diff] [blame] | 38 | import android.text.TextUtils; |
John Reck | 2abaaf7 | 2012-12-12 13:43:43 -0800 | [diff] [blame] | 39 | import android.view.Menu; |
| 40 | import android.view.MenuItem; |
ztenghui | 02f459f | 2013-08-30 16:34:23 -0700 | [diff] [blame] | 41 | import android.view.View; |
huiyan | 4c35ffd | 2016-03-09 11:48:47 +0800 | [diff] [blame] | 42 | import android.view.ViewGroup; |
| 43 | import android.view.Window; |
huiyan | 8782c24 | 2016-04-23 14:52:23 +0800 | [diff] [blame] | 44 | import android.view.WindowManager; |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 45 | import android.widget.RelativeLayout; |
Ray Chen | 604f053 | 2011-10-21 16:07:12 +0800 | [diff] [blame] | 46 | import android.widget.Toast; |
| 47 | |
Likai Ding | c83b5b7 | 2016-05-25 14:48:41 +0800 | [diff] [blame] | 48 | import org.codeaurora.gallery.R; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 49 | |
| 50 | import com.android.gallery3d.app.dualcam3d.ThreeDimensionalActivity; |
Yuli Huang | fc86994 | 2012-06-29 18:59:17 +0800 | [diff] [blame] | 51 | import com.android.gallery3d.common.ApiHelper; |
Bobby Georgescu | ee899c0 | 2012-10-01 17:49:30 -0700 | [diff] [blame] | 52 | import com.android.gallery3d.data.ComboAlbum; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 53 | import com.android.gallery3d.data.DataManager; |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 54 | import com.android.gallery3d.data.FilterDeleteSet; |
Bobby Georgescu | 45f089d | 2012-10-02 13:30:09 -0700 | [diff] [blame] | 55 | import com.android.gallery3d.data.FilterSource; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 56 | import com.android.gallery3d.data.MediaDetails; |
| 57 | import com.android.gallery3d.data.MediaItem; |
| 58 | import com.android.gallery3d.data.MediaObject; |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 59 | import com.android.gallery3d.data.MediaObject.PanoramaSupportCallback; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 60 | import com.android.gallery3d.data.MediaSet; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 61 | import com.android.gallery3d.data.Path; |
Wu-cheng Li | a0ce682 | 2012-08-22 19:15:35 +0800 | [diff] [blame] | 62 | import com.android.gallery3d.data.SecureAlbum; |
| 63 | import com.android.gallery3d.data.SecureSource; |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 64 | import com.android.gallery3d.data.SnailAlbum; |
| 65 | import com.android.gallery3d.data.SnailItem; |
Chih-Chung Chang | 15b351a | 2012-03-15 16:38:45 +0800 | [diff] [blame] | 66 | import com.android.gallery3d.data.SnailSource; |
Ruben Brunk | 63926d2 | 2012-10-17 00:40:35 -0700 | [diff] [blame] | 67 | import com.android.gallery3d.filtershow.FilterShowActivity; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 68 | import com.android.gallery3d.filtershow.imageshow.MasterImage; |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 69 | import com.android.gallery3d.filtershow.tools.DualCameraEffect; |
Ray Chen | 4105e22 | 2011-08-24 11:40:04 +0800 | [diff] [blame] | 70 | import com.android.gallery3d.ui.DetailsHelper; |
| 71 | import com.android.gallery3d.ui.DetailsHelper.CloseListener; |
| 72 | import com.android.gallery3d.ui.DetailsHelper.DetailsSource; |
ztenghui | 02f459f | 2013-08-30 16:34:23 -0700 | [diff] [blame] | 73 | import com.android.gallery3d.ui.GLRootView; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 74 | import com.android.gallery3d.ui.GLView; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 75 | import com.android.gallery3d.ui.MenuExecutor; |
Owen Lin | 21a412c | 2012-04-20 18:42:22 +0800 | [diff] [blame] | 76 | import com.android.gallery3d.ui.PhotoView; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 77 | import com.android.gallery3d.ui.SelectionManager; |
| 78 | import com.android.gallery3d.ui.SynchronizedHandler; |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 79 | import com.android.gallery3d.util.GDepth; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 80 | import com.android.gallery3d.util.GalleryUtils; |
Bobby Georgescu | f37648b | 2013-03-12 22:45:17 -0700 | [diff] [blame] | 81 | import com.android.gallery3d.util.UsageStatistics; |
Likai Ding | b2e9100 | 2013-08-13 14:07:48 +0800 | [diff] [blame] | 82 | import com.android.gallery3d.util.ViewGifImage; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 83 | |
Chao Zhang | 8724b7e | 2016-05-12 17:34:31 +0800 | [diff] [blame] | 84 | import java.util.List; |
kaiyiz | ed2687a | 2014-10-15 10:10:13 +0800 | [diff] [blame] | 85 | import java.util.Locale; |
| 86 | |
Likai Ding | ba67cf5 | 2016-05-27 10:38:42 +0800 | [diff] [blame] | 87 | //import android.drm.DrmHelper; |
| 88 | |
Bobby Georgescu | cfa7fde | 2012-11-05 14:12:51 -0800 | [diff] [blame] | 89 | public abstract class PhotoPage extends ActivityState implements |
maxwen | d57f723 | 2016-06-04 22:51:06 +0200 | [diff] [blame] | 90 | PhotoView.Listener, AppBridge.Server, PhotoPageBottomControls.Delegate, |
| 91 | ThreeDButton.Delegate { |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 92 | private static final String TAG = "PhotoPage"; |
| 93 | |
| 94 | private static final int MSG_HIDE_BARS = 1; |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 95 | private static final int MSG_ON_FULL_SCREEN_CHANGED = 4; |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 96 | private static final int MSG_UPDATE_ACTION_BAR = 5; |
Chih-Chung Chang | e6251df | 2012-05-22 11:35:46 -0700 | [diff] [blame] | 97 | private static final int MSG_WANT_BARS = 7; |
Bobby Georgescu | 3cf502a | 2012-10-01 15:50:11 -0700 | [diff] [blame] | 98 | private static final int MSG_REFRESH_BOTTOM_CONTROLS = 8; |
| 99 | private static final int MSG_ON_CAMERA_CENTER = 9; |
Bobby Georgescu | f4e22eb | 2012-10-02 18:34:08 -0700 | [diff] [blame] | 100 | private static final int MSG_ON_PICTURE_CENTER = 10; |
George Mount | f122d56 | 2012-10-09 17:50:33 -0700 | [diff] [blame] | 101 | private static final int MSG_REFRESH_IMAGE = 11; |
Mangesh Ghiware | 423e45e | 2012-10-11 23:11:27 -0700 | [diff] [blame] | 102 | private static final int MSG_UPDATE_PHOTO_UI = 12; |
Mangesh Ghiware | 423e45e | 2012-10-11 23:11:27 -0700 | [diff] [blame] | 103 | private static final int MSG_UPDATE_DEFERRED = 14; |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 104 | private static final int MSG_UPDATE_SHARE_URI = 15; |
| 105 | private static final int MSG_UPDATE_PANORAMA_UI = 16; |
Owen Lin | 6cf8074 | 2011-08-28 10:50:21 +0800 | [diff] [blame] | 106 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 107 | private static final int HIDE_BARS_TIMEOUT = 3500; |
| 108 | |
| 109 | private static final int REQUEST_SLIDESHOW = 1; |
| 110 | private static final int REQUEST_CROP = 2; |
| 111 | private static final int REQUEST_CROP_PICASA = 3; |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 112 | private static final int REQUEST_EDIT = 4; |
Chih-Chung Chang | 71cd89a | 2012-05-17 18:22:27 -0700 | [diff] [blame] | 113 | private static final int REQUEST_PLAY_VIDEO = 5; |
Teng-Hui Zhu | 3f1f1ba | 2012-08-24 14:50:37 -0700 | [diff] [blame] | 114 | private static final int REQUEST_TRIM = 6; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 115 | |
| 116 | public static final String KEY_MEDIA_SET_PATH = "media-set-path"; |
| 117 | public static final String KEY_MEDIA_ITEM_PATH = "media-item-path"; |
| 118 | public static final String KEY_INDEX_HINT = "index-hint"; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 119 | public static final String KEY_CURRENT_PHOTO_HINT = "currtent_photo_path"; |
Yuli Huang | 04ac045 | 2012-03-20 16:37:05 +0800 | [diff] [blame] | 120 | public static final String KEY_OPEN_ANIMATION_RECT = "open-animation-rect"; |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 121 | public static final String KEY_APP_BRIDGE = "app-bridge"; |
Yuli Huang | 54fe620 | 2012-05-23 16:06:32 +0800 | [diff] [blame] | 122 | public static final String KEY_TREAT_BACK_AS_UP = "treat-back-as-up"; |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 123 | public static final String KEY_START_IN_FILMSTRIP = "start-in-filmstrip"; |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 124 | public static final String KEY_RETURN_INDEX_HINT = "return-index-hint"; |
Wu-cheng Li | 23e595f | 2012-09-21 14:36:21 +0800 | [diff] [blame] | 125 | public static final String KEY_SHOW_WHEN_LOCKED = "show_when_locked"; |
Bobby Georgescu | 45f089d | 2012-10-02 13:30:09 -0700 | [diff] [blame] | 126 | public static final String KEY_IN_CAMERA_ROLL = "in_camera_roll"; |
John Hoford | 463b918 | 2013-09-16 15:51:02 -0700 | [diff] [blame] | 127 | public static final String KEY_READONLY = "read-only"; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 128 | public static final String KEY_FROM_VIDEOS_SCREEN = "from-video-screen"; |
| 129 | public static final String KEY_FROM_TIMELINE_SCREEN = "from-timeline-screen"; |
kaiyiz | ed2687a | 2014-10-15 10:10:13 +0800 | [diff] [blame] | 130 | |
| 131 | // Bundle key, used for checking whether it is from widget |
| 132 | public static final String KEY_IS_FROM_WIDGET = "is_from_widget"; |
| 133 | |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 134 | public static final String KEY_ALBUMPAGE_TRANSITION = "albumpage-transition"; |
| 135 | public static final int MSG_ALBUMPAGE_NONE = 0; |
| 136 | public static final int MSG_ALBUMPAGE_STARTED = 1; |
| 137 | public static final int MSG_ALBUMPAGE_RESUMED = 2; |
| 138 | public static final int MSG_ALBUMPAGE_PICKED = 4; |
| 139 | |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 140 | public static final String ACTION_NEXTGEN_EDIT = "action_nextgen_edit"; |
nicolasroard | 8c4e95f | 2013-04-08 18:16:17 -0700 | [diff] [blame] | 141 | public static final String ACTION_SIMPLE_EDIT = "action_simple_edit"; |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 142 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 143 | private GalleryApp mApplication; |
| 144 | private SelectionManager mSelectionManager; |
| 145 | |
| 146 | private PhotoView mPhotoView; |
| 147 | private PhotoPage.Model mModel; |
Ray Chen | 4105e22 | 2011-08-24 11:40:04 +0800 | [diff] [blame] | 148 | private DetailsHelper mDetailsHelper; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 149 | private boolean mShowDetails; |
| 150 | |
| 151 | // mMediaSet could be null if there is no KEY_MEDIA_SET_PATH supplied. |
| 152 | // E.g., viewing a photo in gmail attachment |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 153 | private FilterDeleteSet mMediaSet; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 154 | |
Wu-cheng Li | a0ce682 | 2012-08-22 19:15:35 +0800 | [diff] [blame] | 155 | // The mediaset used by camera launched from secure lock screen. |
| 156 | private SecureAlbum mSecureAlbum; |
| 157 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 158 | private int mCurrentIndex = 0; |
| 159 | private Handler mHandler; |
Owen Lin | 113bfc7 | 2011-08-30 10:38:59 +0800 | [diff] [blame] | 160 | private boolean mShowBars = true; |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 161 | private volatile boolean mActionBarAllowed = true; |
Ray Chen | 8cab3e8 | 2012-03-20 16:32:57 +0800 | [diff] [blame] | 162 | private GalleryActionBar mActionBar; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 163 | private boolean mIsMenuVisible; |
John Reck | 8fe22ec | 2012-09-26 16:13:02 -0700 | [diff] [blame] | 164 | private boolean mHaveImageEditor; |
Bobby Georgescu | f44499d | 2012-09-17 18:12:11 -0700 | [diff] [blame] | 165 | private PhotoPageBottomControls mBottomControls; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 166 | private MediaItem mCurrentPhoto = null; |
| 167 | private MenuExecutor mMenuExecutor; |
| 168 | private boolean mIsActive; |
Bobby Georgescu | ba65c37 | 2012-10-06 01:06:43 -0700 | [diff] [blame] | 169 | private boolean mShowSpinner; |
Ray Chen | 84c220f | 2012-03-06 17:24:28 +0800 | [diff] [blame] | 170 | private String mSetPathString; |
Chih-Chung Chang | b1e9fd8 | 2012-04-30 17:33:21 +0800 | [diff] [blame] | 171 | // This is the original mSetPathString before adding the camera preview item. |
John Hoford | 463b918 | 2013-09-16 15:51:02 -0700 | [diff] [blame] | 172 | private boolean mReadOnlyView = false; |
Chih-Chung Chang | b1e9fd8 | 2012-04-30 17:33:21 +0800 | [diff] [blame] | 173 | private String mOriginalSetPathString; |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 174 | private AppBridge mAppBridge; |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 175 | private SnailItem mScreenNailItem; |
| 176 | private SnailAlbum mScreenNailSet; |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 177 | private OrientationManager mOrientationManager; |
Yuli Huang | 54fe620 | 2012-05-23 16:06:32 +0800 | [diff] [blame] | 178 | private boolean mTreatBackAsUp; |
kaiyiz | ed2687a | 2014-10-15 10:10:13 +0800 | [diff] [blame] | 179 | // Used for checking whether it is from widget |
| 180 | private boolean mIsFromWidget; |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 181 | private boolean mStartInFilmstrip; |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 182 | private boolean mHasCameraScreennailOrPlaceholder = false; |
Bobby Georgescu | d81b264 | 2012-10-07 16:25:54 -0700 | [diff] [blame] | 183 | private boolean mRecenterCameraOnResume = true; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 184 | private boolean mIsFromVideoScreen; |
| 185 | private boolean mIsFromTimelineScreen; |
Chih-Chung Chang | 15b351a | 2012-03-15 16:38:45 +0800 | [diff] [blame] | 186 | |
Doris Liu | a680a0c | 2012-10-18 15:01:35 -0700 | [diff] [blame] | 187 | // These are only valid after the panorama callback |
| 188 | private boolean mIsPanorama; |
| 189 | private boolean mIsPanorama360; |
| 190 | |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 191 | private long mCameraSwitchCutoff = 0; |
| 192 | private boolean mSkipUpdateCurrentPhoto = false; |
| 193 | private static final long CAMERA_SWITCH_CUTOFF_THRESHOLD_MS = 300; |
| 194 | |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 195 | private static final long DEFERRED_UPDATE_MS = 250; |
Bobby Georgescu | e23a9d4 | 2012-10-10 10:49:51 -0700 | [diff] [blame] | 196 | private boolean mDeferredUpdateWaiting = false; |
| 197 | private long mDeferUpdateUntil = Long.MAX_VALUE; |
| 198 | |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 199 | // The item that is deleted (but it can still be undeleted before commiting) |
| 200 | private Path mDeletePath; |
| 201 | private boolean mDeleteIsFocus; // whether the deleted item was in focus |
| 202 | |
John Reck | ddf0225 | 2012-09-26 11:37:23 -0700 | [diff] [blame] | 203 | private Uri[] mNfcPushUris = new Uri[1]; |
Martijn Coenen | 33ef037 | 2012-03-26 18:25:50 -0700 | [diff] [blame] | 204 | |
Owen Lin | 2bb717f | 2012-07-13 17:23:05 +0800 | [diff] [blame] | 205 | private final MyMenuVisibilityListener mMenuVisibilityListener = |
| 206 | new MyMenuVisibilityListener(); |
| 207 | |
ztenghui | 02f459f | 2013-08-30 16:34:23 -0700 | [diff] [blame] | 208 | private int mLastSystemUiVis = 0; |
| 209 | |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 210 | private Intent mShareIntent; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 211 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 212 | private ThreeDButton m3DButton; |
| 213 | private boolean bShow3DButton; |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 214 | private ParseGDepthTask mParseGDepthTask; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 215 | |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 216 | private final PanoramaSupportCallback mUpdatePanoramaMenuItemsCallback = new PanoramaSupportCallback() { |
| 217 | @Override |
| 218 | public void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama, |
| 219 | boolean isPanorama360) { |
| 220 | if (mediaObject == mCurrentPhoto) { |
| 221 | mHandler.obtainMessage(MSG_UPDATE_PANORAMA_UI, isPanorama360 ? 1 : 0, 0, |
| 222 | mediaObject).sendToTarget(); |
Mangesh Ghiware | 825afb1 | 2012-10-10 18:37:24 -0700 | [diff] [blame] | 223 | } |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 224 | } |
| 225 | }; |
| 226 | |
| 227 | private final PanoramaSupportCallback mRefreshBottomControlsCallback = new PanoramaSupportCallback() { |
| 228 | @Override |
| 229 | public void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama, |
| 230 | boolean isPanorama360) { |
| 231 | if (mediaObject == mCurrentPhoto) { |
Doris Liu | a680a0c | 2012-10-18 15:01:35 -0700 | [diff] [blame] | 232 | mHandler.obtainMessage(MSG_REFRESH_BOTTOM_CONTROLS, isPanorama ? 1 : 0, isPanorama360 ? 1 : 0, |
| 233 | mediaObject).sendToTarget(); |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | }; |
| 237 | |
| 238 | private final PanoramaSupportCallback mUpdateShareURICallback = new PanoramaSupportCallback() { |
| 239 | @Override |
| 240 | public void panoramaInfoAvailable(MediaObject mediaObject, boolean isPanorama, |
| 241 | boolean isPanorama360) { |
| 242 | if (mediaObject == mCurrentPhoto) { |
| 243 | mHandler.obtainMessage(MSG_UPDATE_SHARE_URI, isPanorama360 ? 1 : 0, 0, mediaObject) |
| 244 | .sendToTarget(); |
| 245 | } |
| 246 | } |
| 247 | }; |
Mangesh Ghiware | 825afb1 | 2012-10-10 18:37:24 -0700 | [diff] [blame] | 248 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 249 | public static interface Model extends PhotoView.Model { |
| 250 | public void resume(); |
| 251 | public void pause(); |
| 252 | public boolean isEmpty(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 253 | public void setCurrentPhoto(Path path, int indexHint); |
| 254 | } |
| 255 | |
| 256 | private class MyMenuVisibilityListener implements OnMenuVisibilityListener { |
Pin Ting | 06c6401 | 2012-05-03 08:26:17 +0800 | [diff] [blame] | 257 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 258 | public void onMenuVisibilityChanged(boolean isVisible) { |
| 259 | mIsMenuVisible = isVisible; |
| 260 | refreshHidingMessage(); |
| 261 | } |
| 262 | } |
| 263 | |
Bobby Georgescu | 915c2c5 | 2012-08-23 13:05:53 -0700 | [diff] [blame] | 264 | @Override |
| 265 | protected int getBackgroundColorId() { |
| 266 | return R.color.photo_background; |
| 267 | } |
| 268 | |
Bobby Georgescu | f4a707f | 2012-08-20 16:26:26 -0700 | [diff] [blame] | 269 | private final GLView mRootPane = new GLView() { |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 270 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 271 | protected void onLayout( |
| 272 | boolean changed, int left, int top, int right, int bottom) { |
| 273 | mPhotoView.layout(0, 0, right - left, bottom - top); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 274 | if (mShowDetails) { |
Ray Chen | 8cab3e8 | 2012-03-20 16:32:57 +0800 | [diff] [blame] | 275 | mDetailsHelper.layout(left, mActionBar.getHeight(), right, bottom); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | }; |
| 279 | |
| 280 | @Override |
| 281 | public void onCreate(Bundle data, Bundle restoreState) { |
Bobby Georgescu | 45c56f2 | 2012-08-26 23:47:19 -0700 | [diff] [blame] | 282 | super.onCreate(data, restoreState); |
Ray Chen | 8cab3e8 | 2012-03-20 16:32:57 +0800 | [diff] [blame] | 283 | mActionBar = mActivity.getGalleryActionBar(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 284 | mActionBar.setBackGroundTransparent(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 285 | mSelectionManager = new SelectionManager(mActivity, false); |
| 286 | mMenuExecutor = new MenuExecutor(mActivity, mSelectionManager); |
| 287 | |
| 288 | mPhotoView = new PhotoView(mActivity); |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 289 | mPhotoView.setListener(this); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 290 | mRootPane.addComponent(mPhotoView); |
Angus Kong | 83be4e0 | 2012-08-24 19:30:08 +0800 | [diff] [blame] | 291 | mApplication = (GalleryApp) ((Activity) mActivity).getApplication(); |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 292 | mOrientationManager = mActivity.getOrientationManager(); |
Chih-Chung Chang | 2ef46ed | 2012-05-08 17:57:33 +0800 | [diff] [blame] | 293 | mActivity.getGLRoot().setOrientationSource(mOrientationManager); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 294 | mIsFromVideoScreen = data.getBoolean(KEY_FROM_VIDEOS_SCREEN, false); |
| 295 | mIsFromTimelineScreen = data.getBoolean(KEY_FROM_TIMELINE_SCREEN, false); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 296 | |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 297 | mHandler = new SynchronizedHandler(mActivity.getGLRoot()) { |
| 298 | @Override |
| 299 | public void handleMessage(Message message) { |
| 300 | switch (message.what) { |
| 301 | case MSG_HIDE_BARS: { |
| 302 | hideBars(); |
| 303 | break; |
| 304 | } |
Bobby Georgescu | f44499d | 2012-09-17 18:12:11 -0700 | [diff] [blame] | 305 | case MSG_REFRESH_BOTTOM_CONTROLS: { |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 306 | if (mCurrentPhoto == message.obj && mBottomControls != null) { |
Doris Liu | a680a0c | 2012-10-18 15:01:35 -0700 | [diff] [blame] | 307 | mIsPanorama = message.arg1 == 1; |
| 308 | mIsPanorama360 = message.arg2 == 1; |
| 309 | mBottomControls.refresh(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 310 | if (null != m3DButton) { |
| 311 | m3DButton.refresh(); |
| 312 | } |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 313 | } |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 314 | break; |
| 315 | } |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 316 | case MSG_ON_FULL_SCREEN_CHANGED: { |
Bobby Georgescu | db99a10 | 2012-12-04 23:50:02 -0800 | [diff] [blame] | 317 | if (mAppBridge != null) { |
| 318 | mAppBridge.onFullScreenChanged(message.arg1 == 1); |
| 319 | } |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 320 | break; |
| 321 | } |
| 322 | case MSG_UPDATE_ACTION_BAR: { |
| 323 | updateBars(); |
| 324 | break; |
| 325 | } |
| 326 | case MSG_WANT_BARS: { |
| 327 | wantBars(); |
| 328 | break; |
| 329 | } |
Bobby Georgescu | e23a9d4 | 2012-10-10 10:49:51 -0700 | [diff] [blame] | 330 | case MSG_UPDATE_DEFERRED: { |
| 331 | long nextUpdate = mDeferUpdateUntil - SystemClock.uptimeMillis(); |
| 332 | if (nextUpdate <= 0) { |
| 333 | mDeferredUpdateWaiting = false; |
| 334 | updateUIForCurrentPhoto(); |
| 335 | } else { |
| 336 | mHandler.sendEmptyMessageDelayed(MSG_UPDATE_DEFERRED, nextUpdate); |
| 337 | } |
| 338 | break; |
| 339 | } |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 340 | case MSG_ON_CAMERA_CENTER: { |
| 341 | mSkipUpdateCurrentPhoto = false; |
Bobby Georgescu | bbc9931 | 2012-10-07 13:34:57 -0700 | [diff] [blame] | 342 | boolean stayedOnCamera = false; |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 343 | if (!mPhotoView.getFilmMode()) { |
Bobby Georgescu | bbc9931 | 2012-10-07 13:34:57 -0700 | [diff] [blame] | 344 | stayedOnCamera = true; |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 345 | } else if (SystemClock.uptimeMillis() < mCameraSwitchCutoff && |
| 346 | mMediaSet.getMediaItemCount() > 1) { |
| 347 | mPhotoView.switchToImage(1); |
| 348 | } else { |
Bobby Georgescu | cc6ad82 | 2012-10-22 13:49:35 -0700 | [diff] [blame] | 349 | if (mAppBridge != null) mPhotoView.setFilmMode(false); |
Bobby Georgescu | bbc9931 | 2012-10-07 13:34:57 -0700 | [diff] [blame] | 350 | stayedOnCamera = true; |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Bobby Georgescu | bbc9931 | 2012-10-07 13:34:57 -0700 | [diff] [blame] | 353 | if (stayedOnCamera) { |
Bobby Georgescu | 617551e | 2013-01-07 11:25:46 -0800 | [diff] [blame] | 354 | if (mAppBridge == null && mMediaSet.getTotalMediaItemCount() > 1) { |
Bobby Georgescu | 5bd0033 | 2012-10-24 12:09:38 -0700 | [diff] [blame] | 355 | launchCamera(); |
Bobby Georgescu | cc6ad82 | 2012-10-22 13:49:35 -0700 | [diff] [blame] | 356 | /* We got here by swiping from photo 1 to the |
| 357 | placeholder, so make it be the thing that |
| 358 | is in focus when the user presses back from |
| 359 | the camera app */ |
| 360 | mPhotoView.switchToImage(1); |
| 361 | } else { |
| 362 | updateBars(); |
| 363 | updateCurrentPhoto(mModel.getMediaItem(0)); |
| 364 | } |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 365 | } |
| 366 | break; |
| 367 | } |
Bobby Georgescu | f4e22eb | 2012-10-02 18:34:08 -0700 | [diff] [blame] | 368 | case MSG_ON_PICTURE_CENTER: { |
Bobby Georgescu | e23a9d4 | 2012-10-10 10:49:51 -0700 | [diff] [blame] | 369 | if (!mPhotoView.getFilmMode() && mCurrentPhoto != null |
Bobby Georgescu | f4e22eb | 2012-10-02 18:34:08 -0700 | [diff] [blame] | 370 | && (mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0) { |
| 371 | mPhotoView.setFilmMode(true); |
| 372 | } |
| 373 | break; |
| 374 | } |
George Mount | f122d56 | 2012-10-09 17:50:33 -0700 | [diff] [blame] | 375 | case MSG_REFRESH_IMAGE: { |
Mangesh Ghiware | 423e45e | 2012-10-11 23:11:27 -0700 | [diff] [blame] | 376 | final MediaItem photo = mCurrentPhoto; |
| 377 | mCurrentPhoto = null; |
| 378 | updateCurrentPhoto(photo); |
| 379 | break; |
| 380 | } |
| 381 | case MSG_UPDATE_PHOTO_UI: { |
Mangesh Ghiware | 825afb1 | 2012-10-10 18:37:24 -0700 | [diff] [blame] | 382 | updateUIForCurrentPhoto(); |
| 383 | break; |
| 384 | } |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 385 | case MSG_UPDATE_SHARE_URI: { |
| 386 | if (mCurrentPhoto == message.obj) { |
| 387 | boolean isPanorama360 = message.arg1 != 0; |
| 388 | Uri contentUri = mCurrentPhoto.getContentUri(); |
| 389 | Intent panoramaIntent = null; |
| 390 | if (isPanorama360) { |
| 391 | panoramaIntent = createSharePanoramaIntent(contentUri); |
| 392 | } |
| 393 | Intent shareIntent = createShareIntent(mCurrentPhoto); |
Paramananda Pradhan | 9382a97 | 2014-12-14 17:27:31 +0530 | [diff] [blame] | 394 | if (shareIntent != null) { |
maxwen | d57f723 | 2016-06-04 22:51:06 +0200 | [diff] [blame] | 395 | mActionBar.setShareIntents(panoramaIntent, shareIntent); |
Paramananda Pradhan | 9382a97 | 2014-12-14 17:27:31 +0530 | [diff] [blame] | 396 | } |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 397 | setNfcBeamPushUri(contentUri); |
| 398 | } |
| 399 | break; |
| 400 | } |
| 401 | case MSG_UPDATE_PANORAMA_UI: { |
| 402 | if (mCurrentPhoto == message.obj) { |
| 403 | boolean isPanorama360 = message.arg1 != 0; |
| 404 | updatePanoramaUI(isPanorama360); |
| 405 | } |
| 406 | break; |
| 407 | } |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 408 | default: throw new AssertionError(message.what); |
| 409 | } |
| 410 | } |
| 411 | }; |
| 412 | |
Ray Chen | 84c220f | 2012-03-06 17:24:28 +0800 | [diff] [blame] | 413 | mSetPathString = data.getString(KEY_MEDIA_SET_PATH); |
John Hoford | 463b918 | 2013-09-16 15:51:02 -0700 | [diff] [blame] | 414 | mReadOnlyView = data.getBoolean(KEY_READONLY); |
Chih-Chung Chang | b1e9fd8 | 2012-04-30 17:33:21 +0800 | [diff] [blame] | 415 | mOriginalSetPathString = mSetPathString; |
John Reck | ddf0225 | 2012-09-26 11:37:23 -0700 | [diff] [blame] | 416 | setupNfcBeamPush(); |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 417 | String itemPathString = data.getString(KEY_MEDIA_ITEM_PATH); |
| 418 | Path itemPath = itemPathString != null ? |
| 419 | Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) : |
| 420 | null; |
Yuli Huang | 54fe620 | 2012-05-23 16:06:32 +0800 | [diff] [blame] | 421 | mTreatBackAsUp = data.getBoolean(KEY_TREAT_BACK_AS_UP, false); |
kaiyiz | ed2687a | 2014-10-15 10:10:13 +0800 | [diff] [blame] | 422 | mIsFromWidget = data.getBoolean(KEY_IS_FROM_WIDGET, false); |
Bobby Georgescu | 45f089d | 2012-10-02 13:30:09 -0700 | [diff] [blame] | 423 | mStartInFilmstrip = data.getBoolean(KEY_START_IN_FILMSTRIP, false); |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 424 | boolean inCameraRoll = data.getBoolean(KEY_IN_CAMERA_ROLL, false); |
huiyan | e0e8256 | 2016-04-28 14:19:11 +0800 | [diff] [blame] | 425 | if (restoreState == null || mSetPathString == null) { |
| 426 | mCurrentIndex = data.getInt(KEY_INDEX_HINT, 0); |
| 427 | } else { |
| 428 | mCurrentIndex = restoreState.getInt(KEY_INDEX_HINT, 0); |
| 429 | //we only save index in onSaveState, set itemPath to null to get the right path later |
| 430 | itemPath = null; |
| 431 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 432 | if ((mCurrentPhoto == null) && (restoreState != null)) { |
| 433 | String curPath = restoreState.getString(KEY_CURRENT_PHOTO_HINT, null); |
| 434 | if (curPath != null) |
| 435 | mCurrentPhoto = (MediaItem) |
| 436 | mActivity.getDataManager().getMediaObject(curPath); |
| 437 | } |
Ray Chen | 84c220f | 2012-03-06 17:24:28 +0800 | [diff] [blame] | 438 | if (mSetPathString != null) { |
Bobby Georgescu | ba65c37 | 2012-10-06 01:06:43 -0700 | [diff] [blame] | 439 | mShowSpinner = true; |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 440 | mAppBridge = (AppBridge) data.getParcelable(KEY_APP_BRIDGE); |
| 441 | if (mAppBridge != null) { |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 442 | mShowBars = false; |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 443 | mHasCameraScreennailOrPlaceholder = true; |
Chih-Chung Chang | 253c5ae | 2012-05-16 17:37:10 -0700 | [diff] [blame] | 444 | mAppBridge.setServer(this); |
Chih-Chung Chang | 15b351a | 2012-03-15 16:38:45 +0800 | [diff] [blame] | 445 | |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 446 | // Get the ScreenNail from AppBridge and register it. |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 447 | int id = SnailSource.newId(); |
Chih-Chung Chang | b29a27f | 2012-03-22 17:42:33 +0800 | [diff] [blame] | 448 | Path screenNailSetPath = SnailSource.getSetPath(id); |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 449 | Path screenNailItemPath = SnailSource.getItemPath(id); |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 450 | mScreenNailSet = (SnailAlbum) mActivity.getDataManager() |
| 451 | .getMediaObject(screenNailSetPath); |
| 452 | mScreenNailItem = (SnailItem) mActivity.getDataManager() |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 453 | .getMediaObject(screenNailItemPath); |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 454 | mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail()); |
Chih-Chung Chang | b29a27f | 2012-03-22 17:42:33 +0800 | [diff] [blame] | 455 | |
Wu-cheng Li | 23e595f | 2012-09-21 14:36:21 +0800 | [diff] [blame] | 456 | if (data.getBoolean(KEY_SHOW_WHEN_LOCKED, false)) { |
Wu-cheng Li | efd480e | 2012-08-30 16:44:32 +0800 | [diff] [blame] | 457 | // Set the flag to be on top of the lock screen. |
| 458 | mFlags |= FLAG_SHOW_WHEN_LOCKED; |
Wu-cheng Li | a0ce682 | 2012-08-22 19:15:35 +0800 | [diff] [blame] | 459 | } |
| 460 | |
George Mount | 4e091eb | 2012-10-09 21:02:42 -0700 | [diff] [blame] | 461 | // Don't display "empty album" action item for capture intents. |
Wu-cheng Li | 2c83c5f | 2012-10-09 14:44:31 +0800 | [diff] [blame] | 462 | if (!mSetPathString.equals("/local/all/0")) { |
| 463 | // Check if the path is a secure album. |
| 464 | if (SecureSource.isSecurePath(mSetPathString)) { |
| 465 | mSecureAlbum = (SecureAlbum) mActivity.getDataManager() |
| 466 | .getMediaSet(mSetPathString); |
| 467 | mShowSpinner = false; |
Wu-cheng Li | 2c83c5f | 2012-10-09 14:44:31 +0800 | [diff] [blame] | 468 | } |
Bobby Georgescu | c7e3c76 | 2012-09-27 16:36:03 -0700 | [diff] [blame] | 469 | mSetPathString = "/filter/empty/{"+mSetPathString+"}"; |
| 470 | } |
| 471 | |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 472 | // Combine the original MediaSet with the one for ScreenNail |
| 473 | // from AppBridge. |
Chih-Chung Chang | b29a27f | 2012-03-22 17:42:33 +0800 | [diff] [blame] | 474 | mSetPathString = "/combo/item/{" + screenNailSetPath + |
| 475 | "," + mSetPathString + "}"; |
| 476 | |
| 477 | // Start from the screen nail. |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 478 | itemPath = screenNailItemPath; |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 479 | } else if (inCameraRoll && GalleryUtils.isCameraAvailable(mActivity)) { |
Bobby Georgescu | 45f089d | 2012-10-02 13:30:09 -0700 | [diff] [blame] | 480 | mSetPathString = "/combo/item/{" + FilterSource.FILTER_CAMERA_SHORTCUT + |
| 481 | "," + mSetPathString + "}"; |
| 482 | mCurrentIndex++; |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 483 | mHasCameraScreennailOrPlaceholder = true; |
Chih-Chung Chang | b29a27f | 2012-03-22 17:42:33 +0800 | [diff] [blame] | 484 | } |
| 485 | |
Chih-Chung Chang | 6118af9 | 2012-06-22 20:56:04 +0800 | [diff] [blame] | 486 | MediaSet originalSet = mActivity.getDataManager() |
| 487 | .getMediaSet(mSetPathString); |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 488 | if (mHasCameraScreennailOrPlaceholder && originalSet instanceof ComboAlbum) { |
Bobby Georgescu | ee899c0 | 2012-10-01 17:49:30 -0700 | [diff] [blame] | 489 | // Use the name of the camera album rather than the default |
| 490 | // ComboAlbum behavior |
| 491 | ((ComboAlbum) originalSet).useNameOfChild(1); |
| 492 | } |
Chih-Chung Chang | 6118af9 | 2012-06-22 20:56:04 +0800 | [diff] [blame] | 493 | mSelectionManager.setSourceMediaSet(originalSet); |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 494 | mSetPathString = "/filter/delete/{" + mSetPathString + "}"; |
| 495 | mMediaSet = (FilterDeleteSet) mActivity.getDataManager() |
| 496 | .getMediaSet(mSetPathString); |
huiyan | e9fa3d6 | 2016-04-13 12:48:07 +0800 | [diff] [blame] | 497 | if (mMediaSet != null && mIsFromTimelineScreen) { |
Kedi Xu | fece30c | 2016-10-21 15:13:32 +0800 | [diff] [blame] | 498 | mMediaSet.setShowAlbumsetTimeTitle(false); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 499 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 500 | if (mMediaSet == null) { |
Ray Chen | 84c220f | 2012-03-06 17:24:28 +0800 | [diff] [blame] | 501 | Log.w(TAG, "failed to restore " + mSetPathString); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 502 | } |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 503 | if (itemPath == null) { |
Bobby Georgescu | 3eb2e64 | 2012-09-24 11:26:10 -0700 | [diff] [blame] | 504 | int mediaItemCount = mMediaSet.getMediaItemCount(); |
| 505 | if (mediaItemCount > 0) { |
| 506 | if (mCurrentIndex >= mediaItemCount) mCurrentIndex = 0; |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 507 | itemPath = mMediaSet.getMediaItem(mCurrentIndex, 1) |
| 508 | .get(0).getPath(); |
| 509 | } else { |
Bobby Georgescu | 3eb2e64 | 2012-09-24 11:26:10 -0700 | [diff] [blame] | 510 | // Bail out, PhotoPage can't load on an empty album |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 511 | return; |
| 512 | } |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 513 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 514 | PhotoDataAdapter pda = new PhotoDataAdapter( |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 515 | mActivity, mPhotoView, mMediaSet, itemPath, mCurrentIndex, |
Angus Kong | 43a80fd | 2012-05-17 12:47:26 -0700 | [diff] [blame] | 516 | mAppBridge == null ? -1 : 0, |
Wu-cheng Li | dbb6acc | 2012-08-19 17:04:02 +0800 | [diff] [blame] | 517 | mAppBridge == null ? false : mAppBridge.isPanorama(), |
Kedi Xu | 93a9182 | 2016-09-14 11:30:29 +0800 | [diff] [blame] | 518 | mAppBridge == null ? false : mAppBridge.isStaticCamera()); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 519 | mModel = pda; |
| 520 | mPhotoView.setModel(mModel); |
| 521 | |
kaiyiz | ed2687a | 2014-10-15 10:10:13 +0800 | [diff] [blame] | 522 | // If RTL and from widget, set the flag into PhotoDataAdapter. |
| 523 | if (View.LAYOUT_DIRECTION_RTL == TextUtils |
| 524 | .getLayoutDirectionFromLocale(Locale.getDefault()) |
| 525 | && mIsFromWidget) { |
| 526 | pda.setFromWidget(mIsFromWidget); |
| 527 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 528 | pda.setDataListener(new PhotoDataAdapter.DataListener() { |
| 529 | |
Owen Lin | 113bfc7 | 2011-08-30 10:38:59 +0800 | [diff] [blame] | 530 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 531 | public void onPhotoChanged(int index, Path item) { |
Bobby Georgescu | 00ccf35 | 2012-09-19 16:51:05 -0700 | [diff] [blame] | 532 | int oldIndex = mCurrentIndex; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 533 | mCurrentIndex = index; |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 534 | |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 535 | if (mHasCameraScreennailOrPlaceholder) { |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 536 | if (mCurrentIndex > 0) { |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 537 | mSkipUpdateCurrentPhoto = false; |
| 538 | } |
| 539 | |
Bobby Georgescu | 00ccf35 | 2012-09-19 16:51:05 -0700 | [diff] [blame] | 540 | if (oldIndex == 0 && mCurrentIndex > 0 |
| 541 | && !mPhotoView.getFilmMode()) { |
| 542 | mPhotoView.setFilmMode(true); |
Bobby Georgescu | 9b4c3e9 | 2013-03-13 09:45:18 -0700 | [diff] [blame] | 543 | if (mAppBridge != null) { |
| 544 | UsageStatistics.onEvent("CameraToFilmstrip", |
| 545 | UsageStatistics.TRANSITION_SWIPE, null); |
| 546 | } |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 547 | } else if (oldIndex == 2 && mCurrentIndex == 1) { |
| 548 | mCameraSwitchCutoff = SystemClock.uptimeMillis() + |
| 549 | CAMERA_SWITCH_CUTOFF_THRESHOLD_MS; |
| 550 | mPhotoView.stopScrolling(); |
Bobby Georgescu | bbc9931 | 2012-10-07 13:34:57 -0700 | [diff] [blame] | 551 | } else if (oldIndex >= 1 && mCurrentIndex == 0) { |
Bobby Georgescu | f4e22eb | 2012-10-02 18:34:08 -0700 | [diff] [blame] | 552 | mPhotoView.setWantPictureCenterCallbacks(true); |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 553 | mSkipUpdateCurrentPhoto = true; |
Bobby Georgescu | 00ccf35 | 2012-09-19 16:51:05 -0700 | [diff] [blame] | 554 | } |
| 555 | } |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 556 | if (!mSkipUpdateCurrentPhoto) { |
| 557 | if (item != null) { |
| 558 | MediaItem photo = mModel.getMediaItem(0); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 559 | if (photo != null) { |
| 560 | mActionBar.setTitle(photo.getName()); |
| 561 | updateCurrentPhoto(photo); |
| 562 | } |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 563 | } |
| 564 | updateBars(); |
| 565 | } |
Bobby Georgescu | 00ccf35 | 2012-09-19 16:51:05 -0700 | [diff] [blame] | 566 | // Reset the timeout for the bars after a swipe |
| 567 | refreshHidingMessage(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | @Override |
Hung-ying Tyan | 05da3f5 | 2012-10-30 17:47:35 +0800 | [diff] [blame] | 571 | public void onLoadingFinished(boolean loadingFailed) { |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 572 | if (!mModel.isEmpty()) { |
Owen Lin | 616a70f | 2012-05-07 16:35:53 +0800 | [diff] [blame] | 573 | MediaItem photo = mModel.getMediaItem(0); |
lihai | 556b0f6 | 2015-09-11 16:39:15 +0800 | [diff] [blame] | 574 | if (photo != null) { |
| 575 | updateCurrentPhoto(photo); |
| 576 | } else { |
| 577 | mModel.resume(); |
| 578 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 579 | } else if (mIsActive) { |
Chih-Chung Chang | c370476 | 2012-06-27 13:40:06 +0800 | [diff] [blame] | 580 | // We only want to finish the PhotoPage if there is no |
| 581 | // deletion that the user can undo. |
| 582 | if (mMediaSet.getNumberOfDeletions() == 0) { |
huiyan | e9fa3d6 | 2016-04-13 12:48:07 +0800 | [diff] [blame] | 583 | onBackPressed(); |
Chih-Chung Chang | c370476 | 2012-06-27 13:40:06 +0800 | [diff] [blame] | 584 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 588 | @Override |
| 589 | public void onLoadingStarted() { |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 590 | } |
| 591 | }); |
| 592 | } else { |
| 593 | // Get default media set by the URI |
| 594 | MediaItem mediaItem = (MediaItem) |
| 595 | mActivity.getDataManager().getMediaObject(itemPath); |
| 596 | mModel = new SinglePhotoDataAdapter(mActivity, mPhotoView, mediaItem); |
| 597 | mPhotoView.setModel(mModel); |
| 598 | updateCurrentPhoto(mediaItem); |
Bobby Georgescu | ba65c37 | 2012-10-06 01:06:43 -0700 | [diff] [blame] | 599 | mShowSpinner = false; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 600 | } |
Ray Chen | cf46a3a | 2011-09-14 16:46:32 +0800 | [diff] [blame] | 601 | |
Bobby Georgescu | b265ebb | 2012-09-12 16:37:53 -0700 | [diff] [blame] | 602 | mPhotoView.setFilmMode(mStartInFilmstrip && mMediaSet.getMediaItemCount() > 1); |
George Mount | f122d56 | 2012-10-09 17:50:33 -0700 | [diff] [blame] | 603 | RelativeLayout galleryRoot = (RelativeLayout) ((Activity) mActivity) |
| 604 | .findViewById(mAppBridge != null ? R.id.content : R.id.gallery_root); |
| 605 | if (galleryRoot != null) { |
| 606 | if (mSecureAlbum == null) { |
Bobby Georgescu | f44499d | 2012-09-17 18:12:11 -0700 | [diff] [blame] | 607 | mBottomControls = new PhotoPageBottomControls(this, mActivity, galleryRoot); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 608 | m3DButton = new ThreeDButton(this, mActivity, galleryRoot); |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 609 | } |
Bobby Georgescu | f44499d | 2012-09-17 18:12:11 -0700 | [diff] [blame] | 610 | } |
ztenghui | 02f459f | 2013-08-30 16:34:23 -0700 | [diff] [blame] | 611 | |
| 612 | ((GLRootView) mActivity.getGLRoot()).setOnSystemUiVisibilityChangeListener( |
| 613 | new View.OnSystemUiVisibilityChangeListener() { |
| 614 | @Override |
| 615 | public void onSystemUiVisibilityChange(int visibility) { |
| 616 | int diff = mLastSystemUiVis ^ visibility; |
| 617 | mLastSystemUiVis = visibility; |
| 618 | if ((diff & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0 |
| 619 | && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { |
| 620 | showBars(); |
| 621 | } |
| 622 | } |
| 623 | }); |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Sascha Haeberling | e3b50f1 | 2012-10-15 18:28:42 -0700 | [diff] [blame] | 626 | @Override |
huiyan | e0e8256 | 2016-04-28 14:19:11 +0800 | [diff] [blame] | 627 | protected void onSaveState(Bundle outState) { |
jinwu | 80a22b3 | 2017-05-16 20:10:30 +0800 | [diff] [blame] | 628 | if (mCurrentPhoto != null) { |
| 629 | outState.putInt(KEY_INDEX_HINT,mCurrentIndex); |
| 630 | outState.putString(KEY_CURRENT_PHOTO_HINT, mCurrentPhoto.getFilePath()); |
| 631 | super.onSaveState(outState); |
| 632 | } else { |
| 633 | onBackPressed(); |
| 634 | } |
huiyan | e0e8256 | 2016-04-28 14:19:11 +0800 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | @Override |
Bobby Georgescu | f4e22eb | 2012-10-02 18:34:08 -0700 | [diff] [blame] | 638 | public void onPictureCenter(boolean isCamera) { |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 639 | isCamera = isCamera || (mHasCameraScreennailOrPlaceholder && mAppBridge == null); |
Bobby Georgescu | f4e22eb | 2012-10-02 18:34:08 -0700 | [diff] [blame] | 640 | mPhotoView.setWantPictureCenterCallbacks(false); |
| 641 | mHandler.removeMessages(MSG_ON_CAMERA_CENTER); |
| 642 | mHandler.removeMessages(MSG_ON_PICTURE_CENTER); |
| 643 | mHandler.sendEmptyMessage(isCamera ? MSG_ON_CAMERA_CENTER : MSG_ON_PICTURE_CENTER); |
Bobby Georgescu | b27df46 | 2012-09-27 23:55:44 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Sascha Haeberling | e3b50f1 | 2012-10-15 18:28:42 -0700 | [diff] [blame] | 646 | @Override |
Bobby Georgescu | f44499d | 2012-09-17 18:12:11 -0700 | [diff] [blame] | 647 | public boolean canDisplayBottomControls() { |
Bobby Georgescu | 9495843 | 2012-10-23 20:52:26 -0700 | [diff] [blame] | 648 | return mIsActive && !mPhotoView.canUndo(); |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Sascha Haeberling | e3b50f1 | 2012-10-15 18:28:42 -0700 | [diff] [blame] | 651 | @Override |
Doris Liu | a680a0c | 2012-10-18 15:01:35 -0700 | [diff] [blame] | 652 | public boolean canDisplayBottomControl(int control) { |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 653 | if (mCurrentPhoto == null) { |
| 654 | return false; |
| 655 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 656 | switch (control) { |
| 657 | case R.id.photopage_bottom_controls: |
| 658 | return mShowBars; |
| 659 | case R.id.photopage_bottom_control_edit: |
| 660 | return mHaveImageEditor |
| 661 | && mShowBars |
| 662 | && !mReadOnlyView |
| 663 | && !mPhotoView.getFilmMode() |
| 664 | && (mCurrentPhoto.getSupportedOperations() & MediaItem.SUPPORT_EDIT) != 0 |
| 665 | && mCurrentPhoto.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 666 | case R.id.photopage_bottom_control_share: |
| 667 | mShareIntent = new Intent(Intent.ACTION_SEND); |
| 668 | return mShowBars; |
| 669 | case R.id.photopage_bottom_control_delete: |
yongga | 2a611a4 | 2016-01-14 17:45:13 +0800 | [diff] [blame] | 670 | return mShowBars && !mReadOnlyView; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 671 | default: |
| 672 | return false; |
Bobby Georgescu | f44499d | 2012-09-17 18:12:11 -0700 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
Sascha Haeberling | e3b50f1 | 2012-10-15 18:28:42 -0700 | [diff] [blame] | 676 | @Override |
Bobby Georgescu | f44499d | 2012-09-17 18:12:11 -0700 | [diff] [blame] | 677 | public void onBottomControlClicked(int control) { |
| 678 | switch(control) { |
| 679 | case R.id.photopage_bottom_control_edit: |
| 680 | launchPhotoEditor(); |
| 681 | return; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 682 | case R.id.photopage_bottom_control_share: |
| 683 | if (mModel != null && mModel.getMediaItem(0) != null) { |
Abhishek Panjikar | 9775cc3 | 2015-11-06 17:30:50 +0530 | [diff] [blame] | 684 | Uri uri = mActivity.getDataManager().getContentUri(mModel.getMediaItem(0).getPath()); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 685 | mActivity.isTopMenuShow = true; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 686 | mShareIntent.setType(MenuExecutor.getMimeType(mModel |
| 687 | .getMediaItem(0).getMediaType())); |
| 688 | mShareIntent.putExtra(Intent.EXTRA_STREAM, uri); |
c_yongga | 81d10a1 | 2016-01-27 13:29:33 +0800 | [diff] [blame] | 689 | String shareTitle = mActivity.getResources(). |
| 690 | getString(R.string.share_dialogue_title); |
zhuw | 5834703 | 2018-09-20 14:00:43 +0800 | [diff] [blame] | 691 | if (uri.toString().contains("file:")) { |
| 692 | Log.d(TAG, "can't share uri started with file://"); |
| 693 | return; |
| 694 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 695 | mActivity.startActivity(Intent.createChooser(mShareIntent, |
c_yongga | 81d10a1 | 2016-01-27 13:29:33 +0800 | [diff] [blame] | 696 | shareTitle)); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 697 | } |
| 698 | return; |
| 699 | |
| 700 | case R.id.photopage_bottom_control_delete: |
| 701 | String confirmMsg = null; |
| 702 | confirmMsg = mActivity.getResources().getQuantityString( |
| 703 | R.plurals.delete_selection, 1); |
| 704 | if (mModel != null && mModel.getMediaItem(0) != null) { |
| 705 | Path path = mModel.getMediaItem(0).getPath(); |
| 706 | mSelectionManager.deSelectAll(); |
| 707 | mSelectionManager.toggle(path); |
| 708 | MenuItem item = null; |
| 709 | mMenuExecutor.onMenuClicked(item, confirmMsg, |
| 710 | mConfirmDialogListener); |
| 711 | } |
Bobby Georgescu | f44499d | 2012-09-17 18:12:11 -0700 | [diff] [blame] | 712 | return; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 713 | default: |
| 714 | return; |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 715 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 716 | } |
| 717 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 718 | @Override |
| 719 | public boolean canDisplay3DButton() { |
| 720 | return bShow3DButton && mShowBars |
| 721 | && (mPhotoView == null ? false : !mPhotoView.getFilmMode()); |
| 722 | } |
| 723 | |
| 724 | @Override |
| 725 | public void on3DButtonClicked() { |
| 726 | if (mCurrentPhoto != null) { |
| 727 | Path p = mCurrentPhoto.getPath(); |
| 728 | Uri uri = mActivity.getDataManager().getContentUri(p); |
| 729 | Intent intent = new Intent(); |
| 730 | intent.setClass(mActivity, ThreeDimensionalActivity.class); |
| 731 | intent.setData(uri); |
| 732 | mActivity.startActivity(intent); |
| 733 | } |
| 734 | } |
| 735 | |
Chih-Chung Chang | 6772173 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 736 | @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN) |
John Reck | ddf0225 | 2012-09-26 11:37:23 -0700 | [diff] [blame] | 737 | private void setupNfcBeamPush() { |
| 738 | if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) return; |
| 739 | |
huiyan | 73c16da | 2016-03-24 11:39:23 +0800 | [diff] [blame] | 740 | try { |
| 741 | NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mActivity); |
| 742 | if (adapter != null) { |
| 743 | adapter.setBeamPushUris(null, mActivity); |
| 744 | adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() { |
| 745 | @Override |
| 746 | public Uri[] createBeamUris(NfcEvent event) { |
| 747 | return mNfcPushUris; |
| 748 | } |
| 749 | }, mActivity); |
| 750 | } |
| 751 | } catch (NullPointerException e) { |
| 752 | e.printStackTrace(); |
| 753 | } catch (Exception e) { |
| 754 | e.printStackTrace(); |
Yuli Huang | fc86994 | 2012-06-29 18:59:17 +0800 | [diff] [blame] | 755 | } |
| 756 | } |
| 757 | |
John Reck | ddf0225 | 2012-09-26 11:37:23 -0700 | [diff] [blame] | 758 | private void setNfcBeamPushUri(Uri uri) { |
| 759 | mNfcPushUris[0] = uri; |
| 760 | } |
| 761 | |
Paramananda Pradhan | 9382a97 | 2014-12-14 17:27:31 +0530 | [diff] [blame] | 762 | private Intent createShareIntent(MediaObject mediaObject) { |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 763 | int type = mediaObject.getMediaType(); |
Owen Lin | ca181a6 | 2012-10-16 10:22:54 +0800 | [diff] [blame] | 764 | return new Intent(Intent.ACTION_SEND) |
| 765 | .setType(MenuExecutor.getMimeType(type)) |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 766 | .putExtra(Intent.EXTRA_STREAM, mediaObject.getContentUri()) |
Owen Lin | ca181a6 | 2012-10-16 10:22:54 +0800 | [diff] [blame] | 767 | .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Mangesh Ghiware | 5172dee | 2012-09-27 21:05:41 -0700 | [diff] [blame] | 768 | } |
Owen Lin | 2bb717f | 2012-07-13 17:23:05 +0800 | [diff] [blame] | 769 | |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 770 | private static Intent createSharePanoramaIntent(Uri contentUri) { |
Owen Lin | ca181a6 | 2012-10-16 10:22:54 +0800 | [diff] [blame] | 771 | return new Intent(Intent.ACTION_SEND) |
| 772 | .setType(GalleryUtils.MIME_TYPE_PANORAMA360) |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 773 | .putExtra(Intent.EXTRA_STREAM, contentUri) |
Owen Lin | ca181a6 | 2012-10-16 10:22:54 +0800 | [diff] [blame] | 774 | .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Wu-cheng Li | fb55719 | 2012-07-19 17:11:06 +0800 | [diff] [blame] | 775 | } |
| 776 | |
Bobby Georgescu | 48129f3 | 2012-10-22 11:13:34 -0700 | [diff] [blame] | 777 | private void overrideTransitionToEditor() { |
Bobby Georgescu | 2db8b14 | 2013-02-08 13:53:17 -0800 | [diff] [blame] | 778 | ((Activity) mActivity).overridePendingTransition(android.R.anim.fade_in, |
Bobby Georgescu | 48129f3 | 2012-10-22 11:13:34 -0700 | [diff] [blame] | 779 | android.R.anim.fade_out); |
| 780 | } |
| 781 | |
Doris Liu | a680a0c | 2012-10-18 15:01:35 -0700 | [diff] [blame] | 782 | private void launchTinyPlanet() { |
| 783 | // Deep link into tiny planet |
| 784 | MediaItem current = mModel.getMediaItem(0); |
| 785 | Intent intent = new Intent(FilterShowActivity.TINY_PLANET_ACTION); |
| 786 | intent.setClass(mActivity, FilterShowActivity.class); |
| 787 | intent.setDataAndType(current.getContentUri(), current.getMimeType()) |
| 788 | .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Bobby Georgescu | a850a54 | 2012-10-23 15:40:06 -0700 | [diff] [blame] | 789 | intent.putExtra(FilterShowActivity.LAUNCH_FULLSCREEN, |
| 790 | mActivity.isFullscreen()); |
Doris Liu | a680a0c | 2012-10-18 15:01:35 -0700 | [diff] [blame] | 791 | mActivity.startActivityForResult(intent, REQUEST_EDIT); |
Bobby Georgescu | 48129f3 | 2012-10-22 11:13:34 -0700 | [diff] [blame] | 792 | overrideTransitionToEditor(); |
Doris Liu | a680a0c | 2012-10-18 15:01:35 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Bobby Georgescu | 5bd0033 | 2012-10-24 12:09:38 -0700 | [diff] [blame] | 795 | private void launchCamera() { |
Mangesh Ghiware | 55705d5 | 2013-08-19 11:52:32 -0700 | [diff] [blame] | 796 | mRecenterCameraOnResume = false; |
| 797 | GalleryUtils.startCameraActivity(mActivity); |
Bobby Georgescu | 5bd0033 | 2012-10-24 12:09:38 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 800 | private void launchPhotoEditor() { |
| 801 | MediaItem current = mModel.getMediaItem(0); |
Bobby Georgescu | 462923e | 2012-10-02 10:30:07 -0700 | [diff] [blame] | 802 | if (current == null || (current.getSupportedOperations() |
| 803 | & MediaObject.SUPPORT_EDIT) == 0) { |
| 804 | return; |
| 805 | } |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 806 | |
| 807 | Intent intent = new Intent(ACTION_NEXTGEN_EDIT); |
Owen Lin | b669265 | 2012-10-04 11:26:30 +0800 | [diff] [blame] | 808 | |
| 809 | intent.setDataAndType(current.getContentUri(), current.getMimeType()) |
| 810 | .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 811 | if (mActivity.getPackageManager() |
| 812 | .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() == 0) { |
| 813 | intent.setAction(Intent.ACTION_EDIT); |
| 814 | } |
Bobby Georgescu | a850a54 | 2012-10-23 15:40:06 -0700 | [diff] [blame] | 815 | intent.putExtra(FilterShowActivity.LAUNCH_FULLSCREEN, |
| 816 | mActivity.isFullscreen()); |
Chao Zhang | 8724b7e | 2016-05-12 17:34:31 +0800 | [diff] [blame] | 817 | |
| 818 | List<ResolveInfo> resolveInfoList = mActivity.getPackageManager() |
| 819 | .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); |
| 820 | if (resolveInfoList != null && resolveInfoList.size() > 0) { |
| 821 | if (resolveInfoList.size() == 1) { |
| 822 | // only one app can resolve intent, don't use createChooser. |
| 823 | mActivity.startActivityForResult(intent, REQUEST_EDIT); |
| 824 | } else { |
| 825 | mActivity.startActivityForResult(Intent.createChooser(intent, null), REQUEST_EDIT); |
| 826 | } |
| 827 | overrideTransitionToEditor(); |
| 828 | } |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 829 | } |
| 830 | |
nicolasroard | 8c4e95f | 2013-04-08 18:16:17 -0700 | [diff] [blame] | 831 | private void launchSimpleEditor() { |
| 832 | MediaItem current = mModel.getMediaItem(0); |
| 833 | if (current == null || (current.getSupportedOperations() |
| 834 | & MediaObject.SUPPORT_EDIT) == 0) { |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | Intent intent = new Intent(ACTION_SIMPLE_EDIT); |
| 839 | |
| 840 | intent.setDataAndType(current.getContentUri(), current.getMimeType()) |
| 841 | .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| 842 | if (mActivity.getPackageManager() |
| 843 | .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() == 0) { |
| 844 | intent.setAction(Intent.ACTION_EDIT); |
| 845 | } |
| 846 | intent.putExtra(FilterShowActivity.LAUNCH_FULLSCREEN, |
| 847 | mActivity.isFullscreen()); |
| 848 | ((Activity) mActivity).startActivityForResult(Intent.createChooser(intent, null), |
| 849 | REQUEST_EDIT); |
| 850 | overrideTransitionToEditor(); |
| 851 | } |
| 852 | |
Bobby Georgescu | e23a9d4 | 2012-10-10 10:49:51 -0700 | [diff] [blame] | 853 | private void requestDeferredUpdate() { |
| 854 | mDeferUpdateUntil = SystemClock.uptimeMillis() + DEFERRED_UPDATE_MS; |
| 855 | if (!mDeferredUpdateWaiting) { |
| 856 | mDeferredUpdateWaiting = true; |
| 857 | mHandler.sendEmptyMessageDelayed(MSG_UPDATE_DEFERRED, DEFERRED_UPDATE_MS); |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | private void updateUIForCurrentPhoto() { |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 862 | if (mCurrentPhoto == null) return; |
Bobby Georgescu | c7e3c76 | 2012-09-27 16:36:03 -0700 | [diff] [blame] | 863 | |
| 864 | // If by swiping or deletion the user ends up on an action item |
| 865 | // and zoomed in, zoom out so that the context of the action is |
| 866 | // more clear |
Bobby Georgescu | e23a9d4 | 2012-10-10 10:49:51 -0700 | [diff] [blame] | 867 | if ((mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_ACTION) != 0 |
Bobby Georgescu | c7e3c76 | 2012-09-27 16:36:03 -0700 | [diff] [blame] | 868 | && !mPhotoView.getFilmMode()) { |
Bobby Georgescu | f4e22eb | 2012-10-02 18:34:08 -0700 | [diff] [blame] | 869 | mPhotoView.setWantPictureCenterCallbacks(true); |
Bobby Georgescu | c7e3c76 | 2012-09-27 16:36:03 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 872 | updateMenuOperations(); |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 873 | refreshBottomControlsWhenReady(); |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 874 | parseGDepth(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 875 | if (mShowDetails) { |
Michael Kolb | 995c456 | 2012-07-20 12:23:09 -0700 | [diff] [blame] | 876 | mDetailsHelper.reloadDetails(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 877 | } |
Wu-cheng Li | 898a2f4 | 2012-08-27 00:10:38 +0800 | [diff] [blame] | 878 | if ((mSecureAlbum == null) |
Bobby Georgescu | e23a9d4 | 2012-10-10 10:49:51 -0700 | [diff] [blame] | 879 | && (mCurrentPhoto.getSupportedOperations() & MediaItem.SUPPORT_SHARE) != 0) { |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 880 | mCurrentPhoto.getPanoramaSupport(mUpdateShareURICallback); |
Bobby Georgescu | e23a9d4 | 2012-10-10 10:49:51 -0700 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | |
| 884 | private void updateCurrentPhoto(MediaItem photo) { |
| 885 | if (mCurrentPhoto == photo) return; |
| 886 | mCurrentPhoto = photo; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 887 | if (mPhotoView == null) { |
| 888 | return; |
| 889 | } |
Bobby Georgescu | e23a9d4 | 2012-10-10 10:49:51 -0700 | [diff] [blame] | 890 | if (mPhotoView.getFilmMode()) { |
| 891 | requestDeferredUpdate(); |
| 892 | } else { |
| 893 | updateUIForCurrentPhoto(); |
Paramananda | c12b8b1 | 2015-03-24 17:51:29 +0530 | [diff] [blame] | 894 | |
| 895 | // Manage DRM rights while image selection changed. this |
| 896 | // flow will comes for both image and video, but here |
| 897 | // we will consume rights for image files only. |
| 898 | // Do not consume rights of a GIF image and video here. |
| 899 | // ViewGifImage will take care of GIF rights consumption stub. |
| 900 | // MediaPlayer will handle the video rights consumption stub. |
Anand Chaudhari | 922a2fa | 2015-09-23 18:01:06 +0530 | [diff] [blame] | 901 | // String mime = mCurrentPhoto.getMimeType(); |
| 902 | // if (!TextUtils.isEmpty(mime) && !mime.equals("image/gif") |
| 903 | // && !mime.startsWith("video/")) { |
| 904 | // DrmHelper.manageDrmLicense(mActivity.getAndroidContext(), |
| 905 | // mHandler, mCurrentPhoto.getFilePath(), |
| 906 | // mCurrentPhoto.getMimeType()); |
| 907 | // } |
Chih-Chung Chang | 15b351a | 2012-03-15 16:38:45 +0800 | [diff] [blame] | 908 | } |
Mangesh Ghiware | 825afb1 | 2012-10-10 18:37:24 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 911 | private void updateMenuOperations() { |
Owen Lin | 24081fe | 2012-08-28 18:04:00 +0800 | [diff] [blame] | 912 | Menu menu = mActionBar.getMenu(); |
| 913 | |
| 914 | // it could be null if onCreateActionBar has not been called yet |
| 915 | if (menu == null) return; |
| 916 | |
| 917 | MenuItem item = menu.findItem(R.id.action_slideshow); |
John Reck | 53fe9f7 | 2012-09-27 15:26:00 -0700 | [diff] [blame] | 918 | if (item != null) { |
| 919 | item.setVisible((mSecureAlbum == null) && canDoSlideShow()); |
| 920 | } |
Chih-Chung Chang | 2066200 | 2011-11-18 18:04:10 +0800 | [diff] [blame] | 921 | if (mCurrentPhoto == null) return; |
Owen Lin | 24081fe | 2012-08-28 18:04:00 +0800 | [diff] [blame] | 922 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 923 | int supportedOperations = mCurrentPhoto.getSupportedOperations(); |
John Hoford | 463b918 | 2013-09-16 15:51:02 -0700 | [diff] [blame] | 924 | if (mReadOnlyView) { |
kaiyiz | 078fa1b | 2015-01-08 13:50:23 +0800 | [diff] [blame] | 925 | supportedOperations &= ~MediaObject.SUPPORT_EDIT; |
John Hoford | 463b918 | 2013-09-16 15:51:02 -0700 | [diff] [blame] | 926 | } |
Wu-cheng Li | 898a2f4 | 2012-08-27 00:10:38 +0800 | [diff] [blame] | 927 | if (mSecureAlbum != null) { |
Owen Lin | 24081fe | 2012-08-28 18:04:00 +0800 | [diff] [blame] | 928 | supportedOperations &= MediaObject.SUPPORT_DELETE; |
Sascha Haeberling | 8e58283 | 2013-04-22 16:06:25 -0700 | [diff] [blame] | 929 | } else { |
| 930 | mCurrentPhoto.getPanoramaSupport(mUpdatePanoramaMenuItemsCallback); |
| 931 | if (!mHaveImageEditor) { |
| 932 | supportedOperations &= ~MediaObject.SUPPORT_EDIT; |
| 933 | } |
lihai | 260fcaa | 2015-08-20 08:54:29 +0800 | [diff] [blame] | 934 | // If current photo page is single item only, to cut some menu items |
| 935 | boolean singleItemOnly = mData.getBoolean("SingleItemOnly", false); |
| 936 | if (singleItemOnly) { |
| 937 | supportedOperations &= ~MediaObject.SUPPORT_DELETE; |
| 938 | supportedOperations &= ~MediaObject.SUPPORT_ROTATE; |
| 939 | supportedOperations &= ~MediaObject.SUPPORT_SHARE; |
| 940 | supportedOperations &= ~MediaObject.SUPPORT_CROP; |
| 941 | supportedOperations &= ~MediaObject.SUPPORT_INFO; |
| 942 | supportedOperations &= ~MediaObject.SUPPORT_SETAS; |
| 943 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 944 | } |
Owen Lin | 24081fe | 2012-08-28 18:04:00 +0800 | [diff] [blame] | 945 | MenuExecutor.updateMenuOperation(menu, supportedOperations); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 946 | } |
| 947 | |
Chih-Chung Chang | 2066200 | 2011-11-18 18:04:10 +0800 | [diff] [blame] | 948 | private boolean canDoSlideShow() { |
| 949 | if (mMediaSet == null || mCurrentPhoto == null) { |
| 950 | return false; |
| 951 | } |
| 952 | if (mCurrentPhoto.getMediaType() != MediaObject.MEDIA_TYPE_IMAGE) { |
| 953 | return false; |
| 954 | } |
Chih-Chung Chang | 2066200 | 2011-11-18 18:04:10 +0800 | [diff] [blame] | 955 | return true; |
| 956 | } |
| 957 | |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 958 | ////////////////////////////////////////////////////////////////////////// |
| 959 | // Action Bar show/hide management |
| 960 | ////////////////////////////////////////////////////////////////////////// |
| 961 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 962 | private void showBars() { |
| 963 | if (mShowBars) return; |
| 964 | mShowBars = true; |
Chih-Chung Chang | e6251df | 2012-05-22 11:35:46 -0700 | [diff] [blame] | 965 | mOrientationManager.unlockOrientation(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 966 | mActionBar.show(); |
Joey Rizzoli | cca548c | 2016-06-10 17:53:02 +0200 | [diff] [blame] | 967 | mActivity.getGLRoot().setLightsOutMode(false); |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 968 | refreshHidingMessage(); |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 969 | refreshBottomControlsWhenReady(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | private void hideBars() { |
| 973 | if (!mShowBars) return; |
| 974 | mShowBars = false; |
| 975 | mActionBar.hide(); |
Chih-Chung Chang | 0b2486c | 2012-05-17 16:45:12 -0700 | [diff] [blame] | 976 | mActivity.getGLRoot().setLightsOutMode(true); |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 977 | mHandler.removeMessages(MSG_HIDE_BARS); |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 978 | refreshBottomControlsWhenReady(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | private void refreshHidingMessage() { |
| 982 | mHandler.removeMessages(MSG_HIDE_BARS); |
shenfe | 94f1e04 | 2016-10-25 13:07:29 +0800 | [diff] [blame] | 983 | if (mPhotoView == null) { |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 984 | return; |
shenfe | 94f1e04 | 2016-10-25 13:07:29 +0800 | [diff] [blame] | 985 | } |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 986 | if (!mIsMenuVisible && !mPhotoView.getFilmMode()) { |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 987 | mHandler.sendEmptyMessageDelayed(MSG_HIDE_BARS, HIDE_BARS_TIMEOUT); |
| 988 | } |
| 989 | } |
| 990 | |
Chih-Chung Chang | aeb3062 | 2012-05-03 11:41:05 +0800 | [diff] [blame] | 991 | private boolean canShowBars() { |
| 992 | // No bars if we are showing camera preview. |
Bobby Georgescu | 56bdcb7 | 2012-09-19 15:14:53 -0700 | [diff] [blame] | 993 | if (mAppBridge != null && mCurrentIndex == 0 |
| 994 | && !mPhotoView.getFilmMode()) return false; |
| 995 | |
Chih-Chung Chang | aeb3062 | 2012-05-03 11:41:05 +0800 | [diff] [blame] | 996 | // No bars if it's not allowed. |
| 997 | if (!mActionBarAllowed) return false; |
Chih-Chung Chang | aeb3062 | 2012-05-03 11:41:05 +0800 | [diff] [blame] | 998 | |
John Reck | 4ea5c27 | 2013-01-18 16:00:45 -0800 | [diff] [blame] | 999 | Configuration config = mActivity.getResources().getConfiguration(); |
| 1000 | if (config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH) { |
| 1001 | return false; |
| 1002 | } |
| 1003 | |
Chih-Chung Chang | aeb3062 | 2012-05-03 11:41:05 +0800 | [diff] [blame] | 1004 | return true; |
| 1005 | } |
| 1006 | |
Chih-Chung Chang | e6251df | 2012-05-22 11:35:46 -0700 | [diff] [blame] | 1007 | private void wantBars() { |
| 1008 | if (canShowBars()) showBars(); |
| 1009 | } |
| 1010 | |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 1011 | private void toggleBars() { |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1012 | if (mShowBars) { |
| 1013 | hideBars(); |
Chih-Chung Chang | aeb3062 | 2012-05-03 11:41:05 +0800 | [diff] [blame] | 1014 | } else { |
Chih-Chung Chang | e6251df | 2012-05-22 11:35:46 -0700 | [diff] [blame] | 1015 | if (canShowBars()) showBars(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1016 | } |
| 1017 | } |
| 1018 | |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 1019 | private void updateBars() { |
Chih-Chung Chang | e6251df | 2012-05-22 11:35:46 -0700 | [diff] [blame] | 1020 | if (!canShowBars()) { |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 1021 | hideBars(); |
| 1022 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1023 | } |
| 1024 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1025 | @Override |
| 1026 | protected void onBackPressed() { |
nicolasroard | 4d7efab | 2013-10-15 15:36:16 -0700 | [diff] [blame] | 1027 | showBars(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1028 | if (mShowDetails) { |
| 1029 | hideDetails(); |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 1030 | } else if (mAppBridge == null || !switchWithCaptureAnimation(-1)) { |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1031 | // We are leaving this page. Set the result now. |
| 1032 | setResult(); |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1033 | if (mStartInFilmstrip && !mPhotoView.getFilmMode()) { |
| 1034 | mPhotoView.setFilmMode(true); |
| 1035 | } else if (mTreatBackAsUp) { |
Yuli Huang | 54fe620 | 2012-05-23 16:06:32 +0800 | [diff] [blame] | 1036 | onUpPressed(); |
| 1037 | } else { |
huiyan | e9fa3d6 | 2016-04-13 12:48:07 +0800 | [diff] [blame] | 1038 | if (mMediaSet != null && mIsFromTimelineScreen) { |
| 1039 | //if back to TimeLinePage, need show timeline title |
Kedi Xu | fece30c | 2016-10-21 15:13:32 +0800 | [diff] [blame] | 1040 | mMediaSet.setShowAlbumsetTimeTitle(true); |
huiyan | e9fa3d6 | 2016-04-13 12:48:07 +0800 | [diff] [blame] | 1041 | } |
Yuli Huang | 54fe620 | 2012-05-23 16:06:32 +0800 | [diff] [blame] | 1042 | super.onBackPressed(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1043 | mActionBar.setBackGroundDefault(); |
| 1044 | int count = mActivity.getStateManager().getStateCount(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1045 | if (mIsFromVideoScreen || count == 1 || mIsFromTimelineScreen) { |
Arne Coucheron | ccbf7a7 | 2017-07-13 01:36:11 +0200 | [diff] [blame^] | 1046 | ((GalleryActivity) mActivity).toggleNavBar(true); |
wqi | 57d76b0 | 2016-03-25 11:24:08 +0800 | [diff] [blame] | 1047 | if (mModel instanceof PhotoDataAdapter) { |
| 1048 | ((PhotoDataAdapter) mModel).setDataListener(null); |
| 1049 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1050 | } |
Yuli Huang | 54fe620 | 2012-05-23 16:06:32 +0800 | [diff] [blame] | 1051 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | |
Chih-Chung Chang | b1e9fd8 | 2012-04-30 17:33:21 +0800 | [diff] [blame] | 1055 | private void onUpPressed() { |
Bobby Georgescu | 833f775 | 2012-09-26 14:22:57 -0700 | [diff] [blame] | 1056 | if ((mStartInFilmstrip || mAppBridge != null) |
| 1057 | && !mPhotoView.getFilmMode()) { |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1058 | mPhotoView.setFilmMode(true); |
| 1059 | return; |
| 1060 | } |
| 1061 | |
Chih-Chung Chang | b1e9fd8 | 2012-04-30 17:33:21 +0800 | [diff] [blame] | 1062 | if (mActivity.getStateManager().getStateCount() > 1) { |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1063 | setResult(); |
Chih-Chung Chang | b1e9fd8 | 2012-04-30 17:33:21 +0800 | [diff] [blame] | 1064 | super.onBackPressed(); |
Chih-Chung Chang | ba12eae | 2012-05-07 02:29:37 +0800 | [diff] [blame] | 1065 | return; |
Chih-Chung Chang | 66ca848 | 2012-05-04 21:54:01 +0800 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | if (mOriginalSetPathString == null) return; |
| 1069 | |
| 1070 | if (mAppBridge == null) { |
Chih-Chung Chang | b1e9fd8 | 2012-04-30 17:33:21 +0800 | [diff] [blame] | 1071 | // We're in view mode so set up the stacks on our own. |
| 1072 | Bundle data = new Bundle(getData()); |
| 1073 | data.putString(AlbumPage.KEY_MEDIA_PATH, mOriginalSetPathString); |
| 1074 | data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH, |
| 1075 | mActivity.getDataManager().getTopSetPath( |
| 1076 | DataManager.INCLUDE_ALL)); |
| 1077 | mActivity.getStateManager().switchState(this, AlbumPage.class, data); |
Chih-Chung Chang | 66ca848 | 2012-05-04 21:54:01 +0800 | [diff] [blame] | 1078 | } else { |
Bobby Georgescu | 833f775 | 2012-09-26 14:22:57 -0700 | [diff] [blame] | 1079 | GalleryUtils.startGalleryActivity(mActivity); |
Chih-Chung Chang | b1e9fd8 | 2012-04-30 17:33:21 +0800 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1083 | private void setResult() { |
| 1084 | Intent result = null; |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1085 | result = new Intent(); |
| 1086 | result.putExtra(KEY_RETURN_INDEX_HINT, mCurrentIndex); |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1087 | setStateResult(Activity.RESULT_OK, result); |
| 1088 | } |
| 1089 | |
| 1090 | ////////////////////////////////////////////////////////////////////////// |
| 1091 | // AppBridge.Server interface |
| 1092 | ////////////////////////////////////////////////////////////////////////// |
| 1093 | |
| 1094 | @Override |
Chih-Chung Chang | 2ef46ed | 2012-05-08 17:57:33 +0800 | [diff] [blame] | 1095 | public void setCameraRelativeFrame(Rect frame) { |
| 1096 | mPhotoView.setCameraRelativeFrame(frame); |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | @Override |
Chih-Chung Chang | 2c61738 | 2012-04-20 20:06:19 +0800 | [diff] [blame] | 1100 | public boolean switchWithCaptureAnimation(int offset) { |
| 1101 | return mPhotoView.switchWithCaptureAnimation(offset); |
| 1102 | } |
| 1103 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1104 | @Override |
Chih-Chung Chang | 6575794 | 2012-05-06 03:25:16 +0800 | [diff] [blame] | 1105 | public void setSwipingEnabled(boolean enabled) { |
| 1106 | mPhotoView.setSwipingEnabled(enabled); |
| 1107 | } |
| 1108 | |
| 1109 | @Override |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 1110 | public void notifyScreenNailChanged() { |
| 1111 | mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail()); |
| 1112 | mScreenNailSet.notifyChange(); |
| 1113 | } |
| 1114 | |
| 1115 | @Override |
Wu-cheng Li | a0ce682 | 2012-08-22 19:15:35 +0800 | [diff] [blame] | 1116 | public void addSecureAlbumItem(boolean isVideo, int id) { |
| 1117 | mSecureAlbum.addMediaItem(isVideo, id); |
| 1118 | } |
| 1119 | |
| 1120 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1121 | protected boolean onCreateActionBar(Menu menu) { |
Owen Lin | b21b8e5 | 2012-08-24 12:25:57 +0800 | [diff] [blame] | 1122 | mActionBar.createActionBarMenu(R.menu.photo, menu); |
John Reck | 8fe22ec | 2012-09-26 16:13:02 -0700 | [diff] [blame] | 1123 | mHaveImageEditor = GalleryUtils.isEditorAvailable(mActivity, "image/*"); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1124 | updateMenuOperations(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1125 | //mActionBar.setTitle(mMediaSet != null ? mMediaSet.getName() : ""); |
Owen Lin | b21b8e5 | 2012-08-24 12:25:57 +0800 | [diff] [blame] | 1126 | return true; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1127 | } |
| 1128 | |
Owen Lin | d759b7c | 2012-05-16 15:32:02 -0700 | [diff] [blame] | 1129 | private MenuExecutor.ProgressListener mConfirmDialogListener = |
| 1130 | new MenuExecutor.ProgressListener() { |
| 1131 | @Override |
| 1132 | public void onProgressUpdate(int index) {} |
| 1133 | |
| 1134 | @Override |
| 1135 | public void onProgressComplete(int result) {} |
| 1136 | |
| 1137 | @Override |
| 1138 | public void onConfirmDialogShown() { |
| 1139 | mHandler.removeMessages(MSG_HIDE_BARS); |
| 1140 | } |
| 1141 | |
| 1142 | @Override |
| 1143 | public void onConfirmDialogDismissed(boolean confirmed) { |
| 1144 | refreshHidingMessage(); |
| 1145 | } |
Bobby Georgescu | ba50b94 | 2012-08-08 00:09:50 -0700 | [diff] [blame] | 1146 | |
| 1147 | @Override |
| 1148 | public void onProgressStart() {} |
Owen Lin | d759b7c | 2012-05-16 15:32:02 -0700 | [diff] [blame] | 1149 | }; |
| 1150 | |
Bobby Georgescu | 3cf502a | 2012-10-01 15:50:11 -0700 | [diff] [blame] | 1151 | private void switchToGrid() { |
Bobby Georgescu | 5585826 | 2012-10-15 13:48:08 -0700 | [diff] [blame] | 1152 | if (mActivity.getStateManager().hasStateClass(AlbumPage.class)) { |
Bobby Georgescu | 3cf502a | 2012-10-01 15:50:11 -0700 | [diff] [blame] | 1153 | onUpPressed(); |
| 1154 | } else { |
| 1155 | if (mOriginalSetPathString == null) return; |
Bobby Georgescu | 3cf502a | 2012-10-01 15:50:11 -0700 | [diff] [blame] | 1156 | Bundle data = new Bundle(getData()); |
| 1157 | data.putString(AlbumPage.KEY_MEDIA_PATH, mOriginalSetPathString); |
| 1158 | data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH, |
| 1159 | mActivity.getDataManager().getTopSetPath( |
| 1160 | DataManager.INCLUDE_ALL)); |
| 1161 | |
| 1162 | // We only show cluster menu in the first AlbumPage in stack |
| 1163 | // TODO: Enable this when running from the camera app |
| 1164 | boolean inAlbum = mActivity.getStateManager().hasStateClass(AlbumPage.class); |
| 1165 | data.putBoolean(AlbumPage.KEY_SHOW_CLUSTER_MENU, !inAlbum |
| 1166 | && mAppBridge == null); |
| 1167 | |
| 1168 | data.putBoolean(PhotoPage.KEY_APP_BRIDGE, mAppBridge != null); |
| 1169 | |
| 1170 | // Account for live preview being first item |
| 1171 | mActivity.getTransitionStore().put(KEY_RETURN_INDEX_HINT, |
| 1172 | mAppBridge != null ? mCurrentIndex - 1 : mCurrentIndex); |
| 1173 | |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 1174 | if (mHasCameraScreennailOrPlaceholder && mAppBridge != null) { |
Bobby Georgescu | 5585826 | 2012-10-15 13:48:08 -0700 | [diff] [blame] | 1175 | mActivity.getStateManager().startState(AlbumPage.class, data); |
| 1176 | } else { |
| 1177 | mActivity.getStateManager().switchState(this, AlbumPage.class, data); |
| 1178 | } |
Bobby Georgescu | 3cf502a | 2012-10-01 15:50:11 -0700 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1182 | @Override |
| 1183 | protected boolean onItemSelected(MenuItem item) { |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 1184 | if (mModel == null) return true; |
Owen Lin | d759b7c | 2012-05-16 15:32:02 -0700 | [diff] [blame] | 1185 | refreshHidingMessage(); |
Owen Lin | 616a70f | 2012-05-07 16:35:53 +0800 | [diff] [blame] | 1186 | MediaItem current = mModel.getMediaItem(0); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1187 | |
Doris Liu | 599bdd6 | 2012-11-12 15:17:36 -0800 | [diff] [blame] | 1188 | // This is a shield for monkey when it clicks the action bar |
| 1189 | // menu when transitioning from filmstrip to camera |
| 1190 | if (current instanceof SnailItem) return true; |
| 1191 | // TODO: We should check the current photo against the MediaItem |
| 1192 | // that the menu was initially created for. We need to fix this |
| 1193 | // after PhotoPage being refactored. |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1194 | if (current == null) { |
| 1195 | // item is not ready, ignore |
| 1196 | return true; |
| 1197 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1198 | int currentIndex = mModel.getCurrentIndex(); |
kaiyiz | ed2687a | 2014-10-15 10:10:13 +0800 | [diff] [blame] | 1199 | |
| 1200 | // If RTL, the current index need be revised. |
| 1201 | if (View.LAYOUT_DIRECTION_RTL == TextUtils |
| 1202 | .getLayoutDirectionFromLocale(Locale.getDefault())) { |
| 1203 | currentIndex = mMediaSet.getMediaItemCount() - currentIndex - 1; |
| 1204 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1205 | Path path = current.getPath(); |
| 1206 | |
| 1207 | DataManager manager = mActivity.getDataManager(); |
| 1208 | int action = item.getItemId(); |
Ray Chen | 9a033b0 | 2012-05-15 11:22:21 +0800 | [diff] [blame] | 1209 | String confirmMsg = null; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1210 | switch (action) { |
Ray Chen | 84c220f | 2012-03-06 17:24:28 +0800 | [diff] [blame] | 1211 | case android.R.id.home: { |
Chih-Chung Chang | b1e9fd8 | 2012-04-30 17:33:21 +0800 | [diff] [blame] | 1212 | onUpPressed(); |
Ray Chen | 84c220f | 2012-03-06 17:24:28 +0800 | [diff] [blame] | 1213 | return true; |
| 1214 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1215 | case R.id.action_slideshow: { |
| 1216 | Bundle data = new Bundle(); |
Owen Lin | 6cf8074 | 2011-08-28 10:50:21 +0800 | [diff] [blame] | 1217 | data.putString(SlideshowPage.KEY_SET_PATH, mMediaSet.getPath().toString()); |
Ray Chen | 604f053 | 2011-10-21 16:07:12 +0800 | [diff] [blame] | 1218 | data.putString(SlideshowPage.KEY_ITEM_PATH, path.toString()); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1219 | data.putInt(SlideshowPage.KEY_PHOTO_INDEX, currentIndex); |
| 1220 | data.putBoolean(SlideshowPage.KEY_REPEAT, true); |
| 1221 | mActivity.getStateManager().startStateForResult( |
| 1222 | SlideshowPage.class, REQUEST_SLIDESHOW, data); |
| 1223 | return true; |
| 1224 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1225 | /*case R.id.action_crop: { |
Wu-cheng Li | 898a2f4 | 2012-08-27 00:10:38 +0800 | [diff] [blame] | 1226 | Activity activity = mActivity; |
Ruben Brunk | c3178ca | 2013-04-16 16:17:45 -0700 | [diff] [blame] | 1227 | Intent intent = new Intent(CropActivity.CROP_ACTION); |
| 1228 | intent.setClass(activity, CropActivity.class); |
Ruben Brunk | 63926d2 | 2012-10-17 00:40:35 -0700 | [diff] [blame] | 1229 | intent.setDataAndType(manager.getContentUri(path), current.getMimeType()) |
| 1230 | .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1231 | activity.startActivityForResult(intent, PicasaSource.isPicasaImage(current) |
| 1232 | ? REQUEST_CROP_PICASA |
| 1233 | : REQUEST_CROP); |
| 1234 | return true; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1235 | }*/ |
Teng-Hui Zhu | 50ea2d2 | 2012-08-23 16:45:11 -0700 | [diff] [blame] | 1236 | case R.id.action_trim: { |
Teng-Hui Zhu | 3f1f1ba | 2012-08-24 14:50:37 -0700 | [diff] [blame] | 1237 | Intent intent = new Intent(mActivity, TrimVideo.class); |
| 1238 | intent.setData(manager.getContentUri(path)); |
Teng-Hui Zhu | 15ff1b1 | 2012-09-23 15:02:56 -0700 | [diff] [blame] | 1239 | // We need the file path to wrap this into a RandomAccessFile. |
Likai Ding | 4dc5e6d | 2016-05-20 14:21:43 +0800 | [diff] [blame] | 1240 | String str = current.getMimeType(); |
xiaoqiny | 3be6940 | 2014-12-25 13:39:42 +0800 | [diff] [blame] | 1241 | if("video/mp4".equals(str) || "video/mpeg4".equals(str) |
| 1242 | || "video/3gpp".equals(str) || "video/3gpp2".equals(str)) { |
| 1243 | intent.putExtra(KEY_MEDIA_ITEM_PATH, current.getFilePath()); |
| 1244 | mActivity.startActivityForResult(intent, REQUEST_TRIM); |
| 1245 | } else { |
| 1246 | Toast.makeText(mActivity,mActivity.getString(R.string.can_not_trim), |
| 1247 | Toast.LENGTH_SHORT).show(); |
| 1248 | } |
Teng-Hui Zhu | 50ea2d2 | 2012-08-23 16:45:11 -0700 | [diff] [blame] | 1249 | return true; |
| 1250 | } |
Teng-Hui Zhu | 648b339 | 2012-11-13 10:39:26 -0800 | [diff] [blame] | 1251 | case R.id.action_mute: { |
Bobby Georgescu | 1a71980 | 2013-03-14 15:19:23 -0700 | [diff] [blame] | 1252 | MuteVideo muteVideo = new MuteVideo(current.getFilePath(), |
Teng-Hui Zhu | 648b339 | 2012-11-13 10:39:26 -0800 | [diff] [blame] | 1253 | manager.getContentUri(path), mActivity); |
| 1254 | muteVideo.muteInBackground(); |
| 1255 | return true; |
| 1256 | } |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 1257 | case R.id.action_edit: { |
Bobby Georgescu | a9948ef | 2012-09-11 17:02:03 -0700 | [diff] [blame] | 1258 | launchPhotoEditor(); |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 1259 | return true; |
| 1260 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1261 | /*case R.id.action_simple_edit: { |
nicolasroard | 8c4e95f | 2013-04-08 18:16:17 -0700 | [diff] [blame] | 1262 | launchSimpleEditor(); |
| 1263 | return true; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1264 | }*/ |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1265 | case R.id.action_details: { |
| 1266 | if (mShowDetails) { |
| 1267 | hideDetails(); |
| 1268 | } else { |
Michael Kolb | 995c456 | 2012-07-20 12:23:09 -0700 | [diff] [blame] | 1269 | showDetails(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1270 | } |
| 1271 | return true; |
| 1272 | } |
nicolasroard | 513eb24 | 2013-08-19 16:21:12 -0700 | [diff] [blame] | 1273 | case R.id.print: { |
huiyan | 5101dc6 | 2016-05-11 15:10:28 +0800 | [diff] [blame] | 1274 | try { |
| 1275 | mActivity.printSelectedImage(manager.getContentUri(path)); |
| 1276 | } catch (SecurityException e) { |
| 1277 | e.printStackTrace(); |
| 1278 | mActivity.finish(); |
| 1279 | } |
nicolasroard | 513eb24 | 2013-08-19 16:21:12 -0700 | [diff] [blame] | 1280 | return true; |
| 1281 | } |
Ray Chen | 67098d1 | 2012-04-05 17:25:43 +0800 | [diff] [blame] | 1282 | case R.id.action_delete: |
Ray Chen | 9a033b0 | 2012-05-15 11:22:21 +0800 | [diff] [blame] | 1283 | confirmMsg = mActivity.getResources().getQuantityString( |
| 1284 | R.plurals.delete_selection, 1); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1285 | case R.id.action_setas: |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1286 | //case R.id.action_rotate_ccw: |
| 1287 | //case R.id.action_rotate_cw: |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1288 | case R.id.action_show_on_map: |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1289 | mSelectionManager.deSelectAll(); |
| 1290 | mSelectionManager.toggle(path); |
Owen Lin | d759b7c | 2012-05-16 15:32:02 -0700 | [diff] [blame] | 1291 | mMenuExecutor.onMenuClicked(item, confirmMsg, mConfirmDialogListener); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1292 | return true; |
Anand Chaudhari | 922a2fa | 2015-09-23 18:01:06 +0530 | [diff] [blame] | 1293 | // case R.id.action_drm_info: |
| 1294 | // String filepath = current.getFilePath(); |
| 1295 | // if (DrmHelper.isDrmFile(filepath)) { |
| 1296 | // DrmHelper.showDrmInfo(mActivity.getAndroidContext(), filepath); |
| 1297 | // } |
| 1298 | // return true; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1299 | default : |
| 1300 | return false; |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | private void hideDetails() { |
| 1305 | mShowDetails = false; |
Ray Chen | 4105e22 | 2011-08-24 11:40:04 +0800 | [diff] [blame] | 1306 | mDetailsHelper.hide(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1307 | } |
| 1308 | |
Michael Kolb | 995c456 | 2012-07-20 12:23:09 -0700 | [diff] [blame] | 1309 | private void showDetails() { |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1310 | mShowDetails = true; |
Ray Chen | 4105e22 | 2011-08-24 11:40:04 +0800 | [diff] [blame] | 1311 | if (mDetailsHelper == null) { |
| 1312 | mDetailsHelper = new DetailsHelper(mActivity, mRootPane, new MyDetailsSource()); |
| 1313 | mDetailsHelper.setCloseListener(new CloseListener() { |
Pin Ting | 06c6401 | 2012-05-03 08:26:17 +0800 | [diff] [blame] | 1314 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1315 | public void onClose() { |
| 1316 | hideDetails(); |
| 1317 | } |
| 1318 | }); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1319 | } |
Ray Chen | 4105e22 | 2011-08-24 11:40:04 +0800 | [diff] [blame] | 1320 | mDetailsHelper.show(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1321 | } |
| 1322 | |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1323 | //////////////////////////////////////////////////////////////////////////// |
| 1324 | // Callbacks from PhotoView |
| 1325 | //////////////////////////////////////////////////////////////////////////// |
| 1326 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1327 | public void onSingleTapUp(int x, int y) { |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1328 | if (mAppBridge != null) { |
| 1329 | if (mAppBridge.onSingleTapUp(x, y)) return; |
Wu-cheng Li | 014d958 | 2012-04-18 17:10:02 +0800 | [diff] [blame] | 1330 | } |
| 1331 | |
Owen Lin | 616a70f | 2012-05-07 16:35:53 +0800 | [diff] [blame] | 1332 | MediaItem item = mModel.getMediaItem(0); |
Wu-cheng Li | b5dc542 | 2012-04-30 18:36:22 +0800 | [diff] [blame] | 1333 | if (item == null || item == mScreenNailItem) { |
| 1334 | // item is not ready or it is camera preview, ignore |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1335 | return; |
| 1336 | } |
Likai Ding | b2e9100 | 2013-08-13 14:07:48 +0800 | [diff] [blame] | 1337 | if (item.getMimeType().equals(MediaItem.MIME_TYPE_GIF)) { |
| 1338 | viewAnimateGif((Activity) mActivity, item.getContentUri()); |
| 1339 | return; |
| 1340 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1341 | |
Wu-cheng Li | 8868aa1 | 2012-09-24 18:32:59 +0800 | [diff] [blame] | 1342 | int supported = item.getSupportedOperations(); |
Angus Kong | 3935ca3 | 2012-11-01 15:08:44 +0800 | [diff] [blame] | 1343 | boolean playVideo = ((supported & MediaItem.SUPPORT_PLAY) != 0); |
Wu-cheng Li | 8868aa1 | 2012-09-24 18:32:59 +0800 | [diff] [blame] | 1344 | boolean unlock = ((supported & MediaItem.SUPPORT_UNLOCK) != 0); |
Bobby Georgescu | c7e3c76 | 2012-09-27 16:36:03 -0700 | [diff] [blame] | 1345 | boolean goBack = ((supported & MediaItem.SUPPORT_BACK) != 0); |
Bobby Georgescu | 45f089d | 2012-10-02 13:30:09 -0700 | [diff] [blame] | 1346 | boolean launchCamera = ((supported & MediaItem.SUPPORT_CAMERA_SHORTCUT) != 0); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1347 | |
| 1348 | if (playVideo) { |
| 1349 | // determine if the point is at center (1/6) of the photo view. |
| 1350 | // (The position of the "play" icon is at center (1/6) of the photo) |
| 1351 | int w = mPhotoView.getWidth(); |
| 1352 | int h = mPhotoView.getHeight(); |
| 1353 | playVideo = (Math.abs(x - w / 2) * 12 <= w) |
| 1354 | && (Math.abs(y - h / 2) * 12 <= h); |
| 1355 | } |
| 1356 | |
| 1357 | if (playVideo) { |
Angus Kong | 3935ca3 | 2012-11-01 15:08:44 +0800 | [diff] [blame] | 1358 | if (mSecureAlbum == null) { |
| 1359 | playVideo(mActivity, item.getPlayUri(), item.getName()); |
| 1360 | } else { |
| 1361 | mActivity.getStateManager().finishState(this); |
| 1362 | } |
Bobby Georgescu | c7e3c76 | 2012-09-27 16:36:03 -0700 | [diff] [blame] | 1363 | } else if (goBack) { |
| 1364 | onBackPressed(); |
Wu-cheng Li | 8868aa1 | 2012-09-24 18:32:59 +0800 | [diff] [blame] | 1365 | } else if (unlock) { |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 1366 | Intent intent = new Intent(mActivity, GalleryActivity.class); |
| 1367 | intent.putExtra(GalleryActivity.KEY_DISMISS_KEYGUARD, true); |
Wu-cheng Li | 6455ba9 | 2012-11-02 13:36:07 +0800 | [diff] [blame] | 1368 | mActivity.startActivity(intent); |
Bobby Georgescu | 45f089d | 2012-10-02 13:30:09 -0700 | [diff] [blame] | 1369 | } else if (launchCamera) { |
Bobby Georgescu | 5bd0033 | 2012-10-24 12:09:38 -0700 | [diff] [blame] | 1370 | launchCamera(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1371 | } else { |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 1372 | toggleBars(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1376 | @Override |
Chih-Chung Chang | 61f9471 | 2012-05-02 20:05:16 +0800 | [diff] [blame] | 1377 | public void onActionBarAllowed(boolean allowed) { |
| 1378 | mActionBarAllowed = allowed; |
| 1379 | mHandler.sendEmptyMessage(MSG_UPDATE_ACTION_BAR); |
| 1380 | } |
| 1381 | |
| 1382 | @Override |
Chih-Chung Chang | e6251df | 2012-05-22 11:35:46 -0700 | [diff] [blame] | 1383 | public void onActionBarWanted() { |
| 1384 | mHandler.sendEmptyMessage(MSG_WANT_BARS); |
| 1385 | } |
| 1386 | |
| 1387 | @Override |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1388 | public void onFullScreenChanged(boolean full) { |
| 1389 | Message m = mHandler.obtainMessage( |
| 1390 | MSG_ON_FULL_SCREEN_CHANGED, full ? 1 : 0, 0); |
| 1391 | m.sendToTarget(); |
| 1392 | } |
| 1393 | |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 1394 | // How we do delete/undo: |
| 1395 | // |
| 1396 | // When the user choose to delete a media item, we just tell the |
| 1397 | // FilterDeleteSet to hide that item. If the user choose to undo it, we |
| 1398 | // again tell FilterDeleteSet not to hide it. If the user choose to commit |
| 1399 | // the deletion, we then actually delete the media item. |
| 1400 | @Override |
| 1401 | public void onDeleteImage(Path path, int offset) { |
Chih-Chung Chang | 6118af9 | 2012-06-22 20:56:04 +0800 | [diff] [blame] | 1402 | onCommitDeleteImage(); // commit the previous deletion |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 1403 | mDeletePath = path; |
| 1404 | mDeleteIsFocus = (offset == 0); |
kaiyiz | ed2687a | 2014-10-15 10:10:13 +0800 | [diff] [blame] | 1405 | |
| 1406 | // If RTL, the index need be revised. |
| 1407 | if (View.LAYOUT_DIRECTION_RTL == TextUtils |
| 1408 | .getLayoutDirectionFromLocale(Locale.getDefault())) { |
| 1409 | mMediaSet.addDeletion(path, mMediaSet.getMediaItemCount() - mCurrentIndex - 1); |
| 1410 | } else { |
| 1411 | mMediaSet.addDeletion(path, mCurrentIndex + offset); |
| 1412 | } |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | @Override |
| 1416 | public void onUndoDeleteImage() { |
Chih-Chung Chang | 6118af9 | 2012-06-22 20:56:04 +0800 | [diff] [blame] | 1417 | if (mDeletePath == null) return; |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 1418 | // If the deletion was done on the focused item, we want the model to |
| 1419 | // focus on it when it is undeleted. |
| 1420 | if (mDeleteIsFocus) mModel.setFocusHintPath(mDeletePath); |
Chih-Chung Chang | 6118af9 | 2012-06-22 20:56:04 +0800 | [diff] [blame] | 1421 | mMediaSet.removeDeletion(mDeletePath); |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 1422 | mDeletePath = null; |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | @Override |
| 1426 | public void onCommitDeleteImage() { |
| 1427 | if (mDeletePath == null) return; |
Bobby Georgescu | d00f521 | 2013-01-28 16:16:44 -0800 | [diff] [blame] | 1428 | mMenuExecutor.startSingleItemAction(R.id.action_delete, mDeletePath); |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 1429 | mDeletePath = null; |
| 1430 | } |
| 1431 | |
Bobby Georgescu | d81b264 | 2012-10-07 16:25:54 -0700 | [diff] [blame] | 1432 | public void playVideo(Activity activity, Uri uri, String title) { |
Likai Ding | 4dc5e6d | 2016-05-20 14:21:43 +0800 | [diff] [blame] | 1433 | if (GalleryUtils.isTelephonyCallInProgress(mActivity)) { |
Chao Zhang | 0e30577 | 2016-01-27 15:07:11 +0800 | [diff] [blame] | 1434 | Log.w(TAG, "CS/CSVT Call is in progress, can't play video"); |
| 1435 | return; |
| 1436 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1437 | try { |
| 1438 | Intent intent = new Intent(Intent.ACTION_VIEW) |
Ray Chen | a387105 | 2012-05-17 12:15:08 +0800 | [diff] [blame] | 1439 | .setDataAndType(uri, "video/*") |
| 1440 | .putExtra(Intent.EXTRA_TITLE, title) |
| 1441 | .putExtra(MovieActivity.KEY_TREAT_UP_AS_BACK, true); |
Chih-Chung Chang | 71cd89a | 2012-05-17 18:22:27 -0700 | [diff] [blame] | 1442 | activity.startActivityForResult(intent, REQUEST_PLAY_VIDEO); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1443 | } catch (ActivityNotFoundException e) { |
| 1444 | Toast.makeText(activity, activity.getString(R.string.video_err), |
| 1445 | Toast.LENGTH_SHORT).show(); |
| 1446 | } |
| 1447 | } |
| 1448 | |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 1449 | private void setCurrentPhotoByIntent(Intent intent) { |
| 1450 | if (intent == null) return; |
| 1451 | Path path = mApplication.getDataManager() |
| 1452 | .findPathByUri(intent.getData(), intent.getType()); |
| 1453 | if (path != null) { |
Doris Liu | 0addfc7 | 2012-10-17 16:15:51 -0700 | [diff] [blame] | 1454 | Path albumPath = mApplication.getDataManager().getDefaultSetOf(path); |
ztenghui | eb29503 | 2013-08-20 16:38:04 -0700 | [diff] [blame] | 1455 | if (albumPath == null) { |
| 1456 | return; |
| 1457 | } |
Chao Zhang | eb2f1a6 | 2016-03-22 14:12:44 +0800 | [diff] [blame] | 1458 | boolean isClusterType = FilterUtils.isClusterPath(mOriginalSetPathString); |
| 1459 | if (!albumPath.equalsIgnoreCase(mOriginalSetPathString) && !isClusterType) { |
Doris Liu | 0addfc7 | 2012-10-17 16:15:51 -0700 | [diff] [blame] | 1460 | // If the edited image is stored in a different album, we need |
| 1461 | // to start a new activity state to show the new image |
| 1462 | Bundle data = new Bundle(getData()); |
| 1463 | data.putString(KEY_MEDIA_SET_PATH, albumPath.toString()); |
| 1464 | data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, path.toString()); |
Bobby Georgescu | cfa7fde | 2012-11-05 14:12:51 -0800 | [diff] [blame] | 1465 | mActivity.getStateManager().startState(SinglePhotoPage.class, data); |
Doris Liu | 0addfc7 | 2012-10-17 16:15:51 -0700 | [diff] [blame] | 1466 | return; |
| 1467 | } |
Kedi Xu | 6948304 | 2016-09-02 14:05:18 +0800 | [diff] [blame] | 1468 | if (null != mModel) { |
| 1469 | mModel.setCurrentPhoto(path, mCurrentIndex); |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1470 | parseGDepth(); |
Kedi Xu | 6948304 | 2016-09-02 14:05:18 +0800 | [diff] [blame] | 1471 | } |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1475 | @Override |
| 1476 | protected void onStateResult(int requestCode, int resultCode, Intent data) { |
John Reck | f85d974 | 2012-10-24 11:11:51 -0700 | [diff] [blame] | 1477 | if (resultCode == Activity.RESULT_CANCELED) { |
| 1478 | // This is a reset, not a canceled |
| 1479 | return; |
| 1480 | } |
John Reck | f85d974 | 2012-10-24 11:11:51 -0700 | [diff] [blame] | 1481 | mRecenterCameraOnResume = false; |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1482 | switch (requestCode) { |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 1483 | case REQUEST_EDIT: |
zhuw | 48efd7d | 2016-08-03 10:05:00 +0800 | [diff] [blame] | 1484 | if (data.getData() == null) { |
| 1485 | onUpPressed(); |
| 1486 | } else { |
| 1487 | setCurrentPhotoByIntent(data); |
| 1488 | } |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 1489 | break; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1490 | /*case REQUEST_CROP: |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1491 | if (resultCode == Activity.RESULT_OK) { |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 1492 | setCurrentPhotoByIntent(data); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1493 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1494 | break;*/ |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1495 | case REQUEST_CROP_PICASA: { |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 1496 | if (resultCode == Activity.RESULT_OK) { |
| 1497 | Context context = mActivity.getAndroidContext(); |
Yuli Huang | 88cc2ca | 2012-05-05 17:42:32 +0800 | [diff] [blame] | 1498 | String message = context.getString(R.string.crop_saved, |
Ruben Brunk | 00d64dd | 2012-10-18 23:39:18 -0700 | [diff] [blame] | 1499 | context.getString(R.string.folder_edited_online_photos)); |
Yuli Huang | f50ce2b | 2012-05-02 00:50:56 +0800 | [diff] [blame] | 1500 | Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); |
| 1501 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1502 | break; |
| 1503 | } |
| 1504 | case REQUEST_SLIDESHOW: { |
| 1505 | if (data == null) break; |
| 1506 | String path = data.getStringExtra(SlideshowPage.KEY_ITEM_PATH); |
| 1507 | int index = data.getIntExtra(SlideshowPage.KEY_PHOTO_INDEX, 0); |
kaiyiz | ed2687a | 2014-10-15 10:10:13 +0800 | [diff] [blame] | 1508 | |
| 1509 | // If RTL, the index need be revised. |
| 1510 | if (View.LAYOUT_DIRECTION_RTL == TextUtils |
| 1511 | .getLayoutDirectionFromLocale(Locale.getDefault())) { |
| 1512 | index = mMediaSet.getMediaItemCount() - index - 1; |
| 1513 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1514 | if (path != null) { |
| 1515 | mModel.setCurrentPhoto(Path.fromString(path), index); |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1516 | parseGDepth(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | } |
| 1520 | } |
| 1521 | |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1522 | private void parseGDepth() { |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1523 | bShow3DButton = false; |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1524 | if (DualCameraEffect.isSupported()) { |
| 1525 | if (mParseGDepthTask != null |
| 1526 | && mParseGDepthTask.getStatus() != AsyncTask.Status.FINISHED) { |
| 1527 | mParseGDepthTask.cancel(true); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1528 | } |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1529 | mParseGDepthTask = new ParseGDepthTask(); |
| 1530 | mParseGDepthTask.execute(mCurrentPhoto.getContentUri()); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | |
George Mount | 14d3289 | 2012-08-16 11:06:42 -0700 | [diff] [blame] | 1534 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1535 | public void onPause() { |
Owen Lin | d759b7c | 2012-05-16 15:32:02 -0700 | [diff] [blame] | 1536 | super.onPause(); |
| 1537 | mIsActive = false; |
huiyan | 8782c24 | 2016-04-23 14:52:23 +0800 | [diff] [blame] | 1538 | showFullScreen(false); |
Chih-Chung Chang | 253c5ae | 2012-05-16 17:37:10 -0700 | [diff] [blame] | 1539 | |
Ray Chen | 4105e22 | 2011-08-24 11:40:04 +0800 | [diff] [blame] | 1540 | DetailsHelper.pause(); |
Doris Liu | 4438a7c | 2012-10-08 16:31:00 -0700 | [diff] [blame] | 1541 | // Hide the detail dialog on exit |
| 1542 | if (mShowDetails) hideDetails(); |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 1543 | if (mModel != null) { |
Bobby Georgescu | d397378 | 2012-09-12 13:48:50 -0700 | [diff] [blame] | 1544 | mModel.pause(); |
| 1545 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1546 | mPhotoView.pause(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1547 | mHandler.removeMessages(MSG_HIDE_BARS); |
Bobby Georgescu | d2724f6 | 2012-10-06 15:22:03 -0700 | [diff] [blame] | 1548 | mHandler.removeMessages(MSG_REFRESH_BOTTOM_CONTROLS); |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 1549 | refreshBottomControlsWhenReady(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1550 | mActionBar.removeOnMenuVisibilityListener(mMenuVisibilityListener); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1551 | // if (mShowSpinner) { |
| 1552 | // mActionBar.disableAlbumModeMenu(true); |
| 1553 | // } |
Chih-Chung Chang | 6b891c6 | 2012-06-07 20:09:13 +0800 | [diff] [blame] | 1554 | onCommitDeleteImage(); |
Chih-Chung Chang | 2785956 | 2011-09-08 11:51:11 +0800 | [diff] [blame] | 1555 | mMenuExecutor.pause(); |
Chih-Chung Chang | 6118af9 | 2012-06-22 20:56:04 +0800 | [diff] [blame] | 1556 | if (mMediaSet != null) mMediaSet.clearDeletion(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1557 | } |
| 1558 | |
huiyan | 8782c24 | 2016-04-23 14:52:23 +0800 | [diff] [blame] | 1559 | private void showFullScreen(boolean show) { |
| 1560 | Window win = mActivity.getWindow(); |
| 1561 | WindowManager.LayoutParams winParams = win.getAttributes(); |
| 1562 | if (show) { |
| 1563 | //set full screen |
| 1564 | winParams.flags |= (WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 1565 | } else { |
| 1566 | //cancel full screen |
| 1567 | winParams.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 1568 | } |
| 1569 | win.setAttributes(winParams); |
| 1570 | } |
| 1571 | |
Yuli Huang | bd7c016 | 2012-05-15 22:36:59 +0800 | [diff] [blame] | 1572 | |
George Mount | f122d56 | 2012-10-09 17:50:33 -0700 | [diff] [blame] | 1573 | @Override |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1574 | public void onFilmModeChanged(boolean enabled) { |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 1575 | refreshBottomControlsWhenReady(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1576 | /*if (mShowSpinner) { |
Bobby Georgescu | c29588d | 2012-10-18 15:36:03 -0700 | [diff] [blame] | 1577 | if (enabled) { |
| 1578 | mActionBar.enableAlbumModeMenu( |
| 1579 | GalleryActionBar.ALBUM_FILMSTRIP_MODE_SELECTED, this); |
| 1580 | } else { |
| 1581 | mActionBar.disableAlbumModeMenu(true); |
| 1582 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1583 | }*/ |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1584 | if (enabled) { |
| 1585 | mHandler.removeMessages(MSG_HIDE_BARS); |
Bobby Georgescu | f37648b | 2013-03-12 22:45:17 -0700 | [diff] [blame] | 1586 | UsageStatistics.onContentViewChanged( |
| 1587 | UsageStatistics.COMPONENT_GALLERY, "FilmstripPage"); |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1588 | } else { |
| 1589 | refreshHidingMessage(); |
Bobby Georgescu | f37648b | 2013-03-12 22:45:17 -0700 | [diff] [blame] | 1590 | if (mAppBridge == null || mCurrentIndex > 0) { |
| 1591 | UsageStatistics.onContentViewChanged( |
| 1592 | UsageStatistics.COMPONENT_GALLERY, "SinglePhotoPage"); |
| 1593 | } else { |
| 1594 | UsageStatistics.onContentViewChanged( |
| 1595 | UsageStatistics.COMPONENT_CAMERA, "Unknown"); // TODO |
| 1596 | } |
Paramananda | c12b8b1 | 2015-03-24 17:51:29 +0530 | [diff] [blame] | 1597 | |
| 1598 | // Manage DRM rights while image selection changed. this |
| 1599 | // flow will comes for both image and video, but here |
| 1600 | // we will consume rights for image files only. |
| 1601 | // Do not consume rights of a GIF image and video here. |
| 1602 | // ViewGifImage will take care of GIF rights consumption stub. |
| 1603 | // MediaPlayer will handle the video rights consumption stub. |
Anand Chaudhari | 922a2fa | 2015-09-23 18:01:06 +0530 | [diff] [blame] | 1604 | // if ((mMediaSet != null && mMediaSet.getMediaItemCount() > 1) |
| 1605 | // || !(this instanceof SinglePhotoPage)) { |
| 1606 | // String mime = mCurrentPhoto.getMimeType(); |
| 1607 | // if (!TextUtils.isEmpty(mime) && !mime.equals("image/gif") |
| 1608 | // && !mime.startsWith("video/")) { |
| 1609 | // DrmHelper.manageDrmLicense(mActivity.getAndroidContext(), |
| 1610 | // mHandler, mCurrentPhoto.getFilePath(), |
| 1611 | // mCurrentPhoto.getMimeType()); |
| 1612 | // } |
| 1613 | // } |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1614 | } |
| 1615 | } |
| 1616 | |
| 1617 | private void transitionFromAlbumPageIfNeeded() { |
| 1618 | TransitionStore transitions = mActivity.getTransitionStore(); |
| 1619 | |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1620 | int albumPageTransition = transitions.get( |
| 1621 | KEY_ALBUMPAGE_TRANSITION, MSG_ALBUMPAGE_NONE); |
| 1622 | |
Bobby Georgescu | d81b264 | 2012-10-07 16:25:54 -0700 | [diff] [blame] | 1623 | if (albumPageTransition == MSG_ALBUMPAGE_NONE && mAppBridge != null |
| 1624 | && mRecenterCameraOnResume) { |
Bobby Georgescu | 00ccf35 | 2012-09-19 16:51:05 -0700 | [diff] [blame] | 1625 | // Generally, resuming the PhotoPage when in Camera should |
| 1626 | // reset to the capture mode to allow quick photo taking |
| 1627 | mCurrentIndex = 0; |
| 1628 | mPhotoView.resetToFirstPicture(); |
| 1629 | } else { |
| 1630 | int resumeIndex = transitions.get(KEY_INDEX_HINT, -1); |
| 1631 | if (resumeIndex >= 0) { |
Bobby Georgescu | 3ad7bbc | 2012-10-23 20:29:57 -0700 | [diff] [blame] | 1632 | if (mHasCameraScreennailOrPlaceholder) { |
Bobby Georgescu | 76f1881 | 2012-10-07 23:06:05 -0700 | [diff] [blame] | 1633 | // Account for preview/placeholder being the first item |
Bobby Georgescu | 00ccf35 | 2012-09-19 16:51:05 -0700 | [diff] [blame] | 1634 | resumeIndex++; |
| 1635 | } |
| 1636 | if (resumeIndex < mMediaSet.getMediaItemCount()) { |
| 1637 | mCurrentIndex = resumeIndex; |
| 1638 | mModel.moveTo(mCurrentIndex); |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | if (albumPageTransition == MSG_ALBUMPAGE_RESUMED) { |
| 1644 | mPhotoView.setFilmMode(mStartInFilmstrip || mAppBridge != null); |
| 1645 | } else if (albumPageTransition == MSG_ALBUMPAGE_PICKED) { |
| 1646 | mPhotoView.setFilmMode(false); |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1647 | } |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
Yuli Huang | bd7c016 | 2012-05-15 22:36:59 +0800 | [diff] [blame] | 1650 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1651 | protected void onResume() { |
| 1652 | super.onResume(); |
huiyan | 8782c24 | 2016-04-23 14:52:23 +0800 | [diff] [blame] | 1653 | //set full screen to hide the status bar |
| 1654 | showFullScreen(true); |
| 1655 | |
Bobby Georgescu | 7eea4d3 | 2012-09-06 17:14:02 -0700 | [diff] [blame] | 1656 | transitionFromAlbumPageIfNeeded(); |
| 1657 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1658 | mIsActive = true; |
| 1659 | setContentPane(mRootPane); |
Yuli Huang | 04ac045 | 2012-03-20 16:37:05 +0800 | [diff] [blame] | 1660 | |
huiyan | e9fa3d6 | 2016-04-13 12:48:07 +0800 | [diff] [blame] | 1661 | //if from TimeLinePage, don't show the timeline title |
| 1662 | if (mMediaSet != null && mIsFromTimelineScreen) { |
Kedi Xu | fece30c | 2016-10-21 15:13:32 +0800 | [diff] [blame] | 1663 | mMediaSet.setShowAlbumsetTimeTitle(false); |
huiyan | e9fa3d6 | 2016-04-13 12:48:07 +0800 | [diff] [blame] | 1664 | } |
Chao Zhang | 8788884 | 2016-05-18 17:31:21 +0800 | [diff] [blame] | 1665 | |
Wu-cheng Li | 898a2f4 | 2012-08-27 00:10:38 +0800 | [diff] [blame] | 1666 | mActionBar.setDisplayOptions( |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame] | 1667 | (false && (mSetPathString != null)), true); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1668 | mActionBar.addOnMenuVisibilityListener(mMenuVisibilityListener); |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 1669 | refreshBottomControlsWhenReady(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1670 | if (((mSecureAlbum == null) && (mSetPathString != null))) { |
Arne Coucheron | ccbf7a7 | 2017-07-13 01:36:11 +0200 | [diff] [blame^] | 1671 | ((GalleryActivity) mActivity).toggleNavBar(false); |
Bobby Georgescu | 9481d05 | 2012-10-02 16:28:20 -0700 | [diff] [blame] | 1672 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1673 | // if (mShowSpinner && mPhotoView.getFilmMode()) { |
| 1674 | // mActionBar.enableAlbumModeMenu( |
| 1675 | // GalleryActionBar.ALBUM_FILMSTRIP_MODE_SELECTED, this); |
| 1676 | // } |
Bobby Georgescu | 00ccf35 | 2012-09-19 16:51:05 -0700 | [diff] [blame] | 1677 | if (!mShowBars) { |
| 1678 | mActionBar.hide(); |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1679 | } |
John Reck | 8fe22ec | 2012-09-26 16:13:02 -0700 | [diff] [blame] | 1680 | boolean haveImageEditor = GalleryUtils.isEditorAvailable(mActivity, "image/*"); |
| 1681 | if (haveImageEditor != mHaveImageEditor) { |
| 1682 | mHaveImageEditor = haveImageEditor; |
| 1683 | updateMenuOperations(); |
| 1684 | } |
Bobby Georgescu | 00ccf35 | 2012-09-19 16:51:05 -0700 | [diff] [blame] | 1685 | |
Bobby Georgescu | d81b264 | 2012-10-07 16:25:54 -0700 | [diff] [blame] | 1686 | mRecenterCameraOnResume = true; |
Chao Zhang | 8788884 | 2016-05-18 17:31:21 +0800 | [diff] [blame] | 1687 | if (mModel == null) { |
| 1688 | onBackPressed(); |
| 1689 | return; |
| 1690 | } |
| 1691 | mModel.resume(); |
| 1692 | mPhotoView.resume(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1693 | } |
| 1694 | |
Chih-Chung Chang | 15b351a | 2012-03-15 16:38:45 +0800 | [diff] [blame] | 1695 | @Override |
| 1696 | protected void onDestroy() { |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1697 | if (mAppBridge != null) { |
Chih-Chung Chang | 253c5ae | 2012-05-16 17:37:10 -0700 | [diff] [blame] | 1698 | mAppBridge.setServer(null); |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 1699 | mScreenNailItem.setScreenNail(null); |
Chih-Chung Chang | bd141b5 | 2012-04-26 10:10:49 +0800 | [diff] [blame] | 1700 | mAppBridge.detachScreenNail(); |
| 1701 | mAppBridge = null; |
Chih-Chung Chang | 3b4a8ae | 2012-05-09 21:17:10 +0800 | [diff] [blame] | 1702 | mScreenNailSet = null; |
| 1703 | mScreenNailItem = null; |
Chih-Chung Chang | b29a27f | 2012-03-22 17:42:33 +0800 | [diff] [blame] | 1704 | } |
Chih-Chung Chang | 2ef46ed | 2012-05-08 17:57:33 +0800 | [diff] [blame] | 1705 | mActivity.getGLRoot().setOrientationSource(null); |
Bobby Georgescu | f44499d | 2012-09-17 18:12:11 -0700 | [diff] [blame] | 1706 | if (mBottomControls != null) mBottomControls.cleanup(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1707 | if (m3DButton != null) m3DButton.cleanup(); |
Kedi Xu | f1069d5 | 2016-09-26 19:53:51 +0800 | [diff] [blame] | 1708 | mPhotoView.destroy(); |
| 1709 | mPhotoView = null; |
Chih-Chung Chang | aeb3062 | 2012-05-03 11:41:05 +0800 | [diff] [blame] | 1710 | // Remove all pending messages. |
| 1711 | mHandler.removeCallbacksAndMessages(null); |
Chih-Chung Chang | 15b351a | 2012-03-15 16:38:45 +0800 | [diff] [blame] | 1712 | super.onDestroy(); |
| 1713 | } |
| 1714 | |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1715 | private class MyDetailsSource implements DetailsSource { |
Owen Lin | 6cf8074 | 2011-08-28 10:50:21 +0800 | [diff] [blame] | 1716 | |
| 1717 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1718 | public MediaDetails getDetails() { |
Owen Lin | 616a70f | 2012-05-07 16:35:53 +0800 | [diff] [blame] | 1719 | return mModel.getMediaItem(0).getDetails(); |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1720 | } |
Owen Lin | 6cf8074 | 2011-08-28 10:50:21 +0800 | [diff] [blame] | 1721 | |
| 1722 | @Override |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1723 | public int size() { |
| 1724 | return mMediaSet != null ? mMediaSet.getMediaItemCount() : 1; |
| 1725 | } |
Owen Lin | 6cf8074 | 2011-08-28 10:50:21 +0800 | [diff] [blame] | 1726 | |
| 1727 | @Override |
Michael Kolb | 995c456 | 2012-07-20 12:23:09 -0700 | [diff] [blame] | 1728 | public int setIndex() { |
| 1729 | return mModel.getCurrentIndex(); |
Ray Chen | 4105e22 | 2011-08-24 11:40:04 +0800 | [diff] [blame] | 1730 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1731 | } |
Bobby Georgescu | 3cf502a | 2012-10-01 15:50:11 -0700 | [diff] [blame] | 1732 | |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1733 | /*@Override |
Bobby Georgescu | 3cf502a | 2012-10-01 15:50:11 -0700 | [diff] [blame] | 1734 | public void onAlbumModeSelected(int mode) { |
| 1735 | if (mode == GalleryActionBar.ALBUM_GRID_MODE_SELECTED) { |
| 1736 | switchToGrid(); |
| 1737 | } |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 1738 | }*/ |
George Mount | 4b4dbd2 | 2012-10-18 14:20:39 -0700 | [diff] [blame] | 1739 | |
| 1740 | @Override |
| 1741 | public void refreshBottomControlsWhenReady() { |
| 1742 | if (mBottomControls == null) { |
| 1743 | return; |
| 1744 | } |
| 1745 | MediaObject currentPhoto = mCurrentPhoto; |
| 1746 | if (currentPhoto == null) { |
| 1747 | mHandler.obtainMessage(MSG_REFRESH_BOTTOM_CONTROLS, 0, 0, currentPhoto).sendToTarget(); |
| 1748 | } else { |
| 1749 | currentPhoto.getPanoramaSupport(mRefreshBottomControlsCallback); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | private void updatePanoramaUI(boolean isPanorama360) { |
| 1754 | Menu menu = mActionBar.getMenu(); |
| 1755 | |
| 1756 | // it could be null if onCreateActionBar has not been called yet |
| 1757 | if (menu == null) { |
| 1758 | return; |
| 1759 | } |
| 1760 | |
| 1761 | MenuExecutor.updateMenuForPanorama(menu, isPanorama360, isPanorama360); |
| 1762 | |
| 1763 | if (isPanorama360) { |
| 1764 | MenuItem item = menu.findItem(R.id.action_share); |
| 1765 | if (item != null) { |
| 1766 | item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); |
| 1767 | item.setTitle(mActivity.getResources().getString(R.string.share_as_photo)); |
| 1768 | } |
| 1769 | } else if ((mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_SHARE) != 0) { |
| 1770 | MenuItem item = menu.findItem(R.id.action_share); |
| 1771 | if (item != null) { |
| 1772 | item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); |
| 1773 | item.setTitle(mActivity.getResources().getString(R.string.share)); |
| 1774 | } |
| 1775 | } |
| 1776 | } |
Bobby Georgescu | 9495843 | 2012-10-23 20:52:26 -0700 | [diff] [blame] | 1777 | |
| 1778 | @Override |
| 1779 | public void onUndoBarVisibilityChanged(boolean visible) { |
| 1780 | refreshBottomControlsWhenReady(); |
| 1781 | } |
Flavio Lerda | 2251386 | 2013-04-16 09:46:07 +0100 | [diff] [blame] | 1782 | |
Flavio Lerda | 2251386 | 2013-04-16 09:46:07 +0100 | [diff] [blame] | 1783 | private static String getMediaTypeString(MediaItem item) { |
| 1784 | if (item.getMediaType() == MediaObject.MEDIA_TYPE_VIDEO) { |
| 1785 | return "Video"; |
| 1786 | } else if (item.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE) { |
| 1787 | return "Photo"; |
| 1788 | } else { |
| 1789 | return "Unknown:" + item.getMediaType(); |
| 1790 | } |
| 1791 | } |
| 1792 | |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1793 | private class ParseGDepthTask extends AsyncTask<Uri, Void, Boolean> { |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1794 | @Override |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1795 | protected Boolean doInBackground(Uri... params) { |
| 1796 | GDepth.Parser parser = new GDepth.Parser(); |
| 1797 | return parser.parse(mActivity, params[0]); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | @Override |
| 1801 | protected void onPostExecute(Boolean result) { |
Likai Ding | b7c13c2 | 2017-02-16 14:54:04 +0800 | [diff] [blame] | 1802 | bShow3DButton = !isCancelled() && result; |
| 1803 | m3DButton.refresh(); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 1804 | } |
| 1805 | } |
Likai Ding | b2e9100 | 2013-08-13 14:07:48 +0800 | [diff] [blame] | 1806 | |
| 1807 | private static void viewAnimateGif(Activity activity, Uri uri) { |
| 1808 | Intent intent = new Intent(ViewGifImage.VIEW_GIF_ACTION, uri); |
| 1809 | activity.startActivity(intent); |
| 1810 | } |
Owen Lin | f9a0a43 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1811 | } |