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

[WIP] Enabled Card Form Activity #95

Open
wants to merge 2 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
8 changes: 7 additions & 1 deletion SampleApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.1.3'
}
}

repositories {
jcenter()
maven {
url 'https://oss.sonatype.org/content/repositories/releases/'
}
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}

apply plugin: 'com.android.application'
Expand Down
9 changes: 5 additions & 4 deletions SampleApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.my.scanExample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
xmlns:tools="http://schemas.android.com/tools"
package="org.my.scanExample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" tools:overrideLibrary="com.braintreepayments.cardform" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import io.card.payment.CardIOActivity;
import io.card.payment.CreditCard;
import io.card.payment.ManualActivity;

public class MyScanActivity extends Activity {
final String TAG = getClass().getName();
Expand Down Expand Up @@ -51,7 +52,7 @@ public void onScanPress(View v) {

// customize these values to suit your needs.
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, true); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_RESTRICT_POSTAL_CODE_TO_NUMERIC_ONLY, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CARDHOLDER_NAME, false); // default: false
Expand Down Expand Up @@ -103,5 +104,9 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
resultTextView.setText(resultStr);

}

public void onManualClick(View view) {
startActivity(new Intent(this, ManualActivity.class));
}
}

8 changes: 8 additions & 0 deletions SampleApp/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
android:text="Scan a credit card with card.io"
android:onClick="onScanPress"/>

<Button
android:id="@+id/manual_entry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:text="Manual"
android:onClick="onManualClick" />

<TextView
android:id="@+id/resultTextView"
android:layout_width="match_parent"
Expand Down
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.1.3'
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3"
}
}

task assemble {}

ext {
compileSdkVersion = 24
buildToolsVersion = '24.0.1'
Expand Down
9 changes: 8 additions & 1 deletion card.io/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ apply plugin: 'io.codearte.nexus-staging'

repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/releases/'
}
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}

def getBuildVersion = { ->
Expand All @@ -23,7 +29,7 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
minSdkVersion 8
minSdkVersion 9
targetSdkVersion 23

buildConfigField "String", "PRODUCT_NAME", "\"${product_name}\""
Expand Down Expand Up @@ -76,6 +82,7 @@ android {
}

dependencies {
compile 'com.braintreepayments:card-form:3.0.0-SNAPSHOT'
androidTestCompile "com.jayway.android.robotium:robotium-solo:5.2.1"
}

Expand Down
10 changes: 7 additions & 3 deletions card.io/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.card.payment" android:versionCode="2"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18"/>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="18"/>

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.VIBRATE"/>

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<application>
<activity android:name="io.card.payment.CardIOActivity" android:configChanges="keyboardHidden|orientation"/>
<activity android:name="io.card.payment.DataEntryActivity"/>
<activity
android:name=".CardIOActivity"
android:configChanges="keyboardHidden|orientation" />
<activity android:name=".DataEntryActivity" />
<activity android:name=".ManualActivity"
android:theme="@style/LightTheme"></activity>
</application>

</manifest>
4 changes: 2 additions & 2 deletions card.io/src/main/java/io/card/payment/CardIOActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ private void nextActivity() {

final Intent origIntent = getIntent();
if (origIntent != null && origIntent.getBooleanExtra(EXTRA_SUPPRESS_CONFIRMATION, false)) {
Intent dataIntent = new Intent(CardIOActivity.this, DataEntryActivity.class);
Intent dataIntent = new Intent(CardIOActivity.this, ManualActivity.class);
if (mDetectedCard != null) {
dataIntent.putExtra(EXTRA_SCAN_RESULT, mDetectedCard);
mDetectedCard = null;
Expand All @@ -861,7 +861,7 @@ public void run() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

Intent dataIntent = new Intent(CardIOActivity.this, DataEntryActivity.class);
Intent dataIntent = new Intent(CardIOActivity.this, ManualActivity.class);
Util.writeCapturedCardImageIfNecessary(origIntent, dataIntent, mOverlay);

if (mOverlay != null) {
Expand Down
110 changes: 110 additions & 0 deletions card.io/src/main/java/io/card/payment/ManualActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package io.card.payment;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.braintreepayments.cardform.OnCardFormSubmitListener;
import com.braintreepayments.cardform.utils.CardType;
import com.braintreepayments.cardform.view.CardEditText;
import com.braintreepayments.cardform.view.CardForm;
import com.braintreepayments.cardform.view.ErrorEditText;
import com.braintreepayments.cardform.view.SupportedCardTypesView;

import io.card.payment.i18n.LocalizedStrings;
import io.card.payment.i18n.StringKey;
import io.card.payment.ui.ActivityHelper;

public class ManualActivity extends AppCompatActivity implements OnCardFormSubmitListener,
CardEditText.OnCardTypeChangedListener {

private static final com.braintreepayments.cardform.utils.CardType[] SUPPORTED_CARD_TYPES = { com.braintreepayments.cardform.utils.CardType.VISA, com.braintreepayments.cardform.utils.CardType.MASTERCARD, com.braintreepayments.cardform.utils.CardType.DISCOVER,
com.braintreepayments.cardform.utils.CardType.AMEX, com.braintreepayments.cardform.utils.CardType.DINERS_CLUB, com.braintreepayments.cardform.utils.CardType.JCB, com.braintreepayments.cardform.utils.CardType.MAESTRO, com.braintreepayments.cardform.utils.CardType.UNIONPAY };

private SupportedCardTypesView mSupportedCardTypesView;

protected CardForm mCardForm;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

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

LocalizedStrings.setLanguage(getIntent());
CreditCard capture = getIntent().getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);

setContentView(R.layout.card_form);

boolean requireExpiry = getIntent().getBooleanExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, false);
boolean requireCVV = getIntent().getBooleanExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false);
boolean requirePostalCode = getIntent().getBooleanExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false);

mSupportedCardTypesView = (SupportedCardTypesView) findViewById(R.id.supported_card_types);
mSupportedCardTypesView.setSupportedCardTypes(SUPPORTED_CARD_TYPES);

mCardForm = (CardForm) findViewById(R.id.card_form);
mCardForm.cardRequired(true)
.expirationRequired(requireExpiry)
.cvvRequired(requireCVV)
.postalCodeRequired(requirePostalCode)
.mobileNumberRequired(false)
.actionLabel(getString(R.string.purchase))
.setup(this);
mCardForm.setOnCardFormSubmitListener(this);
mCardForm.setOnCardTypeChangedListener(this);


String cvvText = LocalizedStrings.getString(StringKey.ENTRY_CVV);
mCardForm.getCvvEditText().setHint(cvvText);

if (mCardForm.getCvvEditText().getTextInputLayoutParent() != null) {
mCardForm.getCvvEditText().getTextInputLayoutParent().setHint(cvvText);
} else {
mCardForm.getCvvEditText().setHint(cvvText);
}

if (capture != null) {
((ErrorEditText)mCardForm.findViewById(R.id.bt_card_form_card_number)).setText(capture.cardNumber);
((ErrorEditText)mCardForm.findViewById(R.id.bt_card_form_card_number)).focusNextView();
}

}

@Override
public void onCardTypeChanged(com.braintreepayments.cardform.utils.CardType cardType) {
if (cardType == CardType.EMPTY) {
mSupportedCardTypesView.setSupportedCardTypes(SUPPORTED_CARD_TYPES);
} else {
mSupportedCardTypesView.setSelected(cardType);
}
}

@Override
public void onCardFormSubmit() {
if (mCardForm.isValid()) {
// TODO: We need cardform to have CardHolderNameEditText
CreditCard result = new CreditCard(mCardForm.getCardNumber(), Integer.valueOf(mCardForm.getExpirationMonth()),
Integer.valueOf(mCardForm.getExpirationYear()), mCardForm.getCvv(), mCardForm.getPostalCode(),
"Card Name");
Intent dataIntent = new Intent();
dataIntent.putExtra(CardIOActivity.EXTRA_SCAN_RESULT, result);
if(getIntent().hasExtra(CardIOActivity.EXTRA_CAPTURED_CARD_IMAGE)){
dataIntent.putExtra(CardIOActivity.EXTRA_CAPTURED_CARD_IMAGE,
getIntent().getByteArrayExtra(CardIOActivity.EXTRA_CAPTURED_CARD_IMAGE));
}
ManualActivity.this.setResult(CardIOActivity.RESULT_CARD_INFO, dataIntent);
finish();
Toast.makeText(this, R.string.valid, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, R.string.invalid, Toast.LENGTH_SHORT).show();
}
}

public void onClick(View v) {
onCardFormSubmit();
}
}
41 changes: 41 additions & 0 deletions card.io/src/main/res/layout/card_form.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<com.braintreepayments.cardform.view.SupportedCardTypesView
android:id="@+id/supported_card_types"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="20dp" />

<com.braintreepayments.cardform.view.CardForm
android:id="@+id/card_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/bt_margin"/>

<Button
android:id="@+id/material_dark_theme_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/submit"
android:textAllCaps="true"
android:onClick="onClick" />
</LinearLayout>

</ScrollView>

</LinearLayout>
6 changes: 6 additions & 0 deletions card.io/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="light_theme_primary">#a5d6a7</color>
<color name="light_theme_primary_dark">#164313</color>
<color name="light_theme_accent">#61d395</color>
</resources>
5 changes: 5 additions & 0 deletions card.io/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
6 changes: 6 additions & 0 deletions card.io/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<string name="purchase">Purchase</string>
<string name="valid">Form is valid</string>
<string name="invalid">Form is invalid</string>
<string name="submit">Submit</string>
</resources>
11 changes: 11 additions & 0 deletions card.io/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LightTheme" parent="Theme.AppCompat.Light">
<!-- color for the app bar -->
<item name="colorPrimary">@color/light_theme_primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">@color/light_theme_primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">@color/light_theme_accent</item>
</style>
</resources>
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Mon Aug 08 16:12:31 CDT 2016
#Fri Sep 09 16:12:13 CDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
4 changes: 1 addition & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
include 'card.io'

include 'SampleApp'
include ':card.io', ':SampleApp'