当前位置: 首页>>代码示例>>Java>>正文


Java AutoFocusCallback类代码示例

本文整理汇总了Java中android.hardware.Camera.AutoFocusCallback的典型用法代码示例。如果您正苦于以下问题:Java AutoFocusCallback类的具体用法?Java AutoFocusCallback怎么用?Java AutoFocusCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AutoFocusCallback类属于android.hardware.Camera包,在下文中一共展示了AutoFocusCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: surfaceChanged

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
@Override
public void surfaceChanged(final SurfaceHolder holder, int format, int width, int height) {
    if (mycamera != null) {
        mycamera.autoFocus(new AutoFocusCallback() {
            @Override
            public void onAutoFocus(boolean success, Camera camera) {
                if (success) {
                    synchronized (camera) {
                        new Thread() {
                            public void run() {
                                initCamera(holder);
                                super.run();
                            }
                        }.start();
                    }
                }
            }
        });
    }
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:21,代码来源:OrcVinActivity.java

示例2: autoFocus

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
/**
 * 自动对焦
 *
 * @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;
}
 
开发者ID:Zhaoss,项目名称:WeiXinRecordedDemo,代码行数:31,代码来源:MediaRecorderBase.java

示例3: CameraPreview

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
public CameraPreview(Context context, Camera camera,
                     PreviewCallback previewCb,
                     AutoFocusCallback autoFocusCb) {
    super(context);
    this.context=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);
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:33,代码来源:CameraPreview.java

示例4: setPreviewForPicture

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
/**
 * 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?
                }
            });
        }
    });
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:19,代码来源:CameraActivity_OldAPI.java

示例5: resetCam

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:22,代码来源:CameraActivity_OldAPI.java

示例6: manualFocus

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
/**
 * 手动对焦
 *
 * @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;
}
 
开发者ID:NullUsera,项目名称:meipai-Android,代码行数:37,代码来源:MediaRecorderBase.java

示例7: takeAction

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
public void takeAction(final int nAction) {
if (CameraPreview.msnFocusMode != 0)	{	// if not support autofocus
	mcameraPreview.mbTakeSnapshot = true;
	mcameraPreview.mnActionAfterTakingSnapshot = nAction;
	Toast.makeText(ActivityQuickRecog.this, ActivityQuickRecog.this.getString(R.string.camera_preview_clicked), Toast.LENGTH_SHORT).show();
      } else if (mCamera != null) {
      	//mCamera.cancelAutoFocus();	// cancel existing auto focus. comment this line because cancel autofcus may hang
      	try {
    	mCamera.autoFocus(new AutoFocusCallback() {
            @Override
            public void onAutoFocus(boolean success, Camera camera) {
            	mcameraPreview.mbTakeSnapshot = true;
    			mcameraPreview.mnActionAfterTakingSnapshot = nAction;
                Toast.makeText(ActivityQuickRecog.this, ActivityQuickRecog.this.getString(R.string.camera_preview_clicked_and_autofocused),
                        Toast.LENGTH_SHORT).show();
            }
        }); 
      	} catch(Exception e) {
              Toast.makeText(ActivityQuickRecog.this, ActivityQuickRecog.this.getString(R.string.camera_preview_fail_to_autofocus),
                      Toast.LENGTH_SHORT).show();
      	}
      }
  }
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:24,代码来源:ActivityQuickRecog.java

示例8: onTouch

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
@Override
public boolean onTouch(View v, MotionEvent event) {
	if (mMediaRecorder == null || !mCreated) {
		return false;
	}

	switch (event.getAction()) {
	case MotionEvent.ACTION_DOWN:
		//检测是否手动对焦
		showFocusImage(event);
		if (!mMediaRecorder.onTouch(event, new AutoFocusCallback() {
			@Override
			public void onAutoFocus(boolean success, Camera camera) {
				mFocusImage.setVisibility(View.GONE);

			}
		})) {
			return true;
		} else {
			mFocusImage.setVisibility(View.GONE);
		}
		mMediaRecorder.setAutoFocus();
		break;
	}
	return true;
}
 
开发者ID:jianlei,项目名称:videorecord,代码行数:27,代码来源:MediaRecorderActivity.java

示例9: CameraPreview

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
@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.
         */
        //API9以上实现连续对焦
        
//        Camera.Parameters parameters = camera.getParameters();
//        for (String f : parameters.getSupportedFocusModes()) {
//            if (f == Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) {
//            	parameters.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);
    }
 
开发者ID:Becavalier,项目名称:QRDataTransfer-Android,代码行数:34,代码来源:CameraPreview.java

示例10: initSurfView

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
private void initSurfView() {
	surfaceView = (SurfaceView) findViewById(R.id.surface_view);
	mSurfaceHolder = surfaceView.getHolder();
	mSurfaceHolder.addCallback(this);
	mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
	mAutoFocusCallback = new AutoFocusCallback() {

		@Override
		public void onAutoFocus(boolean success, Camera camera) {
			if (success) {
				Log.i(TAG, "�Խ��ɹ�");
			} else {

			}
		}
	};
}
 
开发者ID:648578244,项目名称:Logistics,代码行数:18,代码来源:CameraActivity.java

示例11: takePicture

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
public void takePicture() {
	mCamera.setPreviewCallback(null);
	mCamera.autoFocus(new AutoFocusCallback() {
		@Override
		public void onAutoFocus(boolean success, Camera camera) {
			if(success)
			{                           
				Log.d(TAG, "Focusing...successful.");
				camera.takePicture(null, null, null, mCall);
			}
			else
			{
				Log.d(TAG, "Focusing...failed.");
				camera.takePicture(null, null, null, mCall);
			}

		}
	});
}
 
开发者ID:F4b1-,项目名称:Pixtern-Library,代码行数:20,代码来源:FdActivity.java

示例12: BarcodePreview

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
public BarcodePreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) {
    super(context);
    mCamera = camera;
    previewCallback = previewCb;
    autoFocusCallback = autoFocusCb;

    Camera.Parameters parameters = camera.getParameters();
    for (String f : parameters.getSupportedFocusModes()) {
        if (f == Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) {
            parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
            autoFocusCallback = null;
            break;
        }
    }

    mHolder = getHolder();
    mHolder.addCallback(this);
}
 
开发者ID:dimasdanz,项目名称:KendaliPintuAndroid,代码行数:19,代码来源:BarcodePreview.java

示例13: XCameraPreview

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
public XCameraPreview(Context context, Camera camera,
                     PreviewCallback previewCb,
                     AutoFocusCallback autoFocusCb) {
    super(context);
    mCamera = camera;
    mPreviewCallback = previewCb;
    mAutoFocusCallback = autoFocusCb;

    // 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);
}
 
开发者ID:polyvi,项目名称:openxface-android,代码行数:17,代码来源:XCameraPreview.java

示例14: onFocus

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
/**
 * 手动聚焦
 *  @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);
}
 
开发者ID:Alex-Jerry,项目名称:LLApp,代码行数:33,代码来源:CameraView.java

示例15: CameraPreview

import android.hardware.Camera.AutoFocusCallback; //导入依赖的package包/类
@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);
  }
 
开发者ID:zybieku,项目名称:ZbarCode,代码行数:31,代码来源:CameraPreview.java


注:本文中的android.hardware.Camera.AutoFocusCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。