Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Card.io as a Fragment implementation #162

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions card.io/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ android {

ndk {
moduleName "cardioRecognizer"
abiFilters 'armeabi-v7a', 'arm64-v8a'
}

consumerProguardFiles 'proguard.cfg'
Expand All @@ -34,10 +35,18 @@ android {
}

dependencies {
testCompile "junit:junit:4.12"
testCompile "org.robolectric:robolectric:3.1.2"
testImplementation "junit:junit:4.12"
testImplementation "org.robolectric:robolectric:3.1.2"
}

task ndkClean(type: Delete) {
// remove unused archs from build cache
delete fileTree('.externalNativeBuild') {
exclude android.defaultConfig.ndk.abiFilters.collect { '/**' + it }
}
}
tasks.findByPath(':clean').dependsOn ndkClean

task javadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
Expand Down
38 changes: 30 additions & 8 deletions card.io/src/main/java/io/card/payment/CardIOActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

import io.card.payment.i18n.LocalizedStrings;
import io.card.payment.i18n.StringKey;
import io.card.payment.interfaces.CardIOCameraControl;
import io.card.payment.interfaces.CardScanRecognition;
import io.card.payment.ui.ActivityHelper;
import io.card.payment.ui.Appearance;
import io.card.payment.ui.ViewUtil;
Expand All @@ -55,7 +57,7 @@
*
* @version 1.0
*/
public final class CardIOActivity extends Activity {
public final class CardIOActivity extends Activity implements CardScanRecognition, CardIOCameraControl {
/**
* Boolean extra. Optional. Defaults to <code>false</code>. If set, the card will not be scanned
* with the camera.
Expand Down Expand Up @@ -462,7 +464,7 @@ private void showCameraScannerOverlay() {
mCardScanner = (CardScanner) cons.newInstance(new Object[] { this,
mFrameOrientation });
} else {
mCardScanner = new CardScanner(this, mFrameOrientation);
mCardScanner = new CardScanner(this, mFrameOrientation, false);
}
mCardScanner.prepareScanner();

Expand Down Expand Up @@ -733,11 +735,30 @@ void onFirstFrame() {
onEdgeUpdate(new DetectionInfo());
}

void onEdgeUpdate(DetectionInfo dInfo) {
@Override
public void onEdgeUpdate(DetectionInfo dInfo) {
mOverlay.setDetectionInfo(dInfo);
}

void onCardDetected(Bitmap detectedBitmap, DetectionInfo dInfo) {
@Override
public Activity getActivity() {
return this;
}

@Override
public void onFirstFrame(int orientation) {
SurfaceView sv = mPreview.getSurfaceView();
if (mOverlay != null) {
mOverlay.setCameraPreviewRect(new Rect(sv.getLeft(), sv.getTop(), sv.getRight(), sv
.getBottom()));
}
mFrameOrientation = ORIENTATION_PORTRAIT;
setDeviceDegrees(0);

onEdgeUpdate(new DetectionInfo());
}
@Override
public void onCardDetected(Bitmap detectedBitmap, DetectionInfo dInfo) {
try {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_PATTERN, -1);
Expand Down Expand Up @@ -873,7 +894,8 @@ private void setDeviceDegrees(int degrees) {
}

// Called by OverlayView
void toggleFlash() {
@Override
public void toggleFlash() {
setFlashOn(!mCardScanner.isFlashOn());
}

Expand All @@ -883,8 +905,8 @@ void setFlashOn(boolean b) {
mOverlay.setTorchOn(b);
}
}

void triggerAutoFocus() {
@Override
public void triggerAutoFocus() {
mCardScanner.triggerAutoFocus(true);
}

Expand All @@ -908,7 +930,7 @@ private void setPreviewLayout() {
LayoutParams.MATCH_PARENT, Gravity.TOP));
previewFrame.addView(mPreview);

mOverlay = new OverlayView(this, null, Util.deviceSupportsTorch(this));
mOverlay = new OverlayView(this, this, null, Util.deviceSupportsTorch(this));
mOverlay.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
if (getIntent() != null) {
Expand Down
153 changes: 153 additions & 0 deletions card.io/src/main/java/io/card/payment/CardIOConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package io.card.payment;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;

/**
* Created by glaubermartins on 2018-04-04.
*/

public class CardIOConstants {

/**
* Boolean extra. Optional. Defaults to <code>false</code>. If set, the card will not be scanned
* with the camera.
*/
public static final String EXTRA_NO_CAMERA = "io.card.payment.noCamera";

/**
* Boolean extra. Optional. Defaults to <code>false</code>. If set, the user will be prompted
* for the cardholder name.
*/
public static final String EXTRA_REQUIRE_CARDHOLDER_NAME = "io.card.payment.requireCardholderName";

/**
* Boolean extra. Optional. Defaults to <code>false</code>. If set, the card.io logo will be
* shown instead of the PayPal logo.
*/
public static final String EXTRA_USE_CARDIO_LOGO = "io.card.payment.useCardIOLogo";

/**
* Boolean extra. Optional. Defaults to <code>false</code>. Removes the keyboard button from the
* scan screen.
* <br><br>
* If scanning is unavailable, the {@link android.app.Activity} result will be {@link #RESULT_SCAN_NOT_AVAILABLE}.
*/
public static final String EXTRA_SUPPRESS_MANUAL_ENTRY = "io.card.payment.suppressManual";

/**
* String extra. Optional. The preferred language for all strings appearing in the user
* interface. If not set, or if set to null, defaults to the device's current language setting.
* <br><br>
* Can be specified as a language code ("en", "fr", "zh-Hans", etc.) or as a locale ("en_AU",
* "fr_FR", "zh-Hant_TW", etc.).
* <br><br>
* If the library does not contain localized strings for a specified locale, then will fall back
* to the language. E.g., "es_CO" -&gt; "es".
* <br><br>
* If the library does not contain localized strings for a specified language, then will fall
* back to American English.
* <br><br>
* If you specify only a language code, and that code matches the device's currently preferred
* language, then the library will attempt to use the device's current region as well. E.g.,
* specifying "en" on a device set to "English" and "United Kingdom" will result in "en_GB".
* <br><br>
* These localizations are currently included:
* <br><br>
* ar, da, de, en, en_AU, en_GB, es, es_MX, fr, he, is, it, ja, ko, ms, nb, nl, pl, pt, pt_BR, ru,
* sv, th, tr, zh-Hans, zh-Hant, zh-Hant_TW.
*/
public static final String EXTRA_LANGUAGE_OR_LOCALE = "io.card.payment.languageOrLocale";

/**
* Integer extra. Optional. Defaults to {@link Color#GREEN}. Changes the color of the guide overlay on the
* camera.
*/
public static final String EXTRA_GUIDE_COLOR = "io.card.payment.guideColor";

/**
* Boolean extra. Optional. Defaults to <code>false</code>. When set to <code>true</code> the card.io logo
* will not be shown overlaid on the camera.
*/
public static final String EXTRA_HIDE_CARDIO_LOGO = "io.card.payment.hideLogo";

/**
* String extra. Optional. Used to display instructions to the user while they are scanning
* their card.
*/
public static final String EXTRA_SCAN_INSTRUCTIONS = "io.card.payment.scanInstructions";

/**
* Boolean extra. Optional. Once a card image has been captured but before it has been
* processed, this value will determine whether to continue processing as usual. If the value is
* <code>true</code> the {@link CardIOActivity} will finish with a {@link #RESULT_SCAN_SUPPRESSED} result code.
*/
public static final String EXTRA_SUPPRESS_SCAN = "io.card.payment.suppressScan";

/**
* Boolean extra. Optional. If this value is set to <code>true</code>, and the application has a theme,
* the theme for the card.io {@link android.app.Activity}s will be set to the theme of the application.
*/
public static final String EXTRA_KEEP_APPLICATION_THEME = "io.card.payment.keepApplicationTheme";


/**
* Boolean extra. Used for testing only.
*/
public static final String PRIVATE_EXTRA_CAMERA_BYPASS_TEST_MODE = "io.card.payment.cameraBypassTestMode";

public static int lastResult = 0xca8d10; // arbitrary. chosen to be well above
// Activity.RESULT_FIRST_USER.
/**
* result code supplied to {@link Activity#onActivityResult(int, int, Intent)} when a scan request completes.
*/
public static final int RESULT_CARD_INFO = lastResult++;

/**
* result code supplied to {@link Activity#onActivityResult(int, int, Intent)} when the user presses the cancel
* button.
*/
public static final int RESULT_ENTRY_CANCELED = lastResult++;

/**
* result code indicating that scan is not available. Only returned when
* {@link #EXTRA_SUPPRESS_MANUAL_ENTRY} is set and scanning is not available.
* <br><br>
* This error can be avoided in normal situations by checking
* {@link CardIOFragment#canReadCardWithCamera()}.
*/
public static final int RESULT_SCAN_NOT_AVAILABLE = lastResult++;

/**
* result code indicating that we only captured the card image.
*/
public static final int RESULT_SCAN_SUPPRESSED = lastResult++;

public static final int DEGREE_DELTA = 15;

public static final int ORIENTATION_PORTRAIT = 1;
public static final int ORIENTATION_PORTRAIT_UPSIDE_DOWN = 2;
public static final int ORIENTATION_LANDSCAPE_RIGHT = 3;
public static final int ORIENTATION_LANDSCAPE_LEFT = 4;

public static final String BUNDLE_WAITING_FOR_PERMISSION = "io.card.payment.waitingForPermission";

public static final long[] VIBRATE_PATTERN = { 0, 70, 10, 40 };

public static final int TOAST_OFFSET_Y = -75;

public static final int DATA_ENTRY_REQUEST_ID = 10;
public static final int PERMISSION_REQUEST_ID = 11;

public static final String PORTRAIT_ORIENTATION_LOCK = "PORTRAIT_ORIENTATION_LOCK";

/**
* {@link CardIOFragment#getArguments()}
*
* Reference to the id of view which will be a holder for the card.io fragment
* */
public static final String CARD_IO_VIEW = "CARD_IO_VIEW";
public static final String CARD_EXPIRY = "CARD_EXPIRY";
public static final String CARD_IO_OVERLAY_COLOUR = "CARD_IO_OVERLAY_COLOUR";
}
Loading