Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2012 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;
     18 
     19 import android.view.KeyEvent;
     20 import android.view.View;
     21 
     22 import com.android.camera.app.AppController;
     23 import com.android.camera.app.CameraProvider;
     24 import com.android.camera.app.CameraServices;
     25 import com.android.camera.module.ModuleController;
     26 
     27 public abstract class CameraModule implements ModuleController {
     28     /** Provides common services and functionality to the module. */
     29     private final CameraServices mServices;
     30     private final CameraProvider mCameraProvider;
     31 
     32     public CameraModule(AppController app) {
     33         mServices = app.getServices();
     34         mCameraProvider = app.getCameraProvider();
     35     }
     36 
     37     @Override
     38     public boolean onBackPressed() {
     39         return false;
     40     }
     41 
     42     @Override
     43     public void onPreviewVisibilityChanged(int visibility) {
     44         // Do nothing.
     45     }
     46 
     47     @Deprecated
     48     public abstract boolean onKeyDown(int keyCode, KeyEvent event);
     49 
     50     @Deprecated
     51     public abstract boolean onKeyUp(int keyCode, KeyEvent event);
     52 
     53     @Deprecated
     54     public abstract void onSingleTapUp(View view, int x, int y);
     55 
     56     /**
     57      * @return An instance containing common services to be used by the module.
     58      */
     59     protected CameraServices getServices() {
     60         return mServices;
     61     }
     62 
     63     /**
     64      * @return An instance used by the module to get the camera.
     65      */
     66     protected CameraProvider getCameraProvider() {
     67         return mCameraProvider;
     68     }
     69 
     70     /**
     71      * Requests the back camera through {@link CameraProvider}.
     72      * This calls {@link
     73      * com.android.camera.app.CameraProvider#requestCamera(int)}. The camera
     74      * will be returned through {@link
     75      * #onCameraAvailable(com.android.ex.camera2.portability.CameraAgent.CameraProxy)}
     76      * when it's available. This is a no-op when there's no back camera
     77      * available.
     78      */
     79     protected void requestBackCamera() {
     80         int backCameraId = mCameraProvider.getFirstBackCameraId();
     81         if (backCameraId != -1) {
     82             mCameraProvider.requestCamera(backCameraId);
     83         }
     84     }
     85 
     86     public void onPreviewInitialDataReceived() {}
     87 
     88     /**
     89      * Releases the back camera through {@link CameraProvider}.
     90      * This calls {@link
     91      * com.android.camera.app.CameraProvider#releaseCamera(int)}.
     92      * This is a no-op when there's no back camera available.
     93      */
     94     protected void releaseBackCamera() {
     95         int backCameraId = mCameraProvider.getFirstBackCameraId();
     96         if (backCameraId != -1) {
     97             mCameraProvider.releaseCamera(backCameraId);
     98         }
     99     }
    100 
    101     /**
    102      * @return An accessibility String to be announced during the peek animation.
    103      */
    104     public abstract String getPeekAccessibilityString();
    105 }
    106