@Override public void onResume() { super.onResume(); // - Display camera preview. displayCameraPreview(); // - Snack to enable internet if not. if (!AndroidUtils.isDataEnabled(getActivity())) { AndroidUtils.snackEnableData(getActivity(), getView()); } }
@Click(R.id.snapButton) protected void onSnapButtonClicked(final View view) { // - Analyze bitmap if internet is enabled. if (AndroidUtils.isDataEnabled(getActivity())) { mSnapButton.setEnabled(false); new AnalyzeAndSearchAsyncTask( getActivity(), mCropper.getActualCropRect(), webView, analyzeAndSearchAsyncTaskCallBack) .execute(mTextureView.getBitmap()); } else { AndroidUtils.snackEnableData(getActivity(), getView()); } }
/** Initialize and display camera preview with good ratio. */ private void displayCameraPreview() { try { // - Initialize camera. initializeCamera(); // - Initialize preview when the texture view is available AndroidUtils.getSurfaceTexture( mTextureView, (surfaceTexture) -> { initializePreview(surfaceTexture); }); } catch (final Throwable cause) { // - An exception may be thrown when camera is unavailable. displayCameraError(cause); } }