blob: 6c633b73629aa34f8e2f91342196da5d2b5a085a [file] [log] [blame]
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
Wink Saville79085fc2009-06-09 10:27:23 -07003 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
Wink Saville79085fc2009-06-09 10:27:23 -07007 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08008 * http://www.apache.org/licenses/LICENSE-2.0
Wink Saville79085fc2009-06-09 10:27:23 -07009 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080010 * 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.stk;
18
Takanori Nakano48544352016-12-02 18:32:59 +090019import android.app.ActionBar;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080020import android.app.Activity;
21import android.content.Context;
22import android.content.Intent;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090023import android.content.res.Configuration;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080024import android.graphics.drawable.BitmapDrawable;
25import android.os.Bundle;
26import android.os.Handler;
27import android.os.Message;
28import android.text.Editable;
29import android.text.InputFilter;
duho.roee36b6f2013-09-03 15:15:16 +090030import android.text.InputType;
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +090031import android.text.TextUtils;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080032import android.text.TextWatcher;
33import android.text.method.PasswordTransformationMethod;
Srikanth Chintalaa091b732016-02-04 14:46:43 +053034import android.view.inputmethod.EditorInfo;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080035import android.view.KeyEvent;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090036import android.view.Menu;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080037import android.view.MenuItem;
38import android.view.View;
39import android.view.Window;
40import android.widget.Button;
Takanori Nakano48544352016-12-02 18:32:59 +090041import android.widget.ImageView;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090042import android.widget.PopupMenu;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080043import android.widget.TextView;
44import android.widget.EditText;
45import android.widget.TextView.BufferType;
Wink Savillee68857d2014-10-17 15:23:05 -070046import com.android.internal.telephony.cat.CatLog;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070047import com.android.internal.telephony.cat.FontSize;
48import com.android.internal.telephony.cat.Input;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080049
50/**
51 * Display a request for a text input a long with a text edit form.
52 */
53public class StkInputActivity extends Activity implements View.OnClickListener,
54 TextWatcher {
55
56 // Members
57 private int mState;
58 private Context mContext;
59 private EditText mTextIn = null;
60 private TextView mPromptView = null;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090061 private View mMoreOptions = null;
62 private PopupMenu mPopupMenu = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080063 private View mYesNoLayout = null;
64 private View mNormalLayout = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080065
66 // Constants
Wink Savillee68857d2014-10-17 15:23:05 -070067 private static final String className = new Object(){}.getClass().getEnclosingClass().getName();
68 private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1);
69
70 private Input mStkInput = null;
71 private boolean mAcceptUsersInput = true;
72 // Constants
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080073 private static final int STATE_TEXT = 1;
74 private static final int STATE_YES_NO = 2;
75
76 static final String YES_STR_RESPONSE = "YES";
77 static final String NO_STR_RESPONSE = "NO";
78
79 // Font size factor values.
80 static final float NORMAL_FONT_FACTOR = 1;
81 static final float LARGE_FONT_FACTOR = 2;
82 static final float SMALL_FONT_FACTOR = (1 / 2);
83
Takanori Nakano1a672e62017-10-19 19:49:38 +090084 // Keys for saving the state of the activity in the bundle
85 private static final String ACCEPT_USERS_INPUT_KEY = "accept_users_input";
86 private static final String RESPONSE_SENT_KEY = "response_sent";
87 private static final String INPUT_STRING_KEY = "input_string";
88
Wink Saville79085fc2009-06-09 10:27:23 -070089 // message id for time out
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080090 private static final int MSG_ID_TIMEOUT = 1;
Wink Savillee68857d2014-10-17 15:23:05 -070091 private StkAppService appService = StkAppService.getInstance();
92
93 private boolean mIsResponseSent = false;
94 private int mSlotId = -1;
95 Activity mInstance = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080096
97 Handler mTimeoutHandler = new Handler() {
98 @Override
99 public void handleMessage(Message msg) {
100 switch(msg.what) {
101 case MSG_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -0700102 CatLog.d(LOG_TAG, "Msg timeout.");
103 mAcceptUsersInput = false;
104 appService.getStkContext(mSlotId).setPendingActivityInstance(mInstance);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800105 sendResponse(StkAppService.RES_ID_TIMEOUT);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800106 break;
107 }
108 }
109 };
110
111 // Click listener to handle buttons press..
112 public void onClick(View v) {
113 String input = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700114 if (!mAcceptUsersInput) {
115 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
116 return;
117 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800118
119 switch (v.getId()) {
120 case R.id.button_ok:
121 // Check that text entered is valid .
122 if (!verfiyTypedText()) {
Wink Savillee68857d2014-10-17 15:23:05 -0700123 CatLog.d(LOG_TAG, "handleClick, invalid text");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800124 return;
125 }
Wink Savillee68857d2014-10-17 15:23:05 -0700126 mAcceptUsersInput = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800127 input = mTextIn.getText().toString();
128 break;
Takanori Nakano260df9a2017-12-05 22:26:30 +0900129 case R.id.button_cancel:
130 mAcceptUsersInput = false;
131 cancelTimeOut();
132 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
133 sendResponse(StkAppService.RES_ID_END_SESSION);
134 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800135 // Yes/No layout buttons.
136 case R.id.button_yes:
Wink Savillee68857d2014-10-17 15:23:05 -0700137 mAcceptUsersInput = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800138 input = YES_STR_RESPONSE;
139 break;
140 case R.id.button_no:
Wink Savillee68857d2014-10-17 15:23:05 -0700141 mAcceptUsersInput = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800142 input = NO_STR_RESPONSE;
143 break;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900144 case R.id.more:
145 if (mPopupMenu == null) {
146 mPopupMenu = new PopupMenu(this, v);
147 Menu menu = mPopupMenu.getMenu();
148 createOptionsMenuInternal(menu);
149 prepareOptionsMenuInternal(menu);
150 mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
151 public boolean onMenuItemClick(MenuItem item) {
152 optionsItemSelectedInternal(item);
153 return true;
154 }
155 });
156 mPopupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
157 public void onDismiss(PopupMenu menu) {
158 mPopupMenu = null;
159 }
160 });
161 mPopupMenu.show();
162 }
163 return;
164 default:
165 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800166 }
Wink Savillee68857d2014-10-17 15:23:05 -0700167 CatLog.d(LOG_TAG, "handleClick, ready to response");
Preeti Ahuja03be6672012-08-30 19:21:25 +0530168 cancelTimeOut();
Wink Savillee68857d2014-10-17 15:23:05 -0700169 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800170 sendResponse(StkAppService.RES_ID_INPUT, input, false);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800171 }
172
173 @Override
Takanori Nakano1a672e62017-10-19 19:49:38 +0900174 public void onCreate(Bundle savedInstanceState) {
175 super.onCreate(savedInstanceState);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800176
Wink Savillee68857d2014-10-17 15:23:05 -0700177 CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]");
178
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900179 // appService can be null if this activity is automatically recreated by the system
180 // with the saved instance state right after the phone process is killed.
181 if (appService == null) {
182 CatLog.d(LOG_TAG, "onCreate - appService is null");
183 finish();
184 return;
185 }
186
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900187 ActionBar actionBar = null;
188 if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) {
189 actionBar = getActionBar();
190 if (actionBar != null) {
191 actionBar.hide();
192 }
193 }
Takanori Nakano48544352016-12-02 18:32:59 +0900194
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800195 // Set the layout for this activity.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800196 setContentView(R.layout.stk_input);
197
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900198 if (actionBar != null) {
199 mMoreOptions = findViewById(R.id.more);
200 mMoreOptions.setVisibility(View.VISIBLE);
201 mMoreOptions.setOnClickListener(this);
202 }
203
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800204 // Initialize members
205 mTextIn = (EditText) this.findViewById(R.id.in_text);
206 mPromptView = (TextView) this.findViewById(R.id.prompt);
Wink Savillee68857d2014-10-17 15:23:05 -0700207 mInstance = this;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800208 // Set buttons listeners.
Wink Saville79085fc2009-06-09 10:27:23 -0700209 Button okButton = (Button) findViewById(R.id.button_ok);
Takanori Nakano260df9a2017-12-05 22:26:30 +0900210 Button cancelButton = (Button) findViewById(R.id.button_cancel);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800211 Button yesButton = (Button) findViewById(R.id.button_yes);
212 Button noButton = (Button) findViewById(R.id.button_no);
213
214 okButton.setOnClickListener(this);
Takanori Nakano260df9a2017-12-05 22:26:30 +0900215 cancelButton.setOnClickListener(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800216 yesButton.setOnClickListener(this);
217 noButton.setOnClickListener(this);
218
219 mYesNoLayout = findViewById(R.id.yes_no_layout);
220 mNormalLayout = findViewById(R.id.normal_layout);
Wink Savillee68857d2014-10-17 15:23:05 -0700221 initFromIntent(getIntent());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800222 mContext = getBaseContext();
Wink Savillee68857d2014-10-17 15:23:05 -0700223 mAcceptUsersInput = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800224 }
225
226 @Override
227 protected void onPostCreate(Bundle savedInstanceState) {
228 super.onPostCreate(savedInstanceState);
229
230 mTextIn.addTextChangedListener(this);
231 }
232
233 @Override
234 public void onResume() {
235 super.onResume();
Wink Savillee68857d2014-10-17 15:23:05 -0700236 CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
237 "], slot id: " + mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800238 startTimeOut();
239 }
240
241 @Override
242 public void onPause() {
243 super.onPause();
Wink Savillee68857d2014-10-17 15:23:05 -0700244 CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]");
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900245 if (mPopupMenu != null) {
246 mPopupMenu.dismiss();
247 }
Wink Savillee68857d2014-10-17 15:23:05 -0700248 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800249
Wink Savillee68857d2014-10-17 15:23:05 -0700250 @Override
251 public void onStop() {
252 super.onStop();
253 CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]");
Takanori Nakano1a672e62017-10-19 19:49:38 +0900254
255 // Nothing should be done here if this activity is being restarted now.
256 if (isChangingConfigurations()) {
257 return;
258 }
259
Yoshiaki Nakacec55b82017-10-20 15:53:43 +0900260 // It is unnecessary to keep this activity if the response was already sent and
261 // this got invisible because of the other full-screen activity in this application.
262 if (mIsResponseSent && appService.isTopOfStack()) {
Wink Savillee68857d2014-10-17 15:23:05 -0700263 cancelTimeOut();
264 finish();
265 } else {
266 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
267 }
268 }
269
270 @Override
271 public void onDestroy() {
272 super.onDestroy();
273 CatLog.d(LOG_TAG, "onDestroy - before Send End Session mIsResponseSent[" +
274 mIsResponseSent + " , " + mSlotId + "]");
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900275 if (appService == null) {
276 return;
277 }
Takanori Nakano1a672e62017-10-19 19:49:38 +0900278 // Avoid sending the terminal response while the activty is being restarted
279 // due to some kind of configuration change.
280 if (!isChangingConfigurations()) {
281 // If the input activity is finished by stkappservice
282 // when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here,
283 // since the input cmd is waiting user to process.
284 if (!mIsResponseSent && !appService.isInputPending(mSlotId)) {
285 CatLog.d(LOG_TAG, "handleDestroy - Send End Session");
286 sendResponse(StkAppService.RES_ID_END_SESSION);
287 }
288 cancelTimeOut();
Wink Savillee68857d2014-10-17 15:23:05 -0700289 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800290 }
291
292 @Override
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900293 public void onConfigurationChanged(Configuration newConfig) {
294 super.onConfigurationChanged(newConfig);
295 if (mPopupMenu != null) {
296 mPopupMenu.dismiss();
297 }
298 }
299
300 @Override
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800301 public boolean onKeyDown(int keyCode, KeyEvent event) {
Wink Savillee68857d2014-10-17 15:23:05 -0700302 if (!mAcceptUsersInput) {
303 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
304 return true;
305 }
306
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800307 switch (keyCode) {
308 case KeyEvent.KEYCODE_BACK:
Wink Savillee68857d2014-10-17 15:23:05 -0700309 CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK");
310 mAcceptUsersInput = false;
Preeti Ahuja03be6672012-08-30 19:21:25 +0530311 cancelTimeOut();
Wink Savillee68857d2014-10-17 15:23:05 -0700312 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800313 sendResponse(StkAppService.RES_ID_BACKWARD, null, false);
Wink Savillee68857d2014-10-17 15:23:05 -0700314 return true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800315 }
316 return super.onKeyDown(keyCode, event);
317 }
318
Wink Savillee68857d2014-10-17 15:23:05 -0700319 void sendResponse(int resId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800320 sendResponse(resId, null, false);
321 }
322
Wink Savillee68857d2014-10-17 15:23:05 -0700323 void sendResponse(int resId, String input, boolean help) {
324 if (mSlotId == -1) {
325 CatLog.d(LOG_TAG, "slot id is invalid");
326 return;
327 }
328
329 if (StkAppService.getInstance() == null) {
330 CatLog.d(LOG_TAG, "StkAppService is null, Ignore response: id is " + resId);
331 return;
332 }
333
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900334 if (mMoreOptions != null) {
335 mMoreOptions.setVisibility(View.INVISIBLE);
336 }
337
Cuihtlauac ALVARADObde7f032015-05-29 16:25:12 +0200338 CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help["
339 + help + "]");
Wink Savillee68857d2014-10-17 15:23:05 -0700340 mIsResponseSent = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800341 Bundle args = new Bundle();
342 args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE);
Wink Savillee68857d2014-10-17 15:23:05 -0700343 args.putInt(StkAppService.SLOT_ID, mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800344 args.putInt(StkAppService.RES_ID, resId);
345 if (input != null) {
346 args.putString(StkAppService.INPUT, input);
347 }
348 args.putBoolean(StkAppService.HELP, help);
349 mContext.startService(new Intent(mContext, StkAppService.class)
350 .putExtras(args));
351 }
352
353 @Override
354 public boolean onCreateOptionsMenu(android.view.Menu menu) {
355 super.onCreateOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900356 createOptionsMenuInternal(menu);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800357 return true;
358 }
359
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900360 private void createOptionsMenuInternal(Menu menu) {
361 menu.add(Menu.NONE, StkApp.MENU_ID_END_SESSION, 1, R.string.menu_end_session);
362 menu.add(0, StkApp.MENU_ID_HELP, 2, R.string.help);
363 }
364
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800365 @Override
366 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
367 super.onPrepareOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900368 prepareOptionsMenuInternal(menu);
369 return true;
370 }
371
372 private void prepareOptionsMenuInternal(Menu menu) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800373 menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true);
374 menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800375 }
376
377 @Override
378 public boolean onOptionsItemSelected(MenuItem item) {
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900379 if (optionsItemSelectedInternal(item)) {
380 return true;
381 }
382 return super.onOptionsItemSelected(item);
383 }
384
385 private boolean optionsItemSelectedInternal(MenuItem item) {
Wink Savillee68857d2014-10-17 15:23:05 -0700386 if (!mAcceptUsersInput) {
387 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
388 return true;
389 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800390 switch (item.getItemId()) {
391 case StkApp.MENU_ID_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -0700392 mAcceptUsersInput = false;
393 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800394 sendResponse(StkAppService.RES_ID_END_SESSION);
395 finish();
396 return true;
397 case StkApp.MENU_ID_HELP:
Wink Savillee68857d2014-10-17 15:23:05 -0700398 mAcceptUsersInput = false;
399 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800400 sendResponse(StkAppService.RES_ID_INPUT, "", true);
401 finish();
402 return true;
403 }
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900404 return false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800405 }
406
Wink Savillee68857d2014-10-17 15:23:05 -0700407 @Override
408 protected void onSaveInstanceState(Bundle outState) {
409 CatLog.d(LOG_TAG, "onSaveInstanceState: " + mSlotId);
Takanori Nakano1a672e62017-10-19 19:49:38 +0900410 outState.putBoolean(ACCEPT_USERS_INPUT_KEY, mAcceptUsersInput);
411 outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent);
412 outState.putString(INPUT_STRING_KEY, mTextIn.getText().toString());
Wink Savillee68857d2014-10-17 15:23:05 -0700413 }
414
415 @Override
416 protected void onRestoreInstanceState(Bundle savedInstanceState) {
417 CatLog.d(LOG_TAG, "onRestoreInstanceState: " + mSlotId);
Takanori Nakano1a672e62017-10-19 19:49:38 +0900418
419 mAcceptUsersInput = savedInstanceState.getBoolean(ACCEPT_USERS_INPUT_KEY);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900420 if ((mAcceptUsersInput == false) && (mMoreOptions != null)) {
421 mMoreOptions.setVisibility(View.INVISIBLE);
422 }
Takanori Nakano1a672e62017-10-19 19:49:38 +0900423
424 mIsResponseSent = savedInstanceState.getBoolean(RESPONSE_SENT_KEY);
425
426 String savedString = savedInstanceState.getString(INPUT_STRING_KEY);
427 if (!TextUtils.isEmpty(savedString)) {
428 mTextIn.setText(savedString);
429 }
Wink Savillee68857d2014-10-17 15:23:05 -0700430 }
431
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800432 public void beforeTextChanged(CharSequence s, int start, int count,
433 int after) {
434 }
435
436 public void onTextChanged(CharSequence s, int start, int before, int count) {
437 // Reset timeout.
438 startTimeOut();
439 }
440
441 public void afterTextChanged(Editable s) {
442 }
443
444 private boolean verfiyTypedText() {
445 // If not enough input was typed in stay on the edit screen.
446 if (mTextIn.getText().length() < mStkInput.minLen) {
447 return false;
448 }
449
450 return true;
451 }
452
453 private void cancelTimeOut() {
454 mTimeoutHandler.removeMessages(MSG_ID_TIMEOUT);
455 }
456
457 private void startTimeOut() {
Abhishek Adappac7c3a462013-02-14 13:36:57 -0800458 int duration = StkApp.calculateDurationInMilis(mStkInput.duration);
459
460 if (duration <= 0) {
461 duration = StkApp.UI_TIMEOUT;
462 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800463 cancelTimeOut();
464 mTimeoutHandler.sendMessageDelayed(mTimeoutHandler
Abhishek Adappac7c3a462013-02-14 13:36:57 -0800465 .obtainMessage(MSG_ID_TIMEOUT), duration);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800466 }
467
468 private void configInputDisplay() {
469 TextView numOfCharsView = (TextView) findViewById(R.id.num_of_chars);
470 TextView inTypeView = (TextView) findViewById(R.id.input_type);
471
472 int inTypeId = R.string.alphabet;
473
474 // set the prompt.
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900475 if ((mStkInput.icon == null || !mStkInput.iconSelfExplanatory)
476 && !TextUtils.isEmpty(mStkInput.text)) {
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900477 mPromptView.setText(mStkInput.text);
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900478 mPromptView.setVisibility(View.VISIBLE);
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900479 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800480
Wink Saville79085fc2009-06-09 10:27:23 -0700481 // Set input type (alphabet/digit) info close to the InText form.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800482 if (mStkInput.digitOnly) {
483 mTextIn.setKeyListener(StkDigitsKeyListener.getInstance());
484 inTypeId = R.string.digits;
485 }
486 inTypeView.setText(inTypeId);
487
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900488 setTitle(R.string.app_name);
Takanori Nakano48544352016-12-02 18:32:59 +0900489
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800490 if (mStkInput.icon != null) {
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900491 ImageView imageView = (ImageView) findViewById(R.id.icon);
Takanori Nakano48544352016-12-02 18:32:59 +0900492 imageView.setImageBitmap(mStkInput.icon);
493 imageView.setVisibility(View.VISIBLE);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800494 }
495
496 // Handle specific global and text attributes.
497 switch (mState) {
Wink Saville79085fc2009-06-09 10:27:23 -0700498 case STATE_TEXT:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800499 int maxLen = mStkInput.maxLen;
500 int minLen = mStkInput.minLen;
501 mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter(
502 maxLen)});
Wink Saville79085fc2009-06-09 10:27:23 -0700503
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800504 // Set number of chars info.
505 String lengthLimit = String.valueOf(minLen);
506 if (maxLen != minLen) {
507 lengthLimit = minLen + " - " + maxLen;
508 }
509 numOfCharsView.setText(lengthLimit);
510
511 if (!mStkInput.echo) {
Yujing Gu6b9716c2014-04-23 13:50:50 +0800512 mTextIn.setTransformationMethod(PasswordTransformationMethod
513 .getInstance());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800514 }
Srikanth Chintalaa091b732016-02-04 14:46:43 +0530515 mTextIn.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800516 // Set default text if present.
517 if (mStkInput.defaultText != null) {
518 mTextIn.setText(mStkInput.defaultText);
519 } else {
520 // make sure the text is cleared
521 mTextIn.setText("", BufferType.EDITABLE);
522 }
523
524 break;
525 case STATE_YES_NO:
526 // Set display mode - normal / yes-no layout
527 mYesNoLayout.setVisibility(View.VISIBLE);
528 mNormalLayout.setVisibility(View.GONE);
529 break;
530 }
531 }
532
533 private float getFontSizeFactor(FontSize size) {
Wink Saville79085fc2009-06-09 10:27:23 -0700534 final float[] fontSizes =
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800535 {NORMAL_FONT_FACTOR, LARGE_FONT_FACTOR, SMALL_FONT_FACTOR};
536
537 return fontSizes[size.ordinal()];
538 }
Wink Savillee68857d2014-10-17 15:23:05 -0700539
540 private void initFromIntent(Intent intent) {
541 // Get the calling intent type: text/key, and setup the
542 // display parameters.
543 CatLog.d(LOG_TAG, "initFromIntent - slot id: " + mSlotId);
544 if (intent != null) {
545 mStkInput = intent.getParcelableExtra("INPUT");
546 mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
547 CatLog.d(LOG_TAG, "onCreate - slot id: " + mSlotId);
548 if (mStkInput == null) {
549 finish();
550 } else {
551 mState = mStkInput.yesNo ? STATE_YES_NO :
552 STATE_TEXT;
553 configInputDisplay();
554 }
555 } else {
556 finish();
557 }
558 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800559}