當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。