blob: 1192206efdd7f5eb9e91a6cabb88a09a701a9725 [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 *
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +09004 * 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
Wink Saville79085fc2009-06-09 10:27:23 -07007 *
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +09008 * 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;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090021import android.app.AlarmManager;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080022import android.content.Context;
23import android.content.Intent;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090024import android.content.res.Configuration;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080025import android.os.Bundle;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090026import android.os.SystemClock;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080027import android.text.Editable;
28import android.text.InputFilter;
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +090029import android.text.TextUtils;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080030import android.text.TextWatcher;
31import android.text.method.PasswordTransformationMethod;
32import android.view.KeyEvent;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090033import android.view.Menu;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080034import android.view.MenuItem;
35import android.view.View;
Kazuhiro Uto12870912018-07-18 17:43:56 +090036import android.view.WindowManager;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090037import android.view.inputmethod.EditorInfo;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080038import android.widget.Button;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090039import android.widget.EditText;
Takanori Nakano48544352016-12-02 18:32:59 +090040import android.widget.ImageView;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090041import android.widget.PopupMenu;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080042import android.widget.TextView;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080043import android.widget.TextView.BufferType;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090044
Wink Savillee68857d2014-10-17 15:23:05 -070045import com.android.internal.telephony.cat.CatLog;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070046import com.android.internal.telephony.cat.Input;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080047
48/**
49 * Display a request for a text input a long with a text edit form.
50 */
51public class StkInputActivity extends Activity implements View.OnClickListener,
52 TextWatcher {
53
54 // Members
55 private int mState;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080056 private EditText mTextIn = null;
57 private TextView mPromptView = null;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090058 private View mMoreOptions = null;
59 private PopupMenu mPopupMenu = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080060 private View mYesNoLayout = null;
61 private View mNormalLayout = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080062
63 // Constants
Wink Savillee68857d2014-10-17 15:23:05 -070064 private static final String className = new Object(){}.getClass().getEnclosingClass().getName();
65 private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1);
66
67 private Input mStkInput = null;
Wink Savillee68857d2014-10-17 15:23:05 -070068 // Constants
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080069 private static final int STATE_TEXT = 1;
70 private static final int STATE_YES_NO = 2;
71
72 static final String YES_STR_RESPONSE = "YES";
73 static final String NO_STR_RESPONSE = "NO";
74
75 // Font size factor values.
76 static final float NORMAL_FONT_FACTOR = 1;
77 static final float LARGE_FONT_FACTOR = 2;
78 static final float SMALL_FONT_FACTOR = (1 / 2);
79
Takanori Nakano1a672e62017-10-19 19:49:38 +090080 // Keys for saving the state of the activity in the bundle
Takanori Nakano1a672e62017-10-19 19:49:38 +090081 private static final String RESPONSE_SENT_KEY = "response_sent";
82 private static final String INPUT_STRING_KEY = "input_string";
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090083 private static final String ALARM_TIME_KEY = "alarm_time";
Takanori Nakano1a672e62017-10-19 19:49:38 +090084
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090085 private static final String INPUT_ALARM_TAG = LOG_TAG;
86 private static final long NO_INPUT_ALARM = -1;
87 private long mAlarmTime = NO_INPUT_ALARM;
88
Wink Savillee68857d2014-10-17 15:23:05 -070089 private StkAppService appService = StkAppService.getInstance();
90
91 private boolean mIsResponseSent = false;
92 private int mSlotId = -1;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080093
94 // Click listener to handle buttons press..
95 public void onClick(View v) {
96 String input = null;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090097 if (mIsResponseSent) {
98 CatLog.d(LOG_TAG, "Already responded");
Wink Savillee68857d2014-10-17 15:23:05 -070099 return;
100 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800101
102 switch (v.getId()) {
103 case R.id.button_ok:
104 // Check that text entered is valid .
105 if (!verfiyTypedText()) {
Wink Savillee68857d2014-10-17 15:23:05 -0700106 CatLog.d(LOG_TAG, "handleClick, invalid text");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800107 return;
108 }
109 input = mTextIn.getText().toString();
110 break;
Takanori Nakano260df9a2017-12-05 22:26:30 +0900111 case R.id.button_cancel:
Takanori Nakano260df9a2017-12-05 22:26:30 +0900112 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
113 sendResponse(StkAppService.RES_ID_END_SESSION);
114 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800115 // Yes/No layout buttons.
116 case R.id.button_yes:
117 input = YES_STR_RESPONSE;
118 break;
119 case R.id.button_no:
120 input = NO_STR_RESPONSE;
121 break;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900122 case R.id.more:
123 if (mPopupMenu == null) {
124 mPopupMenu = new PopupMenu(this, v);
125 Menu menu = mPopupMenu.getMenu();
126 createOptionsMenuInternal(menu);
127 prepareOptionsMenuInternal(menu);
128 mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
129 public boolean onMenuItemClick(MenuItem item) {
130 optionsItemSelectedInternal(item);
131 return true;
132 }
133 });
134 mPopupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
135 public void onDismiss(PopupMenu menu) {
136 mPopupMenu = null;
137 }
138 });
139 mPopupMenu.show();
140 }
141 return;
142 default:
143 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800144 }
Wink Savillee68857d2014-10-17 15:23:05 -0700145 CatLog.d(LOG_TAG, "handleClick, ready to response");
146 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800147 sendResponse(StkAppService.RES_ID_INPUT, input, false);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800148 }
149
150 @Override
Takanori Nakano1a672e62017-10-19 19:49:38 +0900151 public void onCreate(Bundle savedInstanceState) {
152 super.onCreate(savedInstanceState);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800153
Wink Savillee68857d2014-10-17 15:23:05 -0700154 CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]");
155
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900156 // appService can be null if this activity is automatically recreated by the system
157 // with the saved instance state right after the phone process is killed.
158 if (appService == null) {
159 CatLog.d(LOG_TAG, "onCreate - appService is null");
160 finish();
161 return;
162 }
163
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900164 ActionBar actionBar = null;
165 if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) {
166 actionBar = getActionBar();
167 if (actionBar != null) {
168 actionBar.hide();
169 }
170 }
Takanori Nakano48544352016-12-02 18:32:59 +0900171
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800172 // Set the layout for this activity.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800173 setContentView(R.layout.stk_input);
174
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900175 if (actionBar != null) {
176 mMoreOptions = findViewById(R.id.more);
177 mMoreOptions.setVisibility(View.VISIBLE);
178 mMoreOptions.setOnClickListener(this);
179 }
180
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800181 // Initialize members
182 mTextIn = (EditText) this.findViewById(R.id.in_text);
183 mPromptView = (TextView) this.findViewById(R.id.prompt);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800184 // Set buttons listeners.
Wink Saville79085fc2009-06-09 10:27:23 -0700185 Button okButton = (Button) findViewById(R.id.button_ok);
Takanori Nakano260df9a2017-12-05 22:26:30 +0900186 Button cancelButton = (Button) findViewById(R.id.button_cancel);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800187 Button yesButton = (Button) findViewById(R.id.button_yes);
188 Button noButton = (Button) findViewById(R.id.button_no);
189
190 okButton.setOnClickListener(this);
Takanori Nakano260df9a2017-12-05 22:26:30 +0900191 cancelButton.setOnClickListener(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800192 yesButton.setOnClickListener(this);
193 noButton.setOnClickListener(this);
194
195 mYesNoLayout = findViewById(R.id.yes_no_layout);
196 mNormalLayout = findViewById(R.id.normal_layout);
Wink Savillee68857d2014-10-17 15:23:05 -0700197 initFromIntent(getIntent());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800198 }
199
200 @Override
201 protected void onPostCreate(Bundle savedInstanceState) {
202 super.onPostCreate(savedInstanceState);
203
204 mTextIn.addTextChangedListener(this);
205 }
206
207 @Override
208 public void onResume() {
209 super.onResume();
Wink Savillee68857d2014-10-17 15:23:05 -0700210 CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
211 "], slot id: " + mSlotId);
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900212
213 if (mAlarmTime == NO_INPUT_ALARM) {
214 startTimeOut();
215 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800216 }
217
218 @Override
219 public void onPause() {
220 super.onPause();
Wink Savillee68857d2014-10-17 15:23:05 -0700221 CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]");
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900222 if (mPopupMenu != null) {
223 mPopupMenu.dismiss();
224 }
Wink Savillee68857d2014-10-17 15:23:05 -0700225 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800226
Wink Savillee68857d2014-10-17 15:23:05 -0700227 @Override
228 public void onStop() {
229 super.onStop();
230 CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]");
Takanori Nakano1a672e62017-10-19 19:49:38 +0900231
232 // Nothing should be done here if this activity is being restarted now.
233 if (isChangingConfigurations()) {
234 return;
235 }
236
Yoshiaki Nakacec55b82017-10-20 15:53:43 +0900237 // It is unnecessary to keep this activity if the response was already sent and
238 // this got invisible because of the other full-screen activity in this application.
239 if (mIsResponseSent && appService.isTopOfStack()) {
Wink Savillee68857d2014-10-17 15:23:05 -0700240 finish();
241 } else {
242 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
243 }
244 }
245
246 @Override
247 public void onDestroy() {
248 super.onDestroy();
249 CatLog.d(LOG_TAG, "onDestroy - before Send End Session mIsResponseSent[" +
250 mIsResponseSent + " , " + mSlotId + "]");
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900251 if (appService == null) {
252 return;
253 }
Takanori Nakano1a672e62017-10-19 19:49:38 +0900254 // Avoid sending the terminal response while the activty is being restarted
255 // due to some kind of configuration change.
256 if (!isChangingConfigurations()) {
257 // If the input activity is finished by stkappservice
258 // when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here,
259 // since the input cmd is waiting user to process.
260 if (!mIsResponseSent && !appService.isInputPending(mSlotId)) {
261 CatLog.d(LOG_TAG, "handleDestroy - Send End Session");
262 sendResponse(StkAppService.RES_ID_END_SESSION);
263 }
Wink Savillee68857d2014-10-17 15:23:05 -0700264 }
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900265 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800266 }
267
268 @Override
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900269 public void onConfigurationChanged(Configuration newConfig) {
270 super.onConfigurationChanged(newConfig);
271 if (mPopupMenu != null) {
272 mPopupMenu.dismiss();
273 }
274 }
275
276 @Override
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800277 public boolean onKeyDown(int keyCode, KeyEvent event) {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900278 if (mIsResponseSent) {
279 CatLog.d(LOG_TAG, "Already responded");
Wink Savillee68857d2014-10-17 15:23:05 -0700280 return true;
281 }
282
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800283 switch (keyCode) {
284 case KeyEvent.KEYCODE_BACK:
Wink Savillee68857d2014-10-17 15:23:05 -0700285 CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK");
Wink Savillee68857d2014-10-17 15:23:05 -0700286 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800287 sendResponse(StkAppService.RES_ID_BACKWARD, null, false);
Wink Savillee68857d2014-10-17 15:23:05 -0700288 return true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800289 }
290 return super.onKeyDown(keyCode, event);
291 }
292
Wink Savillee68857d2014-10-17 15:23:05 -0700293 void sendResponse(int resId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800294 sendResponse(resId, null, false);
295 }
296
Wink Savillee68857d2014-10-17 15:23:05 -0700297 void sendResponse(int resId, String input, boolean help) {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900298 cancelTimeOut();
299
Wink Savillee68857d2014-10-17 15:23:05 -0700300 if (mSlotId == -1) {
301 CatLog.d(LOG_TAG, "slot id is invalid");
302 return;
303 }
304
305 if (StkAppService.getInstance() == null) {
306 CatLog.d(LOG_TAG, "StkAppService is null, Ignore response: id is " + resId);
307 return;
308 }
309
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900310 if (mMoreOptions != null) {
311 mMoreOptions.setVisibility(View.INVISIBLE);
312 }
313
Cuihtlauac ALVARADObde7f032015-05-29 16:25:12 +0200314 CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help["
315 + help + "]");
Wink Savillee68857d2014-10-17 15:23:05 -0700316 mIsResponseSent = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800317 Bundle args = new Bundle();
318 args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE);
Wink Savillee68857d2014-10-17 15:23:05 -0700319 args.putInt(StkAppService.SLOT_ID, mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800320 args.putInt(StkAppService.RES_ID, resId);
321 if (input != null) {
322 args.putString(StkAppService.INPUT, input);
323 }
324 args.putBoolean(StkAppService.HELP, help);
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900325 startService(new Intent(this, StkAppService.class).putExtras(args));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800326 }
327
328 @Override
329 public boolean onCreateOptionsMenu(android.view.Menu menu) {
330 super.onCreateOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900331 createOptionsMenuInternal(menu);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800332 return true;
333 }
334
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900335 private void createOptionsMenuInternal(Menu menu) {
336 menu.add(Menu.NONE, StkApp.MENU_ID_END_SESSION, 1, R.string.menu_end_session);
337 menu.add(0, StkApp.MENU_ID_HELP, 2, R.string.help);
338 }
339
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800340 @Override
341 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
342 super.onPrepareOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900343 prepareOptionsMenuInternal(menu);
344 return true;
345 }
346
347 private void prepareOptionsMenuInternal(Menu menu) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800348 menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true);
349 menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800350 }
351
352 @Override
353 public boolean onOptionsItemSelected(MenuItem item) {
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900354 if (optionsItemSelectedInternal(item)) {
355 return true;
356 }
357 return super.onOptionsItemSelected(item);
358 }
359
360 private boolean optionsItemSelectedInternal(MenuItem item) {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900361 if (mIsResponseSent) {
362 CatLog.d(LOG_TAG, "Already responded");
Wink Savillee68857d2014-10-17 15:23:05 -0700363 return true;
364 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800365 switch (item.getItemId()) {
366 case StkApp.MENU_ID_END_SESSION:
367 sendResponse(StkAppService.RES_ID_END_SESSION);
368 finish();
369 return true;
370 case StkApp.MENU_ID_HELP:
371 sendResponse(StkAppService.RES_ID_INPUT, "", true);
372 finish();
373 return true;
374 }
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900375 return false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800376 }
377
Wink Savillee68857d2014-10-17 15:23:05 -0700378 @Override
379 protected void onSaveInstanceState(Bundle outState) {
380 CatLog.d(LOG_TAG, "onSaveInstanceState: " + mSlotId);
Takanori Nakano1a672e62017-10-19 19:49:38 +0900381 outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent);
382 outState.putString(INPUT_STRING_KEY, mTextIn.getText().toString());
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900383 outState.putLong(ALARM_TIME_KEY, mAlarmTime);
Wink Savillee68857d2014-10-17 15:23:05 -0700384 }
385
386 @Override
387 protected void onRestoreInstanceState(Bundle savedInstanceState) {
388 CatLog.d(LOG_TAG, "onRestoreInstanceState: " + mSlotId);
Takanori Nakano1a672e62017-10-19 19:49:38 +0900389
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900390 mIsResponseSent = savedInstanceState.getBoolean(RESPONSE_SENT_KEY);
391 if (mIsResponseSent && (mMoreOptions != null)) {
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900392 mMoreOptions.setVisibility(View.INVISIBLE);
393 }
Takanori Nakano1a672e62017-10-19 19:49:38 +0900394
Takanori Nakano1a672e62017-10-19 19:49:38 +0900395 String savedString = savedInstanceState.getString(INPUT_STRING_KEY);
396 if (!TextUtils.isEmpty(savedString)) {
397 mTextIn.setText(savedString);
398 }
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900399
400 mAlarmTime = savedInstanceState.getLong(ALARM_TIME_KEY, NO_INPUT_ALARM);
401 if (mAlarmTime != NO_INPUT_ALARM) {
402 startTimeOut();
403 }
Wink Savillee68857d2014-10-17 15:23:05 -0700404 }
405
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800406 public void beforeTextChanged(CharSequence s, int start, int count,
407 int after) {
408 }
409
410 public void onTextChanged(CharSequence s, int start, int before, int count) {
411 // Reset timeout.
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900412 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800413 startTimeOut();
414 }
415
416 public void afterTextChanged(Editable s) {
417 }
418
419 private boolean verfiyTypedText() {
420 // If not enough input was typed in stay on the edit screen.
421 if (mTextIn.getText().length() < mStkInput.minLen) {
422 return false;
423 }
424
425 return true;
426 }
427
428 private void cancelTimeOut() {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900429 if (mAlarmTime != NO_INPUT_ALARM) {
430 CatLog.d(LOG_TAG, "cancelTimeOut - slot id: " + mSlotId);
431 AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
432 am.cancel(mAlarmListener);
433 mAlarmTime = NO_INPUT_ALARM;
434 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800435 }
436
437 private void startTimeOut() {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900438 // No need to set alarm if device sent TERMINAL RESPONSE already.
439 if (mIsResponseSent) {
440 return;
Abhishek Adappac7c3a462013-02-14 13:36:57 -0800441 }
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900442
443 if (mAlarmTime == NO_INPUT_ALARM) {
444 int duration = StkApp.calculateDurationInMilis(mStkInput.duration);
445 if (duration <= 0) {
446 duration = StkApp.UI_TIMEOUT;
447 }
448 mAlarmTime = SystemClock.elapsedRealtime() + duration;
449 }
450
451 CatLog.d(LOG_TAG, "startTimeOut: " + mAlarmTime + "ms, slot id: " + mSlotId);
452 AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
453 am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, mAlarmTime, INPUT_ALARM_TAG,
454 mAlarmListener, null);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800455 }
456
457 private void configInputDisplay() {
458 TextView numOfCharsView = (TextView) findViewById(R.id.num_of_chars);
459 TextView inTypeView = (TextView) findViewById(R.id.input_type);
460
461 int inTypeId = R.string.alphabet;
462
463 // set the prompt.
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900464 if ((mStkInput.icon == null || !mStkInput.iconSelfExplanatory)
465 && !TextUtils.isEmpty(mStkInput.text)) {
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900466 mPromptView.setText(mStkInput.text);
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900467 mPromptView.setVisibility(View.VISIBLE);
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900468 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800469
Wink Saville79085fc2009-06-09 10:27:23 -0700470 // Set input type (alphabet/digit) info close to the InText form.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800471 if (mStkInput.digitOnly) {
472 mTextIn.setKeyListener(StkDigitsKeyListener.getInstance());
473 inTypeId = R.string.digits;
474 }
475 inTypeView.setText(inTypeId);
476
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900477 setTitle(R.string.app_name);
Takanori Nakano48544352016-12-02 18:32:59 +0900478
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800479 if (mStkInput.icon != null) {
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900480 ImageView imageView = (ImageView) findViewById(R.id.icon);
Takanori Nakano48544352016-12-02 18:32:59 +0900481 imageView.setImageBitmap(mStkInput.icon);
482 imageView.setVisibility(View.VISIBLE);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800483 }
484
485 // Handle specific global and text attributes.
486 switch (mState) {
Wink Saville79085fc2009-06-09 10:27:23 -0700487 case STATE_TEXT:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800488 int maxLen = mStkInput.maxLen;
489 int minLen = mStkInput.minLen;
490 mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter(
491 maxLen)});
Wink Saville79085fc2009-06-09 10:27:23 -0700492
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800493 // Set number of chars info.
494 String lengthLimit = String.valueOf(minLen);
495 if (maxLen != minLen) {
496 lengthLimit = minLen + " - " + maxLen;
497 }
498 numOfCharsView.setText(lengthLimit);
499
500 if (!mStkInput.echo) {
Yujing Gu6b9716c2014-04-23 13:50:50 +0800501 mTextIn.setTransformationMethod(PasswordTransformationMethod
502 .getInstance());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800503 }
Srikanth Chintalaa091b732016-02-04 14:46:43 +0530504 mTextIn.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
Kazuhiro Uto12870912018-07-18 17:43:56 +0900505 // Request the initial focus on the edit box and show the software keyboard.
506 mTextIn.requestFocus();
507 getWindow().setSoftInputMode(
508 WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800509 // Set default text if present.
510 if (mStkInput.defaultText != null) {
511 mTextIn.setText(mStkInput.defaultText);
512 } else {
513 // make sure the text is cleared
514 mTextIn.setText("", BufferType.EDITABLE);
515 }
516
517 break;
518 case STATE_YES_NO:
519 // Set display mode - normal / yes-no layout
520 mYesNoLayout.setVisibility(View.VISIBLE);
521 mNormalLayout.setVisibility(View.GONE);
522 break;
523 }
524 }
525
Wink Savillee68857d2014-10-17 15:23:05 -0700526 private void initFromIntent(Intent intent) {
527 // Get the calling intent type: text/key, and setup the
528 // display parameters.
529 CatLog.d(LOG_TAG, "initFromIntent - slot id: " + mSlotId);
530 if (intent != null) {
531 mStkInput = intent.getParcelableExtra("INPUT");
532 mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
533 CatLog.d(LOG_TAG, "onCreate - slot id: " + mSlotId);
534 if (mStkInput == null) {
535 finish();
536 } else {
537 mState = mStkInput.yesNo ? STATE_YES_NO :
538 STATE_TEXT;
539 configInputDisplay();
540 }
541 } else {
542 finish();
543 }
544 }
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900545
546 private final AlarmManager.OnAlarmListener mAlarmListener =
547 new AlarmManager.OnAlarmListener() {
548 @Override
549 public void onAlarm() {
550 CatLog.d(LOG_TAG, "The alarm time is reached");
551 mAlarmTime = NO_INPUT_ALARM;
552 appService.getStkContext(mSlotId).setPendingActivityInstance(
553 StkInputActivity.this);
554 sendResponse(StkAppService.RES_ID_TIMEOUT);
555 }
556 };
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800557}