private void cancelAutoFocus() {
    Log.e(TAG, "cancelAutofocus");
    // Note: CameraController.getFocusMode(); will return
    // 'FOCUS_MODE_AUTO' if actual
    // mode is in fact FOCUS_MODE_CONTINUOUS_PICTURE or
    // FOCUS_MODE_CONTINUOUS_VIDEO
    int fm = CameraController.getFocusMode();
    if (fm != CameraParameters.AF_MODE_UNSUPPORTED) {
      if (fm != preferenceFocusMode && preferenceFocusMode != CameraParameters.MF_MODE) {
        CameraController.cancelAutoFocus();
        CameraController.setCameraFocusMode(preferenceFocusMode);
      }
    }

    // Reset the tap area before calling mListener.cancelAutofocus.
    // Otherwise, focus mode stays at auto and the tap area passed to the
    // driver is not reset.
    CameraController.setCameraFocusAreas(null);
    ApplicationScreen.instance.setCameraMeteringMode(ApplicationScreen.getMeteringMode());
    resetTouchFocus();

    mState = STATE_IDLE;
    CameraController.setFocusState(CameraController.FOCUS_STATE_IDLE);

    updateFocusUI();
    mHandler.removeMessages(RESET_TOUCH_FOCUS);
  }
 // This has to be initialized before initialize().
 public void initializeParameters() {
   mFocusAreaSupported =
       (CameraController.getMaxFocusAreasSupported() > 0
           && isSupported(
               CameraParameters.AF_MODE_AUTO, CameraController.getSupportedFocusModes()));
   mMeteringAreaSupported = CameraController.getMaxMeteringAreasSupported() > 0;
 }
  @Override
  public void onShutterClick() {
    if (needAutoFocusCall() && !focusOnShutterDisabled()) {
      if (mState == STATE_IDLE
          && !(preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
              || preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO)
          && !ApplicationScreen.instance.getAutoFocusLock()) {
        if (preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
            || preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO) {
          CameraController.setCameraFocusMode(CameraParameters.AF_MODE_AUTO);
        }
        setFocusParameters();
        setMeteringParameters();
        autoFocus();
      } else if (mState == STATE_FAIL) ApplicationScreen.getGUIManager().lockControls = false;
    } else {
      int focusMode = getFocusMode();
      if (focusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
          && (CameraController.isGalaxyS6
              || CameraController.isGalaxyS5
              || CameraController.isGalaxyNote4)) {
        final int[] supported_focus = CameraController.getSupportedFocusModes();
        int afMode = -1;
        if (CameraController.isModeAvailable(supported_focus, CameraParameters.AF_MODE_AUTO))
          afMode = CameraParameters.AF_MODE_AUTO;
        else if (CameraController.isModeAvailable(supported_focus, CameraParameters.AF_MODE_MACRO))
          afMode = CameraParameters.AF_MODE_MACRO;
        else afMode = supported_focus[0];

        CameraController.setCameraFocusMode(afMode);
        ApplicationScreen.instance.setAutoFocusLock(true);
      }
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    if (wakeLock == null) {
      PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
      wakeLock =
          pm.newWakeLock(
              PowerManager.FULL_WAKE_LOCK
                  | PowerManager.ACQUIRE_CAUSES_WAKEUP
                  | PowerManager.ON_AFTER_RELEASE,
              TAG);
    }
    if (!wakeLock.isHeld()) {
      wakeLock.acquire();
    }

    readyToTakePicture = true;

    try {
      if (ApplicationScreen.instance == null
          || ApplicationScreen.getCameraController() == null
          || (CameraController.getCamera() == null && CameraController.getCamera2() == null)) {
        Intent dialogIntent = new Intent(context, MainScreen.class);
        dialogIntent.addFlags(
            Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
                | Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(dialogIntent);
        if (wakeLock != null) if (wakeLock.isHeld()) wakeLock.release();

      } else {
        takePicture();
      }
    } catch (NullPointerException e) {
    }
  }
  @Override
  public void onCameraParametersSetup() {
    // replace here with [CF] mode as default.
    // Also, check if [CF] is available, and if not - set [AF], if [AF] is
    // not available - set first available
    preferenceFocusMode =
        ApplicationScreen.instance.getFocusModePref(ApplicationScreen.sDefaultFocusValue);

    int[] supportedFocusModes = CameraController.getSupportedFocusModes();
    if (supportedFocusModes != null && supportedFocusModes.length > 0) {
      if (!CameraController.isModeAvailable(supportedFocusModes, preferenceFocusMode)
          && preferenceFocusMode != CameraParameters.MF_MODE) {
        if (CameraController.isModeAvailable(supportedFocusModes, CameraParameters.AF_MODE_AUTO))
          preferenceFocusMode = CameraParameters.AF_MODE_AUTO;
        else preferenceFocusMode = supportedFocusModes[0];
      }
    }

    initializeParameters();

    initialize(CameraController.isFrontCamera(), 90);
    initializeSoundPlayers(
        ApplicationScreen.getAppResources().openRawResourceFd(R.raw.plugin_vf_focus_ok),
        ApplicationScreen.getAppResources().openRawResourceFd(R.raw.plugin_vf_focus_false));

    cancelAutoFocus();

    // Set the length of focus indicator according to preview frame size.
    int len = Math.min(mPreviewWidth, mPreviewHeight) / 25;
    ViewGroup.LayoutParams layout = mFocusIndicator.getLayoutParams();
    layout.width =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    layout.height =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    mFocusIndicator.requestLayout();

    layout = mMeteringIndicator.getLayoutParams();
    layout.width =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    layout.height =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    mMeteringIndicator.requestLayout();
  }
Esempio n. 6
0
  public void setCameraPreviewSize(Camera.Parameters cp) {
    List<CameraController.Size> cs = CameraController.getInstance().getSupportedPreviewSizes();

    CameraController.Size os =
        getOptimalPreviewSize(cs, MainScreen.getImageWidth(), MainScreen.getImageHeight());
    cp.setPreviewSize(os.getWidth(), os.getHeight());
    try {
      CameraController.getInstance().setCameraParameters(cp);
    } catch (RuntimeException e) {
      Log.e("CameraTest", "MainScreen.setupCamera unable setParameters " + e.getMessage());
    }
  }
Esempio n. 7
0
  @Override
  public void onCameraParametersSetup() {
    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());
    if (ModePreference.equals("0")) {
      // FixMe: why not setting exposure if we are in dro-off mode?
      UpdateEv(true, singleModeEV);
    }

    if (CameraController.isRemoteCamera()) {
      Size imageSize = CameraController.getCameraImageSize();
      CameraController.setPictureSize(imageSize.getWidth(), imageSize.getHeight());
    }
  }
  // This can only be called after mParameters is initialized.
  public int getFocusMode() {
    if (mOverrideFocusMode != CameraParameters.AF_MODE_UNSUPPORTED) return mOverrideFocusMode;

    if (mFocusAreaSupported && mFocusArea != null) mFocusMode = CameraParameters.AF_MODE_AUTO;
    else mFocusMode = ApplicationScreen.instance.getFocusModePref(mDefaultFocusMode);

    if (!isSupported(mFocusMode, CameraController.getSupportedFocusModes())) {
      // For some reasons, the driver does not support the current
      // focus mode. Fall back to auto.
      if (isSupported(CameraParameters.AF_MODE_AUTO, CameraController.getSupportedFocusModes()))
        mFocusMode = CameraParameters.AF_MODE_AUTO;
      else mFocusMode = CameraController.getFocusMode();
    }
    return mFocusMode;
  }
Esempio n. 9
0
 @Override
 public void takePicture() {
   framesCaptured = 0;
   resultCompleted = 0;
   createRequestIDList(captureRAW ? 2 : 1);
   if (ModePreference.compareTo("0") == 0)
     CameraController.captureImagesWithParams(
         1, CameraController.YUV, null, null, null, null, true, true);
   else if (captureRAW)
     CameraController.captureImagesWithParams(
         1, CameraController.RAW, null, null, null, null, true, true);
   else
     CameraController.captureImagesWithParams(
         1, CameraController.JPEG, null, null, null, null, true, true);
 }
Esempio n. 10
0
  @Override
  public void onStart() {
    mState = STATE_IDLE;
    updateFocusUI();

    CameraController.setFocusState(CameraController.FOCUS_STATE_IDLE);
  }
Esempio n. 11
0
 private void autoFocus() {
   if (CameraController.autoFocus()) {
     mState = STATE_FOCUSING;
     updateFocusUI();
     mHandler.removeMessages(RESET_TOUCH_FOCUS);
   }
 }
Esempio n. 12
0
  void updatePreferences() {
    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());
    mGyroState = prefs.getBoolean("PrefGyroVF", false);

    if (!prefs.contains("PrefGyroTypeVF")) {
      Editor editor = prefs.edit();
      if (mGyroscope != null) {
        editor.putBoolean("PrefGyroTypeVF", true);
      } else {
        editor.putBoolean("PrefGyroTypeVF", false);
      }
      editor.commit();
    }
    mPrefHardwareGyroscope = prefs.getBoolean("PrefGyroTypeVF", false);

    if (mGyroState == ON) {
      CameraController.setNeedPreviewFrame(true);
      quickControlIconID = R.drawable.gui_almalence_settings_gyro;
      if (mHorizonIndicatorContainer != null) {
        mHorizonIndicatorContainer.setVisibility(View.VISIBLE);
      }
      initSensors();
    } else {
      quickControlIconID = R.drawable.gui_almalence_settings_gyro_off;
      if (mHorizonIndicatorContainer != null) {
        mHorizonIndicatorContainer.setVisibility(View.GONE);
      }
      releaseSensors();
    }
  }
Esempio n. 13
0
  @Override
  public void onGUICreate() {
    ApplicationScreen.getGUIManager().removeViews(modeSwitcher, R.id.specialPluginsLayout3);

    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    if (!CameraController.isRemoteCamera()) {
      ((RelativeLayout) ApplicationScreen.instance.findViewById(R.id.specialPluginsLayout3))
          .addView(this.modeSwitcher, params);
    }

    this.modeSwitcher.setLayoutParams(params);

    if (ModePreference.compareTo("0") == 0)
      ApplicationScreen.getGUIManager()
          .showHelp(
              "Dro help",
              ApplicationScreen.getAppResources().getString(R.string.Dro_Help),
              R.drawable.plugin_help_dro,
              "droShowHelp");
  }
Esempio n. 14
0
 public void setMeteringParameters() {
   if (mMeteringAreaSupported) {
     // Use the same area for focus and metering.
     List<Area> area = getMeteringAreas();
     if (area != null) CameraController.setCameraMeteringAreas(area);
   }
 }
Esempio n. 15
0
  void UpdateEv(boolean isDro, int ev) {
    if (isDro) {
      // for still-image DRO - set Ev just a bit lower (-0.5Ev or less)
      // than for standard shot
      float expStep = CameraController.getExposureCompensationStep();
      int diff = (int) Math.floor(0.5 / expStep);
      if (diff < 1) diff = 1;

      ev -= diff;
    }

    int minValue = CameraController.getMinExposureCompensation();
    if (ev >= minValue) {
      CameraController.setCameraExposureCompensation(ev);
      ApplicationScreen.instance.setEVPref(ev);
    }
  }
Esempio n. 16
0
  // Used only in old camera interface (HALv3 don't use it)
  public void setCameraPictureSize() {
    Camera camera = CameraController.getCamera();
    if (null == camera) return;

    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(MainScreen.getMainContext());
    int jpegQuality = Integer.parseInt(prefs.getString(MainScreen.sJPEGQualityPref, "95"));

    Camera.Parameters cp = CameraController.getInstance().getCameraParameters();
    cp.setPictureSize(MainScreen.getImageWidth(), MainScreen.getImageHeight());
    cp.setJpegQuality(jpegQuality);
    try {
      CameraController.getInstance().setCameraParameters(cp);
    } catch (RuntimeException e) {
      Log.e("CameraTest", "MainScreen.setupCamera unable setParameters " + e.getMessage());
    }
  }
Esempio n. 17
0
  public void onPreviewStopped() {
    mState = STATE_IDLE;
    resetTouchFocus();
    // If auto focus was in progress, it would have been canceled.
    updateFocusUI();

    CameraController.setFocusState(CameraController.FOCUS_STATE_IDLE);
  }
Esempio n. 18
0
  @Override
  public void onStop() {
    // cancelAutoFocus();
    mState = STATE_INACTIVE;
    updateFocusUI();

    CameraController.setFocusState(CameraController.FOCUS_STATE_IDLE);

    ApplicationScreen.getGUIManager().removeViews(focusLayout, R.id.specialPluginsLayout);
  }
Esempio n. 19
0
  public boolean onBroadcast(int arg1, int arg2) {
    if (arg1 == ApplicationInterface.MSG_CONTROL_LOCKED) {
      mFocusDisabled = true;
    } else if (arg1 == ApplicationInterface.MSG_CONTROL_UNLOCKED) {
      mFocusDisabled = false;
    } else if (arg1 == ApplicationInterface.MSG_FOCUS_LOCKED) {
      mFocusLocked = true;
    } else if (arg1 == ApplicationInterface.MSG_FOCUS_UNLOCKED) {
      mFocusLocked = false;
    } else if (arg1 == ApplicationInterface.MSG_CAPTURE_FINISHED) {
      mFocusDisabled = false;
      cancelAutoFocus();
    } else if (arg1 == ApplicationInterface.MSG_FOCUS_CHANGED) {
      int fm = CameraController.getFocusMode();
      if (fm != -1) preferenceFocusMode = fm;
    } else if (arg1 == ApplicationInterface.MSG_PREVIEW_CHANGED) {
      initialize(CameraController.isFrontCamera(), 90);
    }

    return false;
  }
Esempio n. 20
0
  /** The Surface is created/init() */
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    Log.i("Almalence", "GLLayer.onSurfaceCreated()");

    PluginManager.getInstance().onGLSurfaceCreated(gl, config);

    if (PluginManager.getInstance().shouldPreviewToGPU()) {
      final int[] tex = new int[1];
      GLES20.glGenTextures(1, tex, 0);
      this.texture_preview = tex[0];

      GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, this.texture_preview);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);

      this.surfaceTexture = new SurfaceTexture(this.texture_preview);
      this.surfaceTexture.setOnFrameAvailableListener(
          new OnFrameAvailableListener() {
            @Override
            public void onFrameAvailable(final SurfaceTexture surfaceTexture) {
              PluginManager.getInstance().onFrameAvailable();
            }
          });

      final Camera camera = CameraController.getCamera();
      if (camera == null) {
        return;
      }

      try {
        camera.setDisplayOrientation(90);
      } catch (RuntimeException e) {
        e.printStackTrace();
      }

      try {
        camera.setPreviewTexture(this.surfaceTexture);
      } catch (final IOException e) {
        e.printStackTrace();
      }

      camera.startPreview();
    }
  }
Esempio n. 21
0
 private boolean needAutoFocusCall() {
   int focusMode = getFocusMode();
   return !(focusMode == CameraParameters.AF_MODE_INFINITY
       || focusMode == CameraParameters.AF_MODE_FIXED
       || focusMode == CameraParameters.AF_MODE_EDOF // EDOF likely
       // needs
       // auto-focus
       // call
       || focusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
       || focusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO
       || focusMode == CameraParameters.MF_MODE
       || mFocusDisabled
       || mFocusLocked
       || !CameraController.isFocusModeSupported());
 }
Esempio n. 22
0
  @Override
  public void onResume() {
    inCapture = false;
    aboutToTakePicture = false;

    if (ModePreference.compareTo("0") == 0)
      ApplicationScreen.setCaptureFormat(CameraController.YUV);
    else {
      if (captureRAW && CameraController.isRAWCaptureSupported())
        ApplicationScreen.setCaptureFormat(CameraController.RAW);
      else {
        captureRAW = false;
        ApplicationScreen.setCaptureFormat(CameraController.JPEG);
      }
    }
  }
  @Override
  public boolean handleMessage(Message msg) {
    switch (msg.what) {
      case MSG_END_OF_LOADING:
        setupSaveButton();
        postProcessingRun = true;
        break;
      case MSG_LEAVING:
        ApplicationScreen.getMessageHandler()
            .sendEmptyMessage(ApplicationInterface.MSG_POSTPROCESSING_FINISHED);

        PluginManager.getInstance()
            .sendMessage(
                ApplicationInterface.MSG_BROADCAST, ApplicationInterface.MSG_CONTROL_UNLOCKED);

        ApplicationScreen.getGUIManager().lockControls = false;

        postProcessingRun = false;
        return false;

      case MSG_REDRAW:
        if (PreviewBmp != null) PreviewBmp.recycle();
        if (finishing) return true;
        PreviewBmp = mAlmaCLRShot.getPreviewBitmap();
        if (PreviewBmp != null) {
          Matrix matrix = new Matrix();
          matrix.postRotate(90);
          Bitmap rotated =
              Bitmap.createBitmap(
                  PreviewBmp, 0, 0, PreviewBmp.getWidth(), PreviewBmp.getHeight(), matrix, true);
          mImgView.setImageBitmap(rotated);
          mImgView.setRotation(
              CameraController.isFrontCamera()
                  ? ((mDisplayOrientation == 0 || mDisplayOrientation == 180) ? 0 : 180)
                  : 0);
        }

        sequenceView.setEnabled(true);
        break;
      default:
        break;
    }
    return true;
  }
  public void onSequenceChanged(final int[] idx) {
    sequenceView.setEnabled(false);

    CameraController.Size imageSize = CameraController.getCameraImageSize();
    Size input = new Size(imageSize.getWidth(), imageSize.getHeight());
    int minSize = 1000;
    if (mMinSize == 0) {
      minSize = 0;
    } else {
      minSize = input.getWidth() * input.getHeight() / mMinSize;
    }

    Size preview = new Size(mDisplayWidth, mDisplayHeight);
    try {
      mAlmaCLRShot.initialize(
          preview,
          mAngle,
          /*
           * sensitivity for objection detection
           */
          mSensitivity - 15,
          /*
           * Minimum size of object to be able to detect -15 ~ 15 max -> easy
           * detection dull detection min ->
           */
          minSize,
          /*
           * ghosting parameter 0 : normal operation 1 : detect ghosted
           * objects but not remove them 2 : detect and remove all object
           */
          Integer.parseInt(mGhosting),
          idx);
    } catch (NumberFormatException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }

    mHandler.sendEmptyMessage(MSG_REDRAW);
  }
Esempio n. 25
0
  @Override
  public void onImageTaken(int frame, byte[] frameData, int frame_len, int format) {
    framesCaptured++;
    boolean isRAW = (format == CameraController.RAW);

    PluginManager.getInstance()
        .addToSharedMem("frame" + framesCaptured + SessionID, String.valueOf(frame));
    PluginManager.getInstance()
        .addToSharedMem("framelen" + framesCaptured + SessionID, String.valueOf(frame_len));

    PluginManager.getInstance()
        .addToSharedMem("frameisraw" + framesCaptured + SessionID, String.valueOf(isRAW));

    PluginManager.getInstance()
        .addToSharedMem(
            "frameorientation" + framesCaptured + SessionID,
            String.valueOf(ApplicationScreen.getGUIManager().getDisplayOrientation()));
    PluginManager.getInstance()
        .addToSharedMem(
            "framemirrored" + framesCaptured + SessionID,
            String.valueOf(CameraController.isFrontCamera()));

    PluginManager.getInstance()
        .addToSharedMem("amountofcapturedframes" + SessionID, String.valueOf(framesCaptured));
    PluginManager.getInstance()
        .addToSharedMem("amountofcapturedrawframes" + SessionID, isRAW ? "1" : "0");

    PluginManager.getInstance().addToSharedMem("isdroprocessing" + SessionID, ModePreference);

    if ((captureRAW && framesCaptured == 2) || !captureRAW || ModePreference.compareTo("0") == 0) {
      PluginManager.getInstance()
          .sendMessage(ApplicationInterface.MSG_CAPTURE_FINISHED, String.valueOf(SessionID));
      inCapture = false;
      framesCaptured = 0;
      resultCompleted = 0;
    }
  }
Esempio n. 26
0
  public void onTouchFocusArea(MotionEvent e) {
    if (!mFocusAreaSupported) return;

    int xRaw = (int) e.getRawX();
    int yRaw = (int) e.getRawY();

    if (e.getPointerCount() > 1) {
      final int location[] = {0, 0};
      focusLayout.getLocationOnScreen(location);
      xRaw = (int) e.getX(0) + location[0];
      yRaw = (int) e.getY(0) + location[1];
    }

    // Initialize variables.
    int focusWidth = mFocusIndicatorRotateLayout.getWidth();
    int focusHeight = mFocusIndicatorRotateLayout.getHeight();
    int previewWidth = mPreviewWidth;
    int previewHeight = mPreviewHeight;
    int displayWidth = ApplicationScreen.getAppResources().getDisplayMetrics().widthPixels;
    int displayHeight = ApplicationScreen.getAppResources().getDisplayMetrics().heightPixels;
    int diffWidth = displayWidth - previewWidth;
    int diffHeight = displayHeight - previewHeight;

    // Initialize variables.
    int paramsLayoutHeight = 0;

    int xOffset = (focusLayout.getWidth() - previewWidth) / 2;
    int yOffset = (focusLayout.getHeight() - previewHeight) / 2;

    if (mFocusArea == null) {
      mFocusArea = new ArrayList<Area>();
      mFocusArea.add(new Area(new Rect(), 1000));
    }

    // Use margin to set the metering indicator to the touched area.
    RelativeLayout.LayoutParams p =
        (RelativeLayout.LayoutParams) mFocusIndicatorRotateLayout.getLayoutParams();
    int left =
        Util.clamp(
            xRaw - focusWidth / 2 + xOffset,
            diffWidth / 2,
            (previewWidth - focusWidth + xOffset * 2) - diffWidth / 2);
    int top =
        Util.clamp(
            yRaw - focusHeight / 2 + yOffset - diffHeight / 2,
            0,
            previewHeight - focusHeight + yOffset * 2);

    p.leftMargin = left;
    p.topMargin = top;

    int[] rules = p.getRules();
    rules[RelativeLayout.CENTER_IN_PARENT] = 0;

    mFocusIndicatorRotateLayout.setLayoutParams(p);

    calculateTapAreaByTopLeft(
        focusWidth,
        focusHeight,
        1f,
        top,
        left,
        ApplicationScreen.getPreviewSurfaceView().getWidth(),
        ApplicationScreen.getPreviewSurfaceView().getHeight(),
        mFocusArea.get(0).rect);

    // Set the focus area and metering area.
    if (mFocusAreaSupported
        && (e.getActionMasked() == MotionEvent.ACTION_UP
            || e.getActionMasked() == MotionEvent.ACTION_POINTER_UP)) {
      setFocusParameters();

      int focusMode = CameraController.getFocusMode();
      if (focusMode == CameraParameters.AF_MODE_AUTO
          || focusMode == CameraParameters.AF_MODE_MACRO) {
        CameraController.cancelAutoFocus();
        autoFocus();
      } else {
        mState = STATE_FOCUSING;
        updateFocusUI();
      }
    }
    mFocusIndicatorRotateLayout.requestLayout();
  }
Esempio n. 27
0
  public void onTouchFocusAndMeteringArea(MotionEvent e) {
    if (!mFocusAreaSupported) return;

    int xRaw = (int) e.getRawX();
    int yRaw = (int) e.getRawY();

    // Initialize variables.
    int focusWidth = mFocusIndicatorRotateLayout.getWidth();
    int focusHeight = mFocusIndicatorRotateLayout.getHeight();
    int previewWidth = mPreviewWidth;
    int previewHeight = mPreviewHeight;
    int displayWidth = ApplicationScreen.getAppResources().getDisplayMetrics().widthPixels;
    int displayHeight = ApplicationScreen.getAppResources().getDisplayMetrics().heightPixels;
    int diffWidth = displayWidth - previewWidth;
    int diffHeight = displayHeight - previewHeight;

    // Initialize variables.
    int xOffset = (focusLayout.getWidth() - previewWidth) / 2;
    int yOffset = (focusLayout.getHeight() - previewHeight) / 2;

    if (mFocusArea == null) {
      mFocusArea = new ArrayList<Area>();
      mFocusArea.add(new Area(new Rect(), 1000));
    }

    if (mMeteringArea == null) {
      mMeteringArea = new ArrayList<Area>();
      mMeteringArea.add(new Area(new Rect(), 1000));
    }

    // Use margin to set the metering indicator to the touched area.
    RelativeLayout.LayoutParams p =
        (RelativeLayout.LayoutParams) mFocusIndicatorRotateLayout.getLayoutParams();
    int left =
        Util.clamp(
            xRaw - focusWidth / 2 + xOffset,
            diffWidth / 2,
            (previewWidth - focusWidth + xOffset * 2) - diffWidth / 2);
    int top =
        Util.clamp(
            yRaw - focusHeight / 2 + yOffset - diffHeight / 2,
            0,
            previewHeight - focusHeight + yOffset * 2);

    p.leftMargin = left;
    p.topMargin = top;

    int[] rules = p.getRules();
    rules[RelativeLayout.CENTER_IN_PARENT] = 0;

    mFocusIndicatorRotateLayout.setLayoutParams(p);

    calculateTapAreaByTopLeft(
        focusWidth,
        focusHeight,
        1f,
        top,
        left,
        ApplicationScreen.getPreviewSurfaceView().getWidth(),
        ApplicationScreen.getPreviewSurfaceView().getHeight(),
        mFocusArea.get(0).rect);

    if (ApplicationScreen.getMeteringMode() != -1
        && ApplicationScreen.getMeteringMode() == CameraParameters.meteringModeSpot)
      calculateTapAreaByTopLeft(
          focusWidth,
          focusHeight,
          1f,
          top,
          left,
          ApplicationScreen.getPreviewSurfaceView().getWidth(),
          ApplicationScreen.getPreviewSurfaceView().getHeight(),
          mMeteringArea.get(0).rect);
    else mMeteringArea = null;

    // Set the focus area and metering area.
    if ((mFocusAreaSupported && needAutoFocusCall() && (e.getAction() == MotionEvent.ACTION_UP))
        || CameraController.isRemoteCamera()) {
      CameraController.cancelAutoFocus();
      if (preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
          || preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO) {
        CameraController.setCameraFocusMode(CameraParameters.AF_MODE_AUTO);
      }

      setFocusParameters();
      setMeteringParameters();
      autoFocus();

    } else if (e.getAction() == MotionEvent.ACTION_UP
        && ApplicationScreen.instance.isShotOnTap() == 1
        && !PluginManager.getInstance().getActiveMode().modeID.equals("video")
        && !currentTouch) {

      ApplicationScreen.getGUIManager().onHardwareShutterButtonPressed();
    } else if (e.getAction() == MotionEvent.ACTION_UP
        && ApplicationScreen.instance.isShotOnTap() == 2
        && !PluginManager.getInstance().getActiveMode().modeID.equals("video")
        && !currentTouch) {
      if (isDoubleClick) {
        ApplicationScreen.getGUIManager().onHardwareShutterButtonPressed();
        isDoubleClick = false;
      }
    } else if (e.getAction()
        == MotionEvent.ACTION_UP) { // Just show the indicator in all other cases.
      autoFocus();
      // updateFocusUI();
      // Reset the metering area in 3 seconds.
      mHandler.removeMessages(RESET_TOUCH_FOCUS);
      mHandler.sendEmptyMessageDelayed(RESET_TOUCH_FOCUS, RESET_TOUCH_FOCUS_DELAY);
    }

    mFocusIndicatorRotateLayout.requestLayout();
  }
  public void onStartProcessing(long SessionID) {
    finishing = false;
    Message msg = new Message();
    msg.what = ApplicationInterface.MSG_PROCESSING_BLOCK_UI;
    ApplicationScreen.getMessageHandler().sendMessage(msg);

    PluginManager.getInstance()
        .sendMessage(ApplicationInterface.MSG_BROADCAST, ApplicationInterface.MSG_CONTROL_LOCKED);

    ApplicationScreen.getGUIManager().lockControls = true;

    sessionID = SessionID;

    PluginManager.getInstance()
        .addToSharedMem(
            "modeSaveName" + sessionID, PluginManager.getInstance().getActiveMode().modeSaveName);

    mDisplayOrientation =
        Integer.valueOf(
            PluginManager.getInstance().getFromSharedMem("frameorientation1" + sessionID));
    int orientation = ApplicationScreen.getGUIManager().getLayoutOrientation();
    mLayoutOrientationCurrent =
        (orientation == 0 || orientation == 180) ? orientation : (orientation + 180) % 360;

    mCameraMirrored =
        Boolean.valueOf(PluginManager.getInstance().getFromSharedMem("framemirrored1" + sessionID));

    CameraController.Size imageSize = CameraController.getCameraImageSize();
    if (mDisplayOrientation == 0 || mDisplayOrientation == 180) {
      imgWidthOR = imageSize.getHeight();
      imgHeightOR = imageSize.getWidth();
    } else {
      imgWidthOR = imageSize.getWidth();
      imgHeightOR = imageSize.getHeight();
    }

    mAlmaCLRShot = AlmaCLRShot.getInstance();

    getPrefs();

    try {
      Size input = new Size(imageSize.getWidth(), imageSize.getHeight());
      int imagesAmount =
          Integer.parseInt(
              PluginManager.getInstance().getFromSharedMem("amountofcapturedframes" + sessionID));
      int minSize = 1000;
      if (mMinSize == 0) {
        minSize = 0;
      } else {
        minSize = input.getWidth() * input.getHeight() / mMinSize;
      }

      if (imagesAmount == 0) imagesAmount = 1;

      int iImageWidth = imageSize.getWidth();
      int iImageHeight = imageSize.getHeight();

      thumbnails.clear();
      int heightPixels = ApplicationScreen.getAppResources().getDisplayMetrics().heightPixels;
      for (int i = 1; i <= imagesAmount; i++) {
        thumbnails.add(
            Bitmap.createScaledBitmap(
                ImageConversion.decodeYUVfromBuffer(
                    mYUVBufferList.get(i - 1), iImageWidth, iImageHeight),
                heightPixels / imagesAmount,
                (int) (iImageHeight * (((float) heightPixels / imagesAmount) / iImageWidth)),
                false));
      }

      Display display =
          ((WindowManager) ApplicationScreen.instance.getSystemService(Context.WINDOW_SERVICE))
              .getDefaultDisplay();
      Point dis = new Point();
      display.getSize(dis);

      float imageRatio = (float) iImageWidth / (float) iImageHeight;
      float displayRatio = (float) dis.y / (float) dis.x;

      if (imageRatio > displayRatio) {
        mDisplayWidth = dis.y;
        mDisplayHeight = (int) ((float) dis.y / (float) imageRatio);
      } else {
        mDisplayWidth = (int) ((float) dis.x * (float) imageRatio);
        mDisplayHeight = dis.x;
      }

      Size preview = new Size(mDisplayWidth, mDisplayHeight);

      PluginManager.getInstance()
          .addToSharedMem("amountofresultframes" + sessionID, String.valueOf(imagesAmount));

      PluginManager.getInstance()
          .addToSharedMem("saveImageWidth" + sessionID, String.valueOf(imgWidthOR));
      PluginManager.getInstance()
          .addToSharedMem("saveImageHeight" + sessionID, String.valueOf(imgHeightOR));

      this.indexes = new int[imagesAmount];
      for (int i = 0; i < imagesAmount; i++) {
        this.indexes[i] = i;
      }

      // frames!!! should be taken from heap
      mAlmaCLRShot.addYUVInputFrame(mYUVBufferList, input);

      mAlmaCLRShot.initialize(
          preview,
          mAngle,
          /*
           * sensitivity for objection detection
           */
          mSensitivity - 15,
          /*
           * Minimum size of object to be able to detect -15 ~ 15 max -> easy
           * detection dull detection min ->
           */
          minSize,
          /*
           * ghosting parameter 0 : normal operation 1 : detect ghosted
           * objects but not remove them 2 : detect and remove all object
           */
          Integer.parseInt(mGhosting),
          indexes);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 29
0
  public void onTouchAreas(MotionEvent e) {
    // Initialize variables.
    int x = Math.round(e.getX());
    int y = Math.round(e.getY());
    int focusWidth = mFocusIndicatorRotateLayout.getWidth();
    int focusHeight = mFocusIndicatorRotateLayout.getHeight();
    int previewWidth = mPreviewWidth;
    int previewHeight = mPreviewHeight;
    int displayWidth = ApplicationScreen.getAppResources().getDisplayMetrics().widthPixels;
    int diffWidth = displayWidth - previewWidth;

    int paramsLayoutHeight = 0;

    int xOffset = (focusLayout.getWidth() - previewWidth) / 2;
    int yOffset = (focusLayout.getHeight() - previewHeight) / 2;

    if (mFocusArea == null) {
      mFocusArea = new ArrayList<Area>();
      mFocusArea.add(new Area(new Rect(), 1000));
    }

    if (mMeteringArea == null) {
      mMeteringArea = new ArrayList<Area>();
      mMeteringArea.add(new Area(new Rect(), 1000));
    }

    boolean isNexus6 = CameraController.isNexus6;
    // Convert the coordinates to driver format.
    // AE area is bigger because exposure is sensitive and
    // easy to over- or underexposure if area is too small.
    calculateTapArea(
        focusWidth,
        focusHeight,
        1f,
        x,
        y,
        ApplicationScreen.getPreviewSurfaceView().getWidth(),
        ApplicationScreen.getPreviewSurfaceView().getHeight(),
        mFocusArea.get(0).rect);
    if (ApplicationScreen.getMeteringMode() != -1
        && ApplicationScreen.getMeteringMode() == CameraParameters.meteringModeSpot)
      calculateTapArea(
          20 + (isNexus6 ? focusWidth : 0),
          20 + (isNexus6 ? focusHeight : 0),
          1f,
          x,
          y,
          ApplicationScreen.getPreviewSurfaceView().getWidth(),
          ApplicationScreen.getPreviewSurfaceView().getHeight(),
          mMeteringArea.get(0).rect);
    else mMeteringArea = null;

    if (mFocusAreaSupported) {
      // Use margin to set the focus indicator to the touched area.
      RelativeLayout.LayoutParams p =
          (RelativeLayout.LayoutParams) mFocusIndicatorRotateLayout.getLayoutParams();
      int left =
          Util.clamp(
              x - focusWidth / 2 + xOffset,
              diffWidth / 2,
              (previewWidth - focusWidth + xOffset * 2) - diffWidth / 2);
      int top =
          Util.clamp(
              y - focusHeight / 2 + yOffset,
              paramsLayoutHeight / 2,
              (previewHeight - focusHeight + yOffset * 2) - paramsLayoutHeight / 2);
      p.setMargins(left, top, 0, 0);
      // Disable "center" rule because we no longer want to put it in the
      // center.
      int[] rules = p.getRules();
      rules[RelativeLayout.CENTER_IN_PARENT] = 0;
      mFocusIndicatorRotateLayout.requestLayout();
    }

    // Set the focus area and metering area.
    if (mFocusAreaSupported && needAutoFocusCall() && (e.getAction() == MotionEvent.ACTION_UP)) {
      CameraController.cancelAutoFocus();
      if (preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
          || preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO) {
        CameraController.setCameraFocusMode(CameraParameters.AF_MODE_AUTO);
      }

      setFocusParameters();
      setMeteringParameters();
      autoFocus();

    } else if (e.getAction() == MotionEvent.ACTION_UP
        && ApplicationScreen.instance.isShotOnTap() == 1
        && !PluginManager.getInstance().getActiveMode().modeID.equals("video")) {

      ApplicationScreen.getGUIManager().onHardwareShutterButtonPressed();
    } else if (e.getAction() == MotionEvent.ACTION_UP
        && ApplicationScreen.instance.isShotOnTap() == 2
        && !PluginManager.getInstance().getActiveMode().modeID.equals("video")) {
      if (isDoubleClick) {
        ApplicationScreen.getGUIManager().onHardwareShutterButtonPressed();
        isDoubleClick = false;
      }
    } else { // Just show the indicator in all other cases.
      autoFocus();
      // Reset the metering area in 3 seconds.
      mHandler.removeMessages(RESET_TOUCH_FOCUS);
      mHandler.sendEmptyMessageDelayed(RESET_TOUCH_FOCUS, RESET_TOUCH_FOCUS_DELAY);
    }
  }
Esempio n. 30
0
 @Override
 public void onStop() {
   if (!CameraController.isRemoteCamera()) {
     ApplicationScreen.getGUIManager().removeViews(modeSwitcher, R.id.specialPluginsLayout3);
   }
 }