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; |
Srikanth Chintala | a091b73 | 2016-02-04 14:46:43 +0530 | [diff] [blame] | 34 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 35 | import android.view.KeyEvent; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 36 | import android.view.Menu; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 37 | import android.view.MenuItem; |
| 38 | import android.view.View; |
| 39 | import android.view.Window; |
| 40 | import android.widget.Button; |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 41 | import android.widget.ImageView; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 42 | import android.widget.PopupMenu; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 43 | import android.widget.TextView; |
| 44 | import android.widget.EditText; |
| 45 | import android.widget.TextView.BufferType; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 46 | import com.android.internal.telephony.cat.CatLog; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 47 | import com.android.internal.telephony.cat.FontSize; |
| 48 | import com.android.internal.telephony.cat.Input; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Display a request for a text input a long with a text edit form. |
| 52 | */ |
| 53 | public 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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 61 | private View mMoreOptions = null; |
| 62 | private PopupMenu mPopupMenu = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 63 | private View mYesNoLayout = null; |
| 64 | private View mNormalLayout = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 65 | |
| 66 | // Constants |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 67 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 73 | 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 Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 84 | // message id for time out |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 85 | private static final int MSG_ID_TIMEOUT = 1; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 86 | private StkAppService appService = StkAppService.getInstance(); |
| 87 | |
| 88 | private boolean mIsResponseSent = false; |
| 89 | private int mSlotId = -1; |
| 90 | Activity mInstance = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 91 | |
| 92 | Handler mTimeoutHandler = new Handler() { |
| 93 | @Override |
| 94 | public void handleMessage(Message msg) { |
| 95 | switch(msg.what) { |
| 96 | case MSG_ID_TIMEOUT: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 97 | CatLog.d(LOG_TAG, "Msg timeout."); |
| 98 | mAcceptUsersInput = false; |
| 99 | appService.getStkContext(mSlotId).setPendingActivityInstance(mInstance); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 100 | sendResponse(StkAppService.RES_ID_TIMEOUT); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 101 | break; |
| 102 | } |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | // Click listener to handle buttons press.. |
| 107 | public void onClick(View v) { |
| 108 | String input = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 109 | if (!mAcceptUsersInput) { |
| 110 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 111 | return; |
| 112 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 113 | |
| 114 | switch (v.getId()) { |
| 115 | case R.id.button_ok: |
| 116 | // Check that text entered is valid . |
| 117 | if (!verfiyTypedText()) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 118 | CatLog.d(LOG_TAG, "handleClick, invalid text"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 119 | return; |
| 120 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 121 | mAcceptUsersInput = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 122 | input = mTextIn.getText().toString(); |
| 123 | break; |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame^] | 124 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 130 | // Yes/No layout buttons. |
| 131 | case R.id.button_yes: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 132 | mAcceptUsersInput = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 133 | input = YES_STR_RESPONSE; |
| 134 | break; |
| 135 | case R.id.button_no: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 136 | mAcceptUsersInput = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 137 | input = NO_STR_RESPONSE; |
| 138 | break; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 139 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 161 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 162 | CatLog.d(LOG_TAG, "handleClick, ready to response"); |
Preeti Ahuja | 03be667 | 2012-08-30 19:21:25 +0530 | [diff] [blame] | 163 | cancelTimeOut(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 164 | appService.getStkContext(mSlotId).setPendingActivityInstance(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 165 | sendResponse(StkAppService.RES_ID_INPUT, input, false); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void onCreate(Bundle icicle) { |
| 170 | super.onCreate(icicle); |
| 171 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 172 | CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]"); |
| 173 | |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 174 | // 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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 182 | 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 Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 189 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 190 | // Set the layout for this activity. |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 191 | setContentView(R.layout.stk_input); |
| 192 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 193 | if (actionBar != null) { |
| 194 | mMoreOptions = findViewById(R.id.more); |
| 195 | mMoreOptions.setVisibility(View.VISIBLE); |
| 196 | mMoreOptions.setOnClickListener(this); |
| 197 | } |
| 198 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 199 | // Initialize members |
| 200 | mTextIn = (EditText) this.findViewById(R.id.in_text); |
| 201 | mPromptView = (TextView) this.findViewById(R.id.prompt); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 202 | mInstance = this; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 203 | // Set buttons listeners. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 204 | Button okButton = (Button) findViewById(R.id.button_ok); |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame^] | 205 | Button cancelButton = (Button) findViewById(R.id.button_cancel); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 206 | Button yesButton = (Button) findViewById(R.id.button_yes); |
| 207 | Button noButton = (Button) findViewById(R.id.button_no); |
| 208 | |
| 209 | okButton.setOnClickListener(this); |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame^] | 210 | cancelButton.setOnClickListener(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 211 | yesButton.setOnClickListener(this); |
| 212 | noButton.setOnClickListener(this); |
| 213 | |
| 214 | mYesNoLayout = findViewById(R.id.yes_no_layout); |
| 215 | mNormalLayout = findViewById(R.id.normal_layout); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 216 | initFromIntent(getIntent()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 217 | mContext = getBaseContext(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 218 | mAcceptUsersInput = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 219 | } |
| 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 Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 231 | CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent + |
| 232 | "], slot id: " + mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 233 | startTimeOut(); |
| 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public void onPause() { |
| 238 | super.onPause(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 239 | CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]"); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 240 | if (mPopupMenu != null) { |
| 241 | mPopupMenu.dismiss(); |
| 242 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 243 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 244 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 245 | @Override |
| 246 | public void onStop() { |
| 247 | super.onStop(); |
| 248 | CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]"); |
Yoshiaki Naka | cec55b8 | 2017-10-20 15:53:43 +0900 | [diff] [blame] | 249 | // 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 Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 252 | 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 Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 264 | if (appService == null) { |
| 265 | return; |
| 266 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 267 | //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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 274 | cancelTimeOut(); |
| 275 | } |
| 276 | |
| 277 | @Override |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 278 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 286 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 287 | if (!mAcceptUsersInput) { |
| 288 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 289 | return true; |
| 290 | } |
| 291 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 292 | switch (keyCode) { |
| 293 | case KeyEvent.KEYCODE_BACK: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 294 | CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK"); |
| 295 | mAcceptUsersInput = false; |
Preeti Ahuja | 03be667 | 2012-08-30 19:21:25 +0530 | [diff] [blame] | 296 | cancelTimeOut(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 297 | appService.getStkContext(mSlotId).setPendingActivityInstance(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 298 | sendResponse(StkAppService.RES_ID_BACKWARD, null, false); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 299 | return true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 300 | } |
| 301 | return super.onKeyDown(keyCode, event); |
| 302 | } |
| 303 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 304 | void sendResponse(int resId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 305 | sendResponse(resId, null, false); |
| 306 | } |
| 307 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 308 | 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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 319 | if (mMoreOptions != null) { |
| 320 | mMoreOptions.setVisibility(View.INVISIBLE); |
| 321 | } |
| 322 | |
Cuihtlauac ALVARADO | bde7f03 | 2015-05-29 16:25:12 +0200 | [diff] [blame] | 323 | CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help[" |
| 324 | + help + "]"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 325 | mIsResponseSent = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 326 | Bundle args = new Bundle(); |
| 327 | args.putInt(StkAppService.OPCODE, StkAppService.OP_RESPONSE); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 328 | args.putInt(StkAppService.SLOT_ID, mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 329 | 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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 341 | createOptionsMenuInternal(menu); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 342 | return true; |
| 343 | } |
| 344 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 345 | 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 350 | @Override |
| 351 | public boolean onPrepareOptionsMenu(android.view.Menu menu) { |
| 352 | super.onPrepareOptionsMenu(menu); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 353 | prepareOptionsMenuInternal(menu); |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | private void prepareOptionsMenuInternal(Menu menu) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 358 | menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true); |
| 359 | menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public boolean onOptionsItemSelected(MenuItem item) { |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 364 | if (optionsItemSelectedInternal(item)) { |
| 365 | return true; |
| 366 | } |
| 367 | return super.onOptionsItemSelected(item); |
| 368 | } |
| 369 | |
| 370 | private boolean optionsItemSelectedInternal(MenuItem item) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 371 | if (!mAcceptUsersInput) { |
| 372 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 373 | return true; |
| 374 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 375 | switch (item.getItemId()) { |
| 376 | case StkApp.MENU_ID_END_SESSION: |
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_END_SESSION); |
| 380 | finish(); |
| 381 | return true; |
| 382 | case StkApp.MENU_ID_HELP: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 383 | mAcceptUsersInput = false; |
| 384 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 385 | sendResponse(StkAppService.RES_ID_INPUT, "", true); |
| 386 | finish(); |
| 387 | return true; |
| 388 | } |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 389 | return false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 392 | @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 Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 402 | if ((mAcceptUsersInput == false) && (mMoreOptions != null)) { |
| 403 | mMoreOptions.setVisibility(View.INVISIBLE); |
| 404 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 405 | } |
| 406 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 407 | 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 Adappa | c7c3a46 | 2013-02-14 13:36:57 -0800 | [diff] [blame] | 433 | int duration = StkApp.calculateDurationInMilis(mStkInput.duration); |
| 434 | |
| 435 | if (duration <= 0) { |
| 436 | duration = StkApp.UI_TIMEOUT; |
| 437 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 438 | cancelTimeOut(); |
| 439 | mTimeoutHandler.sendMessageDelayed(mTimeoutHandler |
Abhishek Adappa | c7c3a46 | 2013-02-14 13:36:57 -0800 | [diff] [blame] | 440 | .obtainMessage(MSG_ID_TIMEOUT), duration); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 441 | } |
| 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 Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 450 | if ((mStkInput.icon == null || !mStkInput.iconSelfExplanatory) |
| 451 | && !TextUtils.isEmpty(mStkInput.text)) { |
Takeshi Shinohara | c658900 | 2013-05-27 11:01:06 +0900 | [diff] [blame] | 452 | mPromptView.setText(mStkInput.text); |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 453 | mPromptView.setVisibility(View.VISIBLE); |
Takeshi Shinohara | c658900 | 2013-05-27 11:01:06 +0900 | [diff] [blame] | 454 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 455 | |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 456 | // 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] | 457 | if (mStkInput.digitOnly) { |
| 458 | mTextIn.setKeyListener(StkDigitsKeyListener.getInstance()); |
| 459 | inTypeId = R.string.digits; |
| 460 | } |
| 461 | inTypeView.setText(inTypeId); |
| 462 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 463 | setTitle(R.string.app_name); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 464 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 465 | if (mStkInput.icon != null) { |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 466 | ImageView imageView = (ImageView) findViewById(R.id.icon); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 467 | imageView.setImageBitmap(mStkInput.icon); |
| 468 | imageView.setVisibility(View.VISIBLE); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | // Handle specific global and text attributes. |
| 472 | switch (mState) { |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 473 | case STATE_TEXT: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 474 | int maxLen = mStkInput.maxLen; |
| 475 | int minLen = mStkInput.minLen; |
| 476 | mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter( |
| 477 | maxLen)}); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 478 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 479 | // 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 Gu | 6b9716c | 2014-04-23 13:50:50 +0800 | [diff] [blame] | 487 | mTextIn.setTransformationMethod(PasswordTransformationMethod |
| 488 | .getInstance()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 489 | } |
Srikanth Chintala | a091b73 | 2016-02-04 14:46:43 +0530 | [diff] [blame] | 490 | mTextIn.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 491 | // 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 Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 509 | final float[] fontSizes = |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 510 | {NORMAL_FONT_FACTOR, LARGE_FONT_FACTOR, SMALL_FONT_FACTOR}; |
| 511 | |
| 512 | return fontSizes[size.ordinal()]; |
| 513 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 514 | |
| 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 534 | } |