blob: 04892378a296ee3bace6d9e9f7bfca559fbef9cf [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 {
Arne Coucheronccbf7a72017-07-13 01:36:11 +0200209 mBottomNavigation.setVisibility(View.GONE);
chaoz8804f682016-01-15 18:15:33 +0800210 }
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530211 }
212
213 public void showScreen(int position) {
214 if (position > 2) {
215 position = 1;
216 }
217 // Bundle data = new Bundle();
218 // int clusterType;
219 // String newPath;
220 String basePath = getDataManager().getTopSetPath(
221 DataManager.INCLUDE_ALL);
222 switch (position) {
223
224 case 0:
225 startTimelinePage(); //Timeline view
226 break;
227 case 1:
228 startAlbumPage(); // Albums View
229 break;
230 case 2:
231 startVideoPage(); // Videos view
232 break;
233 default:
234 break;
235 }
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530236 }
237
238 public static int getActionTitle(Context context, int type) {
239 for (ActionItem item : sActionItems) {
240 if (item.action == type) {
241 return item.title;
242 }
243 }
244 return -1;
245 }
246
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700247 private void initializeByIntent() {
248 Intent intent = getIntent();
249 String action = intent.getAction();
250
251 if (Intent.ACTION_GET_CONTENT.equalsIgnoreCase(action)) {
chaoz8804f682016-01-15 18:15:33 +0800252 mDrawerLayoutSupported = false;
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700253 startGetContent(intent);
Joey Rizzoli0a421722016-06-01 14:04:38 +0200254 toggleNavBar(false);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700255 } else if (Intent.ACTION_PICK.equalsIgnoreCase(action)) {
chaoz8804f682016-01-15 18:15:33 +0800256 mDrawerLayoutSupported = false;
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700257 // We do NOT really support the PICK intent. Handle it as
258 // the GET_CONTENT. However, we need to translate the type
259 // in the intent here.
260 Log.w(TAG, "action PICK is not supported");
261 String type = Utils.ensureNotNull(intent.getType());
262 if (type.startsWith("vnd.android.cursor.dir/")) {
263 if (type.endsWith("/image")) intent.setType("image/*");
264 if (type.endsWith("/video")) intent.setType("video/*");
265 }
266 startGetContent(intent);
Joey Rizzoli0a421722016-06-01 14:04:38 +0200267 toggleNavBar(false);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700268 } else if (Intent.ACTION_VIEW.equalsIgnoreCase(action)
269 || ACTION_REVIEW.equalsIgnoreCase(action)){
chaoz8804f682016-01-15 18:15:33 +0800270 mDrawerLayoutSupported = false;
jinwu4fafa7a2017-04-07 13:27:48 +0800271 Uri uri = intent.getData();
zhuw85237072017-06-16 11:30:42 +0800272 if (uri != null) {
273 int flag = intent.getFlags();
274 int match = sURIMatcher.match(uri);
275 if ((match == ALL_DOWNLOADS || match == ALL_DOWNLOADS_ID) &&
276 (flag & Intent.FLAG_GRANT_READ_URI_PERMISSION) == 0) {
277 if (checkCallingOrSelfPermission(
278 PERMISSION_ACCESS_ALL) != PackageManager.PERMISSION_GRANTED) {
279 Log.w(TAG, "no permission to view: " + uri);
280 return;
281 }
jinwu4fafa7a2017-04-07 13:27:48 +0800282 }
zhuw85237072017-06-16 11:30:42 +0800283 } else {
284 Log.w(TAG, "uri get from intent is null");
jinwu4fafa7a2017-04-07 13:27:48 +0800285 }
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700286 startViewAction(intent);
Joey Rizzoli0a421722016-06-01 14:04:38 +0200287 toggleNavBar(false);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700288 } else {
chaoz8804f682016-01-15 18:15:33 +0800289 mDrawerLayoutSupported = true;
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530290 startTimelinePage();
291 mToolbar.setTitle(R.string.albums_title);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700292 }
Joey Rizzoli0a421722016-06-01 14:04:38 +0200293 toggleNavBar(mDrawerLayoutSupported);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700294 }
295
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530296 public void startAlbumPage() {
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700297 PicasaSource.showSignInReminder(this);
298 Bundle data = new Bundle();
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530299 int clusterType = FilterUtils.CLUSTER_BY_ALBUM;
300 data.putString(AlbumSetPage.KEY_MEDIA_PATH, getDataManager()
301 .getTopSetPath(DataManager.INCLUDE_ALL));
302 if (getStateManager().getStateCount() == 0)
303 getStateManager().startState(AlbumSetPage.class, data);
304 else {
305 ActivityState state = getStateManager().getTopState();
306 String oldClass = state.getClass().getSimpleName();
307 String newClass = AlbumSetPage.class.getSimpleName();
308 if (!oldClass.equals(newClass)) {
309 getStateManager().switchState(getStateManager().getTopState(),
310 AlbumSetPage.class, data);
311 }
312 }
313 mVersionCheckDialog = PicasaSource.getVersionCheckDialog(this);
314 if (mVersionCheckDialog != null) {
315 mVersionCheckDialog.setOnCancelListener(this);
316 }
317 }
318
319 private void startTimelinePage() {
320 String newBPath = getDataManager().getTopSetPath(DataManager.INCLUDE_ALL);
321 String newPath = FilterUtils.switchClusterPath(newBPath, FilterUtils.CLUSTER_BY_TIME);
322 Bundle data = new Bundle();
323 data.putString(TimeLinePage.KEY_MEDIA_PATH, newPath);
324 if (getStateManager().getStateCount() == 0)
325 getStateManager().startState(TimeLinePage.class, data);
326 else {
327 ActivityState state = getStateManager().getTopState();
328 String oldClass = state.getClass().getSimpleName();
329 String newClass = TimeLinePage.class.getSimpleName();
330 if (!oldClass.equals(newClass)) {
331 getStateManager().switchState(getStateManager().getTopState(),
332 TimeLinePage.class, data);
333 }
334 }
335 mVersionCheckDialog = PicasaSource.getVersionCheckDialog(this);
336 if (mVersionCheckDialog != null) {
337 mVersionCheckDialog.setOnCancelListener(this);
338 }
339 }
340
341 public void startVideoPage() {
342 PicasaSource.showSignInReminder(this);
343 String basePath = getDataManager().getTopSetPath(
344 DataManager.INCLUDE_ALL);
345 Bundle data = new Bundle();
346 int clusterType = FilterUtils.CLUSTER_BY_VIDEOS;
347 String newPath = FilterUtils.switchClusterPath(basePath, clusterType);
348 data.putString(AlbumPage.KEY_MEDIA_PATH, newPath);
349 data.putBoolean(AlbumPage.KEY_IS_VIDEOS_SCREEN, true);
350 ActivityState state = getStateManager().getTopState();
351 String oldClass = state.getClass().getSimpleName();
352 String newClass = AlbumPage.class.getSimpleName();
353 if (!oldClass.equals(newClass)) {
354 getStateManager().switchState(getStateManager().getTopState(),
355 AlbumPage.class, data);
356 }
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700357 mVersionCheckDialog = PicasaSource.getVersionCheckDialog(this);
358 if (mVersionCheckDialog != null) {
359 mVersionCheckDialog.setOnCancelListener(this);
360 }
361 }
362
363 private void startGetContent(Intent intent) {
364 Bundle data = intent.getExtras() != null
365 ? new Bundle(intent.getExtras())
366 : new Bundle();
367 data.putBoolean(KEY_GET_CONTENT, true);
368 int typeBits = GalleryUtils.determineTypeBits(this, intent);
369 data.putInt(KEY_TYPE_BITS, typeBits);
370 data.putString(AlbumSetPage.KEY_MEDIA_PATH,
371 getDataManager().getTopSetPath(typeBits));
372 getStateManager().startState(AlbumSetPage.class, data);
373 }
374
375 private String getContentType(Intent intent) {
376 String type = intent.getType();
377 if (type != null) {
378 return GalleryUtils.MIME_TYPE_PANORAMA360.equals(type)
379 ? MediaItem.MIME_TYPE_JPEG : type;
380 }
381
382 Uri uri = intent.getData();
383 try {
384 return getContentResolver().getType(uri);
385 } catch (Throwable t) {
386 Log.w(TAG, "get type fail", t);
387 return null;
388 }
389 }
390
391 private void startViewAction(Intent intent) {
392 Boolean slideshow = intent.getBooleanExtra(EXTRA_SLIDESHOW, false);
393 if (slideshow) {
394 getActionBar().hide();
395 DataManager manager = getDataManager();
396 Path path = manager.findPathByUri(intent.getData(), intent.getType());
397 if (path == null || manager.getMediaObject(path)
398 instanceof MediaItem) {
399 path = Path.fromString(
400 manager.getTopSetPath(DataManager.INCLUDE_IMAGE));
401 }
402 Bundle data = new Bundle();
403 data.putString(SlideshowPage.KEY_SET_PATH, path.toString());
404 data.putBoolean(SlideshowPage.KEY_RANDOM_ORDER, true);
405 data.putBoolean(SlideshowPage.KEY_REPEAT, true);
406 if (intent.getBooleanExtra(EXTRA_DREAM, false)) {
407 data.putBoolean(SlideshowPage.KEY_DREAM, true);
408 }
409 getStateManager().startState(SlideshowPage.class, data);
410 } else {
411 Bundle data = new Bundle();
412 DataManager dm = getDataManager();
413 Uri uri = intent.getData();
414 String contentType = getContentType(intent);
415 if (contentType == null) {
416 Toast.makeText(this,
417 R.string.no_such_item, Toast.LENGTH_LONG).show();
418 finish();
419 return;
420 }
421 if (uri == null) {
422 int typeBits = GalleryUtils.determineTypeBits(this, intent);
423 data.putInt(KEY_TYPE_BITS, typeBits);
424 data.putString(AlbumSetPage.KEY_MEDIA_PATH,
425 getDataManager().getTopSetPath(typeBits));
426 getStateManager().startState(AlbumSetPage.class, data);
427 } else if (contentType.startsWith(
428 ContentResolver.CURSOR_DIR_BASE_TYPE)) {
429 int mediaType = intent.getIntExtra(KEY_MEDIA_TYPES, 0);
430 if (mediaType != 0) {
431 uri = uri.buildUpon().appendQueryParameter(
432 KEY_MEDIA_TYPES, String.valueOf(mediaType))
433 .build();
434 }
435 Path setPath = dm.findPathByUri(uri, null);
436 MediaSet mediaSet = null;
437 if (setPath != null) {
438 mediaSet = (MediaSet) dm.getMediaObject(setPath);
439 }
440 if (mediaSet != null) {
441 if (mediaSet.isLeafAlbum()) {
442 data.putString(AlbumPage.KEY_MEDIA_PATH, setPath.toString());
443 data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH,
444 dm.getTopSetPath(DataManager.INCLUDE_ALL));
445 getStateManager().startState(AlbumPage.class, data);
446 } else {
447 data.putString(AlbumSetPage.KEY_MEDIA_PATH, setPath.toString());
448 getStateManager().startState(AlbumSetPage.class, data);
449 }
450 } else {
Ravi Banuri49f14dd2015-10-21 15:54:59 +0530451 startTimelinePage();
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700452 }
453 } else {
Paramanandac12b8b12015-03-24 17:51:29 +0530454 Path itemPath = dm.findPathByUri(uri, contentType);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700455 Path albumPath = dm.getDefaultSetOf(itemPath);
456
457 data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, itemPath.toString());
Byunghun Jeond699b6a2015-02-24 16:46:04 -0800458 if (!intent.getBooleanExtra(KEY_FROM_SNAPCAM, false)) {
459 data.putBoolean(PhotoPage.KEY_READONLY, true);
wangjing03d43a02015-04-03 14:42:17 +0800460 } else {
461 int hintIndex = 0;
462 if (View.LAYOUT_DIRECTION_RTL == TextUtils
463 .getLayoutDirectionFromLocale(Locale.getDefault())) {
464 hintIndex = intent.getIntExtra(KEY_TOTAL_NUMBER, 1) - 1;
465 }
466 data.putInt(PhotoPage.KEY_INDEX_HINT, hintIndex);
Byunghun Jeond699b6a2015-02-24 16:46:04 -0800467 }
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700468
469 // TODO: Make the parameter "SingleItemOnly" public so other
470 // activities can reference it.
471 boolean singleItemOnly = (albumPath == null)
472 || intent.getBooleanExtra("SingleItemOnly", false);
473 if (!singleItemOnly) {
474 data.putString(PhotoPage.KEY_MEDIA_SET_PATH, albumPath.toString());
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700475 }
lihai260fcaa2015-08-20 08:54:29 +0800476 data.putBoolean("SingleItemOnly", singleItemOnly);
huiyan391b17f2016-05-31 17:54:38 +0800477 // set the cover View to black
478 View cover = findViewById(R.id.gl_root_cover);
479 cover.setBackgroundColor(Color.BLACK);
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700480 getStateManager().startState(SinglePhotoPage.class, data);
481 }
482 }
483 }
484
485 @Override
486 protected void onResume() {
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700487 super.onResume();
488 if (mVersionCheckDialog != null) {
489 mVersionCheckDialog.show();
490 }
491 }
492
493 @Override
494 protected void onPause() {
495 super.onPause();
496 if (mVersionCheckDialog != null) {
497 mVersionCheckDialog.dismiss();
498 }
499 }
500
501 @Override
Jay Wang642c4212015-09-24 14:56:06 -0700502 protected void onDestroy() {
Jay Wang642c4212015-09-24 14:56:06 -0700503 super.onDestroy();
504 }
505
506 @Override
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700507 public void onCancel(DialogInterface dialog) {
508 if (dialog == mVersionCheckDialog) {
509 mVersionCheckDialog = null;
510 }
511 }
512
513 @Override
514 public boolean onGenericMotionEvent(MotionEvent event) {
515 final boolean isTouchPad = (event.getSource()
516 & InputDevice.SOURCE_CLASS_POSITION) != 0;
517 if (isTouchPad) {
518 float maxX = event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax();
519 float maxY = event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax();
520 View decor = getWindow().getDecorView();
521 float scaleX = decor.getWidth() / maxX;
522 float scaleY = decor.getHeight() / maxY;
523 float x = event.getX() * scaleX;
524 //x = decor.getWidth() - x; // invert x
525 float y = event.getY() * scaleY;
526 //y = decor.getHeight() - y; // invert y
527 MotionEvent touchEvent = MotionEvent.obtain(event.getDownTime(),
528 event.getEventTime(), event.getAction(), x, y, event.getMetaState());
529 return dispatchTouchEvent(touchEvent);
530 }
531 return super.onGenericMotionEvent(event);
532 }
Mangesh Ghiware06c02762013-09-11 15:59:59 -0700533}