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
17package com.android.camera.session;
18
19import android.location.Location;
20import android.net.Uri;
21
22import com.android.camera.app.MediaSaver.OnMediaSavedListener;
23import com.android.camera.exif.ExifInterface;
24
25/**
26 * A session is an item that is in progress of being created and saved, such as
27 * a photo sphere or HDR+ photo.
28 */
29public interface CaptureSession {
30    /**
31     * Classes implementing this interface can listen to progress updates of
32     * this session.
33     */
34    public static interface ProgressListener {
35        /**
36         * Called when the progress is changed.
37         *
38         * @param progressPercent The current progress in percent.
39         */
40        public void onProgressChanged(int progressPercent);
41
42        /**
43         * Called when the progress message is changed.
44         *
45         * @param message The current progress message.
46         */
47        public void onStatusMessageChanged(CharSequence message);
48    }
49
50    /** Returns the title/name of this session. */
51    public String getTitle();
52
53    /** Returns the location of this session or null. */
54    public Location getLocation();
55
56    /** Sets the location of this session. */
57    public void setLocation(Location location);
58
59    /**
60     * Set the progress in percent for the current session. If set to or left at
61     * 0, no progress bar is shown.
62     */
63    public void setProgress(int percent);
64
65    /**
66     * Returns the progress of this session in percent.
67     */
68    public int getProgress();
69
70    /**
71     * Returns the current progress message.
72     */
73    public CharSequence getProgressMessage();
74
75    /**
76     * Starts the session by adding a placeholder to the filmstrip and adding
77     * notifications.
78     *
79     * @param placeholder a valid encoded bitmap to be used as the placeholder.
80     * @param progressMessage the message to be used to the progress
81     *            notification initially. This can later be changed using
82     *            {@link #setProgressMessage(CharSequence)}.
83     */
84    public void startSession(byte[] placeholder, CharSequence progressMessage);
85
86    /**
87     * Starts the session by marking the item as in-progress and adding
88     * notifications.
89     *
90     * @param uri the URI of the item to be re-processed.
91     * @param progressMessage the message to be used to the progress
92     *            notification initially. This can later be changed using
93     *            {@link #setProgressMessage(CharSequence)}.
94     */
95    public void startSession(Uri uri, CharSequence progressMessage);
96
97    /**
98     * Start a session like this if it's not processing for a long time and
99     * therefore doesn't need a temporary placeholder or a progress message.
100     */
101    public void startEmpty();
102
103    /**
104     * Cancel the session without a final result. The session will be removed
105     * from the film strip, progress notifications will be cancelled.
106     */
107    public void cancel();
108
109    /**
110     * Changes the progress status message of this session.
111     *
112     * @param message the new message
113     */
114    public void setProgressMessage(CharSequence message);
115
116    /**
117     * Finish the session by saving the image to disk. Will add the final item
118     * in the film strip and remove the progress notifications.
119     */
120    public void saveAndFinish(byte[] data, int width, int height, int orientation,
121            ExifInterface exif, OnMediaSavedListener listener);
122
123    /**
124     * Finishes the session.
125     */
126    public void finish();
127
128    /**
129     * Finish the session and indicate it failed.
130     */
131    public void finishWithFailure(CharSequence reason);
132
133    /**
134     * Returns the path to the final output of this session. This is only
135     * available after startSession has been called.
136     */
137    public String getPath();
138
139    /**
140     * Returns the URI to the final output of this session. This is only available
141     * after startSession has been called.
142     */
143    public Uri getUri();
144
145    /**
146     * Returns the Content URI to the final output of this session. This is only
147     * available if the session has been finished.
148     *
149     * Returns null if it has not been finished.
150     */
151    public Uri getContentUri();
152
153    /**
154     * Whether this session already has a path. This is the case once it has
155     * been started. False is returned, if the session has not been started yet
156     * and no path is available.
157     */
158    public boolean hasPath();
159
160    /**
161     * Updates the preview from a file. {@link #onPreviewAvailable()} will be
162     * invoked upon completion.
163     *
164     * @param previewPath The path to the file.
165     */
166    public void updatePreview(String previewPath);
167
168    /**
169     * Called when the preview is already available.
170     */
171    public void onPreviewAvailable();
172
173    /**
174     * Adds a progress listener to this session.
175     */
176    public void addProgressListener(ProgressListener listener);
177
178    /**
179     * Removes the given progress listener from this session.
180     */
181    public void removeProgressListener(ProgressListener listener);
182}
183