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.app;
18
19import android.content.ContentValues;
20import android.location.Location;
21import android.net.Uri;
22
23import com.android.camera.exif.ExifInterface;
24
25/**
26 * An interface defining the media saver which saves media files in the
27 * background.
28 */
29public interface MediaSaver {
30
31    /**
32     * An interface defining the callback for task queue status changes.
33     */
34    public interface QueueListener {
35        /**
36         * The callback when the queue status changes. Every time a new
37         * {@link com.android.camera.app.MediaSaver.QueueListener} is set by
38         * {@link #setQueueListener(com.android.camera.app.MediaSaver.QueueListener)}
39         * this callback will be invoked to notify the current status of the
40         * queue.
41         *
42         * @param full Whether the queue is full.
43         */
44        public void onQueueStatus(boolean full);
45    }
46
47    /**
48     * An interface defining the callback when a media is saved.
49     */
50    public interface OnMediaSavedListener {
51        /**
52         * The callback when the saving is done in the background.
53         * @param uri The final content Uri of the saved media.
54         */
55        public void onMediaSaved(Uri uri);
56    }
57
58    /**
59     * Checks whether the queue is full.
60     */
61    boolean isQueueFull();
62
63    /**
64     * Adds an image into {@link android.content.ContentResolver} and also
65     * saves the file to the storage in the background.
66     * <p/>
67     * Equivalent to calling
68     * {@link #addImage(byte[], String, long, Location, int, int, int,
69     * ExifInterface, OnMediaSavedListener, String)}
70     * with <code>image/jpeg</code> as <code>mimeType</code>.
71     *
72     * @param data The JPEG image data.
73     * @param title The title of the image.
74     * @param date The date when the image is created.
75     * @param loc The location where the image is created. Can be {@code null}.
76     * @param width The width of the image data before the orientation is
77     *              applied.
78     * @param height The height of the image data before the orientation is
79     *               applied.
80     * @param orientation The orientation of the image. The value should be a
81     *                    degree of rotation in clockwise. Valid values are
82     *                    0, 90, 180 and 270.
83     * @param exif The EXIF data of this image.
84     * @param l A callback object used when the saving is done.
85     */
86    void addImage(byte[] data, String title, long date, Location loc, int width, int height,
87            int orientation, ExifInterface exif, OnMediaSavedListener l);
88
89    /**
90     * Adds an image into {@link android.content.ContentResolver} and also
91     * saves the file to the storage in the background.
92     *
93     * @param data The image data.
94     * @param title The title of the image.
95     * @param date The date when the image is created.
96     * @param loc The location where the image is created. Can be {@code null}.
97     * @param width The width of the image data before the orientation is
98     *              applied.
99     * @param height The height of the image data before the orientation is
100     *               applied.
101     * @param orientation The orientation of the image. The value should be a
102     *                    degree of rotation in clockwise. Valid values are
103     *                    0, 90, 180 and 270.
104     * @param exif The EXIF data of this image.
105     * @param l A callback object used when the saving is done.
106     * @param mimeType The mimeType of the image.
107     */
108    void addImage(byte[] data, String title, long date, Location loc, int width, int height,
109            int orientation, ExifInterface exif, OnMediaSavedListener l, String mimeType);
110
111    /**
112     * Adds an image into {@link android.content.ContentResolver} and also
113     * saves the file to the storage in the background. The width and height
114     * will be obtained directly from the image data.
115     *
116     * @param data The JPEG image data.
117     * @param title The title of the image.
118     * @param date The date when the image is created.
119     * @param loc The location where the image is created. Can be {@code null}.
120     * @param orientation The orientation of the image. The value should be a
121     *                    degree of rotation in clockwise. Valid values are
122     *                    0, 90, 180 and 270.
123     * @param exif The EXIF data of this image.
124     * @param l A callback object used when the saving is done.
125     */
126    void addImage(byte[] data, String title, long date, Location loc, int orientation,
127            ExifInterface exif, OnMediaSavedListener l);
128
129    /**
130     * Adds an image into {@link android.content.ContentResolver} and also
131     * saves the file to the storage in the background. The time will be set by
132     * {@link System#currentTimeMillis()}.
133     * will be obtained directly from the image data.
134     *
135     * @param data The JPEG image data.
136     * @param title The title of the image.
137     * @param loc The location where the image is created. Can be {@code null}.
138     * @param width The width of the image data before the orientation is
139     *              applied.
140     * @param height The height of the image data before the orientation is
141     *               applied.
142     * @param orientation
143     * @param exif The EXIF data of this image.
144     * @param l A callback object used when the saving is done.
145     */
146    void addImage(byte[] data, String title, Location loc, int width, int height, int orientation,
147            ExifInterface exif, OnMediaSavedListener l);
148
149    /**
150     * Adds the video data into the {@link android.content.ContentResolver} in
151     * the background. Only the database is updated here. The file should
152     * already be created by {@link android.media.MediaRecorder}.
153     * @param path The path of the video file on the storage.
154     * @param values The values to be stored in the database.
155     * @param l A callback object used when the saving is done.
156     */
157    void addVideo(String path, ContentValues values, OnMediaSavedListener l);
158
159    /**
160     * Sets the queue listener.
161     */
162    void setQueueListener(QueueListener l);
163}
164