From ed20fd439d3f435303871a202ca6ca3965c54af9 Mon Sep 17 00:00:00 2001 From: Harish Sridharan Date: Tue, 10 Jan 2017 20:02:31 +0530 Subject: [PATCH] Minor fixes and indentation fix Minor fixes and indentation fix --- .../creditcarddesign/sample/MainActivity.java | 82 ++++++++++++------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/cooltechworks/creditcarddesign/sample/MainActivity.java b/app/src/main/java/com/cooltechworks/creditcarddesign/sample/MainActivity.java index be4b7b4..aacb718 100644 --- a/app/src/main/java/com/cooltechworks/creditcarddesign/sample/MainActivity.java +++ b/app/src/main/java/com/cooltechworks/creditcarddesign/sample/MainActivity.java @@ -1,37 +1,74 @@ package com.cooltechworks.creditcarddesign.sample; import android.content.Intent; -import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; import android.view.View; +import android.widget.Button; import android.widget.LinearLayout; import com.cooltechworks.checkoutflow.R; +import com.cooltechworks.creditcarddesign.CreditCardView; import com.cooltechworks.creditcarddesign.CardEditActivity; import com.cooltechworks.creditcarddesign.CreditCardUtils; -import com.cooltechworks.creditcarddesign.CreditCardView; + +/** + * Created by glarencezhao on 10/23/16. + */ public class MainActivity extends AppCompatActivity { + private final int CREATE_NEW_CARD = 0; + + private LinearLayout cardContainer; + private Button addCardButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + initialize(); + listeners(); + } - findViewById(R.id.add_card).setOnClickListener(new View.OnClickListener() { + private void initialize() { + addCardButton = (Button) findViewById(R.id.add_card); + cardContainer = (LinearLayout) findViewById(R.id.card_container); +// getSupportActionBar().setTitle("Payment"); + populate(); + } + + private void populate() { + CreditCardView sampleCreditCardView = new CreditCardView(this); + + String name = "Glarence Zhao"; + String cvv = "420"; + String expiry = "01/18"; + String cardNumber = "4242424242424242"; + + sampleCreditCardView.setCVV(cvv); + sampleCreditCardView.setCardHolderName(name); + sampleCreditCardView.setCardExpiry(expiry); + sampleCreditCardView.setCardNumber(cardNumber); + + cardContainer.addView(sampleCreditCardView); + int index = cardContainer.getChildCount() - 1; + addCardListener(index, sampleCreditCardView); + } + + private void listeners() { + addCardButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + Intent intent = new Intent(MainActivity.this, CardEditActivity.class); - startActivityForResult(intent, 0); + startActivityForResult(intent, CREATE_NEW_CARD); } }); } - private void initListener(final int index, CreditCardView creditCardView) { - - + private void addCardListener(final int index, CreditCardView creditCardView) { creditCardView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -40,39 +77,32 @@ public void onClick(View v) { String cardNumber = creditCardView.getCardNumber(); String expiry = creditCardView.getExpiry(); String cardHolderName = creditCardView.getCardHolderName(); + String cvv = creditCardView.getCVV(); Intent intent = new Intent(MainActivity.this, CardEditActivity.class); 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, false); - + intent.putExtra(CreditCardUtils.EXTRA_VALIDATE_EXPIRY_DATE, true); startActivityForResult(intent, index); - } }); - } - - public void onActivityResult(int reqCode, int resultCode, Intent data) { - if(resultCode == RESULT_OK) { - - LinearLayout cardContainer = (LinearLayout) findViewById(R.id.card_container); - + if (resultCode == RESULT_OK) { +// Debug.printToast("Result Code is OK", getApplicationContext()); String name = data.getStringExtra(CreditCardUtils.EXTRA_CARD_HOLDER_NAME); String cardNumber = data.getStringExtra(CreditCardUtils.EXTRA_CARD_NUMBER); String expiry = data.getStringExtra(CreditCardUtils.EXTRA_CARD_EXPIRY); String cvv = data.getStringExtra(CreditCardUtils.EXTRA_CARD_CVV); - - if(reqCode == 0) { - + if (reqCode == CREATE_NEW_CARD) { CreditCardView creditCardView = new CreditCardView(this); @@ -81,14 +111,11 @@ public void onActivityResult(int reqCode, int resultCode, Intent data) { creditCardView.setCardExpiry(expiry); creditCardView.setCardNumber(cardNumber); - int index = cardContainer.getChildCount(); cardContainer.addView(creditCardView); - initListener(index, creditCardView); - + int index = cardContainer.getChildCount() - 1; + addCardListener(index, creditCardView); - - } - else { + } else { CreditCardView creditCardView = (CreditCardView) cardContainer.getChildAt(reqCode); @@ -100,7 +127,6 @@ public void onActivityResult(int reqCode, int resultCode, Intent data) { } } - } -} +} \ No newline at end of file