blob: 0af6767d88b98a626bc06a86378f68098c831423 [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;
Yukiko Fujimura913c1432019-02-21 17:14:30 +090027import android.telephony.CarrierConfigManager;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080028import android.text.Editable;
29import android.text.InputFilter;
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +090030import android.text.TextUtils;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080031import android.text.TextWatcher;
32import android.text.method.PasswordTransformationMethod;
33import android.view.KeyEvent;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090034import android.view.Menu;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080035import android.view.MenuItem;
36import android.view.View;
Kazuhiro Uto12870912018-07-18 17:43:56 +090037import android.view.WindowManager;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090038import android.view.inputmethod.EditorInfo;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080039import android.widget.Button;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090040import android.widget.EditText;
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;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080044import android.widget.TextView.BufferType;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090045
Yoshiaki Nakac1efd352019-02-21 17:13:38 +090046import androidx.appcompat.app.AppCompatActivity;
47import androidx.appcompat.widget.Toolbar;
48
Wink Savillee68857d2014-10-17 15:23:05 -070049import com.android.internal.telephony.cat.CatLog;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070050import com.android.internal.telephony.cat.Input;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080051
Yoshiaki Nakac1efd352019-02-21 17:13:38 +090052import com.google.android.material.textfield.TextInputLayout;
53
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080054/**
55 * Display a request for a text input a long with a text edit form.
56 */
Yoshiaki Nakac1efd352019-02-21 17:13:38 +090057public class StkInputActivity extends AppCompatActivity implements View.OnClickListener,
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080058 TextWatcher {
59
60 // Members
61 private int mState;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080062 private EditText mTextIn = null;
63 private TextView mPromptView = null;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090064 private View mMoreOptions = null;
65 private PopupMenu mPopupMenu = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080066 private View mYesNoLayout = null;
67 private View mNormalLayout = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080068
69 // Constants
Yoshiaki Naka3a980db2019-10-30 17:11:33 +090070 private static final String LOG_TAG =
71 new Object(){}.getClass().getEnclosingClass().getSimpleName();
Wink Savillee68857d2014-10-17 15:23:05 -070072
73 private Input mStkInput = null;
Wink Savillee68857d2014-10-17 15:23:05 -070074 // Constants
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080075 private static final int STATE_TEXT = 1;
76 private static final int STATE_YES_NO = 2;
77
78 static final String YES_STR_RESPONSE = "YES";
79 static final String NO_STR_RESPONSE = "NO";
80
81 // Font size factor values.
82 static final float NORMAL_FONT_FACTOR = 1;
83 static final float LARGE_FONT_FACTOR = 2;
84 static final float SMALL_FONT_FACTOR = (1 / 2);
85
Takanori Nakano1a672e62017-10-19 19:49:38 +090086 // Keys for saving the state of the activity in the bundle
Takanori Nakano1a672e62017-10-19 19:49:38 +090087 private static final String RESPONSE_SENT_KEY = "response_sent";
88 private static final String INPUT_STRING_KEY = "input_string";
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090089 private static final String ALARM_TIME_KEY = "alarm_time";
Takanori Nakano1a672e62017-10-19 19:49:38 +090090
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +090091 private static final String INPUT_ALARM_TAG = LOG_TAG;
92 private static final long NO_INPUT_ALARM = -1;
93 private long mAlarmTime = NO_INPUT_ALARM;
94
Wink Savillee68857d2014-10-17 15:23:05 -070095 private StkAppService appService = StkAppService.getInstance();
96
97 private boolean mIsResponseSent = false;
98 private int mSlotId = -1;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080099
100 // Click listener to handle buttons press..
101 public void onClick(View v) {
102 String input = null;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900103 if (mIsResponseSent) {
104 CatLog.d(LOG_TAG, "Already responded");
Wink Savillee68857d2014-10-17 15:23:05 -0700105 return;
106 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800107
Amit Mahajand51bbb52020-02-07 20:03:11 +0000108 switch (v.getId()) {
109 case R.id.button_ok:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800110 input = mTextIn.getText().toString();
Amit Mahajand51bbb52020-02-07 20:03:11 +0000111 break;
112 case R.id.button_cancel:
Takanori Nakano260df9a2017-12-05 22:26:30 +0900113 sendResponse(StkAppService.RES_ID_END_SESSION);
Yoshiaki Naka03a79d92018-08-09 18:41:31 +0900114 finish();
Takanori Nakano260df9a2017-12-05 22:26:30 +0900115 return;
Amit Mahajand51bbb52020-02-07 20:03:11 +0000116 // Yes/No layout buttons.
117 case R.id.button_yes:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800118 input = YES_STR_RESPONSE;
Amit Mahajand51bbb52020-02-07 20:03:11 +0000119 break;
120 case R.id.button_no:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800121 input = NO_STR_RESPONSE;
Amit Mahajand51bbb52020-02-07 20:03:11 +0000122 break;
123 case R.id.more:
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900124 if (mPopupMenu == null) {
125 mPopupMenu = new PopupMenu(this, v);
126 Menu menu = mPopupMenu.getMenu();
127 createOptionsMenuInternal(menu);
128 prepareOptionsMenuInternal(menu);
129 mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
130 public boolean onMenuItemClick(MenuItem item) {
131 optionsItemSelectedInternal(item);
132 return true;
133 }
134 });
135 mPopupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
136 public void onDismiss(PopupMenu menu) {
137 mPopupMenu = null;
138 }
139 });
140 mPopupMenu.show();
141 }
142 return;
Amit Mahajand51bbb52020-02-07 20:03:11 +0000143 default:
144 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800145 }
Wink Savillee68857d2014-10-17 15:23:05 -0700146 CatLog.d(LOG_TAG, "handleClick, ready to response");
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
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800164 // Set the layout for this activity.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800165 setContentView(R.layout.stk_input);
Yoshiaki Nakac1efd352019-02-21 17:13:38 +0900166 setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800167
Yoshiaki Nakac1efd352019-02-21 17:13:38 +0900168 if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) {
169 getSupportActionBar().hide();
170
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900171 mMoreOptions = findViewById(R.id.more);
172 mMoreOptions.setVisibility(View.VISIBLE);
173 mMoreOptions.setOnClickListener(this);
174 }
175
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800176 // Initialize members
177 mTextIn = (EditText) this.findViewById(R.id.in_text);
178 mPromptView = (TextView) this.findViewById(R.id.prompt);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800179 // Set buttons listeners.
Wink Saville79085fc2009-06-09 10:27:23 -0700180 Button okButton = (Button) findViewById(R.id.button_ok);
Takanori Nakano260df9a2017-12-05 22:26:30 +0900181 Button cancelButton = (Button) findViewById(R.id.button_cancel);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800182 Button yesButton = (Button) findViewById(R.id.button_yes);
183 Button noButton = (Button) findViewById(R.id.button_no);
184
185 okButton.setOnClickListener(this);
Takanori Nakano260df9a2017-12-05 22:26:30 +0900186 cancelButton.setOnClickListener(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800187 yesButton.setOnClickListener(this);
188 noButton.setOnClickListener(this);
189
190 mYesNoLayout = findViewById(R.id.yes_no_layout);
191 mNormalLayout = findViewById(R.id.normal_layout);
Wink Savillee68857d2014-10-17 15:23:05 -0700192 initFromIntent(getIntent());
Anna Suzuki35309b02019-02-15 16:24:59 +0900193 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800194 }
195
196 @Override
197 protected void onPostCreate(Bundle savedInstanceState) {
198 super.onPostCreate(savedInstanceState);
199
200 mTextIn.addTextChangedListener(this);
201 }
202
203 @Override
204 public void onResume() {
205 super.onResume();
Wink Savillee68857d2014-10-17 15:23:05 -0700206 CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
207 "], slot id: " + mSlotId);
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900208 if (mAlarmTime == NO_INPUT_ALARM) {
209 startTimeOut();
210 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800211 }
212
213 @Override
214 public void onPause() {
215 super.onPause();
Wink Savillee68857d2014-10-17 15:23:05 -0700216 CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]");
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900217 if (mPopupMenu != null) {
218 mPopupMenu.dismiss();
219 }
Wink Savillee68857d2014-10-17 15:23:05 -0700220 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800221
Wink Savillee68857d2014-10-17 15:23:05 -0700222 @Override
223 public void onStop() {
224 super.onStop();
225 CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]");
Wink Savillee68857d2014-10-17 15:23:05 -0700226 }
227
228 @Override
229 public void onDestroy() {
230 super.onDestroy();
231 CatLog.d(LOG_TAG, "onDestroy - before Send End Session mIsResponseSent[" +
232 mIsResponseSent + " , " + mSlotId + "]");
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900233 if (appService == null) {
234 return;
235 }
Takanori Nakano1a672e62017-10-19 19:49:38 +0900236 // Avoid sending the terminal response while the activty is being restarted
237 // due to some kind of configuration change.
238 if (!isChangingConfigurations()) {
239 // If the input activity is finished by stkappservice
240 // when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here,
241 // since the input cmd is waiting user to process.
242 if (!mIsResponseSent && !appService.isInputPending(mSlotId)) {
243 CatLog.d(LOG_TAG, "handleDestroy - Send End Session");
244 sendResponse(StkAppService.RES_ID_END_SESSION);
245 }
Wink Savillee68857d2014-10-17 15:23:05 -0700246 }
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900247 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800248 }
249
250 @Override
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900251 public void onConfigurationChanged(Configuration newConfig) {
252 super.onConfigurationChanged(newConfig);
253 if (mPopupMenu != null) {
254 mPopupMenu.dismiss();
255 }
256 }
257
258 @Override
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800259 public boolean onKeyDown(int keyCode, KeyEvent event) {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900260 if (mIsResponseSent) {
261 CatLog.d(LOG_TAG, "Already responded");
Wink Savillee68857d2014-10-17 15:23:05 -0700262 return true;
263 }
264
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800265 switch (keyCode) {
266 case KeyEvent.KEYCODE_BACK:
Wink Savillee68857d2014-10-17 15:23:05 -0700267 CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800268 sendResponse(StkAppService.RES_ID_BACKWARD, null, false);
Wink Savillee68857d2014-10-17 15:23:05 -0700269 return true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800270 }
271 return super.onKeyDown(keyCode, event);
272 }
273
Wink Savillee68857d2014-10-17 15:23:05 -0700274 void sendResponse(int resId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800275 sendResponse(resId, null, false);
276 }
277
Wink Savillee68857d2014-10-17 15:23:05 -0700278 void sendResponse(int resId, String input, boolean help) {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900279 cancelTimeOut();
280
Wink Savillee68857d2014-10-17 15:23:05 -0700281 if (mSlotId == -1) {
282 CatLog.d(LOG_TAG, "slot id is invalid");
283 return;
284 }
285
286 if (StkAppService.getInstance() == null) {
287 CatLog.d(LOG_TAG, "StkAppService is null, Ignore response: id is " + resId);
288 return;
289 }
290
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900291 if (mMoreOptions != null) {
292 mMoreOptions.setVisibility(View.INVISIBLE);
293 }
294
Cuihtlauac ALVARADObde7f032015-05-29 16:25:12 +0200295 CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help["
296 + help + "]");
Wink Savillee68857d2014-10-17 15:23:05 -0700297 mIsResponseSent = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800298 Bundle args = new Bundle();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800299 args.putInt(StkAppService.RES_ID, resId);
300 if (input != null) {
301 args.putString(StkAppService.INPUT, input);
302 }
303 args.putBoolean(StkAppService.HELP, help);
Takanori Nakano43dacc02018-07-26 11:27:39 +0900304 appService.sendResponse(args, mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800305 }
306
307 @Override
308 public boolean onCreateOptionsMenu(android.view.Menu menu) {
309 super.onCreateOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900310 createOptionsMenuInternal(menu);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800311 return true;
312 }
313
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900314 private void createOptionsMenuInternal(Menu menu) {
315 menu.add(Menu.NONE, StkApp.MENU_ID_END_SESSION, 1, R.string.menu_end_session);
316 menu.add(0, StkApp.MENU_ID_HELP, 2, R.string.help);
317 }
318
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800319 @Override
320 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
321 super.onPrepareOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900322 prepareOptionsMenuInternal(menu);
323 return true;
324 }
325
326 private void prepareOptionsMenuInternal(Menu menu) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800327 menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true);
328 menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800329 }
330
331 @Override
332 public boolean onOptionsItemSelected(MenuItem item) {
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900333 if (optionsItemSelectedInternal(item)) {
334 return true;
335 }
336 return super.onOptionsItemSelected(item);
337 }
338
339 private boolean optionsItemSelectedInternal(MenuItem item) {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900340 if (mIsResponseSent) {
341 CatLog.d(LOG_TAG, "Already responded");
Wink Savillee68857d2014-10-17 15:23:05 -0700342 return true;
343 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800344 switch (item.getItemId()) {
345 case StkApp.MENU_ID_END_SESSION:
346 sendResponse(StkAppService.RES_ID_END_SESSION);
347 finish();
348 return true;
349 case StkApp.MENU_ID_HELP:
350 sendResponse(StkAppService.RES_ID_INPUT, "", true);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800351 return true;
352 }
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900353 return false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800354 }
355
Wink Savillee68857d2014-10-17 15:23:05 -0700356 @Override
357 protected void onSaveInstanceState(Bundle outState) {
358 CatLog.d(LOG_TAG, "onSaveInstanceState: " + mSlotId);
Takanori Nakano1a672e62017-10-19 19:49:38 +0900359 outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent);
360 outState.putString(INPUT_STRING_KEY, mTextIn.getText().toString());
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900361 outState.putLong(ALARM_TIME_KEY, mAlarmTime);
Wink Savillee68857d2014-10-17 15:23:05 -0700362 }
363
364 @Override
365 protected void onRestoreInstanceState(Bundle savedInstanceState) {
366 CatLog.d(LOG_TAG, "onRestoreInstanceState: " + mSlotId);
Takanori Nakano1a672e62017-10-19 19:49:38 +0900367
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900368 mIsResponseSent = savedInstanceState.getBoolean(RESPONSE_SENT_KEY);
369 if (mIsResponseSent && (mMoreOptions != null)) {
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900370 mMoreOptions.setVisibility(View.INVISIBLE);
371 }
Takanori Nakano1a672e62017-10-19 19:49:38 +0900372
Takanori Nakano1a672e62017-10-19 19:49:38 +0900373 String savedString = savedInstanceState.getString(INPUT_STRING_KEY);
Miyu Iijima1e28c652018-11-14 10:08:05 +0900374 mTextIn.setText(savedString);
375 updateButton();
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900376
377 mAlarmTime = savedInstanceState.getLong(ALARM_TIME_KEY, NO_INPUT_ALARM);
378 if (mAlarmTime != NO_INPUT_ALARM) {
379 startTimeOut();
380 }
Wink Savillee68857d2014-10-17 15:23:05 -0700381 }
382
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800383 public void beforeTextChanged(CharSequence s, int start, int count,
384 int after) {
385 }
386
387 public void onTextChanged(CharSequence s, int start, int before, int count) {
388 // Reset timeout.
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900389 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800390 startTimeOut();
Miyu Iijimac9a17202018-10-17 19:17:14 +0900391 updateButton();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800392 }
393
394 public void afterTextChanged(Editable s) {
395 }
396
Miyu Iijimac9a17202018-10-17 19:17:14 +0900397 private void updateButton() {
398 // Disable the button if the length of the input text does not meet the expectation.
399 Button okButton = (Button) findViewById(R.id.button_ok);
400 okButton.setEnabled((mTextIn.getText().length() < mStkInput.minLen) ? false : true);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800401 }
402
403 private void cancelTimeOut() {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900404 if (mAlarmTime != NO_INPUT_ALARM) {
405 CatLog.d(LOG_TAG, "cancelTimeOut - slot id: " + mSlotId);
406 AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
407 am.cancel(mAlarmListener);
408 mAlarmTime = NO_INPUT_ALARM;
409 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800410 }
411
412 private void startTimeOut() {
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900413 // No need to set alarm if device sent TERMINAL RESPONSE already.
414 if (mIsResponseSent) {
415 return;
Abhishek Adappac7c3a462013-02-14 13:36:57 -0800416 }
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900417
418 if (mAlarmTime == NO_INPUT_ALARM) {
419 int duration = StkApp.calculateDurationInMilis(mStkInput.duration);
420 if (duration <= 0) {
421 duration = StkApp.UI_TIMEOUT;
422 }
423 mAlarmTime = SystemClock.elapsedRealtime() + duration;
424 }
425
426 CatLog.d(LOG_TAG, "startTimeOut: " + mAlarmTime + "ms, slot id: " + mSlotId);
427 AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
428 am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, mAlarmTime, INPUT_ALARM_TAG,
429 mAlarmListener, null);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800430 }
431
432 private void configInputDisplay() {
Yoshiaki Nakac1efd352019-02-21 17:13:38 +0900433 TextInputLayout textInput = (TextInputLayout) findViewById(R.id.text_input_layout);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800434
435 int inTypeId = R.string.alphabet;
436
437 // set the prompt.
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900438 if ((mStkInput.icon == null || !mStkInput.iconSelfExplanatory)
439 && !TextUtils.isEmpty(mStkInput.text)) {
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900440 mPromptView.setText(mStkInput.text);
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900441 mPromptView.setVisibility(View.VISIBLE);
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900442 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800443
Wink Saville79085fc2009-06-09 10:27:23 -0700444 // Set input type (alphabet/digit) info close to the InText form.
Yukiko Fujimura913c1432019-02-21 17:14:30 +0900445 boolean hideHelper = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800446 if (mStkInput.digitOnly) {
447 mTextIn.setKeyListener(StkDigitsKeyListener.getInstance());
448 inTypeId = R.string.digits;
Yukiko Fujimura913c1432019-02-21 17:14:30 +0900449 hideHelper = StkAppService.getBooleanCarrierConfig(this,
450 CarrierConfigManager.KEY_HIDE_DIGITS_HELPER_TEXT_ON_STK_INPUT_SCREEN_BOOL,
451 mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800452 }
Yoshiaki Nakac1efd352019-02-21 17:13:38 +0900453 textInput.setHelperText(getResources().getString(inTypeId));
Yukiko Fujimura913c1432019-02-21 17:14:30 +0900454 textInput.setHelperTextEnabled(!hideHelper);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800455
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900456 setTitle(R.string.app_name);
Takanori Nakano48544352016-12-02 18:32:59 +0900457
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800458 if (mStkInput.icon != null) {
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900459 ImageView imageView = (ImageView) findViewById(R.id.icon);
Takanori Nakano48544352016-12-02 18:32:59 +0900460 imageView.setImageBitmap(mStkInput.icon);
461 imageView.setVisibility(View.VISIBLE);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800462 }
463
464 // Handle specific global and text attributes.
465 switch (mState) {
Wink Saville79085fc2009-06-09 10:27:23 -0700466 case STATE_TEXT:
Yoshiaki Nakac1efd352019-02-21 17:13:38 +0900467 mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter(mStkInput.maxLen)});
Wink Saville79085fc2009-06-09 10:27:23 -0700468
Yoshiaki Nakac1efd352019-02-21 17:13:38 +0900469 textInput.setCounterMaxLength(mStkInput.maxLen);
470 textInput.setCounterEnabled(true);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800471
472 if (!mStkInput.echo) {
Yujing Gu6b9716c2014-04-23 13:50:50 +0800473 mTextIn.setTransformationMethod(PasswordTransformationMethod
474 .getInstance());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800475 }
Srikanth Chintalaa091b732016-02-04 14:46:43 +0530476 mTextIn.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
Kazuhiro Uto12870912018-07-18 17:43:56 +0900477 // Request the initial focus on the edit box and show the software keyboard.
478 mTextIn.requestFocus();
479 getWindow().setSoftInputMode(
480 WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800481 // Set default text if present.
482 if (mStkInput.defaultText != null) {
483 mTextIn.setText(mStkInput.defaultText);
484 } else {
485 // make sure the text is cleared
486 mTextIn.setText("", BufferType.EDITABLE);
487 }
Miyu Iijimac9a17202018-10-17 19:17:14 +0900488 updateButton();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800489
490 break;
491 case STATE_YES_NO:
492 // Set display mode - normal / yes-no layout
493 mYesNoLayout.setVisibility(View.VISIBLE);
494 mNormalLayout.setVisibility(View.GONE);
495 break;
496 }
497 }
498
Wink Savillee68857d2014-10-17 15:23:05 -0700499 private void initFromIntent(Intent intent) {
500 // Get the calling intent type: text/key, and setup the
501 // display parameters.
502 CatLog.d(LOG_TAG, "initFromIntent - slot id: " + mSlotId);
503 if (intent != null) {
504 mStkInput = intent.getParcelableExtra("INPUT");
505 mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
506 CatLog.d(LOG_TAG, "onCreate - slot id: " + mSlotId);
507 if (mStkInput == null) {
508 finish();
509 } else {
510 mState = mStkInput.yesNo ? STATE_YES_NO :
511 STATE_TEXT;
512 configInputDisplay();
513 }
514 } else {
515 finish();
516 }
517 }
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900518
519 private final AlarmManager.OnAlarmListener mAlarmListener =
520 new AlarmManager.OnAlarmListener() {
521 @Override
522 public void onAlarm() {
523 CatLog.d(LOG_TAG, "The alarm time is reached");
524 mAlarmTime = NO_INPUT_ALARM;
Yoshiaki Nakaa95f5c82016-09-02 11:27:05 +0900525 sendResponse(StkAppService.RES_ID_TIMEOUT);
526 }
527 };
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800528}