Home | History | Annotate | Download | only in app
      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.autofillframework.app
     17 
     18 import android.content.Context
     19 import android.content.Intent
     20 import android.os.Bundle
     21 import android.support.v7.app.AppCompatActivity
     22 import com.example.android.autofillframework.R
     23 import kotlinx.android.synthetic.main.credit_card_compound_view_activity.clearButton
     24 import kotlinx.android.synthetic.main.credit_card_compound_view_activity.creditCardExpirationView
     25 import kotlinx.android.synthetic.main.credit_card_compound_view_activity.creditCardNumberField
     26 import kotlinx.android.synthetic.main.credit_card_compound_view_activity.submitButton
     27 
     28 class CreditCardCompoundViewActivity : AppCompatActivity() {
     29 
     30     override fun onCreate(savedInstanceState: Bundle?) {
     31         super.onCreate(savedInstanceState)
     32         setContentView(R.layout.credit_card_compound_view_activity)
     33         submitButton.setOnClickListener { submit() }
     34         clearButton.setOnClickListener { resetFields() }
     35     }
     36 
     37     private fun resetFields() {
     38         creditCardExpirationView.reset()
     39         creditCardNumberField.setText("")
     40     }
     41 
     42     /**
     43      * Launches new Activity and finishes, triggering an autofill save request if the user entered
     44      * any new data.
     45      */
     46     private fun submit() {
     47         val intent = WelcomeActivity.getStartActivityIntent(this)
     48         startActivity(intent)
     49         finish()
     50     }
     51 
     52     companion object {
     53         fun getStartActivityIntent(context: Context): Intent {
     54             val intent = Intent(context, CreditCardCompoundViewActivity::class.java)
     55             return intent
     56         }
     57     }
     58 }
     59