Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature default app dialog #242

Merged
merged 6 commits into from Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,6 +5,7 @@
import android.support.annotation.NonNull;

import net.gini.android.vision.GiniVisionFeatureConfiguration;
import net.gini.android.vision.internal.ui.FragmentImplCallback;

/**
* Created by Alpar Szotyori on 15.12.2017.
Expand All @@ -19,7 +20,7 @@ public class CameraFragmentHelperFake extends CameraFragmentHelper {
@NonNull
@Override
protected CameraFragmentImpl createCameraFragment(
@NonNull final CameraFragmentImplCallback fragment,
@NonNull final FragmentImplCallback fragment,
@NonNull final GiniVisionFeatureConfiguration giniVisionFeatureConfiguration) {
return mCameraFragmentImplFake = spy(new CameraFragmentImplFake(fragment,
giniVisionFeatureConfiguration));
Expand All @@ -28,7 +29,7 @@ protected CameraFragmentImpl createCameraFragment(
@NonNull
@Override
protected CameraFragmentImpl createCameraFragment(
@NonNull final CameraFragmentImplCallback fragment) {
@NonNull final FragmentImplCallback fragment) {
return mCameraFragmentImplFake = spy(new CameraFragmentImplFake(fragment));
}

Expand Down
Expand Up @@ -7,6 +7,7 @@
import net.gini.android.vision.document.QRCodeDocument;
import net.gini.android.vision.internal.camera.api.CameraControllerFake;
import net.gini.android.vision.internal.camera.api.CameraInterface;
import net.gini.android.vision.internal.ui.FragmentImplCallback;

/**
* Created by Alpar Szotyori on 15.12.2017.
Expand All @@ -21,12 +22,12 @@ public class CameraFragmentImplFake extends CameraFragmentImpl {
private QRCodeDocument mQRCodeDocument;

CameraFragmentImplFake(
@NonNull final CameraFragmentImplCallback fragment) {
@NonNull final FragmentImplCallback fragment) {
super(fragment);
}

CameraFragmentImplFake(
@NonNull final CameraFragmentImplCallback fragment,
@NonNull final FragmentImplCallback fragment,
@NonNull final GiniVisionFeatureConfiguration giniVisionFeatureConfiguration) {
super(fragment, giniVisionFeatureConfiguration);
}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions ginivision/src/doc/source/customization-guide.rst
Expand Up @@ -1853,4 +1853,59 @@ All Action Bar customizations except the title are global to all Activities.
from the `Gini Vision Library UI Assets
<https://github.com/gini/gini-vision-lib-assets>`_ repository.

:ref:`Back to screenshot. <file-import>`

Clear Defaults Dialog
----

.. raw:: html

<img src="_static/customization/Clear Defaults Dialog.png" usemap="#clear-defaults-map" width="324" height="576">

<map id="clear-defaults-map" name="clear-defaults-map">
<area shape="rect" alt="" title="Message" coords="236,139,260,166" href="customization-guide.html#clear-defaults-1" target="" />
<area shape="rect" alt="" title="File Type" coords="265,223,299,257" href="customization-guide.html#clear-defaults-1-1" target="" />
<area shape="rect" alt="" title="Positive Button Title" coords="73,329,106,362" href="customization-guide.html#clear-defaults-2" target="" />
<area shape="rect" alt="" title="Negative Button Title" coords="74,369,105,400" href="customization-guide.html#clear-defaults-3" target="" />
<!-- Created by Online Image Map Editor (http://www.maschek.hu/imagemap/index) -->
</map>

.. _clear-defaults-1:

1. Message
^^^^

Via the string resource named ``gv_file_import_default_app_dialog_message``.

.. _clear-defaults-1-1:

1.1 File Type
~~~~

- **PDF**

Via the string resources named ``gv_file_import_default_app_dialog_pdf_file_type``.

- **Image**

Via the string resources named ``gv_file_import_default_app_dialog_image_file_type``.

- **Document (Other)**

Via the string resources named ``gv_file_import_default_app_dialog_document_file_type``.

.. _clear-defaults-2:

2. Positive Button Title
~~~~

Via the string resources named ``gv_file_import_default_app_dialog_positive_button``.

.. _clear-defaults-3:

3. Negative Button Title
~~~~

Via the string resources named ``gv_file_import_default_app_dialog_negative_button``.

:ref:`Back to screenshot. <file-import>`
@@ -1,5 +1,7 @@
package net.gini.android.vision.analysis;

import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -11,39 +13,51 @@

import net.gini.android.vision.Document;
import net.gini.android.vision.internal.ui.FragmentImplCallback;
import net.gini.android.vision.internal.util.AlertDialogHelperCompat;
import net.gini.android.vision.review.ReviewFragmentListener;

/**
* <h3>Component API</h3>
*
* <p>
* When you use the Component API with the Android Support Library, the {@code AnalyzeDocumentFragmentCompat} displays the captured or imported document and an activity indicator while the document is being analyzed by the Gini API.
* When you use the Component API with the Android Support Library, the {@code
* AnalyzeDocumentFragmentCompat} displays the captured or imported document and an activity
* indicator while the document is being analyzed by the Gini API.
* </p>
* <p>
* <b>Note:</b> You can use the activity indicator message to display a message under the activity indicator by overriding the string resource named {@code gv_analysis_activity_indicator_message}. The message is displayed for images only.
* <b>Note:</b> You can use the activity indicator message to display a message under the activity
* indicator by overriding the string resource named {@code gv_analysis_activity_indicator_message}.
* The message is displayed for images only.
* </p>
* <p>
* 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.
* 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.
* </p>
* <p>
* <b>Note:</b> Your Activity hosting this Fragment must extend the {@link android.support.v7.app.AppCompatActivity} and use an AppCompat Theme.
* <b>Note:</b> Your Activity hosting this Fragment must extend the {@link
* android.support.v7.app.AppCompatActivity} and use an AppCompat Theme.
* </p>
* <p>
* Include the {@code AnalyzeDocumentFragmentCompat} into your layout by using the {@link AnalysisFragmentCompat#createInstance(Document, String)} factory method to create an instance and display it using the {@link android.support.v4.app.FragmentManager}.
* Include the {@code AnalyzeDocumentFragmentCompat} into your layout by using the {@link
* AnalysisFragmentCompat#createInstance(Document, String)} factory method to create an instance and
* display it using the {@link android.support.v4.app.FragmentManager}.
* </p>
* <p>
* An {@link AnalysisFragmentListener} instance must be available until the {@code 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 {@link AnalysisFragmentListener} interface or explicitly by
* setting the listener using {@link AnalysisFragmentCompat#setListener(AnalysisFragmentListener)}.
* An {@link AnalysisFragmentListener} instance must be available until the {@code
* 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
* {@link AnalysisFragmentListener} interface or explicitly by setting the listener using {@link
* AnalysisFragmentCompat#setListener(AnalysisFragmentListener)}.
* </p>
* <p>
* Your Activity is automatically set as the listener in {@link AnalysisFragmentCompat#onCreate(Bundle)}.
* Your Activity is automatically set as the listener in {@link AnalysisFragmentCompat#onCreate(Bundle)}.
* </p>
*
* <h3>Customizing the Analysis Screen</h3>
*
* <p>
* See the {@link AnalysisActivity} for details.
* See the {@link AnalysisActivity} for details.
* </p>
*/
public class AnalysisFragmentCompat extends Fragment implements FragmentImplCallback,
Expand Down Expand Up @@ -150,8 +164,7 @@ public void setListener(@NonNull final AnalysisFragmentListener listener) {
* </p>
* <p>
* You may pass in an optional analysis error message. This error message is shown to the user
* with a retry
* button.
* with a retry button.
* </p>
* <p>
* <b>Note:</b> Always use this method to create new instances. Document is required and an
Expand All @@ -162,6 +175,7 @@ public void setListener(@NonNull final AnalysisFragmentListener listener) {
* ReviewFragmentListener#onProceedToAnalysisScreen
* (Document)}
* @param documentAnalysisErrorMessage an optional error message shown to the user
*
* @return a new instance of the Fragment
*/
public static AnalysisFragmentCompat createInstance(@NonNull final Document document,
Expand All @@ -172,6 +186,22 @@ public static AnalysisFragmentCompat createInstance(@NonNull final Document docu
return fragment;
}

@Override
public void showAlertDialog(@NonNull final String message,
@NonNull final String positiveButtonTitle,
@NonNull final DialogInterface.OnClickListener positiveButtonClickListener,
@Nullable final String negativeButtonTitle,
@Nullable final DialogInterface.OnClickListener negativeButtonClickListener,
@Nullable final DialogInterface.OnCancelListener cancelListener) {
final Activity activity = getActivity();
if (activity == null) {
return;
}
AlertDialogHelperCompat.showAlertDialog(activity, message, positiveButtonTitle,
positiveButtonClickListener, negativeButtonTitle, negativeButtonClickListener,
cancelListener);
}

@VisibleForTesting
AnalysisFragmentImpl getFragmentImpl() {
return mFragmentImpl;
Expand Down
Expand Up @@ -2,6 +2,7 @@

import static net.gini.android.vision.internal.network.NetworkRequestsManager.isCancellation;
import static net.gini.android.vision.internal.util.ActivityHelper.forcePortraitOrientationOnPhones;
import static net.gini.android.vision.internal.util.FileImportHelper.showAlertIfOpenWithDocument;

import android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -50,6 +51,7 @@
import net.gini.android.vision.internal.storage.ImageDiskStore;
import net.gini.android.vision.internal.ui.ErrorSnackbar;
import net.gini.android.vision.internal.ui.FragmentImplCallback;
import net.gini.android.vision.internal.util.MimeType;
import net.gini.android.vision.internal.util.Size;
import net.gini.android.vision.network.model.GiniVisionSpecificExtraction;
import net.gini.android.vision.util.UriHelper;
Expand Down Expand Up @@ -121,7 +123,8 @@ public void onProceedToNoExtractionsScreen(@NonNull final Document document) {
private boolean mStopped;
private boolean mAnalysisCompleted;

AnalysisFragmentImpl(final FragmentImplCallback fragment, @NonNull final Document document,
AnalysisFragmentImpl(final FragmentImplCallback fragment,
@NonNull final Document document,
final String documentAnalysisErrorMessage) {
mFragment = fragment;
mMultiPageDocument = asMultiPageDocument(document);
Expand Down Expand Up @@ -283,6 +286,7 @@ public void onStart() {
if (activity == null) {
return;
}

clearParcelableMemoryCache();

startScanAnimation();
Expand Down Expand Up @@ -445,16 +449,28 @@ ProgressBar getProgressActivity() {
}

private void analyzeDocument() {
if (mFragment.getActivity() == null) {
final Activity activity = mFragment.getActivity();
if (activity == null) {
return;
}
if (mDocumentAnalysisErrorMessage != null) {
showError(mDocumentAnalysisErrorMessage,
mFragment.getActivity().getString(R.string.gv_document_analysis_error_retry),
new View.OnClickListener() {
if (MimeType.APPLICATION_PDF.asString().equals(mMultiPageDocument.getMimeType())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 🔺 cannot be avoided, can it?

showAlertIfOpenWithDocument(activity, mMultiPageDocument, mFragment)
.thenRun(new Runnable() {
@Override
public void onClick(final View v) {
doAnalyzeDocument();
public void run() {
if (mDocumentAnalysisErrorMessage != null) {
showError(mDocumentAnalysisErrorMessage,
activity.getString(
R.string.gv_document_analysis_error_retry),
new View.OnClickListener() {
@Override
public void onClick(final View v) {
doAnalyzeDocument();
}
});
} else {
doAnalyzeDocument();
}
}
});
} else {
Expand Down
@@ -1,6 +1,8 @@
package net.gini.android.vision.analysis;

import android.app.Activity;
import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -10,6 +12,7 @@

import net.gini.android.vision.Document;
import net.gini.android.vision.internal.ui.FragmentImplCallback;
import net.gini.android.vision.internal.util.AlertDialogHelperStandard;
import net.gini.android.vision.review.ReviewFragmentListener;

/**
Expand Down Expand Up @@ -167,4 +170,21 @@ public static AnalysisFragmentStandard createInstance(@NonNull final Document do
AnalysisFragmentHelper.createArguments(document, documentAnalysisErrorMessage));
return fragment;
}

@Override
public void showAlertDialog(@NonNull final String message,
@NonNull final String positiveButtonTitle,
@NonNull final DialogInterface.OnClickListener positiveButtonClickListener,
@Nullable final String negativeButtonTitle,
@Nullable final DialogInterface.OnClickListener negativeButtonClickListener,
@Nullable final DialogInterface.OnCancelListener cancelListener) {
final Activity activity = getActivity();
if (activity == null) {
return;
}
AlertDialogHelperStandard.showAlertDialog(activity, message, positiveButtonTitle,
positiveButtonClickListener, negativeButtonTitle, negativeButtonClickListener,
cancelListener);
}

}