• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.camera.session;
18 
19 import android.graphics.Bitmap;
20 import android.location.Location;
21 import android.net.Uri;
22 
23 import com.android.camera.exif.ExifInterface;
24 import com.android.camera.stats.CaptureSessionStatsCollector;
25 import com.android.camera.util.Size;
26 import com.google.common.annotations.VisibleForTesting;
27 import com.google.common.base.Optional;
28 import com.google.common.util.concurrent.ListenableFuture;
29 
30 import javax.annotation.Nonnull;
31 import javax.annotation.Nullable;
32 
33 /**
34  * A session is an item that is in progress of being created and saved, such as
35  * a photo sphere or HDR+ photo.
36  */
37 public interface CaptureSession {
38 
39     /** Classes implementing this interface can produce a capture session. */
40     public static interface CaptureSessionCreator {
41         /** Creates and starts a new capture session. */
createAndStartEmpty()42         public CaptureSession createAndStartEmpty();
43     }
44 
45     /**
46      * Classes implementing this interface can listen to progress updates of
47      * this session.
48      */
49     public static interface ProgressListener {
50         /**
51          * Called when the progress is changed.
52          *
53          * @param progressPercent The current progress in percent.
54          */
onProgressChanged(int progressPercent)55         public void onProgressChanged(int progressPercent);
56 
57         /**
58          * Called when the progress message is changed.
59          *
60          * @param messageId The current progress message ID.
61          */
onStatusMessageChanged(int messageId)62         public void onStatusMessageChanged(int messageId);
63     }
64 
65     /**
66      * Classes implementing this interface can listen to progress updates of
67      * this session.
68      */
69     public static interface ImageLifecycleListener {
70         /**
71          * Occurs when, for a particular image type, an image capture has
72          * started. This method is always executed, and will always be called
73          * first.
74          */
onCaptureStarted()75         public void onCaptureStarted();
76 
77         /**
78          * Occurs when the tiny thumbnail bytes are received.
79          */
onTinyThumb()80         public void onTinyThumb();
81 
82         /**
83          * Occurs when the medium thumbnail bytes are received.
84          */
onMediumThumb()85         public void onMediumThumb();
86 
87         /**
88          * Occurs when rendering/processing/encoding starts for the full size image.
89          */
onProcessingStarted()90         public void onProcessingStarted();
91 
92         /**
93          * Occurs when the rendering/processing/encoding for the full size image
94          * is completed.
95          */
onProcessingComplete()96         public void onProcessingComplete();
97 
98         /**
99          * This occurs after all the bytes are physically on disk.
100          */
onCapturePersisted()101         public void onCapturePersisted();
102 
103         /**
104          * This occurs if a capture session is created but is later canceled for
105          * some reason.
106          */
onCaptureCanceled()107         public void onCaptureCanceled();
108 
109         /**
110          * This occurs if a capture session is created but failed to persist the
111          * final image.
112          */
onCaptureFailed()113         public void onCaptureFailed();
114     }
115 
116     /** Returns the title/name of this session. */
getTitle()117     public String getTitle();
118 
119     /** Returns the location of this session or null. */
getLocation()120     public Location getLocation();
121 
122     /** Sets the location of this session. */
setLocation(Location location)123     public void setLocation(Location location);
124 
125     /**
126      * Set the progress in percent for the current session. If set to or left at
127      * 0, no progress bar is shown.
128      */
setProgress(int percent)129     public void setProgress(int percent);
130 
131     /**
132      * Returns the progress of this session in percent.
133      */
getProgress()134     public int getProgress();
135 
136     /**
137      * Returns the current progress message.
138      */
getProgressMessageId()139     public int getProgressMessageId();
140 
141     /**
142      * Changes the progress status message of this session.
143      *
144      * @param messageId the ID of the new message
145      */
setProgressMessage(int messageId)146     public void setProgressMessage(int messageId);
147 
148     /**
149      * For an ongoing session, this updates the currently displayed thumbnail.
150      *
151      * @param bitmap the thumbnail to be shown while the session is in progress.
152      */
updateThumbnail(Bitmap bitmap)153     public void updateThumbnail(Bitmap bitmap);
154 
155     /**
156      * For an ongoing session, this updates the capture indicator thumbnail.
157      *
158      * @param bitmap the thumbnail to be shown while the session is in progress.
159      *            update the capture indicator
160      * @param rotationDegrees the rotation of the thumbnail in degrees
161      */
updateCaptureIndicatorThumbnail(Bitmap bitmap, int rotationDegrees)162     public void updateCaptureIndicatorThumbnail(Bitmap bitmap, int rotationDegrees);
163 
164     /**
165      * Starts an empty session with the given placeholder size.
166      *
167      * @param listener receives events as the session progresses.
168      * @param pictureSize the size, in pixels of the empty placeholder.
169      */
startEmpty(@ullable ImageLifecycleListener listener, @Nonnull Size pictureSize)170     public void startEmpty(@Nullable ImageLifecycleListener listener, @Nonnull Size pictureSize);
171 
172     /**
173      * Starts the session by adding a placeholder to the filmstrip and adding
174      * notifications.
175      *
176      * @param listener receives events as the session progresses.
177      * @param placeholder a valid encoded bitmap to be used as the placeholder.
178      * @param progressMessageId the message to be used to the progress
179      *            notification initially. This can later be changed using
180      *            {@link #setProgressMessage(int)}.
181      */
startSession(@ullable ImageLifecycleListener listener, @Nonnull byte[] placeholder, int progressMessageId)182     public void startSession(@Nullable ImageLifecycleListener listener, @Nonnull byte[] placeholder,
183           int progressMessageId);
184 
185     /**
186      * Starts the session by adding a placeholder to the filmstrip and adding
187      * notifications.
188      *
189      * @param listener receives events as the session progresses.
190      * @param placeholder a valid bitmap to be used as the placeholder.
191      * @param progressMessageId the message to be used to the progress
192      *            notification initially. This can later be changed using
193      *            {@link #setProgressMessage(int)}.
194      */
195     @VisibleForTesting
startSession(@ullable ImageLifecycleListener listener, @Nonnull Bitmap placeholder, int progressMessageId)196     public void startSession(@Nullable ImageLifecycleListener listener, @Nonnull Bitmap placeholder,
197           int progressMessageId);
198 
199     /**
200      * Starts the session by marking the item as in-progress and adding
201      * notifications.
202      *
203      * @param listener receives events as the session progresses.
204      * @param uri the URI of the item to be re-processed.
205      * @param progressMessageId the message to be used to the progress
206      *            notification initially. This can later be changed using
207      *            {@link #setProgressMessage(int)}.
208      */
startSession(@ullable ImageLifecycleListener listener, @Nonnull Uri uri, int progressMessageId)209     public void startSession(@Nullable ImageLifecycleListener listener, @Nonnull Uri uri,
210           int progressMessageId);
211 
212     /**
213      * Cancel the session without a final result. The session will be removed
214      * from the film strip, progress notifications will be cancelled.
215      */
cancel()216     public void cancel();
217 
218     /**
219      * Finish the session by saving the image to disk. Will add the final item
220      * in the film strip and remove the progress notifications.
221      *
222      * @param data the data of the data (e.g. JPEG bytes) that should be written
223      *            to disk.
224      * @param width the width of the media item, in pixels.
225      * @param height the height of the media item, in pixels.
226      * @param orientation the orientaiton of the media item, in degrees.
227      * @param exif the EXIF information for this media item.
228      * @return A future that will provide the URI once the item is saved. URI
229      *         might be absent if the data could not be saved successfull, which
230      *         in turn means if a URI is returned it is guaranteed that the
231      *         media item was successfully written to disk.
232      */
saveAndFinish(byte[] data, int width, int height, int orientation, ExifInterface exif)233     public ListenableFuture<Optional<Uri>> saveAndFinish(byte[] data, int width, int height,
234             int orientation, ExifInterface exif);
235 
236     /**
237      * Will create and return a {@link StackSaver} for saving out a number of
238      * media items to a stack. The name of the stack will be the title of this
239      * capture session.
240      */
getStackSaver()241     public StackSaver getStackSaver();
242 
243     /**
244      * Finishes the session. Resources may be held during notification of
245      * finished state, {@link #finalizeSession()} must be called to fully complete
246      * the session.
247      */
finish()248     public void finish();
249 
250     /**
251      * Finish the session and indicate it failed. Resources may be held during
252      * notification of finished state, {@link #finalizeSession()} must be called to
253      * fully complete the session.
254      */
finishWithFailure(int failureMessageId, boolean removeFromFilmstrip)255     public void finishWithFailure(int failureMessageId, boolean removeFromFilmstrip);
256 
257     /**
258      * All processing complete, finalize the session and remove any resources.
259      */
finalizeSession()260     public void finalizeSession();
261 
262     /**
263      * Returns the file to where the final output of this session should be
264      * stored. This is only available after startSession has been called and
265      * will become unavailable after finish() was called.
266      */
getTempOutputFile()267     public TemporarySessionFile getTempOutputFile();
268 
269     /**
270      * Returns the URI to the final output of this session. This is only
271      * available after startSession has been called.
272      */
getUri()273     public Uri getUri();
274 
275     /**
276      * Updates the preview from the file created from
277      * {@link #getTempOutputFile()}.
278      */
updatePreview()279     public void updatePreview();
280 
281     /**
282      * Adds a progress listener to this session.
283      */
addProgressListener(ProgressListener listener)284     public void addProgressListener(ProgressListener listener);
285 
286     /**
287      * Removes the given progress listener from this session.
288      */
removeProgressListener(ProgressListener listener)289     public void removeProgressListener(ProgressListener listener);
290 
291     /**
292      * Returns the associated StatsCollector Object
293      * @return
294      */
getCollector()295     public CaptureSessionStatsCollector getCollector();
296 }
297