com.google.zxing.client.android.PreferencesActivity#com.google.zxing.client.android.result.ResultHandler源码实例Demo

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

/**
 * 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) {
  lastResult = rawResult;
  ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(this, rawResult);

  boolean fromLiveScan = barcode != null;
  if (fromLiveScan) {
    drawResultPoints(barcode, rawResult);
  }

  switch (source) {
    case NATIVE_APP_INTENT:
    case PRODUCT_SEARCH_LINK:
      handleDecodeExternally(rawResult, resultHandler, barcode);
      break;
    case NONE:
      if (fromLiveScan) {
        String message = " (bulk scan)";
        Toast.makeText(this, message, 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 {
      }
      break;
  }
}
 
/**
 * 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;
  }
}
 
String buildReplyURL(Result rawResult, ResultHandler resultHandler) {
  String result = returnUrlTemplate;
  result = replace(CODE_PLACEHOLDER,
                   returnRaw ? rawResult.getText() : resultHandler.getDisplayContents(), result);
  result = replace(RAW_CODE_PLACEHOLDER, rawResult.getText(), result);
  result = replace(FORMAT_PLACEHOLDER, rawResult.getBarcodeFormat().toString(), result);
  result = replace(TYPE_PLACEHOLDER, resultHandler.getType().toString(), result);
  result = replace(META_PLACEHOLDER, String.valueOf(rawResult.getResultMetadata()), result);
  return result;
}
 
源代码4 项目: ZXing-Standalone-library   文件: HistoryManager.java
public void addHistoryItem(Result result, ResultHandler handler) {
  // Do not save this item to the history if the preference is turned off, or the contents are
  // considered secure.
  if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
      handler.areContentsSecure() || !enableHistory) {
    return;
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
  if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
    deletePrevious(result.getText());
  }

  ContentValues values = new ContentValues();
  values.put(DBHelper.TEXT_COL, result.getText());
  values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
  values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
  values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());

  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  try {
    db = helper.getWritableDatabase();      
    // Insert the new entry into the DB.
    db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
  } finally {
    close(null, db);
  }
}
 
String buildReplyURL(Result rawResult, ResultHandler resultHandler) {
  String result = returnUrlTemplate;
  result = replace(CODE_PLACEHOLDER,
                   returnRaw ? rawResult.getText() : resultHandler.getDisplayContents(), result);
  result = replace(RAW_CODE_PLACEHOLDER, rawResult.getText(), result);
  result = replace(FORMAT_PLACEHOLDER, rawResult.getBarcodeFormat().toString(), result);
  result = replace(TYPE_PLACEHOLDER, resultHandler.getType().toString(), result);
  result = replace(META_PLACEHOLDER, String.valueOf(rawResult.getResultMetadata()), result);
  return result;
}
 
public void addHistoryItem(Result result, ResultHandler handler) {
  // Do not save this item to the history if the preference is turned off, or the contents are
  // considered secure.
  if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
      handler.areContentsSecure() || !enableHistory) {
    return;
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
  if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
    deletePrevious(result.getText());
  }

  ContentValues values = new ContentValues();
  values.put(DBHelper.TEXT_COL, result.getText());
  values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
  values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
  values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());

  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  try {
    db = helper.getWritableDatabase();      
    // Insert the new entry into the DB.
    db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
  } finally {
    close(null, db);
  }
}
 
源代码7 项目: weex   文件: ScanFromWebPageManager.java
String buildReplyURL(Result rawResult, ResultHandler resultHandler) {
  String result = returnUrlTemplate;
  result = replace(CODE_PLACEHOLDER,
                   returnRaw ? rawResult.getText() : resultHandler.getDisplayContents(), result);
  result = replace(RAW_CODE_PLACEHOLDER, rawResult.getText(), result);
  result = replace(FORMAT_PLACEHOLDER, rawResult.getBarcodeFormat().toString(), result);
  result = replace(TYPE_PLACEHOLDER, resultHandler.getType().toString(), result);
  result = replace(META_PLACEHOLDER, String.valueOf(rawResult.getResultMetadata()), result);
  return result;
}
 
源代码8 项目: weex   文件: HistoryManager.java
public void addHistoryItem(Result result, ResultHandler handler) {
  // Do not save this item to the history if the preference is turned off, or the contents are
  // considered secure.
  if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
      handler.areContentsSecure() || !enableHistory) {
    return;
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
  if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
    deletePrevious(result.getText());
  }

  ContentValues values = new ContentValues();
  values.put(DBHelper.TEXT_COL, result.getText());
  values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
  values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
  values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());

  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  try {
    db = helper.getWritableDatabase();      
    // Insert the new entry into the DB.
    db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
  } finally {
    close(null, db);
  }
}
 
源代码9 项目: Study_Android_Demo   文件: CaptureActivity.java
/**
 * 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;
  }
}
 
String buildReplyURL(Result rawResult, ResultHandler resultHandler) {
  String result = returnUrlTemplate;
  result = replace(CODE_PLACEHOLDER,
                   returnRaw ? rawResult.getText() : resultHandler.getDisplayContents(), result);
  result = replace(RAW_CODE_PLACEHOLDER, rawResult.getText(), result);
  result = replace(FORMAT_PLACEHOLDER, rawResult.getBarcodeFormat().toString(), result);
  result = replace(TYPE_PLACEHOLDER, resultHandler.getType().toString(), result);
  result = replace(META_PLACEHOLDER, String.valueOf(rawResult.getResultMetadata()), result);
  return result;
}
 
源代码11 项目: Study_Android_Demo   文件: HistoryManager.java
public void addHistoryItem(Result result, ResultHandler handler) {
  // Do not save this item to the history if the preference is turned off, or the contents are
  // considered secure.
  if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
      handler.areContentsSecure() || !enableHistory) {
    return;
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
  if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
    deletePrevious(result.getText());
  }

  ContentValues values = new ContentValues();
  values.put(DBHelper.TEXT_COL, result.getText());
  values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
  values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
  values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());

  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  try {
    db = helper.getWritableDatabase();      
    // Insert the new entry into the DB.
    db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
  } finally {
    close(null, db);
  }
}
 
String buildReplyURL(Result rawResult, ResultHandler resultHandler) {
  String result = returnUrlTemplate;
  result = replace(CODE_PLACEHOLDER,
                   returnRaw ? rawResult.getText() : resultHandler.getDisplayContents(), result);
  result = replace(RAW_CODE_PLACEHOLDER, rawResult.getText(), result);
  result = replace(FORMAT_PLACEHOLDER, rawResult.getBarcodeFormat().toString(), result);
  result = replace(TYPE_PLACEHOLDER, resultHandler.getType().toString(), result);
  result = replace(META_PLACEHOLDER, String.valueOf(rawResult.getResultMetadata()), result);
  return result;
}
 
源代码13 项目: barcodescanner-lib-aar   文件: HistoryManager.java
public void addHistoryItem(Result result, ResultHandler handler) {
  // Do not save this item to the history if the preference is turned off, or the contents are
  // considered secure.
  if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
      handler.areContentsSecure() || !enableHistory) {
    return;
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
  if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
    deletePrevious(result.getText());
  }

  ContentValues values = new ContentValues();
  values.put(DBHelper.TEXT_COL, result.getText());
  values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
  values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
  values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());

  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  try {
    db = helper.getWritableDatabase();      
    // Insert the new entry into the DB.
    db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
  } finally {
    close(null, db);
  }
}
 
源代码14 项目: reacteu-app   文件: CaptureActivity.java
/**
 * 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);

  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, 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 (fromLiveScan && prefs.getBoolean(PreferencesActivity.KEY_BULK_MODE, false)) {
        String message = getResources().getString(fakeR.getId("string", "msg_bulk_mode_scanned"))
            + " (" + rawResult.getText() + ')';
        Toast.makeText(this, message, 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;
  }
}
 
源代码15 项目: reacteu-app   文件: HistoryManager.java
public void addHistoryItem(Result result, ResultHandler handler) {
  // Do not save this item to the history if the preference is turned off, or the contents are
  // considered secure.
  if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
      handler.areContentsSecure()) {
    return;
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
  if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
    deletePrevious(result.getText());
  }

  ContentValues values = new ContentValues();
  values.put(DBHelper.TEXT_COL, result.getText());
  values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
  values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
  values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());

  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  try {
    db = helper.getWritableDatabase();      
    // Insert the new entry into the DB.
    db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
  } finally {
    close(null, db);
  }
}
 
源代码16 项目: android-apps   文件: CaptureActivity.java
/**
 * 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;
    }
  }
}
 
源代码17 项目: android-apps   文件: HistoryManager.java
public void addHistoryItem(Result result, ResultHandler handler) {
  // Do not save this item to the history if the preference is turned off, or the contents are
  // considered secure.
  if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
      handler.areContentsSecure()) {
    return;
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
  if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
    deletePrevious(result.getText());
  }

  ContentValues values = new ContentValues();
  values.put(DBHelper.TEXT_COL, result.getText());
  values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
  values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
  values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());

  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  try {
    db = helper.getWritableDatabase();      
    // Insert the new entry into the DB.
    db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
  } finally {
    close(null, db);
  }
}
 
源代码18 项目: zxingfragmentlib   文件: ScanFromWebPageManager.java
String buildReplyURL(Result rawResult, ResultHandler resultHandler) {
  String result = returnUrlTemplate;
  result = replace(CODE_PLACEHOLDER,
                   returnRaw ? rawResult.getText() : resultHandler.getDisplayContents(), result);
  result = replace(RAW_CODE_PLACEHOLDER, rawResult.getText(), result);
  result = replace(FORMAT_PLACEHOLDER, rawResult.getBarcodeFormat().toString(), result);
  result = replace(TYPE_PLACEHOLDER, resultHandler.getType().toString(), result);
  result = replace(META_PLACEHOLDER, String.valueOf(rawResult.getResultMetadata()), result);
  return result;
}
 
源代码19 项目: zxingfragmentlib   文件: HistoryManager.java
public void addHistoryItem(Result result, ResultHandler handler) {
  // Do not save this item to the history if the preference is turned off, or the contents are
  // considered secure.
  if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
      handler.areContentsSecure()) {
    return;
  }

  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
  if (!prefs.getBoolean(PreferencesActivity.KEY_REMEMBER_DUPLICATES, false)) {
    deletePrevious(result.getText());
  }

  ContentValues values = new ContentValues();
  values.put(DBHelper.TEXT_COL, result.getText());
  values.put(DBHelper.FORMAT_COL, result.getBarcodeFormat().toString());
  values.put(DBHelper.DISPLAY_COL, handler.getDisplayContents().toString());
  values.put(DBHelper.TIMESTAMP_COL, System.currentTimeMillis());

  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  try {
    db = helper.getWritableDatabase();      
    // Insert the new entry into the DB.
    db.insert(DBHelper.TABLE_NAME, DBHelper.TIMESTAMP_COL, values);
  } finally {
    close(null, db);
  }
}
 
private void handleDecodeExternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    if (barcode != null) {
      viewfinderView.drawResultBitmap(barcode);
    }

    long resultDurationMS;
    if (getIntent() == null) {
      resultDurationMS = DEFAULT_INTENT_RESULT_DURATION_MS;
    } else {
      resultDurationMS = getIntent().getLongExtra(Intents.Scan.RESULT_DISPLAY_DURATION_MS,
                                                  DEFAULT_INTENT_RESULT_DURATION_MS);
    }

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
      ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
      CharSequence text = resultHandler.getDisplayContents();
      if (text != null) {
        clipboard.setText(text);
      }
    }

    if (source == IntentSource.NATIVE_APP_INTENT) {
      
      // Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when
      // the deprecated intent is retired.
      Intent intent = new Intent(getIntent().getAction());
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      intent.putExtra(Intents.Scan.RESULT, rawResult.toString());
      intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
      byte[] rawBytes = rawResult.getRawBytes();
      if (rawBytes != null && rawBytes.length > 0) {
        intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
      }
      Map<ResultMetadataType,?> metadata = rawResult.getResultMetadata();
      if (metadata != null) {
        if (metadata.containsKey(ResultMetadataType.UPC_EAN_EXTENSION)) {
          intent.putExtra(Intents.Scan.RESULT_UPC_EAN_EXTENSION,
                          metadata.get(ResultMetadataType.UPC_EAN_EXTENSION).toString());
        }
        Integer orientation = (Integer) metadata.get(ResultMetadataType.ORIENTATION);
        if (orientation != null) {
          intent.putExtra(Intents.Scan.RESULT_ORIENTATION, orientation.intValue());
        }
        String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
        if (ecLevel != null) {
          intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, ecLevel);
        }
        Iterable<byte[]> byteSegments = (Iterable<byte[]>) metadata.get(ResultMetadataType.BYTE_SEGMENTS);
        if (byteSegments != null) {
          int i = 0;
          for (byte[] byteSegment : byteSegments) {
            intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, byteSegment);
            i++;
          }
        }
      }
      sendReplyMessage(Constants.return_scan_result, intent, resultDurationMS);
    }
  }
 
源代码21 项目: ZXing-Standalone-library   文件: CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    CharSequence displayContents = resultHandler.getDisplayContents();

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
      ClipboardInterface.setText(displayContents, this);
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
      resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
      return;
    }

    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
      barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(),
          R.drawable.launcher_icon));
    } else {
      barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));


    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType,Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
      StringBuilder metadataText = new StringBuilder(20);
      for (Map.Entry<ResultMetadataType,Object> entry : metadata.entrySet()) {
        if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
          metadataText.append(entry.getValue()).append('\n');
        }
      }
      if (metadataText.length() > 0) {
        metadataText.setLength(metadataText.length() - 1);
        metaTextView.setText(metadataText);
        metaTextView.setVisibility(View.VISIBLE);
        metaTextViewLabel.setVisibility(View.VISIBLE);
      }
    }

    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
        PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
      SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
                                                     resultHandler.getResult(),
                                                     historyManager,
                                                     this);
    }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
      TextView button = (TextView) buttonView.getChildAt(x);
      if (x < buttonCount) {
        button.setVisibility(View.VISIBLE);
        button.setText(resultHandler.getButtonText(x));
        button.setOnClickListener(new ResultButtonListener(resultHandler, x));
      } else {
        button.setVisibility(View.GONE);
      }
    }

  }
 
/**
 * 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;
	}
}
 
源代码23 项目: weex   文件: CaptureActivity.java
/**
 * 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;
	}
}
 
源代码24 项目: Study_Android_Demo   文件: CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    CharSequence displayContents = resultHandler.getDisplayContents();

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
      ClipboardInterface.setText(displayContents, this);
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
      resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
      return;
    }

    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
      barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(),
          R.drawable.launcher_icon));
    } else {
      barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));


    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType,Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
      StringBuilder metadataText = new StringBuilder(20);
      for (Map.Entry<ResultMetadataType,Object> entry : metadata.entrySet()) {
        if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
          metadataText.append(entry.getValue()).append('\n');
        }
      }
      if (metadataText.length() > 0) {
        metadataText.setLength(metadataText.length() - 1);
        metaTextView.setText(metadataText);
        metaTextView.setVisibility(View.VISIBLE);
        metaTextViewLabel.setVisibility(View.VISIBLE);
      }
    }

    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
        PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
      SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
                                                     resultHandler.getResult(),
                                                     historyManager,
                                                     this);
    }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
      TextView button = (TextView) buttonView.getChildAt(x);
      if (x < buttonCount) {
        button.setVisibility(View.VISIBLE);
        button.setText(resultHandler.getButtonText(x));
        button.setOnClickListener(new ResultButtonListener(resultHandler, x));
      } else {
        button.setVisibility(View.GONE);
      }
    }

  }
 
源代码25 项目: barcodescanner-lib-aar   文件: CaptureActivity.java
/**
 * 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
    if (beepOnScan) {
      beepManager.playBeepSoundAndVibrate();
    }
    drawResultPoints(barcode, scaleFactor, rawResult);
  }

  switch (source) {
    case NATIVE_APP_INTENT:
    case PRODUCT_SEARCH_LINK:
      if (fromLiveScan && getIntent().getBooleanExtra(Intents.Scan.BULK_SCAN, false)) {

        Intent intermediateResult = new Intent("bulk-barcode-result");
        intermediateResult.putExtra(Intents.Scan.RESULT, rawResult.toString());
        intermediateResult.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
        LocalBroadcastManager.getInstance(this).sendBroadcast(intermediateResult);

        restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
      } else {
        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;
  }
}
 
源代码26 项目: barcodescanner-lib-aar   文件: CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    CharSequence displayContents = resultHandler.getDisplayContents();

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
      ClipboardInterface.setText(displayContents, this);
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (resultHandler.getDefaultButtonID() != null && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
      resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
      return;
    }

    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
      barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(),
          R.drawable.launcher_icon));
    } else {
      barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));


    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType,Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
      StringBuilder metadataText = new StringBuilder(20);
      for (Map.Entry<ResultMetadataType,Object> entry : metadata.entrySet()) {
        if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
          metadataText.append(entry.getValue()).append('\n');
        }
      }
      if (metadataText.length() > 0) {
        metadataText.setLength(metadataText.length() - 1);
        metaTextView.setText(metadataText);
        metaTextView.setVisibility(View.VISIBLE);
        metaTextViewLabel.setVisibility(View.VISIBLE);
      }
    }

    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
        PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
      SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
                                                     resultHandler.getResult(),
                                                     historyManager,
                                                     this);
    }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
      TextView button = (TextView) buttonView.getChildAt(x);
      if (x < buttonCount) {
        button.setVisibility(View.VISIBLE);
        button.setText(resultHandler.getButtonText(x));
        button.setOnClickListener(new ResultButtonListener(resultHandler, x));
      } else {
        button.setVisibility(View.GONE);
      }
    }

  }
 
源代码27 项目: reacteu-app   文件: CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
  statusView.setVisibility(View.GONE);
  viewfinderView.setVisibility(View.GONE);
  resultView.setVisibility(View.VISIBLE);

  ImageView barcodeImageView = (ImageView) findViewById(fakeR.getId("id", "barcode_image_view"));
  if (barcode == null) {
    barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(),
        fakeR.getId("drawable", "launcher_icon")));
  } else {
    barcodeImageView.setImageBitmap(barcode);
  }

  TextView formatTextView = (TextView) findViewById(fakeR.getId("id", "format_text_view"));
  formatTextView.setText(rawResult.getBarcodeFormat().toString());

  TextView typeTextView = (TextView) findViewById(fakeR.getId("id", "type_text_view"));
  typeTextView.setText(resultHandler.getType().toString());

  DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
  String formattedTime = formatter.format(new Date(rawResult.getTimestamp()));
  TextView timeTextView = (TextView) findViewById(fakeR.getId("id", "time_text_view"));
  timeTextView.setText(formattedTime);


  TextView metaTextView = (TextView) findViewById(fakeR.getId("id", "meta_text_view"));
  View metaTextViewLabel = findViewById(fakeR.getId("id", "meta_text_view_label"));
  metaTextView.setVisibility(View.GONE);
  metaTextViewLabel.setVisibility(View.GONE);
  Map<ResultMetadataType,Object> metadata = rawResult.getResultMetadata();
  if (metadata != null) {
    StringBuilder metadataText = new StringBuilder(20);
    for (Map.Entry<ResultMetadataType,Object> entry : metadata.entrySet()) {
      if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
        metadataText.append(entry.getValue()).append('\n');
      }
    }
    if (metadataText.length() > 0) {
      metadataText.setLength(metadataText.length() - 1);
      metaTextView.setText(metadataText);
      metaTextView.setVisibility(View.VISIBLE);
      metaTextViewLabel.setVisibility(View.VISIBLE);
    }
  }

  TextView contentsTextView = (TextView) findViewById(fakeR.getId("id", "contents_text_view"));
  CharSequence displayContents = resultHandler.getDisplayContents();
  contentsTextView.setText(displayContents);
  // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
  int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
  contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

  TextView supplementTextView = (TextView) findViewById(fakeR.getId("id", "contents_supplement_text_view"));
  supplementTextView.setText("");
  supplementTextView.setOnClickListener(null);
  if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
      PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
    SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
                                                   resultHandler.getResult(),
                                                   historyManager,
                                                   this);
  }

  int buttonCount = resultHandler.getButtonCount();
  ViewGroup buttonView = (ViewGroup) findViewById(fakeR.getId("id", "result_button_view"));
  buttonView.requestFocus();
  for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
    TextView button = (TextView) buttonView.getChildAt(x);
    if (x < buttonCount) {
      button.setVisibility(View.VISIBLE);
      button.setText(resultHandler.getButtonText(x));
      button.setOnClickListener(new ResultButtonListener(resultHandler, x));
    } else {
      button.setVisibility(View.GONE);
    }
  }

  if (copyToClipboard && !resultHandler.areContentsSecure()) {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    if (displayContents != null) {
      clipboard.setText(displayContents);
    }
  }
}
 
源代码28 项目: android-apps   文件: CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
  statusView.setVisibility(View.GONE);
  viewfinderView.setVisibility(View.GONE);
  resultView.setVisibility(View.VISIBLE);

  ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
  if (barcode == null) {
    barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(),
        R.drawable.launcher_icon));
  } else {
    barcodeImageView.setImageBitmap(barcode);
  }

  TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
  formatTextView.setText(rawResult.getBarcodeFormat().toString());

  TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
  typeTextView.setText(resultHandler.getType().toString());

  DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
  String formattedTime = formatter.format(new Date(rawResult.getTimestamp()));
  TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
  timeTextView.setText(formattedTime);


  TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
  View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
  metaTextView.setVisibility(View.GONE);
  metaTextViewLabel.setVisibility(View.GONE);
  Map<ResultMetadataType,Object> metadata = rawResult.getResultMetadata();
  if (metadata != null) {
    StringBuilder metadataText = new StringBuilder(20);
    for (Map.Entry<ResultMetadataType,Object> entry : metadata.entrySet()) {
      if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
        metadataText.append(entry.getValue()).append('\n');
      }
    }
    if (metadataText.length() > 0) {
      metadataText.setLength(metadataText.length() - 1);
      metaTextView.setText(metadataText);
      metaTextView.setVisibility(View.VISIBLE);
      metaTextViewLabel.setVisibility(View.VISIBLE);
    }
  }

  TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
  CharSequence displayContents = resultHandler.getDisplayContents();
  contentsTextView.setText(displayContents);
  // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
  int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
  contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

  TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
  supplementTextView.setText("");
  supplementTextView.setOnClickListener(null);
  if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
      PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
    SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
                                                   resultHandler.getResult(),
                                                   handler,
                                                   historyManager,
                                                   this);
  }

  int buttonCount = resultHandler.getButtonCount();
  ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
  buttonView.requestFocus();
  for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
    TextView button = (TextView) buttonView.getChildAt(x);
    if (x < buttonCount) {
      button.setVisibility(View.VISIBLE);
      button.setText(resultHandler.getButtonText(x));
      button.setOnClickListener(new ResultButtonListener(resultHandler, x));
    } else {
      button.setVisibility(View.GONE);
    }
  }

  if (copyToClipboard && !resultHandler.areContentsSecure()) {
    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    clipboard.setText(displayContents);
  }
}