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 | * |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 7 | * |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [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; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 21 | import android.app.AlarmManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 24 | import android.content.res.Configuration; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 26 | import android.os.SystemClock; |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 27 | import android.telephony.CarrierConfigManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 28 | import android.text.Editable; |
| 29 | import android.text.InputFilter; |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 30 | import android.text.TextUtils; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 31 | import android.text.TextWatcher; |
| 32 | import android.text.method.PasswordTransformationMethod; |
| 33 | import android.view.KeyEvent; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 34 | import android.view.Menu; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 35 | import android.view.MenuItem; |
| 36 | import android.view.View; |
Kazuhiro Uto | 1287091 | 2018-07-18 17:43:56 +0900 | [diff] [blame] | 37 | import android.view.WindowManager; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 38 | import android.view.inputmethod.EditorInfo; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 39 | import android.widget.Button; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 40 | import android.widget.EditText; |
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; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 44 | import android.widget.TextView.BufferType; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 45 | |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 46 | import androidx.appcompat.app.AppCompatActivity; |
| 47 | import androidx.appcompat.widget.Toolbar; |
| 48 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 49 | import com.android.internal.telephony.cat.CatLog; |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 50 | import com.android.internal.telephony.cat.Input; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 51 | |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 52 | import com.google.android.material.textfield.TextInputLayout; |
| 53 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 54 | /** |
| 55 | * Display a request for a text input a long with a text edit form. |
| 56 | */ |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 57 | public class StkInputActivity extends AppCompatActivity implements View.OnClickListener, |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 58 | TextWatcher { |
| 59 | |
| 60 | // Members |
| 61 | private int mState; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 62 | private EditText mTextIn = null; |
| 63 | private TextView mPromptView = null; |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 64 | private View mMoreOptions = null; |
| 65 | private PopupMenu mPopupMenu = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 66 | private View mYesNoLayout = null; |
| 67 | private View mNormalLayout = null; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 68 | |
| 69 | // Constants |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 70 | private static final String LOG_TAG = |
| 71 | new Object(){}.getClass().getEnclosingClass().getSimpleName(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 72 | |
| 73 | private Input mStkInput = null; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 74 | // Constants |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 75 | private static final int STATE_TEXT = 1; |
| 76 | private static final int STATE_YES_NO = 2; |
| 77 | |
| 78 | static final String YES_STR_RESPONSE = "YES"; |
| 79 | static final String NO_STR_RESPONSE = "NO"; |
| 80 | |
| 81 | // Font size factor values. |
| 82 | static final float NORMAL_FONT_FACTOR = 1; |
| 83 | static final float LARGE_FONT_FACTOR = 2; |
| 84 | static final float SMALL_FONT_FACTOR = (1 / 2); |
| 85 | |
Takanori Nakano | 1a672e6 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 86 | // Keys for saving the state of the activity in the bundle |
Takanori Nakano | 1a672e6 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 87 | private static final String RESPONSE_SENT_KEY = "response_sent"; |
| 88 | private static final String INPUT_STRING_KEY = "input_string"; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 89 | private static final String ALARM_TIME_KEY = "alarm_time"; |
Takanori Nakano | 1a672e6 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 90 | |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 91 | private static final String INPUT_ALARM_TAG = LOG_TAG; |
| 92 | private static final long NO_INPUT_ALARM = -1; |
| 93 | private long mAlarmTime = NO_INPUT_ALARM; |
| 94 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 95 | private StkAppService appService = StkAppService.getInstance(); |
| 96 | |
| 97 | private boolean mIsResponseSent = false; |
| 98 | private int mSlotId = -1; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 99 | |
| 100 | // Click listener to handle buttons press.. |
| 101 | public void onClick(View v) { |
| 102 | String input = null; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 103 | if (mIsResponseSent) { |
| 104 | CatLog.d(LOG_TAG, "Already responded"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 105 | return; |
| 106 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 107 | |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 108 | switch (v.getId()) { |
| 109 | case R.id.button_ok: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 110 | input = mTextIn.getText().toString(); |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 111 | break; |
| 112 | case R.id.button_cancel: |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame] | 113 | sendResponse(StkAppService.RES_ID_END_SESSION); |
Yoshiaki Naka | 03a79d9 | 2018-08-09 18:41:31 +0900 | [diff] [blame] | 114 | finish(); |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame] | 115 | return; |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 116 | // Yes/No layout buttons. |
| 117 | case R.id.button_yes: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 118 | input = YES_STR_RESPONSE; |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 119 | break; |
| 120 | case R.id.button_no: |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 121 | input = NO_STR_RESPONSE; |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 122 | break; |
| 123 | case R.id.more: |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 124 | if (mPopupMenu == null) { |
| 125 | mPopupMenu = new PopupMenu(this, v); |
| 126 | Menu menu = mPopupMenu.getMenu(); |
| 127 | createOptionsMenuInternal(menu); |
| 128 | prepareOptionsMenuInternal(menu); |
| 129 | mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { |
| 130 | public boolean onMenuItemClick(MenuItem item) { |
| 131 | optionsItemSelectedInternal(item); |
| 132 | return true; |
| 133 | } |
| 134 | }); |
| 135 | mPopupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() { |
| 136 | public void onDismiss(PopupMenu menu) { |
| 137 | mPopupMenu = null; |
| 138 | } |
| 139 | }); |
| 140 | mPopupMenu.show(); |
| 141 | } |
| 142 | return; |
Amit Mahajan | d51bbb5 | 2020-02-07 20:03:11 +0000 | [diff] [blame] | 143 | default: |
| 144 | break; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 145 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 146 | CatLog.d(LOG_TAG, "handleClick, ready to response"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 147 | sendResponse(StkAppService.RES_ID_INPUT, input, false); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | @Override |
Takanori Nakano | 1a672e6 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 151 | public void onCreate(Bundle savedInstanceState) { |
| 152 | super.onCreate(savedInstanceState); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 153 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 154 | CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]"); |
| 155 | |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 156 | // appService can be null if this activity is automatically recreated by the system |
| 157 | // with the saved instance state right after the phone process is killed. |
| 158 | if (appService == null) { |
| 159 | CatLog.d(LOG_TAG, "onCreate - appService is null"); |
| 160 | finish(); |
| 161 | return; |
| 162 | } |
| 163 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 164 | // Set the layout for this activity. |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 165 | setContentView(R.layout.stk_input); |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 166 | setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 167 | |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 168 | if (getResources().getBoolean(R.bool.show_menu_title_only_on_menu)) { |
| 169 | getSupportActionBar().hide(); |
| 170 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 171 | mMoreOptions = findViewById(R.id.more); |
| 172 | mMoreOptions.setVisibility(View.VISIBLE); |
| 173 | mMoreOptions.setOnClickListener(this); |
| 174 | } |
| 175 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 176 | // Initialize members |
| 177 | mTextIn = (EditText) this.findViewById(R.id.in_text); |
| 178 | mPromptView = (TextView) this.findViewById(R.id.prompt); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 179 | // Set buttons listeners. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 180 | Button okButton = (Button) findViewById(R.id.button_ok); |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame] | 181 | Button cancelButton = (Button) findViewById(R.id.button_cancel); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 182 | Button yesButton = (Button) findViewById(R.id.button_yes); |
| 183 | Button noButton = (Button) findViewById(R.id.button_no); |
| 184 | |
| 185 | okButton.setOnClickListener(this); |
Takanori Nakano | 260df9a | 2017-12-05 22:26:30 +0900 | [diff] [blame] | 186 | cancelButton.setOnClickListener(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 187 | yesButton.setOnClickListener(this); |
| 188 | noButton.setOnClickListener(this); |
| 189 | |
| 190 | mYesNoLayout = findViewById(R.id.yes_no_layout); |
| 191 | mNormalLayout = findViewById(R.id.normal_layout); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 192 | initFromIntent(getIntent()); |
Anna Suzuki | 35309b0 | 2019-02-15 16:24:59 +0900 | [diff] [blame] | 193 | appService.getStkContext(mSlotId).setPendingActivityInstance(this); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | @Override |
| 197 | protected void onPostCreate(Bundle savedInstanceState) { |
| 198 | super.onPostCreate(savedInstanceState); |
| 199 | |
| 200 | mTextIn.addTextChangedListener(this); |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public void onResume() { |
| 205 | super.onResume(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 206 | CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent + |
| 207 | "], slot id: " + mSlotId); |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 208 | if (mAlarmTime == NO_INPUT_ALARM) { |
| 209 | startTimeOut(); |
| 210 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public void onPause() { |
| 215 | super.onPause(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 216 | CatLog.d(LOG_TAG, "onPause - mIsResponseSent[" + mIsResponseSent + "]"); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 217 | if (mPopupMenu != null) { |
| 218 | mPopupMenu.dismiss(); |
| 219 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 220 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 221 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 222 | @Override |
| 223 | public void onStop() { |
| 224 | super.onStop(); |
| 225 | CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public void onDestroy() { |
| 230 | super.onDestroy(); |
| 231 | CatLog.d(LOG_TAG, "onDestroy - before Send End Session mIsResponseSent[" + |
| 232 | mIsResponseSent + " , " + mSlotId + "]"); |
Ryuto Sawada | ba9b86b | 2016-10-03 14:03:16 +0900 | [diff] [blame] | 233 | if (appService == null) { |
| 234 | return; |
| 235 | } |
Takanori Nakano | 1a672e6 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 236 | // Avoid sending the terminal response while the activty is being restarted |
| 237 | // due to some kind of configuration change. |
| 238 | if (!isChangingConfigurations()) { |
| 239 | // If the input activity is finished by stkappservice |
| 240 | // when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here, |
| 241 | // since the input cmd is waiting user to process. |
| 242 | if (!mIsResponseSent && !appService.isInputPending(mSlotId)) { |
| 243 | CatLog.d(LOG_TAG, "handleDestroy - Send End Session"); |
| 244 | sendResponse(StkAppService.RES_ID_END_SESSION); |
| 245 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 246 | } |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 247 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | @Override |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 251 | public void onConfigurationChanged(Configuration newConfig) { |
| 252 | super.onConfigurationChanged(newConfig); |
| 253 | if (mPopupMenu != null) { |
| 254 | mPopupMenu.dismiss(); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | @Override |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 259 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 260 | if (mIsResponseSent) { |
| 261 | CatLog.d(LOG_TAG, "Already responded"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 262 | return true; |
| 263 | } |
| 264 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 265 | switch (keyCode) { |
| 266 | case KeyEvent.KEYCODE_BACK: |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 267 | CatLog.d(LOG_TAG, "onKeyDown - KEYCODE_BACK"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 268 | sendResponse(StkAppService.RES_ID_BACKWARD, null, false); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 269 | return true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 270 | } |
| 271 | return super.onKeyDown(keyCode, event); |
| 272 | } |
| 273 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 274 | void sendResponse(int resId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 275 | sendResponse(resId, null, false); |
| 276 | } |
| 277 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 278 | void sendResponse(int resId, String input, boolean help) { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 279 | cancelTimeOut(); |
| 280 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 281 | if (mSlotId == -1) { |
| 282 | CatLog.d(LOG_TAG, "slot id is invalid"); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | if (StkAppService.getInstance() == null) { |
| 287 | CatLog.d(LOG_TAG, "StkAppService is null, Ignore response: id is " + resId); |
| 288 | return; |
| 289 | } |
| 290 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 291 | if (mMoreOptions != null) { |
| 292 | mMoreOptions.setVisibility(View.INVISIBLE); |
| 293 | } |
| 294 | |
Cuihtlauac ALVARADO | bde7f03 | 2015-05-29 16:25:12 +0200 | [diff] [blame] | 295 | CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] input[*****] help[" |
| 296 | + help + "]"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 297 | mIsResponseSent = true; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 298 | Bundle args = new Bundle(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 299 | args.putInt(StkAppService.RES_ID, resId); |
| 300 | if (input != null) { |
| 301 | args.putString(StkAppService.INPUT, input); |
| 302 | } |
| 303 | args.putBoolean(StkAppService.HELP, help); |
Takanori Nakano | 43dacc0 | 2018-07-26 11:27:39 +0900 | [diff] [blame] | 304 | appService.sendResponse(args, mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public boolean onCreateOptionsMenu(android.view.Menu menu) { |
| 309 | super.onCreateOptionsMenu(menu); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 310 | createOptionsMenuInternal(menu); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 311 | return true; |
| 312 | } |
| 313 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 314 | private void createOptionsMenuInternal(Menu menu) { |
| 315 | menu.add(Menu.NONE, StkApp.MENU_ID_END_SESSION, 1, R.string.menu_end_session); |
| 316 | menu.add(0, StkApp.MENU_ID_HELP, 2, R.string.help); |
| 317 | } |
| 318 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 319 | @Override |
| 320 | public boolean onPrepareOptionsMenu(android.view.Menu menu) { |
| 321 | super.onPrepareOptionsMenu(menu); |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 322 | prepareOptionsMenuInternal(menu); |
| 323 | return true; |
| 324 | } |
| 325 | |
| 326 | private void prepareOptionsMenuInternal(Menu menu) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 327 | menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(true); |
| 328 | menu.findItem(StkApp.MENU_ID_HELP).setVisible(mStkInput.helpAvailable); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | @Override |
| 332 | public boolean onOptionsItemSelected(MenuItem item) { |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 333 | if (optionsItemSelectedInternal(item)) { |
| 334 | return true; |
| 335 | } |
| 336 | return super.onOptionsItemSelected(item); |
| 337 | } |
| 338 | |
| 339 | private boolean optionsItemSelectedInternal(MenuItem item) { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 340 | if (mIsResponseSent) { |
| 341 | CatLog.d(LOG_TAG, "Already responded"); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 342 | return true; |
| 343 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 344 | switch (item.getItemId()) { |
| 345 | case StkApp.MENU_ID_END_SESSION: |
| 346 | sendResponse(StkAppService.RES_ID_END_SESSION); |
| 347 | finish(); |
| 348 | return true; |
| 349 | case StkApp.MENU_ID_HELP: |
| 350 | sendResponse(StkAppService.RES_ID_INPUT, "", true); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 351 | return true; |
| 352 | } |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 353 | return false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 354 | } |
| 355 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 356 | @Override |
| 357 | protected void onSaveInstanceState(Bundle outState) { |
| 358 | CatLog.d(LOG_TAG, "onSaveInstanceState: " + mSlotId); |
Takanori Nakano | 1a672e6 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 359 | outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent); |
| 360 | outState.putString(INPUT_STRING_KEY, mTextIn.getText().toString()); |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 361 | outState.putLong(ALARM_TIME_KEY, mAlarmTime); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | @Override |
| 365 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 366 | CatLog.d(LOG_TAG, "onRestoreInstanceState: " + mSlotId); |
Takanori Nakano | 1a672e6 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 367 | |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 368 | mIsResponseSent = savedInstanceState.getBoolean(RESPONSE_SENT_KEY); |
| 369 | if (mIsResponseSent && (mMoreOptions != null)) { |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 370 | mMoreOptions.setVisibility(View.INVISIBLE); |
| 371 | } |
Takanori Nakano | 1a672e6 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 372 | |
Takanori Nakano | 1a672e6 | 2017-10-19 19:49:38 +0900 | [diff] [blame] | 373 | String savedString = savedInstanceState.getString(INPUT_STRING_KEY); |
Miyu Iijima | 1e28c65 | 2018-11-14 10:08:05 +0900 | [diff] [blame] | 374 | mTextIn.setText(savedString); |
| 375 | updateButton(); |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 376 | |
| 377 | mAlarmTime = savedInstanceState.getLong(ALARM_TIME_KEY, NO_INPUT_ALARM); |
| 378 | if (mAlarmTime != NO_INPUT_ALARM) { |
| 379 | startTimeOut(); |
| 380 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 381 | } |
| 382 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 383 | public void beforeTextChanged(CharSequence s, int start, int count, |
| 384 | int after) { |
| 385 | } |
| 386 | |
| 387 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 388 | // Reset timeout. |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 389 | cancelTimeOut(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 390 | startTimeOut(); |
Miyu Iijima | c9a1720 | 2018-10-17 19:17:14 +0900 | [diff] [blame] | 391 | updateButton(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | public void afterTextChanged(Editable s) { |
| 395 | } |
| 396 | |
Miyu Iijima | c9a1720 | 2018-10-17 19:17:14 +0900 | [diff] [blame] | 397 | private void updateButton() { |
| 398 | // Disable the button if the length of the input text does not meet the expectation. |
| 399 | Button okButton = (Button) findViewById(R.id.button_ok); |
| 400 | okButton.setEnabled((mTextIn.getText().length() < mStkInput.minLen) ? false : true); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | private void cancelTimeOut() { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 404 | if (mAlarmTime != NO_INPUT_ALARM) { |
| 405 | CatLog.d(LOG_TAG, "cancelTimeOut - slot id: " + mSlotId); |
| 406 | AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); |
| 407 | am.cancel(mAlarmListener); |
| 408 | mAlarmTime = NO_INPUT_ALARM; |
| 409 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | private void startTimeOut() { |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 413 | // No need to set alarm if device sent TERMINAL RESPONSE already. |
| 414 | if (mIsResponseSent) { |
| 415 | return; |
Abhishek Adappa | c7c3a46 | 2013-02-14 13:36:57 -0800 | [diff] [blame] | 416 | } |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 417 | |
| 418 | if (mAlarmTime == NO_INPUT_ALARM) { |
| 419 | int duration = StkApp.calculateDurationInMilis(mStkInput.duration); |
| 420 | if (duration <= 0) { |
| 421 | duration = StkApp.UI_TIMEOUT; |
| 422 | } |
| 423 | mAlarmTime = SystemClock.elapsedRealtime() + duration; |
| 424 | } |
| 425 | |
| 426 | CatLog.d(LOG_TAG, "startTimeOut: " + mAlarmTime + "ms, slot id: " + mSlotId); |
| 427 | AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); |
| 428 | am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, mAlarmTime, INPUT_ALARM_TAG, |
| 429 | mAlarmListener, null); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | private void configInputDisplay() { |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 433 | TextInputLayout textInput = (TextInputLayout) findViewById(R.id.text_input_layout); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 434 | |
| 435 | int inTypeId = R.string.alphabet; |
| 436 | |
| 437 | // set the prompt. |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 438 | if ((mStkInput.icon == null || !mStkInput.iconSelfExplanatory) |
| 439 | && !TextUtils.isEmpty(mStkInput.text)) { |
Takeshi Shinohara | c658900 | 2013-05-27 11:01:06 +0900 | [diff] [blame] | 440 | mPromptView.setText(mStkInput.text); |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 441 | mPromptView.setVisibility(View.VISIBLE); |
Takeshi Shinohara | c658900 | 2013-05-27 11:01:06 +0900 | [diff] [blame] | 442 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 443 | |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 444 | // Set input type (alphabet/digit) info close to the InText form. |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 445 | boolean hideHelper = false; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 446 | if (mStkInput.digitOnly) { |
| 447 | mTextIn.setKeyListener(StkDigitsKeyListener.getInstance()); |
| 448 | inTypeId = R.string.digits; |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 449 | hideHelper = StkAppService.getBooleanCarrierConfig(this, |
| 450 | CarrierConfigManager.KEY_HIDE_DIGITS_HELPER_TEXT_ON_STK_INPUT_SCREEN_BOOL, |
| 451 | mSlotId); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 452 | } |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 453 | textInput.setHelperText(getResources().getString(inTypeId)); |
Yukiko Fujimura | 913c143 | 2019-02-21 17:14:30 +0900 | [diff] [blame] | 454 | textInput.setHelperTextEnabled(!hideHelper); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 455 | |
Yoshiaki Naka | 28313ba | 2017-08-04 12:20:53 +0900 | [diff] [blame] | 456 | setTitle(R.string.app_name); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 457 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 458 | if (mStkInput.icon != null) { |
Yoshiaki Naka | dd0dbb1 | 2017-08-03 21:20:38 +0900 | [diff] [blame] | 459 | ImageView imageView = (ImageView) findViewById(R.id.icon); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 460 | imageView.setImageBitmap(mStkInput.icon); |
| 461 | imageView.setVisibility(View.VISIBLE); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | // Handle specific global and text attributes. |
| 465 | switch (mState) { |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 466 | case STATE_TEXT: |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 467 | mTextIn.setFilters(new InputFilter[] {new InputFilter.LengthFilter(mStkInput.maxLen)}); |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 468 | |
Yoshiaki Naka | c1efd35 | 2019-02-21 17:13:38 +0900 | [diff] [blame] | 469 | textInput.setCounterMaxLength(mStkInput.maxLen); |
| 470 | textInput.setCounterEnabled(true); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 471 | |
| 472 | if (!mStkInput.echo) { |
Yujing Gu | 6b9716c | 2014-04-23 13:50:50 +0800 | [diff] [blame] | 473 | mTextIn.setTransformationMethod(PasswordTransformationMethod |
| 474 | .getInstance()); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 475 | } |
Srikanth Chintala | a091b73 | 2016-02-04 14:46:43 +0530 | [diff] [blame] | 476 | mTextIn.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN); |
Kazuhiro Uto | 1287091 | 2018-07-18 17:43:56 +0900 | [diff] [blame] | 477 | // Request the initial focus on the edit box and show the software keyboard. |
| 478 | mTextIn.requestFocus(); |
| 479 | getWindow().setSoftInputMode( |
| 480 | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 481 | // Set default text if present. |
| 482 | if (mStkInput.defaultText != null) { |
| 483 | mTextIn.setText(mStkInput.defaultText); |
| 484 | } else { |
| 485 | // make sure the text is cleared |
| 486 | mTextIn.setText("", BufferType.EDITABLE); |
| 487 | } |
Miyu Iijima | c9a1720 | 2018-10-17 19:17:14 +0900 | [diff] [blame] | 488 | updateButton(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 489 | |
| 490 | break; |
| 491 | case STATE_YES_NO: |
| 492 | // Set display mode - normal / yes-no layout |
| 493 | mYesNoLayout.setVisibility(View.VISIBLE); |
| 494 | mNormalLayout.setVisibility(View.GONE); |
| 495 | break; |
| 496 | } |
| 497 | } |
| 498 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 499 | private void initFromIntent(Intent intent) { |
| 500 | // Get the calling intent type: text/key, and setup the |
| 501 | // display parameters. |
| 502 | CatLog.d(LOG_TAG, "initFromIntent - slot id: " + mSlotId); |
| 503 | if (intent != null) { |
| 504 | mStkInput = intent.getParcelableExtra("INPUT"); |
| 505 | mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1); |
| 506 | CatLog.d(LOG_TAG, "onCreate - slot id: " + mSlotId); |
| 507 | if (mStkInput == null) { |
| 508 | finish(); |
| 509 | } else { |
| 510 | mState = mStkInput.yesNo ? STATE_YES_NO : |
| 511 | STATE_TEXT; |
| 512 | configInputDisplay(); |
| 513 | } |
| 514 | } else { |
| 515 | finish(); |
| 516 | } |
| 517 | } |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 518 | |
| 519 | private final AlarmManager.OnAlarmListener mAlarmListener = |
| 520 | new AlarmManager.OnAlarmListener() { |
| 521 | @Override |
| 522 | public void onAlarm() { |
| 523 | CatLog.d(LOG_TAG, "The alarm time is reached"); |
| 524 | mAlarmTime = NO_INPUT_ALARM; |
Yoshiaki Naka | a95f5c8 | 2016-09-02 11:27:05 +0900 | [diff] [blame] | 525 | sendResponse(StkAppService.RES_ID_TIMEOUT); |
| 526 | } |
| 527 | }; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 528 | } |