CameraAgentFactory.java revision d61058f788eae0805bb20c4f68874f0f6caef423
1/* 2 * Copyright (C) 2013 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.ex.camera2.portability; 18 19/** 20 * A factory class for {@link CameraAgent}. 21 */ 22public class CameraAgentFactory { 23 24 private static AndroidCameraAgentImpl sAndroidCameraAgent; 25 private static int sAndroidCameraAgentClientCount; 26 27 /** 28 * Returns the android camera implementation of {@link com.android.camera.cameradevice.CameraAgent}. 29 * 30 * @return The {@link CameraAgent} to control the camera device. 31 */ 32 public static synchronized CameraAgent getAndroidCameraAgent() { 33 if (sAndroidCameraAgent == null) { 34 sAndroidCameraAgent = new AndroidCameraAgentImpl(); 35 sAndroidCameraAgentClientCount = 1; 36 } else { 37 ++sAndroidCameraAgentClientCount; 38 } 39 return sAndroidCameraAgent; 40 } 41 42 /** 43 * Recycles the resources. Always call this method when the activity is 44 * stopped. 45 */ 46 public static synchronized void recycle() { 47 if (--sAndroidCameraAgentClientCount == 0 && sAndroidCameraAgent != null) { 48 sAndroidCameraAgent.recycle(); 49 sAndroidCameraAgent = null; 50 } 51 } 52} 53