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.location.Location; 20 import android.net.Uri; 21 22 import com.android.camera.app.MediaSaver.OnMediaSavedListener; 23 import com.android.camera.exif.ExifInterface; 24 25 import java.io.File; 26 import java.io.IOException; 27 28 /** 29 * Modules use this manager to store capture results. 30 */ 31 public interface CaptureSessionManager { 32 /** 33 * Callback interface for session events. 34 */ 35 public interface SessionListener { 36 /** 37 * Called when the session with the given Uri was queued and will be 38 * processed. 39 */ 40 public void onSessionQueued(Uri mediaUri); 41 42 /** 43 * Called when the media underlying the session with the given Uri has 44 * been updated. 45 */ 46 public void onSessionUpdated(Uri mediaUri); 47 48 /** 49 * Called when the preview of the media underlying the session with the 50 * given Uri has been updated. 51 */ 52 public void onSessionPreviewAvailable(Uri mediaUri); 53 54 /** Called when the session with the given Uri finished. */ 55 public void onSessionDone(Uri mediaUri); 56 57 /** Called when the session with the given Uri failed processing. */ 58 public void onSessionFailed(Uri mediaUri, CharSequence reason); 59 60 /** Called when the session with the given Uri has progressed. */ 61 public void onSessionProgress(Uri mediaUri, int progress); 62 63 /** Called when the session with the given Uri has changed its progress text. */ 64 public void onSessionProgressText(Uri mediaUri, CharSequence message); 65 } 66 67 /** 68 * Creates a new capture session. 69 * 70 * @param title the title of the new session. 71 * @param sessionStartMillis the start time of the new session (millis since epoch). 72 * @param location the location of the new session. 73 */ 74 CaptureSession createNewSession(String title, long sessionStartMillis, Location location); 75 76 /** 77 * Creates a session based on an existing URI in the filmstrip and media 78 * store. This can be used to re-process an image. 79 */ 80 CaptureSession createSession(); 81 82 /** 83 * Returns a session by session Uri or null if it is not found. 84 * 85 * @param sessionUri the Uri to look up. 86 * 87 * @return The corresponding CaptureSession. 88 */ 89 CaptureSession getSession(Uri sessionUri); 90 91 /** 92 * Save an image without creating a session that includes progress. 93 * 94 * @param data the image data to be saved. 95 * @param title the title of the media item. 96 * @param date the timestamp of the capture. 97 * @param loc the capture location. 98 * @param width the width of the captured image. 99 * @param height the height of the captured image. 100 * @param orientation the orientation of the captured image. 101 * @param exif the EXIF data of the captured image. 102 * @param listener called when saving is complete. 103 */ 104 void saveImage(byte[] data, String title, long date, Location loc, int width, int height, 105 int orientation, ExifInterface exif, OnMediaSavedListener listener); 106 107 /** 108 * Add a listener to be informed about capture session updates. 109 * <p> 110 * Note: It is guaranteed that the callbacks will happen on the main thread, 111 * so callers have to make sure to not block execution. 112 */ 113 public void addSessionListener(SessionListener listener); 114 115 /** 116 * Adds the session with the given uri. 117 */ 118 public void putSession(Uri sessionUri, CaptureSession session); 119 120 /** 121 * Removes a previously added listener from receiving further capture 122 * session updates. 123 */ 124 public void removeSessionListener(SessionListener listener); 125 126 /** 127 * Calls the given listener for all the sessions that are currently 128 * in-flight. 129 */ 130 public void fillTemporarySession(SessionListener listener); 131 132 /** 133 * Gets the directory to be used for temporary data. See 134 * {@link SessionStorageManager#getSessionDirectory(String)} 135 */ 136 public File getSessionDirectory(String subDirectory) throws IOException; 137 138 /** 139 * @return Whether the session with the given URI exists and has an error 140 * message. 141 */ 142 public boolean hasErrorMessage(Uri uri); 143 144 /** 145 * @return If existant, returns the error message for the session with the 146 * given URI. 147 */ 148 public CharSequence getErrorMesage(Uri uri); 149 150 /** 151 * Removes any existing error messages for the session with the given URI. 152 */ 153 public void removeErrorMessage(Uri uri); 154 } 155