FileDocCategorySizeDatePackage
CameraAgentFactory.javaAPI DocAndroid 5.1 API6460Thu Mar 12 22:22:48 GMT 2015com.android.ex.camera2.portability

CameraAgentFactory

public class CameraAgentFactory extends Object
A factory class for {@link CameraAgent}.

The choice of framework API to use can be made automatically based on the system API level, explicitly forced by the client app, or overridden entirely by setting the system property com.camera2.portability.fwk_api to 1 or 2.

Fields Summary
private static final Log.Tag
TAG
private static final int
FIRST_SDK_WITH_API_2
Android release replacing the Camera class with the camera2 package.
private static final String
API_LEVEL_OVERRIDE_KEY
private static final String
API_LEVEL_OVERRIDE_DEFAULT
private static final String
API_LEVEL_OVERRIDE_API1
private static final String
API_LEVEL_OVERRIDE_API2
private static final String
API_LEVEL_OVERRIDE_VALUE
private static CameraAgent
sAndroidCameraAgent
private static CameraAgent
sAndroidCamera2Agent
private static int
sAndroidCameraAgentClientCount
private static int
sAndroidCamera2AgentClientCount
Constructors Summary
Methods Summary
public static synchronized CameraAgentgetAndroidCameraAgent(android.content.Context context, com.android.ex.camera2.portability.CameraAgentFactory$CameraApi api)
Returns the android camera implementation of {@link com.android.camera.cameradevice.CameraAgent}.

To clean up the resources allocated by this call, be sure to invoke {@link #recycle(boolean)} with the same {@code api} value provided here.

param
context The application context.
param
api Which camera framework to use.
return
The {@link CameraAgent} to control the camera device.
throws
UnsupportedOperationException If {@code CameraApi.API_2} was requested on an unsupported device.

        api = validateApiChoice(api);

        if (api == CameraApi.API_1) {
            if (sAndroidCameraAgent == null) {
                sAndroidCameraAgent = new AndroidCameraAgentImpl();
                sAndroidCameraAgentClientCount = 1;
            } else {
                ++sAndroidCameraAgentClientCount;
            }
            return sAndroidCameraAgent;
        } else { // API_2
            if (highestSupportedApi() == CameraApi.API_1) {
                throw new UnsupportedOperationException("Camera API_2 unavailable on this device");
            }

            if (sAndroidCamera2Agent == null) {
                sAndroidCamera2Agent = new AndroidCamera2AgentImpl(context);
                sAndroidCamera2AgentClientCount = 1;
            } else {
                ++sAndroidCamera2AgentClientCount;
            }
            return sAndroidCamera2Agent;
        }
    
private static com.android.ex.camera2.portability.CameraAgentFactory$CameraApihighestSupportedApi()
Use the {@link android.hardware.camera2} package.


                  
        
                 
        

              
        

              
        
    

        
        // TODO: Check SDK_INT instead of RELEASE before L launch
        if (Build.VERSION.SDK_INT >= FIRST_SDK_WITH_API_2 || Build.VERSION.CODENAME.equals("L")) {
            return CameraApi.API_2;
        } else {
            return CameraApi.API_1;
        }
    
public static synchronized voidrecycle(com.android.ex.camera2.portability.CameraAgentFactory$CameraApi api)
Recycles the resources. Always call this method when the activity is stopped.

param
api Which camera framework handle to recycle.
throws
UnsupportedOperationException If {@code CameraApi.API_2} was requested on an unsupported device.

        api = validateApiChoice(api);

        if (api == CameraApi.API_1) {
            if (--sAndroidCameraAgentClientCount == 0 && sAndroidCameraAgent != null) {
                sAndroidCameraAgent.recycle();
                sAndroidCameraAgent = null;
            }
        } else { // API_2
            if (highestSupportedApi() == CameraApi.API_1) {
                throw new UnsupportedOperationException("Camera API_2 unavailable on this device");
            }

            if (--sAndroidCamera2AgentClientCount == 0 && sAndroidCamera2Agent != null) {
                sAndroidCamera2Agent.recycle();
                sAndroidCamera2Agent = null;
            }
        }
    
private static com.android.ex.camera2.portability.CameraAgentFactory$CameraApivalidateApiChoice(com.android.ex.camera2.portability.CameraAgentFactory$CameraApi choice)

        if (API_LEVEL_OVERRIDE_VALUE.equals(API_LEVEL_OVERRIDE_API1)) {
            Log.d(TAG, "API level overridden by system property: forced to 1");
            return CameraApi.API_1;
        } else if (API_LEVEL_OVERRIDE_VALUE.equals(API_LEVEL_OVERRIDE_API2)) {
            Log.d(TAG, "API level overridden by system property: forced to 2");
            return CameraApi.API_2;
        }

        if (choice == null) {
            Log.w(TAG, "null API level request, so assuming AUTO");
            choice = CameraApi.AUTO;
        }
        if (choice == CameraApi.AUTO) {
            choice = highestSupportedApi();
        }

        return choice;