├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── ru │ │ └── adonixis │ │ └── submitcreditcardflow │ │ ├── Card.java │ │ ├── SubmitCreditCardActivity.java │ │ └── WrapContentHeightViewPager.java │ └── res │ ├── animator │ ├── card_flip_in.xml │ └── card_flip_out.xml │ ├── drawable │ ├── blue_gradient.xml │ ├── ic_close_gray_24dp.xml │ ├── ic_help_translucent_24dp.xml │ ├── ic_lock_translucent_24dp.xml │ └── ic_reset_blue_24dp.xml │ ├── font │ └── ptmono.ttf │ ├── layout │ └── activity_submit_credit_card.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-v21 │ └── styles.xml │ ├── values-v23 │ └── styles.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | /*.jks 2 | .gradle 3 | .DS_Store 4 | 5 | # generated files 6 | build/ 7 | app/build 8 | 9 | # Local configuration file (sdk path, etc) 10 | local.properties 11 | 12 | # Eclipse project files 13 | .classpath 14 | .project 15 | 16 | # Proguard folder generated by Eclipse 17 | proguard/ 18 | 19 | # Intellij project files 20 | *.iml 21 | *.ipr 22 | *.iws 23 | .idea/ 24 | 25 | # Gradle wrapper 26 | /gradle 27 | /gradlew 28 | /gradlew.bat 29 | gradle.properties 30 | 31 | app/src/androidTest/ 32 | app/src/test/ 33 | /app/google-services.json 34 | /captures/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Ilya Fomenko 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Submit Credit Card Flow 2 | Implementation of credit card form in material design. 3 | Thanks to [Azis Pradana](https://material.uplabs.com/azippy "Azis's profile on Uplabs") for his [animation.](https://material.uplabs.com/posts/submit-credit-card-flow-gif-animation "Page of animation on UpLabs") 4 | 5 | ![Demo gif](https://cloud.githubusercontent.com/assets/1766863/22521376/afb55130-e8d9-11e6-92e2-e6bcbf2ba6aa.gif) 6 | 7 | License 8 | ====== 9 | 10 | ``` 11 | Copyright 2017 Ilya Fomenko 12 | 13 | Licensed under the Apache License, Version 2.0 (the "License"); 14 | you may not use this file except in compliance with the License. 15 | You may obtain a copy of the License at 16 | 17 | http://www.apache.org/licenses/LICENSE-2.0 18 | 19 | Unless required by applicable law or agreed to in writing, software 20 | distributed under the License is distributed on an "AS IS" BASIS, 21 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | See the License for the specific language governing permissions and 23 | limitations under the License. 24 | ``` -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.1" 6 | 7 | dexOptions { 8 | javaMaxHeapSize "2g" 9 | } 10 | 11 | dataBinding { 12 | enabled = true 13 | } 14 | 15 | defaultConfig { 16 | applicationId "ru.adonixis.submitcreditcardflow" 17 | minSdkVersion 16 18 | targetSdkVersion 26 19 | versionCode 1 20 | versionName "1.0" 21 | vectorDrawables.useSupportLibrary = true 22 | } 23 | 24 | buildTypes { 25 | release { 26 | minifyEnabled true 27 | shrinkResources true 28 | zipAlignEnabled true 29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 30 | } 31 | 32 | debug { 33 | minifyEnabled false 34 | debuggable true 35 | proguardFiles getDefaultProguardFile('proguard-android.txt') 36 | } 37 | } 38 | } 39 | 40 | dependencies { 41 | compile 'com.android.support:appcompat-v7:26.0.0' 42 | compile 'com.android.support:cardview-v7:26.0.0' 43 | compile 'com.android.support:design:26.0.0' 44 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 45 | } 46 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in H:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/ru/adonixis/submitcreditcardflow/Card.java: -------------------------------------------------------------------------------- 1 | package ru.adonixis.submitcreditcardflow; 2 | 3 | public class Card { 4 | 5 | private String cardNumber; 6 | private String expiredDate; 7 | private String cardHolder; 8 | private String cvvCode; 9 | 10 | public Card() { 11 | } 12 | 13 | public Card(String cardNumber, String expiredDate, String cardHolder, String cvvCode) { 14 | this.cardNumber = cardNumber; 15 | this.expiredDate = expiredDate; 16 | this.cardHolder = cardHolder; 17 | this.cvvCode = cvvCode; 18 | } 19 | 20 | public String getCardNumber() { 21 | return cardNumber; 22 | } 23 | 24 | public void setCardNumber(String cardNumber) { 25 | this.cardNumber = cardNumber; 26 | } 27 | 28 | public String getExpiredDate() { 29 | return expiredDate; 30 | } 31 | 32 | public void setExpiredDate(String expiredDate) { 33 | this.expiredDate = expiredDate; 34 | } 35 | 36 | public String getCardHolder() { 37 | return cardHolder; 38 | } 39 | 40 | public void setCardHolder(String cardHolder) { 41 | this.cardHolder = cardHolder; 42 | } 43 | 44 | public String getCvvCode() { 45 | return cvvCode; 46 | } 47 | 48 | public void setCvvCode(String cvvCode) { 49 | this.cvvCode = cvvCode; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Card info:\r\n" + 55 | "Card number = " + cardNumber + "\r\n" + 56 | "Expired date = " + expiredDate + "\r\n" + 57 | "Card holder = " + cardHolder + "\r\n" + 58 | "CVV code = " + cvvCode; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/ru/adonixis/submitcreditcardflow/SubmitCreditCardActivity.java: -------------------------------------------------------------------------------- 1 | package ru.adonixis.submitcreditcardflow; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorInflater; 5 | import android.animation.AnimatorSet; 6 | import android.animation.ObjectAnimator; 7 | import android.content.Context; 8 | import android.content.res.Resources; 9 | import android.databinding.DataBindingUtil; 10 | import android.graphics.Point; 11 | import android.os.Bundle; 12 | import android.os.Handler; 13 | import android.support.v4.view.PagerAdapter; 14 | import android.support.v4.view.ViewPager; 15 | import android.support.v7.app.AppCompatActivity; 16 | import android.text.Editable; 17 | import android.text.TextWatcher; 18 | import android.util.DisplayMetrics; 19 | import android.view.Display; 20 | import android.view.KeyEvent; 21 | import android.view.Menu; 22 | import android.view.MenuItem; 23 | import android.view.View; 24 | import android.view.ViewGroup; 25 | import android.view.WindowManager; 26 | import android.view.animation.DecelerateInterpolator; 27 | import android.view.inputmethod.EditorInfo; 28 | import android.view.inputmethod.InputMethodManager; 29 | import android.widget.TextView; 30 | import android.widget.Toast; 31 | 32 | import ru.adonixis.submitcreditcardflow.databinding.ActivitySubmitCreditCardBinding; 33 | 34 | public class SubmitCreditCardActivity extends AppCompatActivity { 35 | 36 | private boolean showingGray = true; 37 | private AnimatorSet inSet; 38 | private AnimatorSet outSet; 39 | private ActivitySubmitCreditCardBinding activitySubmitCreditCardBinding; 40 | private Card card; 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | 46 | activitySubmitCreditCardBinding = DataBindingUtil.setContentView(this, R.layout.activity_submit_credit_card); 47 | card = new Card(); 48 | 49 | setSupportActionBar(activitySubmitCreditCardBinding.toolbar); 50 | 51 | View.OnClickListener onHelpClickListener = new View.OnClickListener() { 52 | @Override 53 | public void onClick(View v) { 54 | Toast.makeText(SubmitCreditCardActivity.this, "The CVV Number (\"Card Verification Value\") is a 3 or 4 digit number on your credit and debit cards", Toast.LENGTH_LONG).show(); 55 | } 56 | }; 57 | 58 | activitySubmitCreditCardBinding.iconHelpGray.setOnClickListener(onHelpClickListener); 59 | activitySubmitCreditCardBinding.iconHelpBlue.setOnClickListener(onHelpClickListener); 60 | 61 | activitySubmitCreditCardBinding.inputEditCardNumber.addTextChangedListener(new TextWatcher() { 62 | 63 | private boolean lock; 64 | 65 | @Override 66 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 67 | } 68 | 69 | @Override 70 | public void onTextChanged(CharSequence s, int start, int before, int count) { 71 | if (s.length() != 0) { 72 | flipToBlue(); 73 | } 74 | } 75 | 76 | @Override 77 | public void afterTextChanged(Editable s) { 78 | if (lock || s.length() > 16) { 79 | return; 80 | } 81 | lock = true; 82 | for (int i = 4; i < s.length(); i += 5) { 83 | if (s.toString().charAt(i) != ' ') { 84 | s.insert(i, " "); 85 | } 86 | } 87 | lock = false; 88 | } 89 | }); 90 | 91 | activitySubmitCreditCardBinding.inputEditExpiredDate.addTextChangedListener(new TextWatcher() { 92 | 93 | private boolean lock; 94 | 95 | @Override 96 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 97 | } 98 | 99 | @Override 100 | public void onTextChanged(CharSequence s, int start, int before, int count) { 101 | 102 | } 103 | 104 | @Override 105 | public void afterTextChanged(Editable s) { 106 | if (lock || s.length() > 4) { 107 | return; 108 | } 109 | lock = true; 110 | if (s.length() > 2 && s.toString().charAt(2) != '/') { 111 | s.insert(2, "/"); 112 | } 113 | lock = false; 114 | } 115 | }); 116 | 117 | Display display = getWindowManager().getDefaultDisplay(); 118 | Point size = new Point(); 119 | display.getSize(size); 120 | int width = size.x; 121 | int height = size.y; 122 | 123 | PagerAdapter adapter = new MyPagerAdapter(); 124 | activitySubmitCreditCardBinding.viewPager.setAdapter(adapter); 125 | activitySubmitCreditCardBinding.viewPager.setClipToPadding(false); 126 | activitySubmitCreditCardBinding.viewPager.setPadding(width / 4, 0, width / 4, 0); 127 | activitySubmitCreditCardBinding.viewPager.setPageMargin(width / 14); 128 | activitySubmitCreditCardBinding.viewPager.setPagingEnabled(false); 129 | activitySubmitCreditCardBinding.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { 130 | @Override 131 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 132 | } 133 | 134 | @Override 135 | public void onPageSelected(int position) { 136 | switch (position) { 137 | case 0: 138 | updateProgressBar(25); 139 | activitySubmitCreditCardBinding.inputEditCardNumber.setFocusableInTouchMode(true); 140 | activitySubmitCreditCardBinding.inputEditExpiredDate.setFocusable(false); 141 | activitySubmitCreditCardBinding.inputEditCardHolder.setFocusable(false); 142 | activitySubmitCreditCardBinding.inputEditCvvCode.setFocusable(false); 143 | activitySubmitCreditCardBinding.inputEditCardNumber.requestFocus(); 144 | return; 145 | case 1: 146 | updateProgressBar(50); 147 | activitySubmitCreditCardBinding.inputEditCardNumber.setFocusable(false); 148 | activitySubmitCreditCardBinding.inputEditExpiredDate.setFocusableInTouchMode(true); 149 | activitySubmitCreditCardBinding.inputEditCardHolder.setFocusable(false); 150 | activitySubmitCreditCardBinding.inputEditCvvCode.setFocusable(false); 151 | activitySubmitCreditCardBinding.inputEditExpiredDate.requestFocus(); 152 | return; 153 | case 2: 154 | updateProgressBar(75); 155 | activitySubmitCreditCardBinding.inputEditCardNumber.setFocusable(false); 156 | activitySubmitCreditCardBinding.inputEditExpiredDate.setFocusable(false); 157 | activitySubmitCreditCardBinding.inputEditCardHolder.setFocusableInTouchMode(true); 158 | activitySubmitCreditCardBinding.inputEditCvvCode.setFocusable(false); 159 | activitySubmitCreditCardBinding.inputEditCardHolder.requestFocus(); 160 | return; 161 | case 3: 162 | updateProgressBar(100); 163 | activitySubmitCreditCardBinding.inputEditCardNumber.setFocusable(false); 164 | activitySubmitCreditCardBinding.inputEditExpiredDate.setFocusable(false); 165 | activitySubmitCreditCardBinding.inputEditCardHolder.setFocusable(false); 166 | activitySubmitCreditCardBinding.inputEditCvvCode.setFocusableInTouchMode(true); 167 | activitySubmitCreditCardBinding.inputEditCvvCode.requestFocus(); 168 | return; 169 | case 4: 170 | activitySubmitCreditCardBinding.inputEditCardNumber.setFocusable(false); 171 | activitySubmitCreditCardBinding.inputEditExpiredDate.setFocusable(false); 172 | activitySubmitCreditCardBinding.inputEditCardHolder.setFocusable(false); 173 | activitySubmitCreditCardBinding.inputEditCvvCode.setFocusable(false); 174 | return; 175 | } 176 | } 177 | 178 | @Override 179 | public void onPageScrollStateChanged(int state) { 180 | } 181 | }); 182 | 183 | TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() { 184 | @Override 185 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 186 | boolean handled = false; 187 | if (actionId == EditorInfo.IME_ACTION_NEXT) { 188 | activitySubmitCreditCardBinding.viewPager.setCurrentItem(activitySubmitCreditCardBinding.viewPager.getCurrentItem() + 1); 189 | handled = true; 190 | } 191 | if (actionId == EditorInfo.IME_ACTION_DONE) { 192 | submit(); 193 | handled = true; 194 | } 195 | return handled; 196 | } 197 | }; 198 | 199 | activitySubmitCreditCardBinding.inputEditCardNumber.setOnEditorActionListener(onEditorActionListener); 200 | activitySubmitCreditCardBinding.inputEditExpiredDate.setOnEditorActionListener(onEditorActionListener); 201 | activitySubmitCreditCardBinding.inputEditCardHolder.setOnEditorActionListener(onEditorActionListener); 202 | activitySubmitCreditCardBinding.inputEditCvvCode.setOnEditorActionListener(onEditorActionListener); 203 | 204 | activitySubmitCreditCardBinding.inputEditCardNumber.requestFocus(); 205 | 206 | inSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.card_flip_in); 207 | outSet = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.card_flip_out); 208 | } 209 | 210 | private class MyPagerAdapter extends PagerAdapter { 211 | 212 | @Override 213 | public Object instantiateItem(ViewGroup container, int position) { 214 | int resId = 0; 215 | switch (position) { 216 | case 0: 217 | resId = R.id.input_layout_card_number; 218 | break; 219 | case 1: 220 | resId = R.id.input_layout_expired_date; 221 | break; 222 | case 2: 223 | resId = R.id.input_layout_card_holder; 224 | break; 225 | case 3: 226 | resId = R.id.input_layout_cvv_code; 227 | break; 228 | case 4: 229 | resId = R.id.space; 230 | break; 231 | 232 | } 233 | return findViewById(resId); 234 | } 235 | 236 | 237 | @Override 238 | public void destroyItem(ViewGroup container, int position, Object object) { 239 | } 240 | 241 | 242 | @Override 243 | public int getCount() { 244 | return 5; 245 | } 246 | 247 | @Override 248 | public boolean isViewFromObject(View view, Object object) { 249 | return view == object; 250 | } 251 | } 252 | 253 | private void hideKeyboard(View view) { 254 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 255 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 256 | } 257 | 258 | private void showKeyboard(View view) { 259 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 260 | imm.showSoftInput(view, 0); 261 | } 262 | 263 | private void updateProgressBar(int progress) { 264 | ObjectAnimator animation = ObjectAnimator.ofInt(activitySubmitCreditCardBinding.progressHorizontal, "progress", progress); 265 | animation.setDuration(300); 266 | animation.setInterpolator(new DecelerateInterpolator()); 267 | animation.start(); 268 | } 269 | 270 | private void submit() { 271 | activitySubmitCreditCardBinding.viewPager.setCurrentItem(4); 272 | card.setCardNumber(activitySubmitCreditCardBinding.inputEditCardNumber.getText().toString()); 273 | card.setExpiredDate(activitySubmitCreditCardBinding.inputEditExpiredDate.getText().toString()); 274 | card.setCardHolder(activitySubmitCreditCardBinding.inputEditCardHolder.getText().toString()); 275 | card.setCvvCode(activitySubmitCreditCardBinding.inputEditCvvCode.getText().toString()); 276 | Toast.makeText(SubmitCreditCardActivity.this, card.toString(), Toast.LENGTH_LONG).show(); 277 | 278 | new Handler().postDelayed(new Runnable() { 279 | @Override 280 | public void run() { 281 | activitySubmitCreditCardBinding.inputLayoutCvvCode.setVisibility(View.INVISIBLE); 282 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); 283 | activitySubmitCreditCardBinding.labelSecureSubmission.setVisibility(View.VISIBLE); 284 | hideKeyboard(activitySubmitCreditCardBinding.inputEditCvvCode); 285 | activitySubmitCreditCardBinding.progressCircle.setVisibility(View.VISIBLE); 286 | } 287 | }, 300); 288 | } 289 | 290 | private void reset() { 291 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 292 | 293 | activitySubmitCreditCardBinding.inputLayoutCvvCode.setVisibility(View.VISIBLE); 294 | activitySubmitCreditCardBinding.progressCircle.setVisibility(View.GONE); 295 | activitySubmitCreditCardBinding.labelSecureSubmission.setVisibility(View.GONE); 296 | flipToGray(); 297 | activitySubmitCreditCardBinding.viewPager.setCurrentItem(0); 298 | activitySubmitCreditCardBinding.inputEditCardNumber.setText(""); 299 | activitySubmitCreditCardBinding.inputEditExpiredDate.setText(""); 300 | activitySubmitCreditCardBinding.inputEditCardHolder.setText(""); 301 | activitySubmitCreditCardBinding.inputEditCvvCode.setText(""); 302 | activitySubmitCreditCardBinding.inputEditCardNumber.requestFocus(); 303 | showKeyboard(activitySubmitCreditCardBinding.inputEditCardNumber); 304 | } 305 | 306 | private void flipToGray() { 307 | if (!showingGray && !outSet.isRunning() && !inSet.isRunning()) { 308 | showingGray = true; 309 | 310 | activitySubmitCreditCardBinding.cardBlue.setCardElevation(0); 311 | activitySubmitCreditCardBinding.cardGray.setCardElevation(0); 312 | 313 | outSet.setTarget(activitySubmitCreditCardBinding.cardBlue); 314 | outSet.start(); 315 | 316 | inSet.setTarget(activitySubmitCreditCardBinding.cardGray); 317 | inSet.addListener(new Animator.AnimatorListener() { 318 | @Override 319 | public void onAnimationStart(Animator animation) { 320 | 321 | } 322 | 323 | @Override 324 | public void onAnimationEnd(Animator animation) { 325 | activitySubmitCreditCardBinding.cardGray.setCardElevation(convertDpToPixel(12, SubmitCreditCardActivity.this)); 326 | } 327 | 328 | @Override 329 | public void onAnimationCancel(Animator animation) { 330 | 331 | } 332 | 333 | @Override 334 | public void onAnimationRepeat(Animator animation) { 335 | 336 | } 337 | }); 338 | inSet.start(); 339 | } 340 | } 341 | 342 | private void flipToBlue() { 343 | if (showingGray && !outSet.isRunning() && !inSet.isRunning()) { 344 | showingGray = false; 345 | 346 | activitySubmitCreditCardBinding.cardGray.setCardElevation(0); 347 | activitySubmitCreditCardBinding.cardBlue.setCardElevation(0); 348 | 349 | outSet.setTarget(activitySubmitCreditCardBinding.cardGray); 350 | outSet.start(); 351 | 352 | inSet.setTarget(activitySubmitCreditCardBinding.cardBlue); 353 | inSet.addListener(new Animator.AnimatorListener() { 354 | @Override 355 | public void onAnimationStart(Animator animation) { 356 | 357 | } 358 | 359 | @Override 360 | public void onAnimationEnd(Animator animation) { 361 | activitySubmitCreditCardBinding.cardBlue.setCardElevation(convertDpToPixel(12, SubmitCreditCardActivity.this)); 362 | } 363 | 364 | @Override 365 | public void onAnimationCancel(Animator animation) { 366 | 367 | } 368 | 369 | @Override 370 | public void onAnimationRepeat(Animator animation) { 371 | 372 | } 373 | }); 374 | inSet.start(); 375 | } 376 | } 377 | 378 | public static float convertDpToPixel(float dp, Context context){ 379 | Resources resources = context.getResources(); 380 | DisplayMetrics metrics = resources.getDisplayMetrics(); 381 | float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); 382 | return px; 383 | } 384 | 385 | public static float convertPixelsToDp(float px, Context context){ 386 | Resources resources = context.getResources(); 387 | DisplayMetrics metrics = resources.getDisplayMetrics(); 388 | float dp = px / ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); 389 | return dp; 390 | } 391 | 392 | @Override 393 | public boolean onCreateOptionsMenu(Menu menu) { 394 | super.onCreateOptionsMenu(menu); 395 | getMenuInflater().inflate(R.menu.menu_main, menu); 396 | return true; 397 | } 398 | 399 | @Override 400 | public boolean onOptionsItemSelected(MenuItem item) { 401 | switch (item.getItemId()) { 402 | case R.id.action_reset: 403 | reset(); 404 | return true; 405 | case android.R.id.home: 406 | finish(); 407 | return true; 408 | } 409 | return super.onOptionsItemSelected(item); 410 | } 411 | 412 | } 413 | -------------------------------------------------------------------------------- /app/src/main/java/ru/adonixis/submitcreditcardflow/WrapContentHeightViewPager.java: -------------------------------------------------------------------------------- 1 | package ru.adonixis.submitcreditcardflow; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewPager; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | 9 | public class WrapContentHeightViewPager extends ViewPager { 10 | 11 | private boolean enabled; 12 | 13 | public WrapContentHeightViewPager(Context context) { 14 | super(context); 15 | this.enabled = true; 16 | } 17 | 18 | public WrapContentHeightViewPager(Context context, AttributeSet attrs) { 19 | super(context, attrs); 20 | this.enabled = true; 21 | } 22 | 23 | @Override 24 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 25 | int height = 0; 26 | for (int i = 0; i < getChildCount(); i++) { 27 | View child = getChildAt(i); 28 | child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 29 | int h = child.getMeasuredHeight(); 30 | if (h > height) height = h; 31 | } 32 | 33 | heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); 34 | 35 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 36 | } 37 | 38 | 39 | @Override 40 | public boolean onTouchEvent(MotionEvent event) { 41 | if (this.enabled) { 42 | return super.onTouchEvent(event); 43 | } 44 | 45 | return false; 46 | } 47 | 48 | @Override 49 | public boolean onInterceptTouchEvent(MotionEvent event) { 50 | if (this.enabled) { 51 | return super.onInterceptTouchEvent(event); 52 | } 53 | 54 | return false; 55 | } 56 | 57 | public void setPagingEnabled(boolean enabled) { 58 | this.enabled = enabled; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/res/animator/card_flip_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 14 | 20 | 26 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/animator/card_flip_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 14 | 19 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/blue_gradient.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_close_gray_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_help_translucent_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_lock_translucent_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_reset_blue_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/font/ptmono.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adonixis/android-submit-credit-card-flow/27cf5d281ea210585b82256a0aa093f1a14bf866/app/src/main/res/font/ptmono.ttf -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_submit_credit_card.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 17 | 18 | 24 | 25 | 33 | 34 | 35 | 36 | 42 | 43 | 57 | 58 | 64 | 65 | 82 | 83 | 103 | 104 | 121 | 122 | 142 | 143 | 152 | 153 | 154 | 155 | 156 | 157 | 171 | 172 | 178 | 179 | 194 | 195 | 213 | 214 | 229 | 230 | 247 | 248 | 257 | 258 | 259 | 260 | 261 | 262 | 269 | 270 | 276 | 277 | 289 | 290 | 291 | 292 | 298 | 299 | 312 | 313 | 314 | 315 | 321 | 322 | 334 | 335 | 336 | 337 | 343 | 344 | 357 | 358 | 359 | 360 | 365 | 366 | 367 | 368 | 376 | 377 | 386 | 387 | 397 | 398 | 413 | 414 | 415 | 416 | 417 | 418 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adonixis/android-submit-credit-card-flow/27cf5d281ea210585b82256a0aa093f1a14bf866/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adonixis/android-submit-credit-card-flow/27cf5d281ea210585b82256a0aa093f1a14bf866/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adonixis/android-submit-credit-card-flow/27cf5d281ea210585b82256a0aa093f1a14bf866/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adonixis/android-submit-credit-card-flow/27cf5d281ea210585b82256a0aa093f1a14bf866/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adonixis/android-submit-credit-card-flow/27cf5d281ea210585b82256a0aa093f1a14bf866/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values-v23/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #F0F5F5 4 | #80FFFFFF 5 | #243037 6 | 7 | #59AAFF 8 | #2C7DE3 9 | #1C6AC9 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Submit Credit Card 3 | 4 | Reset 5 | 6 | XXXX XXXX XXXX XXXX 7 | MM/YY 8 | CARD HOLDER 9 | CVV CODE 10 | 11 | 16-DIGIT CARD NUMBER 12 | EXPIRED DATE 13 | CARD HOLDER 14 | CVV CODE 15 | 16 | Secure Submission 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 16 | 17 | 20 | 21 |