blob: 5c6087b1314bdb4587acbc5c61213aa5fe767807 [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
Wink Saville79085fc2009-06-09 10:27:23 -070084 // message id for time out
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080085 private static final int MSG_ID_TIMEOUT = 1;
Wink Savillee68857d2014-10-17 15:23:05 -070086 private StkAppService appService = StkAppService.getInstance();
87
88 private boolean mIsResponseSent = false;
89 private int mSlotId = -1;
90 Activity mInstance = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080091
92 Handler mTimeoutHandler = new Handler() {
93 @Override
94 public void handleMessage(Message msg) {
95 switch(msg.what) {
96 case MSG_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -070097 CatLog.d(LOG_TAG, "Msg timeout.");
98 mAcceptUsersInput = false;
99 appService.getStkContext(mSlotId).setPendingActivityInstance(mInstance);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800100 sendResponse(StkAppService.RES_ID_TIMEOUT);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800101 break;
102 }
103 }
104 };
105
106 // Click listener to handle buttons press..
107 public void onClick(View v) {
108 String input = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700109 if (!mAcceptUsersInput) {
110 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
111 return;
112 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800113
114 switch (v.getId()) {
115 case R.id.button_ok:
116 // Check that text entered is valid .
117 if (!verfiyTypedText()) {
Wink Savillee68857d2014-10-17 15:23:05 -0700118 CatLog.d(LOG_TAG, "handleClick, invalid text");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800119 return;
120 }
Wink Savillee68857d2014-10-17 15:23:05 -0700121 mAcceptUsersInput = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800122 input = mTextIn.getText().toString();
123 break;
Takanori Nakano260df9a2017-12-05 22:26:30 +0900124 case R.id.button_cancel:
125 mAcceptUsersInput = false;
126 cancelTimeOut();
127 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
128 sendResponse(StkAppService.RES_ID_END_SESSION);
129 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800130 // Yes/No layout buttons.
131 case R.id.button_yes:
Wink Savillee68857d2014-10-17 15:23:05 -0700132 mAcceptUsersInput = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800133 input = YES_STR_RESPONSE;
134 break;
135 case R.id.button_no:
Wink Savillee68857d2014-10-17 15:23:05 -0700136 mAcceptUsersInput = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800137 input = NO_STR_RESPONSE;
138 break;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900139 case R.id.more:
140 if (mPopupMenu == null) {
141 mPopupMenu = new PopupMenu(this, v);
142 Menu menu = mPopupMenu.getMenu();
143 createOptionsMenuInternal(menu);
144 prepareOptionsMenuInternal(menu);
145 mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
146 public boolean onMenuItemClick(MenuItem item) {
147 optionsItemSelectedInternal(item);
148 return true;
149 }
150 });
151 mPopupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
152 public void onDismiss(PopupMenu menu) {
153 mPopupMenu = null;
154 }
155 });
156 mPopupMenu.show();
157 }
158 return;
159 default:
160 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800161 }
Wink Savillee68857d2014-10-17 15:23:05 -0700162 CatLog.d(LOG_TAG, "handleClick, ready to response");
Preeti Ahuja03be6672012-08-30 19:21:25 +0530163 cancelTimeOut();
Wink Savillee68857d2014-10-17 15:23:05 -0700164 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800165 sendResponse(StkAppService.RES_ID_INPUT, input, false);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800166 }
167
168 @Override
169 public void onCreate(Bundle icicle) {
170 super.onCreate(icicle);
171
Wink Savillee68857d2014-10-17 15:23:05 -0700172 CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]");
173
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900174 // appService can be null if this activity is automatically recreated by the system
175 // with the saved instance state right after the phone process is killed.
176 if (appService == null) {
177 CatLog.d(LOG_TAG, "onCreate - appService is null");
178 finish();
179 return;
180 }
181
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900182 ActionBar actionBar = null;
183 if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) {
184 actionBar = getActionBar();
185 if (actionBar != null) {
186 actionBar.hide();
187 }
188 }
Takanori Nakano48544352016-12-02 18:32:59 +0900189
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800190 // Set the layout for this activity.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800191 setContentView(R.layout.stk_input);
192
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900193 if (actionBar != null) {
194 mMoreOptions = findViewById(R.id.more);
195 mMoreOptions.setVisibility(View.VISIBLE);
196 mMoreOptions.setOnClickListener(this);
197 }
198
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800199 // Initialize members
200 mTextIn = (EditText) this.findViewById(R.id.in_text);
201 mPromptView = (TextView) this.findViewById(R.id.prompt);
Wink Savillee68857d2014-10-17 15:23:05 -0700202 mInstance = this;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800203 // Set buttons listeners.
Wink Saville79085fc2009-06-09 10:27:23 -0700204 Button okButton = (Button) findViewById(R.id.button_ok);
Takanori Nakano260df9a2017-12-05 22:26:30 +0900205 Button cancelButton = (Button) findViewById(R.id.button_cancel);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800206 Button yesButton = (Button) findViewById(R.id.button_yes);
207 Button noButton = (Button) findViewById(R.id.button_no);
208
209 okButton.setOnClickListener(this);
Takanori Nakano260df9a2017-12-05 22:26:30 +0900210 cancelButton.setOnClickListener(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800211 yesButton.setOnClickListener(this);
212 noButton.setOnClickListener(this);
213
214 mYesNoLayout = findViewById(R.id.yes_no_layout);
215 mNormalLayout = findViewById(R.id.normal_layout);
Wink Savillee68857d2014-10-17 15:23:05 -0700216 initFromIntent(getIntent());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800217 mContext = getBaseContext();
Wink Savillee68857d2014-10-17 15:23:05 -0700218 mAcceptUsersInput = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800219 }
220
221 @Override
222 protected void onPostCreate(Bundle savedInstanceState) {
223 super.onPostCreate(savedInstanceState);
224
225 mTextIn.addTextChangedListener(this);
226 }
227
228 @Override
229 public void onResume() {
230 super.onResume();
Wink Savillee68857d2014-10-17 15:23:05 -0700231 CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
232 "], slot id: " + mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800233 startTimeOut();
234 }
235
236 @Override
237 public void onPause() {
238 super.onPause();
Wink Savillee68857d2014-10-17 15:23:05 -0700239 CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]");
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900240 if (mPopupMenu != null) {
241 mPopupMenu.dismiss();
242 }
Wink Savillee68857d2014-10-17 15:23:05 -0700243 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800244
Wink Savillee68857d2014-10-17 15:23:05 -0700245 @Override
246 public void onStop() {
247 super.onStop();
248 CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]");
Yoshiaki Nakacec55b82017-10-20 15:53:43 +0900249 // It is unnecessary to keep this activity if the response was already sent and
250 // this got invisible because of the other full-screen activity in this application.
251 if (mIsResponseSent && appService.isTopOfStack()) {
Wink Savillee68857d2014-10-17 15:23:05 -0700252 cancelTimeOut();
253 finish();
254 } else {
255 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
256 }
257 }
258
259 @Override
260 public void onDestroy() {
261 super.onDestroy();
262 CatLog.d(LOG_TAG, "onDestroy - before Send End Session mIsResponseSent[" +
263 mIsResponseSent + " , " + mSlotId + "]");
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900264 if (appService == null) {
265 return;
266 }
Wink Savillee68857d2014-10-17 15:23:05 -0700267 //If the input activity is finished by stkappservice
268 //when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here
269 //, since the input cmd is waiting user to process.
270 if (!mIsResponseSent && !appService.isInputPending(mSlotId)) {
271 CatLog.d(LOG_TAG, "handleDestroy - Send End Session");
272 sendResponse(StkAppService.RES_ID_END_SESSION);
273 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800274 cancelTimeOut();
275 }
276
277 @Override
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900278 public void onConfigurationChanged(Configuration newConfig) {
279 super.onConfigurationChanged(newConfig);
280 if (mPopupMenu != null) {
281 mPopupMenu.dismiss();
282 }
283 }
284
285 @Override
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800286 public boolean onKeyDown(int keyCode, KeyEvent event) {
Wink Savillee68857d2014-10-17 15:23:05 -0700287 if (!mAcceptUsersInput) {
288 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
289 return true;
290 }
291
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800292 switch (keyCode) {
293 case KeyEvent.KEYCODE_BACK:
Wink Savillee68857d2014-10-17 15:23:05 -0700294 CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK");
295 mAcceptUsersInput = false;
Preeti Ahuja03be6672012-08-30 19:21:25 +0530296 cancelTimeOut();
Wink Savillee68857d2014-10-17 15:23:05 -0700297 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800298 sendResponse(StkAppService.RES_ID_BACKWARD, null, false);
Wink Savillee68857d2014-10-17 15:23:05 -0700299 return true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800300 }
301 return super.onKeyDown(keyCode, event);
302 }
303
Wink Savillee68857d2014-10-17 15:23:05 -0700304 void sendResponse(int resId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800305 sendResponse(resId, null, false);
306 }
307
Wink Savillee68857d2014-10-17 15:23:05 -0700308 void sendResponse(int resId, String input, boolean help) {
309 if (mSlotId == -1) {
310 CatLog.d(LOG_TAG, "slot id is invalid");
311 return;
312 }
313
314 if (StkAppService.getInstance() == null) {
315 CatLog.d(LOG_TAG, "StkAppService is null, Ignore response: id is " + resId);
316 return;
317 }
318
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900319 if (mMoreOptions != null) {
320 mMoreOptions.setVisibility(View.INVISIBLE);
321 }
322
Cuihtlauac ALVARADObde7f032015-05-29 16:25:12 +0200323 CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help["
324 + help + "]");
Wink Savillee68857d2014-10-17 15:23:05 -0700325 mIsResponseSent = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800326 Bundle args = new Bundle();
327 args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE);
Wink Savillee68857d2014-10-17 15:23:05 -0700328 args.putInt(StkAppService.SLOT_ID, mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800329 args.putInt(StkAppService.RES_ID, resId);
330 if (input != null) {
331 args.putString(StkAppService.INPUT, input);
332 }
333 args.putBoolean(StkAppService.HELP, help);
334 mContext.startService(new Intent(mContext, StkAppService.class)
335 .putExtras(args));
336 }
337
338 @Override
339 public boolean onCreateOptionsMenu(android.view.Menu menu) {
340 super.onCreateOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900341 createOptionsMenuInternal(menu);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800342 return true;
343 }
344
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900345 private void createOptionsMenuInternal(Menu menu) {
346 menu.add(Menu.NONE, StkApp.MENU_ID_END_SESSION, 1, R.string.menu_end_session);
347 menu.add(0, StkApp.MENU_ID_HELP, 2, R.string.help);
348 }
349
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800350 @Override
351 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
352 super.onPrepareOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900353 prepareOptionsMenuInternal(menu);
354 return true;
355 }
356
357 private void prepareOptionsMenuInternal(Menu menu) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800358 menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true);
359 menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800360 }
361
362 @Override
363 public boolean onOptionsItemSelected(MenuItem item) {
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900364 if (optionsItemSelectedInternal(item)) {
365 return true;
366 }
367 return super.onOptionsItemSelected(item);
368 }
369
370 private boolean optionsItemSelectedInternal(MenuItem item) {
Wink Savillee68857d2014-10-17 15:23:05 -0700371 if (!mAcceptUsersInput) {
372 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
373 return true;
374 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800375 switch (item.getItemId()) {
376 case StkApp.MENU_ID_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -0700377 mAcceptUsersInput = false;
378 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800379 sendResponse(StkAppService.RES_ID_END_SESSION);
380 finish();
381 return true;
382 case StkApp.MENU_ID_HELP:
Wink Savillee68857d2014-10-17 15:23:05 -0700383 mAcceptUsersInput = false;
384 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800385 sendResponse(StkAppService.RES_ID_INPUT, "", true);
386 finish();
387 return true;
388 }
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900389 return false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800390 }
391
Wink Savillee68857d2014-10-17 15:23:05 -0700392 @Override
393 protected void onSaveInstanceState(Bundle outState) {
394 CatLog.d(LOG_TAG, "onSaveInstanceState: " + mSlotId);
395 outState.putBoolean("ACCEPT_USERS_INPUT", mAcceptUsersInput);
396 }
397
398 @Override
399 protected void onRestoreInstanceState(Bundle savedInstanceState) {
400 CatLog.d(LOG_TAG, "onRestoreInstanceState: " + mSlotId);
401 mAcceptUsersInput = savedInstanceState.getBoolean("ACCEPT_USERS_INPUT");
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900402 if ((mAcceptUsersInput == false) && (mMoreOptions != null)) {
403 mMoreOptions.setVisibility(View.INVISIBLE);
404 }
Wink Savillee68857d2014-10-17 15:23:05 -0700405 }
406
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800407 public void beforeTextChanged(CharSequence s, int start, int count,
408 int after) {
409 }
410
411 public void onTextChanged(CharSequence s, int start, int before, int count) {
412 // Reset timeout.
413 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() {
429 mTimeoutHandler.removeMessages(MSG_ID_TIMEOUT);
430 }
431
432 private void startTimeOut() {
Abhishek Adappac7c3a462013-02-14 13:36:57 -0800433 int duration = StkApp.calculateDurationInMilis(mStkInput.duration);
434
435 if (duration <= 0) {
436 duration = StkApp.UI_TIMEOUT;
437 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800438 cancelTimeOut();
439 mTimeoutHandler.sendMessageDelayed(mTimeoutHandler
Abhishek Adappac7c3a462013-02-14 13:36:57 -0800440 .obtainMessage(MSG_ID_TIMEOUT), duration);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800441 }
442
443 private void configInputDisplay() {
444 TextView numOfCharsView = (TextView) findViewById(R.id.num_of_chars);
445 TextView inTypeView = (TextView) findViewById(R.id.input_type);
446
447 int inTypeId = R.string.alphabet;
448
449 // set the prompt.
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900450 if ((mStkInput.icon == null || !mStkInput.iconSelfExplanatory)
451 && !TextUtils.isEmpty(mStkInput.text)) {
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900452 mPromptView.setText(mStkInput.text);
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900453 mPromptView.setVisibility(View.VISIBLE);
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900454 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800455
Wink Saville79085fc2009-06-09 10:27:23 -0700456 // Set input type (alphabet/digit) info close to the InText form.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800457 if (mStkInput.digitOnly) {
458 mTextIn.setKeyListener(StkDigitsKeyListener.getInstance());
459 inTypeId = R.string.digits;
460 }
461 inTypeView.setText(inTypeId);
462
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900463 setTitle(R.string.app_name);
Takanori Nakano48544352016-12-02 18:32:59 +0900464
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800465 if (mStkInput.icon != null) {
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900466 ImageView imageView = (ImageView) findViewById(R.id.icon);
Takanori Nakano48544352016-12-02 18:32:59 +0900467 imageView.setImageBitmap(mStkInput.icon);
468 imageView.setVisibility(View.VISIBLE);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800469 }
470
471 // Handle specific global and text attributes.
472 switch (mState) {
Wink Saville79085fc2009-06-09 10:27:23 -0700473 case STATE_TEXT:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800474 int maxLen = mStkInput.maxLen;
475 int minLen = mStkInput.minLen;
476 mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter(
477 maxLen)});
Wink Saville79085fc2009-06-09 10:27:23 -0700478
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800479 // Set number of chars info.
480 String lengthLimit = String.valueOf(minLen);
481 if (maxLen != minLen) {
482 lengthLimit = minLen + " - " + maxLen;
483 }
484 numOfCharsView.setText(lengthLimit);
485
486 if (!mStkInput.echo) {
Yujing Gu6b9716c2014-04-23 13:50:50 +0800487 mTextIn.setTransformationMethod(PasswordTransformationMethod
488 .getInstance());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800489 }
Srikanth Chintalaa091b732016-02-04 14:46:43 +0530490 mTextIn.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800491 // Set default text if present.
492 if (mStkInput.defaultText != null) {
493 mTextIn.setText(mStkInput.defaultText);
494 } else {
495 // make sure the text is cleared
496 mTextIn.setText("", BufferType.EDITABLE);
497 }
498
499 break;
500 case STATE_YES_NO:
501 // Set display mode - normal / yes-no layout
502 mYesNoLayout.setVisibility(View.VISIBLE);
503 mNormalLayout.setVisibility(View.GONE);
504 break;
505 }
506 }
507
508 private float getFontSizeFactor(FontSize size) {
Wink Saville79085fc2009-06-09 10:27:23 -0700509 final float[] fontSizes =
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800510 {NORMAL_FONT_FACTOR, LARGE_FONT_FACTOR, SMALL_FONT_FACTOR};
511
512 return fontSizes[size.ordinal()];
513 }
Wink Savillee68857d2014-10-17 15:23:05 -0700514
515 private void initFromIntent(Intent intent) {
516 // Get the calling intent type: text/key, and setup the
517 // display parameters.
518 CatLog.d(LOG_TAG, "initFromIntent - slot id: " + mSlotId);
519 if (intent != null) {
520 mStkInput = intent.getParcelableExtra("INPUT");
521 mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
522 CatLog.d(LOG_TAG, "onCreate - slot id: " + mSlotId);
523 if (mStkInput == null) {
524 finish();
525 } else {
526 mState = mStkInput.yesNo ? STATE_YES_NO :
527 STATE_TEXT;
528 configInputDisplay();
529 }
530 } else {
531 finish();
532 }
533 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800534}