com.google.zxing.client.android.camera.CameraManager#setManualFramingRect ( )源码实例Demo

下面列出了com.google.zxing.client.android.camera.CameraManager#setManualFramingRect ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ProjectX   文件: ZxingScanView.java
private void openDriver(SurfaceHolder surfaceHolder) {
    notifyListenerPrepareOpen();
    if (surfaceHolder == null)
        return;// 已经销毁
    if (isOpen())
        return;// 摄像头已经打开
    if (Compat.checkSelfPermission(getContext(), Manifest.permission.CAMERA)
            == PackageManager.PERMISSION_DENIED) {
        mErrorCode = ERROR_CODE_1;
        notifyListenerError();
        return;
    }
    mCameraManager = new CameraManager(getContext());
    if (mCameraId != OpenCameraInterface.NO_REQUESTED_CAMERA)
        mCameraManager.setManualCameraId(mCameraId);
    final int width = mScanWidth == ViewGroup.LayoutParams.MATCH_PARENT ? getWidth() :
            (mScanWidth > getWidth() ? getWidth() : mScanWidth);
    final int height = mScanHeight == ViewGroup.LayoutParams.MATCH_PARENT ? getHeight() :
            (mScanHeight > getHeight() ? getHeight() : mScanHeight);
    mCameraManager.setManualFramingRect(width, height);
    try {
        mCameraManager.openDriver(surfaceHolder);
        mCameraManager.startPreview();
        mScanHandler = new ScanHandler(resultListener, mBarcodeType, mBaseHints,
                mCharacterSet, mCameraManager,
                resultPointCallback);
    } catch (Exception e) {
        mErrorCode = ERROR_CODE_0;
        notifyListenerError();
        return;
    }
    mAmbientLightManager.resume();
    notifyListenerOpened();
}
 
源代码2 项目: reacteu-app   文件: CaptureActivity.java
@Override
protected void onResume() {
  super.onResume();

  // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
  // want to open the camera driver and measure the screen size if we're going to show the help on
  // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
  // off screen.
  cameraManager = new CameraManager(getApplication());

  viewfinderView = (ViewfinderView) findViewById(fakeR.getId("id", "viewfinder_view"));
  viewfinderView.setCameraManager(cameraManager);

  resultView = findViewById(fakeR.getId("id", "result_view"));
  statusView = (TextView) findViewById(fakeR.getId("id", "status_view"));

  handler = null;
  lastResult = null;

  resetStatusView();

  SurfaceView surfaceView = (SurfaceView) findViewById(fakeR.getId("id", "preview_view"));
  SurfaceHolder surfaceHolder = surfaceView.getHolder();
  if (hasSurface) {
    // The activity was paused but not stopped, so the surface still exists. Therefore
    // surfaceCreated() won't be called, so init the camera here.
    initCamera(surfaceHolder);
  } else {
    // Install the callback and wait for surfaceCreated() to init the camera.
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  }

  beepManager.updatePrefs();

  inactivityTimer.onResume();

  Intent intent = getIntent();

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
      && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));

  // source = IntentSource.NONE;
  source = IntentSource.NATIVE_APP_INTENT;
  decodeFormats = null;
  characterSet = null;

  if (intent != null) {

    String action = intent.getAction();
    String dataString = intent.getDataString();

    if (Intents.Scan.ACTION.equals(action)) {

      // Scan the formats the intent requested, and return the result to the calling activity.
      source = IntentSource.NATIVE_APP_INTENT;
      decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);

      if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
        int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
        int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
        if (width > 0 && height > 0) {
          cameraManager.setManualFramingRect(width, height);
        }
      }
      
      String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
      if (customPromptMessage != null) {
        statusView.setText(customPromptMessage);
      }

    } else if (dataString != null &&
               dataString.contains(PRODUCT_SEARCH_URL_PREFIX) &&
               dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {

      // Scan only products and send the result to mobile Product Search.
      source = IntentSource.PRODUCT_SEARCH_LINK;
      sourceUrl = dataString;
      decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;

    } else if (isZXingURL(dataString)) {

      // Scan formats requested in query string (all formats if none specified).
      // If a return URL is specified, send the results there. Otherwise, handle it ourselves.
      source = IntentSource.ZXING_LINK;
      sourceUrl = dataString;
      Uri inputUri = Uri.parse(sourceUrl);
      returnUrlTemplate = inputUri.getQueryParameter(RETURN_URL_PARAM);
      returnRaw = inputUri.getQueryParameter(RAW_PARAM) != null;
      decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);

    }

    characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

  }
}
 
源代码3 项目: android-apps   文件: CaptureActivity.java
@Override
protected void onResume() {
  super.onResume();

  // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
  // want to open the camera driver and measure the screen size if we're going to show the help on
  // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
  // off screen.
  cameraManager = new CameraManager(getApplication());

  viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
  viewfinderView.setCameraManager(cameraManager);

  resultView = findViewById(R.id.result_view);
  statusView = (TextView) findViewById(R.id.status_view);

  handler = null;
  lastResult = null;

  resetStatusView();

  SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
  SurfaceHolder surfaceHolder = surfaceView.getHolder();
  if (hasSurface) {
    // The activity was paused but not stopped, so the surface still exists. Therefore
    // surfaceCreated() won't be called, so init the camera here.
    initCamera(surfaceHolder);
  } else {
    // Install the callback and wait for surfaceCreated() to init the camera.
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  }

  beepManager.updatePrefs();

  inactivityTimer.onResume();

  Intent intent = getIntent();

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
      && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));

  source = IntentSource.NONE;
  decodeFormats = null;
  characterSet = null;

  if (intent != null) {

    String action = intent.getAction();
    String dataString = intent.getDataString();

    if (Intents.Scan.ACTION.equals(action)) {

      // Scan the formats the intent requested, and return the result to the calling activity.
      source = IntentSource.NATIVE_APP_INTENT;
      decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);

      if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
        int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
        int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
        if (width > 0 && height > 0) {
          cameraManager.setManualFramingRect(width, height);
        }
      }
      
      String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
      if (customPromptMessage != null) {
        statusView.setText(customPromptMessage);
      }

    } else if (dataString != null &&
               dataString.contains(PRODUCT_SEARCH_URL_PREFIX) &&
               dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {

      // Scan only products and send the result to mobile Product Search.
      source = IntentSource.PRODUCT_SEARCH_LINK;
      sourceUrl = dataString;
      decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;

    } else if (isZXingURL(dataString)) {

      // Scan formats requested in query string (all formats if none specified).
      // If a return URL is specified, send the results there. Otherwise, handle it ourselves.
      source = IntentSource.ZXING_LINK;
      sourceUrl = dataString;
      Uri inputUri = Uri.parse(sourceUrl);
      returnUrlTemplate = inputUri.getQueryParameter(RETURN_URL_PARAM);
      decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);

    }

    characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

  }
}