blob: ae59a8f626bd19375a088a225349b6b80a0356d8 [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;
34import android.view.KeyEvent;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090035import android.view.Menu;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080036import android.view.MenuItem;
37import android.view.View;
38import android.view.Window;
39import android.widget.Button;
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;
43import android.widget.EditText;
44import android.widget.TextView.BufferType;
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.FontSize;
47import com.android.internal.telephony.cat.Input;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080048
49/**
50 * Display a request for a text input a long with a text edit form.
51 */
52public class StkInputActivity extends Activity implements View.OnClickListener,
53 TextWatcher {
54
55 // Members
56 private int mState;
57 private Context mContext;
58 private EditText mTextIn = null;
59 private TextView mPromptView = null;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +090060 private View mMoreOptions = null;
61 private PopupMenu mPopupMenu = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080062 private View mYesNoLayout = null;
63 private View mNormalLayout = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080064
65 // Constants
Wink Savillee68857d2014-10-17 15:23:05 -070066 private static final String className = new Object(){}.getClass().getEnclosingClass().getName();
67 private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1);
68
69 private Input mStkInput = null;
70 private boolean mAcceptUsersInput = true;
71 // Constants
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080072 private static final int STATE_TEXT = 1;
73 private static final int STATE_YES_NO = 2;
74
75 static final String YES_STR_RESPONSE = "YES";
76 static final String NO_STR_RESPONSE = "NO";
77
78 // Font size factor values.
79 static final float NORMAL_FONT_FACTOR = 1;
80 static final float LARGE_FONT_FACTOR = 2;
81 static final float SMALL_FONT_FACTOR = (1 / 2);
82
Wink Saville79085fc2009-06-09 10:27:23 -070083 // message id for time out
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080084 private static final int MSG_ID_TIMEOUT = 1;
Wink Savillee68857d2014-10-17 15:23:05 -070085 private StkAppService appService = StkAppService.getInstance();
86
87 private boolean mIsResponseSent = false;
88 private int mSlotId = -1;
89 Activity mInstance = null;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080090
91 Handler mTimeoutHandler = new Handler() {
92 @Override
93 public void handleMessage(Message msg) {
94 switch(msg.what) {
95 case MSG_ID_TIMEOUT:
Wink Savillee68857d2014-10-17 15:23:05 -070096 CatLog.d(LOG_TAG, "Msg timeout.");
97 mAcceptUsersInput = false;
98 appService.getStkContext(mSlotId).setPendingActivityInstance(mInstance);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080099 sendResponse(StkAppService.RES_ID_TIMEOUT);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800100 break;
101 }
102 }
103 };
104
105 // Click listener to handle buttons press..
106 public void onClick(View v) {
107 String input = null;
Wink Savillee68857d2014-10-17 15:23:05 -0700108 if (!mAcceptUsersInput) {
109 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
110 return;
111 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800112
113 switch (v.getId()) {
114 case R.id.button_ok:
115 // Check that text entered is valid .
116 if (!verfiyTypedText()) {
Wink Savillee68857d2014-10-17 15:23:05 -0700117 CatLog.d(LOG_TAG, "handleClick, invalid text");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800118 return;
119 }
Wink Savillee68857d2014-10-17 15:23:05 -0700120 mAcceptUsersInput = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800121 input = mTextIn.getText().toString();
122 break;
123 // Yes/No layout buttons.
124 case R.id.button_yes:
Wink Savillee68857d2014-10-17 15:23:05 -0700125 mAcceptUsersInput = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800126 input = YES_STR_RESPONSE;
127 break;
128 case R.id.button_no:
Wink Savillee68857d2014-10-17 15:23:05 -0700129 mAcceptUsersInput = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800130 input = NO_STR_RESPONSE;
131 break;
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900132 case R.id.more:
133 if (mPopupMenu == null) {
134 mPopupMenu = new PopupMenu(this, v);
135 Menu menu = mPopupMenu.getMenu();
136 createOptionsMenuInternal(menu);
137 prepareOptionsMenuInternal(menu);
138 mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
139 public boolean onMenuItemClick(MenuItem item) {
140 optionsItemSelectedInternal(item);
141 return true;
142 }
143 });
144 mPopupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
145 public void onDismiss(PopupMenu menu) {
146 mPopupMenu = null;
147 }
148 });
149 mPopupMenu.show();
150 }
151 return;
152 default:
153 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800154 }
Wink Savillee68857d2014-10-17 15:23:05 -0700155 CatLog.d(LOG_TAG, "handleClick, ready to response");
Preeti Ahuja03be6672012-08-30 19:21:25 +0530156 cancelTimeOut();
Wink Savillee68857d2014-10-17 15:23:05 -0700157 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800158 sendResponse(StkAppService.RES_ID_INPUT, input, false);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800159 }
160
161 @Override
162 public void onCreate(Bundle icicle) {
163 super.onCreate(icicle);
164
Wink Savillee68857d2014-10-17 15:23:05 -0700165 CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]");
166
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900167 // appService can be null if this activity is automatically recreated by the system
168 // with the saved instance state right after the phone process is killed.
169 if (appService == null) {
170 CatLog.d(LOG_TAG, "onCreate - appService is null");
171 finish();
172 return;
173 }
174
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900175 ActionBar actionBar = null;
176 if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) {
177 actionBar = getActionBar();
178 if (actionBar != null) {
179 actionBar.hide();
180 }
181 }
Takanori Nakano48544352016-12-02 18:32:59 +0900182
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800183 // Set the layout for this activity.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800184 setContentView(R.layout.stk_input);
185
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900186 if (actionBar != null) {
187 mMoreOptions = findViewById(R.id.more);
188 mMoreOptions.setVisibility(View.VISIBLE);
189 mMoreOptions.setOnClickListener(this);
190 }
191
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800192 // Initialize members
193 mTextIn = (EditText) this.findViewById(R.id.in_text);
194 mPromptView = (TextView) this.findViewById(R.id.prompt);
Wink Savillee68857d2014-10-17 15:23:05 -0700195 mInstance = this;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800196 // Set buttons listeners.
Wink Saville79085fc2009-06-09 10:27:23 -0700197 Button okButton = (Button) findViewById(R.id.button_ok);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800198 Button yesButton = (Button) findViewById(R.id.button_yes);
199 Button noButton = (Button) findViewById(R.id.button_no);
200
201 okButton.setOnClickListener(this);
202 yesButton.setOnClickListener(this);
203 noButton.setOnClickListener(this);
204
205 mYesNoLayout = findViewById(R.id.yes_no_layout);
206 mNormalLayout = findViewById(R.id.normal_layout);
Wink Savillee68857d2014-10-17 15:23:05 -0700207 initFromIntent(getIntent());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800208 mContext = getBaseContext();
Wink Savillee68857d2014-10-17 15:23:05 -0700209 mAcceptUsersInput = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800210 }
211
212 @Override
213 protected void onPostCreate(Bundle savedInstanceState) {
214 super.onPostCreate(savedInstanceState);
215
216 mTextIn.addTextChangedListener(this);
217 }
218
219 @Override
220 public void onResume() {
221 super.onResume();
Wink Savillee68857d2014-10-17 15:23:05 -0700222 CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
223 "], slot id: " + mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800224 startTimeOut();
Wink Savillee68857d2014-10-17 15:23:05 -0700225 appService.getStkContext(mSlotId).setPendingActivityInstance(null);
hoonsung.parkcba29962015-07-06 23:17:38 +0900226 if (mIsResponseSent) {
227 cancelTimeOut();
228 finish();
229 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800230 }
231
232 @Override
233 public void onPause() {
234 super.onPause();
Wink Savillee68857d2014-10-17 15:23:05 -0700235 CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]");
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900236 if (mPopupMenu != null) {
237 mPopupMenu.dismiss();
238 }
Wink Savillee68857d2014-10-17 15:23:05 -0700239 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800240
Wink Savillee68857d2014-10-17 15:23:05 -0700241 @Override
242 public void onStop() {
243 super.onStop();
244 CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]");
245 if (mIsResponseSent) {
246 cancelTimeOut();
247 finish();
248 } else {
249 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
250 }
251 }
252
253 @Override
254 public void onDestroy() {
255 super.onDestroy();
256 CatLog.d(LOG_TAG, "onDestroy - before Send End Session mIsResponseSent[" +
257 mIsResponseSent + " , " + mSlotId + "]");
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900258 if (appService == null) {
259 return;
260 }
Wink Savillee68857d2014-10-17 15:23:05 -0700261 //If the input activity is finished by stkappservice
262 //when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here
263 //, since the input cmd is waiting user to process.
264 if (!mIsResponseSent && !appService.isInputPending(mSlotId)) {
265 CatLog.d(LOG_TAG, "handleDestroy - Send End Session");
266 sendResponse(StkAppService.RES_ID_END_SESSION);
267 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800268 cancelTimeOut();
269 }
270
271 @Override
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900272 public void onConfigurationChanged(Configuration newConfig) {
273 super.onConfigurationChanged(newConfig);
274 if (mPopupMenu != null) {
275 mPopupMenu.dismiss();
276 }
277 }
278
279 @Override
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800280 public boolean onKeyDown(int keyCode, KeyEvent event) {
Wink Savillee68857d2014-10-17 15:23:05 -0700281 if (!mAcceptUsersInput) {
282 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
283 return true;
284 }
285
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800286 switch (keyCode) {
287 case KeyEvent.KEYCODE_BACK:
Wink Savillee68857d2014-10-17 15:23:05 -0700288 CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK");
289 mAcceptUsersInput = false;
Preeti Ahuja03be6672012-08-30 19:21:25 +0530290 cancelTimeOut();
Wink Savillee68857d2014-10-17 15:23:05 -0700291 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800292 sendResponse(StkAppService.RES_ID_BACKWARD, null, false);
Wink Savillee68857d2014-10-17 15:23:05 -0700293 return true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800294 }
295 return super.onKeyDown(keyCode, event);
296 }
297
Wink Savillee68857d2014-10-17 15:23:05 -0700298 void sendResponse(int resId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800299 sendResponse(resId, null, false);
300 }
301
Wink Savillee68857d2014-10-17 15:23:05 -0700302 void sendResponse(int resId, String input, boolean help) {
303 if (mSlotId == -1) {
304 CatLog.d(LOG_TAG, "slot id is invalid");
305 return;
306 }
307
308 if (StkAppService.getInstance() == null) {
309 CatLog.d(LOG_TAG, "StkAppService is null, Ignore response: id is " + resId);
310 return;
311 }
312
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900313 if (mMoreOptions != null) {
314 mMoreOptions.setVisibility(View.INVISIBLE);
315 }
316
Cuihtlauac ALVARADObde7f032015-05-29 16:25:12 +0200317 CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help["
318 + help + "]");
Wink Savillee68857d2014-10-17 15:23:05 -0700319 mIsResponseSent = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800320 Bundle args = new Bundle();
321 args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE);
Wink Savillee68857d2014-10-17 15:23:05 -0700322 args.putInt(StkAppService.SLOT_ID, mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800323 args.putInt(StkAppService.RES_ID, resId);
324 if (input != null) {
325 args.putString(StkAppService.INPUT, input);
326 }
327 args.putBoolean(StkAppService.HELP, help);
328 mContext.startService(new Intent(mContext, StkAppService.class)
329 .putExtras(args));
330 }
331
332 @Override
333 public boolean onCreateOptionsMenu(android.view.Menu menu) {
334 super.onCreateOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900335 createOptionsMenuInternal(menu);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800336 return true;
337 }
338
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900339 private void createOptionsMenuInternal(Menu menu) {
340 menu.add(Menu.NONE, StkApp.MENU_ID_END_SESSION, 1, R.string.menu_end_session);
341 menu.add(0, StkApp.MENU_ID_HELP, 2, R.string.help);
342 }
343
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800344 @Override
345 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
346 super.onPrepareOptionsMenu(menu);
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900347 prepareOptionsMenuInternal(menu);
348 return true;
349 }
350
351 private void prepareOptionsMenuInternal(Menu menu) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800352 menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true);
353 menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800354 }
355
356 @Override
357 public boolean onOptionsItemSelected(MenuItem item) {
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900358 if (optionsItemSelectedInternal(item)) {
359 return true;
360 }
361 return super.onOptionsItemSelected(item);
362 }
363
364 private boolean optionsItemSelectedInternal(MenuItem item) {
Wink Savillee68857d2014-10-17 15:23:05 -0700365 if (!mAcceptUsersInput) {
366 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
367 return true;
368 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800369 switch (item.getItemId()) {
370 case StkApp.MENU_ID_END_SESSION:
Wink Savillee68857d2014-10-17 15:23:05 -0700371 mAcceptUsersInput = false;
372 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800373 sendResponse(StkAppService.RES_ID_END_SESSION);
374 finish();
375 return true;
376 case StkApp.MENU_ID_HELP:
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_INPUT, "", true);
380 finish();
381 return true;
382 }
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900383 return false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800384 }
385
Wink Savillee68857d2014-10-17 15:23:05 -0700386 @Override
387 protected void onSaveInstanceState(Bundle outState) {
388 CatLog.d(LOG_TAG, "onSaveInstanceState: " + mSlotId);
389 outState.putBoolean("ACCEPT_USERS_INPUT", mAcceptUsersInput);
390 }
391
392 @Override
393 protected void onRestoreInstanceState(Bundle savedInstanceState) {
394 CatLog.d(LOG_TAG, "onRestoreInstanceState: " + mSlotId);
395 mAcceptUsersInput = savedInstanceState.getBoolean("ACCEPT_USERS_INPUT");
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900396 if ((mAcceptUsersInput == false) && (mMoreOptions != null)) {
397 mMoreOptions.setVisibility(View.INVISIBLE);
398 }
Wink Savillee68857d2014-10-17 15:23:05 -0700399 }
400
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800401 public void beforeTextChanged(CharSequence s, int start, int count,
402 int after) {
403 }
404
405 public void onTextChanged(CharSequence s, int start, int before, int count) {
406 // Reset timeout.
407 startTimeOut();
408 }
409
410 public void afterTextChanged(Editable s) {
411 }
412
413 private boolean verfiyTypedText() {
414 // If not enough input was typed in stay on the edit screen.
415 if (mTextIn.getText().length() < mStkInput.minLen) {
416 return false;
417 }
418
419 return true;
420 }
421
422 private void cancelTimeOut() {
423 mTimeoutHandler.removeMessages(MSG_ID_TIMEOUT);
424 }
425
426 private void startTimeOut() {
Abhishek Adappac7c3a462013-02-14 13:36:57 -0800427 int duration = StkApp.calculateDurationInMilis(mStkInput.duration);
428
429 if (duration <= 0) {
430 duration = StkApp.UI_TIMEOUT;
431 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800432 cancelTimeOut();
433 mTimeoutHandler.sendMessageDelayed(mTimeoutHandler
Abhishek Adappac7c3a462013-02-14 13:36:57 -0800434 .obtainMessage(MSG_ID_TIMEOUT), duration);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800435 }
436
437 private void configInputDisplay() {
438 TextView numOfCharsView = (TextView) findViewById(R.id.num_of_chars);
439 TextView inTypeView = (TextView) findViewById(R.id.input_type);
440
441 int inTypeId = R.string.alphabet;
442
443 // set the prompt.
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900444 if ((mStkInput.icon == null || !mStkInput.iconSelfExplanatory)
445 && !TextUtils.isEmpty(mStkInput.text)) {
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900446 mPromptView.setText(mStkInput.text);
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900447 mPromptView.setVisibility(View.VISIBLE);
Takeshi Shinoharac6589002013-05-27 11:01:06 +0900448 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800449
Wink Saville79085fc2009-06-09 10:27:23 -0700450 // Set input type (alphabet/digit) info close to the InText form.
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800451 if (mStkInput.digitOnly) {
452 mTextIn.setKeyListener(StkDigitsKeyListener.getInstance());
453 inTypeId = R.string.digits;
454 }
455 inTypeView.setText(inTypeId);
456
Yoshiaki Naka28313ba2017-08-04 12:20:53 +0900457 setTitle(R.string.app_name);
Takanori Nakano48544352016-12-02 18:32:59 +0900458
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800459 if (mStkInput.icon != null) {
Yoshiaki Nakadd0dbb12017-08-03 21:20:38 +0900460 ImageView imageView = (ImageView) findViewById(R.id.icon);
Takanori Nakano48544352016-12-02 18:32:59 +0900461 imageView.setImageBitmap(mStkInput.icon);
462 imageView.setVisibility(View.VISIBLE);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800463 }
464
465 // Handle specific global and text attributes.
466 switch (mState) {
Wink Saville79085fc2009-06-09 10:27:23 -0700467 case STATE_TEXT:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800468 int maxLen = mStkInput.maxLen;
469 int minLen = mStkInput.minLen;
470 mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter(
471 maxLen)});
Wink Saville79085fc2009-06-09 10:27:23 -0700472
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800473 // Set number of chars info.
474 String lengthLimit = String.valueOf(minLen);
475 if (maxLen != minLen) {
476 lengthLimit = minLen + " - " + maxLen;
477 }
478 numOfCharsView.setText(lengthLimit);
479
480 if (!mStkInput.echo) {
Yujing Gu6b9716c2014-04-23 13:50:50 +0800481 mTextIn.setTransformationMethod(PasswordTransformationMethod
482 .getInstance());
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800483 }
484 // Set default text if present.
485 if (mStkInput.defaultText != null) {
486 mTextIn.setText(mStkInput.defaultText);
487 } else {
488 // make sure the text is cleared
489 mTextIn.setText("", BufferType.EDITABLE);
490 }
491
492 break;
493 case STATE_YES_NO:
494 // Set display mode - normal / yes-no layout
495 mYesNoLayout.setVisibility(View.VISIBLE);
496 mNormalLayout.setVisibility(View.GONE);
497 break;
498 }
499 }
500
501 private float getFontSizeFactor(FontSize size) {
Wink Saville79085fc2009-06-09 10:27:23 -0700502 final float[] fontSizes =
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800503 {NORMAL_FONT_FACTOR, LARGE_FONT_FACTOR, SMALL_FONT_FACTOR};
504
505 return fontSizes[size.ordinal()];
506 }
Wink Savillee68857d2014-10-17 15:23:05 -0700507
508 private void initFromIntent(Intent intent) {
509 // Get the calling intent type: text/key, and setup the
510 // display parameters.
511 CatLog.d(LOG_TAG, "initFromIntent - slot id: " + mSlotId);
512 if (intent != null) {
513 mStkInput = intent.getParcelableExtra("INPUT");
514 mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
515 CatLog.d(LOG_TAG, "onCreate - slot id: " + mSlotId);
516 if (mStkInput == null) {
517 finish();
518 } else {
519 mState = mStkInput.yesNo ? STATE_YES_NO :
520 STATE_TEXT;
521 configInputDisplay();
522 }
523 } else {
524 finish();
525 }
526 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800527}