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; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 23 | import android.content.res.Configuration; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 24 | import android.graphics.drawable.BitmapDrawable; |
| 25 | import android.os.Bundle; |
| 26 | import android.os.Handler; |
| 27 | import android.os.Message; |
| 28 | import android.text.Editable; |
| 29 | import android.text.InputFilter; |
duho.ro | ee36b6f | 2013-09-03 15:15:16 +0900 | [diff] [blame] | 30 | import android.text.InputType; |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 31 | import android.text.TextUtils; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 32 | import android.text.TextWatcher; |
| 33 | import android.text.method.PasswordTransformationMethod; |
| 34 | import android.view.KeyEvent; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 35 | import android.view.Menu; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 36 | import android.view.MenuItem; |
| 37 | import android.view.View; |
| 38 | import android.view.Window; |
| 39 | import android.widget.Button; |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 40 | import android.widget.ImageView; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 41 | import android.widget.PopupMenu; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 42 | import android.widget.TextView; |
| 43 | import android.widget.EditText; |
| 44 | import android.widget.TextView.BufferType; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 45 | import com.android.internal.telephony.cat.CatLog; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 46 | import com.android.internal.telephony.cat.FontSize; |
| 47 | import com.android.internal.telephony.cat.Input; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Display a request for a text input a long with a text edit form. |
| 51 | */ |
| 52 | public 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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 60 | private View mMoreOptions = null; |
| 61 | private PopupMenu mPopupMenu = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 62 | private View mYesNoLayout = null; |
| 63 | private View mNormalLayout = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 64 | |
| 65 | // Constants |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 66 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 72 | 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 Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 83 | // message id for time out |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 84 | private static final int MSG_ID_TIMEOUT = 1; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 85 | private StkAppService appService = StkAppService.getInstance(); |
| 86 | |
| 87 | private boolean mIsResponseSent = false; |
| 88 | private int mSlotId = -1; |
| 89 | Activity mInstance = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 90 | |
| 91 | Handler mTimeoutHandler = new Handler() { |
| 92 | @Override |
| 93 | public void handleMessage(Message msg) { |
| 94 | switch(msg.what) { |
| 95 | case MSG_ID_TIMEOUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 96 | CatLog.d(LOG_TAG, "Msg timeout."); |
| 97 | mAcceptUsersInput = false; |
| 98 | appService.getStkContext(mSlotId).setPendingActivityInstance(mInstance); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 99 | sendResponse(StkAppService.RES_ID_TIMEOUT); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 100 | break; |
| 101 | } |
| 102 | } |
| 103 | }; |
| 104 | |
| 105 | // Click listener to handle buttons press.. |
| 106 | public void onClick(View v) { |
| 107 | String input = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 108 | if (!mAcceptUsersInput) { |
| 109 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 110 | return; |
| 111 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 112 | |
| 113 | switch (v.getId()) { |
| 114 | case R.id.button_ok: |
| 115 | // Check that text entered is valid . |
| 116 | if (!verfiyTypedText()) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 117 | CatLog.d(LOG_TAG, "handleClick, invalid text"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 118 | return; |
| 119 | } |
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 = mTextIn.getText().toString(); |
| 122 | break; |
| 123 | // Yes/No layout buttons. |
| 124 | case R.id.button_yes: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 125 | mAcceptUsersInput = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 126 | input = YES_STR_RESPONSE; |
| 127 | break; |
| 128 | case R.id.button_no: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 129 | mAcceptUsersInput = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 130 | input = NO_STR_RESPONSE; |
| 131 | break; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 132 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 154 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 155 | CatLog.d(LOG_TAG, "handleClick, ready to response"); |
Preeti Ahuja | 03be667 | 2012-08-30 19:21:25 +0530 | [diff] [blame] | 156 | cancelTimeOut(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 157 | appService.getStkContext(mSlotId).setPendingActivityInstance(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 158 | sendResponse(StkAppService.RES_ID_INPUT, input, false); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public void onCreate(Bundle icicle) { |
| 163 | super.onCreate(icicle); |
| 164 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 165 | CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]"); |
| 166 | |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 167 | // 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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 175 | 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 Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 182 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 183 | // Set the layout for this activity. |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 184 | setContentView(R.layout.stk_input); |
| 185 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 186 | if (actionBar != null) { |
| 187 | mMoreOptions = findViewById(R.id.more); |
| 188 | mMoreOptions.setVisibility(View.VISIBLE); |
| 189 | mMoreOptions.setOnClickListener(this); |
| 190 | } |
| 191 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 192 | // Initialize members |
| 193 | mTextIn = (EditText) this.findViewById(R.id.in_text); |
| 194 | mPromptView = (TextView) this.findViewById(R.id.prompt); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 195 | mInstance = this; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 196 | // Set buttons listeners. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 197 | Button okButton = (Button) findViewById(R.id.button_ok); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 198 | 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 Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 207 | initFromIntent(getIntent()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 208 | mContext = getBaseContext(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 209 | mAcceptUsersInput = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 210 | } |
| 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 Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 222 | CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent + |
| 223 | "], slot id: " + mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 224 | startTimeOut(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 225 | appService.getStkContext(mSlotId).setPendingActivityInstance(null); |
hoonsung.park | cba2996 | 2015-07-06 23:17:38 +0900 | [diff] [blame] | 226 | if (mIsResponseSent) { |
| 227 | cancelTimeOut(); |
| 228 | finish(); |
| 229 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public void onPause() { |
| 234 | super.onPause(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 235 | CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]"); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 236 | if (mPopupMenu != null) { |
| 237 | mPopupMenu.dismiss(); |
| 238 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 239 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 240 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 241 | @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 Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 258 | if (appService == null) { |
| 259 | return; |
| 260 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 261 | //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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 268 | cancelTimeOut(); |
| 269 | } |
| 270 | |
| 271 | @Override |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 272 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 280 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 281 | if (!mAcceptUsersInput) { |
| 282 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 283 | return true; |
| 284 | } |
| 285 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 286 | switch (keyCode) { |
| 287 | case KeyEvent.KEYCODE_BACK: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 288 | CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK"); |
| 289 | mAcceptUsersInput = false; |
Preeti Ahuja | 03be667 | 2012-08-30 19:21:25 +0530 | [diff] [blame] | 290 | cancelTimeOut(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 291 | appService.getStkContext(mSlotId).setPendingActivityInstance(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 292 | sendResponse(StkAppService.RES_ID_BACKWARD, null, false); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 293 | return true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 294 | } |
| 295 | return super.onKeyDown(keyCode, event); |
| 296 | } |
| 297 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 298 | void sendResponse(int resId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 299 | sendResponse(resId, null, false); |
| 300 | } |
| 301 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 302 | 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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 313 | if (mMoreOptions != null) { |
| 314 | mMoreOptions.setVisibility(View.INVISIBLE); |
| 315 | } |
| 316 | |
Cuihtlauac ALVARADO | bde7f03 | 2015-05-29 16:25:12 +0200 | [diff] [blame] | 317 | CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help[" |
| 318 | + help + "]"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 319 | mIsResponseSent = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 320 | Bundle args = new Bundle(); |
| 321 | args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 322 | args.putInt(StkAppService.SLOT_ID, mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 323 | 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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 335 | createOptionsMenuInternal(menu); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 336 | return true; |
| 337 | } |
| 338 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 339 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 344 | @Override |
| 345 | public boolean onPrepareOptionsMenu(android.view.Menu menu) { |
| 346 | super.onPrepareOptionsMenu(menu); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 347 | prepareOptionsMenuInternal(menu); |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | private void prepareOptionsMenuInternal(Menu menu) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 352 | menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true); |
| 353 | menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public boolean onOptionsItemSelected(MenuItem item) { |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 358 | if (optionsItemSelectedInternal(item)) { |
| 359 | return true; |
| 360 | } |
| 361 | return super.onOptionsItemSelected(item); |
| 362 | } |
| 363 | |
| 364 | private boolean optionsItemSelectedInternal(MenuItem item) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 365 | if (!mAcceptUsersInput) { |
| 366 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 367 | return true; |
| 368 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 369 | switch (item.getItemId()) { |
| 370 | case StkApp.MENU_ID_END_SESSION: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 371 | mAcceptUsersInput = false; |
| 372 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 373 | sendResponse(StkAppService.RES_ID_END_SESSION); |
| 374 | finish(); |
| 375 | return true; |
| 376 | case StkApp.MENU_ID_HELP: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 377 | mAcceptUsersInput = false; |
| 378 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 379 | sendResponse(StkAppService.RES_ID_INPUT, "", true); |
| 380 | finish(); |
| 381 | return true; |
| 382 | } |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 383 | return false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 386 | @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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 396 | if ((mAcceptUsersInput == false) && (mMoreOptions != null)) { |
| 397 | mMoreOptions.setVisibility(View.INVISIBLE); |
| 398 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 399 | } |
| 400 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 401 | 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 Adappa | c7c3a46 | 2013-02-14 13:36:57 -0800 | [diff] [blame] | 427 | int duration = StkApp.calculateDurationInMilis(mStkInput.duration); |
| 428 | |
| 429 | if (duration <= 0) { |
| 430 | duration = StkApp.UI_TIMEOUT; |
| 431 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 432 | cancelTimeOut(); |
| 433 | mTimeoutHandler.sendMessageDelayed(mTimeoutHandler |
Abhishek Adappa | c7c3a46 | 2013-02-14 13:36:57 -0800 | [diff] [blame] | 434 | .obtainMessage(MSG_ID_TIMEOUT), duration); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 435 | } |
| 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 Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 444 | if ((mStkInput.icon == null || !mStkInput.iconSelfExplanatory) |
| 445 | && !TextUtils.isEmpty(mStkInput.text)) { |
Takeshi Shinohara | c658900 | 2013-05-27 11:01:06 +0900 | [diff] [blame] | 446 | mPromptView.setText(mStkInput.text); |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 447 | mPromptView.setVisibility(View.VISIBLE); |
Takeshi Shinohara | c658900 | 2013-05-27 11:01:06 +0900 | [diff] [blame] | 448 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 449 | |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 450 | // 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] | 451 | if (mStkInput.digitOnly) { |
| 452 | mTextIn.setKeyListener(StkDigitsKeyListener.getInstance()); |
| 453 | inTypeId = R.string.digits; |
| 454 | } |
| 455 | inTypeView.setText(inTypeId); |
| 456 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame^] | 457 | setTitle(R.string.app_name); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 458 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 459 | if (mStkInput.icon != null) { |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 460 | ImageView imageView = (ImageView) findViewById(R.id.icon); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 461 | imageView.setImageBitmap(mStkInput.icon); |
| 462 | imageView.setVisibility(View.VISIBLE); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | // Handle specific global and text attributes. |
| 466 | switch (mState) { |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 467 | case STATE_TEXT: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 468 | int maxLen = mStkInput.maxLen; |
| 469 | int minLen = mStkInput.minLen; |
| 470 | mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter( |
| 471 | maxLen)}); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 472 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 473 | // 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 Gu | 6b9716c | 2014-04-23 13:50:50 +0800 | [diff] [blame] | 481 | mTextIn.setTransformationMethod(PasswordTransformationMethod |
| 482 | .getInstance()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 483 | } |
| 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 Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 502 | final float[] fontSizes = |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 503 | {NORMAL_FONT_FACTOR, LARGE_FONT_FACTOR, SMALL_FONT_FACTOR}; |
| 504 | |
| 505 | return fontSizes[size.ordinal()]; |
| 506 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 507 | |
| 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 527 | } |