예제 #1
0
  @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();
  }
  @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;
  }
예제 #3
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;
  }
예제 #4
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;
    }
  }
  public void showDialog() {
    int currentIdx = -1;

    final String pref1 = MainScreen.sRearColorEffectPref;
    final String pref2 = MainScreen.sFrontColorEffectPref;

    int[] colorEfects = CameraController.getSupportedColorEffects();

    // Normally it should never happens. It's paranoia check.
    if (colorEfects == null
        || colorEfects.length == 0
        || CameraController.ColorEffectsNamesList == null
        || !CameraController.isColorEffectSupported()) {
      return;
    }

    mEntries =
        CameraController.ColorEffectsNamesList.toArray(
            new String[CameraController.ColorEffectsNamesList.size()]);

    mEntryValues = new CharSequence[colorEfects.length];
    for (int i = 0; i < colorEfects.length; i++) {
      mEntryValues[i] = Integer.toString(colorEfects[i]);
    }

    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(MainScreen.getMainContext());
    currentIdx = 0;
    try {
      currentIdx =
          Integer.parseInt(prefs.getString(CameraController.isFrontCamera() ? pref1 : pref2, "0"));
    } catch (Exception e) {
      currentIdx =
          prefs.getInt(
              CameraController.isFrontCamera() ? pref1 : pref2,
              MainScreen.sDefaultColorEffectValue);
    }

    int idx = 0;
    if (currentIdx != -1) {
      // set currently selected image size
      for (idx = 0; idx < mEntryValues.length; ++idx) {
        if (Integer.valueOf(mEntryValues[idx].toString()) == currentIdx) {
          mClickedDialogEntryIndex = idx;
          break;
        }
      }
    } else {
      mClickedDialogEntryIndex = 0;
    }

    dialog = new QuickSettingDialog(context);
    colorEffetcsListView = (ListView) dialog.findViewById(android.R.id.list);

    ListPreferenceAdapter adapter =
        new ListPreferenceAdapter(
            context,
            R.layout.simple_list_item_single_choice,
            android.R.id.text1,
            (String[]) mEntries,
            mClickedDialogEntryIndex);

    colorEffetcsListView.setAdapter(adapter);
    colorEffetcsListView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mClickedDialogEntryIndex != position) {
              mClickedDialogEntryIndex = position;
              Object newValue = mEntryValues[mClickedDialogEntryIndex];

              SharedPreferences prefs =
                  PreferenceManager.getDefaultSharedPreferences(MainScreen.getMainContext());
              prefs
                  .edit()
                  .putString(
                      CameraController.isFrontCamera() ? pref1 : pref2,
                      String.valueOf(newValue.toString()))
                  .commit();

              CameraController.setCameraColorEffect(Integer.parseInt(newValue.toString()));
            }
            dialog.dismiss();
          }
        });
    dialog.show();
  }
예제 #6
0
  public void selectImageDimension() {
    // ----- Figure how much memory do we have and possibly limit resolution
    long maxMem = Runtime.getRuntime().maxMemory();
    long maxMpix = (maxMem - 1000000) / 3; // 2 x Mpix - result, 1/4 x Mpix
    // x 4 - compressed input jpegs,
    // 1Mb - safe reserve

    // find index selected in preferences
    int prefIdx = -1;
    try {
      prefIdx = Integer.parseInt(MainScreen.getImageSizeIndex());
    } catch (IndexOutOfBoundsException e) {
      prefIdx = -1;
    }

    List<CameraController.Size> cs = CameraController.getResolutionsSizeList();
    // add 8 Mpix for rear camera for HTC One X
    if (Build.MODEL.contains("HTC One X")) {
      if (!CameraController.isFrontCamera()) {
        CameraController.Size additional = null;
        additional = CameraController.getInstance().new Size(3264, 2448);
        additional.setWidth(3264);
        additional.setHeight(2448);
        cs.add(additional);
      }
    }
    int defaultCaptureIdx = -1;
    long defaultCaptureMpix = 0;
    int defaultCaptureWidth = 0;
    int defaultCaptureHeight = 0;
    long CaptureMpix = 0;
    int CaptureWidth = 0;
    int CaptureHeight = 0;
    int CaptureIdx = -1;
    boolean prefFound = false;

    // figure default resolution
    int ii = 0;
    for (CameraController.Size s : cs) {
      long mpix = (long) s.getWidth() * s.getHeight();

      if ((mpix >= CameraController.MIN_MPIX_SUPPORTED) && (mpix < maxMpix)) {
        if (mpix > defaultCaptureMpix && mpix <= MPIX_8) {
          defaultCaptureIdx = ii;
          defaultCaptureMpix = mpix;
          defaultCaptureWidth = s.getWidth();
          defaultCaptureHeight = s.getHeight();
        }
      }

      ii++;
    }

    ii = 0;
    for (CameraController.Size s : cs) {
      long mpix = (long) s.getWidth() * s.getHeight();

      if ((Integer.parseInt(CameraController.getResolutionsIdxesList().get(ii)) == prefIdx)
          && (mpix >= CameraController.MIN_MPIX_SUPPORTED)) {
        prefFound = true;
        CaptureIdx = ii;
        CaptureMpix = mpix;
        CaptureWidth = s.getWidth();
        CaptureHeight = s.getHeight();
        break;
      }

      if (mpix > CaptureMpix) {
        CaptureIdx = ii;
        CaptureMpix = mpix;
        CaptureWidth = s.getWidth();
        CaptureHeight = s.getHeight();
      }

      ii++;
    }

    // default to about 8Mpix if nothing is set in preferences or maximum
    // resolution is above memory limits
    if (defaultCaptureMpix > 0) {
      if (!prefFound) {
        CaptureIdx = defaultCaptureIdx;
        CaptureMpix = defaultCaptureMpix;
        CaptureWidth = defaultCaptureWidth;
        CaptureHeight = defaultCaptureHeight;
      }
    }

    CameraController.setCameraImageSizeIndex(CaptureIdx);
    MainScreen.setImageWidth(CaptureWidth);
    MainScreen.setImageHeight(CaptureHeight);

    MainScreen.setSaveImageWidth(CaptureWidth);
    MainScreen.setSaveImageHeight(CaptureHeight);
  }