public class AnalysisFragmentCompat extends Fragment implements AnalysisFragmentInterface
When you use the Component API with the Android Support Library, the AnalyzeDocumentFragmentCompat
displays the captured or imported document and an activity
indicator while the document is being analyzed by the Gini API.
Note: You can use the activity indicator message to display a message under the activity
indicator 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.
Note: Your Activity hosting this Fragment must extend the android.support.v7.app.AppCompatActivity
and use an AppCompat Theme.
Include the AnalyzeDocumentFragmentCompat
into your layout by using the AnalysisFragmentCompat.createInstance(Document, String)
factory method to create an instance and
display it using the android.support.v4.app.FragmentManager
.
An AnalysisFragmentListener
instance must be available until the AnalysisFragmentCompat
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
AnalysisFragmentListener
interface or explicitly by setting the listener using AnalysisFragmentCompat.setListener(AnalysisFragmentListener)
.
Your Activity is automatically set as the listener in AnalysisFragmentCompat.onCreate(Bundle)
.
See the AnalysisActivity
for details.
Constructor and Description |
---|
AnalysisFragmentCompat() |
Modifier and Type | Method and Description |
---|---|
static AnalysisFragmentCompat |
createInstance(Document document,
java.lang.String documentAnalysisErrorMessage)
Factory method for creating a new instance of the Fragment using the provided document.
|
void |
hideError()
Call this method to hide the error shown before with
AnalysisFragmentInterface.showError(String, String, View.OnClickListener) or
AnalysisFragmentInterface.showError(String, int) . |
void |
onDocumentAnalyzed()
You should call this method after you've received the analysis results from the Gini API.
|
void |
onNoExtractionsFound()
You should call this method after you've received the analysis results from the Gini API
without the required extractions.
|
void |
setListener(AnalysisFragmentListener listener)
Set a listener for analysis events.
|
void |
showAlertDialog(java.lang.String message,
java.lang.String positiveButtonTitle,
DialogInterface.OnClickListener positiveButtonClickListener,
java.lang.String negativeButtonTitle,
DialogInterface.OnClickListener negativeButtonClickListener,
DialogInterface.OnCancelListener cancelListener) |
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()
You should call this method when you start the document analysis using the Gini API.
|
void |
stopScanAnimation()
You should call this method when the document analysis has finished.
|
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
public void onNoExtractionsFound()
AnalysisFragmentInterface
You should call this method after you've received the analysis results from the Gini API without the required extractions.
onNoExtractionsFound
in interface AnalysisFragmentInterface
public void onDocumentAnalyzed()
AnalysisFragmentInterface
You should call this method after you've received the analysis results from the Gini API.
onDocumentAnalyzed
in interface AnalysisFragmentInterface
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 mspublic void startScanAnimation()
AnalysisFragmentInterface
You should call this method when you start the document analysis using the Gini API.
startScanAnimation
in interface AnalysisFragmentInterface
public void stopScanAnimation()
AnalysisFragmentInterface
You should call this method when the document analysis has finished.
stopScanAnimation
in interface AnalysisFragmentInterface
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 static AnalysisFragmentCompat createInstance(Document document, java.lang.String documentAnalysisErrorMessage)
Factory method for creating a new instance of the Fragment using the provided document.
You may pass in an optional analysis error message. This error message is shown to the user with a retry button.
Note: Always use this method to create new instances. Document is required and an exception is thrown if it's missing.
document
- must be the Document
from (Document)
documentAnalysisErrorMessage
- an optional error message shown to the userpublic void showAlertDialog(java.lang.String message, java.lang.String positiveButtonTitle, DialogInterface.OnClickListener positiveButtonClickListener, java.lang.String negativeButtonTitle, DialogInterface.OnClickListener negativeButtonClickListener, DialogInterface.OnCancelListener cancelListener)