android.hardware.Camera.AutoFocusCallback Java Examples
The following examples show how to use
android.hardware.Camera.AutoFocusCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CameraActivity_OldAPI.java From microbit with Apache License 2.0 | 6 votes |
/** * Setups preview button to take a picture state. */ private void setPreviewForPicture() { mPreview.setSoundEffectsEnabled(false); mPreview.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mCamera.autoFocus(new AutoFocusCallback() { @Override public void onAutoFocus(boolean arg0, Camera arg1) { //TODO Is there anything we have to do after autofocus? } }); } }); }
Example #2
Source File: CameraActivity_OldAPI.java From microbit with Apache License 2.0 | 6 votes |
/** * Resets camera parameters and starts camera preview. */ private void resetCam() { try { Camera.Parameters parameters = mCamera.getParameters(); logi("Set Flash mode ON"); parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); mCamera.setParameters(parameters); mCamera.startPreview(); mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { //TODO: add implementation or leave a comment if it's nothing to do here } }); parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); mCamera.setParameters(parameters); } catch(RuntimeException e) { Log.e(TAG, e.toString()); } }
Example #3
Source File: MediaRecorderBase.java From VideoRecord with MIT License | 6 votes |
/** * 自动对焦 * * @param cb * @return */ public boolean autoFocus(AutoFocusCallback cb) { if (camera != null) { try { camera.cancelAutoFocus(); if (mParameters != null) { String mode = getAutoFocusMode(); if (StringUtils.isNotEmpty(mode)) { mParameters.setFocusMode(mode); camera.setParameters(mParameters); } } camera.autoFocus(cb); return true; } catch (Exception e) { if (mOnErrorListener != null) { mOnErrorListener.onVideoError(MEDIA_ERROR_CAMERA_AUTO_FOCUS, 0); } if (e != null) Log.e("Yixia", "autoFocus", e); } } return false; }
Example #4
Source File: CameraPreview.java From imsdk-android with MIT License | 5 votes |
@SuppressWarnings("deprecation") public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use software * auto-focus. Only works for API level >=9. */ /* * Camera.Parameters parameters = camera.getParameters(); for (String f * : parameters.getSupportedFocusModes()) { if (f == * Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { * mCamera.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); * autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
Example #5
Source File: CameraPreview.java From ScanZbar with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use software * auto-focus. Only works for API level >=9. */ Camera.Parameters parameters = camera.getParameters(); for (String f: parameters.getSupportedFocusModes()) { if (f == Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
Example #6
Source File: AndroidCameraAgentImpl.java From Camera2 with Apache License 2.0 | 5 votes |
@Override public void autoFocus(final Handler handler, final CameraAFCallback cb) { final AutoFocusCallback afCallback = new AutoFocusCallback() { @Override public void onAutoFocus(final boolean b, Camera camera) { if (mCameraState.getState() != AndroidCameraStateHolder.CAMERA_FOCUSING) { Log.w(TAG, "onAutoFocus callback returning when not focusing"); } else { mCameraState.setState(AndroidCameraStateHolder.CAMERA_IDLE); } handler.post(new Runnable() { @Override public void run() { cb.onAutoFocus(b, AndroidCameraProxyImpl.this); } }); } }; mDispatchThread.runJob(new Runnable() { @Override public void run() { // Don't bother to wait since camera is in bad state. if (getCameraState().isInvalid()) { return; } mCameraState.waitForStates(AndroidCameraStateHolder.CAMERA_IDLE); mCameraHandler.obtainMessage(CameraActions.AUTO_FOCUS, afCallback) .sendToTarget(); } }); }
Example #7
Source File: MediaRecorderBase.java From VideoRecord with MIT License | 5 votes |
/** * 手动对焦 * * @param focusAreas 对焦区域 * @return */ @SuppressLint("NewApi") @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public boolean manualFocus(AutoFocusCallback cb, List<Area> focusAreas) { if (camera != null && focusAreas != null && mParameters != null && DeviceUtils.hasICS()) { try { camera.cancelAutoFocus(); // getMaxNumFocusAreas检测设备是否支持 if (mParameters.getMaxNumFocusAreas() > 0) { // mParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);// // Macro(close-up) focus mode mParameters.setFocusAreas(focusAreas); } if (mParameters.getMaxNumMeteringAreas() > 0) mParameters.setMeteringAreas(focusAreas); mParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO); camera.setParameters(mParameters); camera.autoFocus(cb); return true; } catch (Exception e) { if (mOnErrorListener != null) { mOnErrorListener.onVideoError(MEDIA_ERROR_CAMERA_AUTO_FOCUS, 0); } if (e != null) Log.e("Yixia", "autoFocus", e); } } return false; }
Example #8
Source File: CameraView.java From LLApp with Apache License 2.0 | 5 votes |
/** * 手动聚焦 * @param point 触屏坐标 */ protected void onFocus(Point point,AutoFocusCallback callback){ Parameters parameters=mCamera.getParameters(); //不支持设置自定义聚焦,则使用自动聚焦,返回 if (parameters.getMaxNumFocusAreas()<=0) { mCamera.autoFocus(callback); return; } List<Area> areas=new ArrayList<Area>(); int left=point.x-300; int top=point.y-300; int right=point.x+300; int bottom=point.y+300; left=left<-1000?-1000:left; top=top<-1000?-1000:top; right=right>1000?1000:right; bottom=bottom>1000?1000:bottom; areas.add(new Area(new Rect(left,top,right,bottom), 100)); parameters.setFocusAreas(areas); try { //本人使用的小米手机在设置聚焦区域的时候经常会出异常,看日志发现是框架层的字符串转int的时候出错了, //目测是小米修改了框架层代码导致,在此try掉,对实际聚焦效果没影响 mCamera.setParameters(parameters); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } mCamera.autoFocus(callback); }
Example #9
Source File: CameraPreview.java From ZbarCode with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use software * auto-focus. Only works for API level >=9. */ Camera.Parameters parameters = camera.getParameters(); for (String f: parameters.getSupportedFocusModes()) { if (f == Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
Example #10
Source File: MainActivity.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if(checkCameraHardware(this)){ // ��ȡ����ͷʵ�� mCamera = getCameraInstance(); // ����Ԥ������Ķ��� mPreview = new CameraPreview(this, mCamera); FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); //��Ԥ���������Ϊ֡���ֵ��ӽڵ� preview.addView(mPreview); //��ȡ���հ�ť Button captureButton = (Button) findViewById(R.id.button_capture); //���õ������ captureButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { //�Զ��Խ� mCamera.autoFocus(new AutoFocusCallback(){ //�Խ����ʱ���� @Override public void onAutoFocus(boolean success, Camera camera) { //���� mCamera.takePicture(null, null, mPicture); } }); } } ); } }
Example #11
Source File: CameraPreview.java From ZBarScanProj with MIT License | 5 votes |
@SuppressWarnings("deprecation") public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use software * auto-focus. Only works for API level >=9. */ /* * Camera.Parameters parameters = camera.getParameters(); for (String f * : parameters.getSupportedFocusModes()) { if (f == * Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { * mCamera.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); * autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }