blob: d4b5087827d3de9acfc87c613fcbae09731881f3 [file] [log] [blame]
Mangesh Ghiware06c02762013-09-11 15:59:59 -07001/*
jinwu4fafa7a2017-04-07 13:27:48 +08002 * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Ravi Banuri49f14dd2015-10-21 15:54:59 +05303 * Not a Contribution
4 *
Mangesh Ghiware06c02762013-09-11 15:59:59 -07005 * Copyright (C) 2009 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20package com.android.gallery3d.app;
21
22import android.app.Dialog;
23import android.content.ContentResolver;
Jay Wang642c4212015-09-24 14:56:06 -070024import android.content.Context;
Mangesh Ghiware06c02762013-09-11 15:59:59 -070025import android.content.DialogInterface;
26import android.content.DialogInterface.OnCancelListener;
27import android.content.Intent;
jinwu4fafa7a2017-04-07 13:27:48 +080028import android.content.UriMatcher;
Likai Ding80eaa182016-02-25 15:01:30 +080029import android.content.pm.PackageManager;
huiyan391b17f2016-05-31 17:54:38 +080030import android.graphics.Color;
Mangesh Ghiware06c02762013-09-11 15:59:59 -070031import android.net.Uri;
32import android.os.Bundle;
Joey Rizzoli0a421722016-06-01 14:04:38 +020033import android.support.design.widget.BottomNavigationView;
Likai Ding711aee72016-05-18 13:47:56 +080034import android.support.v4.widget.DrawerLayout;
35import android.support.v4.widget.DrawerLayout.DrawerListener;
Jay Wang642c4212015-09-24 14:56:06 -070036import android.text.TextUtils;
37import android.util.Log;
Ravi Banuri49f14dd2015-10-21 15:54:59 +053038import android.view.Gravity;
Mangesh Ghiware06c02762013-09-11 15:59:59 -070039import android.view.InputDevice;
Ravi Banuri49f14dd2015-10-21 15:54:59 +053040import android.view.LayoutInflater;
Joey Rizzoli0a421722016-06-01 14:04:38 +020041import android.view.MenuItem;
Mangesh Ghiware06c02762013-09-11 15:59:59 -070042import android.view.MotionEvent;
43import android.view.View;
Likai Ding711aee72016-05-18 13:47:56 +080044import android.view.View.OnClickListener;
Ravi Banuri49f14dd2015-10-21 15:54:59 +053045import android.view.ViewGroup;
Mangesh Ghiware06c02762013-09-11 15:59:59 -070046import android.view.WindowManager;
Ravi Banuri49f14dd2015-10-21 15:54:59 +053047import android.widget.AdapterView;
48import android.widget.BaseAdapter;
Ravi Banuri49f14dd2015-10-21 15:54:59 +053049import android.widget.ImageView;
50import android.widget.ListView;
Joey Rizzoli0a421722016-06-01 14:04:38 +020051import android.widget.RelativeLayout;
52import android.widget.RelativeLayout.LayoutParams;
Ravi Banuri49f14dd2015-10-21 15:54:59 +053053import android.widget.TextView;
Mangesh Ghiware06c02762013-09-11 15:59:59 -070054import android.widget.Toast;
Ravi Banuri49f14dd2015-10-21 15:54:59 +053055import android.widget.Toolbar;
Mangesh Ghiware06c02762013-09-11 15:59:59 -070056
Likai Dingc83b5b72016-05-25 14:48:41 +080057import org.codeaurora.gallery.R;
Mangesh Ghiware06c02762013-09-11 15:59:59 -070058import com.android.gallery3d.common.Utils;
59import com.android.gallery3d.data.DataManager;
60import com.android.gallery3d.data.MediaItem;
61import com.android.gallery3d.data.MediaSet;
62import com.android.gallery3d.data.Path;
63import com.android.gallery3d.picasasource.PicasaSource;
64import com.android.gallery3d.util.GalleryUtils;
65
Likai Ding711aee72016-05-18 13:47:56 +080066import java.util.Locale;
67
Mangesh Ghiware06c02762013-09-11 15:59:59 -070068public final class GalleryActivity extends AbstractGalleryActivity implements OnCancelListener {
69 public static final String EXTRA_SLIDESHOW = "slideshow";
70 public static final String EXTRA_DREAM = "dream";
71 public static final String EXTRA_CROP = "crop";
72
73 public static final String ACTION_REVIEW = "com.android.camera.action.REVIEW";
74 public static final String KEY_GET_CONTENT = "get-content";
75 public static final String KEY_GET_ALBUM = "get-album";
76 public static final String KEY_TYPE_BITS = "type-bits";
77 public static final String KEY_MEDIA_TYPES = "mediaTypes";
78 public static final String KEY_DISMISS_KEYGUARD = "dismiss-keyguard";
Byunghun Jeond699b6a2015-02-24 16:46:04 -080079 public static final String KEY_FROM_SNAPCAM = "from-snapcam";
wangjing03d43a02015-04-03 14:42:17 +080080 public static final String KEY_TOTAL_NUMBER = "total-number";
zhuwa429ce02017-07-11 16:45:59 +080081 public static final String QSST = "QSST";
Mangesh Ghiware06c02762013-09-11 15:59:59 -070082
jinwu4fafa7a2017-04-07 13:27:48 +080083 private static final int ALL_DOWNLOADS = 1;
84 private static final int ALL_DOWNLOADS_ID = 2;
85 private static final UriMatcher sURIMatcher =
86 new UriMatcher(UriMatcher.NO_MATCH);
87 public static final String PERMISSION_ACCESS_ALL =
88 "android.permission.ACCESS_ALL_DOWNLOADS";
89 static {
90 sURIMatcher.addURI("downloads", "all_downloads", ALL_DOWNLOADS);
91 sURIMatcher.addURI("downloads", "all_downloads/#", ALL_DOWNLOADS_ID);
92 }
93
Mangesh Ghiware06c02762013-09-11 15:59:59 -070094 private static final String TAG = "GalleryActivity";
95 private Dialog mVersionCheckDialog;
Ravi Banuri49f14dd2015-10-21 15:54:59 +053096 private ListView mDrawerListView;
97 private DrawerLayout mDrawerLayout;
98 public static boolean mIsparentActivityFInishing;
Ravi Banuri49f14dd2015-10-21 15:54:59 +053099 public Toolbar mToolbar;
Joey Rizzoli0a421722016-06-01 14:04:38 +0200100
101 private BottomNavigationView mBottomNavigation;
102 private RelativeLayout mGLParentLayout;
103 private RelativeLayout.LayoutParams params;
104
chaoz8804f682016-01-15 18:15:33 +0800105 /** DrawerLayout is not supported in some entrances.
106 * such as Intent.ACTION_VIEW, Intent.ACTION_GET_CONTENT, Intent.PICK. */
107 private boolean mDrawerLayoutSupported = true;
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700108
Likai Ding80eaa182016-02-25 15:01:30 +0800109 private static final int PERMISSION_REQUEST_STORAGE = 1;
110 private Bundle mSavedInstanceState;
zhuw8d0e4ce2017-12-20 16:31:43 +0800111 private boolean mIsViewInited = false;
Likai Ding80eaa182016-02-25 15:01:30 +0800112
113
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700114 @Override
115 protected void onCreate(Bundle savedInstanceState) {
116 super.onCreate(savedInstanceState);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700117
118 if (getIntent().getBooleanExtra(KEY_DISMISS_KEYGUARD, false)) {
119 getWindow().addFlags(
120 WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
121 }
122
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530123 setContentView(R.layout.gallery_main);
124 initView();
zhuw8d0e4ce2017-12-20 16:31:43 +0800125 mIsViewInited = true;
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700126
Likai Ding80eaa182016-02-25 15:01:30 +0800127 mSavedInstanceState = savedInstanceState;
zhuw50ebf4b2016-08-23 18:42:01 +0800128 if (isPermissionGranted()) {
Likai Ding80eaa182016-02-25 15:01:30 +0800129 init();
130 }
131 }
132
133 private void init() {
134 if (mSavedInstanceState != null) {
135 getStateManager().restoreFromState(mSavedInstanceState);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700136 } else {
137 initializeByIntent();
138 }
Likai Ding80eaa182016-02-25 15:01:30 +0800139 mSavedInstanceState = null;
140 }
141
142 @Override
zhuw50ebf4b2016-08-23 18:42:01 +0800143 protected void onGetPermissionsSuccess() {
zhuw8d0e4ce2017-12-20 16:31:43 +0800144 if (mIsViewInited) {
145 init();
146 }
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700147 }
148
zhuw50ebf4b2016-08-23 18:42:01 +0800149 @Override
150 protected void onGetPermissionsFailure() {
151 finish();
Chao Zhang0404c642016-04-07 20:55:03 +0800152 }
153
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530154 private static class ActionItem {
155 public int action;
156 public int title;
157 public int icon;
158
159 public ActionItem(int action, int title, int icon) {
160 this.action = action;
161 this.title = title;
162 this.icon = icon;
163 }
164 }
165
166 private static final ActionItem[] sActionItems = new ActionItem[] {
167 new ActionItem(FilterUtils.CLUSTER_BY_TIME,
168 R.string.timeline_title, R.drawable.timeline),
169 new ActionItem(FilterUtils.CLUSTER_BY_ALBUM, R.string.albums_title,
170 R.drawable.albums),
171 new ActionItem(FilterUtils.CLUSTER_BY_VIDEOS,
172 R.string.videos_title, R.drawable.videos) };
173
174 public void initView() {
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530175 mToolbar = (Toolbar) findViewById(R.id.toolbar);
176 setActionBar(mToolbar);
Joey Rizzoli0a421722016-06-01 14:04:38 +0200177 setToolbar(mToolbar);
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530178
Joey Rizzoli0a421722016-06-01 14:04:38 +0200179 mGLParentLayout = (RelativeLayout) findViewById(R.id.gl_parent_layout);
180 params = (RelativeLayout.LayoutParams) mGLParentLayout.getLayoutParams();
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530181
Joey Rizzoli0a421722016-06-01 14:04:38 +0200182 mBottomNavigation = (BottomNavigationView) findViewById(R.id.bottom_navigation);
183 mBottomNavigation.setOnNavigationItemSelectedListener(
184 new BottomNavigationView.OnNavigationItemSelectedListener() {
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530185 @Override
Joey Rizzoli0a421722016-06-01 14:04:38 +0200186 public boolean onNavigationItemSelected(MenuItem item) {
187 getGLRoot().lockRenderThread();
188 switch (item.getItemId()) {
189 case R.id.action_timeline:
190 showScreen(0);
191 break;
192 case R.id.action_album:
193 showScreen(1);
194 break;
195 case R.id.action_videos:
196 showScreen(2);
197 break;
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530198 }
Joey Rizzoli0a421722016-06-01 14:04:38 +0200199 getGLRoot().unlockRenderThread();
200 return true;
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530201 }
202 });
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530203 }
204
Joey Rizzoli0a421722016-06-01 14:04:38 +0200205 public void toggleNavBar(boolean show) {
206 if (show) {
207 mBottomNavigation.setVisibility(View.VISIBLE);
208 } else {
209 mBottomNavigation.setVisibility(View.INVISIBLE);
chaoz8804f682016-01-15 18:15:33 +0800210 }
Joey Rizzoli0a421722016-06-01 14:04:38 +0200211
212 // Convert dp to pixels
213 float dp = getApplicationContext().getResources().getDisplayMetrics().density;
214
215 params.setMargins(0, 0, 0, show ? Math.round(56 * dp) : 0);
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530216 }
217
218 public void showScreen(int position) {
219 if (position > 2) {
220 position = 1;
221 }
222 // Bundle data = new Bundle();
223 // int clusterType;
224 // String newPath;
225 String basePath = getDataManager().getTopSetPath(
226 DataManager.INCLUDE_ALL);
227 switch (position) {
228
229 case 0:
230 startTimelinePage(); //Timeline view
231 break;
232 case 1:
233 startAlbumPage(); // Albums View
234 break;
235 case 2:
236 startVideoPage(); // Videos view
237 break;
238 default:
239 break;
240 }
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530241 }
242
243 public static int getActionTitle(Context context, int type) {
244 for (ActionItem item : sActionItems) {
245 if (item.action == type) {
246 return item.title;
247 }
248 }
249 return -1;
250 }
251
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700252 private void initializeByIntent() {
253 Intent intent = getIntent();
254 String action = intent.getAction();
255
256 if (Intent.ACTION_GET_CONTENT.equalsIgnoreCase(action)) {
chaoz8804f682016-01-15 18:15:33 +0800257 mDrawerLayoutSupported = false;
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700258 startGetContent(intent);
Joey Rizzoli0a421722016-06-01 14:04:38 +0200259 toggleNavBar(false);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700260 } else if (Intent.ACTION_PICK.equalsIgnoreCase(action)) {
chaoz8804f682016-01-15 18:15:33 +0800261 mDrawerLayoutSupported = false;
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700262 // We do NOT really support the PICK intent. Handle it as
263 // the GET_CONTENT. However, we need to translate the type
264 // in the intent here.
265 Log.w(TAG, "action PICK is not supported");
266 String type = Utils.ensureNotNull(intent.getType());
267 if (type.startsWith("vnd.android.cursor.dir/")) {
268 if (type.endsWith("/image")) intent.setType("image/*");
269 if (type.endsWith("/video")) intent.setType("video/*");
270 }
271 startGetContent(intent);
Joey Rizzoli0a421722016-06-01 14:04:38 +0200272 toggleNavBar(false);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700273 } else if (Intent.ACTION_VIEW.equalsIgnoreCase(action)
274 || ACTION_REVIEW.equalsIgnoreCase(action)){
chaoz8804f682016-01-15 18:15:33 +0800275 mDrawerLayoutSupported = false;
jinwu4fafa7a2017-04-07 13:27:48 +0800276 Uri uri = intent.getData();
zhuw85237072017-06-16 11:30:42 +0800277 if (uri != null) {
278 int flag = intent.getFlags();
279 int match = sURIMatcher.match(uri);
280 if ((match == ALL_DOWNLOADS || match == ALL_DOWNLOADS_ID) &&
281 (flag & Intent.FLAG_GRANT_READ_URI_PERMISSION) == 0) {
282 if (checkCallingOrSelfPermission(
283 PERMISSION_ACCESS_ALL) != PackageManager.PERMISSION_GRANTED) {
284 Log.w(TAG, "no permission to view: " + uri);
285 return;
286 }
jinwu4fafa7a2017-04-07 13:27:48 +0800287 }
zhuw85237072017-06-16 11:30:42 +0800288 } else {
289 Log.w(TAG, "uri get from intent is null");
jinwu4fafa7a2017-04-07 13:27:48 +0800290 }
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700291 startViewAction(intent);
Joey Rizzoli0a421722016-06-01 14:04:38 +0200292 toggleNavBar(false);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700293 } else {
chaoz8804f682016-01-15 18:15:33 +0800294 mDrawerLayoutSupported = true;
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530295 startTimelinePage();
296 mToolbar.setTitle(R.string.albums_title);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700297 }
Joey Rizzoli0a421722016-06-01 14:04:38 +0200298 toggleNavBar(mDrawerLayoutSupported);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700299 }
300
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530301 public void startAlbumPage() {
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700302 PicasaSource.showSignInReminder(this);
303 Bundle data = new Bundle();
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530304 int clusterType = FilterUtils.CLUSTER_BY_ALBUM;
305 data.putString(AlbumSetPage.KEY_MEDIA_PATH, getDataManager()
306 .getTopSetPath(DataManager.INCLUDE_ALL));
307 if (getStateManager().getStateCount() == 0)
308 getStateManager().startState(AlbumSetPage.class, data);
309 else {
310 ActivityState state = getStateManager().getTopState();
311 String oldClass = state.getClass().getSimpleName();
312 String newClass = AlbumSetPage.class.getSimpleName();
313 if (!oldClass.equals(newClass)) {
314 getStateManager().switchState(getStateManager().getTopState(),
315 AlbumSetPage.class, data);
316 }
317 }
318 mVersionCheckDialog = PicasaSource.getVersionCheckDialog(this);
319 if (mVersionCheckDialog != null) {
320 mVersionCheckDialog.setOnCancelListener(this);
321 }
322 }
323
324 private void startTimelinePage() {
325 String newBPath = getDataManager().getTopSetPath(DataManager.INCLUDE_ALL);
326 String newPath = FilterUtils.switchClusterPath(newBPath, FilterUtils.CLUSTER_BY_TIME);
327 Bundle data = new Bundle();
328 data.putString(TimeLinePage.KEY_MEDIA_PATH, newPath);
329 if (getStateManager().getStateCount() == 0)
330 getStateManager().startState(TimeLinePage.class, data);
331 else {
332 ActivityState state = getStateManager().getTopState();
333 String oldClass = state.getClass().getSimpleName();
334 String newClass = TimeLinePage.class.getSimpleName();
335 if (!oldClass.equals(newClass)) {
336 getStateManager().switchState(getStateManager().getTopState(),
337 TimeLinePage.class, data);
338 }
339 }
340 mVersionCheckDialog = PicasaSource.getVersionCheckDialog(this);
341 if (mVersionCheckDialog != null) {
342 mVersionCheckDialog.setOnCancelListener(this);
343 }
344 }
345
346 public void startVideoPage() {
347 PicasaSource.showSignInReminder(this);
348 String basePath = getDataManager().getTopSetPath(
349 DataManager.INCLUDE_ALL);
350 Bundle data = new Bundle();
351 int clusterType = FilterUtils.CLUSTER_BY_VIDEOS;
352 String newPath = FilterUtils.switchClusterPath(basePath, clusterType);
353 data.putString(AlbumPage.KEY_MEDIA_PATH, newPath);
354 data.putBoolean(AlbumPage.KEY_IS_VIDEOS_SCREEN, true);
355 ActivityState state = getStateManager().getTopState();
356 String oldClass = state.getClass().getSimpleName();
357 String newClass = AlbumPage.class.getSimpleName();
358 if (!oldClass.equals(newClass)) {
359 getStateManager().switchState(getStateManager().getTopState(),
360 AlbumPage.class, data);
361 }
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700362 mVersionCheckDialog = PicasaSource.getVersionCheckDialog(this);
363 if (mVersionCheckDialog != null) {
364 mVersionCheckDialog.setOnCancelListener(this);
365 }
366 }
367
368 private void startGetContent(Intent intent) {
369 Bundle data = intent.getExtras() != null
370 ? new Bundle(intent.getExtras())
371 : new Bundle();
372 data.putBoolean(KEY_GET_CONTENT, true);
373 int typeBits = GalleryUtils.determineTypeBits(this, intent);
374 data.putInt(KEY_TYPE_BITS, typeBits);
375 data.putString(AlbumSetPage.KEY_MEDIA_PATH,
376 getDataManager().getTopSetPath(typeBits));
377 getStateManager().startState(AlbumSetPage.class, data);
378 }
379
380 private String getContentType(Intent intent) {
381 String type = intent.getType();
382 if (type != null) {
383 return GalleryUtils.MIME_TYPE_PANORAMA360.equals(type)
384 ? MediaItem.MIME_TYPE_JPEG : type;
385 }
386
387 Uri uri = intent.getData();
388 try {
389 return getContentResolver().getType(uri);
390 } catch (Throwable t) {
391 Log.w(TAG, "get type fail", t);
392 return null;
393 }
394 }
395
396 private void startViewAction(Intent intent) {
397 Boolean slideshow = intent.getBooleanExtra(EXTRA_SLIDESHOW, false);
398 if (slideshow) {
399 getActionBar().hide();
400 DataManager manager = getDataManager();
401 Path path = manager.findPathByUri(intent.getData(), intent.getType());
402 if (path == null || manager.getMediaObject(path)
403 instanceof MediaItem) {
404 path = Path.fromString(
405 manager.getTopSetPath(DataManager.INCLUDE_IMAGE));
406 }
407 Bundle data = new Bundle();
408 data.putString(SlideshowPage.KEY_SET_PATH, path.toString());
409 data.putBoolean(SlideshowPage.KEY_RANDOM_ORDER, true);
410 data.putBoolean(SlideshowPage.KEY_REPEAT, true);
411 if (intent.getBooleanExtra(EXTRA_DREAM, false)) {
412 data.putBoolean(SlideshowPage.KEY_DREAM, true);
413 }
414 getStateManager().startState(SlideshowPage.class, data);
415 } else {
416 Bundle data = new Bundle();
417 DataManager dm = getDataManager();
418 Uri uri = intent.getData();
419 String contentType = getContentType(intent);
420 if (contentType == null) {
421 Toast.makeText(this,
422 R.string.no_such_item, Toast.LENGTH_LONG).show();
423 finish();
424 return;
425 }
426 if (uri == null) {
427 int typeBits = GalleryUtils.determineTypeBits(this, intent);
428 data.putInt(KEY_TYPE_BITS, typeBits);
429 data.putString(AlbumSetPage.KEY_MEDIA_PATH,
430 getDataManager().getTopSetPath(typeBits));
431 getStateManager().startState(AlbumSetPage.class, data);
432 } else if (contentType.startsWith(
433 ContentResolver.CURSOR_DIR_BASE_TYPE)) {
434 int mediaType = intent.getIntExtra(KEY_MEDIA_TYPES, 0);
435 if (mediaType != 0) {
436 uri = uri.buildUpon().appendQueryParameter(
437 KEY_MEDIA_TYPES, String.valueOf(mediaType))
438 .build();
439 }
440 Path setPath = dm.findPathByUri(uri, null);
441 MediaSet mediaSet = null;
442 if (setPath != null) {
443 mediaSet = (MediaSet) dm.getMediaObject(setPath);
444 }
445 if (mediaSet != null) {
446 if (mediaSet.isLeafAlbum()) {
447 data.putString(AlbumPage.KEY_MEDIA_PATH, setPath.toString());
448 data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH,
449 dm.getTopSetPath(DataManager.INCLUDE_ALL));
450 getStateManager().startState(AlbumPage.class, data);
451 } else {
452 data.putString(AlbumSetPage.KEY_MEDIA_PATH, setPath.toString());
453 getStateManager().startState(AlbumSetPage.class, data);
454 }
455 } else {
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530456 startTimelinePage();
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700457 }
458 } else {
Paramanandac12b8b12015-03-24 17:51:29 +0530459 Path itemPath = dm.findPathByUri(uri, contentType);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700460 Path albumPath = dm.getDefaultSetOf(itemPath);
461
462 data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, itemPath.toString());
Byunghun Jeond699b6a2015-02-24 16:46:04 -0800463 if (!intent.getBooleanExtra(KEY_FROM_SNAPCAM, false)) {
464 data.putBoolean(PhotoPage.KEY_READONLY, true);
wangjing03d43a02015-04-03 14:42:17 +0800465 } else {
466 int hintIndex = 0;
467 if (View.LAYOUT_DIRECTION_RTL == TextUtils
468 .getLayoutDirectionFromLocale(Locale.getDefault())) {
469 hintIndex = intent.getIntExtra(KEY_TOTAL_NUMBER, 1) - 1;
470 }
471 data.putInt(PhotoPage.KEY_INDEX_HINT, hintIndex);
Byunghun Jeond699b6a2015-02-24 16:46:04 -0800472 }
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700473
474 // TODO: Make the parameter "SingleItemOnly" public so other
475 // activities can reference it.
476 boolean singleItemOnly = (albumPath == null)
477 || intent.getBooleanExtra("SingleItemOnly", false);
478 if (!singleItemOnly) {
479 data.putString(PhotoPage.KEY_MEDIA_SET_PATH, albumPath.toString());
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700480 }
lihai260fcaa2015-08-20 08:54:29 +0800481 data.putBoolean("SingleItemOnly", singleItemOnly);
huiyan391b17f2016-05-31 17:54:38 +0800482 // set the cover View to black
483 View cover = findViewById(R.id.gl_root_cover);
484 cover.setBackgroundColor(Color.BLACK);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700485 getStateManager().startState(SinglePhotoPage.class, data);
486 }
487 }
488 }
489
490 @Override
491 protected void onResume() {
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700492 super.onResume();
493 if (mVersionCheckDialog != null) {
494 mVersionCheckDialog.show();
495 }
496 }
497
498 @Override
499 protected void onPause() {
500 super.onPause();
501 if (mVersionCheckDialog != null) {
502 mVersionCheckDialog.dismiss();
503 }
504 }
505
506 @Override
Jay Wang642c4212015-09-24 14:56:06 -0700507 protected void onDestroy() {
Jay Wang642c4212015-09-24 14:56:06 -0700508 super.onDestroy();
509 }
510
511 @Override
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700512 public void onCancel(DialogInterface dialog) {
513 if (dialog == mVersionCheckDialog) {
514 mVersionCheckDialog = null;
515 }
516 }
517
518 @Override
519 public boolean onGenericMotionEvent(MotionEvent event) {
520 final boolean isTouchPad = (event.getSource()
521 & InputDevice.SOURCE_CLASS_POSITION) != 0;
522 if (isTouchPad) {
523 float maxX = event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax();
524 float maxY = event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax();
525 View decor = getWindow().getDecorView();
526 float scaleX = decor.getWidth() / maxX;
527 float scaleY = decor.getHeight() / maxY;
528 float x = event.getX() * scaleX;
529 //x = decor.getWidth() - x; // invert x
530 float y = event.getY() * scaleY;
531 //y = decor.getHeight() - y; // invert y
532 MotionEvent touchEvent = MotionEvent.obtain(event.getDownTime(),
533 event.getEventTime(), event.getAction(), x, y, event.getMetaState());
534 return dispatchTouchEvent(touchEvent);
535 }
536 return super.onGenericMotionEvent(event);
537 }
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700538}