public class AnalysisActivity extends AppCompatActivity implements AnalysisFragmentListener, AnalysisFragmentInterface
When you use the Screen API, the AnalysisActivity
displays the captured or imported
document and an activity indicator while the document is being analyzed by the Gini API.
Note: The title from the ActionBar was removed. Use the activity indicator message
instead by overriding the string resource named gv_analysis_activity_indicator_message
.
The message is displayed for images only.
For PDF documents the first page is shown (only on Android 5.0 Lollipop and newer) along with the PDF's filename and number of pages above the page. On Android KitKat and older only the PDF's filename is shown with the preview area left empty.
Extending the AnalysisActivity
in your application has been deprecated. The preferred
way of adding network calls to the Gini Vision Library is by creating a GiniVision
instance with a GiniVisionNetworkService
and a GiniVisionNetworkApi
implementation.
Note: When declaring your AnalysisActivity
subclass in the AndroidManifest.xml
you should set the theme to the GiniVisionTheme
. If you would like
to use your own theme please consider that AnalysisActivity
extends AppCompatActivity
and requires an AppCompat Theme.
The AnalysisActivity
is started by the CameraActivity
after the user has
reviewed the document and either made no changes to the document and it hasn't been analyzed
before tapping the Next button, or the user has modified the document, e.g. by rotating it.
For imported documents that cannot be reviewed, like PDFs, the CameraActivity
starts
the AnalysisActivity
directly.
If you didn't create GiniVision
instance you have to implement the following methods
in your AnalysisActivity
subclass:
AnalysisActivity.onAnalyzeDocument(Document)
- start analyzing the document by
sending it to the Gini API.AnalysisActivity.onDocumentAnalyzed()
when the analysis is done and the Activity hasn't been stopped.ReviewActivity.onDocumentAnalysisError(String)
this method won't be called until the user clicks the retry button next to the error message.
AnalysisActivity.onAddDataToResult(Intent)
- you should add the results of the
analysis to the Intent as extras and retrieve them once the CameraActivity
returns.AnalysisActivity.onDocumentAnalyzed()
before.CameraActivity
and you can extract the results of the analysis.
You can also override the following method:
AnalysisActivity.onBackPressed()
- called when the back or the up button was
clicked.
The following items are customizable:
gv_analysis_activity_indicator
gv_analysis_activity_indicator_message
GiniVisionTheme.Analysis.AnalysingMessage.TextStyle
GiniVisionTheme.Analysis.AnalysingMessage.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
gv_analysis_pdf_info_background
GiniVisionTheme.Analysis.PdfFilename.TextStyle
and setting an item named android:textStyle
to normal
, bold
or italic
GiniVisionTheme.Analysis.PdfFilename.TextStyle
and setting an item named autoSizeMaxTextSize
and autoSizeMinTextSize
to the desired maximum and minimum sp
sizes
gv_analysis_pdf_info_text
GiniVisionTheme.Analysis.PdfFilename.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
GiniVisionTheme.Analysis.PdfPageCount.TextStyle
and setting an item named android:textStyle
to normal
, bold
or italic
GiniVisionTheme.Analysis.PdfPageCount.TextStyle
and setting an item named android:textSize
to the desired sp
size
gv_analysis_pdf_info_text
GiniVisionTheme.Analysis.PdfPageCount.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
gv_background
. Note:
this color resource is global to all Activities (CameraActivity
, OnboardingActivity
, ReviewActivity
, AnalysisActivity
)
gv_snackbar_error_text
GiniVisionTheme.Snackbar.Error.TextStyle
and setting an item named gvCustomFont
with the
path to the font file in your assets
folder
GiniVisionTheme.Snackbar.Error.TextStyle
and setting an item named android:textStyle
to
normal
, bold
or italic
GiniVisionTheme.Snackbar.Error.TextStyle
and setting an item named android:textSize
to
the desired sp
size
gv_snackbar_error_button_title
and gv_snackbar_error_button_title_pressed
GiniVisionTheme.Snackbar.Error.Button.TextStyle
and setting an item named gvCustomFont
with the path to the font file in your assets
folder
GiniVisionTheme.Snackbar.Error.Button.TextStyle
and setting an item named android:textStyle
to normal
, bold
or italic
GiniVisionTheme.Snackbar.Error.Button.TextStyle
and setting an item named android:textSize
to the desired sp
size
gv_snackbar_error_background
gv_document_analysis_error_retry
Important: All overriden styles must have their respective Root.
prefixed
style as their parent. Ex.: the parent of GiniVisionTheme.Snackbar.Error.TextStyle
must
be Root.GiniVisionTheme.Snackbar.Error.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
)
ReviewActivity
and AnalysisActivity
): via
images for mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi named gv_action_bar_back
Constructor and Description |
---|
AnalysisActivity() |
Modifier and Type | Method and Description |
---|---|
void |
hideError()
Call this method to hide the error shown before with
AnalysisFragmentInterface.showError(String, String, View.OnClickListener) or
AnalysisFragmentInterface.showError(String, int) . |
void |
onAddDataToResult(Intent result)
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 |
onAnalyzeDocument(Document document)
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 |
onBackPressed() |
void |
onDefaultPDFAppAlertDialogCancelled()
Called when the default PDF app alert dialog was cancelled.
|
void |
onDocumentAnalyzed()
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 |
onError(GiniVisionError error)
Called when an error occurred.
|
void |
onExtractionsAvailable(java.util.Map extractions)
Called when the document has been analyzed and extractions are available.
|
void |
onNoExtractionsFound()
Deprecated.
When a
GiniVision instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService implementation. |
boolean |
onOptionsItemSelected(MenuItem item) |
void |
onProceedToNoExtractionsScreen(Document document)
Called when the document has been analyzed and no extractions were received.
|
void |
setListener(AnalysisFragmentListener listener)
Set a listener for analysis events.
|
void |
showError(java.lang.String message,
int duration)
Call this method when you need to show an error message to the user in the Analysis
Screen.
|
void |
showError(java.lang.String message,
java.lang.String buttonTitle,
View.OnClickListener onClickListener)
Call this method when you need to show an error message with an invokable action to the user
in the Analysis Screen.
|
void |
startScanAnimation()
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 |
stopScanAnimation()
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. |
public void hideError()
AnalysisFragmentInterface
Call this method to hide the error shown before with
AnalysisFragmentInterface.showError(String, String, View.OnClickListener)
or
AnalysisFragmentInterface.showError(String, int)
.
hideError
in interface AnalysisFragmentInterface
@Deprecated public void onNoExtractionsFound()
GiniVision
instance is available the document is analyzed
internally by using the configured GiniVisionNetworkService
implementation.You should call this method after you've received the analysis results from the Gini API without the required extractions.
It will launch the NoResultsActivity
, if
the Document
's type is Document.Type#IMAGE
. For other types it will just
finish the AnalysisActivity
with RESULT_OK
.
onNoExtractionsFound
in interface AnalysisFragmentInterface
@Deprecated public void onAnalyzeDocument(Document document)
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. Screen API: If an analysis error message was set in the Review Screen with ReviewActivity.onDocumentAnalysisError(String)
this method won't be called until the user
clicks the retry button next to the error message.
onAnalyzeDocument
in interface AnalysisFragmentListener
document
- contains the image taken by the camera (original or modified)@Deprecated public void onDocumentAnalyzed()
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.AnalysisFragmentInterface
You should call this method after you've received the analysis results from the Gini API.
onDocumentAnalyzed
in interface AnalysisFragmentInterface
public void onError(GiniVisionError error)
AnalysisFragmentListener
Called when an error occurred.
onError
in interface AnalysisFragmentListener
error
- details about what went wrongpublic boolean onOptionsItemSelected(MenuItem item)
public void onBackPressed()
public void showError(java.lang.String message, java.lang.String buttonTitle, View.OnClickListener onClickListener)
AnalysisFragmentInterface
Call this method when you need to show an error message with an invokable action to the user in the Analysis Screen.
showError
in interface AnalysisFragmentInterface
message
- a short error messagebuttonTitle
- if not null and not empty, shows a button with the given titleonClickListener
- listener for the buttonpublic void showError(java.lang.String message, int duration)
AnalysisFragmentInterface
Call this method when you need to show an error message to the user in the Analysis Screen.
showError
in interface AnalysisFragmentInterface
message
- a short error messageduration
- how long should the error message be shown in ms@Deprecated public void startScanAnimation()
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.AnalysisFragmentInterface
You should call this method when you start the document analysis using the Gini API.
startScanAnimation
in interface AnalysisFragmentInterface
@Deprecated public void stopScanAnimation()
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.AnalysisFragmentInterface
You should call this method when the document analysis has finished.
stopScanAnimation
in interface AnalysisFragmentInterface
@Deprecated public void onAddDataToResult(Intent result)
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.Callback for adding your own data to the Activity's result.
Called when the document was analyzed.
You should add the results of the analysis as extras and
retrieve them when the CameraActivity
returned.
Note: you must call
AnalysisActivity.onDocumentAnalyzed()
after you received the analysis results from
the Gini API, otherwise this method won't be invoked.
result
- the Intent
which will be returned as the result data.public void setListener(AnalysisFragmentListener listener)
AnalysisFragmentInterface
Set a listener for analysis events.
By default the hosting Activity is expected to implement
the AnalysisFragmentListener
. 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 AnalysisFragmentInterface
listener
- AnalysisFragmentListener
instancepublic void onExtractionsAvailable(java.util.Map extractions)
AnalysisFragmentListener
onExtractionsAvailable
in interface AnalysisFragmentListener
extractions
- a map of the extractions with the extraction labels as keyspublic void onProceedToNoExtractionsScreen(Document document)
AnalysisFragmentListener
You should show the NoResultsFragmentStandard
or NoResultsFragmentCompat
.
onProceedToNoExtractionsScreen
in interface AnalysisFragmentListener
document
- contains the reviewed documentpublic void onDefaultPDFAppAlertDialogCancelled()
AnalysisFragmentListener
This alert dialog is shown for PDFs imported from another app when your app was set as default for opening PDFs.
onDefaultPDFAppAlertDialogCancelled
in interface AnalysisFragmentListener