/*
* Copyright (C) 2012 CyberAgent
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.yokmama.learn10.chapter10.lesson42.utils;
import android.annotation.TargetApi;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
@TargetApi(9)
public class CameraHelperGB implements CameraHelper.CameraHelperImpl {
@Override
public int getNumberOfCameras() {
return Camera.getNumberOfCameras();
}
@Override
public Camera openCamera(final int id) {
return Camera.open(id);
}
@Override
public Camera openDefaultCamera() {
return Camera.open(0);
}
@Override
public boolean hasCamera(final int facing) {
return getCameraId(facing) != -1;
}
@Override
public Camera openCameraFacing(final int facing) {
return Camera.open(getCameraId(facing));
}
@Override
public void getCameraInfo(final int cameraId, final CameraHelper.CameraInfo2 cameraInfo) {
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(cameraId, info);
cameraInfo.facing = info.facing;
cameraInfo.orientation = info.orientation;
}
private int getCameraId(final int facing) {
int numberOfCameras = Camera.getNumberOfCameras();
CameraInfo info = new CameraInfo();
for (int id = 0; id < numberOfCameras; id++) {
Camera.getCameraInfo(id, info);
if (info.facing == facing) {
return id;
}
}
return -1;
}
}