Package net.gini.android.vision.camera

Contains the Activity and Fragments used for the Camera Screen.

Screen API

The net.gini.android.vision.camera.CameraActivity is the main entry point when using the Screen API. Start net.gini.android.vision.camera.CameraActivity and as a result, if something went wrong, a net.gini.android.vision.GiniVisionError is returned.

Component API

To use the Component API you have to include the net.gini.android.vision.camera.CameraFragmentStandard or the net.gini.android.vision.camera.CameraFragmentCompat in an Activity in your app (a dedicated Activity is recommended). To receive events from the Fragments your Activity must implement the net.gini.android.vision.camera.CameraFragmentListener interface.

Types

CameraActivity
Link copied to clipboard

Screen API

{@code CameraActivity} is the main entry point to the Gini Vision Library 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 Vision Library is used to inform the user about document importing.

For importing documents {@code READ_EXTERNAL_STORAGE} permission is required and if the permission is not granted the Gini Vision Library will prompt the user to grant the permission. See {@code Customizing the Camera Screen} on how to override the message and button titles for the rationale and on permission denial alerts.

Start the {@code CameraActivity} with startActivityForResult to receive the extractions or a GiniVisionError in case there was an error.

These formerly mandatory extras have been deprecated. Still required if GiniVision is not used:

These optional extras have been deprecated. Should be set only if GiniVision is not used:

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 Vision Library
  • RESULT_ERROR - an error occured

Result extra returned by the {@code CameraActivity} :

Note: For returning the extractions from the Gini API you can add your own extras in onAddDataToResult or onAddDataToResult .

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 Screen

Customizing 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 {@code * gv_camera_preview_corners}
  • Camera trigger button: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named {@code * gv_camera_trigger_default.png} and {@code gv_camera_trigger_pressed.png}
  • Document import button: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named {@code gv_document_import_icon.png}
  • Document import button subtitle text: via the string resource named {@code * gv_camera_document_import_subtitle}
  • Document import button subtitle text style: via overriding the style named {@code * GiniVisionTheme.Camera.DocumentImportSubtitle.TextStyle}
  • Document import button subtitle font: via overriding the style named {@code * GiniVisionTheme.Camera.DocumentImportSubtitle.TextStyle} and setting an item named {@code * gvCustomFont} with the path to the font file in your {@code assets} folder
  • Document import hint background: via the color resource named {@code * gv_document_import_hint_background}
  • Document import hint close icon color: via the color resource name {@code * gv_hint_close}
  • Document import hint text: via the string resource named {@code * gv_document_import_hint_text}
  • Document import hint text size: via overriding the style named {@code * GiniVisionTheme.Camera.DocumentImportHint.TextStyle} and setting an item named {@code * android:textSize} with the desired {@code sp} size
  • Document import hint text color: via the color resource name {@code * gv_document_import_hint_text}
  • Document import hint font: via overriding the style named {@code * GiniVisionTheme.Camera.DocumentImportHint.TextStyle} and setting an item named {@code * gvCustomFont} with the path to the font file in your {@code assets} folder
  • Images stack badge text style: via overriding the style named {@code * GiniVisionTheme.Camera.ImageStackBadge.TextStyle}
  • Images stack badge font: via overriding the style named {@code * GiniVisionTheme.Camera.ImageStackBadge.TextStyle} and setting an item named {@code gvCustomFont} with the path to the font file in your {@code assets} folder
  • Images stack badge background colors: via the color resources named {@code * gv_camera_image_stack_badge_background} and {@code gv_camera_image_stack_badge_background_border}
  • Images stack badge background size: via the dimension resource named {@code * gv_camera_image_stack_badge_size}
  • Images stack subtitle text: via the string resource named {@code * gv_camera_image_stack_subtitle}
  • Images stack subtitle text style: via overriding the style named {@code * GiniVisionTheme.Camera.ImageStackSubtitle.TextStyle}
  • Images stack subtitle font: via overriding the style named {@code * GiniVisionTheme.Camera.ImageStackSubtitle.TextStyle} and setting an item named {@code * gvCustomFont} with the path to the font file in your {@code assets} folder
  • Multi-page document page limit exceeded alert message: via the string resource named {@code * gv_document_error_too_many_pages}
  • Multi-page document page limit exceeded alert positive button text: via the string resource named {@code gv_document_error_multi_page_limit_review_pages_button}
  • Multi-page document page limit exceeded alert cancel button text: via the string resource named {@code gv_document_error_multi_page_limit_cancel_button}
  • Read storage permission denied button color: via the color resource named {@code * gv_accent}
  • QRCode detected popup background: via the color resource named {@code * gv_qrcode_detected_popup_background}
  • QRCode detected popup texts: via the string resources named {@code * gv_qrcode_detected_popup_message_1} and {@code gv_qrcode_detected_popup_message_2}
  • QRCode detected popup text sizes: via overriding the styles named {@code * GiniVisionTheme.Camera.QRCodeDetectedPopup.Message1.TextStyle} and {@code * GiniVisionTheme.Camera.QRCodeDetectedPopup.Message2.TextStyle} and setting an item named {@code * android:textSize} with the desired {@code sp} size
  • QRCode detected popup text colors: via the color resource name {@code * gv_qrcode_detected_popup_message_1} and {@code gv_qrcode_detected_popup_message_2}
  • QRCode detected popup fonts: via overriding the styles named {@code * GiniVisionTheme.Camera.QRCodeDetectedPopup.Message1.TextStyle} and {@code * GiniVisionTheme.Camera.QRCodeDetectedPopup.Message2.TextStyle} and setting an item named {@code * gvCustomFont} with the path to the font file in your {@code assets} folder
  • Read storage permission rationale text: via the string resource named {@code * gv_storage_permission_rationale}
  • Read storage permission rationale positive button text: via the string resource named {@code gv_storage_permission_rationale_positive_button}
  • Read storage permission rationale negative button text: via the string resource named {@code gv_storage_permission_rationale_negative_button}
  • Read storage permission rationale button color: via the color resource named {@code * gv_accent}
  • Read storage permission denied text: via the string resource named {@code * gv_storage_permission_denied}
  • Read storage permission denied positive button text: via the string resource named {@code gv_storage_permission_denied_positive_button}
  • Read storage permission denied negative button text: via the string resource named {@code gv_storage_permission_denied_negative_button}
  • Read storage permission denied button color: via the color resource named {@code * gv_accent}
  • Tap-to-focus indicator: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named {@code gv_camera_focus_indicator.png}
  • Help menu item icon: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named {@code * gv_help_icon.png}
  • Onboarding menu item title: via the string resource named {@code gv_show_onboarding}
  • Background color: via the color resource named {@code gv_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 {@code * gv_no_camera.png}
  • No camera permission text: via the string resource named {@code * gv_camera_error_no_permission}
  • No camera permission text color: via the color resource named {@code * gv_camera_error_no_permission}
  • No camera permission font: via overriding the style named {@code * GiniVisionTheme.Camera.Error.NoPermission.TextStyle} and setting an item named {@code * gvCustomFont} with the path to the font file in your {@code assets} folder
  • No camera permission text style: via overriding the style named {@code * GiniVisionTheme.Camera.Error.NoPermission.TextStyle} and setting an item named {@code * android:textStyle} to {@code normal} , {@code bold} or {@code italic}
  • No camera permission text size: via overriding the style named {@code * GiniVisionTheme.Camera.Error.NoPermission.TextStyle} and setting an item named {@code * android:textSize} to the desired {@code sp} size
  • No camera permission button title: via the string resource named {@code * gv_camera_error_no_permission_button_title}
  • No camera permission button title color: via the color resources named {@code * gv_camera_error_no_permission_button_title} and {@code gv_camera_error_no_permission_button_title_pressed}
  • No camera permission button font: via overriding the style named {@code * GiniVisionTheme.Camera.Error.NoPermission.Button.TextStyle} and setting an item named {@code * gvCustomFont} with the path to the font file in your {@code assets} folder
  • No camera permission button text style: via overriding the style named {@code * GiniVisionTheme.Camera.Error.NoPermission.Button.TextStyle} and setting an item named {@code * android:textStyle} to {@code normal} , {@code bold} or {@code italic}
  • No camera permission button text size: via overriding the style named {@code * GiniVisionTheme.Camera.Error.NoPermission.Button.TextStyle} and setting an item named {@code * android:textSize} to the desired {@code sp} size

Important: All overriden styles must have their respective {@code Root.} prefixed style as their parent. Ex.: the parent of {@code GiniVisionTheme.Camera.Error.NoPermission.TextStyle} must be {@code Root.GiniVisionTheme.Camera.Error.NoPermission.TextStyle} .

Customizing the Action Bar

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 {@code gv_action_bar} (highly recommended for Android 5+: customize the status bar color via {@code gv_status_bar} )
  • Title: via the string resource name {@code gv_title_camera}
  • Title color: via the color resource named {@code gv_action_bar_title}
  • Back button: via images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named {@code gv_action_bar_back}

public class CameraActivity extends AppCompatActivity implements CameraFragmentListener, CameraFragmentInterface
CameraFragmentCompat
Link copied to clipboard

Component API

{@code CameraFragmentCompat} is the main entry point to the Gini Vision Library when using the Component API with the Android Support Library.

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.

If instantiated with createInstance then a button for importing documents is shown next to the trigger button. A hint popup is displayed the first time the Gini Vision Library is used to inform the user about document importing.

For importing documents {@code READ_EXTERNAL_STORAGE} permission is required and if the permission is not granted the Gini Vision Library will prompt the user to grant the permission. See @ { code Customizing the Camera Screen } on how to override the message and button titles for the rationale and on permission denial alerts.

Note: Your Activity hosting this Fragment must extend the and use an AppCompat Theme.

Include the {@code CameraFragmentCompat} into your layout either directly with {@code } in your Activity's layout or using the androidx.fragment.app.FragmentManager and one of the {@code createInstance()} methods.

A CameraFragmentListener instance must be available until the {@code * CameraFragmentCompat} is attached to an activity. Failing to do so will throw an exception. The listener instance can be provided either implicitly by making the hosting Activity implement the CameraFragmentListener interface or explicitly by setting the listener using .

Your Activity is automatically set as the listener in onAttach .

Customizing the Camera Screen

See the CameraActivity for details.

public class CameraFragmentCompat extends Fragment implements CameraFragmentInterface, FragmentImplCallback
CameraFragmentHelper
Link copied to clipboard
class CameraFragmentHelper
CameraFragmentImpl
Link copied to clipboard
class CameraFragmentImpl implements CameraFragmentInterface, PaymentQRCodeReader.Listener
CameraFragmentInterface
Link copied to clipboard

Methods which both Camera Fragments must implement.

public interface CameraFragmentInterface
CameraFragmentListener
Link copied to clipboard

Interface used by CameraFragmentStandard and CameraFragmentCompat to dispatch events to the hosting Activity.

public interface CameraFragmentListener
CameraFragmentStandard
Link copied to clipboard

Component API

{@code CameraFragmentStandard} is the main entry point to the Gini Vision Library when using the Component API without the Android Support Library.

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.

If instantiated with createInstance then a button for importing documents is shown next to the trigger button. A hint popup is displayed the first time the Gini Vision Library is used to inform the user about document importing.

For importing documents {@code READ_EXTERNAL_STORAGE} permission is required and if the permission is not granted the Gini Vision Library will prompt the user to grant the permission. See @ { code Customizing the Camera Screen } on how to override the message and button titles for the rationale and on permission denial alerts.

Include the {@code CameraFragmentStandard} into your layout either directly with {@code } in your Activity's layout or using the android.app.FragmentManager and one of the {@code createInstance()} methods.

A CameraFragmentListener instance must be available until the {@code CameraFragmentStandard} is attached to an activity. Failing to do so will throw an exception. The listener instance can be provided either implicitly by making the hosting Activity implement the CameraFragmentListener interface or explicitly by setting the listener using setListener .

Your Activity is automatically set as the listener in onAttach .

Customizing the Camera Screen

See the CameraActivity for details.

public class CameraFragmentStandard extends Fragment implements CameraFragmentInterface, FragmentImplCallback
FrameView
Link copied to clipboard

Internal use only.

public class FrameView extends View
ImageStack
Link copied to clipboard

Created by Alpar Szotyori on 13.02.2018. Copyright (c) 2018 Gini GmbH.

public class ImageStack extends RelativeLayout
ImportImageDocumentUrisAsyncTask
Link copied to clipboard

Created by Alpar Szotyori on 23.03.2018. Copyright (c) 2018 Gini GmbH.

class ImportImageDocumentUrisAsyncTask extends AbstractImportImageUrisAsyncTask
Util
Link copied to clipboard

Internal use only.

final class Util