@Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   switch (keyCode) {
     case KeyEvent.KEYCODE_BACK:
       if (source == IntentSource.NATIVE_APP_INTENT) {
         setResult(RESULT_CANCELED);
         finish();
         return true;
       }
       if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK)
           && lastResult != null) {
         restartPreviewAfterDelay(0L);
         return true;
       }
       break;
     case KeyEvent.KEYCODE_FOCUS:
     case KeyEvent.KEYCODE_CAMERA:
       // Handle these events so they don't launch the Camera app
       return true;
       // Use volume up/down to turn on light
     case KeyEvent.KEYCODE_VOLUME_DOWN:
       cameraManager.setTorch(false);
       return true;
     case KeyEvent.KEYCODE_VOLUME_UP:
       cameraManager.setTorch(true);
       return true;
   }
   return super.onKeyDown(keyCode, event);
 }
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   switch (keyCode) {
     case KeyEvent.KEYCODE_BACK:
       if (source == IntentSource.NATIVE_APP_INTENT) {
         setResult(RESULT_CANCELED);
         AppManager.getAppManager().finishActivity(this);
         overridePendingTransition(R.anim.exit_in_from_left, R.anim.exit_out_to_right);
         return true;
       }
       if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK)
           && lastResult != null) {
         restartPreviewAfterDelay(0L);
         Logger.i("dd");
         return true;
       } else {
         AppManager.getAppManager().finishActivity(this);
         overridePendingTransition(R.anim.exit_in_from_left, R.anim.exit_out_to_right);
       }
       break;
     case KeyEvent.KEYCODE_FOCUS:
     case KeyEvent.KEYCODE_CAMERA:
       // Handle these events so they don't launch the Camera app
       return true;
       // Use volume up/down to turn on light
     case KeyEvent.KEYCODE_VOLUME_DOWN:
       cameraManager.setTorch(false);
       return true;
     case KeyEvent.KEYCODE_VOLUME_UP:
       cameraManager.setTorch(true);
       return true;
   }
   return super.onKeyDown(keyCode, event);
 }
Пример #3
0
 @Override
 public void handleButtonPress(int index) {
   if (index == 0) {
     WifiParsedResult wifiResult = (WifiParsedResult) getResult();
     WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
     if (wifiManager == null) {
       Log.w(TAG, "No WifiManager available from device");
       return;
     }
     final Activity activity = getActivity();
     activity.runOnUiThread(
         new Runnable() {
           @Override
           public void run() {
             Toast.makeText(
                     activity.getApplicationContext(),
                     R.string.wifi_changing_network,
                     Toast.LENGTH_SHORT)
                 .show();
           }
         });
     new WifiConfigManager(wifiManager)
         .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, wifiResult);
     parent.restartPreviewAfterDelay(0L);
   }
 }
Пример #4
0
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK) {
     if (source == IntentSource.NATIVE_APP_INTENT) {
       setResult(RESULT_CANCELED);
       finish();
       return true;
     } else if ((source == IntentSource.NONE || source == IntentSource.ZXING_LINK)
         && lastResult != null) {
       restartPreviewAfterDelay(0L);
       return true;
     }
   } else if (keyCode == KeyEvent.KEYCODE_FOCUS || keyCode == KeyEvent.KEYCODE_CAMERA) {
     // Handle these events so they don't launch the Camera app
     return true;
   }
   return super.onKeyDown(keyCode, event);
 }
Пример #5
0
  /**
   * A valid barcode has been found, so give an indication of success and show the results.
   *
   * @param rawResult The contents of the barcode.
   * @param scaleFactor amount by which thumbnail was scaled
   * @param barcode A greyscale bitmap of the camera data which was decoded.
   */
  public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
    inactivityTimer.onActivity();
    lastResult = rawResult;
    ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(this, rawResult);

    boolean fromLiveScan = barcode != null;
    if (fromLiveScan) {
      historyManager.addHistoryItem(rawResult, resultHandler);
      // Then not from history, so beep/vibrate and we have an image to draw on
      beepManager.playBeepSoundAndVibrate();
      drawResultPoints(barcode, scaleFactor, rawResult);
    }

    switch (source) {
      case NATIVE_APP_INTENT:
      case PRODUCT_SEARCH_LINK:
        handleDecodeExternally(rawResult, resultHandler, barcode);
        break;
      case ZXING_LINK:
        if (scanFromWebPageManager == null || !scanFromWebPageManager.isScanFromWebPage()) {
          handleDecodeInternally(rawResult, resultHandler, barcode);
        } else {
          handleDecodeExternally(rawResult, resultHandler, barcode);
        }
        break;
      case NONE:
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        if (fromLiveScan && prefs.getBoolean(PreferencesActivity.KEY_BULK_MODE, false)) {
          Toast.makeText(
                  getApplicationContext(),
                  getResources().getString(R.string.msg_bulk_mode_scanned)
                      + " ("
                      + rawResult.getText()
                      + ')',
                  Toast.LENGTH_SHORT)
              .show();
          // Wait a moment or else it will scan the same barcode continuously about 3 times
          restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
        } else {
          handleDecodeInternally(rawResult, resultHandler, barcode);
        }
        break;
    }
  }
Пример #6
0
  /**
   * A valid barcode has been found, so give an indication of success and show the results.
   *
   * @param rawResult The contents of the barcode.
   * @param barcode A greyscale bitmap of the camera data which was decoded.
   */
  public void handleDecode(Result rawResult, Bitmap barcode) {
    inactivityTimer.onActivity();
    lastResult = rawResult;
    ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(this, rawResult);
    historyManager.addHistoryItem(rawResult, resultHandler);

    if (barcode == null) {
      // This is from history -- no saved barcode
      handleDecodeInternally(rawResult, resultHandler, null);
    } else {
      beepManager.playBeepSoundAndVibrate();
      drawResultPoints(barcode, rawResult);
      switch (source) {
        case NATIVE_APP_INTENT:
        case PRODUCT_SEARCH_LINK:
          handleDecodeExternally(rawResult, resultHandler, barcode);
          break;
        case ZXING_LINK:
          if (returnUrlTemplate == null) {
            handleDecodeInternally(rawResult, resultHandler, barcode);
          } else {
            handleDecodeExternally(rawResult, resultHandler, barcode);
          }
          break;
        case NONE:
          SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
          if (prefs.getBoolean(PreferencesActivity.KEY_BULK_MODE, false)) {
            Toast.makeText(this, R.string.msg_bulk_mode_scanned, Toast.LENGTH_SHORT).show();
            // Wait a moment or else it will scan the same barcode continuously about 3 times
            restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
          } else {
            handleDecodeInternally(rawResult, resultHandler, barcode);
          }
          break;
      }
    }
  }