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; 244a6abe405e4de31a14e2c5489c413c806f2f11f2Andrew Sappersteinimport android.net.Uri; 25f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 26f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinimport com.android.ex.photo.fragments.PhotoViewFragment; 27f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 28f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein/** 29f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Build intents to start app activities 30f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */ 318670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon 32f77a7eb196d16110c7b1087352b423913821ff61Andrew Sappersteinpublic class Intents { 33f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein // Intent extras 34f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static final String EXTRA_PHOTO_INDEX = "photo_index"; 3599f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon public static final String EXTRA_INITIAL_PHOTO_URI = "initial_photo_uri"; 36f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static final String EXTRA_PHOTOS_URI = "photos_uri"; 37f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static final String EXTRA_RESOLVED_PHOTO_URI = "resolved_photo_uri"; 38f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static final String EXTRA_PROJECTION = "projection"; 39928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein public static final String EXTRA_THUMBNAIL_URI = "thumbnail_uri"; 4091dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp public static final String EXTRA_MAX_INITIAL_SCALE = "max_scale"; 417732839c0cd9d87954a07e166b52b93cabea1374Adam Copp public static final String EXTRA_WATCH_NETWORK = "watch_network"; 428650d3cda75562489551ee04bff9145a49a6f16fKen Thai public static final String EXTRA_ENABLE_TIMER_LIGHTS_OUT = "enable_timer_lights_out"; 43f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 44ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 45ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // Parameters affecting the intro/exit animation 46ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public static final String EXTRA_SCALE_UP_ANIMATION = "scale_up_animation"; 478670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon public static final String EXTRA_ANIMATION_START_X = "start_x_extra"; 488670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon public static final String EXTRA_ANIMATION_START_Y = "start_y_extra"; 498670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon public static final String EXTRA_ANIMATION_START_WIDTH = "start_width_extra"; 508670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon public static final String EXTRA_ANIMATION_START_HEIGHT = "start_height_extra"; 51ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 52ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // Parameters affecting the display and features 53ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public static final String EXTRA_ACTION_BAR_HIDDEN_INITIALLY = "action_bar_hidden_initially"; 54ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public static final String EXTRA_DISPLAY_THUMBS_FULLSCREEN = "display_thumbs_fullscreen"; 55ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 56f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** 57f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Gets a photo view intent builder to display the photos from phone activity. 58f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * 59f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * @param context The context 60f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * @return The intent builder 61f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */ 62f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static PhotoViewIntentBuilder newPhotoViewActivityIntentBuilder(Context context) { 63f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return new PhotoViewIntentBuilder(context, PhotoViewActivity.class); 64f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 65f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 66f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** 67f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * Gets a photo view intent builder to display the photo view fragment 68f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * 69f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * @param context The context 70f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * @return The intent builder 71f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein */ 72f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static PhotoViewIntentBuilder newPhotoViewFragmentIntentBuilder(Context context) { 73bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood return newPhotoViewFragmentIntentBuilder(context, PhotoViewFragment.class); 74bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood } 75bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood 76bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood /** 77bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * Gets a photo view intent builder to display the photo view fragment with a custom fragment 78bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * subclass. 79bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * 80bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * @param context The context 81bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * @param clazz Subclass of PhotoViewFragment to use 82bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood * @return The intent builder 83bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood */ 84bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood public static PhotoViewIntentBuilder newPhotoViewFragmentIntentBuilder(Context context, 85bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood Class<? extends PhotoViewFragment> clazz) { 86bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood return new PhotoViewIntentBuilder(context, clazz); 87f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 88f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 89f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Gets a new photo view intent builder */ 90f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static PhotoViewIntentBuilder newPhotoViewIntentBuilder( 915c16562ccda53e0f204490c2218f0f8127169dd8Martin Hibdon Context context, Class<? extends Activity> cls) { 92f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return new PhotoViewIntentBuilder(context, cls); 93f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 94f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 956893051dad361413e483425bad0c27272596bb5cPaul Westbrook /** Gets a new photo view intent builder */ 966893051dad361413e483425bad0c27272596bb5cPaul Westbrook public static PhotoViewIntentBuilder newPhotoViewIntentBuilder( 976893051dad361413e483425bad0c27272596bb5cPaul Westbrook Context context, String activityName) { 986893051dad361413e483425bad0c27272596bb5cPaul Westbrook return new PhotoViewIntentBuilder(context, activityName); 996893051dad361413e483425bad0c27272596bb5cPaul Westbrook } 1006893051dad361413e483425bad0c27272596bb5cPaul Westbrook 101f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Builder to create a photo view intent */ 102f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public static class PhotoViewIntentBuilder { 103f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private final Intent mIntent; 104f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 105f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** The index of the photo to show */ 106f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private Integer mPhotoIndex; 10799f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon /** The URI of the initial photo to show */ 10899f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon private String mInitialPhotoUri; 109ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon /** The URI of the initial thumbnail to show */ 110ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private String mInitialThumbnailUri; 111f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** The URI of the group of photos to display */ 112f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private String mPhotosUri; 113f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** The URL of the photo to display */ 114f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private String mResolvedPhotoUri; 115f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** The projection for the query to use; optional */ 116f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private String[] mProjection; 117928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein /** The URI of a thumbnail of the photo to display */ 118928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein private String mThumbnailUri; 11991dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp /** The maximum scale to display images at before */ 12091dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp private Float mMaxInitialScale; 1218650d3cda75562489551ee04bff9145a49a6f16fKen Thai /** True if lights out should automatically be invoked on a timer basis */ 1228650d3cda75562489551ee04bff9145a49a6f16fKen Thai private boolean mEnableTimerLightsOut; 1237732839c0cd9d87954a07e166b52b93cabea1374Adam Copp /** 1247732839c0cd9d87954a07e166b52b93cabea1374Adam Copp * True if the PhotoViewFragments should watch for network changes to restart their loaders 1257732839c0cd9d87954a07e166b52b93cabea1374Adam Copp */ 1267732839c0cd9d87954a07e166b52b93cabea1374Adam Copp private boolean mWatchNetwork; 127ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon /** true we want to run the image scale animation */ 128ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private boolean mScaleAnimation; 129ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon /** The parameters for performing the scale up/scale down animations 130ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon * upon enter and exit. StartX and StartY represent the screen coordinates 131ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon * of the upper left corner of the start rectangle, startWidth and startHeight 132ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon * represent the width and height of the start rectangle. 133ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon */ 134ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private int mStartX; 135ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private int mStartY; 136ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private int mStartWidth; 137ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private int mStartHeight; 138ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 139ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private boolean mActionBarHiddenInitially; 140ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon private boolean mDisplayFullScreenThumbs; 141f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 142f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein private PhotoViewIntentBuilder(Context context, Class<?> cls) { 143f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent = new Intent(context, cls); 1446893051dad361413e483425bad0c27272596bb5cPaul Westbrook initialize(); 1456893051dad361413e483425bad0c27272596bb5cPaul Westbrook } 1466893051dad361413e483425bad0c27272596bb5cPaul Westbrook 1476893051dad361413e483425bad0c27272596bb5cPaul Westbrook private PhotoViewIntentBuilder(Context context, String activityName) { 1486893051dad361413e483425bad0c27272596bb5cPaul Westbrook mIntent = new Intent(); 1496893051dad361413e483425bad0c27272596bb5cPaul Westbrook mIntent.setClassName(context, activityName); 1506893051dad361413e483425bad0c27272596bb5cPaul Westbrook initialize(); 1516893051dad361413e483425bad0c27272596bb5cPaul Westbrook } 1526893051dad361413e483425bad0c27272596bb5cPaul Westbrook 1536893051dad361413e483425bad0c27272596bb5cPaul Westbrook private void initialize() { 154ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mScaleAnimation = false; 155ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mActionBarHiddenInitially = false; 156ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mDisplayFullScreenThumbs = false; 1578650d3cda75562489551ee04bff9145a49a6f16fKen Thai mEnableTimerLightsOut = true; 1588650d3cda75562489551ee04bff9145a49a6f16fKen Thai } 1598650d3cda75562489551ee04bff9145a49a6f16fKen Thai 1608650d3cda75562489551ee04bff9145a49a6f16fKen Thai /** Sets auto lights out */ 1618650d3cda75562489551ee04bff9145a49a6f16fKen Thai public PhotoViewIntentBuilder setEnableTimerLightsOut(boolean enable) { 1628650d3cda75562489551ee04bff9145a49a6f16fKen Thai mEnableTimerLightsOut = enable; 1638650d3cda75562489551ee04bff9145a49a6f16fKen Thai return this; 164f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 165f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 166f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Sets the photo index */ 167f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public PhotoViewIntentBuilder setPhotoIndex(Integer photoIndex) { 168f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mPhotoIndex = photoIndex; 169f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return this; 170f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 171f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 17299f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon /** Sets the initial photo URI */ 17399f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon public PhotoViewIntentBuilder setInitialPhotoUri(String initialPhotoUri) { 17499f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon mInitialPhotoUri = initialPhotoUri; 17599f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon return this; 17699f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon } 17799f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon 178f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Sets the photos URI */ 179f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public PhotoViewIntentBuilder setPhotosUri(String photosUri) { 180f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mPhotosUri = photosUri; 181f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return this; 182f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 183f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 184f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Sets the query projection */ 185f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public PhotoViewIntentBuilder setProjection(String[] projection) { 186f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mProjection = projection; 187f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return this; 188f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 189f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 190f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Sets the resolved photo URI. This method is for the case 191f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * where the URI given to {@link PhotoViewActivity} points directly 192f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * to a single image and does not need to be resolved via a query 193f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * to the {@link ContentProvider}. If this value is set, it supersedes 194f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein * {@link #setPhotosUri(String)}. */ 195f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public PhotoViewIntentBuilder setResolvedPhotoUri(String resolvedPhotoUri) { 196f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mResolvedPhotoUri = resolvedPhotoUri; 197f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return this; 198f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 199f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 200928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein /** 201928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein * Sets the URI for a thumbnail preview of the photo. 202928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein */ 203928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein public PhotoViewIntentBuilder setThumbnailUri(String thumbnailUri) { 204928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein mThumbnailUri = thumbnailUri; 205928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein return this; 206928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein } 207928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein 20891dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp /** 20991dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp * Sets the maximum scale which an image is initially displayed at 21091dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp */ 21191dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp public PhotoViewIntentBuilder setMaxInitialScale(float maxScale) { 21291dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp mMaxInitialScale = maxScale; 21391dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp return this; 21491dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp } 21591dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp 2167732839c0cd9d87954a07e166b52b93cabea1374Adam Copp /** 2177732839c0cd9d87954a07e166b52b93cabea1374Adam Copp * Enable watching the network for connectivity changes. 2187732839c0cd9d87954a07e166b52b93cabea1374Adam Copp * 2197732839c0cd9d87954a07e166b52b93cabea1374Adam Copp * When a change is detected, bitmap loaders will be restarted if required. 2207732839c0cd9d87954a07e166b52b93cabea1374Adam Copp */ 2217732839c0cd9d87954a07e166b52b93cabea1374Adam Copp public PhotoViewIntentBuilder watchNetworkConnectivityChanges() { 2227732839c0cd9d87954a07e166b52b93cabea1374Adam Copp mWatchNetwork = true; 2236c056da7dd8d6a48b792050fa671a35781483fc2Martin Hibdon return this; 224ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon } 225ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 226f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian /** 227f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * Enable a scale animation that animates the initial photo URI passed in using 228f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * {@link #setInitialPhotoUri}. 229f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * 230f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * Note: To avoid janky transitions, particularly when exiting the photoviewer, ensure the 231f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * following system UI flags are set on the root view of the relying app's activity 232f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * (via @{link View.setSystemUiVisibility(int)}): 233f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * {@code View.SYSTEM_UI_FLAG_VISIBLE | View.SYSTEM_UI_FLAG_LAYOUT_STABLE} 234f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * As well, client should ensure {@code android:fitsSystemWindows} is set on the root 235f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian * content view. 236f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian */ 237ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public PhotoViewIntentBuilder setScaleAnimation(int startX, int startY, 238ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon int startWidth, int startHeight) { 239ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mScaleAnimation = true; 240ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mStartX = startX; 241ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mStartY = startY; 242ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mStartWidth = startWidth; 243ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mStartHeight = startHeight; 244ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon return this; 245ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon } 246ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 247ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // If this option is turned on, then the photoViewer will be initially 248ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // displayed with the action bar hidden. This is as opposed to the default 249ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // behavior, where the actionBar is initially shown. 250ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public PhotoViewIntentBuilder setActionBarHiddenInitially( 251ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon boolean actionBarHiddenInitially) { 252ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mActionBarHiddenInitially = actionBarHiddenInitially; 253ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon return this; 254ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon } 255ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 256ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // If this option is turned on, then the small, lo-res thumbnail will 257ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // be scaled up to the maximum size to cover as much of the screen as 258ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // possible while still maintaining the correct aspect ratio. This means 259ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // that the image may appear blurry until the the full-res image is 260ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // loaded. 261ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // This is as opposed to the default behavior, where only part of the 262ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // thumbnail is displayed in a small view in the center of the screen, 263ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon // and a loading spinner is displayed until the full-res image is loaded. 264ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon public PhotoViewIntentBuilder setDisplayThumbsFullScreen( 265ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon boolean displayFullScreenThumbs) { 266ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mDisplayFullScreenThumbs = displayFullScreenThumbs; 2677732839c0cd9d87954a07e166b52b93cabea1374Adam Copp return this; 2687732839c0cd9d87954a07e166b52b93cabea1374Adam Copp } 2697732839c0cd9d87954a07e166b52b93cabea1374Adam Copp 270f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein /** Build the intent */ 271f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein public Intent build() { 272f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.setAction(Intent.ACTION_VIEW); 273f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 274ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde // In Lollipop, each list of photos should appear as a document in the "Recents" 275ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde // list. In earlier versions, this flag was Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET. 276ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT 277ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde // FLAG_ACTIVITY_CLEAR_TOP is needed for the case where the app tries to 278ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde // display a different photo while there is an existing activity instance 279ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde // for that list of photos. Since the initial photo is specified as an 280ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde // extra, without FLAG_ACTIVITY_CLEAR_TOP, the activity instance would 281ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde // just get restarted and it would display whatever photo it was last 282ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde // displaying. FLAG_ACTIVITY_CLEAR_TOP causes a new instance to be created, 283ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde // and it will display the new initial photo. 284ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde | Intent.FLAG_ACTIVITY_CLEAR_TOP); 285f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 286f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein if (mPhotoIndex != null) { 287f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.putExtra(EXTRA_PHOTO_INDEX, (int) mPhotoIndex); 288f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 289f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 29099f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon if (mInitialPhotoUri != null) { 29199f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon mIntent.putExtra(EXTRA_INITIAL_PHOTO_URI, mInitialPhotoUri); 29299f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon } 29399f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon 29499f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon if (mInitialPhotoUri != null && mPhotoIndex != null) { 29599f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon throw new IllegalStateException( 29699f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon "specified both photo index and photo uri"); 29799f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon } 29899f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon 299f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein if (mPhotosUri != null) { 300f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.putExtra(EXTRA_PHOTOS_URI, mPhotosUri); 3014a6abe405e4de31a14e2c5489c413c806f2f11f2Andrew Sapperstein mIntent.setData(Uri.parse(mPhotosUri)); 302f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 303f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 304f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein if (mResolvedPhotoUri != null) { 305f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.putExtra(EXTRA_RESOLVED_PHOTO_URI, mResolvedPhotoUri); 306f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 307f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 308f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein if (mProjection != null) { 309f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein mIntent.putExtra(EXTRA_PROJECTION, mProjection); 310f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 311f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein 312928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein if (mThumbnailUri != null) { 313928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein mIntent.putExtra(EXTRA_THUMBNAIL_URI, mThumbnailUri); 314928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein } 315928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein 31691dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp if (mMaxInitialScale != null) { 31791dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp mIntent.putExtra(EXTRA_MAX_INITIAL_SCALE, mMaxInitialScale); 31891dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp } 31991dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp 3204a6abe405e4de31a14e2c5489c413c806f2f11f2Andrew Sapperstein mIntent.putExtra(EXTRA_WATCH_NETWORK, mWatchNetwork); 3217732839c0cd9d87954a07e166b52b93cabea1374Adam Copp 322ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_SCALE_UP_ANIMATION, mScaleAnimation); 323ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon if (mScaleAnimation) { 324ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ANIMATION_START_X, mStartX); 325ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ANIMATION_START_Y, mStartY); 326ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ANIMATION_START_WIDTH, mStartWidth); 327ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ANIMATION_START_HEIGHT, mStartHeight); 328ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon } 329ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon 330ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_ACTION_BAR_HIDDEN_INITIALLY, mActionBarHiddenInitially); 331ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon mIntent.putExtra(EXTRA_DISPLAY_THUMBS_FULLSCREEN, mDisplayFullScreenThumbs); 3328650d3cda75562489551ee04bff9145a49a6f16fKen Thai mIntent.putExtra(EXTRA_ENABLE_TIMER_LIGHTS_OUT, mEnableTimerLightsOut); 333f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein return mIntent; 334f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 335f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein } 336f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein} 337