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

Fix 158 #160

Open
wants to merge 3 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
28 changes: 13 additions & 15 deletions SampleApp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.0.1'
}
}

repositories {
jcenter()
google()
maven {
url "https://jitpack.io"
}
Expand All @@ -17,13 +19,12 @@ repositories {
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 27

defaultConfig {
applicationId "io.card.development"
minSdkVersion 18
targetSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0.0"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
Expand All @@ -37,24 +38,21 @@ android {
}

android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
output.outputFile = new File(outputFile.parent, "card.io-sample-app-${variant.name}.apk")
variant.outputs.all {
if (outputFileName.endsWith('.apk')) {
outputFileName = "card.io-sample-app-${variant.name}.apk"
}
}
}
}

dependencies {
if (parent != null) {
compile project(':card.io')
implementation project(':card.io')
} else {
compile 'io.card:android-sdk:REPLACE_VERSION'
implementation 'io.card:android-sdk:REPLACE_VERSION'
}

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4'

androidTestCompile "com.android.support.test.espresso:espresso-core:2.2.2"
androidTestCompile "com.github.lkorth:device-automator:01d85912ec"
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.4'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2-alpha1'
androidTestImplementation 'com.github.lkorth:device-automator:01d85912ec'
}
56 changes: 33 additions & 23 deletions SampleApp/src/main/java/io/card/development/SampleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class SampleActivity extends Activity {
private CheckBox mUseCardIOLogoToggle;
private CheckBox mShowPayPalActionBarIconToggle;
private CheckBox mKeepApplicationThemeToggle;
private CheckBox mLockOrientationToggle;
private CheckBox mAddOverlayToggle;
private Spinner mLanguageSpinner;
private EditText mUnblurEdit;

Expand All @@ -64,29 +66,32 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_activity);

mManualToggle = (CheckBox) findViewById(R.id.force_manual);
mEnableExpiryToggle = (CheckBox) findViewById(R.id.gather_expiry);
mScanExpiryToggle = (CheckBox) findViewById(R.id.scan_expiry);
mCvvToggle = (CheckBox) findViewById(R.id.gather_cvv);
mPostalCodeToggle = (CheckBox) findViewById(R.id.gather_postal_code);
mPostalCodeNumericOnlyToggle = (CheckBox) findViewById(R.id.postal_code_numeric_only);
mCardholderNameToggle = (CheckBox) findViewById(R.id.gather_cardholder_name);
mSuppressManualToggle = (CheckBox) findViewById(R.id.suppress_manual);
mSuppressConfirmationToggle = (CheckBox) findViewById(R.id.suppress_confirmation);
mSuppressScanToggle = (CheckBox) findViewById(R.id.detect_only);

mUseCardIOLogoToggle = (CheckBox) findViewById(R.id.use_card_io_logo);
mShowPayPalActionBarIconToggle = (CheckBox) findViewById(R.id.show_paypal_action_bar_icon);
mKeepApplicationThemeToggle = (CheckBox) findViewById(R.id.keep_application_theme);

mLanguageSpinner = (Spinner) findViewById(R.id.language);
mUnblurEdit = (EditText) findViewById(R.id.unblur);

mResultLabel = (TextView) findViewById(R.id.result);
mResultImage = (ImageView) findViewById(R.id.result_image);
mResultCardTypeImage = (ImageView) findViewById(R.id.result_card_type_image);

TextView version = (TextView) findViewById(R.id.version);
mManualToggle = findViewById(R.id.force_manual);
mEnableExpiryToggle = findViewById(R.id.gather_expiry);
mScanExpiryToggle = findViewById(R.id.scan_expiry);
mCvvToggle = findViewById(R.id.gather_cvv);
mPostalCodeToggle = findViewById(R.id.gather_postal_code);
mPostalCodeNumericOnlyToggle = findViewById(R.id.postal_code_numeric_only);
mCardholderNameToggle = findViewById(R.id.gather_cardholder_name);
mSuppressManualToggle = findViewById(R.id.suppress_manual);
mSuppressConfirmationToggle = findViewById(R.id.suppress_confirmation);
mSuppressScanToggle = findViewById(R.id.detect_only);

mUseCardIOLogoToggle = findViewById(R.id.use_card_io_logo);
mShowPayPalActionBarIconToggle = findViewById(R.id.show_paypal_action_bar_icon);
mKeepApplicationThemeToggle = findViewById(R.id.keep_application_theme);

mLockOrientationToggle = findViewById(R.id.lock_orientation);
mAddOverlayToggle = findViewById(R.id.add_overlay);

mLanguageSpinner = findViewById(R.id.language);
mUnblurEdit = findViewById(R.id.unblur);

mResultLabel = findViewById(R.id.result);
mResultImage = findViewById(R.id.result_image);
mResultCardTypeImage = findViewById(R.id.result_card_type_image);

TextView version = findViewById(R.id.version);
version.setText("card.io library: " + CardIOActivity.sdkVersion() + "\n" +
"Build date: " + CardIOActivity.sdkBuildDate());

Expand Down Expand Up @@ -116,11 +121,16 @@ public void onScan(View pressed) {
.putExtra(CardIOActivity.EXTRA_LANGUAGE_OR_LOCALE, (String) mLanguageSpinner.getSelectedItem())
.putExtra(CardIOActivity.EXTRA_USE_PAYPAL_ACTIONBAR_ICON, mShowPayPalActionBarIconToggle.isChecked())
.putExtra(CardIOActivity.EXTRA_KEEP_APPLICATION_THEME, mKeepApplicationThemeToggle.isChecked())
.putExtra(CardIOActivity.EXTRA_LOCK_ORIENTATION, mLockOrientationToggle.isChecked())
.putExtra(CardIOActivity.EXTRA_GUIDE_COLOR, Color.GREEN)
.putExtra(CardIOActivity.EXTRA_SUPPRESS_CONFIRMATION, mSuppressConfirmationToggle.isChecked())
.putExtra(CardIOActivity.EXTRA_SUPPRESS_SCAN, mSuppressScanToggle.isChecked())
.putExtra(CardIOActivity.EXTRA_RETURN_CARD_IMAGE, true);

if (mAddOverlayToggle.isChecked()) {
intent.putExtra(CardIOActivity.EXTRA_SCAN_OVERLAY_LAYOUT_ID, R.layout.overlay_layout);
}

try {
int unblurDigits = Integer.parseInt(mUnblurEdit.getText().toString());
intent.putExtra(CardIOActivity.EXTRA_UNBLUR_DIGITS, unblurDigits);
Expand Down
32 changes: 32 additions & 0 deletions SampleApp/src/main/res/layout/overlay_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="32dp">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="top|center_horizontal"
android:text="OVERLAY MESSAGE" />

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="OVERLAY MESSAGE" />

<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom|center_horizontal"
android:text="OVERLAY MESSAGE" />

</LinearLayout>
12 changes: 12 additions & 0 deletions SampleApp/src/main/res/layout/sample_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@
android:layout_height="wrap_content"
android:text="Keep application theme"/>

<CheckBox
android:id="@+id/lock_orientation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lock orientation"/>

<CheckBox
android:id="@+id/add_overlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show sample overlay layout"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3"
}
}

task assemble {}

ext {
sdkVersion = 25
buildToolsVersion = '25.0.2'
sdkVersion = 27
buildToolsVersion = '27.0.3'
}

repositories {
google()
}
5 changes: 3 additions & 2 deletions card.io/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ 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 javadocs(type: Javadoc) {
Expand All @@ -50,6 +50,7 @@ task javadocs(type: Javadoc) {
options.version(true)
options.use(true)
options.setMemberLevel(JavadocMemberLevel.PUBLIC)
options.encoding = 'UTF-8'

// enables links to Java 7 docs
options.links("http://docs.oracle.com/javase/7/docs/api/")
Expand Down
35 changes: 25 additions & 10 deletions card.io/src/main/java/io/card/payment/CardIOActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ public final class CardIOActivity extends Activity {
*/
public static final String EXTRA_KEEP_APPLICATION_THEME = "io.card.payment.keepApplicationTheme";

/**
* Boolean extra. Optional. If this value is set to <code>true</code>, the scanner view will
* remain in portrait mode. Default value is {@code false}.
*/
public static final String EXTRA_LOCK_ORIENTATION = "io.card.payment.lockOrientation";


/**
* Boolean extra. Used for testing only.
Expand Down Expand Up @@ -305,6 +311,8 @@ public final class CardIOActivity extends Activity {

private boolean manualEntryFallbackOrForced = false;

private boolean mOrientationLocked;

/**
* Static variable for the decorated card image. This is ugly, but works. Parceling and
* unparceling card image data to pass to the next {@link android.app.Activity} does not work because the image
Expand All @@ -326,6 +334,8 @@ protected void onCreate(Bundle savedInstanceState) {

final Intent clientData = this.getIntent();

mOrientationLocked = clientData.getBooleanExtra(EXTRA_LOCK_ORIENTATION, false);

useApplicationTheme = getIntent().getBooleanExtra(CardIOActivity.EXTRA_KEEP_APPLICATION_THEME, false);
ActivityHelper.setActivityTheme(this, useApplicationTheme);

Expand Down Expand Up @@ -468,13 +478,15 @@ private void showCameraScannerOverlay() {

setPreviewLayout();

orientationListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_UI) {
@Override
public void onOrientationChanged(int orientation) {
doOrientationChange(orientation);
}
};
if (!mOrientationLocked) {
orientationListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_UI) {
@Override
public void onOrientationChanged(int orientation) {
doOrientationChange(orientation);
}
};
}

} catch (Exception e) {
handleGeneralExceptionError(e);
Expand All @@ -497,7 +509,7 @@ private void doOrientationChange(int orientation) {
return;
}

orientation += mCardScanner.getRotationalOffset();
orientation += mOrientationLocked ? 0 : mCardScanner.getRotationalOffset();

// Check if we have gone too far forward with
// rotation adjustment, keep the result between 0-360
Expand Down Expand Up @@ -560,7 +572,10 @@ protected void onResume() {
ActivityHelper.setFlagSecure(this);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
orientationListener.enable();

if (orientationListener != null && !mOrientationLocked) {
orientationListener.enable();
}

if (!restartPreview()) {
StringKey error = StringKey.ERROR_CAMERA_UNEXPECTED_FAIL;
Expand All @@ -571,7 +586,7 @@ protected void onResume() {
setFlashOn(false);
}

doOrientationChange(mLastDegrees);
doOrientationChange(mOrientationLocked ? 0 : mLastDegrees);
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip