Intents.java revision bb137c8e2ed363e6f5e2c0f14719483d27e8c062
1f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein/* 2f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Copyright (C) 2011 Google Inc. 3f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Licensed to The Android Open Source Project. 4f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * 5f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Licensed under the Apache License, Version 2.0 (the "License"); 6f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * you may not use this file except in compliance with the License. 7f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * You may obtain a copy of the License at 8f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * 9f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * http://www.apache.org/licenses/LICENSE-2.0 10f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * 11f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Unless required by applicable law or agreed to in writing, software 12f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * distributed under the License is distributed on an "AS IS" BASIS, 13f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * See the License for the specific language governing permissions and 15f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * limitations under the License. 16f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */ 17f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 18f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinpackage com.android.ex.photo; 19f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 205c16562ccda53e0f204490c2218f0f8127169dd8Martin Hibdonimport android.app.Activity; 21f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport android.content.ContentProvider; 22f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport android.content.Context; 23f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport android.content.Intent; 24f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 25f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport com.android.ex.photo.fragments.PhotoViewFragment; 26f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 27f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein/** 28f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Build intents to start app activities 29f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */ 308670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon 31f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinpublic class Intents { 32f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein // Intent extras 33f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static final String EXTRA_PHOTO_INDEX = "photo_index"; 3499f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon public static final String EXTRA_INITIAL_PHOTO_URI = "initial_photo_uri"; 35f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static final String EXTRA_PHOTOS_URI = "photos_uri"; 36f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static final String EXTRA_RESOLVED_PHOTO_URI = "resolved_photo_uri"; 37f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static final String EXTRA_PROJECTION = "projection"; 38928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein public static final String EXTRA_THUMBNAIL_URI = "thumbnail_uri"; 3991dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp public static final String EXTRA_MAX_INITIAL_SCALE = "max_scale"; 407732839c0cd9d87954a07e166b52b93cabea1374Adam Copp public static final String EXTRA_WATCH_NETWORK = "watch_network"; 41f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 42ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 43ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // Parameters affecting the intro/exit animation 44ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public static final String EXTRA_SCALE_UP_ANIMATION = "scale_up_animation"; 458670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon public static final String EXTRA_ANIMATION_START_X = "start_x_extra"; 468670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon public static final String EXTRA_ANIMATION_START_Y = "start_y_extra"; 478670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon public static final String EXTRA_ANIMATION_START_WIDTH = "start_width_extra"; 488670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon public static final String EXTRA_ANIMATION_START_HEIGHT = "start_height_extra"; 49ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 50ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // Parameters affecting the display and features 51ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public static final String EXTRA_ACTION_BAR_HIDDEN_INITIALLY = "action_bar_hidden_initially"; 52ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public static final String EXTRA_DISPLAY_THUMBS_FULLSCREEN = "display_thumbs_fullscreen"; 53ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 54f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** 55f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Gets a photo view intent builder to display the photos from phone activity. 56f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * 57f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * @param context The context 58f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * @return The intent builder 59f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */ 60f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static PhotoViewIntentBuilder newPhotoViewActivityIntentBuilder(Context context) { 61f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return new PhotoViewIntentBuilder(context, PhotoViewActivity.class); 62f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 63f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 64f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** 65f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Gets a photo view intent builder to display the photo view fragment 66f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * 67f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * @param context The context 68f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * @return The intent builder 69f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */ 70f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static PhotoViewIntentBuilder newPhotoViewFragmentIntentBuilder(Context context) { 71bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood return newPhotoViewFragmentIntentBuilder(context, PhotoViewFragment.class); 72bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood } 73bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood 74bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood /** 75bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * Gets a photo view intent builder to display the photo view fragment with a custom fragment 76bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * subclass. 77bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * 78bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * @param context The context 79bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * @param clazz Subclass of PhotoViewFragment to use 80bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * @return The intent builder 81bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood */ 82bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood public static PhotoViewIntentBuilder newPhotoViewFragmentIntentBuilder(Context context, 83bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood Class<? extends PhotoViewFragment> clazz) { 84bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood return new PhotoViewIntentBuilder(context, clazz); 85f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 86f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 87f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Gets a new photo view intent builder */ 88f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static PhotoViewIntentBuilder newPhotoViewIntentBuilder( 895c16562ccda53e0f204490c2218f0f8127169dd8Martin Hibdon Context context, Class<? extends Activity> cls) { 90f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return new PhotoViewIntentBuilder(context, cls); 91f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 92f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 936893051dad361413e483425bad0c27272596bb5cPaul Westbrook /** Gets a new photo view intent builder */ 946893051dad361413e483425bad0c27272596bb5cPaul Westbrook public static PhotoViewIntentBuilder newPhotoViewIntentBuilder( 956893051dad361413e483425bad0c27272596bb5cPaul Westbrook Context context, String activityName) { 966893051dad361413e483425bad0c27272596bb5cPaul Westbrook return new PhotoViewIntentBuilder(context, activityName); 976893051dad361413e483425bad0c27272596bb5cPaul Westbrook } 986893051dad361413e483425bad0c27272596bb5cPaul Westbrook 99f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Builder to create a photo view intent */ 100f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static class PhotoViewIntentBuilder { 101f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private final Intent mIntent; 102f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 103f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** The index of the photo to show */ 104f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private Integer mPhotoIndex; 10599f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon /** The URI of the initial photo to show */ 10699f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon private String mInitialPhotoUri; 107ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon /** The URI of the initial thumbnail to show */ 108ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private String mInitialThumbnailUri; 109f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** The URI of the group of photos to display */ 110f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private String mPhotosUri; 111f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** The URL of the photo to display */ 112f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private String mResolvedPhotoUri; 113f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** The projection for the query to use; optional */ 114f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private String[] mProjection; 115928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein /** The URI of a thumbnail of the photo to display */ 116928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein private String mThumbnailUri; 11791dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp /** The maximum scale to display images at before */ 11891dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp private Float mMaxInitialScale; 1197732839c0cd9d87954a07e166b52b93cabea1374Adam Copp /** 1207732839c0cd9d87954a07e166b52b93cabea1374Adam Copp * True if the PhotoViewFragments should watch for network changes to restart their loaders 1217732839c0cd9d87954a07e166b52b93cabea1374Adam Copp */ 1227732839c0cd9d87954a07e166b52b93cabea1374Adam Copp private boolean mWatchNetwork; 123ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon /** true we want to run the image scale animation */ 124ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private boolean mScaleAnimation; 125ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon /** The parameters for performing the scale up/scale down animations 126ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon * upon enter and exit. StartX and StartY represent the screen coordinates 127ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon * of the upper left corner of the start rectangle, startWidth and startHeight 128ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon * represent the width and height of the start rectangle. 129ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon */ 130ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private int mStartX; 131ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private int mStartY; 132ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private int mStartWidth; 133ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private int mStartHeight; 134ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 135ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private boolean mActionBarHiddenInitially; 136ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private boolean mDisplayFullScreenThumbs; 137f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 138f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private PhotoViewIntentBuilder(Context context, Class<?> cls) { 139f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent = new Intent(context, cls); 1406893051dad361413e483425bad0c27272596bb5cPaul Westbrook initialize(); 1416893051dad361413e483425bad0c27272596bb5cPaul Westbrook } 1426893051dad361413e483425bad0c27272596bb5cPaul Westbrook 1436893051dad361413e483425bad0c27272596bb5cPaul Westbrook private PhotoViewIntentBuilder(Context context, String activityName) { 1446893051dad361413e483425bad0c27272596bb5cPaul Westbrook mIntent = new Intent(); 1456893051dad361413e483425bad0c27272596bb5cPaul Westbrook mIntent.setClassName(context, activityName); 1466893051dad361413e483425bad0c27272596bb5cPaul Westbrook initialize(); 1476893051dad361413e483425bad0c27272596bb5cPaul Westbrook } 1486893051dad361413e483425bad0c27272596bb5cPaul Westbrook 1496893051dad361413e483425bad0c27272596bb5cPaul Westbrook private void initialize() { 150ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mScaleAnimation = false; 151ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mActionBarHiddenInitially = false; 152ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mDisplayFullScreenThumbs = false; 153f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 154f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 155f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Sets the photo index */ 156f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public PhotoViewIntentBuilder setPhotoIndex(Integer photoIndex) { 157f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mPhotoIndex = photoIndex; 158f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return this; 159f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 160f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 16199f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon /** Sets the initial photo URI */ 16299f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon public PhotoViewIntentBuilder setInitialPhotoUri(String initialPhotoUri) { 16399f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon mInitialPhotoUri = initialPhotoUri; 16499f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon return this; 16599f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon } 16699f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon 167f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Sets the photos URI */ 168f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public PhotoViewIntentBuilder setPhotosUri(String photosUri) { 169f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mPhotosUri = photosUri; 170f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return this; 171f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 172f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 173f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Sets the query projection */ 174f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public PhotoViewIntentBuilder setProjection(String[] projection) { 175f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mProjection = projection; 176f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return this; 177f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 178f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 179f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Sets the resolved photo URI. This method is for the case 180f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * where the URI given to {@link PhotoViewActivity} points directly 181f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * to a single image and does not need to be resolved via a query 182f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * to the {@link ContentProvider}. If this value is set, it supersedes 183f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * {@link #setPhotosUri(String)}. */ 184f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public PhotoViewIntentBuilder setResolvedPhotoUri(String resolvedPhotoUri) { 185f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mResolvedPhotoUri = resolvedPhotoUri; 186f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return this; 187f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 188f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 189928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein /** 190928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein * Sets the URI for a thumbnail preview of the photo. 191928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein */ 192928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein public PhotoViewIntentBuilder setThumbnailUri(String thumbnailUri) { 193928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein mThumbnailUri = thumbnailUri; 194928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein return this; 195928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein } 196928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein 19791dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp /** 19891dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp * Sets the maximum scale which an image is initially displayed at 19991dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp */ 20091dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp public PhotoViewIntentBuilder setMaxInitialScale(float maxScale) { 20191dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp mMaxInitialScale = maxScale; 20291dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp return this; 20391dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp } 20491dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp 2057732839c0cd9d87954a07e166b52b93cabea1374Adam Copp /** 2067732839c0cd9d87954a07e166b52b93cabea1374Adam Copp * Enable watching the network for connectivity changes. 2077732839c0cd9d87954a07e166b52b93cabea1374Adam Copp * 2087732839c0cd9d87954a07e166b52b93cabea1374Adam Copp * When a change is detected, bitmap loaders will be restarted if required. 2097732839c0cd9d87954a07e166b52b93cabea1374Adam Copp */ 2107732839c0cd9d87954a07e166b52b93cabea1374Adam Copp public PhotoViewIntentBuilder watchNetworkConnectivityChanges() { 2117732839c0cd9d87954a07e166b52b93cabea1374Adam Copp mWatchNetwork = true; 2126c056da7dd8d6a48b792050fa671a35781483fc2Martin Hibdon return this; 213ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon } 214ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 215f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian /** 216f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * Enable a scale animation that animates the initial photo URI passed in using 217f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * {@link #setInitialPhotoUri}. 218f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * 219f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * Note: To avoid janky transitions, particularly when exiting the photoviewer, ensure the 220f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * following system UI flags are set on the root view of the relying app's activity 221f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * (via @{link View.setSystemUiVisibility(int)}): 222f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * {@code View.SYSTEM_UI_FLAG_VISIBLE | View.SYSTEM_UI_FLAG_LAYOUT_STABLE} 223f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * As well, client should ensure {@code android:fitsSystemWindows} is set on the root 224f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * content view. 225f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian */ 226ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public PhotoViewIntentBuilder setScaleAnimation(int startX, int startY, 227ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon int startWidth, int startHeight) { 228ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mScaleAnimation = true; 229ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mStartX = startX; 230ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mStartY = startY; 231ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mStartWidth = startWidth; 232ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mStartHeight = startHeight; 233ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon return this; 234ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon } 235ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 236ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // If this option is turned on, then the photoViewer will be initially 237ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // displayed with the action bar hidden. This is as opposed to the default 238ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // behavior, where the actionBar is initially shown. 239ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public PhotoViewIntentBuilder setActionBarHiddenInitially( 240ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon boolean actionBarHiddenInitially) { 241ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mActionBarHiddenInitially = actionBarHiddenInitially; 242ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon return this; 243ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon } 244ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 245ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // If this option is turned on, then the small, lo-res thumbnail will 246ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // be scaled up to the maximum size to cover as much of the screen as 247ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // possible while still maintaining the correct aspect ratio. This means 248ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // that the image may appear blurry until the the full-res image is 249ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // loaded. 250ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // This is as opposed to the default behavior, where only part of the 251ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // thumbnail is displayed in a small view in the center of the screen, 252ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // and a loading spinner is displayed until the full-res image is loaded. 253ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public PhotoViewIntentBuilder setDisplayThumbsFullScreen( 254ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon boolean displayFullScreenThumbs) { 255ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mDisplayFullScreenThumbs = displayFullScreenThumbs; 2567732839c0cd9d87954a07e166b52b93cabea1374Adam Copp return this; 2577732839c0cd9d87954a07e166b52b93cabea1374Adam Copp } 2587732839c0cd9d87954a07e166b52b93cabea1374Adam Copp 259f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Build the intent */ 260f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public Intent build() { 261f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.setAction(Intent.ACTION_VIEW); 262f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 263f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 264f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 265f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein if (mPhotoIndex != null) { 266f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.putExtra(EXTRA_PHOTO_INDEX, (int) mPhotoIndex); 267f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 268f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 26999f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon if (mInitialPhotoUri != null) { 27099f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon mIntent.putExtra(EXTRA_INITIAL_PHOTO_URI, mInitialPhotoUri); 27199f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon } 27299f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon 27399f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon if (mInitialPhotoUri != null && mPhotoIndex != null) { 27499f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon throw new IllegalStateException( 27599f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon "specified both photo index and photo uri"); 27699f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon } 27799f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon 278f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein if (mPhotosUri != null) { 279f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.putExtra(EXTRA_PHOTOS_URI, mPhotosUri); 280f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 281f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 282f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein if (mResolvedPhotoUri != null) { 283f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.putExtra(EXTRA_RESOLVED_PHOTO_URI, mResolvedPhotoUri); 284f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 285f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 286f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein if (mProjection != null) { 287f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.putExtra(EXTRA_PROJECTION, mProjection); 288f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 289f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 290928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein if (mThumbnailUri != null) { 291928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein mIntent.putExtra(EXTRA_THUMBNAIL_URI, mThumbnailUri); 292928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein } 293928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein 29491dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp if (mMaxInitialScale != null) { 29591dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp mIntent.putExtra(EXTRA_MAX_INITIAL_SCALE, mMaxInitialScale); 29691dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp } 29791dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp 2987732839c0cd9d87954a07e166b52b93cabea1374Adam Copp if (mWatchNetwork == true) { 2997732839c0cd9d87954a07e166b52b93cabea1374Adam Copp mIntent.putExtra(EXTRA_WATCH_NETWORK, true); 3007732839c0cd9d87954a07e166b52b93cabea1374Adam Copp } 3017732839c0cd9d87954a07e166b52b93cabea1374Adam Copp 302ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_SCALE_UP_ANIMATION, mScaleAnimation); 303ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon if (mScaleAnimation) { 304ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ANIMATION_START_X, mStartX); 305ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ANIMATION_START_Y, mStartY); 306ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ANIMATION_START_WIDTH, mStartWidth); 307ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ANIMATION_START_HEIGHT, mStartHeight); 308ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon } 309ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 310ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ACTION_BAR_HIDDEN_INITIALLY, mActionBarHiddenInitially); 311ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_DISPLAY_THUMBS_FULLSCREEN, mDisplayFullScreenThumbs); 312ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 313f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return mIntent; 314f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 315f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 316f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein} 317