The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 3 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 4 | * 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 Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 7 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 9 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 10 | * 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 | |
| 17 | package com.android.stk; |
| 18 | |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 19 | import android.app.ActionBar; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 20 | import android.app.Activity; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.graphics.drawable.BitmapDrawable; |
| 24 | import android.os.Bundle; |
| 25 | import android.os.Handler; |
| 26 | import android.os.Message; |
| 27 | import android.text.Editable; |
| 28 | import android.text.InputFilter; |
duho.ro | ee36b6f | 2013-09-03 15:15:16 +0900 | [diff] [blame] | 29 | import android.text.InputType; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 30 | import android.text.TextWatcher; |
| 31 | import android.text.method.PasswordTransformationMethod; |
Srikanth Chintala | a091b73 | 2016-02-04 14:46:43 +0530 | [diff] [blame^] | 32 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 33 | import android.view.KeyEvent; |
| 34 | import android.view.MenuItem; |
| 35 | import android.view.View; |
| 36 | import android.view.Window; |
| 37 | import android.widget.Button; |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 38 | import android.widget.ImageView; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 39 | import android.widget.TextView; |
| 40 | import android.widget.EditText; |
| 41 | import android.widget.TextView.BufferType; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 42 | import com.android.internal.telephony.cat.CatLog; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 43 | import com.android.internal.telephony.cat.FontSize; |
| 44 | import com.android.internal.telephony.cat.Input; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Display a request for a text input a long with a text edit form. |
| 48 | */ |
| 49 | public class StkInputActivity extends Activity implements View.OnClickListener, |
| 50 | TextWatcher { |
| 51 | |
| 52 | // Members |
| 53 | private int mState; |
| 54 | private Context mContext; |
| 55 | private EditText mTextIn = null; |
| 56 | private TextView mPromptView = null; |
| 57 | private View mYesNoLayout = null; |
| 58 | private View mNormalLayout = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 59 | |
| 60 | // Constants |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 61 | private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); |
| 62 | private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); |
| 63 | |
| 64 | private Input mStkInput = null; |
| 65 | private boolean mAcceptUsersInput = true; |
| 66 | // Constants |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 67 | private static final int STATE_TEXT = 1; |
| 68 | private static final int STATE_YES_NO = 2; |
| 69 | |
| 70 | static final String YES_STR_RESPONSE = "YES"; |
| 71 | static final String NO_STR_RESPONSE = "NO"; |
| 72 | |
| 73 | // Font size factor values. |
| 74 | static final float NORMAL_FONT_FACTOR = 1; |
| 75 | static final float LARGE_FONT_FACTOR = 2; |
| 76 | static final float SMALL_FONT_FACTOR = (1 / 2); |
| 77 | |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 78 | // message id for time out |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 79 | private static final int MSG_ID_TIMEOUT = 1; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 80 | private StkAppService appService = StkAppService.getInstance(); |
| 81 | |
| 82 | private boolean mIsResponseSent = false; |
| 83 | private int mSlotId = -1; |
| 84 | Activity mInstance = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 85 | |
| 86 | Handler mTimeoutHandler = new Handler() { |
| 87 | @Override |
| 88 | public void handleMessage(Message msg) { |
| 89 | switch(msg.what) { |
| 90 | case MSG_ID_TIMEOUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 91 | CatLog.d(LOG_TAG, "Msg timeout."); |
| 92 | mAcceptUsersInput = false; |
| 93 | appService.getStkContext(mSlotId).setPendingActivityInstance(mInstance); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 94 | sendResponse(StkAppService.RES_ID_TIMEOUT); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 95 | break; |
| 96 | } |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | // Click listener to handle buttons press.. |
| 101 | public void onClick(View v) { |
| 102 | String input = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 103 | if (!mAcceptUsersInput) { |
| 104 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 105 | return; |
| 106 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 107 | |
| 108 | switch (v.getId()) { |
| 109 | case R.id.button_ok: |
| 110 | // Check that text entered is valid . |
| 111 | if (!verfiyTypedText()) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 112 | CatLog.d(LOG_TAG, "handleClick, invalid text"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 113 | return; |
| 114 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 115 | mAcceptUsersInput = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 116 | input = mTextIn.getText().toString(); |
| 117 | break; |
| 118 | // Yes/No layout buttons. |
| 119 | case R.id.button_yes: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 120 | mAcceptUsersInput = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 121 | input = YES_STR_RESPONSE; |
| 122 | break; |
| 123 | case R.id.button_no: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 124 | mAcceptUsersInput = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 125 | input = NO_STR_RESPONSE; |
| 126 | break; |
| 127 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 128 | CatLog.d(LOG_TAG, "handleClick, ready to response"); |
Preeti Ahuja | 03be667 | 2012-08-30 19:21:25 +0530 | [diff] [blame] | 129 | cancelTimeOut(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 130 | appService.getStkContext(mSlotId).setPendingActivityInstance(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 131 | sendResponse(StkAppService.RES_ID_INPUT, input, false); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public void onCreate(Bundle icicle) { |
| 136 | super.onCreate(icicle); |
| 137 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 138 | CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]"); |
| 139 | |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 140 | // appService can be null if this activity is automatically recreated by the system |
| 141 | // with the saved instance state right after the phone process is killed. |
| 142 | if (appService == null) { |
| 143 | CatLog.d(LOG_TAG, "onCreate - appService is null"); |
| 144 | finish(); |
| 145 | return; |
| 146 | } |
| 147 | |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 148 | ActionBar actionBar = getActionBar(); |
| 149 | actionBar.setCustomView(R.layout.stk_title); |
| 150 | actionBar.setDisplayShowCustomEnabled(true); |
| 151 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 152 | // Set the layout for this activity. |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 153 | setContentView(R.layout.stk_input); |
| 154 | |
| 155 | // Initialize members |
| 156 | mTextIn = (EditText) this.findViewById(R.id.in_text); |
| 157 | mPromptView = (TextView) this.findViewById(R.id.prompt); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 158 | mInstance = this; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 159 | // Set buttons listeners. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 160 | Button okButton = (Button) findViewById(R.id.button_ok); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 161 | Button yesButton = (Button) findViewById(R.id.button_yes); |
| 162 | Button noButton = (Button) findViewById(R.id.button_no); |
| 163 | |
| 164 | okButton.setOnClickListener(this); |
| 165 | yesButton.setOnClickListener(this); |
| 166 | noButton.setOnClickListener(this); |
| 167 | |
| 168 | mYesNoLayout = findViewById(R.id.yes_no_layout); |
| 169 | mNormalLayout = findViewById(R.id.normal_layout); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 170 | initFromIntent(getIntent()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 171 | mContext = getBaseContext(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 172 | mAcceptUsersInput = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Override |
| 176 | protected void onPostCreate(Bundle savedInstanceState) { |
| 177 | super.onPostCreate(savedInstanceState); |
| 178 | |
| 179 | mTextIn.addTextChangedListener(this); |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public void onResume() { |
| 184 | super.onResume(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 185 | CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent + |
| 186 | "], slot id: " + mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 187 | startTimeOut(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 188 | appService.getStkContext(mSlotId).setPendingActivityInstance(null); |
hoonsung.park | cba2996 | 2015-07-06 23:17:38 +0900 | [diff] [blame] | 189 | if (mIsResponseSent) { |
| 190 | cancelTimeOut(); |
| 191 | finish(); |
| 192 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void onPause() { |
| 197 | super.onPause(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 198 | CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]"); |
| 199 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 200 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 201 | @Override |
| 202 | public void onStop() { |
| 203 | super.onStop(); |
| 204 | CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]"); |
| 205 | if (mIsResponseSent) { |
| 206 | cancelTimeOut(); |
| 207 | finish(); |
| 208 | } else { |
| 209 | appService.getStkContext(mSlotId).setPendingActivityInstance(this); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void onDestroy() { |
| 215 | super.onDestroy(); |
| 216 | CatLog.d(LOG_TAG, "onDestroy - before Send End Session mIsResponseSent[" + |
| 217 | mIsResponseSent + " , " + mSlotId + "]"); |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 218 | if (appService == null) { |
| 219 | return; |
| 220 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 221 | //If the input activity is finished by stkappservice |
| 222 | //when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here |
| 223 | //, since the input cmd is waiting user to process. |
| 224 | if (!mIsResponseSent && !appService.isInputPending(mSlotId)) { |
| 225 | CatLog.d(LOG_TAG, "handleDestroy - Send End Session"); |
| 226 | sendResponse(StkAppService.RES_ID_END_SESSION); |
| 227 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 228 | cancelTimeOut(); |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 233 | if (!mAcceptUsersInput) { |
| 234 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 235 | return true; |
| 236 | } |
| 237 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 238 | switch (keyCode) { |
| 239 | case KeyEvent.KEYCODE_BACK: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 240 | CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK"); |
| 241 | mAcceptUsersInput = false; |
Preeti Ahuja | 03be667 | 2012-08-30 19:21:25 +0530 | [diff] [blame] | 242 | cancelTimeOut(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 243 | appService.getStkContext(mSlotId).setPendingActivityInstance(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 244 | sendResponse(StkAppService.RES_ID_BACKWARD, null, false); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 245 | return true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 246 | } |
| 247 | return super.onKeyDown(keyCode, event); |
| 248 | } |
| 249 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 250 | void sendResponse(int resId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 251 | sendResponse(resId, null, false); |
| 252 | } |
| 253 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 254 | void sendResponse(int resId, String input, boolean help) { |
| 255 | if (mSlotId == -1) { |
| 256 | CatLog.d(LOG_TAG, "slot id is invalid"); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | if (StkAppService.getInstance() == null) { |
| 261 | CatLog.d(LOG_TAG, "StkAppService is null, Ignore response: id is " + resId); |
| 262 | return; |
| 263 | } |
| 264 | |
Cuihtlauac ALVARADO | bde7f03 | 2015-05-29 16:25:12 +0200 | [diff] [blame] | 265 | CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help[" |
| 266 | + help + "]"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 267 | mIsResponseSent = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 268 | Bundle args = new Bundle(); |
| 269 | args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 270 | args.putInt(StkAppService.SLOT_ID, mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 271 | args.putInt(StkAppService.RES_ID, resId); |
| 272 | if (input != null) { |
| 273 | args.putString(StkAppService.INPUT, input); |
| 274 | } |
| 275 | args.putBoolean(StkAppService.HELP, help); |
| 276 | mContext.startService(new Intent(mContext, StkAppService.class) |
| 277 | .putExtras(args)); |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public boolean onCreateOptionsMenu(android.view.Menu menu) { |
| 282 | super.onCreateOptionsMenu(menu); |
| 283 | menu.add(android.view.Menu.NONE, StkApp.MENU_ID_END_SESSION, 1, |
| 284 | R.string.menu_end_session); |
| 285 | menu.add(0, StkApp.MENU_ID_HELP, 2, R.string.help); |
| 286 | |
| 287 | return true; |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public boolean onPrepareOptionsMenu(android.view.Menu menu) { |
| 292 | super.onPrepareOptionsMenu(menu); |
| 293 | menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true); |
| 294 | menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable); |
| 295 | |
| 296 | return true; |
| 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public boolean onOptionsItemSelected(MenuItem item) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 301 | if (!mAcceptUsersInput) { |
| 302 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 303 | return true; |
| 304 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 305 | switch (item.getItemId()) { |
| 306 | case StkApp.MENU_ID_END_SESSION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 307 | mAcceptUsersInput = false; |
| 308 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 309 | sendResponse(StkAppService.RES_ID_END_SESSION); |
| 310 | finish(); |
| 311 | return true; |
| 312 | case StkApp.MENU_ID_HELP: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 313 | mAcceptUsersInput = false; |
| 314 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 315 | sendResponse(StkAppService.RES_ID_INPUT, "", true); |
| 316 | finish(); |
| 317 | return true; |
| 318 | } |
| 319 | return super.onOptionsItemSelected(item); |
| 320 | } |
| 321 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 322 | @Override |
| 323 | protected void onSaveInstanceState(Bundle outState) { |
| 324 | CatLog.d(LOG_TAG, "onSaveInstanceState: " + mSlotId); |
| 325 | outState.putBoolean("ACCEPT_USERS_INPUT", mAcceptUsersInput); |
| 326 | } |
| 327 | |
| 328 | @Override |
| 329 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 330 | CatLog.d(LOG_TAG, "onRestoreInstanceState: " + mSlotId); |
| 331 | mAcceptUsersInput = savedInstanceState.getBoolean("ACCEPT_USERS_INPUT"); |
| 332 | } |
| 333 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 334 | public void beforeTextChanged(CharSequence s, int start, int count, |
| 335 | int after) { |
| 336 | } |
| 337 | |
| 338 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 339 | // Reset timeout. |
| 340 | startTimeOut(); |
| 341 | } |
| 342 | |
| 343 | public void afterTextChanged(Editable s) { |
| 344 | } |
| 345 | |
| 346 | private boolean verfiyTypedText() { |
| 347 | // If not enough input was typed in stay on the edit screen. |
| 348 | if (mTextIn.getText().length() < mStkInput.minLen) { |
| 349 | return false; |
| 350 | } |
| 351 | |
| 352 | return true; |
| 353 | } |
| 354 | |
| 355 | private void cancelTimeOut() { |
| 356 | mTimeoutHandler.removeMessages(MSG_ID_TIMEOUT); |
| 357 | } |
| 358 | |
| 359 | private void startTimeOut() { |
Abhishek Adappa | c7c3a46 | 2013-02-14 13:36:57 -0800 | [diff] [blame] | 360 | int duration = StkApp.calculateDurationInMilis(mStkInput.duration); |
| 361 | |
| 362 | if (duration <= 0) { |
| 363 | duration = StkApp.UI_TIMEOUT; |
| 364 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 365 | cancelTimeOut(); |
| 366 | mTimeoutHandler.sendMessageDelayed(mTimeoutHandler |
Abhishek Adappa | c7c3a46 | 2013-02-14 13:36:57 -0800 | [diff] [blame] | 367 | .obtainMessage(MSG_ID_TIMEOUT), duration); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | private void configInputDisplay() { |
| 371 | TextView numOfCharsView = (TextView) findViewById(R.id.num_of_chars); |
| 372 | TextView inTypeView = (TextView) findViewById(R.id.input_type); |
| 373 | |
| 374 | int inTypeId = R.string.alphabet; |
| 375 | |
| 376 | // set the prompt. |
Takeshi Shinohara | c658900 | 2013-05-27 11:01:06 +0900 | [diff] [blame] | 377 | if (mStkInput.iconSelfExplanatory && mStkInput.icon != null) { |
| 378 | mPromptView.setVisibility(View.GONE); |
| 379 | } else { |
| 380 | mPromptView.setText(mStkInput.text); |
| 381 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 382 | |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 383 | // Set input type (alphabet/digit) info close to the InText form. |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 384 | if (mStkInput.digitOnly) { |
| 385 | mTextIn.setKeyListener(StkDigitsKeyListener.getInstance()); |
| 386 | inTypeId = R.string.digits; |
| 387 | } |
| 388 | inTypeView.setText(inTypeId); |
| 389 | |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 390 | TextView textView = (TextView) this.findViewById(R.id.title_text); |
| 391 | textView.setText(R.string.app_name); |
| 392 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 393 | if (mStkInput.icon != null) { |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 394 | ImageView imageView = (ImageView) findViewById(R.id.title_icon); |
| 395 | imageView.setImageBitmap(mStkInput.icon); |
| 396 | imageView.setVisibility(View.VISIBLE); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | // Handle specific global and text attributes. |
| 400 | switch (mState) { |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 401 | case STATE_TEXT: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 402 | int maxLen = mStkInput.maxLen; |
| 403 | int minLen = mStkInput.minLen; |
| 404 | mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter( |
| 405 | maxLen)}); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 406 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 407 | // Set number of chars info. |
| 408 | String lengthLimit = String.valueOf(minLen); |
| 409 | if (maxLen != minLen) { |
| 410 | lengthLimit = minLen + " - " + maxLen; |
| 411 | } |
| 412 | numOfCharsView.setText(lengthLimit); |
| 413 | |
| 414 | if (!mStkInput.echo) { |
Yujing Gu | 6b9716c | 2014-04-23 13:50:50 +0800 | [diff] [blame] | 415 | mTextIn.setTransformationMethod(PasswordTransformationMethod |
| 416 | .getInstance()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 417 | } |
Srikanth Chintala | a091b73 | 2016-02-04 14:46:43 +0530 | [diff] [blame^] | 418 | mTextIn.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 419 | // Set default text if present. |
| 420 | if (mStkInput.defaultText != null) { |
| 421 | mTextIn.setText(mStkInput.defaultText); |
| 422 | } else { |
| 423 | // make sure the text is cleared |
| 424 | mTextIn.setText("", BufferType.EDITABLE); |
| 425 | } |
| 426 | |
| 427 | break; |
| 428 | case STATE_YES_NO: |
| 429 | // Set display mode - normal / yes-no layout |
| 430 | mYesNoLayout.setVisibility(View.VISIBLE); |
| 431 | mNormalLayout.setVisibility(View.GONE); |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | private float getFontSizeFactor(FontSize size) { |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 437 | final float[] fontSizes = |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 438 | {NORMAL_FONT_FACTOR, LARGE_FONT_FACTOR, SMALL_FONT_FACTOR}; |
| 439 | |
| 440 | return fontSizes[size.ordinal()]; |
| 441 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 442 | |
| 443 | private void initFromIntent(Intent intent) { |
| 444 | // Get the calling intent type: text/key, and setup the |
| 445 | // display parameters. |
| 446 | CatLog.d(LOG_TAG, "initFromIntent - slot id: " + mSlotId); |
| 447 | if (intent != null) { |
| 448 | mStkInput = intent.getParcelableExtra("INPUT"); |
| 449 | mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1); |
| 450 | CatLog.d(LOG_TAG, "onCreate - slot id: " + mSlotId); |
| 451 | if (mStkInput == null) { |
| 452 | finish(); |
| 453 | } else { |
| 454 | mState = mStkInput.yesNo ? STATE_YES_NO : |
| 455 | STATE_TEXT; |
| 456 | configInputDisplay(); |
| 457 | } |
| 458 | } else { |
| 459 | finish(); |
| 460 | } |
| 461 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 462 | } |