-
- All Implemented Interfaces:
-
android.content.ComponentCallbacks,android.content.ComponentCallbacks2,android.view.KeyEvent.Callback,android.view.LayoutInflater.Factory,android.view.LayoutInflater.Factory2,android.view.View.OnCreateContextMenuListener,android.view.Window.Callback,androidx.activity.OnBackPressedDispatcherOwner,androidx.activity.contextaware.ContextAware,androidx.activity.result.ActivityResultCaller,androidx.activity.result.ActivityResultRegistryOwner,androidx.appcompat.app.ActionBarDrawerToggle.DelegateProvider,androidx.appcompat.app.AppCompatCallback,androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback,androidx.core.app.ActivityCompat.RequestPermissionsRequestCodeValidator,androidx.core.app.TaskStackBuilder.SupportParentable,androidx.core.view.KeyEventDispatcher.Component,androidx.lifecycle.HasDefaultViewModelProviderFactory,androidx.lifecycle.LifecycleOwner,androidx.lifecycle.ViewModelStoreOwner,androidx.savedstate.SavedStateRegistryOwner,net.gini.android.capture.camera.CameraFragmentInterface,net.gini.android.capture.camera.CameraFragmentListener
public class CameraActivity extends AppCompatActivity implements CameraFragmentListener, CameraFragmentInterface
Screen APICameraActivityis the main entry point to the Gini Capture SDK when using the Screen API.It shows a camera preview with tap-to-focus functionality, a trigger button and an optional flash on/off button. The camera preview also shows document corner guides to which the user should align the document.
On tablets in landscape orientation the camera trigger button is shown on the right side of the screen for easier access.
If you enabled document import with setDocumentImportEnabledFileTypes then a button for importing documents is shown next to the trigger button. A hint popup is displayed the first time the Gini Capture SDK is used to inform the user about document importing.
For importing documents
READ_EXTERNAL_STORAGEpermission is required and if the permission is not granted the Gini Capture SDK will prompt the user to grant the permission. SeeCustomizing the Camera Screenon how to override the message and button titles for the rationale and on permission denial alerts.Start the
CameraActivitywith startActivityForResult to receive the extractions or a GiniCaptureError in case there was an error.The following result codes need to be handled:
- RESULT_OK - image of a document was taken, reviewed and analyzed
- RESULT_CANCELED - image of document was not taken, user canceled the Gini Capture SDK
- RESULT_ERROR - an error occured
Result extra returned by the
CameraActivity:- EXTRA_OUT_EXTRACTIONS - set when result is RESULT_OK, contains a Bundle with the extraction labels as keys and as values.
- EXTRA_OUT_ERROR - set when result is RESULT_ERROR, contains a GiniCaptureError object detailing what went wrong
If the camera could not be opened due to missing permissions, the content of the Camera Screen is replaced with a no-camera icon, a short message and an optional button. The button is shown only on Android 6.0+ and tapping the button leads the user to the Application Details page in the Settings. If these are shown on Android 5.0 and earlier means that the camera permission was not declared in your manifest.
Customizing the Camera ScreenCustomizing the look of the Camera Screen is done via overriding of app resources.
The following items are customizable:
- Document corner guides: via the color resource named
gc_camera_preview_corners - Camera trigger button: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named
gc_camera_trigger_default.pngandgc_camera_trigger_pressed.png - Document import button: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named
gc_document_import_icon.png - Document import button subtitle text: via the string resource named
gc_camera_document_import_subtitle - Document import button subtitle text style: via overriding the style named
GiniCaptureTheme.Camera.DocumentImportSubtitle.TextStyle - Document import button subtitle font: via overriding the style named
GiniCaptureTheme.Camera.DocumentImportSubtitle.TextStyleand setting an item namedgcCustomFontwith the path to the font file in yourassetsfolder - Document import hint background: via the color resource named
gc_document_import_hint_background - Document import hint close icon color: via the color resource name
gc_hint_close - Document import hint text: via the string resource named
gc_document_import_hint_text - Document import hint text size: via overriding the style named
GiniCaptureTheme.Camera.DocumentImportHint.TextStyleand setting an item namedandroid:textSizewith the desiredspsize - Document import hint text color: via the color resource name
gc_document_import_hint_text - Document import hint font: via overriding the style named
GiniCaptureTheme.Camera.DocumentImportHint.TextStyleand setting an item namedgcCustomFontwith the path to the font file in yourassetsfolder - Images stack badge text style: via overriding the style named
GiniCaptureTheme.Camera.ImageStackBadge.TextStyle - Images stack badge font: via overriding the style named
GiniCaptureTheme.Camera.ImageStackBadge.TextStyleand setting an item namedgcCustomFontwith the path to the font file in yourassetsfolder - Images stack badge background colors: via the color resources named
gc_camera_image_stack_badge_backgroundandgc_camera_image_stack_badge_background_border - Images stack badge background size: via the dimension resource named
gc_camera_image_stack_badge_size - Images stack subtitle text: via the string resource named
gc_camera_image_stack_subtitle - Images stack subtitle text style: via overriding the style named
GiniCaptureTheme.Camera.ImageStackSubtitle.TextStyle - Images stack subtitle font: via overriding the style named
GiniCaptureTheme.Camera.ImageStackSubtitle.TextStyleand setting an item namedgcCustomFontwith the path to the font file in yourassetsfolder - Multi-page document page limit exceeded alert message: via the string resource named
gc_document_error_too_many_pages - Multi-page document page limit exceeded alert positive button text: via the string resource named
gc_document_error_multi_page_limit_review_pages_button - Multi-page document page limit exceeded alert cancel button text: via the string resource named
gc_document_error_multi_page_limit_cancel_button - Read storage permission denied button color: via the color resource named
gc_accent - QRCode detected popup background: via the color resource named
gc_qrcode_detected_popup_background - QRCode detected popup texts: via the string resources named
gc_qrcode_detected_popup_message_1andgc_qrcode_detected_popup_message_2 - QRCode detected popup text sizes: via overriding the styles named
GiniCaptureTheme.Camera.QRCodeDetectedPopup.Message1.TextStyleandGiniCaptureTheme.Camera.QRCodeDetectedPopup.Message2.TextStyleand setting an item namedandroid:textSizewith the desiredspsize - QRCode detected popup text colors: via the color resource name
gc_qrcode_detected_popup_message_1andgc_qrcode_detected_popup_message_2 - QRCode detected popup fonts: via overriding the styles named
GiniCaptureTheme.Camera.QRCodeDetectedPopup.Message1.TextStyleandGiniCaptureTheme.Camera.QRCodeDetectedPopup.Message2.TextStyleand setting an item namedgcCustomFontwith the path to the font file in yourassetsfolder - Read storage permission rationale text: via the string resource named
gc_storage_permission_rationale - Read storage permission rationale positive button text: via the string resource named
gc_storage_permission_rationale_positive_button - Read storage permission rationale negative button text: via the string resource named
gc_storage_permission_rationale_negative_button - Read storage permission rationale button color: via the color resource named
gc_accent - Read storage permission denied text: via the string resource named
gc_storage_permission_denied - Read storage permission denied positive button text: via the string resource named
gc_storage_permission_denied_positive_button - Read storage permission denied negative button text: via the string resource named
gc_storage_permission_denied_negative_button - Read storage permission denied button color: via the color resource named
gc_accent - Tap-to-focus indicator: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named
gc_camera_focus_indicator.png - Help menu item icon: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named
gc_help_icon.png - Onboarding menu item title: via the string resource named
gc_show_onboarding - Background color: via the color resource named
gc_background. Note: this color resource is global to all Activities (CameraActivity, , ReviewActivity, AnalysisActivity) - No-camera icon: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named
gc_no_camera.png - No camera permission text: via the string resource named
gc_camera_error_no_permission - No camera permission text color: via the color resource named
gc_camera_error_no_permission - No camera permission font: via overriding the style named
GiniCaptureTheme.Camera.Error.NoPermission.TextStyleand setting an item namedgcCustomFontwith the path to the font file in yourassetsfolder - No camera permission text style: via overriding the style named
GiniCaptureTheme.Camera.Error.NoPermission.TextStyleand setting an item namedandroid:textStyletonormal,boldoritalic - No camera permission text size: via overriding the style named
GiniCaptureTheme.Camera.Error.NoPermission.TextStyleand setting an item namedandroid:textSizeto the desiredspsize - No camera permission button title: via the string resource named
gc_camera_error_no_permission_button_title - No camera permission button title color: via the color resources named
gc_camera_error_no_permission_button_titleandgc_camera_error_no_permission_button_title_pressed - No camera permission button font: via overriding the style named
GiniCaptureTheme.Camera.Error.NoPermission.Button.TextStyleand setting an item namedgcCustomFontwith the path to the font file in yourassetsfolder - No camera permission button text style: via overriding the style named
GiniCaptureTheme.Camera.Error.NoPermission.Button.TextStyleand setting an item namedandroid:textStyletonormal,boldoritalic - No camera permission button text size: via overriding the style named
GiniCaptureTheme.Camera.Error.NoPermission.Button.TextStyleand setting an item namedandroid:textSizeto the desiredspsize
Important: All overriden styles must have their respective
Customizing the Action BarRoot.prefixed style as their parent. Ex.: the parent ofGiniCaptureTheme.Camera.Error.NoPermission.TextStylemust beRoot.GiniCaptureTheme.Camera.Error.NoPermission.TextStyle.Customizing the Action Bar is also done via overriding of app resources and each one - except the title string resource - is global to all Activities (CameraActivity, , ReviewActivity, MultiPageReviewActivity, ).
The following items are customizable:
- Background color: via the color resource named
gc_action_bar(highly recommended for Android 5+: customize the status bar color viagc_status_bar) - Title: via the string resource name
gc_title_camera - Title color: via the color resource named
gc_action_bar_title - Back button: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named
gc_action_bar_back
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringEXTRA_OUT_ERRORpublic final static StringEXTRA_OUT_EXTRACTIONSpublic final static StringEXTRA_OUT_COMPOUND_EXTRACTIONSpublic final static StringEXTRA_OUT_RETURN_REASONSpublic final static intRESULT_ERROR
-
Method Summary
Modifier and Type Method Description booleanonCreateOptionsMenu(Menu menu)Internal use only. booleanonOptionsItemSelected(MenuItem item)Internal use only. voidonBackPressed()voidonDocumentAvailable(@NonNull() Document document)Called when the user has taken an image with the camera or has imported a document that passed the Gini Capture SDK's validation and any custom checks that were implemented. voidonProceedToMultiPageReviewScreen(@NonNull() GiniCaptureMultiPageDocument multiPageDocument)voidonCheckImportedDocument(@NonNull() Document document, @NonNull() CameraFragmentListener.DocumentCheckResultCallback callback)This method is invoked for imported documents to allow custom validations. voidonError(@NonNull() GiniCaptureError error)Called when an error occurred. voidonExtractionsAvailable(@NonNull() Map<String, GiniCaptureSpecificExtraction> extractions)Called after a QRCode was successfully analyzed. voidsetListener(@NonNull() CameraFragmentListener listener)Set a listener for camera events. voidshowInterface()Call this method to show the interface elements. voidhideInterface()Call this method to hide the interface elements. voidshowActivityIndicatorAndDisableInteraction()Call this method to show an activity indicator and disable user interaction. voidhideActivityIndicatorAndEnableInteraction()Call this method to hide the activity indicator and enable user interaction. voidshowError(@NonNull() String message, int duration)Call this method to show an error message to the user in the Camera Screen. -
Methods inherited from class androidx.appcompat.app.AppCompatActivity
addContentView, closeOptionsMenu, dispatchKeyEvent, findViewById, getDelegate, getDrawerToggleDelegate, getMenuInflater, getResources, getSupportActionBar, getSupportParentActivityIntent, invalidateOptionsMenu, onConfigurationChanged, onContentChanged, onCreateSupportNavigateUpTaskStack, onKeyDown, onMenuItemSelected, onMenuOpened, onPanelClosed, onPrepareSupportNavigateUpTaskStack, onSupportActionModeFinished, onSupportActionModeStarted, onSupportContentChanged, onSupportNavigateUp, onWindowStartingSupportActionMode, openOptionsMenu, setContentView, setSupportActionBar, setSupportProgress, setSupportProgressBarIndeterminate, setSupportProgressBarIndeterminateVisibility, setSupportProgressBarVisibility, setTheme, startSupportActionMode, supportInvalidateOptionsMenu, supportNavigateUpTo, supportRequestWindowFeature, supportShouldUpRecreateTask -
Methods inherited from class androidx.fragment.app.FragmentActivity
dump, getSupportFragmentManager, getSupportLoaderManager, onAttachFragment, onCreatePanelMenu, onCreateView, onLowMemory, onMultiWindowModeChanged, onPictureInPictureModeChanged, onPreparePanel, onRequestPermissionsResult, onStateNotSaved, setEnterSharedElementCallback, setExitSharedElementCallback, startActivityFromFragment, startIntentSenderFromFragment, supportFinishAfterTransition, supportPostponeEnterTransition, supportStartPostponedEnterTransition, validateRequestPermissionsRequestCode -
Methods inherited from class androidx.activity.ComponentActivity
addOnContextAvailableListener, getActivityResultRegistry, getDefaultViewModelProviderFactory, getLastCustomNonConfigurationInstance, getLifecycle, getOnBackPressedDispatcher, getSavedStateRegistry, getViewModelStore, onRetainCustomNonConfigurationInstance, onRetainNonConfigurationInstance, peekAvailableContext, registerForActivityResult, removeOnContextAvailableListener, reportFullyDrawn, startActivityForResult, startIntentSenderForResult -
Methods inherited from class androidx.core.app.ComponentActivity
dispatchKeyShortcutEvent, getExtraData, putExtraData, superDispatchKeyEvent -
Methods inherited from class android.app.Activity
closeContextMenu, createPendingResult, dismissDialog, dismissKeyboardShortcutsHelper, dispatchGenericMotionEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, enterPictureInPictureMode, enterPictureInPictureMode, finish, finishActivity, finishActivityFromChild, finishAffinity, finishAfterTransition, finishAndRemoveTask, finishFromChild, getActionBar, getApplication, getCallingActivity, getCallingPackage, getChangingConfigurations, getComponentName, getContentScene, getContentTransitionManager, getCurrentFocus, getFragmentManager, getIntent, getLastNonConfigurationInstance, getLayoutInflater, getLoaderManager, getLocalClassName, getMaxNumPictureInPictureActions, getMediaController, getParent, getParentActivityIntent, getPreferences, getReferrer, getRequestedOrientation, getSearchEvent, getSplashScreen, getSystemService, getTaskId, getTitle, getTitleColor, getVoiceInteractor, getVolumeControlStream, getWindow, getWindowManager, hasWindowFocus, isActivityTransitionRunning, isChangingConfigurations, isChild, isDestroyed, isFinishing, isImmersive, isInMultiWindowMode, isInPictureInPictureMode, isLaunchedFromBubble, isLocalVoiceInteractionSupported, isTaskRoot, isVoiceInteraction, isVoiceInteractionRoot, managedQuery, moveTaskToBack, navigateUpTo, navigateUpToFromChild, onActionModeFinished, onActionModeStarted, onActivityReenter, onAttachedToWindow, onContextItemSelected, onContextMenuClosed, onCreateContextMenu, onCreateDescription, onCreateNavigateUpTaskStack, onCreatePanelView, onCreateThumbnail, onDetachedFromWindow, onEnterAnimationComplete, onGenericMotionEvent, onGetDirectActions, onKeyLongPress, onKeyMultiple, onKeyShortcut, onKeyUp, onLocalVoiceInteractionStarted, onLocalVoiceInteractionStopped, onNavigateUp, onNavigateUpFromChild, onOptionsMenuClosed, onPerformDirectAction, onPictureInPictureRequested, onPictureInPictureUiStateChanged, onPrepareNavigateUpTaskStack, onPrepareOptionsMenu, onProvideAssistContent, onProvideAssistData, onProvideKeyboardShortcuts, onProvideReferrer, onSearchRequested, onTopResumedActivityChanged, onTouchEvent, onTrackballEvent, onTrimMemory, onUserInteraction, onVisibleBehindCanceled, onWindowAttributesChanged, onWindowFocusChanged, onWindowStartingActionMode, openContextMenu, overridePendingTransition, postponeEnterTransition, recreate, registerActivityLifecycleCallbacks, registerForContextMenu, releaseInstance, removeDialog, requestDragAndDropPermissions, requestPermissions, requestShowKeyboardShortcuts, requestVisibleBehind, requestWindowFeature, requireViewById, runOnUiThread, setActionBar, setContentTransitionManager, setDefaultKeyMode, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setFinishOnTouchOutside, setImmersive, setInheritShowWhenLocked, setIntent, setLocusContext, setMediaController, setPictureInPictureParams, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRequestedOrientation, setResult, setSecondaryProgress, setShowWhenLocked, setTaskDescription, setTitle, setTitleColor, setTranslucent, setTurnScreenOn, setVisible, setVolumeControlStream, setVrModeEnabled, shouldShowRequestPermissionRationale, shouldUpRecreateTask, showAssist, showDialog, showDialog, showLockTaskEscapeMessage, startActionMode, startActivities, startActivity, startActivityFromChild, startActivityIfNeeded, startIntentSender, startIntentSenderFromChild, startLocalVoiceInteraction, startLockTask, startManagingCursor, startNextMatchingActivity, startPostponedEnterTransition, startSearch, stopLocalVoiceInteraction, stopLockTask, stopManagingCursor, takeKeyEvents, triggerSearch, unregisterActivityLifecycleCallbacks, unregisterForContextMenu -
Methods inherited from class android.view.ContextThemeWrapper
applyOverrideConfiguration, getAssets, getTheme -
Methods inherited from class android.content.ContextWrapper
bindIsolatedService, bindService, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingOrSelfUriPermissions, checkCallingPermission, checkCallingUriPermission, checkCallingUriPermissions, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermissions, clearWallpaper, createAttributionContext, createConfigurationContext, createContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createWindowContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAttributionSource, getAttributionTag, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDataDir, getDatabasePath, getDir, getDisplay, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFileStreamPath, getFilesDir, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getParams, getSharedPreferences, getSystemServiceName, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, isUiContext, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setWallpaper, startForegroundService, startInstrumentation, startService, stopService, unbindService, unregisterReceiver, updateServiceGroup -
Methods inherited from class android.content.Context
getColor, getColorStateList, getDrawable, getString, getSystemService, getText, obtainStyledAttributes, registerComponentCallbacks, sendBroadcastWithMultiplePermissions, unregisterComponentCallbacks -
Methods inherited from class android.view.Window.Callback
onPointerCaptureChanged -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
onCreateOptionsMenu
boolean onCreateOptionsMenu(Menu menu)
Internal use only.
-
onOptionsItemSelected
boolean onOptionsItemSelected(MenuItem item)
Internal use only.
-
onBackPressed
void onBackPressed()
-
onDocumentAvailable
void onDocumentAvailable(@NonNull() Document document)
Called when the user has taken an image with the camera or has imported a document that passed the Gini Capture SDK's validation and any custom checks that were implemented.
- Parameters:
document- the image taken by the camera or the validated imported document
-
onProceedToMultiPageReviewScreen
void onProceedToMultiPageReviewScreen(@NonNull() GiniCaptureMultiPageDocument multiPageDocument)
-
onCheckImportedDocument
void onCheckImportedDocument(@NonNull() Document document, @NonNull() CameraFragmentListener.DocumentCheckResultCallback callback)
This method is invoked for imported documents to allow custom validations.
Invoke one of the DocumentCheckResultCallback methods on the main thread to inform the Gini Capture SDK about the result.
Note: The Gini Capture SDK will wait until one of the DocumentCheckResultCallback methods are invoked.
- Parameters:
document- a Document created from the file the user pickedcallback- use this callback to inform the Gini Capture SDK about the result of the custom checks
-
onError
void onError(@NonNull() GiniCaptureError error)
Called when an error occurred.
- Parameters:
error- details about what went wrong
-
onExtractionsAvailable
void onExtractionsAvailable(@NonNull() Map<String, GiniCaptureSpecificExtraction> extractions)
Called after a QRCode was successfully analyzed.
- Parameters:
extractions- a map of the extractions with the extraction labels as keys
-
setListener
void setListener(@NonNull() CameraFragmentListener listener)
Set a listener for camera events.
By default the hosting Activity is expected to implement the CameraFragmentListener. In case that is not feasible you may set the listener using this method.
Note: the listener is expected to be available until the fragment is attached to an activity. Make sure to set the listener before that.
- Parameters:
listener- the CameraFragmentListener instance
-
showInterface
void showInterface()
Call this method to show the interface elements. The camera preview is always visible.
Note: the interface elements are shown by default.
-
hideInterface
void hideInterface()
Call this method to hide the interface elements. The camera preview remains visible.
Note: the interface elements are shown by default.
-
showActivityIndicatorAndDisableInteraction
void showActivityIndicatorAndDisableInteraction()
Call this method to show an activity indicator and disable user interaction. The camera preview remains visible.
-
hideActivityIndicatorAndEnableInteraction
void hideActivityIndicatorAndEnableInteraction()
Call this method to hide the activity indicator and enable user interaction.
-
-
-
-