public class CameraActivity extends AppCompatActivity implements CameraFragmentListener, CameraFragmentInterface
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 GiniVision.Builder#setDocumentImportEnabledFileTypes(DocumentImportEnabledFileTypes)
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 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 Customizing the Camera Screen
on how to override the message and button titles for
the rationale and on permission denial alerts.
Start the CameraActivity
with android.app.Activity#startActivityForResult(Intent,
int)
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:
CameraActivity.EXTRA_IN_REVIEW_ACTIVITY
- use the CameraActivity.setReviewActivityExtra(Intent, Context, Class)
helper to set it. Must contain an
explicit Intent to the ReviewActivity
subclass from your application
CameraActivity.EXTRA_IN_ANALYSIS_ACTIVITY
- use the CameraActivity.setAnalysisActivityExtra(Intent, Context, Class)
helper to set it. Must contain
an explicit Intent to the AnalysisActivity
subclass from your application
These optional extras have been deprecated. Should be set only if GiniVision
is not
used:
CameraActivity.EXTRA_IN_SHOW_ONBOARDING_AT_FIRST_RUN
- the Onboarding Screen is shown
by default the first time the Gini Vision Library is started. You may disable it by setting this
extra to false
- we highly recommend keeping the default behavior
CameraActivity.EXTRA_IN_SHOW_ONBOARDING
- if set to true
the Onboarding
Screen is shown when the Gini Vision Library is started
CameraActivity.EXTRA_IN_ONBOARDING_PAGES
- custom pages for the Onboarding Screen as
an ArrayList
containing OnboardingPage
objects
CameraActivity.EXTRA_IN_BACK_BUTTON_SHOULD_CLOSE_LIBRARY
- if set
to true
the back button closes the Gini Vision Library from any of its activities with
result code CameraActivity#RESULT_CANCELED
CameraActivity.EXTRA_IN_GINI_VISION_FEATURE_CONFIGURATION
- must contain a GiniVisionFeatureConfiguration
instance to apply the feature configuration
The following result codes need to be handled:
CameraActivity#RESULT_OK
- image of a document was taken, reviewed and analyzed
CameraActivity#RESULT_CANCELED
- image of document was not taken, user canceled the
Gini Vision Library
CameraActivity.RESULT_ERROR
- an error occured
Result extra returned by the CameraActivity
:
CameraActivity.EXTRA_OUT_EXTRACTIONS
- set when result is CameraActivity#RESULT_OK
, contains a Bundle with the extraction labels as keys and GiniVisionSpecificExtraction
as values.
CameraActivity.EXTRA_OUT_ERROR
- set when result is CameraActivity.RESULT_ERROR
, contains a GiniVisionError
object detailing what went
wrong
Note: For returning the extractions from the Gini API you can add your own extras in
ReviewActivity.onAddDataToResult(Intent)
or AnalysisActivity.onAddDataToResult(Intent)
.
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 look of the Camera Screen is done via overriding of app resources.
The following items are customizable:
gv_camera_preview_corners
gv_camera_trigger_default.png
and gv_camera_trigger_pressed.png
gv_document_import_icon.png
gv_camera_document_import_subtitle
GiniVisionTheme.Camera.DocumentImportSubtitle.TextStyle
GiniVisionTheme.Camera.DocumentImportSubtitle.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
gv_document_import_hint_background
gv_hint_close
gv_document_import_hint_text
GiniVisionTheme.Camera.DocumentImportHint.TextStyle
and setting an item named android:textSize
with the desired sp
size
gv_document_import_hint_text
GiniVisionTheme.Camera.DocumentImportHint.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
GiniVisionTheme.Camera.ImageStackBadge.TextStyle
GiniVisionTheme.Camera.ImageStackBadge.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
gv_camera_image_stack_badge_background
and gv_camera_image_stack_badge_background_border
gv_camera_image_stack_badge_size
gv_camera_image_stack_subtitle
GiniVisionTheme.Camera.ImageStackSubtitle.TextStyle
GiniVisionTheme.Camera.ImageStackSubtitle.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
gv_document_error_too_many_pages
gv_document_error_multi_page_limit_review_pages_button
gv_document_error_multi_page_limit_cancel_button
gv_accent
gv_qrcode_detected_popup_background
gv_qrcode_detected_popup_message_1
and gv_qrcode_detected_popup_message_2
GiniVisionTheme.Camera.QRCodeDetectedPopup.Message1.TextStyle
and GiniVisionTheme.Camera.QRCodeDetectedPopup.Message2.TextStyle
and setting an item named android:textSize
with the desired sp
size
gv_qrcode_detected_popup_message_1
and gv_qrcode_detected_popup_message_2
GiniVisionTheme.Camera.QRCodeDetectedPopup.Message1.TextStyle
and GiniVisionTheme.Camera.QRCodeDetectedPopup.Message2.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
gv_storage_permission_rationale
gv_storage_permission_rationale_positive_button
gv_storage_permission_rationale_negative_button
gv_accent
gv_storage_permission_denied
gv_storage_permission_denied_positive_button
gv_storage_permission_denied_negative_button
gv_accent
gv_camera_focus_indicator.png
gv_help_icon.png
gv_show_onboarding
gv_background
. Note:
this color resource is global to all Activities (CameraActivity
, OnboardingActivity
, ReviewActivity
, AnalysisActivity
)
gv_no_camera.png
gv_camera_error_no_permission
gv_camera_error_no_permission
GiniVisionTheme.Camera.Error.NoPermission.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
GiniVisionTheme.Camera.Error.NoPermission.TextStyle
and setting an item named android:textStyle
to normal
, bold
or italic
GiniVisionTheme.Camera.Error.NoPermission.TextStyle
and setting an item named android:textSize
to the desired sp
size
gv_camera_error_no_permission_button_title
gv_camera_error_no_permission_button_title
and gv_camera_error_no_permission_button_title_pressed
GiniVisionTheme.Camera.Error.NoPermission.Button.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
GiniVisionTheme.Camera.Error.NoPermission.Button.TextStyle
and setting an item named android:textStyle
to normal
, bold
or italic
GiniVisionTheme.Camera.Error.NoPermission.Button.TextStyle
and setting an item named android:textSize
to the desired sp
size
Important: All overriden styles must have their respective Root.
prefixed
style as their parent. Ex.: the parent of GiniVisionTheme.Camera.Error.NoPermission.TextStyle
must be Root.GiniVisionTheme.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
, OnboardingActivity
, ReviewActivity
, MultiPageReviewActivity
, AnalysisActivity
).
The following items are customizable:
gv_action_bar
(highly
recommended for Android 5+: customize the status bar color via gv_status_bar
)
gv_title_camera
gv_action_bar_title
gv_action_bar_back
CameraFragmentListener.DocumentCheckResultCallback
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EXTRA_IN_ANALYSIS_ACTIVITY
Deprecated.
When a
GiniVision instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService implementation. The
extractions will be returned in the extra called CameraActivity.EXTRA_OUT_EXTRACTIONS
of the CameraActivity 's result Intent. |
static java.lang.String |
EXTRA_IN_BACK_BUTTON_SHOULD_CLOSE_LIBRARY
Deprecated.
The option to close the library with the back button from any screen will be
removed in a future version.
|
static java.lang.String |
EXTRA_IN_GINI_VISION_FEATURE_CONFIGURATION
Deprecated.
Configuration should be applied by creating a
GiniVision instance using
GiniVision.newInstance() and the returned GiniVision.Builder . |
static java.lang.String |
EXTRA_IN_ONBOARDING_PAGES
Deprecated.
Configuration should be applied by creating a
GiniVision instance using
GiniVision.newInstance() and the returned GiniVision.Builder . |
static java.lang.String |
EXTRA_IN_REVIEW_ACTIVITY
Deprecated.
When a
GiniVision instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService implementation. The
extractions will be returned in the extra called CameraActivity.EXTRA_OUT_EXTRACTIONS
of the CameraActivity 's result Intent. |
static java.lang.String |
EXTRA_IN_SHOW_ONBOARDING
Deprecated.
Configuration should be applied by creating a
GiniVision instance using
GiniVision.newInstance() and the returned GiniVision.Builder . |
static java.lang.String |
EXTRA_IN_SHOW_ONBOARDING_AT_FIRST_RUN
Deprecated.
Configuration should be applied by creating a
GiniVision instance using
GiniVision.newInstance() and the returned GiniVision.Builder . |
static java.lang.String |
EXTRA_OUT_ERROR
Returned when the result code is
CameraActivity.RESULT_ERROR and contains a
GiniVisionError object detailing what went wrong. |
static java.lang.String |
EXTRA_OUT_EXTRACTIONS
Returned when extractions are available.
|
static int |
RESULT_ERROR
Returned result code in case something went wrong.
|
Constructor and Description |
---|
CameraActivity() |
Modifier and Type | Method and Description |
---|---|
void |
hideActivityIndicatorAndEnableInteraction()
Call this method to hide the activity indicator and enable user interaction.
|
void |
hideCameraTriggerButton()
Call this method to hide the camera trigger button.
|
void |
hideDocumentCornerGuides()
Call this method to hide the document corner guides.
|
void |
hideInterface()
Call this method to hide the interface elements.
|
void |
onBackPressed() |
void |
onCheckImportedDocument(Document document,
CameraFragmentListener.DocumentCheckResultCallback callback)
This method is invoked for imported documents to allow custom validations.
|
void |
onDocumentAvailable(Document document)
Called when the user has taken an image with the camera or has imported a document that passed the Gini Vision Library's validation and any custom checks that were implemented.
|
void |
onError(GiniVisionError error)
Called when an error occurred.
|
void |
onExtractionsAvailable(java.util.Map extractions)
Called after a QRCode was successfully analyzed.
|
void |
onProceedToMultiPageReviewScreen(GiniVisionMultiPageDocument multiPageDocument) |
void |
onQRCodeAvailable(QRCodeDocument qrCodeDocument)
Called when the user clicked the QR Code detected popup.
|
static void |
setAnalysisActivityExtra(Intent target,
Context context,
java.lang.Class analysisActivityClass)
Deprecated.
When a
GiniVision instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService implementation. The
extractions will be returned in the extra called CameraActivity.EXTRA_OUT_EXTRACTIONS
of the CameraActivity 's result Intent. |
void |
setListener(CameraFragmentListener listener)
Set a listener for camera events.
|
static void |
setReviewActivityExtra(Intent target,
Context context,
java.lang.Class reviewActivityClass)
Deprecated.
When a
GiniVision instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService implementation. The
extractions will be returned in the extra called CameraActivity.EXTRA_OUT_EXTRACTIONS
of the CameraActivity 's result Intent. |
void |
showActivityIndicatorAndDisableInteraction()
Call this method to show an activity indicator and disable user interaction.
|
void |
showCameraTriggerButton()
Call this method to show the camera trigger button.
|
void |
showDocumentCornerGuides()
Call this method to show the document corner guides.
|
void |
showError(java.lang.String message,
int duration)
Call this method to show an error message to the user in the Camera Screen.
|
void |
showInterface()
Call this method to show the interface elements.
|
public static final java.lang.String EXTRA_IN_REVIEW_ACTIVITY
GiniVision
instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService
implementation. The
extractions will be returned in the extra called CameraActivity.EXTRA_OUT_EXTRACTIONS
of the CameraActivity
's result Intent. Mandatory extra which must contain an explicit Intent to the ReviewActivity
subclass from your application.
Use the CameraActivity.setReviewActivityExtra(Intent,
Context, Class)
helper to set it.
public static final java.lang.String EXTRA_IN_ANALYSIS_ACTIVITY
GiniVision
instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService
implementation. The
extractions will be returned in the extra called CameraActivity.EXTRA_OUT_EXTRACTIONS
of the CameraActivity
's result Intent. Mandatory extra which must contain an explicit Intent to the AnalysisActivity
subclass from your application.
Use the CameraActivity.setAnalysisActivityExtra(Intent,
Context, Class)
helper to set it.
public static final java.lang.String EXTRA_IN_ONBOARDING_PAGES
GiniVision
instance using
GiniVision.newInstance()
and the returned GiniVision.Builder
.ArrayList
with OnboardingPage
objects.public static final java.lang.String EXTRA_IN_SHOW_ONBOARDING_AT_FIRST_RUN
GiniVision
instance using
GiniVision.newInstance()
and the returned GiniVision.Builder
.Optional extra which must contain a boolean and indicates whether the Onboarding Screen should be shown when the Gini Vision Library is started for the first time.
Default
value is true
.
public static final java.lang.String EXTRA_IN_SHOW_ONBOARDING
GiniVision
instance using
GiniVision.newInstance()
and the returned GiniVision.Builder
.Optional extra which must contain a boolean and indicates whether the Onboarding Screen should be shown when the Gini Vision Library is started.
Default value is false
.
public static final java.lang.String EXTRA_IN_BACK_BUTTON_SHOULD_CLOSE_LIBRARY
Optional extra wich must contain a boolean and indicates whether the back button should close the Gini Vision Library.
Default value is false
.
public static final java.lang.String EXTRA_IN_GINI_VISION_FEATURE_CONFIGURATION
GiniVision
instance using
GiniVision.newInstance()
and the returned GiniVision.Builder
.GiniVisionFeatureConfiguration
instance.public static final java.lang.String EXTRA_OUT_ERROR
Returned when the result code is CameraActivity.RESULT_ERROR
and contains a
GiniVisionError
object detailing what went wrong.
public static final java.lang.String EXTRA_OUT_EXTRACTIONS
GiniVisionSpecificExtraction
as values.public static final int RESULT_ERROR
Returned result code in case something went wrong. You should retrieve the CameraActivity.EXTRA_OUT_ERROR
extra to find out what went wrong.
@Deprecated public static void setReviewActivityExtra(Intent target, Context context, java.lang.Class reviewActivityClass)
GiniVision
instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService
implementation. The
extractions will be returned in the extra called CameraActivity.EXTRA_OUT_EXTRACTIONS
of the CameraActivity
's result Intent. Helper for setting the CameraActivity.EXTRA_IN_REVIEW_ACTIVITY
.
target
- your explicit Intent
used to start the CameraActivity
context
- Context
used to create the explicit Intent
for
your ReviewActivity
subclassreviewActivityClass
- class of your ReviewActivity
subclass@Deprecated public static void setAnalysisActivityExtra(Intent target, Context context, java.lang.Class analysisActivityClass)
GiniVision
instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService
implementation. The
extractions will be returned in the extra called CameraActivity.EXTRA_OUT_EXTRACTIONS
of the CameraActivity
's result Intent. Helper for setting the CameraActivity.EXTRA_IN_ANALYSIS_ACTIVITY
.
target
- your explicit Intent
used to start the CameraActivity
context
- Context
used to create the explicit Intent
for
your AnalysisActivity
subclassanalysisActivityClass
- class of your AnalysisActivity
subclasspublic void onBackPressed()
public void onDocumentAvailable(Document document)
CameraFragmentListener
Called when the user has taken an image with the camera or has imported a document that passed the Gini Vision Library's validation and any custom checks that were implemented.
onDocumentAvailable
in interface CameraFragmentListener
document
- the image taken by the camera or the validated imported documentpublic void onProceedToMultiPageReviewScreen(GiniVisionMultiPageDocument multiPageDocument)
onProceedToMultiPageReviewScreen
in interface CameraFragmentListener
public void onQRCodeAvailable(QRCodeDocument qrCodeDocument)
CameraFragmentListener
Called when the user clicked the QR Code detected popup.
You should upload the QRCodeDocument
's data to the Gini API to get the extractions,
close the Gini Vision Library and continue to your app's transfer form.
See QRCodeDocument
for supported formats.
onQRCodeAvailable
in interface CameraFragmentListener
qrCodeDocument
- contains payment data from a QR Codepublic void onCheckImportedDocument(Document document, CameraFragmentListener.DocumentCheckResultCallback callback)
CameraFragmentListener
This method is invoked for imported documents to allow custom validations.
Invoke one of the CameraFragmentListener.DocumentCheckResultCallback
methods on the main thread to inform the Gini Vision Library about the result.
Note: The Gini Vision Library will wait until one of the CameraFragmentListener.DocumentCheckResultCallback
methods are invoked.
onCheckImportedDocument
in interface CameraFragmentListener
document
- a Document
created from the file the user pickedcallback
- use this callback to inform the Gini Vision Library about the result of the custom checkspublic void onError(GiniVisionError error)
CameraFragmentListener
Called when an error occurred.
onError
in interface CameraFragmentListener
error
- details about what went wrongpublic void onExtractionsAvailable(java.util.Map extractions)
CameraFragmentListener
onExtractionsAvailable
in interface CameraFragmentListener
extractions
- a map of the extractions with the extraction labels as keyspublic void setListener(CameraFragmentListener listener)
CameraFragmentInterface
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.
setListener
in interface CameraFragmentInterface
listener
- the CameraFragmentListener
instancepublic void showDocumentCornerGuides()
CameraFragmentInterface
Call this method to show the document corner guides.
Note: the document corner guides are shown by default.
showDocumentCornerGuides
in interface CameraFragmentInterface
public void hideDocumentCornerGuides()
CameraFragmentInterface
Call this method to hide the document corner guides.
Note: the document corner guides are shown by default.
hideDocumentCornerGuides
in interface CameraFragmentInterface
public void showCameraTriggerButton()
CameraFragmentInterface
Call this method to show the camera trigger button.
Note: the camera trigger button is shown by default.
showCameraTriggerButton
in interface CameraFragmentInterface
public void hideCameraTriggerButton()
CameraFragmentInterface
Call this method to hide the camera trigger button.
Note: the camera trigger button is shown by default.
hideCameraTriggerButton
in interface CameraFragmentInterface
public void showInterface()
CameraFragmentInterface
Call this method to show the interface elements. The camera preview is always visible.
Note: the interface elements are shown by default.
showInterface
in interface CameraFragmentInterface
public void hideInterface()
CameraFragmentInterface
Call this method to hide the interface elements. The camera preview remains visible.
Note: the interface elements are shown by default.
hideInterface
in interface CameraFragmentInterface
public void showActivityIndicatorAndDisableInteraction()
CameraFragmentInterface
Call this method to show an activity indicator and disable user interaction. The camera preview remains visible.
showActivityIndicatorAndDisableInteraction
in interface CameraFragmentInterface
public void hideActivityIndicatorAndEnableInteraction()
CameraFragmentInterface
Call this method to hide the activity indicator and enable user interaction.
hideActivityIndicatorAndEnableInteraction
in interface CameraFragmentInterface
public void showError(java.lang.String message, int duration)
CameraFragmentInterface
Call this method to show an error message to the user in the Camera Screen.
showError
in interface CameraFragmentInterface
message
- a short error messageduration
- how long should the error message be shown in ms