类com.google.zxing.camera.CameraManager源码实例Demo

下面列出了怎么用com.google.zxing.camera.CameraManager的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: QrCodeLib   文件: CaptureActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scanner);
    CameraManager.init(getApplication());
    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_content);
    back = (ImageButton) findViewById(R.id.btn_back);
    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    btnFlash = (ImageButton) findViewById(R.id.btn_flash);
    btnFlash.setOnClickListener(flashListener);

    btnAlbum = (Button) findViewById(R.id.btn_album);
    btnAlbum.setOnClickListener(albumOnClick);

    hasSurface = false;
    inactivityTimer = new InactivityTimer(this);

}
 
源代码2 项目: QrCodeLib   文件: CaptureActivity.java
@Override
public void onClick(View view) {
    try {
        boolean isSuccess = CameraManager.get().setFlashLight(!isFlashOn);
        if (!isSuccess) {
            Toast.makeText(CaptureActivity.this, R.string.note_no_flashlight, Toast.LENGTH_SHORT).show();
            return;
        }
        if (isFlashOn) {
            // 关闭闪光灯
            btnFlash.setImageResource(R.drawable.flash_off);
            isFlashOn = false;
        } else {
            // 开启闪光灯
            btnFlash.setImageResource(R.drawable.flash_on);
            isFlashOn = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
源代码3 项目: vmqApk   文件: CaptureActivity.java
@Override
public void onClick(View view) {
    try {
        boolean isSuccess = CameraManager.get().setFlashLight(!isFlashOn);
        if(!isSuccess){
            Toast.makeText(CaptureActivity.this, "暂时无法开启闪光灯", Toast.LENGTH_SHORT).show();
            return;
        }
        if (isFlashOn) {
            // 关闭闪光灯
            btnFlash.setImageResource(R.drawable.flash_off);
            isFlashOn = false;
        } else {
            // 开启闪光灯
            btnFlash.setImageResource(R.drawable.flash_on);
            isFlashOn = true;
        }
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
源代码4 项目: QrCodeDemo4   文件: CaptureActivity.java
@Override
public void onClick(View view) {
    try {
        boolean isSuccess = CameraManager.get().setFlashLight(!isFlashOn);
        if(!isSuccess){
            Toast.makeText(CaptureActivity.this, "暂时无法开启闪光灯", Toast.LENGTH_SHORT).show();
            return;
        }
        if (isFlashOn) {
            // 关闭闪光灯
            btnFlash.setImageResource(R.drawable.flash_off);
            isFlashOn = false;
        } else {
            // 开启闪光灯
            btnFlash.setImageResource(R.drawable.flash_on);
            isFlashOn = true;
        }
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
源代码5 项目: CodeScaner   文件: CaptureActivityHandler.java
CaptureActivityHandler(CaptureActivity activity,
                       Collection<BarcodeFormat> decodeFormats,
                       Map<DecodeHintType,?> baseHints,
                       String characterSet,
                       CameraManager cameraManager) {
  this.activity = activity;
  decodeThread = new DecodeThread(activity, decodeFormats, baseHints, characterSet,
          new ViewfinderResultPointCallback(activity.getViewfinderView()));
  decodeThread.start();
  state = State.SUCCESS;

  // Start ourselves capturing previews and decoding.
  this.cameraManager = cameraManager;
  cameraManager.startPreview();
  restartPreviewAndDecode();
}
 
public CaptureActivityHandler(QrCodeScanActivity activity,
                              Collection<BarcodeFormat> decodeFormats,
                              Map<DecodeHintType, ?> baseHints,
                              String characterSet,
                              CameraManager cameraManager) {
    this.activity = activity;
    decodeThread = new DecodeThread(activity, decodeFormats, baseHints, characterSet,
            new ViewfinderResultPointCallback(activity.getViewfinderView()));
    decodeThread.start();
    state = State.SUCCESS;

    // Start ourselves capturing previews and decoding.
    this.cameraManager = cameraManager;
    cameraManager.startPreview();
    restartPreviewAndDecode();
}
 
源代码7 项目: QrCodeLib   文件: CaptureActivity.java
@Override
protected void onPause() {
    super.onPause();
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    CameraManager.get().closeDriver();
}
 
源代码8 项目: QrCodeLib   文件: CaptureActivityHandler.java
public CaptureActivityHandler(CaptureActivity activity, Vector<BarcodeFormat> decodeFormats,
                              String characterSet) {
    this.activity = activity;
    decodeThread = new DecodeThread(activity, decodeFormats, characterSet,
            new ViewfinderResultPointCallback(activity.getViewfinderView()));
    decodeThread.start();
    state = State.SUCCESS;
    // Start ourselves capturing previews and decoding.
    CameraManager.get().startPreview();
    restartPreviewAndDecode();
}
 
源代码9 项目: QrCodeLib   文件: CaptureActivityHandler.java
@Override
public void handleMessage(Message message) {
    int id = message.what;
    if (id == R.id.auto_focus) {
        //Log.d(TAG, "Got auto-focus message");
        // When one auto focus pass finishes, start another. This is the closest thing to
        // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do.
        if (state == State.PREVIEW) {
            CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
        }
    } else if (id == R.id.restart_preview) {
        Log.d(TAG, "Got restart preview message");
        restartPreviewAndDecode();
    } else if (id == R.id.decode_succeeded) {
        Log.d(TAG, "Got decode succeeded message");
        state = State.SUCCESS;
        Bundle bundle = message.getData();

        /***********************************************************************/
        Bitmap barcode = bundle == null ? null :
                (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳�

        activity.handleDecode((Result) message.obj, barcode);//���ؽ��
        /***********************************************************************/
    } else if (id == R.id.decode_failed) {
        // We're decoding as fast as possible, so when one decode fails, start another.
        state = State.PREVIEW;
        CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
    } else if (id == R.id.return_scan_result) {
        Log.d(TAG, "Got return scan result message");
        activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
        activity.finish();
    } else if (id == R.id.launch_product_query) {
        Log.d(TAG, "Got product query message");
        String url = (String) message.obj;
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        activity.startActivity(intent);
    }
}
 
源代码10 项目: QrCodeLib   文件: CaptureActivityHandler.java
public void quitSynchronously() {
    state = State.DONE;
    CameraManager.get().stopPreview();
    Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
    quit.sendToTarget();
    try {
        decodeThread.join();
    } catch (InterruptedException e) {
        // continue
    }

    // Be absolutely sure we don't send any queued up messages
    removeMessages(R.id.decode_succeeded);
    removeMessages(R.id.decode_failed);
}
 
源代码11 项目: QrCodeLib   文件: CaptureActivityHandler.java
private void restartPreviewAndDecode() {
    if (state == State.SUCCESS) {
        state = State.PREVIEW;
        CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
        CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
        activity.drawViewfinder();
    }
}
 
源代码12 项目: vmqApk   文件: CaptureActivity.java
/**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scanner);
        //ViewUtil.addTopView(getApplicationContext(), this, R.string.scan_card);
        CameraManager.init(getApplication());
        viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_content);
        back = (ImageButton) findViewById(R.id.btn_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        btnFlash = (ImageButton) findViewById(R.id.btn_flash);
        btnFlash.setOnClickListener(flashListener);

        btnAlbum = (Button) findViewById(R.id.btn_album);
        btnAlbum.setOnClickListener(albumOnClick);

//		cancelScanButton = (Button) this.findViewById(R.id.btn_cancel_scan);
        hasSurface = false;
        inactivityTimer = new InactivityTimer(this);

    }
 
源代码13 项目: vmqApk   文件: CaptureActivity.java
@Override
protected void onPause() {
    super.onPause();
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    CameraManager.get().closeDriver();
}
 
源代码14 项目: vmqApk   文件: CaptureActivityHandler.java
public CaptureActivityHandler(CaptureActivity activity, Vector<BarcodeFormat> decodeFormats,
                              String characterSet) {
  this.activity = activity;
  decodeThread = new DecodeThread(activity, decodeFormats, characterSet,
      new ViewfinderResultPointCallback(activity.getViewfinderView()));
  decodeThread.start();
  state = State.SUCCESS;
  // Start ourselves capturing previews and decoding.
  CameraManager.get().startPreview();
  restartPreviewAndDecode();
}
 
源代码15 项目: vmqApk   文件: CaptureActivityHandler.java
public void quitSynchronously() {
  state = State.DONE;
  CameraManager.get().stopPreview();
  Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
  quit.sendToTarget();
  try {
    decodeThread.join();
  } catch (InterruptedException e) {
    // continue
  }

  // Be absolutely sure we don't send any queued up messages
  removeMessages(R.id.decode_succeeded);
  removeMessages(R.id.decode_failed);
}
 
源代码16 项目: vmqApk   文件: CaptureActivityHandler.java
private void restartPreviewAndDecode() {
  if (state == State.SUCCESS) {
    state = State.PREVIEW;
    CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
    CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
    activity.drawViewfinder();
  }
}
 
源代码17 项目: QrCodeDemo4   文件: CaptureActivity.java
/**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scanner);
        //ViewUtil.addTopView(getApplicationContext(), this, R.string.scan_card);
        CameraManager.init(getApplication());
        viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_content);
        back = (ImageButton) findViewById(R.id.btn_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        btnFlash = (ImageButton) findViewById(R.id.btn_flash);
        btnFlash.setOnClickListener(flashListener);

        btnAlbum = (Button) findViewById(R.id.btn_album);
        btnAlbum.setOnClickListener(albumOnClick);

//		cancelScanButton = (Button) this.findViewById(R.id.btn_cancel_scan);
        hasSurface = false;
        inactivityTimer = new InactivityTimer(this);

    }
 
源代码18 项目: QrCodeDemo4   文件: CaptureActivity.java
@Override
protected void onPause() {
    super.onPause();
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    CameraManager.get().closeDriver();
}
 
源代码19 项目: QrCodeDemo4   文件: CaptureActivityHandler.java
public CaptureActivityHandler(CaptureActivity activity, Vector<BarcodeFormat> decodeFormats,
                              String characterSet) {
  this.activity = activity;
  decodeThread = new DecodeThread(activity, decodeFormats, characterSet,
      new ViewfinderResultPointCallback(activity.getViewfinderView()));
  decodeThread.start();
  state = State.SUCCESS;
  // Start ourselves capturing previews and decoding.
  CameraManager.get().startPreview();
  restartPreviewAndDecode();
}
 
源代码20 项目: QrCodeDemo4   文件: CaptureActivityHandler.java
public void quitSynchronously() {
  state = State.DONE;
  CameraManager.get().stopPreview();
  Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
  quit.sendToTarget();
  try {
    decodeThread.join();
  } catch (InterruptedException e) {
    // continue
  }

  // Be absolutely sure we don't send any queued up messages
  removeMessages(R.id.decode_succeeded);
  removeMessages(R.id.decode_failed);
}
 
源代码21 项目: QrCodeDemo4   文件: CaptureActivityHandler.java
private void restartPreviewAndDecode() {
  if (state == State.SUCCESS) {
    state = State.PREVIEW;
    CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
    CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
    activity.drawViewfinder();
  }
}
 
源代码22 项目: CodeScaner   文件: AmbientLightManager.java
void start(CameraManager cameraManager) {
  this.cameraManager = cameraManager;
  SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
  if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    if (lightSensor != null) {
      sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
  }
}
 
源代码23 项目: vmqApk   文件: CaptureActivityHandler.java
@Override
public void handleMessage(Message message) {
  switch (message.what) {
    case R.id.auto_focus:
      //Log.d(TAG, "Got auto-focus message");
      // When one auto focus pass finishes, start another. This is the closest thing to
      // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do.
      if (state == State.PREVIEW) {
        CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
      }
      break;
    case R.id.restart_preview:
      Log.d(TAG, "Got restart preview message");
      restartPreviewAndDecode();
      break;
    case R.id.decode_succeeded:
      Log.d(TAG, "Got decode succeeded message");
      state = State.SUCCESS;
      Bundle bundle = message.getData();
      
      /***********************************************************************/
      Bitmap barcode = bundle == null ? null :
          (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳�
      
      activity.handleDecode((Result) message.obj, barcode);//���ؽ��
      /***********************************************************************/
      break;
    case R.id.decode_failed:
      // We're decoding as fast as possible, so when one decode fails, start another.
      state = State.PREVIEW;
      CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
      break;
    case R.id.return_scan_result:
      Log.d(TAG, "Got return scan result message");
      activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
      activity.finish();
      break;
    case R.id.launch_product_query:
      Log.d(TAG, "Got product query message");
      String url = (String) message.obj;
      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      activity.startActivity(intent);
      break;
  }
}
 
源代码24 项目: QrCodeDemo4   文件: CaptureActivityHandler.java
@Override
public void handleMessage(Message message) {
  switch (message.what) {
    case R.id.auto_focus:
      //Log.d(TAG, "Got auto-focus message");
      // When one auto focus pass finishes, start another. This is the closest thing to
      // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do.
      if (state == State.PREVIEW) {
        CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
      }
      break;
    case R.id.restart_preview:
      Log.d(TAG, "Got restart preview message");
      restartPreviewAndDecode();
      break;
    case R.id.decode_succeeded:
      Log.d(TAG, "Got decode succeeded message");
      state = State.SUCCESS;
      Bundle bundle = message.getData();
      
      /***********************************************************************/
      Bitmap barcode = bundle == null ? null :
          (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳�
      
      activity.handleDecode((Result) message.obj, barcode);//���ؽ��
      /***********************************************************************/
      break;
    case R.id.decode_failed:
      // We're decoding as fast as possible, so when one decode fails, start another.
      state = State.PREVIEW;
      CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
      break;
    case R.id.return_scan_result:
      Log.d(TAG, "Got return scan result message");
      activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
      activity.finish();
      break;
    case R.id.launch_product_query:
      Log.d(TAG, "Got product query message");
      String url = (String) message.obj;
      Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      activity.startActivity(intent);
      break;
  }
}
 
源代码25 项目: CodeScaner   文件: CaptureActivity.java
CameraManager getCameraManager() {
    return cameraManager;
}
 
源代码26 项目: CodeScaner   文件: CaptureActivity.java
@Override
protected void onResume() {
    super.onResume();

    // historyManager must be initialized here to update the history preference

    // CameraManager must be initialized here, not in onCreate(). This is necessary because
    // we don't
    // want to open the camera driver and measure the screen size if we're going to show the
    // help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and
    // partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);

    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
    decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
    decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
    characterSet = null;

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }
}
 
源代码27 项目: CodeScaner   文件: ViewfinderView.java
public void setCameraManager(CameraManager cameraManager) {
    this.cameraManager = cameraManager;
}
 
源代码28 项目: AndroidHttpCapture   文件: ViewfinderView.java
public void setCameraManager(CameraManager cameraManager) {
    this.cameraManager = cameraManager;
}
 
源代码29 项目: AndroidHttpCapture   文件: QrCodeScanActivity.java
public CameraManager getCameraManager() {
    return cameraManager;
}
 
源代码30 项目: AndroidHttpCapture   文件: QrCodeScanActivity.java
@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is
    // necessary because we don't
    // want to open the camera driver and measure the screen size if we're
    // going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());
    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    viewfinderView.setVisibility(View.VISIBLE);

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
    }

    decodeFormats = null;
    characterSet = null;

    playBeep = true;
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        playBeep = false;
    }
    initBeepSound();
    vibrate = true;

    inactivityTimer.onResume();
}
 
 类所在包
 类方法
 同包方法