public int setCameraProperty(String key, String value) {
    if (mCamera == null) {
      return MAAPI_consts.MA_CAMERA_RES_FAILED;
    }
    try {
      Camera.Parameters param = getCurrentParameters();
      if (key.equals(MAAPI_consts.MA_CAMERA_IMAGE_FORMAT)) {
        if (value.equals(MAAPI_consts.MA_CAMERA_IMAGE_RAW)) {
          rawMode = true;
        } else {
          // default mode is jpeg
          rawMode = false;
        }
      } else if (key.equals(MAAPI_consts.MA_CAMERA_FOCUS_MODE)) {
        if (value.equals(MAAPI_consts.MA_CAMERA_FOCUS_AUTO)) {
          if (false == param.getSupportedFocusModes().contains(value)) {

            return MAAPI_consts.MA_CAMERA_RES_VALUE_NOTSUPPORTED;
          }

          mCamera.autoFocus(autoFocusCallback);
        } else if (value.equals(MAAPI_consts.MA_CAMERA_FOCUS_MACRO)) {

          if (false == param.getSupportedFocusModes().contains(value)) {
            return MAAPI_consts.MA_CAMERA_RES_VALUE_NOTSUPPORTED;
          }
          mCamera.autoFocus(autoFocusCallback);
        } else if (false == param.getSupportedFocusModes().contains(value)) {
          mCamera.cancelAutoFocus();
          return MAAPI_consts.MA_CAMERA_RES_VALUE_NOTSUPPORTED;
        } else mCamera.cancelAutoFocus();

        param.setFocusMode(value);
      } else if (key.equals(MAAPI_consts.MA_CAMERA_FLASH_MODE)) {
        if (true == param.getSupportedFlashModes().contains(value)) {
          param.setFlashMode(value);
        } else {
          return MAAPI_consts.MA_CAMERA_RES_VALUE_NOTSUPPORTED;
        }
      } else {
        param.set(key, value);
      }
      mCamera.setParameters(param);
    } catch (Exception e) {
      return MAAPI_consts.MA_CAMERA_RES_FAILED;
    }
    return MAAPI_consts.MA_CAMERA_RES_OK;
  }
 /*
 the camera hardware to perform an autofocus
   */
 public void requestAutoFocus(Handler handler, int message) {
   if (camera != null && previewing) {
     autoFocusHandler = handler;
     autoFocusMessage = message;
     camera.autoFocus(autoFocusCallback);
   }
 }
Exemplo n.º 3
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_camera);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mContext = CameraActivity.this;

    mUsersSQL = "select a.[CORPNO], a.[OPERNO], a.[OPERPASS] from b_opera a;";
    mSearchUsersSQL = "select count(*) from b_opera a where a.[CORPNO] = ? and a.[OPERNO] = ?;";
    mInsertOperaSQL = "INSERT INTO B_OPERA (CORPNO, OPERNO, OPERPASS) VALUES(?, ?, ?, ?, ?);";
    mInsertDownInfoSQL =
        "INSERT INTO B_LOGININFO (CORPNO, PROJDESC, DOWNURL, UPLOADURL, DBFILENAME, DOWNTIME) VALUES(?, ?, ?, ?, ?, ?);";
    mDownLoadInfoSQL =
        "select a.[CORPNO], a.[PROJDESC], a.[DOWNURL], a.[UPLOADURL], a.[DBFILENAME] from b_logininfo a;";
    autoFocusHandler = new Handler();
    mCamera = getCameraInstance();

    /* Instance barcode scanner */
    scanner = new ImageScanner();
    scanner.setConfig(0, Config.X_DENSITY, 3);
    scanner.setConfig(0, Config.Y_DENSITY, 3);

    Log.i(TAG, "CameraActivity onCreate()");
    mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
    FrameLayout preview = (FrameLayout) findViewById(R.id.cameraPreview);
    preview.addView(mPreview);

    mCamera.setPreviewCallback(previewCb);
    mCamera.startPreview();
    previewing = true;
    mCamera.autoFocus(autoFocusCB);

    // 初始化声音和震动
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    // 如果手机是震动模式就震动
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
      playBeep = false;
    }
    // 初始化声音
    initBeepSound();
    initLoginDataBase();
    // MyApp.showToast(CameraActivity.this, "hello");

    Button mButtonBack = (Button) findViewById(R.id.button_back);

    /*返回按钮*/
    mButtonBack.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent intent = new Intent();
            intent.putExtra("downloadfile", "");
            setResult(RESULT_OK, intent);
            finish();
          }
        });
  }
Exemplo n.º 4
0
 /**
  * Asks the camera hardware to perform an autofocus.
  *
  * @param handler The Handler to notify when the autofocus completes.
  * @param message The message to deliver.
  */
 public void requestAutoFocus(Handler handler, int message) {
   if (camera != null && previewing) {
     autoFocusCallback.setHandler(handler, message);
     // Log.d(TAG, "Requesting auto-focus callback");
     camera.autoFocus(autoFocusCallback);
   }
 }
Exemplo n.º 5
0
 // 停止拍照,并将拍摄的照片传入PictureCallback接口的onPictureTaken方法
 public void takePicture() {
   // Log.e(TAG, "==takePicture==");
   if (mCamera != null) {
     // 自动对焦
     mCamera.autoFocus(
         new AutoFocusCallback() {
           @Override
           public void onAutoFocus(boolean success, Camera camera) {
             if (null != listener) {
               try {
                 success = true; // 我这里把他设为true了,其实
                 listener.onAutoFocus(success);
               } catch (Exception e) {
                 // TODO: handle exception
                 e.printStackTrace();
                 success = true;
               }
             }
             // 自动对焦成功后才拍摄
             if (success || cameraPosition == 0) {
               camera.takePicture(null, null, pictureCallback);
             } else {
               // AppToast.showShortText(mContext, "焦距不准,请重拍!");
             }
           }
         });
   }
 }
  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    /*
     * If your preview can change or rotate, take care of those events here.
     * Make sure to stop the preview before resizing or reformatting it.
     */
    if (mHolder.getSurface() == null) {
      // preview surface does not exist
      return;
    }

    // stop preview before making changes
    try {
      mCamera.stopPreview();
    } catch (Exception e) {
      // ignore: tried to stop a non-existent preview
    }

    try {
      // Hard code camera surface rotation 90 degs to match Activity view in portrait
      mCamera.setDisplayOrientation(90);

      mCamera.setPreviewDisplay(mHolder);
      mCamera.setPreviewCallback(previewCallback);
      mCamera.startPreview();
      mCamera.autoFocus(autoFocusCallback);
    } catch (Exception e) {
      Log.d("DBG", "Error starting camera preview: " + e.getMessage());
    }
  }
 private void initCamera() {
   if (!isPreview) {
     camera = Camera.open();
   }
   if (camera != null && !isPreview) {
     streamIt = new StreamIt();
     try {
       Camera.Parameters parameters = camera.getParameters();
       parameters.setPreviewSize(screenWidth, screenHeight); // 设置预览照片的大小	
       parameters.setPreviewFpsRange(20, 30); // 每秒显示20~30帧	
       parameters.setPictureFormat(ImageFormat.NV21); // 设置图片格式	
       parameters.setPictureSize(screenWidth, screenHeight); // 设置照片的大小
       camera.setPreviewDisplay(surfaceHolder); // 通过SurfaceView显示取景画面
       camera.setPreviewCallback(streamIt); // 设置回调的类	
       camera.startPreview(); // 开始预览	
       camera.autoFocus(null); // 自动对焦
     } catch (Exception e) {
       e.printStackTrace();
     }
     isPreview = true;
     Thread postThread2 = new Thread(new postThread());
     postThread2.start();
     System.out.println("线程启动了@@@@@@@@@@@@@@@@@@@@@@@@@@");
   }
 }
Exemplo n.º 8
0
 public void takeCroppedPicture(final CroppedPictureCallback callback) {
   if (!opened) throw new IllegalStateException("Camera not opened yet");
   final Camera.PictureCallback pictureCallback =
       new Camera.PictureCallback() {
         @Override
         public void onPictureTaken(byte[] data, Camera cam) {
           previewing = false;
           int pictureWidth, pictureHeight;
           if (cameraRotation == 90 || cameraRotation == 270) {
             pictureWidth = pictureSize.height;
             pictureHeight = pictureSize.width;
           } else {
             pictureWidth = pictureSize.width;
             pictureHeight = pictureSize.height;
           }
           if (CROP_PREVIEW) { // The preview was cropped
             double scaleFactor, widthOffset, heightOffset;
             if (layoutWidth * pictureHeight > layoutHeight * pictureWidth) {
               scaleFactor = (double) pictureWidth / (double) layoutWidth;
               widthOffset = 0;
               heightOffset = (pictureHeight - layoutHeight * scaleFactor) / 2;
             } else {
               scaleFactor = (double) pictureHeight / (double) layoutHeight;
               widthOffset = (pictureWidth - layoutWidth * scaleFactor) / 2;
               heightOffset = 0;
             }
             callback.onPictureCropped(
                 Image.fromCroppedData(
                     data,
                     cameraRotation,
                     (int) (Edge.LEFT.getCoordinate() * scaleFactor + widthOffset),
                     (int) (Edge.TOP.getCoordinate() * scaleFactor + heightOffset),
                     (int) (Edge.getWidth() * scaleFactor),
                     (int) (Edge.getHeight() * scaleFactor)));
           } else { // The preview was stretched
             final double scaleFactorHorizontal = (double) pictureWidth / (double) layoutWidth;
             final double scaleFactorVertical = (double) pictureHeight / (double) layoutHeight;
             callback.onPictureCropped(
                 Image.fromCroppedData(
                     data,
                     cameraRotation,
                     (int) (Edge.LEFT.getCoordinate() * scaleFactorHorizontal),
                     (int) (Edge.TOP.getCoordinate() * scaleFactorVertical),
                     (int) (Edge.getWidth() * scaleFactorHorizontal),
                     (int) (Edge.getHeight() * scaleFactorVertical)));
           }
         }
       };
   final Camera.AutoFocusCallback autoFocusCallback =
       new Camera.AutoFocusCallback() {
         @Override
         public void onAutoFocus(boolean success, Camera cam) {
           camera.takePicture(null, null, pictureCallback);
         }
       };
   joinPreviewStarter();
   if (autofocus) camera.autoFocus(autoFocusCallback);
   else camera.takePicture(null, null, pictureCallback);
 }
Exemplo n.º 9
0
 public void playFlash(boolean isFlash) {
   this.IsFlash = isFlash;
   if (Deviceinfo.getFlashAvailableOnDevice(activity)) {
     Parameters param = cam.getParameters();
     List<String> supportedFlashModes = param.getSupportedFlashModes();
     PrintLog.print(activity.getApplicationContext(), supportedFlashModes.toString());
     // For Support Mode Torch
     if (supportedFlashModes != null
         && supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) {
       if (isFlash) {
         param.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
       } else {
         param.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
       }
       cam.setParameters(param);
     } else {
       // For unSupport Mode Torch
       if (isFlash) {
         if (devicearraydata[0].equals("GT-S5830")) {
           param.setFlashMode(Parameters.FLASH_MODE_ON);
           cam.setParameters(param);
           cam.autoFocus(
               new Camera.AutoFocusCallback() {
                 public void onAutoFocus(final boolean success, Camera camera) {}
               });
           cam.startPreview();
           param = cam.getParameters();
           param.setFlashMode(Parameters.FLASH_MODE_OFF);
           cam.setParameters(param);
         }
       } else {
         if (devicearraydata[0].equals("GT-S5830")) {
           param.setFlashMode(Parameters.FLASH_MODE_ON);
           cam.setParameters(param);
           cam.autoFocus(
               new Camera.AutoFocusCallback() {
                 public void onAutoFocus(final boolean success, Camera camera) {}
               });
           cam.startPreview();
         }
       }
     }
   } else {
     PrintLog.print(activity.getApplicationContext(), "Not Found Flash On Device.");
   }
 }
Exemplo n.º 10
0
 public void safeAutoFocus() {
   try {
     mCamera.autoFocus(autoFocusCB);
   } catch (RuntimeException re) {
     // Horrible hack to deal with autofocus errors on Sony devices
     // See https://github.com/dm77/barcodescanner/issues/7 for example
     scheduleAutoFocus(); // wait 1 sec and then do check again
   }
 }
Exemplo n.º 11
0
 private void autoFocus() {
   // Initiate autofocus only when preview is started and snapshot is not
   // in progress.
   if (canTakePicture()) {
     mFocusStartTime = System.currentTimeMillis();
     mFocusState = FOCUSING;
     updateFocusIndicator();
     mCameraDevice.autoFocus(mAutoFocusCallback);
   }
 }
Exemplo n.º 12
0
 @Override
 public void run() {
   camera.autoFocus(
       new Camera.AutoFocusCallback() {
         @Override
         public void onAutoFocus(final boolean success, final Camera camera) {
           // schedule again
           cameraHandler.postDelayed(AutoFocusRunnable.this, AUTO_FOCUS_INTERVAL_MS);
         }
       });
 }
Exemplo n.º 13
0
 synchronized void start() {
   if (useAutoFocus) {
     active = true;
     try {
       camera.autoFocus(this);
     } catch (RuntimeException re) {
       // Have heard RuntimeException reported in Android 4.0.x+; continue?
       Log.w(TAG, "Unexpected exception while focusing", re);
     }
   }
 }
Exemplo n.º 14
0
 /** 按下快门一瞬间 */
 @Override
 public void capture() {
   if (mCamera != null) {
     // 控制摄像头自动对焦后才拍照,仅限于后置摄像头
     if (mCameraType == 0) {
       mCamera.autoFocus(autoFocusCallback);
     }
     // 前置摄像头有可能没有自动对焦功能
     mCamera.takePicture(null, null, mPictureCallback);
   }
 }
Exemplo n.º 15
0
 /**
  * Asks the camera hardware to perform an autofocus.
  *
  * @param handler The Handler to notify when the autofocus completes.
  * @param message The message to deliver.
  */
 public void requestAutoFocus(Handler handler, int message) {
   if (camera != null && previewing) {
     autoFocusCallback.setHandler(handler, message);
     try {
       camera.autoFocus(autoFocusCallback);
     } catch (RuntimeException re) {
       // Have heard RuntimeException reported in Android 4.0.x+;
       // continue?
       Log.w(TAG, "Unexpected exception while focusing", re);
     }
   }
 }
Exemplo n.º 16
0
 /** Take picture. */
 private void takePicture() {
   notTakingPic = false;
   try {
     // Try to auto-focus
     mCamera.autoFocus(onFocus);
   } catch (RuntimeException e) {
     e.printStackTrace();
     // If auto-focus didn't work, call the take picture method using the
     // jpegCallback variable
     mCamera.takePicture(null, null, jpegCallback);
   }
 }
Exemplo n.º 17
0
 /**
  * Starts camera auto-focus and registers a callback function to run when the camera is focused.
  * This method is only valid when preview is active (between {@link #start()} or {@link
  * #start(SurfaceHolder)} and before {@link #stop()} or {@link #release()}).
  *
  * <p>
  *
  * <p>Callers should check {@link #getFocusMode()} to determine if this method should be called.
  * If the camera does not support auto-focus, it is a no-op and {@link
  * AutoFocusCallback#onAutoFocus(boolean)} callback will be called immediately.
  *
  * <p>
  *
  * <p>If the current flash mode is not {@link Camera.Parameters#FLASH_MODE_OFF}, flash may be
  * fired during auto-focus, depending on the driver and camera hardware.
  *
  * <p>
  *
  * @param cb the callback to run
  * @see #cancelAutoFocus()
  */
 public void autoFocus(@Nullable AutoFocusCallback cb) {
   synchronized (mCameraLock) {
     if (mCamera != null) {
       CameraAutoFocusCallback autoFocusCallback = null;
       if (cb != null) {
         autoFocusCallback = new CameraAutoFocusCallback();
         autoFocusCallback.mDelegate = cb;
       }
       mCamera.autoFocus(autoFocusCallback);
     }
   }
 }
Exemplo n.º 18
0
 @Override
 public void onClick(View arg0) {
   // TODO Auto-generated method stub
   switch (arg0.getId()) {
     case R.id.zoom_img:
       mCamera.autoFocus(mAutoFocusCallback);
       mZoomImg.setBackgroundResource(R.drawable.capture);
       break;
     case R.id.left_frame:
       startWebActivity("http://wafm.sinosns.cn/");
       break;
   }
 }
Exemplo n.º 19
0
  /** Called from PreviewSurfaceView to set touch focus. */
  public void onTouchFocus(Rect touchFocusRect) {

    List<Camera.Area> focusList = new ArrayList<>();
    Camera.Area focusArea = new Camera.Area(touchFocusRect, 1000);
    focusList.add(focusArea);

    Camera.Parameters cameraParams = camera.getParameters();
    cameraParams.setFocusAreas(focusList);
    cameraParams.setMeteringAreas(focusList);
    camera.setParameters(cameraParams);

    camera.autoFocus(autoFocusCallback);
  }
Exemplo n.º 20
0
  /**
   * 设置焦点和测光区域
   *
   * @param event
   */
  public void focusOnTouch(MotionEvent event) {
    try {
      if (mCamera == null) {
        return;
      }
      Camera.Parameters parameters = mCamera.getParameters();
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        int[] location = new int[2];
        mSurfaceView.getLocationOnScreen(location);
        Rect focusRect =
            calculateTapArea(
                view_focus.getWidth(),
                view_focus.getHeight(),
                1f,
                event.getRawX(),
                event.getRawY(),
                location[0],
                location[0] + mSurfaceView.getWidth(),
                location[1],
                location[1] + mSurfaceView.getHeight());
        Rect meteringRect =
            calculateTapArea(
                view_focus.getWidth(),
                view_focus.getHeight(),
                1.5f,
                event.getRawX(),
                event.getRawY(),
                location[0],
                location[0] + mSurfaceView.getWidth(),
                location[1],
                location[1] + mSurfaceView.getHeight());
        if (parameters.getMaxNumFocusAreas() > 0) {
          List<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
          focusAreas.add(new Camera.Area(focusRect, 1000));
          parameters.setFocusAreas(focusAreas);
        }

        if (parameters.getMaxNumMeteringAreas() > 0) {
          List<Camera.Area> meteringAreas = new ArrayList<Camera.Area>();
          meteringAreas.add(new Camera.Area(meteringRect, 1000));
          parameters.setMeteringAreas(meteringAreas);
        }
      }

      parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
      mCamera.setParameters(parameters);
      mCamera.autoFocus(this);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 21
0
 public void capturePhoto() throws Exception {
   if (autoFocusEnabled) {
     mCamera.autoFocus(
         new Camera.AutoFocusCallback() {
           @Override
           public void onAutoFocus(boolean success, Camera camera) {
             if (success) mCamera.takePicture(null, null, mPicture);
           }
         });
   } else {
     mCamera.takePicture(null, null, mPicture);
   }
   // mCamera.takePicture(null, null, mPicture);
 }
Exemplo n.º 22
0
  // 设置相机的属性 抓取图像
  private void setCameraParameters() {
    Camera.Parameters caParameters = camera.getParameters();
    caParameters.setPictureFormat(ImageFormat.JPEG);
    caParameters.setPreviewSize(400, 500);
    caParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    camera.autoFocus(
        new Camera.AutoFocusCallback() {
          @Override
          public void onAutoFocus(boolean success, Camera camera) {

            if (success) {
              camera.takePicture(null, null, pictureCallback);
            }
          }
        });
  }
Exemplo n.º 23
0
 synchronized void start() {
   if (useAutoFocus) {
     outstandingTask = null;
     if (!stopped && !focusing) {
       try {
         camera.autoFocus(this);
         focusing = true;
       } catch (RuntimeException re) {
         // Have heard RuntimeException reported in Android 4.0.x+; continue?
         Log.w(TAG, "Unexpected exception while focusing", re);
         // Try again later to keep cycle going
         autoFocusAgainLater();
       }
     }
   }
 }
 @Override
 public void onClick(View view) {
   if (view.getId() == R.id.rootFrame) {
     if (mCamera == null) return;
     mCamera.cancelAutoFocus();
     mCamera.autoFocus(
         new Camera.AutoFocusCallback() {
           @Override
           public void onAutoFocus(boolean success, Camera camera) {
             if (!success)
               Toast.makeText(getActivity(), "Unable to auto-focus!", Toast.LENGTH_SHORT).show();
           }
         });
   } else {
     super.onClick(view);
   }
 }
Exemplo n.º 25
0
 public void playAutoFocus(boolean isFocus) {
   if (isFocus) {
     if (devicearraydata[0].equals("GT-S7562")) {
       if (IsFlash) {
         playFlash(true);
       }
     } else {
       cam.autoFocus(
           new AutoFocusCallback() {
             @Override
             public void onAutoFocus(boolean success, Camera camera) {}
           });
     }
   } else {
     cam.cancelAutoFocus();
   }
 }
Exemplo n.º 26
0
 public void takePicture() {
   int id = getFrontCameraId();
   if (id == -1) {
     Log.w(TAG, "No front camera available");
     return;
   }
   try {
     Log.d(TAG, "trying id" + id);
     mCamera = Camera.open(id);
     setCameraDisplayOrientation(mContext, id, mCamera);
     mCamera.startPreview();
     mCamera.autoFocus(null);
     mCamera.takePicture(null, null, null, new PictureSaver(mContext));
   } catch (Exception e) {
     Log.w(TAG, "Failed to take picture", e);
     close();
   }
 }
Exemplo n.º 27
0
 private void initCamera(SurfaceHolder surfaceHolder) {
   try {
     if (null == mCamera) {
       mCamera = Camera.open();
     }
     if (null == mCamera) {
       throw new RuntimeException("camera error!");
     }
     initCameraParameters();
     mCamera.setPreviewDisplay(surfaceHolder);
     mCamera.startPreview();
     mPreviewing = true;
     Log.d("mPreviewing", "after inti camera mPreviewing changed to :" + mPreviewing);
     mCamera.autoFocus(this);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  public void takePhoto(View v) {
    Camera.Parameters p = mCamera.getParameters();
    p.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    mCamera.setParameters(p);

    mCamera.autoFocus(
        new Camera.AutoFocusCallback() {
          @Override
          public void onAutoFocus(boolean success, Camera camera) {
            if (success) {
              // captureButton.setEnabled(false);
              mCamera.takePicture(null, null, mPicture);
            } else {
              // captureButton.setEnabled(false);
              mCamera.takePicture(null, null, mPicture);
            }
          }
        });
  }
Exemplo n.º 29
0
 public void run() {
   if (previewing) mCamera.autoFocus(autoFocusCB);
 }
 public void run() {
   if (mCamera != null && mPreviewing) {
     mCamera.autoFocus(autoFocusCB);
   }
 }