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