1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.example.android.autofill.app.edgecases; 17 18 import android.content.Context; 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.support.annotation.Nullable; 22 import android.support.v7.app.AppCompatActivity; 23 import android.view.View; 24 import android.view.autofill.AutofillManager; 25 import android.widget.EditText; 26 27 import com.example.android.autofill.app.R; 28 import com.example.android.autofill.app.WelcomeActivity; 29 30 public class CreditCardAntiPatternActivity extends AppCompatActivity { 31 32 private EditText mCcExpDateView; 33 private EditText mCcExpNumber; 34 private EditText mCcSecurityCode; 35 36 @Override onCreate(@ullable Bundle savedInstanceState)37 protected void onCreate(@Nullable Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 setContentView(R.layout.credit_card_anti_pattern_activity); 40 mCcExpDateView = findViewById(R.id.creditCardExpirationView); 41 mCcExpNumber = findViewById(R.id.creditCardNumberField); 42 mCcSecurityCode = findViewById(R.id.creditCardSecurityCode); 43 findViewById(R.id.submitButton).setOnClickListener(new View.OnClickListener() { 44 @Override 45 public void onClick(View v) { 46 submit(); 47 } 48 }); 49 findViewById(R.id.clearButton).setOnClickListener(new View.OnClickListener() { 50 @Override 51 public void onClick(View v) { 52 AutofillManager afm = getSystemService(AutofillManager.class); 53 if (afm != null) { 54 afm.cancel(); 55 } 56 resetFields(); 57 } 58 }); 59 } 60 resetFields()61 private void resetFields() { 62 mCcExpDateView.setText(""); 63 mCcExpNumber.setText(""); 64 mCcSecurityCode.setText(""); 65 } 66 67 /** 68 * Launches new Activity and finishes, triggering an autofill save request if the user entered 69 * any new data. 70 */ submit()71 private void submit() { 72 Intent intent = WelcomeActivity.getStartActivityIntent(this); 73 startActivity(intent); 74 finish(); 75 } 76 } 77