public void onBtnExitClicked(View v) { finish(); }
@Override public void onOperationDone(boolean success) { if (success) { mTorchOn = !mTorchOn; runOnUiThread(new Runnable() { @Override public void run() { if (mTorchOn) { mFlashButton.setImageResource(R.drawable.flashlight_inverse); } else { mFlashButton.setImageResource(R.drawable.flashlight); } } }); } } });
public void onBtnHelpClicked(View v) { Intent intent = new Intent(this, HelpActivity.class); startActivity(intent); }
super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_scan); mRecognizerView = findViewById(R.id.rec_view); mFlashButton = findViewById(R.id.btnFlash); mResultView = findViewById(R.id.layResult); mMessage = findViewById(R.id.txtMessage); mResult = findViewById(R.id.txtResult); mTitleIndicator = findViewById(R.id.indicator); ViewPager viewPager = findViewById(R.id.viewpager); viewPager.setAdapter(new SamplePagerAdapter()); mTitleIndicator = findViewById(R.id.indicator); mTitleIndicator.setViewPager(viewPager); mRecognizerView.setRecognizerBundle(createRecognizerBundle(mParserGroupProcessor)); if (v != null) { ViewGroup vg = findViewById(R.id.custom_segment_scan_root); vg.addView(v); updateUI(false);
public void onBtnAcceptClicked(View v) { // do something with data from mResult mSelectedElement = (mSelectedElement + 1) % mFieldByFieldElements.length; mResultView.setVisibility(View.INVISIBLE); updateUI(true); }
/** * Return the title of the item at {@code position}. This is important as what this method * returns is what is displayed in the {@link SlidingTabLayout}. * <p> * Here we construct one using the position value, but for real application the title should * refer to the item's contents. */ @Override public CharSequence getPageTitle(int position) { return getResources().getString(mFieldByFieldElements[position].getTitleResource()); } /**
/** * Updates user interface based on currently selected configuration. Also updates the * recognizers configuration if {@code updateRecognizerSettings} is set to {@code true}. * @param updateRecognizerSettings Indicates whether the recognizers reconfiguration * will be performed, based on current settings. */ private void updateUI(boolean updateRecognizerSettings) { mMessage.setText(mFieldByFieldElements[mSelectedElement].getTextResource()); mTitleIndicator.getViewPager().setCurrentItem(mSelectedElement); if (updateRecognizerSettings) { FieldByFieldElement scanElement = mFieldByFieldElements[mSelectedElement]; Parser currentParser = scanElement.getParser(); mParserGroupProcessor = new ParserGroupProcessor(currentParser); // unlike setRecognitionSettings that needs to be set before calling create, reconfigureRecognizers is designed // to be called while recognizer is active. mRecognizerView.reconfigureRecognizers(createRecognizerBundle(mParserGroupProcessor)); } }
@Override public void onClick(DialogInterface dialog, int which) { if(dialog != null) dialog.dismiss(); finish(); } }).create().show();
@Override public void onScanningDone(@NonNull RecognitionSuccessType recognitionSuccessType) { if (recognitionSuccessType == RecognitionSuccessType.UNSUCCESSFUL) { // ignore event if nothing has been scanned return; } FieldByFieldElement scanElement = mFieldByFieldElements[mSelectedElement]; // obtain result of the currently active parser Parser.Result<?> parserResult = scanElement.getParser().getResult(); if (parserResult.getResultState() == Parser.Result.State.Valid) { final String resultString = parserResult.toString().trim(); runOnUiThread(new Runnable() { @Override public void run() { mResult.setText(resultString); mResultView.setVisibility(View.VISIBLE); } }); // additionally if you want to process raw OCR result instead of parsed strings, and // your license key allows obtaining of the OCR result, you can obtain it like this: // OcrResult ocrResult = mParserGroupProcessor.getResult().getOcrResult(); } // Finally, scanning will be resumed automatically and will reuse // results from previous scan to make current scan of better quality. // Note that preserving state preserves state of all // recognizers, including barcode recognizers (if enabled). // If you want to reset internal state call: // mRecognizerRunnerView.resetRecognitionState(); }
@Override public void onError(Throwable ex) { // This method will be called when opening of camera resulted in exception or // recognition process encountered an error. // The error details will be given in exc parameter. Log.e(this, ex, "Error"); AlertDialog.Builder ab = new AlertDialog.Builder(this); ab.setCancelable(false) .setTitle("Error") .setMessage(ex.getMessage()) .setNeutralButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if(dialog != null) dialog.dismiss(); finish(); } }).create().show(); finish(); }