private void start(final boolean isCamera) {
Log.d("ImageTakin", "StartCommand()");
pref = getApplicationContext().getSharedPreferences("MyPref", 0);
editor = pref.edit();
if (mCamera != null) {
queue.removeCallbacks(null);
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mCamera.release();
mCamera = Camera.open();
} else
mCamera = getCameraInstance();
parameters = mCamera.getParameters();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && parameters.getSupportedFocusModes().contains(
Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
} else if (parameters.getSupportedFocusModes().contains(
Camera.Parameters.FOCUS_MODE_AUTO)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
}
mCamera.setParameters(parameters);
size = parameters.getPreviewSize();
if (registeredShieldsIDs.contains(UIShield.COLOR_DETECTION_SHIELD.name()))
mCamera.setPreviewCallback(previewCallback);
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PRIORITY_PHONE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.RGBX_8888);
params.gravity = Gravity.TOP | Gravity.LEFT;
DisplayMetrics metrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(metrics);
int expectedHeight = metrics.heightPixels - ((int) (250 * metrics.density + .5f));
int expectedWidth = ((expectedHeight * (size == null ? metrics.widthPixels : size.height)) / (size == null ? metrics.heightPixels : size.width));
params.width = 1;// metrics.widthPixels - ((int) (60 * metrics.density + .5f));
params.height = 1;
params.x = (int) ((metrics.widthPixels / 2) - expectedWidth / 2);
params.y = (int) (150 * metrics.density + .5f);
params.alpha = 1;
sv = new SurfaceView(getApplicationContext());
windowManager.addView(sv, params);
params = (WindowManager.LayoutParams) sv.getLayoutParams();
sHolder = sv.getHolder();
sHolder.addCallback(this);
mOrientationEventListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
if (orientation == ORIENTATION_UNKNOWN) return;
mOrientation = (orientation + 45) / 90 * 90;
}
};
if (mOrientationEventListener.canDetectOrientation()) {
mOrientationEventListener.enable();
}
// tells Android that this surface will have its data constantly
// replaced
if (Build.VERSION.SDK_INT < 11)
sHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}