summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/session/CaptureSession.java
blob: 0dff1a1b3f104fb808df1fba0b4916a6bec08b52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.camera.session;

import android.graphics.Bitmap;
import android.location.Location;
import android.net.Uri;

import com.android.camera.exif.ExifInterface;
import com.android.camera.stats.CaptureSessionStatsCollector;
import com.android.camera.util.Size;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * A session is an item that is in progress of being created and saved, such as
 * a photo sphere or HDR+ photo.
 */
public interface CaptureSession {

    /** Classes implementing this interface can produce a capture session. */
    public static interface CaptureSessionCreator {
        /** Creates and starts a new capture session. */
        public CaptureSession createAndStartEmpty();
    }

    /**
     * Classes implementing this interface can listen to progress updates of
     * this session.
     */
    public static interface ProgressListener {
        /**
         * Called when the progress is changed.
         *
         * @param progressPercent The current progress in percent.
         */
        public void onProgressChanged(int progressPercent);

        /**
         * Called when the progress message is changed.
         *
         * @param messageId The current progress message ID.
         */
        public void onStatusMessageChanged(int messageId);
    }

    /**
     * Classes implementing this interface can listen to progress updates of
     * this session.
     */
    public static interface ImageLifecycleListener {
        /**
         * Occurs when, for a particular image type, an image capture has
         * started. This method is always executed, and will always be called
         * first.
         */
        public void onCaptureStarted();

        /**
         * Occurs when the tiny thumbnail bytes are received.
         */
        public void onTinyThumb();

        /**
         * Occurs when the medium thumbnail bytes are received.
         */
        public void onMediumThumb();

        /**
         * Occurs when rendering/processing/encoding starts for the full size image.
         */
        public void onProcessingStarted();

        /**
         * Occurs when the rendering/processing/encoding for the full size image
         * is completed.
         */
        public void onProcessingComplete();

        /**
         * This occurs after all the bytes are physically on disk.
         */
        public void onCapturePersisted();
    }

    /** Returns the title/name of this session. */
    public String getTitle();

    /** Returns the location of this session or null. */
    public Location getLocation();

    /** Sets the location of this session. */
    public void setLocation(Location location);

    /**
     * Set the progress in percent for the current session. If set to or left at
     * 0, no progress bar is shown.
     */
    public void setProgress(int percent);

    /**
     * Returns the progress of this session in percent.
     */
    public int getProgress();

    /**
     * Returns the current progress message.
     */
    public int getProgressMessageId();

    /**
     * Changes the progress status message of this session.
     *
     * @param messageId the ID of the new message
     */
    public void setProgressMessage(int messageId);

    /**
     * For an ongoing session, this updates the currently displayed thumbnail.
     *
     * @param bitmap the thumbnail to be shown while the session is in progress.
     */
    public void updateThumbnail(Bitmap bitmap);

    /**
     * For an ongoing session, this updates the capture indicator thumbnail.
     *
     * @param bitmap the thumbnail to be shown while the session is in progress.
     *            update the capture indicator
     * @param rotationDegrees the rotation of the thumbnail in degrees
     */
    public void updateCaptureIndicatorThumbnail(Bitmap bitmap, int rotationDegrees);

    /**
     * Starts an empty session with the given placeholder size.
     *
     * @param listener receives events as the session progresses.
     * @param pictureSize the size, in pixels of the empty placeholder.
     */
    public void startEmpty(@Nullable ImageLifecycleListener listener, @Nonnull Size pictureSize);

    /**
     * Starts the session by adding a placeholder to the filmstrip and adding
     * notifications.
     *
     * @param listener receives events as the session progresses.
     * @param placeholder a valid encoded bitmap to be used as the placeholder.
     * @param progressMessageId the message to be used to the progress
     *            notification initially. This can later be changed using
     *            {@link #setProgressMessage(int)}.
     */
    public void startSession(@Nullable ImageLifecycleListener listener, @Nonnull byte[] placeholder,
          int progressMessageId);

    /**
     * Starts the session by adding a placeholder to the filmstrip and adding
     * notifications.
     *
     * @param listener receives events as the session progresses.
     * @param placeholder a valid bitmap to be used as the placeholder.
     * @param progressMessageId the message to be used to the progress
     *            notification initially. This can later be changed using
     *            {@link #setProgressMessage(int)}.
     */
    @VisibleForTesting
    public void startSession(@Nullable ImageLifecycleListener listener, @Nonnull Bitmap placeholder,
          int progressMessageId);

    /**
     * Starts the session by marking the item as in-progress and adding
     * notifications.
     *
     * @param listener receives events as the session progresses.
     * @param uri the URI of the item to be re-processed.
     * @param progressMessageId the message to be used to the progress
     *            notification initially. This can later be changed using
     *            {@link #setProgressMessage(int)}.
     */
    public void startSession(@Nullable ImageLifecycleListener listener, @Nonnull Uri uri,
          int progressMessageId);

    /**
     * Cancel the session without a final result. The session will be removed
     * from the film strip, progress notifications will be cancelled.
     */
    public void cancel();

    /**
     * Finish the session by saving the image to disk. Will add the final item
     * in the film strip and remove the progress notifications.
     *
     * @param data the data of the data (e.g. JPEG bytes) that should be written
     *            to disk.
     * @param width the width of the media item, in pixels.
     * @param height the height of the media item, in pixels.
     * @param orientation the orientaiton of the media item, in degrees.
     * @param exif the EXIF information for this media item.
     * @return A future that will provide the URI once the item is saved. URI
     *         might be absent if the data could not be saved successfull, which
     *         in turn means if a URI is returned it is guaranteed that the
     *         media item was successfully written to disk.
     */
    public ListenableFuture<Optional<Uri>> saveAndFinish(byte[] data, int width, int height,
            int orientation, ExifInterface exif);

    /**
     * Will create and return a {@link StackSaver} for saving out a number of
     * media items to a stack. The name of the stack will be the title of this
     * capture session.
     */
    public StackSaver getStackSaver();

    /**
     * Finishes the session. Resources may be held during notification of
     * finished state, {@link #finalizeSession()} must be called to fully complete
     * the session.
     */
    public void finish();

    /**
     * Finish the session and indicate it failed. Resources may be held during
     * notification of finished state, {@link #finalizeSession()} must be called to
     * fully complete the session.
     */
    public void finishWithFailure(int failureMessageId, boolean removeFromFilmstrip);

    /**
     * All processing complete, finalize the session and remove any resources.
     */
    public void finalizeSession();

    /**
     * Returns the file to where the final output of this session should be
     * stored. This is only available after startSession has been called and
     * will become unavailable after finish() was called.
     */
    public TemporarySessionFile getTempOutputFile();

    /**
     * Returns the URI to the final output of this session. This is only
     * available after startSession has been called.
     */
    public Uri getUri();

    /**
     * Updates the preview from the file created from
     * {@link #getTempOutputFile()}.
     */
    public void updatePreview();

    /**
     * Adds a progress listener to this session.
     */
    public void addProgressListener(ProgressListener listener);

    /**
     * Removes the given progress listener from this session.
     */
    public void removeProgressListener(ProgressListener listener);

    /**
     * Returns the associated StatsCollector Object
     * @return
     */
    public CaptureSessionStatsCollector getCollector();
}