/* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.camera.one.v2.photo; import android.net.Uri; import com.android.camera.async.Updatable; import com.android.camera.one.OneCamera; import com.android.camera.session.CaptureSession; import java.util.concurrent.Executor; import javax.annotation.Nonnull; /** * Splits a {@link OneCamera.PictureCallback} into separate thread-safe * callbacks for each method. */ class PictureCallbackAdapter { private final OneCamera.PictureCallback mPictureCallback; private final Executor mMainExecutor; public PictureCallbackAdapter(OneCamera.PictureCallback pictureCallback, Executor mainExecutor) { mPictureCallback = pictureCallback; mMainExecutor = mainExecutor; } public Updatable provideQuickExposeUpdatable() { return new Updatable() { @Override public void update(@Nonnull Void v) { mMainExecutor.execute(new Runnable() { public void run() { mPictureCallback.onQuickExpose(); } }); } }; } public Updatable provideThumbnailUpdatable() { return new Updatable() { @Override public void update(@Nonnull final byte[] jpegData) { mMainExecutor.execute(new Runnable() { public void run() { mPictureCallback.onThumbnailResult(jpegData); } }); } }; } public Updatable providePictureTakenUpdatable() { return new Updatable() { @Override public void update(@Nonnull final CaptureSession session) { mMainExecutor.execute(new Runnable() { public void run() { mPictureCallback.onPictureTaken(session); } }); } }; } public Updatable providePictureSavedUpdatable() { return new Updatable() { @Override public void update(@Nonnull final Uri uri) { mMainExecutor.execute(new Runnable() { @Override public void run() { mPictureCallback.onPictureSaved(uri); } }); } }; } public Updatable providePictureTakingFailedUpdatable() { return new Updatable() { @Override public void update(@Nonnull Void v) { mMainExecutor.execute(new Runnable() { @Override public void run() { mPictureCallback.onPictureTakingFailed(); } }); } }; } public Updatable providePictureTakingProgressUpdatable() { return new Updatable() { @Override public void update(@Nonnull final Float progress) { mMainExecutor.execute(new Runnable() { @Override public void run() { mPictureCallback.onTakePictureProgress(progress); } }); } }; } }