Skip to content

Commit

Permalink
Merge branch 'master' into PR
Browse files Browse the repository at this point in the history
  • Loading branch information
sharish authored Jan 10, 2017
2 parents ed20fd4 + dd00f00 commit 0c4b944
Show file tree
Hide file tree
Showing 23 changed files with 236 additions and 135 deletions.
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.DS_Store

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties

# Eclipse project files
.classpath
.project

# Android Studio
.idea/
.gradle
/*/local.properties
/*/out
/*/*/build
build
/*/*/production
*.iml
*.iws
*.ipr
*~
*.swp
*.alloc
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ repositories {
}
dependencies {
compile 'com.github.cooltechworks:CreditCardView:v1.0.1'
compile 'com.github.cooltechworks:CreditCardView:v1.0.2'
}
```
- Add the following activity to your AndroidManifest.xml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
341292733940663
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ public void onClick(View v) {
intent.putExtra(CreditCardUtils.EXTRA_CARD_HOLDER_NAME, cardHolderName);
intent.putExtra(CreditCardUtils.EXTRA_CARD_NUMBER, cardNumber);
intent.putExtra(CreditCardUtils.EXTRA_CARD_EXPIRY, expiry);
intent.putExtra(CreditCardUtils.EXTRA_CARD_CVV, cvv);
intent.putExtra(CreditCardUtils.EXTRA_CARD_SHOW_CARD_SIDE, CreditCardUtils.CARD_SIDE_FRONT);
intent.putExtra(CreditCardUtils.EXTRA_VALIDATE_EXPIRY_DATE, true);
intent.putExtra(CreditCardUtils.EXTRA_CARD_SHOW_CARD_SIDE, CreditCardUtils.CARD_SIDE_BACK);
intent.putExtra(CreditCardUtils.EXTRA_VALIDATE_EXPIRY_DATE, false);

// start at the CVV activity to edit it as it is not being passed
intent.putExtra(CreditCardUtils.EXTRA_ENTRY_START_PAGE, CreditCardUtils.CARD_CVV_PAGE);
startActivityForResult(intent, index);
}
});
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
classpath 'com.android.tools.build:gradle:2.2.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
1 change: 0 additions & 1 deletion creditcarddesign/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ android {
}

dependencies {

final SUPPORT_VERSION = "25.0.1"
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:$SUPPORT_VERSION"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import com.cooltechworks.creditcarddesign.pager.CardFragmentAdapter;
import com.cooltechworks.creditcarddesign.pager.CardFragmentAdapter.ICardEntryCompleteListener;

import static com.cooltechworks.creditcarddesign.CreditCardUtils.CARD_NAME_PAGE;
import static com.cooltechworks.creditcarddesign.CreditCardUtils.EXTRA_CARD_CVV;
import static com.cooltechworks.creditcarddesign.CreditCardUtils.EXTRA_CARD_EXPIRY;
import static com.cooltechworks.creditcarddesign.CreditCardUtils.EXTRA_CARD_HOLDER_NAME;
import static com.cooltechworks.creditcarddesign.CreditCardUtils.*;

import static com.cooltechworks.creditcarddesign.CreditCardUtils.EXTRA_CARD_NUMBER;
import static com.cooltechworks.creditcarddesign.CreditCardUtils.EXTRA_ENTRY_START_PAGE;


public class CardEditActivity extends AppCompatActivity {
Expand All @@ -34,6 +35,7 @@ public class CardEditActivity extends AppCompatActivity {
private String mCVV;
private String mCardHolderName;
private String mExpiry;
private int mStartPage = 0;
private CardFragmentAdapter mCardAdapter;

@Override
Expand All @@ -49,11 +51,10 @@ public void onClick(View v) {

int max = pager.getAdapter().getCount();

if(pager.getCurrentItem() == max -1) {
if (pager.getCurrentItem() == max - 1) {
// if last card.
onDoneTapped();
}
else {
} else {
showNext();
}
}
Expand All @@ -67,65 +68,66 @@ public void onClick(View v) {

setKeyboardVisibility(true);
mCreditCardView = (CreditCardView) findViewById(R.id.credit_card_view);
Bundle args = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();

checkParams(args);
loadPager(args);


if(savedInstanceState != null) {
checkParams(savedInstanceState);
if (mStartPage > 0 && mStartPage <= CARD_NAME_PAGE) {
getViewPager().setCurrentItem(mStartPage);
}
else {
checkParams(getIntent().getExtras());
}

loadPager();

}

private void checkParams(Bundle bundle) {


if(bundle == null) {
if (bundle == null) {
return;
}
mCardHolderName = bundle.getString(EXTRA_CARD_HOLDER_NAME);
mCVV = bundle.getString(EXTRA_CARD_CVV);
mExpiry = bundle.getString(EXTRA_CARD_EXPIRY);
mCardNumber = bundle.getString(EXTRA_CARD_NUMBER);
mStartPage = bundle.getInt(EXTRA_ENTRY_START_PAGE);


int maxCvvLength = CardSelector.selectCard(mCardNumber).getCvvLength();
if (mCVV != null && mCVV.length() >= maxCvvLength) {
mCVV = mCVV.substring(0, maxCvvLength);
}

mCreditCardView.setCVV(mCVV);
mCreditCardView.setCardHolderName(mCardHolderName);
mCreditCardView.setCardExpiry(mExpiry);
mCreditCardView.setCardNumber(mCardNumber);



if(mCardAdapter != null) {
if (mCardAdapter != null) {
mCardAdapter.setMaxCVV(maxCvvLength);
mCardAdapter.notifyDataSetChanged();
}
}

public void refreshNextButton() {

ViewPager pager = (ViewPager) findViewById(R.id.card_field_container_pager);

int max = pager.getAdapter().getCount();

int text = R.string.next;

if(pager.getCurrentItem() == max -1) {
if (pager.getCurrentItem() == max - 1) {
text = R.string.done;
}

((TextView)findViewById(R.id.next)).setText(text);
((TextView) findViewById(R.id.next)).setText(text);
}

public void loadPager() {
ViewPager getViewPager() {
return (ViewPager) findViewById(R.id.card_field_container_pager);
}

ViewPager pager = (ViewPager) findViewById(R.id.card_field_container_pager);
public void loadPager(Bundle bundle) {
ViewPager pager = getViewPager();
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}

@Override
public void onPageSelected(int position) {
Expand All @@ -145,25 +147,27 @@ public void onPageSelected(int position) {
}

@Override
public void onPageScrollStateChanged(int state) {}
public void onPageScrollStateChanged(int state) {
}
});
pager.setOffscreenPageLimit(4);

mCardAdapter = new CardFragmentAdapter(getSupportFragmentManager(),getIntent().getExtras());
mCardAdapter = new CardFragmentAdapter(getSupportFragmentManager(), bundle);
mCardAdapter.setOnCardEntryCompleteListener(new ICardEntryCompleteListener() {
@Override
public void onCardEntryComplete(int currentIndex) {

showNext();
}

@Override
public void onCardEntryEdit(int currentIndex, String entryValue) {
switch (currentIndex) {
case 0:

mCardNumber = entryValue.replace(CreditCardUtils.SPACE_SEPERATOR,"");
mCardNumber = entryValue.replace(CreditCardUtils.SPACE_SEPERATOR, "");
mCreditCardView.setCardNumber(mCardNumber);
if (mCardAdapter != null) {
mCardAdapter.setMaxCVV(CardSelector.selectCard(mCardNumber).getCvvLength());
}
break;
case 1:
mExpiry = entryValue;
Expand All @@ -174,7 +178,7 @@ public void onCardEntryEdit(int currentIndex, String entryValue) {
mCreditCardView.setCVV(entryValue);
break;
case 3:
mCardHolderName = entryValue;
mCardHolderName = entryValue;
mCreditCardView.setCardHolderName(entryValue);
break;
}
Expand All @@ -184,18 +188,16 @@ public void onCardEntryEdit(int currentIndex, String entryValue) {
pager.setAdapter(mCardAdapter);

int cardSide = getIntent().getIntExtra(CreditCardUtils.EXTRA_CARD_SHOW_CARD_SIDE, CreditCardUtils.CARD_SIDE_FRONT);
if(cardSide == CreditCardUtils.CARD_SIDE_BACK) {
pager.setCurrentItem(2);
if (cardSide == CreditCardUtils.CARD_SIDE_BACK) {
pager.setCurrentItem(2);
}
}

public void onSaveInstanceState(Bundle outState) {

outState.putString(EXTRA_CARD_CVV,mCVV);
outState.putString(EXTRA_CARD_HOLDER_NAME,mCardHolderName);
outState.putString(EXTRA_CARD_EXPIRY,mExpiry);
outState.putString(EXTRA_CARD_NUMBER,mCardNumber);

outState.putString(EXTRA_CARD_CVV, mCVV);
outState.putString(EXTRA_CARD_HOLDER_NAME, mCardHolderName);
outState.putString(EXTRA_CARD_EXPIRY, mExpiry);
outState.putString(EXTRA_CARD_NUMBER, mCardNumber);

super.onSaveInstanceState(outState);
}
Expand All @@ -207,10 +209,14 @@ public void onRestoreInstanceState(Bundle inState) {


public void showPrevious() {

final ViewPager pager = (ViewPager) findViewById(R.id.card_field_container_pager);
int currentIndex = pager.getCurrentItem();

if (currentIndex == 0) {
setResult(RESULT_CANCELED);
finish();
}

if (currentIndex - 1 >= 0) {
pager.setCurrentItem(currentIndex - 1);
}
Expand All @@ -219,7 +225,6 @@ public void showPrevious() {
}

public void showNext() {

final ViewPager pager = (ViewPager) findViewById(R.id.card_field_container_pager);
CardFragmentAdapter adapter = (CardFragmentAdapter) pager.getAdapter();

Expand All @@ -238,27 +243,22 @@ public void showNext() {
}

private void onDoneTapped() {

Intent intent = new Intent();

intent.putExtra(EXTRA_CARD_CVV, mCVV);
intent.putExtra(EXTRA_CARD_HOLDER_NAME, mCardHolderName);
intent.putExtra(EXTRA_CARD_EXPIRY, mExpiry);
intent.putExtra(EXTRA_CARD_NUMBER, mCardNumber);


setResult(RESULT_OK,intent);
setResult(RESULT_OK, intent);
finish();


}

// from the link above
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);


// Checks whether a hardware keyboard is available
if (newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {

Expand All @@ -271,10 +271,8 @@ public void onConfigurationChanged(Configuration newConfig) {
}

private void setKeyboardVisibility(boolean visible) {

final EditText editText = (EditText) findViewById(R.id.card_number_field);


if (!visible) {

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
Expand All @@ -283,11 +281,9 @@ private void setKeyboardVisibility(boolean visible) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}

@Override
public void onBackPressed() {
this.finish();
}


}
Loading

0 comments on commit 0c4b944

Please sign in to comment.