zxing源碼分析(二)decode部分,zxingdecode

來源:互聯網
上載者:User

zxing源碼分析(二)decode部分,zxingdecode
       在上一篇部落格中分析了zxing怎麼開啟網路攝影機,並且掃描結果,那麼掃描之後的資料呢,是不是就要解析了呢,那我們看一下zxing怎麼解析這個資料的。      上一篇部落格地址ZXING源碼分析(一)CAMERA部分。       首先看一下解碼涉及到的類       一、com.google.zxing.client.android.camera.PreviewCallback 實現了Camera.PreviewCallback介面,回調的方法,掃描到內容後會回調此方法       二、com.google.zxing.client.android.CaptureActivityHandler 當執行個體化開,開始調用掃描的方法,看有沒有掃描到資料       三、com.google.zxing.client.android.camera.CameraManager 定義了requestPreviewFrame方法,對Camera.PreviewCallback進行註冊       四、com.google.zxing.client.android.DecodeHandler 定義瞭解碼的handler,用來對掃描的資料進行解碼,由com.google.zxing.client.android.camera.PreviewCallback 調用       流程如下:                      由此就完成瞭解碼的操作。             在CaptureActivityHandler 得到資料後,會執行以下操作

   activity.handleDecode((Result) message.obj, barcode, scaleFactor);

  這樣子就會把得到的結果資料發送到CaptureActivity,這個時間就到了我們要顯示的時候了

 /************************************************************************   **************************** 對解析成功的資料進行處理*************   ************************************************************************/  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 {          //在UI介面顯示出來資料          handleDecodeInternally(rawResult, resultHandler, barcode);        }        break;    }  }
  handleDecodeInternally(rawResult, resultHandler, barcode)執行完這個方法,掃描後的資料就顯示到頁面上了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.