Home | History | Annotate | Download | only in common
      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.one.v2.common;
     18 
     19 import android.annotation.TargetApi;
     20 import android.hardware.camera2.CaptureRequest;
     21 import android.os.Build.VERSION_CODES;
     22 
     23 import com.android.camera.one.OneCameraCharacteristics.FaceDetectMode;
     24 import com.android.camera.one.OneCameraCharacteristics.SupportedHardwareLevel;
     25 import com.google.common.base.Supplier;
     26 
     27 /**
     28  * Computes the current scene mode to use based on the HDR and face detect modes.
     29  */
     30 @TargetApi(VERSION_CODES.LOLLIPOP)
     31 public class ControlSceneModeSelector implements Supplier<Integer> {
     32     // API 21 omitted this constant officially, but kept it around as a hidden constant
     33     // MR1 brings it back officially as the same int value.
     34     public static final int CONTROL_SCENE_MODE_HDR = 0x12;
     35 
     36     private final Supplier<Boolean> mHdrSetting;
     37     private final Supplier<FaceDetectMode> mFaceDetectMode;
     38     private final SupportedHardwareLevel mSupportedHardwareLevel;
     39 
     40     public ControlSceneModeSelector(Supplier<Boolean> hdrSetting,
     41           Supplier<FaceDetectMode> faceDetectMode,
     42           SupportedHardwareLevel supportedHardwareLevel) {
     43         mHdrSetting = hdrSetting;
     44         mFaceDetectMode = faceDetectMode;
     45         mSupportedHardwareLevel = supportedHardwareLevel;
     46     }
     47 
     48     @Override
     49     public Integer get() {
     50         if (mSupportedHardwareLevel == SupportedHardwareLevel.LEGACY) {
     51             if (mHdrSetting.get()) {
     52                 return CONTROL_SCENE_MODE_HDR;
     53             }
     54         }
     55 
     56         if (mFaceDetectMode.get() == FaceDetectMode.FULL ||
     57               mFaceDetectMode.get() == FaceDetectMode.SIMPLE) {
     58             return CaptureRequest.CONTROL_SCENE_MODE_FACE_PRIORITY;
     59         }
     60 
     61         return CaptureRequest.CONTROL_SCENE_MODE_DISABLED;
     62     }
     63 }
     64