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