Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 1 | /* |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 2 | * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 3 | * Not a Contribution |
| 4 | * |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 5 | * 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 | |
| 20 | package com.android.gallery3d.app; |
| 21 | |
| 22 | import android.app.Dialog; |
| 23 | import android.content.ContentResolver; |
Jay Wang | 642c421 | 2015-09-24 14:56:06 -0700 | [diff] [blame] | 24 | import android.content.Context; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 25 | import android.content.DialogInterface; |
| 26 | import android.content.DialogInterface.OnCancelListener; |
| 27 | import android.content.Intent; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 28 | import android.content.UriMatcher; |
Likai Ding | 80eaa18 | 2016-02-25 15:01:30 +0800 | [diff] [blame] | 29 | import android.content.pm.PackageManager; |
huiyan | 391b17f | 2016-05-31 17:54:38 +0800 | [diff] [blame] | 30 | import android.graphics.Color; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 31 | import android.net.Uri; |
| 32 | import android.os.Bundle; |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 33 | import android.support.design.widget.BottomNavigationView; |
Likai Ding | 711aee7 | 2016-05-18 13:47:56 +0800 | [diff] [blame] | 34 | import android.support.v4.widget.DrawerLayout; |
| 35 | import android.support.v4.widget.DrawerLayout.DrawerListener; |
Jay Wang | 642c421 | 2015-09-24 14:56:06 -0700 | [diff] [blame] | 36 | import android.text.TextUtils; |
| 37 | import android.util.Log; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 38 | import android.view.Gravity; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 39 | import android.view.InputDevice; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 40 | import android.view.LayoutInflater; |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 41 | import android.view.MenuItem; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 42 | import android.view.MotionEvent; |
| 43 | import android.view.View; |
Likai Ding | 711aee7 | 2016-05-18 13:47:56 +0800 | [diff] [blame] | 44 | import android.view.View.OnClickListener; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 45 | import android.view.ViewGroup; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 46 | import android.view.WindowManager; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 47 | import android.widget.AdapterView; |
| 48 | import android.widget.BaseAdapter; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 49 | import android.widget.ImageView; |
| 50 | import android.widget.ListView; |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 51 | import android.widget.RelativeLayout; |
| 52 | import android.widget.RelativeLayout.LayoutParams; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 53 | import android.widget.TextView; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 54 | import android.widget.Toast; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 55 | import android.widget.Toolbar; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 56 | |
Likai Ding | c83b5b7 | 2016-05-25 14:48:41 +0800 | [diff] [blame] | 57 | import org.codeaurora.gallery.R; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 58 | import com.android.gallery3d.common.Utils; |
| 59 | import com.android.gallery3d.data.DataManager; |
| 60 | import com.android.gallery3d.data.MediaItem; |
| 61 | import com.android.gallery3d.data.MediaSet; |
| 62 | import com.android.gallery3d.data.Path; |
| 63 | import com.android.gallery3d.picasasource.PicasaSource; |
| 64 | import com.android.gallery3d.util.GalleryUtils; |
| 65 | |
Likai Ding | 711aee7 | 2016-05-18 13:47:56 +0800 | [diff] [blame] | 66 | import java.util.Locale; |
| 67 | |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 68 | public 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 Jeon | d699b6a | 2015-02-24 16:46:04 -0800 | [diff] [blame] | 79 | public static final String KEY_FROM_SNAPCAM = "from-snapcam"; |
wangjing | 03d43a0 | 2015-04-03 14:42:17 +0800 | [diff] [blame] | 80 | public static final String KEY_TOTAL_NUMBER = "total-number"; |
zhuw | a429ce0 | 2017-07-11 16:45:59 +0800 | [diff] [blame] | 81 | public static final String QSST = "QSST"; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 82 | |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 83 | 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 Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 94 | private static final String TAG = "GalleryActivity"; |
| 95 | private Dialog mVersionCheckDialog; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 96 | private ListView mDrawerListView; |
| 97 | private DrawerLayout mDrawerLayout; |
| 98 | public static boolean mIsparentActivityFInishing; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 99 | public Toolbar mToolbar; |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 100 | |
| 101 | private BottomNavigationView mBottomNavigation; |
| 102 | private RelativeLayout mGLParentLayout; |
| 103 | private RelativeLayout.LayoutParams params; |
| 104 | |
chaoz | 8804f68 | 2016-01-15 18:15:33 +0800 | [diff] [blame] | 105 | /** 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 Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 108 | |
Likai Ding | 80eaa18 | 2016-02-25 15:01:30 +0800 | [diff] [blame] | 109 | private static final int PERMISSION_REQUEST_STORAGE = 1; |
| 110 | private Bundle mSavedInstanceState; |
zhuw | 8d0e4ce | 2017-12-20 16:31:43 +0800 | [diff] [blame] | 111 | private boolean mIsViewInited = false; |
Likai Ding | 80eaa18 | 2016-02-25 15:01:30 +0800 | [diff] [blame] | 112 | |
| 113 | |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 114 | @Override |
| 115 | protected void onCreate(Bundle savedInstanceState) { |
| 116 | super.onCreate(savedInstanceState); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 117 | |
| 118 | if (getIntent().getBooleanExtra(KEY_DISMISS_KEYGUARD, false)) { |
| 119 | getWindow().addFlags( |
| 120 | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); |
| 121 | } |
| 122 | |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 123 | setContentView(R.layout.gallery_main); |
| 124 | initView(); |
zhuw | 8d0e4ce | 2017-12-20 16:31:43 +0800 | [diff] [blame] | 125 | mIsViewInited = true; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 126 | |
Likai Ding | 80eaa18 | 2016-02-25 15:01:30 +0800 | [diff] [blame] | 127 | mSavedInstanceState = savedInstanceState; |
zhuw | 50ebf4b | 2016-08-23 18:42:01 +0800 | [diff] [blame] | 128 | if (isPermissionGranted()) { |
Likai Ding | 80eaa18 | 2016-02-25 15:01:30 +0800 | [diff] [blame] | 129 | init(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | private void init() { |
| 134 | if (mSavedInstanceState != null) { |
| 135 | getStateManager().restoreFromState(mSavedInstanceState); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 136 | } else { |
| 137 | initializeByIntent(); |
| 138 | } |
Likai Ding | 80eaa18 | 2016-02-25 15:01:30 +0800 | [diff] [blame] | 139 | mSavedInstanceState = null; |
| 140 | } |
| 141 | |
| 142 | @Override |
zhuw | 50ebf4b | 2016-08-23 18:42:01 +0800 | [diff] [blame] | 143 | protected void onGetPermissionsSuccess() { |
zhuw | 8d0e4ce | 2017-12-20 16:31:43 +0800 | [diff] [blame] | 144 | if (mIsViewInited) { |
| 145 | init(); |
| 146 | } |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 147 | } |
| 148 | |
zhuw | 50ebf4b | 2016-08-23 18:42:01 +0800 | [diff] [blame] | 149 | @Override |
| 150 | protected void onGetPermissionsFailure() { |
| 151 | finish(); |
Chao Zhang | 0404c64 | 2016-04-07 20:55:03 +0800 | [diff] [blame] | 152 | } |
| 153 | |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 154 | 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 Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 175 | mToolbar = (Toolbar) findViewById(R.id.toolbar); |
| 176 | setActionBar(mToolbar); |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 177 | setToolbar(mToolbar); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 178 | |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 179 | mGLParentLayout = (RelativeLayout) findViewById(R.id.gl_parent_layout); |
| 180 | params = (RelativeLayout.LayoutParams) mGLParentLayout.getLayoutParams(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 181 | |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 182 | mBottomNavigation = (BottomNavigationView) findViewById(R.id.bottom_navigation); |
| 183 | mBottomNavigation.setOnNavigationItemSelectedListener( |
| 184 | new BottomNavigationView.OnNavigationItemSelectedListener() { |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 185 | @Override |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 186 | 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 Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 198 | } |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 199 | getGLRoot().unlockRenderThread(); |
| 200 | return true; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 201 | } |
| 202 | }); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 203 | } |
| 204 | |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 205 | public void toggleNavBar(boolean show) { |
| 206 | if (show) { |
| 207 | mBottomNavigation.setVisibility(View.VISIBLE); |
| 208 | } else { |
| 209 | mBottomNavigation.setVisibility(View.INVISIBLE); |
chaoz | 8804f68 | 2016-01-15 18:15:33 +0800 | [diff] [blame] | 210 | } |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 211 | |
| 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 Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 216 | } |
| 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 Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 241 | } |
| 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 Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 252 | private void initializeByIntent() { |
| 253 | Intent intent = getIntent(); |
| 254 | String action = intent.getAction(); |
| 255 | |
| 256 | if (Intent.ACTION_GET_CONTENT.equalsIgnoreCase(action)) { |
chaoz | 8804f68 | 2016-01-15 18:15:33 +0800 | [diff] [blame] | 257 | mDrawerLayoutSupported = false; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 258 | startGetContent(intent); |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 259 | toggleNavBar(false); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 260 | } else if (Intent.ACTION_PICK.equalsIgnoreCase(action)) { |
chaoz | 8804f68 | 2016-01-15 18:15:33 +0800 | [diff] [blame] | 261 | mDrawerLayoutSupported = false; |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 262 | // 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 Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 272 | toggleNavBar(false); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 273 | } else if (Intent.ACTION_VIEW.equalsIgnoreCase(action) |
| 274 | || ACTION_REVIEW.equalsIgnoreCase(action)){ |
chaoz | 8804f68 | 2016-01-15 18:15:33 +0800 | [diff] [blame] | 275 | mDrawerLayoutSupported = false; |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 276 | Uri uri = intent.getData(); |
zhuw | 8523707 | 2017-06-16 11:30:42 +0800 | [diff] [blame] | 277 | 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 | } |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 287 | } |
zhuw | 8523707 | 2017-06-16 11:30:42 +0800 | [diff] [blame] | 288 | } else { |
| 289 | Log.w(TAG, "uri get from intent is null"); |
jinwu | 4fafa7a | 2017-04-07 13:27:48 +0800 | [diff] [blame] | 290 | } |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 291 | startViewAction(intent); |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 292 | toggleNavBar(false); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 293 | } else { |
chaoz | 8804f68 | 2016-01-15 18:15:33 +0800 | [diff] [blame] | 294 | mDrawerLayoutSupported = true; |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 295 | startTimelinePage(); |
| 296 | mToolbar.setTitle(R.string.albums_title); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 297 | } |
Joey Rizzoli | 0a42172 | 2016-06-01 14:04:38 +0200 | [diff] [blame^] | 298 | toggleNavBar(mDrawerLayoutSupported); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 301 | public void startAlbumPage() { |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 302 | PicasaSource.showSignInReminder(this); |
| 303 | Bundle data = new Bundle(); |
Ravi Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 304 | 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 Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 362 | 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 Banuri | 49f14dd | 2015-10-21 15:54:59 +0530 | [diff] [blame] | 456 | startTimelinePage(); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 457 | } |
| 458 | } else { |
Paramananda | c12b8b1 | 2015-03-24 17:51:29 +0530 | [diff] [blame] | 459 | Path itemPath = dm.findPathByUri(uri, contentType); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 460 | Path albumPath = dm.getDefaultSetOf(itemPath); |
| 461 | |
| 462 | data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, itemPath.toString()); |
Byunghun Jeon | d699b6a | 2015-02-24 16:46:04 -0800 | [diff] [blame] | 463 | if (!intent.getBooleanExtra(KEY_FROM_SNAPCAM, false)) { |
| 464 | data.putBoolean(PhotoPage.KEY_READONLY, true); |
wangjing | 03d43a0 | 2015-04-03 14:42:17 +0800 | [diff] [blame] | 465 | } 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 Jeon | d699b6a | 2015-02-24 16:46:04 -0800 | [diff] [blame] | 472 | } |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 473 | |
| 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 Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 480 | } |
lihai | 260fcaa | 2015-08-20 08:54:29 +0800 | [diff] [blame] | 481 | data.putBoolean("SingleItemOnly", singleItemOnly); |
huiyan | 391b17f | 2016-05-31 17:54:38 +0800 | [diff] [blame] | 482 | // set the cover View to black |
| 483 | View cover = findViewById(R.id.gl_root_cover); |
| 484 | cover.setBackgroundColor(Color.BLACK); |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 485 | getStateManager().startState(SinglePhotoPage.class, data); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | protected void onResume() { |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 492 | 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 Wang | 642c421 | 2015-09-24 14:56:06 -0700 | [diff] [blame] | 507 | protected void onDestroy() { |
Jay Wang | 642c421 | 2015-09-24 14:56:06 -0700 | [diff] [blame] | 508 | super.onDestroy(); |
| 509 | } |
| 510 | |
| 511 | @Override |
Mangesh Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 512 | 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 Ghiware | 06c0276 | 2013-09-11 15:59:59 -0700 | [diff] [blame] | 538 | } |