Fields Summary |
---|
private static final Log.Tag | TAG |
private static final int | FIRST_SDK_WITH_API_2Android 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 |
Methods Summary |
---|
public static synchronized CameraAgent | getAndroidCameraAgent(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.
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$CameraApi | highestSupportedApi()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 void | recycle(com.android.ex.camera2.portability.CameraAgentFactory$CameraApi api)Recycles the resources. Always call this method when the activity is
stopped.
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$CameraApi | validateApiChoice(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;
|