Home | History | Annotate | Download | only in photo
      1 /*
      2  * Copyright (C) 2014 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.one.v2.photo;
     18 
     19 import android.net.Uri;
     20 
     21 import com.android.camera.async.Updatable;
     22 import com.android.camera.one.OneCamera;
     23 import com.android.camera.session.CaptureSession;
     24 
     25 import java.util.concurrent.Executor;
     26 
     27 import javax.annotation.Nonnull;
     28 
     29 /**
     30  * Splits a {@link OneCamera.PictureCallback} into separate thread-safe
     31  * callbacks for each method.
     32  */
     33 class PictureCallbackAdapter {
     34     private final OneCamera.PictureCallback mPictureCallback;
     35     private final Executor mMainExecutor;
     36 
     37     public PictureCallbackAdapter(OneCamera.PictureCallback pictureCallback,
     38           Executor mainExecutor) {
     39         mPictureCallback = pictureCallback;
     40         mMainExecutor = mainExecutor;
     41     }
     42 
     43     public Updatable<Void> provideQuickExposeUpdatable() {
     44         return new Updatable<Void>() {
     45             @Override
     46             public void update(@Nonnull Void v) {
     47                 mMainExecutor.execute(new Runnable() {
     48                     public void run() {
     49                         mPictureCallback.onQuickExpose();
     50                     }
     51                 });
     52             }
     53         };
     54     }
     55 
     56     public Updatable<byte[]> provideThumbnailUpdatable() {
     57         return new Updatable<byte[]>() {
     58             @Override
     59             public void update(@Nonnull final byte[] jpegData) {
     60                 mMainExecutor.execute(new Runnable() {
     61                     public void run() {
     62                         mPictureCallback.onThumbnailResult(jpegData);
     63                     }
     64                 });
     65             }
     66         };
     67     }
     68 
     69     public Updatable<CaptureSession> providePictureTakenUpdatable() {
     70         return new Updatable<CaptureSession>() {
     71             @Override
     72             public void update(@Nonnull final CaptureSession session) {
     73                 mMainExecutor.execute(new Runnable() {
     74                     public void run() {
     75                         mPictureCallback.onPictureTaken(session);
     76                     }
     77                 });
     78             }
     79         };
     80     }
     81 
     82     public Updatable<Uri> providePictureSavedUpdatable() {
     83         return new Updatable<Uri>() {
     84             @Override
     85             public void update(@Nonnull final Uri uri) {
     86                 mMainExecutor.execute(new Runnable() {
     87                     @Override
     88                     public void run() {
     89                         mPictureCallback.onPictureSaved(uri);
     90                     }
     91                 });
     92             }
     93         };
     94     }
     95 
     96     public Updatable<Void> providePictureTakingFailedUpdatable() {
     97         return new Updatable<Void>() {
     98             @Override
     99             public void update(@Nonnull Void v) {
    100                 mMainExecutor.execute(new Runnable() {
    101                     @Override
    102                     public void run() {
    103                         mPictureCallback.onPictureTakingFailed();
    104                     }
    105                 });
    106             }
    107         };
    108     }
    109 
    110     public Updatable<Float> providePictureTakingProgressUpdatable() {
    111         return new Updatable<Float>() {
    112             @Override
    113             public void update(@Nonnull final Float progress) {
    114                 mMainExecutor.execute(new Runnable() {
    115                     @Override
    116                     public void run() {
    117                         mPictureCallback.onTakePictureProgress(progress);
    118                     }
    119                 });
    120             }
    121         };
    122     }
    123 }
    124