@Override protected void onResume() { LanguageUtils.setLanguage(Config.LANGUAGE, this); super.onResume(); mRecognizerView.resume(); mMediaPlayer = MediaPlayer.create(this, R.raw.beep); }
@Override protected void onCreate(Bundle savedInstanceState) { LanguageUtils.setLanguage(Config.LANGUAGE, this); super.onCreate(savedInstanceState); // create recognizer view mRecognizerView = new RecognizerView(this); /* * Prepare settings for recognition. */ RecognizerSettings[] settArray = Config.getRecognizerSettings(); if (settArray != null) { mRecognizerView.setRecognitionSettings(settArray); } /* add license that allows creating custom camera overlay - obtain your key at * https://microblink.com/idscan */ try { mRecognizerView.setLicenseKey( "UF57DWJN-MCIEASQR-3FUVQU2V-WQ2YBMT4-SH4UTH2I-Z6MDB6FO-36NHEV7P-CZYI7I5N"); // demo // license key // for package // com.microblink.blinkid } catch (InvalidLicenceKeyException e) { e.printStackTrace(); Log.e(TAG, "Invalid licence key!"); Toast.makeText(this, "Invalid licence key!", Toast.LENGTH_SHORT).show(); finish(); } // scan result listener will be notified when scan result gets available mRecognizerView.setScanResultListener(this); // camera events listener receives events such as when camera preview has started // or there was an error while starting the camera mRecognizerView.setCameraEventsListener(this); // orientation allowed listener is asked if orientation is allowed when device orientation // changes - if orientation is allowed, rotatable views will be rotated to that orientation mRecognizerView.setOrientationAllowedListener(this); // on size changed listener is notified whenever the size of the view is changed (for example // when transforming the view from portrait to landscape or vice versa) mRecognizerView.setOnSizeChangedListener(this); // recognizer view events listener gets notified when recognizer did not detect anything // or has detected an object represented with quadrilateral or points of interest // it also gets notified when camera cannot perform focusing mRecognizerView.setRecognizerViewEventListener(this); // orientation change listener is notified when device orientation changes, regardless // of underlying activity's configuration settings mRecognizerView.setOrientationChangeListener(this); // set initial orientation if (Config.IS_LANDSCAPE) { mRecognizerView.setInitialOrientation(Orientation.ORIENTATION_LANDSCAPE_RIGHT); } else { mRecognizerView.setInitialOrientation(Orientation.ORIENTATION_PORTRAIT); } // initialize QuadView mQuadView = new QuadView( this, null, new IdQuadDrawer(new IdQuadTransformer(0.45f, Orientation.ORIENTATION_PORTRAIT)), 0.0, 0.6, mRecognizerView.getHostScreenOrientation()); mQuadView.setMovable(Config.VIEWFINDER_MOVEABLE); // add quadView to BlinkIdView as non-rotatable (fixed) view mRecognizerView.addChildView(mQuadView, false); // initialize buttons and status view View view = getLayoutInflater().inflate(R.layout.default_photopay_viewfinder, null); /** setup back button */ mBackButton = (Button) view.findViewById(R.id.defaultBackButton); mBackButton.setText(getString(R.string.photopayHome)); mBackButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { setResult(Activity.RESULT_CANCELED); finish(); } }); mTorchButton = (Button) view.findViewById(R.id.defaultTorchButton); mTorchButton.setVisibility(View.GONE); mStatusTextView = (TextView) view.findViewById(R.id.defaultStatusTextView); // hide status text mStatusTextView.setVisibility(View.INVISIBLE); // you need to pass all activity's lifecycle methods to RecognizerView // make sure you've called create after you've set all settings to RecognizerView mRecognizerView.create(); setContentView(mRecognizerView); // add buttons and status view as rotatable view to BlinkIdView (it will be rotated even if // activity remains in portrait/landscape) // allowed orientations are controlled via OrientationAllowedListener mRecognizerView.addChildView(view, true); }