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