Intents.java revision f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41e
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) {
71f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        return new PhotoViewIntentBuilder(context, PhotoViewFragment.class);
72f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
73f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
74f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    /** Gets a new photo view intent builder */
75f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public static PhotoViewIntentBuilder newPhotoViewIntentBuilder(
765c16562ccda53e0f204490c2218f0f8127169dd8Martin Hibdon            Context context, Class<? extends Activity> cls) {
77f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        return new PhotoViewIntentBuilder(context, cls);
78f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
79f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
806893051dad361413e483425bad0c27272596bb5cPaul Westbrook    /** Gets a new photo view intent builder */
816893051dad361413e483425bad0c27272596bb5cPaul Westbrook    public static PhotoViewIntentBuilder newPhotoViewIntentBuilder(
826893051dad361413e483425bad0c27272596bb5cPaul Westbrook            Context context, String activityName) {
836893051dad361413e483425bad0c27272596bb5cPaul Westbrook        return new PhotoViewIntentBuilder(context, activityName);
846893051dad361413e483425bad0c27272596bb5cPaul Westbrook    }
856893051dad361413e483425bad0c27272596bb5cPaul Westbrook
86f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    /** Builder to create a photo view intent */
87f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    public static class PhotoViewIntentBuilder {
88f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private final Intent mIntent;
89f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
90f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** The index of the photo to show */
91f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private Integer mPhotoIndex;
9299f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        /** The URI of the initial photo to show */
9399f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        private String mInitialPhotoUri;
94ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        /** The URI of the initial thumbnail to show */
95ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private String mInitialThumbnailUri;
96f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** The URI of the group of photos to display */
97f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private String mPhotosUri;
98f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** The URL of the photo to display */
99f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private String mResolvedPhotoUri;
100f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** The projection for the query to use; optional */
101f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private String[] mProjection;
102928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        /** The URI of a thumbnail of the photo to display */
103928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        private String mThumbnailUri;
10491dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        /** The maximum scale to display images at before  */
10591dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        private Float mMaxInitialScale;
1067732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        /**
1077732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         * True if the PhotoViewFragments should watch for network changes to restart their loaders
1087732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         */
1097732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        private boolean mWatchNetwork;
110ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        /** true we want to run the image scale animation */
111ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private boolean mScaleAnimation;
112ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        /** The parameters for performing the scale up/scale down animations
113ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon         * upon enter and exit. StartX and StartY represent the screen coordinates
114ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon         * of the upper left corner of the start rectangle, startWidth and startHeight
115ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon         * represent the width and height of the start rectangle.
116ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon         */
117ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private int mStartX;
118ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private int mStartY;
119ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private int mStartWidth;
120ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private int mStartHeight;
121ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
122ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private boolean mActionBarHiddenInitially;
123ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        private boolean mDisplayFullScreenThumbs;
124f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
125f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        private PhotoViewIntentBuilder(Context context, Class<?> cls) {
126f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mIntent = new Intent(context, cls);
1276893051dad361413e483425bad0c27272596bb5cPaul Westbrook            initialize();
1286893051dad361413e483425bad0c27272596bb5cPaul Westbrook        }
1296893051dad361413e483425bad0c27272596bb5cPaul Westbrook
1306893051dad361413e483425bad0c27272596bb5cPaul Westbrook        private PhotoViewIntentBuilder(Context context, String activityName) {
1316893051dad361413e483425bad0c27272596bb5cPaul Westbrook            mIntent = new Intent();
1326893051dad361413e483425bad0c27272596bb5cPaul Westbrook            mIntent.setClassName(context, activityName);
1336893051dad361413e483425bad0c27272596bb5cPaul Westbrook            initialize();
1346893051dad361413e483425bad0c27272596bb5cPaul Westbrook        }
1356893051dad361413e483425bad0c27272596bb5cPaul Westbrook
1366893051dad361413e483425bad0c27272596bb5cPaul Westbrook        private void initialize() {
137ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mScaleAnimation = false;
138ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mActionBarHiddenInitially = false;
139ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mDisplayFullScreenThumbs = false;
140f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
141f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
142f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Sets the photo index */
143f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public PhotoViewIntentBuilder setPhotoIndex(Integer photoIndex) {
144f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mPhotoIndex = photoIndex;
145f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return this;
146f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
147f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
14899f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        /** Sets the initial photo URI */
14999f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        public PhotoViewIntentBuilder setInitialPhotoUri(String initialPhotoUri) {
15099f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            mInitialPhotoUri = initialPhotoUri;
15199f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            return this;
15299f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon        }
15399f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon
154f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Sets the photos URI */
155f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public PhotoViewIntentBuilder setPhotosUri(String photosUri) {
156f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mPhotosUri = photosUri;
157f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return this;
158f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
159f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
160f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Sets the query projection */
161f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public PhotoViewIntentBuilder setProjection(String[] projection) {
162f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mProjection = projection;
163f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return this;
164f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
165f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
166f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Sets the resolved photo URI. This method is for the case
167f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein         *  where the URI given to {@link PhotoViewActivity} points directly
168f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein         *  to a single image and does not need to be resolved via a query
169f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein         *  to the {@link ContentProvider}. If this value is set, it supersedes
170f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein         *  {@link #setPhotosUri(String)}. */
171f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public PhotoViewIntentBuilder setResolvedPhotoUri(String resolvedPhotoUri) {
172f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mResolvedPhotoUri = resolvedPhotoUri;
173f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return this;
174f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
175f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
176928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        /**
177928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein         * Sets the URI for a thumbnail preview of the photo.
178928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein         */
179928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        public PhotoViewIntentBuilder setThumbnailUri(String thumbnailUri) {
180928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein            mThumbnailUri = thumbnailUri;
181928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein            return this;
182928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein        }
183928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein
18491dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        /**
18591dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp         * Sets the maximum scale which an image is initially displayed at
18691dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp         */
18791dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        public PhotoViewIntentBuilder setMaxInitialScale(float maxScale) {
18891dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp            mMaxInitialScale = maxScale;
18991dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp            return this;
19091dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp        }
19191dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp
1927732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        /**
1937732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         * Enable watching the network for connectivity changes.
1947732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         *
1957732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         * When a change is detected, bitmap loaders will be restarted if required.
1967732839c0cd9d87954a07e166b52b93cabea1374Adam Copp         */
1977732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        public PhotoViewIntentBuilder watchNetworkConnectivityChanges() {
1987732839c0cd9d87954a07e166b52b93cabea1374Adam Copp            mWatchNetwork = true;
1996c056da7dd8d6a48b792050fa671a35781483fc2Martin Hibdon            return this;
200ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        }
201ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
202f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian        /**
203f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * Enable a scale animation that animates the initial photo URI passed in using
204f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * {@link #setInitialPhotoUri}.
205f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         *
206f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * Note: To avoid janky transitions, particularly when exiting the photoviewer, ensure the
207f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * following system UI flags are set on the root view of the relying app's activity
208f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * (via @{link View.setSystemUiVisibility(int)}):
209f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         *     {@code View.SYSTEM_UI_FLAG_VISIBLE | View.SYSTEM_UI_FLAG_LAYOUT_STABLE}
210f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * As well, client should ensure {@code android:fitsSystemWindows} is set on the root
211f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         * content view.
212f5a30690749a354cbbf8c8d9ad4fd5ed84e7d41eMatt Keoshkerian         */
213ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        public PhotoViewIntentBuilder setScaleAnimation(int startX, int startY,
214ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                int startWidth, int startHeight) {
215ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mScaleAnimation = true;
216ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mStartX = startX;
217ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mStartY = startY;
218ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mStartWidth = startWidth;
219ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mStartHeight = startHeight;
220ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            return this;
221ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        }
222ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
223ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // If this option is turned on, then the photoViewer will be initially
224ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // displayed with the action bar hidden. This is as opposed to the default
225ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // behavior, where the actionBar is initially shown.
226ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        public PhotoViewIntentBuilder setActionBarHiddenInitially(
227ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                boolean actionBarHiddenInitially) {
228ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mActionBarHiddenInitially = actionBarHiddenInitially;
229ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            return this;
230ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        }
231ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
232ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // If this option is turned on, then the small, lo-res thumbnail will
233ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // be scaled up to the maximum size to cover as much of the screen as
234ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // possible while still maintaining the correct aspect ratio. This means
235ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // that the image may appear blurry until the the full-res image is
236ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // loaded.
237ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // This is as opposed to the default behavior, where only part of the
238ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // thumbnail is displayed in a small view in the center of the screen,
239ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        // and a loading spinner is displayed until the full-res image is loaded.
240ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon        public PhotoViewIntentBuilder setDisplayThumbsFullScreen(
241ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                boolean displayFullScreenThumbs) {
242ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mDisplayFullScreenThumbs = displayFullScreenThumbs;
2437732839c0cd9d87954a07e166b52b93cabea1374Adam Copp            return this;
2447732839c0cd9d87954a07e166b52b93cabea1374Adam Copp        }
2457732839c0cd9d87954a07e166b52b93cabea1374Adam Copp
246f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        /** Build the intent */
247f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        public Intent build() {
248f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mIntent.setAction(Intent.ACTION_VIEW);
249f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
250f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
251f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
252f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            if (mPhotoIndex != null) {
253f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein                mIntent.putExtra(EXTRA_PHOTO_INDEX, (int) mPhotoIndex);
254f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            }
255f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
25699f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            if (mInitialPhotoUri != null) {
25799f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon                mIntent.putExtra(EXTRA_INITIAL_PHOTO_URI, mInitialPhotoUri);
25899f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            }
25999f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon
26099f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            if (mInitialPhotoUri != null && mPhotoIndex != null) {
26199f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon                throw new IllegalStateException(
26299f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon                        "specified both photo index and photo uri");
26399f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon            }
26499f6f3ea0e43d5ac96344a987735fc39485f8f05Martin Hibdon
265f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            if (mPhotosUri != null) {
266f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein                mIntent.putExtra(EXTRA_PHOTOS_URI, mPhotosUri);
267f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            }
268f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
269f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            if (mResolvedPhotoUri != null) {
270f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein                mIntent.putExtra(EXTRA_RESOLVED_PHOTO_URI, mResolvedPhotoUri);
271f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            }
272f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
273f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            if (mProjection != null) {
274f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein                mIntent.putExtra(EXTRA_PROJECTION, mProjection);
275f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            }
276f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein
277928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein            if (mThumbnailUri != null) {
278928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein                mIntent.putExtra(EXTRA_THUMBNAIL_URI, mThumbnailUri);
279928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein            }
280928a39fb533255b34145285fabbd4f51961df63aAndrew Sapperstein
28191dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp            if (mMaxInitialScale != null) {
28291dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp                mIntent.putExtra(EXTRA_MAX_INITIAL_SCALE, mMaxInitialScale);
28391dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp            }
28491dbfd25cc234de393ae22fc39a832a6335e1bc2Adam Copp
2857732839c0cd9d87954a07e166b52b93cabea1374Adam Copp            if (mWatchNetwork == true) {
2867732839c0cd9d87954a07e166b52b93cabea1374Adam Copp                mIntent.putExtra(EXTRA_WATCH_NETWORK, true);
2877732839c0cd9d87954a07e166b52b93cabea1374Adam Copp            }
2887732839c0cd9d87954a07e166b52b93cabea1374Adam Copp
289ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mIntent.putExtra(EXTRA_SCALE_UP_ANIMATION, mScaleAnimation);
290ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            if (mScaleAnimation) {
291ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                mIntent.putExtra(EXTRA_ANIMATION_START_X, mStartX);
292ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                mIntent.putExtra(EXTRA_ANIMATION_START_Y, mStartY);
293ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                mIntent.putExtra(EXTRA_ANIMATION_START_WIDTH, mStartWidth);
294ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon                mIntent.putExtra(EXTRA_ANIMATION_START_HEIGHT, mStartHeight);
295ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            }
296ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
297ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mIntent.putExtra(EXTRA_ACTION_BAR_HIDDEN_INITIALLY, mActionBarHiddenInitially);
298ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon            mIntent.putExtra(EXTRA_DISPLAY_THUMBS_FULLSCREEN, mDisplayFullScreenThumbs);
299ca8fdcd23fcc53e0429abf8d4ef80e8d6d8fe6faMartin Hibdon
300f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein            return mIntent;
301f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein        }
302f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein    }
303f77a7eb196d16110c7b1087352b423913821ff61Andrew Sapperstein}
304