1 /* 2 * Copyright (C) 2015 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.captureintent; 18 19 import android.graphics.Bitmap; 20 import android.location.Location; 21 import android.net.Uri; 22 23 import com.android.camera.debug.Log; 24 import com.android.camera.exif.ExifInterface; 25 import com.android.camera.session.CaptureSession; 26 import com.android.camera.session.CaptureSessionManager; 27 import com.android.camera.session.SessionNotifier; 28 import com.android.camera.session.StackSaver; 29 import com.android.camera.session.TemporarySessionFile; 30 import com.android.camera.stats.CaptureSessionStatsCollector; 31 import com.android.camera.util.Size; 32 import com.google.common.base.Optional; 33 import com.google.common.util.concurrent.Futures; 34 import com.google.common.util.concurrent.ListenableFuture; 35 36 import javax.annotation.Nonnull; 37 38 /** 39 * An implementation of {@link CaptureSession} which is used by 40 * {@link CaptureIntentModule}. 41 */ 42 public class CaptureIntentSession implements CaptureSession { 43 private static final Log.Tag TAG = new Log.Tag("CapIntSession"); 44 45 /** For aggregation of capture information */ 46 // TODO: Implement mCaptureSessionStatsCollector.decorateAtTimeCaptureRequest call. 47 private final CaptureSessionStatsCollector mCaptureSessionStatsCollector = 48 new CaptureSessionStatsCollector(); 49 /** The capture session manager responsible for this session. */ 50 private final CaptureSessionManager mSessionManager; 51 /** Used to inform about session status updates. */ 52 private final SessionNotifier mSessionNotifier; 53 /** The title of the item being processed. */ 54 private final String mTitle; 55 /** The location this session was created at. Used for media store. */ 56 private Location mLocation; 57 /** Whether one of start methods are called. */ 58 private boolean isStarted; 59 60 /** 61 * Creates a new {@link CaptureSession}. 62 * 63 * @param title the title of this session. 64 * @param location the location of this session, used for media store. 65 * @param captureSessionManager the capture session manager responsible for 66 * this session. 67 */ 68 public CaptureIntentSession(String title, Location location, 69 CaptureSessionManager captureSessionManager, SessionNotifier sessionNotifier) { 70 mTitle = title; 71 mLocation = location; 72 mSessionManager = captureSessionManager; 73 mSessionNotifier = sessionNotifier; 74 isStarted = false; 75 } 76 77 @Override 78 public String getTitle() { 79 return mTitle; 80 } 81 82 @Override 83 public Location getLocation() { 84 return mLocation; 85 } 86 87 @Override 88 public void setLocation(Location location) { 89 mLocation = location; 90 } 91 92 // TODO: Support progress in the future once HDR is enabled for capture intent. 93 @Override 94 public synchronized int getProgress() { 95 return 0; 96 } 97 98 @Override 99 public synchronized void setProgress(int percent) { 100 // Do nothing. 101 } 102 103 @Override 104 public synchronized int getProgressMessageId() { 105 return -1; 106 } 107 108 @Override 109 public synchronized void setProgressMessage(int messageId) { 110 } 111 112 @Override 113 public void updateThumbnail(Bitmap bitmap) { 114 mSessionNotifier.notifySessionThumbnailAvailable(bitmap); 115 } 116 117 @Override 118 public void updateCaptureIndicatorThumbnail(Bitmap indicator, int rotationDegrees) { 119 // Do nothing 120 } 121 122 @Override 123 public synchronized void startEmpty(ImageLifecycleListener listener, @Nonnull Size pictureSize) { 124 isStarted = true; 125 } 126 127 @Override 128 public synchronized void startSession(ImageLifecycleListener listener, @Nonnull Bitmap placeholder, 129 int progressMessageId) { 130 throw new RuntimeException("Not supported."); 131 } 132 133 @Override 134 public synchronized void startSession(ImageLifecycleListener listener, @Nonnull byte[] placeholder, 135 int progressMessageId) { 136 throw new RuntimeException("Not supported."); 137 } 138 139 @Override 140 public synchronized void startSession(ImageLifecycleListener listener, @Nonnull Uri uri, 141 @Nonnull int progressMessageId) { 142 throw new RuntimeException("Not supported."); 143 } 144 145 @Override 146 public synchronized void cancel() { 147 } 148 149 @Override 150 public synchronized ListenableFuture<Optional<Uri>> saveAndFinish(byte[] data, int width, 151 int height, int orientation, ExifInterface exif) { 152 mSessionNotifier.notifySessionPictureDataAvailable(data, orientation); 153 return Futures.immediateFuture(Optional.<Uri> absent()); 154 } 155 156 @Override 157 public StackSaver getStackSaver() { 158 return null; 159 } 160 161 @Override 162 public void finish() { 163 // Do nothing. 164 } 165 166 @Override 167 public TemporarySessionFile getTempOutputFile() { 168 throw new RuntimeException("Not supported."); 169 } 170 171 @Override 172 public Uri getUri() { 173 throw new RuntimeException("Not supported."); 174 } 175 176 @Override 177 public void updatePreview() { 178 throw new RuntimeException("Not supported."); 179 } 180 181 @Override 182 public void finishWithFailure(int progressMessageId, boolean removeFromFilmstrip) { 183 throw new RuntimeException("Not supported."); 184 } 185 186 @Override 187 public void finalizeSession() { 188 // Do nothing. 189 } 190 191 @Override 192 public void addProgressListener(CaptureSession.ProgressListener listener) { 193 // Do nothing. 194 } 195 196 @Override 197 public void removeProgressListener(CaptureSession.ProgressListener listener) { 198 // Do nothing. 199 } 200 201 @Override 202 public CaptureSessionStatsCollector getCollector() { 203 return mCaptureSessionStatsCollector; 204 } 205 206 private boolean isStarted() { 207 return isStarted; 208 } 209 } 210