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 
17 package com.example.android.autofill.app.commoncases;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.support.annotation.Nullable;
23 import android.support.v7.app.AppCompatActivity;
24 import android.view.View;
25 import android.view.autofill.AutofillManager;
26 import android.widget.EditText;
27 
28 import com.example.android.autofill.app.R;
29 import com.example.android.autofill.app.WelcomeActivity;
30 import com.example.android.autofill.app.view.autofillable.CreditCardExpirationDateCompoundView;
31 
32 public class CreditCardCompoundViewActivity extends AppCompatActivity {
33 
34     private CreditCardExpirationDateCompoundView mCcExpDateView;
35     private EditText mCcExpNumber;
36     private EditText mCcSecurityCode;
37 
38     @Override
onCreate(@ullable Bundle savedInstanceState)39     protected void onCreate(@Nullable Bundle savedInstanceState) {
40         super.onCreate(savedInstanceState);
41         setContentView(R.layout.credit_card_compound_view_activity);
42         mCcExpDateView = findViewById(R.id.creditCardExpirationView);
43         mCcExpNumber = findViewById(R.id.creditCardNumberField);
44         mCcSecurityCode = findViewById(R.id.creditCardSecurityCode);
45         findViewById(R.id.submitButton).setOnClickListener(new View.OnClickListener() {
46             @Override
47             public void onClick(View v) {
48                 submit();
49             }
50         });
51         findViewById(R.id.clearButton).setOnClickListener(new View.OnClickListener() {
52             @Override
53             public void onClick(View v) {
54                 AutofillManager afm = getSystemService(AutofillManager.class);
55                 if (afm != null) {
56                     afm.cancel();
57                 }
58                 resetFields();
59             }
60         });
61     }
62 
resetFields()63     private void resetFields() {
64         mCcExpDateView.reset();
65         mCcExpNumber.setText("");
66         mCcSecurityCode.setText("");
67     }
68 
69     /**
70      * Launches new Activity and finishes, triggering an autofill save request if the user entered
71      * any new data.
72      */
submit()73     private void submit() {
74         Intent intent = WelcomeActivity.getStartActivityIntent(this);
75         startActivity(intent);
76         finish();
77     }
78 }
79