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;
  }
Exemplo n.º 2
0
 /**
  * Cancels any auto-focus function in progress. Whether or not auto-focus is currently in
  * progress, this function will return the focus position to the default. If the camera does not
  * support auto-focus, this is a no-op.
  *
  * @see #autoFocus(AutoFocusCallback)
  */
 public void cancelAutoFocus() {
   synchronized (mCameraLock) {
     if (mCamera != null) {
       mCamera.cancelAutoFocus();
     }
   }
 }
  public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Camera.Size size = parameters.getPreviewSize();

    Image barcode = new Image(size.width, size.height, "Y800");
    barcode.setData(data);

    int result = mScanner.scanImage(barcode);

    if (result != 0) {
      mCamera.cancelAutoFocus();
      mCamera.setPreviewCallback(null);
      mCamera.stopPreview();
      mPreviewing = false;
      SymbolSet syms = mScanner.getResults();
      for (Symbol sym : syms) {
        String symData = sym.getData();
        if (!TextUtils.isEmpty(symData)) {
          Intent dataIntent = new Intent();
          dataIntent.putExtra(SCAN_RESULT, symData);
          dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
          setResult(Activity.RESULT_OK, dataIntent);
          finish();
          break;
        }
      }
    }
  }
Exemplo n.º 4
0
 public void onPictureTaken(byte[] imageData, Camera c) {
   if (imageData != null) {
     System.out.println("__________________ length: " + imageData.length);
     FileManager.savePicture(imageData);
     camera.cancelAutoFocus();
     camera.startPreview();
   }
 }
Exemplo n.º 5
0
 private void cancelAutoFocus() {
   // User releases half-pressed focus key.
   if (mFocusState == FOCUSING || mFocusState == FOCUS_SUCCESS || mFocusState == FOCUS_FAIL) {
     mCameraDevice.cancelAutoFocus();
   }
   if (mFocusState != FOCUSING_SNAP_ON_FINISH) {
     clearFocusState();
   }
 }
Exemplo n.º 6
0
 public void stopCameraPreview() {
   if (mCamera != null) {
     try {
       mPreviewing = false;
       mCamera.cancelAutoFocus();
       mCamera.setOneShotPreviewCallback(null);
       mCamera.stopPreview();
     } catch (Exception e) {
       Log.e(TAG, e.toString(), e);
     }
   }
 }
Exemplo n.º 7
0
 synchronized void stop() {
   stopped = true;
   if (useAutoFocus) {
     cancelOutstandingTask();
     // Doesn't hurt to call this even if not focusing
     try {
       camera.cancelAutoFocus();
     } catch (RuntimeException re) {
       // Have heard RuntimeException reported in Android 4.0.x+; continue?
       Log.w(TAG, "Unexpected exception while cancelling focusing", re);
     }
   }
 }
Exemplo n.º 8
0
  public void stop() {

    camera.cancelAutoFocus();

    if (timerTask != null) {
      timerTask.cancel();
      timerTask = null;
    }

    running = false;

    Log.d(TAG, "AutoFocusEngine Stopped");
  }
 synchronized void stop() {
   if (useAutoFocus) {
     try {
       camera.cancelAutoFocus();
     } catch (RuntimeException re) {
       // Have heard RuntimeException reported in Android 4.0.x+; continue?
       Log.w(TAG, "Unexpected exception while cancelling focusing", re);
     }
   }
   if (outstandingTask != null) {
     outstandingTask.cancel(true);
     outstandingTask = null;
   }
   active = false;
 }
 @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.º 11
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.º 12
0
 public void setAutoFocus(boolean state) {
   if (mCamera != null && mPreviewing) {
     if (state == mAutoFocus) {
       return;
     }
     mAutoFocus = state;
     if (mAutoFocus) {
       if (mSurfaceCreated) { // check if surface created before using autofocus
         Log.v(TAG, "Starting autofocus");
         safeAutoFocus();
       } else {
         scheduleAutoFocus(); // wait 1 sec and then do check again
       }
     } else {
       Log.v(TAG, "Cancelling autofocus");
       mCamera.cancelAutoFocus();
     }
   }
 }
  @Override
  protected void onPause() {
    super.onPause();

    // Because the Camera object is a shared resource, it's very
    // important to release it when the activity is paused.
    if (mCamera != null) {
      mPreview.setCamera(null);
      mCamera.cancelAutoFocus();
      mCamera.setPreviewCallback(null);
      mCamera.stopPreview();
      mCamera.release();

      mPreview.hideSurfaceView();

      mPreviewing = false;
      mCamera = null;
    }
  }
  private static void setTorchEnabled(final Camera camera, final boolean enabled) {
    final Camera.Parameters parameters = camera.getParameters();

    final List<String> supportedFlashModes = parameters.getSupportedFlashModes();
    if (supportedFlashModes != null) {
      final String flashMode;
      if (enabled)
        flashMode =
            findValue(
                supportedFlashModes,
                Camera.Parameters.FLASH_MODE_TORCH,
                Camera.Parameters.FLASH_MODE_ON);
      else flashMode = findValue(supportedFlashModes, Camera.Parameters.FLASH_MODE_OFF);

      if (flashMode != null) {
        camera.cancelAutoFocus(); // autofocus can cause conflict

        parameters.setFlashMode(flashMode);
        camera.setParameters(parameters);
      }
    }
  }
Exemplo n.º 15
0
 public void getPicture() {
   camera.takePicture(null, mPictureCallback, mPictureCallback);
   camera.cancelAutoFocus();
 }
Exemplo n.º 16
0
 public void cancelAutoFocus() {
   camera.cancelAutoFocus();
 }
Exemplo n.º 17
0
 @Override
 public void onAutoFocus(boolean success, Camera camera) {
   if (success) camera.cancelAutoFocus();
 }