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";
401f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne    public static final String EXTRA_CONTENT_DESCRIPTION = "content_description";
4191dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp    public static final String EXTRA_MAX_INITIAL_SCALE = "max_scale";
427732839c0cd9d87954a07e166b52b93cabea1374Adam Copp    public static final String EXTRA_WATCH_NETWORK = "watch_network";
438650d3cda75562489551ee04bff9145a49a6f16fKen Thai    public static final String EXTRA_ENABLE_TIMER_LIGHTS_OUT = "enable_timer_lights_out";
44f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
45ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
46ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon    // Parameters affecting the intro/exit animation
47ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon    public static final String EXTRA_SCALE_UP_ANIMATION = "scale_up_animation";
488670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon    public static final String EXTRA_ANIMATION_START_X = "start_x_extra";
498670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon    public static final String EXTRA_ANIMATION_START_Y = "start_y_extra";
508670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon    public static final String EXTRA_ANIMATION_START_WIDTH = "start_width_extra";
518670cefb043f865c7275876dcc94f65ce5bda041Martin Hibdon    public static final String EXTRA_ANIMATION_START_HEIGHT = "start_height_extra";
52ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
53ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon    // Parameters affecting the display and features
54ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon    public static final String EXTRA_ACTION_BAR_HIDDEN_INITIALLY = "action_bar_hidden_initially";
55ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon    public static final String EXTRA_DISPLAY_THUMBS_FULLSCREEN = "display_thumbs_fullscreen";
56ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
57f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    /**
58f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     * Gets a photo view intent builder to display the photos from phone activity.
59f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     *
60f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     * @param context The context
61f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     * @return The intent builder
62f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     */
63f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public static PhotoViewIntentBuilder newPhotoViewActivityIntentBuilder(Context context) {
64f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        return new PhotoViewIntentBuilder(context, PhotoViewActivity.class);
65f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
66f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
67f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    /**
68f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     * Gets a photo view intent builder to display the photo view fragment
69f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     *
70f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     * @param context The context
71f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     * @return The intent builder
72f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein     */
73f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public static PhotoViewIntentBuilder newPhotoViewFragmentIntentBuilder(Context context) {
74bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        return newPhotoViewFragmentIntentBuilder(context, PhotoViewFragment.class);
75bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    }
76bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood
77bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    /**
78bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood     * Gets a photo view intent builder to display the photo view fragment with a custom fragment
79bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood     * subclass.
80bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood     *
81bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood     * @param context The context
82bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood     * @param clazz Subclass of PhotoViewFragment to use
83bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood     * @return The intent builder
84bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood     */
85bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood    public static PhotoViewIntentBuilder newPhotoViewFragmentIntentBuilder(Context context,
86bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood            Class<? extends PhotoViewFragment> clazz) {
87bb137c8e2ed363e6f5e2c0f14719483d27e8c062Mathew Inwood        return new PhotoViewIntentBuilder(context, clazz);
88f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
89f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
90f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    /** Gets a new photo view intent builder */
91f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public static PhotoViewIntentBuilder newPhotoViewIntentBuilder(
925c16562ccda53e0f204490c2218f0f8127169dd8Martin Hibdon            Context context, Class<? extends Activity> cls) {
93f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        return new PhotoViewIntentBuilder(context, cls);
94f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
95f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
966893051dad361413e483425bad0c27272596bb5cPaul Westbrook    /** Gets a new photo view intent builder */
976893051dad361413e483425bad0c27272596bb5cPaul Westbrook    public static PhotoViewIntentBuilder newPhotoViewIntentBuilder(
986893051dad361413e483425bad0c27272596bb5cPaul Westbrook            Context context, String activityName) {
996893051dad361413e483425bad0c27272596bb5cPaul Westbrook        return new PhotoViewIntentBuilder(context, activityName);
1006893051dad361413e483425bad0c27272596bb5cPaul Westbrook    }
1016893051dad361413e483425bad0c27272596bb5cPaul Westbrook
102f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    /** Builder to create a photo view intent */
103f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public static class PhotoViewIntentBuilder {
104f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private final Intent mIntent;
105f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
106f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** The index of the photo to show */
107f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private Integer mPhotoIndex;
10899f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        /** The URI of the initial photo to show */
10999f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        private String mInitialPhotoUri;
110ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        /** The URI of the initial thumbnail to show */
111ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private String mInitialThumbnailUri;
112f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** The URI of the group of photos to display */
113f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private String mPhotosUri;
114f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** The URL of the photo to display */
115f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private String mResolvedPhotoUri;
116f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** The projection for the query to use; optional */
117f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private String[] mProjection;
118928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        /** The URI of a thumbnail of the photo to display */
119928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        private String mThumbnailUri;
1201f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne        /** The content Description for the photo to show */
1211f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne        private String mContentDescription;
12291dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        /** The maximum scale to display images at before  */
12391dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        private Float mMaxInitialScale;
1248650d3cda75562489551ee04bff9145a49a6f16fKen Thai        /** True if lights out should automatically be invoked on a timer basis */
1258650d3cda75562489551ee04bff9145a49a6f16fKen Thai        private boolean mEnableTimerLightsOut;
1267732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        /**
1277732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         * True if the PhotoViewFragments should watch for network changes to restart their loaders
1287732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         */
1297732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        private boolean mWatchNetwork;
130ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        /** true we want to run the image scale animation */
131ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private boolean mScaleAnimation;
132ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        /** The parameters for performing the scale up/scale down animations
133ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon         * upon enter and exit. StartX and StartY represent the screen coordinates
134ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon         * of the upper left corner of the start rectangle, startWidth and startHeight
135ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon         * represent the width and height of the start rectangle.
136ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon         */
137ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private int mStartX;
138ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private int mStartY;
139ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private int mStartWidth;
140ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private int mStartHeight;
141ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
142ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private boolean mActionBarHiddenInitially;
143ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private boolean mDisplayFullScreenThumbs;
144f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
145f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private PhotoViewIntentBuilder(Context context, Class<?> cls) {
146f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mIntent = new Intent(context, cls);
1476893051dad361413e483425bad0c27272596bb5cPaul Westbrook            initialize();
1486893051dad361413e483425bad0c27272596bb5cPaul Westbrook        }
1496893051dad361413e483425bad0c27272596bb5cPaul Westbrook
1506893051dad361413e483425bad0c27272596bb5cPaul Westbrook        private PhotoViewIntentBuilder(Context context, String activityName) {
1516893051dad361413e483425bad0c27272596bb5cPaul Westbrook            mIntent = new Intent();
1526893051dad361413e483425bad0c27272596bb5cPaul Westbrook            mIntent.setClassName(context, activityName);
1536893051dad361413e483425bad0c27272596bb5cPaul Westbrook            initialize();
1546893051dad361413e483425bad0c27272596bb5cPaul Westbrook        }
1556893051dad361413e483425bad0c27272596bb5cPaul Westbrook
1566893051dad361413e483425bad0c27272596bb5cPaul Westbrook        private void initialize() {
157ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mScaleAnimation = false;
158ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mActionBarHiddenInitially = false;
159ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mDisplayFullScreenThumbs = false;
1608650d3cda75562489551ee04bff9145a49a6f16fKen Thai            mEnableTimerLightsOut = true;
1618650d3cda75562489551ee04bff9145a49a6f16fKen Thai        }
1628650d3cda75562489551ee04bff9145a49a6f16fKen Thai
1638650d3cda75562489551ee04bff9145a49a6f16fKen Thai        /** Sets auto lights out */
1648650d3cda75562489551ee04bff9145a49a6f16fKen Thai        public PhotoViewIntentBuilder setEnableTimerLightsOut(boolean enable) {
1658650d3cda75562489551ee04bff9145a49a6f16fKen Thai            mEnableTimerLightsOut = enable;
1668650d3cda75562489551ee04bff9145a49a6f16fKen Thai            return this;
167f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
168f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
169f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Sets the photo index */
170f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public PhotoViewIntentBuilder setPhotoIndex(Integer photoIndex) {
171f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mPhotoIndex = photoIndex;
172f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return this;
173f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
174f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
17599f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        /** Sets the initial photo URI */
17699f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        public PhotoViewIntentBuilder setInitialPhotoUri(String initialPhotoUri) {
17799f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            mInitialPhotoUri = initialPhotoUri;
17899f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            return this;
17999f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        }
18099f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon
181f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Sets the photos URI */
182f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public PhotoViewIntentBuilder setPhotosUri(String photosUri) {
183f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mPhotosUri = photosUri;
184f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return this;
185f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
186f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
187f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Sets the query projection */
188f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public PhotoViewIntentBuilder setProjection(String[] projection) {
189f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mProjection = projection;
190f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return this;
191f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
192f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
193f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Sets the resolved photo URI. This method is for the case
194f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein         *  where the URI given to {@link PhotoViewActivity} points directly
195f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein         *  to a single image and does not need to be resolved via a query
196f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein         *  to the {@link ContentProvider}. If this value is set, it supersedes
197f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein         *  {@link #setPhotosUri(String)}. */
198f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public PhotoViewIntentBuilder setResolvedPhotoUri(String resolvedPhotoUri) {
199f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mResolvedPhotoUri = resolvedPhotoUri;
200f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return this;
201f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
202f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
203928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        /**
204928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein         * Sets the URI for a thumbnail preview of the photo.
205928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein         */
206928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        public PhotoViewIntentBuilder setThumbnailUri(String thumbnailUri) {
207928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein            mThumbnailUri = thumbnailUri;
208928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein            return this;
209928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        }
210928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein
21191dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        /**
2121f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne         * Sets the content Description for the photo
2131f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne         */
2141f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne        public PhotoViewIntentBuilder setContentDescription(String contentDescription) {
2151f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne            mContentDescription = contentDescription;
2161f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne            return this;
2171f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne        }
2181f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne
2191f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne        /**
22091dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp         * Sets the maximum scale which an image is initially displayed at
22191dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp         */
22291dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        public PhotoViewIntentBuilder setMaxInitialScale(float maxScale) {
22391dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp            mMaxInitialScale = maxScale;
22491dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp            return this;
22591dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        }
22691dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp
2277732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        /**
2287732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         * Enable watching the network for connectivity changes.
2297732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         *
2307732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         * When a change is detected, bitmap loaders will be restarted if required.
2317732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         */
2327732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        public PhotoViewIntentBuilder watchNetworkConnectivityChanges() {
2337732839c0cd9d87954a07e166b52b93cabea1374Adam Copp            mWatchNetwork = true;
2346c056da7dd8d6a48b792050fa671a35781483fc2Martin Hibdon            return this;
235ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        }
236ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
237f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian        /**
238f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * Enable a scale animation that animates the initial photo URI passed in using
239f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * {@link #setInitialPhotoUri}.
240f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         *
241f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * Note: To avoid janky transitions, particularly when exiting the photoviewer, ensure the
242f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * following system UI flags are set on the root view of the relying app's activity
243f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * (via @{link View.setSystemUiVisibility(int)}):
244f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         *     {@code View.SYSTEM_UI_FLAG_VISIBLE | View.SYSTEM_UI_FLAG_LAYOUT_STABLE}
245f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * As well, client should ensure {@code android:fitsSystemWindows} is set on the root
246f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * content view.
247f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         */
248ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        public PhotoViewIntentBuilder setScaleAnimation(int startX, int startY,
249ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                int startWidth, int startHeight) {
250ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mScaleAnimation = true;
251ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mStartX = startX;
252ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mStartY = startY;
253ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mStartWidth = startWidth;
254ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mStartHeight = startHeight;
255ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            return this;
256ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        }
257ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
258ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // If this option is turned on, then the photoViewer will be initially
259ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // displayed with the action bar hidden. This is as opposed to the default
260ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // behavior, where the actionBar is initially shown.
261ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        public PhotoViewIntentBuilder setActionBarHiddenInitially(
262ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                boolean actionBarHiddenInitially) {
263ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mActionBarHiddenInitially = actionBarHiddenInitially;
264ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            return this;
265ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        }
266ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
267ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // If this option is turned on, then the small, lo-res thumbnail will
268ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // be scaled up to the maximum size to cover as much of the screen as
269ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // possible while still maintaining the correct aspect ratio. This means
270ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // that the image may appear blurry until the the full-res image is
271ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // loaded.
272ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // This is as opposed to the default behavior, where only part of the
273ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // thumbnail is displayed in a small view in the center of the screen,
274ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // and a loading spinner is displayed until the full-res image is loaded.
275ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        public PhotoViewIntentBuilder setDisplayThumbsFullScreen(
276ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                boolean displayFullScreenThumbs) {
277ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mDisplayFullScreenThumbs = displayFullScreenThumbs;
2787732839c0cd9d87954a07e166b52b93cabea1374Adam Copp            return this;
2797732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        }
2807732839c0cd9d87954a07e166b52b93cabea1374Adam Copp
281f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Build the intent */
282f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public Intent build() {
283f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mIntent.setAction(Intent.ACTION_VIEW);
284f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
285ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde            // In Lollipop, each list of photos should appear as a document in the "Recents"
286ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde            // list. In earlier versions, this flag was Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET.
287ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde            mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT
288ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde                    // FLAG_ACTIVITY_CLEAR_TOP is needed for the case where the app tries to
289ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde                    // display a different photo while there is an existing activity instance
290ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde                    // for that list of photos. Since the initial photo is specified as an
291ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde                    // extra, without FLAG_ACTIVITY_CLEAR_TOP, the activity instance would
292ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde                    // just get restarted and it would display whatever photo it was last
293ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde                    // displaying. FLAG_ACTIVITY_CLEAR_TOP causes a new instance to be created,
294ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde                    // and it will display the new initial photo.
295ff6ac38cd3fd60e63882f3163d233d8c09a70db8Shri Borde                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
296f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
297f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            if (mPhotoIndex != null) {
298f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein                mIntent.putExtra(EXTRA_PHOTO_INDEX, (int) mPhotoIndex);
299f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            }
300f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
30199f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            if (mInitialPhotoUri != null) {
30299f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon                mIntent.putExtra(EXTRA_INITIAL_PHOTO_URI, mInitialPhotoUri);
30399f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            }
30499f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon
30599f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            if (mInitialPhotoUri != null && mPhotoIndex != null) {
30699f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon                throw new IllegalStateException(
30799f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon                        "specified both photo index and photo uri");
30899f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            }
30999f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon
310f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            if (mPhotosUri != null) {
311f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein                mIntent.putExtra(EXTRA_PHOTOS_URI, mPhotosUri);
3124a6abe405e4de31a14e2c5489c413c806f2f11f2Andrew Sapperstein                mIntent.setData(Uri.parse(mPhotosUri));
313f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            }
314f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
315f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            if (mResolvedPhotoUri != null) {
316f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein                mIntent.putExtra(EXTRA_RESOLVED_PHOTO_URI, mResolvedPhotoUri);
317f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            }
318f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
319f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            if (mProjection != null) {
320f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein                mIntent.putExtra(EXTRA_PROJECTION, mProjection);
321f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            }
322f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
323928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein            if (mThumbnailUri != null) {
324928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein                mIntent.putExtra(EXTRA_THUMBNAIL_URI, mThumbnailUri);
325928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein            }
326928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein
3271f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne            if (mContentDescription != null) {
3281f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne                mIntent.putExtra(EXTRA_CONTENT_DESCRIPTION, mContentDescription);
3291f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne            }
3301f9535b34b069c2071b90fb8409f0f5421f3310fTavis Bohne
33191dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp            if (mMaxInitialScale != null) {
33291dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp                mIntent.putExtra(EXTRA_MAX_INITIAL_SCALE, mMaxInitialScale);
33391dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp            }
33491dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp
3354a6abe405e4de31a14e2c5489c413c806f2f11f2Andrew Sapperstein            mIntent.putExtra(EXTRA_WATCH_NETWORK, mWatchNetwork);
3367732839c0cd9d87954a07e166b52b93cabea1374Adam Copp
337ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mIntent.putExtra(EXTRA_SCALE_UP_ANIMATION, mScaleAnimation);
338ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            if (mScaleAnimation) {
339ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                mIntent.putExtra(EXTRA_ANIMATION_START_X, mStartX);
340ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                mIntent.putExtra(EXTRA_ANIMATION_START_Y, mStartY);
341ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                mIntent.putExtra(EXTRA_ANIMATION_START_WIDTH, mStartWidth);
342ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                mIntent.putExtra(EXTRA_ANIMATION_START_HEIGHT, mStartHeight);
343ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            }
344ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
345ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mIntent.putExtra(EXTRA_ACTION_BAR_HIDDEN_INITIALLY, mActionBarHiddenInitially);
346ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mIntent.putExtra(EXTRA_DISPLAY_THUMBS_FULLSCREEN, mDisplayFullScreenThumbs);
3478650d3cda75562489551ee04bff9145a49a6f16fKen Thai            mIntent.putExtra(EXTRA_ENABLE_TIMER_LIGHTS_OUT, mEnableTimerLightsOut);
348f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return mIntent;
349f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
350f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
351f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein}
352