• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.autofocus;
18 
19 import android.hardware.camera2.CameraAccessException;
20 
21 import com.android.camera.async.ResettingDelayedExecutor;
22 import com.android.camera.async.Updatable;
23 import com.android.camera.one.v2.camera2proxy.CameraCaptureSessionClosedException;
24 import com.android.camera.one.v2.commands.CameraCommand;
25 import com.android.camera.one.v2.core.ResourceAcquisitionFailedException;
26 
27 /**
28  * Performs a full Auto Focus scan, holds for a period of time, and then resets
29  * the preview.
30  */
31 class AFScanHoldResetCommand implements CameraCommand {
32     private final CameraCommand mAFScanCommand;
33     private final ResettingDelayedExecutor mDelayedExecutor;
34     private final Runnable mPreviewRunnable;
35     private final Updatable<MeteringParameters> mMeteringParametersUpdatable;
36 
AFScanHoldResetCommand(CameraCommand afScanCommand, ResettingDelayedExecutor delayedExecutor, Runnable previewRunnable, Updatable<MeteringParameters> meteringParametersUpdatable)37     public AFScanHoldResetCommand(CameraCommand afScanCommand,
38             ResettingDelayedExecutor delayedExecutor,
39             Runnable previewRunnable,
40             Updatable<MeteringParameters> meteringParametersUpdatable) {
41         mAFScanCommand = afScanCommand;
42         mDelayedExecutor = delayedExecutor;
43         mPreviewRunnable = previewRunnable;
44         mMeteringParametersUpdatable = meteringParametersUpdatable;
45     }
46 
47     @Override
run()48     public void run() throws CameraAccessException, InterruptedException,
49             CameraCaptureSessionClosedException, ResourceAcquisitionFailedException {
50         // Reset any delayed preview-restart which may be pending execution as a
51         // result of a previous tap-to-focus.
52         mDelayedExecutor.reset();
53         mAFScanCommand.run();
54         mDelayedExecutor.execute(new Runnable() {
55             public void run() {
56                 // Reset metering regions and restart the preview.
57                 mMeteringParametersUpdatable.update(GlobalMeteringParameters.create());
58                 mPreviewRunnable.run();
59             }
60         });
61     }
62 }
63