blob: ea6fb58f4775e80978965709f47f74cd90eb79be [file] [log] [blame]
Joel Fernandesb5fbd412017-10-26 12:24:30 -07001/*
2 * Copyright (C) 2015 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
17package com.android.benchmark.ui;
18
19import android.content.Intent;
20import android.os.Bundle;
21import android.support.v7.app.ActionBar;
22import android.support.v7.app.AppCompatActivity;
23import android.view.KeyEvent;
24import android.widget.EditText;
25
26import com.android.benchmark.R;
27import com.android.benchmark.ui.automation.Automator;
28import com.android.benchmark.ui.automation.Interaction;
29
30public class EditTextInputActivity extends AppCompatActivity {
31
32 private Automator mAutomator;
33 @Override
34 protected void onCreate(Bundle savedInstanceState) {
35 super.onCreate(savedInstanceState);
36 final EditText editText = new EditText(this);
37 final int runId = getIntent().getIntExtra("com.android.benchmark.RUN_ID", 0);
38 final int iteration = getIntent().getIntExtra("com.android.benchmark.ITERATION", -1);
39
40 editText.setWidth(400);
41 editText.setHeight(200);
42 setContentView(editText);
43
44 String testName = getString(R.string.edit_text_input_name);
45
46 ActionBar actionBar = getSupportActionBar();
47 if (actionBar != null) {
48 actionBar.setTitle(testName);
49 }
50
51 mAutomator = new Automator(testName, runId, iteration, getWindow(),
52 new Automator.AutomateCallback() {
53 @Override
54 public void onPostAutomate() {
55 Intent result = new Intent();
56 setResult(RESULT_OK, result);
57 finish();
58 }
59
60 @Override
61 public void onAutomate() {
62
63 int[] coordinates = new int[2];
64 editText.getLocationOnScreen(coordinates);
65
66 int x = coordinates[0];
67 int y = coordinates[1];
68
69 float width = editText.getWidth();
70 float height = editText.getHeight();
71
72 float middleX = (x + width) / 2;
73 float middleY = (y + height) / 2;
74
75 Interaction tap = Interaction.newTap(middleX, middleY);
76 addInteraction(tap);
77
78 int[] alphabet = {
79 KeyEvent.KEYCODE_A,
80 KeyEvent.KEYCODE_B,
81 KeyEvent.KEYCODE_C,
82 KeyEvent.KEYCODE_D,
83 KeyEvent.KEYCODE_E,
84 KeyEvent.KEYCODE_F,
85 KeyEvent.KEYCODE_G,
86 KeyEvent.KEYCODE_H,
87 KeyEvent.KEYCODE_I,
88 KeyEvent.KEYCODE_J,
89 KeyEvent.KEYCODE_K,
90 KeyEvent.KEYCODE_L,
91 KeyEvent.KEYCODE_M,
92 KeyEvent.KEYCODE_N,
93 KeyEvent.KEYCODE_O,
94 KeyEvent.KEYCODE_P,
95 KeyEvent.KEYCODE_Q,
96 KeyEvent.KEYCODE_R,
97 KeyEvent.KEYCODE_S,
98 KeyEvent.KEYCODE_T,
99 KeyEvent.KEYCODE_U,
100 KeyEvent.KEYCODE_V,
101 KeyEvent.KEYCODE_W,
102 KeyEvent.KEYCODE_X,
103 KeyEvent.KEYCODE_Y,
104 KeyEvent.KEYCODE_Z,
105 KeyEvent.KEYCODE_SPACE
106 };
107 Interaction typeAlphabet = Interaction.newKeyInput(new int[] {
108 KeyEvent.KEYCODE_A,
109 KeyEvent.KEYCODE_B,
110 KeyEvent.KEYCODE_C,
111 KeyEvent.KEYCODE_D,
112 KeyEvent.KEYCODE_E,
113 KeyEvent.KEYCODE_F,
114 KeyEvent.KEYCODE_G,
115 KeyEvent.KEYCODE_H,
116 KeyEvent.KEYCODE_I,
117 KeyEvent.KEYCODE_J,
118 KeyEvent.KEYCODE_K,
119 KeyEvent.KEYCODE_L,
120 KeyEvent.KEYCODE_M,
121 KeyEvent.KEYCODE_N,
122 KeyEvent.KEYCODE_O,
123 KeyEvent.KEYCODE_P,
124 KeyEvent.KEYCODE_Q,
125 KeyEvent.KEYCODE_R,
126 KeyEvent.KEYCODE_S,
127 KeyEvent.KEYCODE_T,
128 KeyEvent.KEYCODE_U,
129 KeyEvent.KEYCODE_V,
130 KeyEvent.KEYCODE_W,
131 KeyEvent.KEYCODE_X,
132 KeyEvent.KEYCODE_Y,
133 KeyEvent.KEYCODE_Z,
134 KeyEvent.KEYCODE_SPACE,
135 });
136
137 for (int i = 0; i < 5; i++) {
138 addInteraction(typeAlphabet);
139 }
140 }
141 });
142 mAutomator.start();
143 }
144
145 @Override
146 protected void onPause() {
147 super.onPause();
148 if (mAutomator != null) {
149 mAutomator.cancel();
150 mAutomator = null;
151 }
152 }
153
154 private String getRunFilename() {
155 StringBuilder builder = new StringBuilder();
156 builder.append(getClass().getSimpleName());
157 builder.append(System.currentTimeMillis());
158 return builder.toString();
159 }
160}