Home | History | Annotate | Download | only in resource
      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.resource;
     18 
     19 import android.graphics.PointF;
     20 import android.view.Surface;
     21 
     22 import com.android.camera.async.RefCountBase;
     23 import com.android.camera.debug.Log;
     24 import com.android.camera.device.CameraId;
     25 import com.android.camera.one.OneCamera;
     26 import com.android.camera.one.OneCameraCaptureSetting;
     27 import com.android.camera.one.OneCameraCharacteristics;
     28 import com.android.camera.util.Size;
     29 
     30 public final class ResourceOpenedCameraImpl implements ResourceOpenedCamera {
     31     private static final Log.Tag TAG = new Log.Tag("ResOpenedCam");
     32 
     33     /** The camera object. */
     34     private final OneCamera mCamera;
     35 
     36     /** The camera device key. */
     37     private final CameraId mCameraId;
     38 
     39     /** The camera facing. */
     40     private final OneCamera.Facing mCameraFacing;
     41 
     42     /** The camera characteristics. */
     43     private final OneCameraCharacteristics mCameraCharacteristics;
     44 
     45     /** The desired picture size. */
     46     private final Size mPictureSize;
     47 
     48     /** The current zoom ratio. */
     49     private float mZoomRatio;
     50 
     51     private final OneCameraCaptureSetting mOneCameraCaptureSetting;
     52 
     53     /**
     54      * Creates a reference counted {@link ResourceOpenedCameraImpl} object.
     55      */
     56     public static RefCountBase<ResourceOpenedCamera> create(
     57             OneCamera camera,
     58             CameraId cameraId,
     59             OneCamera.Facing cameraFacing,
     60             OneCameraCharacteristics cameraCharacteristics,
     61             Size pictureSize,
     62             OneCameraCaptureSetting captureSetting) {
     63         ResourceOpenedCamera resourceOpenedCamera = new ResourceOpenedCameraImpl(
     64                 camera, cameraId, cameraFacing, cameraCharacteristics, pictureSize, captureSetting);
     65         return new RefCountBase<>(resourceOpenedCamera);
     66     }
     67 
     68     private ResourceOpenedCameraImpl(
     69             OneCamera camera,
     70             CameraId cameraId,
     71             OneCamera.Facing cameraFacing,
     72             OneCameraCharacteristics cameraCharacteristics,
     73             Size pictureSize,
     74             OneCameraCaptureSetting captureSetting) {
     75         mCamera = camera;
     76         mCameraId = cameraId;
     77         mCameraFacing = cameraFacing;
     78         mCameraCharacteristics = cameraCharacteristics;
     79         mPictureSize = pictureSize;
     80         mZoomRatio = mCamera.getMaxZoom();
     81         mOneCameraCaptureSetting = captureSetting;
     82     }
     83 
     84     @Override
     85     public void close() {
     86         Log.d(TAG, "close");
     87         mCamera.setFocusStateListener(null);
     88         mCamera.close();
     89     }
     90 
     91     @Override
     92     public OneCamera getCamera() {
     93         return mCamera;
     94     }
     95 
     96     @Override
     97     public CameraId getCameraId() {
     98         return mCameraId;
     99     }
    100 
    101     @Override
    102     public OneCamera.Facing getCameraFacing() {
    103         return mCameraFacing;
    104     }
    105 
    106     @Override
    107     public OneCameraCharacteristics getCameraCharacteristics() {
    108         return mCameraCharacteristics;
    109     }
    110 
    111     @Override
    112     public Size getPictureSize() {
    113         return mPictureSize;
    114     }
    115 
    116     @Override
    117     public OneCameraCaptureSetting getCaptureSetting() {
    118         return mOneCameraCaptureSetting;
    119     }
    120 
    121     @Override
    122     public float getZoomRatio() {
    123         return mZoomRatio;
    124     }
    125 
    126     @Override
    127     public void setZoomRatio(float zoomRatio) {
    128         mZoomRatio = zoomRatio;
    129         mCamera.setZoom(zoomRatio);
    130     }
    131 
    132     @Override
    133     public void startPreview(
    134             Surface previewSurface, OneCamera.CaptureReadyCallback captureReadyCallback) {
    135         mCamera.startPreview(previewSurface, captureReadyCallback);
    136     }
    137 
    138     @Override
    139     public void triggerFocusAndMeterAtPoint(PointF point) {
    140         mCamera.triggerFocusAndMeterAtPoint(point.x, point.y);
    141     }
    142 }
    143