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 android.autofillservice.cts;
17 
18 import android.content.Intent;
19 import android.os.Bundle;
20 import android.widget.Button;
21 import android.widget.EditText;
22 import android.widget.TextView;
23 
24 /**
25  * A simple activity that upon submission launches {@link SimpleSaveActivity}.
26  */
27 public class PreSimpleSaveActivity extends AbstractAutoFillActivity {
28 
29     static final String ID_PRE_LABEL = "preLabel";
30     static final String ID_PRE_INPUT = "preInput";
31 
32     private static PreSimpleSaveActivity sInstance;
33 
34     TextView mPreLabel;
35     EditText mPreInput;
36     Button mSubmit;
37 
getInstance()38     public static PreSimpleSaveActivity getInstance() {
39         return sInstance;
40     }
41 
PreSimpleSaveActivity()42     public PreSimpleSaveActivity() {
43         sInstance = this;
44     }
45 
46     @Override
onCreate(Bundle savedInstanceState)47     protected void onCreate(Bundle savedInstanceState) {
48         super.onCreate(savedInstanceState);
49 
50         setContentView(R.layout.pre_simple_save_activity);
51 
52         mPreLabel = findViewById(R.id.preLabel);
53         mPreInput = findViewById(R.id.preInput);
54         mSubmit = findViewById(R.id.submit);
55 
56         mSubmit.setOnClickListener((v) -> {
57             finish();
58             startActivity(new Intent(this, SimpleSaveActivity.class));
59         });
60     }
61 
expectAutoFill(String input)62     public FillExpectation expectAutoFill(String input) {
63         final FillExpectation expectation = new FillExpectation(input);
64         mPreInput.addTextChangedListener(expectation.mInputWatcher);
65         return expectation;
66     }
67 
getPreInput()68     public EditText getPreInput() {
69         return mPreInput;
70     }
71 
72     public final class FillExpectation {
73         private final OneTimeTextWatcher mInputWatcher;
74 
FillExpectation(String input)75         private FillExpectation(String input) {
76             mInputWatcher = new OneTimeTextWatcher("input", mPreInput, input);
77         }
78 
assertAutoFilled()79         public void assertAutoFilled() throws Exception {
80             mInputWatcher.assertAutoFilled();
81         }
82     }
83 }
84