コード例 #1
0
 public void flipCamera(View view) {
   stopCamera();
   camera.flip();
   viewfinder.invalidate();
   startCamera();
   updateMenu();
 }
コード例 #2
0
  protected void updateMenu() {
    Button flipCameraButton = (Button) findViewById(R.id.flipCameraButton);
    if (camera.getCameraCount() > 1) {
      flipCameraButton.setVisibility(View.VISIBLE);
      if (camera.isFront()) {
        flipCameraButton.setCompoundDrawablesWithIntrinsicBounds(
            R.drawable.ic_camera_front_white_24dp, 0, 0, 0);
        flipCameraButton.setText(getString(R.string.camera_front));
      } else {
        flipCameraButton.setCompoundDrawablesWithIntrinsicBounds(
            R.drawable.ic_camera_rear_white_24dp, 0, 0, 0);
        flipCameraButton.setText(getString(R.string.camera_rear));
      }
    } else {
      flipCameraButton.setVisibility(View.GONE);
    }

    Button thresholdDisplayButton = (Button) findViewById(R.id.thresholdDisplayButton);
    if (detector.shouldDrawThreshold()) {
      thresholdDisplayButton.setText(getString(R.string.threshold_on));
      thresholdDisplayButton.setCompoundDrawablesWithIntrinsicBounds(
          R.drawable.ic_filter_b_and_w_white_24dp, 0, 0, 0);
    } else {
      thresholdDisplayButton.setText(getString(R.string.threshold_off));
      thresholdDisplayButton.setCompoundDrawablesWithIntrinsicBounds(
          R.drawable.ic_filter_b_and_w_off_white_24dp, 0, 0, 0);
    }

    Button markerDisplayButton = (Button) findViewById(R.id.markerDisplayButton);
    if (detector.getMarkerDrawMode() == MarkerDetector.MarkerDrawMode.off) {
      markerDisplayButton.setCompoundDrawablesWithIntrinsicBounds(
          R.drawable.ic_border_clear_white_24dp, 0, 0, 0);
      markerDisplayButton.setText(getString(R.string.marker_off));
    } else if (detector.getMarkerDrawMode() == MarkerDetector.MarkerDrawMode.outline) {
      markerDisplayButton.setCompoundDrawablesWithIntrinsicBounds(
          R.drawable.ic_border_outer_white_24dp, 0, 0, 0);
      markerDisplayButton.setText(getString(R.string.marker_outline));
    } else {
      markerDisplayButton.setCompoundDrawablesWithIntrinsicBounds(
          R.drawable.ic_border_all_white_24dp, 0, 0, 0);
      markerDisplayButton.setText(getString(R.string.marker_on));
    }

    // private ImageView autoOpenIcon;
    // private TextView autoOpenLabel;
  }
コード例 #3
0
 private void startCamera() {
   if (camera != null) {
     try {
       camera.start(holder);
       detector.start();
       layout();
     } catch (Exception e) {
       Log.e(TAG, e.getMessage(), e);
     }
   }
 }
コード例 #4
0
  private void layout() {
    Rect frame = camera.getFrame(viewfinder.getWidth(), viewfinder.getHeight());
    if (frame == null) {
      return;
    }

    Log.i(TAG, "Frame = " + frame + ", " + viewfinder.getWidth());
    ViewGroup.LayoutParams p = bottomView.getLayoutParams();
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview);
    p.height = surfaceView.getHeight() - frame.bottom;
    p.width = frame.width();
    bottomView.setLayoutParams(p);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && hasNavBar(this)) {
      // Don't draw over nav bar
      bottomView.setPadding(0, 0, 0, getNavBarHeight());
    }

    bottomView.requestLayout();
    viewfinder.invalidate();
  }
コード例 #5
0
 private void stopCamera() {
   if (camera != null) {
     detector.stop();
     camera.release();
   }
 }