blob: b35877f357f30ee3fe6865eecf78067c86e2e3b4 [file] [log] [blame]
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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
17package com.android.stk;
18
Takanori Nakano48544352016-12-02 18:32:59 +090019import android.app.ActionBar;
Yoshiaki Naka31335342018-03-19 16:24:12 +090020import android.app.AlarmManager;
21import android.app.ListActivity;
Takanori Nakano3776e2c2016-10-14 16:54:28 +090022import android.content.BroadcastReceiver;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080023import android.content.Context;
24import android.content.Intent;
Takanori Nakano3776e2c2016-10-14 16:54:28 +090025import android.content.IntentFilter;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080026import android.os.Bundle;
Yoshiaki Naka31335342018-03-19 16:24:12 +090027import android.os.SystemClock;
pkanwarae3a1c82017-04-13 10:24:48 -070028import android.telephony.SubscriptionManager;
Guillaume Lucas82d3e792012-08-03 17:56:34 +020029import android.view.ContextMenu;
30import android.view.ContextMenu.ContextMenuInfo;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080031import android.view.KeyEvent;
32import android.view.MenuItem;
33import android.view.View;
Guillaume Lucas82d3e792012-08-03 17:56:34 +020034import android.widget.AdapterView;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080035import android.widget.ImageView;
36import android.widget.ListView;
37import android.widget.ProgressBar;
38import android.widget.TextView;
39
Yoshiaki Nakaa89c9342019-02-21 17:08:13 +090040import androidx.localbroadcastmanager.content.LocalBroadcastManager;
41
Yoshiaki Naka31335342018-03-19 16:24:12 +090042import com.android.internal.telephony.cat.CatLog;
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070043import com.android.internal.telephony.cat.Item;
44import com.android.internal.telephony.cat.Menu;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080045
46/**
Wink Saville79085fc2009-06-09 10:27:23 -070047 * ListActivity used for displaying STK menus. These can be SET UP MENU and
48 * SELECT ITEM menus. This activity is started multiple times with different
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080049 * menu content.
50 *
51 */
Guillaume Lucas82d3e792012-08-03 17:56:34 +020052public class StkMenuActivity extends ListActivity implements View.OnCreateContextMenuListener {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080053 private Menu mStkMenu = null;
54 private int mState = STATE_MAIN;
55 private boolean mAcceptUsersInput = true;
Wink Savillee68857d2014-10-17 15:23:05 -070056 private int mSlotId = -1;
57 private boolean mIsResponseSent = false;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080058
59 private TextView mTitleTextView = null;
60 private ImageView mTitleIconView = null;
61 private ProgressBar mProgressView = null;
Yoshiaki Naka3a980db2019-10-30 17:11:33 +090062
63 private static final String LOG_TAG =
64 new Object(){}.getClass().getEnclosingClass().getSimpleName();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080065
Wink Savillee68857d2014-10-17 15:23:05 -070066 private StkAppService appService = StkAppService.getInstance();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080067
Takanori Nakano6c2d4682017-10-19 20:36:50 +090068 // Keys for saving the state of the dialog in the bundle
69 private static final String STATE_KEY = "state";
Takanori Nakano6c2d4682017-10-19 20:36:50 +090070 private static final String ACCEPT_USERS_INPUT_KEY = "accept_users_input";
71 private static final String RESPONSE_SENT_KEY = "response_sent";
Yoshiaki Naka31335342018-03-19 16:24:12 +090072 private static final String ALARM_TIME_KEY = "alarm_time";
73
74 private static final String SELECT_ALARM_TAG = LOG_TAG;
75 private static final long NO_SELECT_ALARM = -1;
76 private long mAlarmTime = NO_SELECT_ALARM;
Takanori Nakano6c2d4682017-10-19 20:36:50 +090077
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080078 // Internal state values
Wink Savillee68857d2014-10-17 15:23:05 -070079 static final int STATE_INIT = 0;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080080 static final int STATE_MAIN = 1;
81 static final int STATE_SECONDARY = 2;
82
Guillaume Lucas82d3e792012-08-03 17:56:34 +020083 private static final int CONTEXT_MENU_HELP = 0;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080084
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080085 @Override
Takanori Nakano6c2d4682017-10-19 20:36:50 +090086 public void onCreate(Bundle savedInstanceState) {
87 super.onCreate(savedInstanceState);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080088
Wink Savillee68857d2014-10-17 15:23:05 -070089 CatLog.d(LOG_TAG, "onCreate");
Takanori Nakano48544352016-12-02 18:32:59 +090090
91 ActionBar actionBar = getActionBar();
92 actionBar.setCustomView(R.layout.stk_title);
93 actionBar.setDisplayShowCustomEnabled(true);
94
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080095 // Set the layout for this activity.
96 setContentView(R.layout.stk_menu_list);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080097 mTitleTextView = (TextView) findViewById(R.id.title_text);
98 mTitleIconView = (ImageView) findViewById(R.id.title_icon);
99 mProgressView = (ProgressBar) findViewById(R.id.progress_bar);
Guillaume Lucas82d3e792012-08-03 17:56:34 +0200100 getListView().setOnCreateContextMenuListener(this);
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900101
102 // appService can be null if this activity is automatically recreated by the system
103 // with the saved instance state right after the phone process is killed.
104 if (appService == null) {
105 CatLog.d(LOG_TAG, "onCreate - appService is null");
106 finish();
107 return;
108 }
109
Takanori Nakano3776e2c2016-10-14 16:54:28 +0900110 LocalBroadcastManager.getInstance(this).registerReceiver(mLocalBroadcastReceiver,
111 new IntentFilter(StkAppService.SESSION_ENDED));
Wink Savillee68857d2014-10-17 15:23:05 -0700112 initFromIntent(getIntent());
pkanwarae3a1c82017-04-13 10:24:48 -0700113 if (!SubscriptionManager.isValidSlotIndex(mSlotId)) {
114 finish();
115 return;
116 }
Anna Suzuki35309b02019-02-15 16:24:59 +0900117 if (mState == STATE_SECONDARY) {
118 appService.getStkContext(mSlotId).setPendingActivityInstance(this);
119 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800120 }
121
122 @Override
123 protected void onListItemClick(ListView l, View v, int position, long id) {
124 super.onListItemClick(l, v, position, id);
Wink Saville79085fc2009-06-09 10:27:23 -0700125
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800126 if (!mAcceptUsersInput) {
Wink Savillee68857d2014-10-17 15:23:05 -0700127 CatLog.d(LOG_TAG, "mAcceptUsersInput:false");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800128 return;
129 }
130
131 Item item = getSelectedItem(position);
132 if (item == null) {
Wink Savillee68857d2014-10-17 15:23:05 -0700133 CatLog.d(LOG_TAG, "Item is null");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800134 return;
135 }
Preeti Ahuja03be6672012-08-30 19:21:25 +0530136
Wink Savillee68857d2014-10-17 15:23:05 -0700137 CatLog.d(LOG_TAG, "onListItemClick Id: " + item.id + ", mState: " + mState);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800138 sendResponse(StkAppService.RES_ID_MENU_SELECTION, item.id, false);
Takanori Nakano48544352016-12-02 18:32:59 +0900139 invalidateOptionsMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800140 }
141
142 @Override
143 public boolean onKeyDown(int keyCode, KeyEvent event) {
Wink Savillee68857d2014-10-17 15:23:05 -0700144 CatLog.d(LOG_TAG, "mAcceptUsersInput: " + mAcceptUsersInput);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800145 if (!mAcceptUsersInput) {
146 return true;
147 }
148
149 switch (keyCode) {
150 case KeyEvent.KEYCODE_BACK:
Wink Savillee68857d2014-10-17 15:23:05 -0700151 CatLog.d(LOG_TAG, "KEYCODE_BACK - mState[" + mState + "]");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800152 switch (mState) {
153 case STATE_SECONDARY:
Wink Savillee68857d2014-10-17 15:23:05 -0700154 CatLog.d(LOG_TAG, "STATE_SECONDARY");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800155 sendResponse(StkAppService.RES_ID_BACKWARD);
156 return true;
157 case STATE_MAIN:
Wink Savillee68857d2014-10-17 15:23:05 -0700158 CatLog.d(LOG_TAG, "STATE_MAIN");
Wink Savillee68857d2014-10-17 15:23:05 -0700159 finish();
160 return true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800161 }
162 break;
163 }
164 return super.onKeyDown(keyCode, event);
165 }
166
167 @Override
168 public void onResume() {
169 super.onResume();
170
Wink Savillee68857d2014-10-17 15:23:05 -0700171 CatLog.d(LOG_TAG, "onResume, slot id: " + mSlotId + "," + mState);
172 appService.indicateMenuVisibility(true, mSlotId);
173 if (mState == STATE_MAIN) {
174 mStkMenu = appService.getMainMenu(mSlotId);
175 } else {
176 mStkMenu = appService.getMenu(mSlotId);
177 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800178 if (mStkMenu == null) {
Wink Savillee68857d2014-10-17 15:23:05 -0700179 CatLog.d(LOG_TAG, "menu is null");
180 cancelTimeOut();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800181 finish();
182 return;
183 }
184 displayMenu();
Yoshiaki Naka31335342018-03-19 16:24:12 +0900185
186 if (mAlarmTime == NO_SELECT_ALARM) {
187 startTimeOut();
188 }
189
w3023464ec38e2014-09-17 16:32:02 -0700190 invalidateOptionsMenu();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800191 }
192
193 @Override
194 public void onPause() {
195 super.onPause();
Wink Savillee68857d2014-10-17 15:23:05 -0700196 CatLog.d(LOG_TAG, "onPause, slot id: " + mSlotId + "," + mState);
197 //If activity is finished in onResume and it reaults from null appService.
198 if (appService != null) {
199 appService.indicateMenuVisibility(false, mSlotId);
200 } else {
201 CatLog.d(LOG_TAG, "onPause: null appService.");
202 }
Preeti Ahuja03be6672012-08-30 19:21:25 +0530203
204 /*
205 * do not cancel the timer here cancelTimeOut(). If any higher/lower
206 * priority events such as incoming call, new sms, screen off intent,
207 * notification alerts, user actions such as 'User moving to another activtiy'
208 * etc.. occur during SELECT ITEM ongoing session,
209 * this activity would receive 'onPause()' event resulting in
210 * cancellation of the timer. As a result no terminal response is
211 * sent to the card.
212 */
213
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800214 }
215
216 @Override
Wink Savillee68857d2014-10-17 15:23:05 -0700217 public void onStop() {
218 super.onStop();
219 CatLog.d(LOG_TAG, "onStop, slot id: " + mSlotId + "," + mIsResponseSent + "," + mState);
Wink Savillee68857d2014-10-17 15:23:05 -0700220 }
221
222 @Override
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800223 public void onDestroy() {
Guillaume Lucas82d3e792012-08-03 17:56:34 +0200224 getListView().setOnCreateContextMenuListener(null);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800225 super.onDestroy();
Srikanth Chintalab5ea5d62014-07-11 02:04:40 -0400226 CatLog.d(LOG_TAG, "onDestroy" + ", " + mState);
pkanwarae3a1c82017-04-13 10:24:48 -0700227 if (appService == null || !SubscriptionManager.isValidSlotIndex(mSlotId)) {
Ryuto Sawadaba9b86b2016-10-03 14:03:16 +0900228 return;
229 }
Wink Savillee68857d2014-10-17 15:23:05 -0700230 //isMenuPending: if input act is finish by stkappservice when OP_LAUNCH_APP again,
231 //we can not send TR here, since the input cmd is waiting user to process.
Tsukasa Gotou46f29b52016-01-28 12:32:54 +0900232 if (mState == STATE_SECONDARY && !mIsResponseSent && !appService.isMenuPending(mSlotId)) {
Takanori Nakano6c2d4682017-10-19 20:36:50 +0900233 // Avoid sending the terminal response while the activty is being restarted
234 // due to some kind of configuration change.
235 if (!isChangingConfigurations()) {
236 CatLog.d(LOG_TAG, "handleDestroy - Send End Session");
237 sendResponse(StkAppService.RES_ID_END_SESSION);
238 }
Wink Savillee68857d2014-10-17 15:23:05 -0700239 }
Yoshiaki Naka31335342018-03-19 16:24:12 +0900240 cancelTimeOut();
Takanori Nakano3776e2c2016-10-14 16:54:28 +0900241 LocalBroadcastManager.getInstance(this).unregisterReceiver(mLocalBroadcastReceiver);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800242 }
243
244 @Override
245 public boolean onCreateOptionsMenu(android.view.Menu menu) {
246 super.onCreateOptionsMenu(menu);
247 menu.add(0, StkApp.MENU_ID_END_SESSION, 1, R.string.menu_end_session);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800248 return true;
249 }
250
251 @Override
252 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
253 super.onPrepareOptionsMenu(menu);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800254 boolean mainVisible = false;
255
Takanori Nakano48544352016-12-02 18:32:59 +0900256 if (mState == STATE_SECONDARY && mAcceptUsersInput) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800257 mainVisible = true;
258 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800259
260 menu.findItem(StkApp.MENU_ID_END_SESSION).setVisible(mainVisible);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800261
Srikanth Chintalab5ea5d62014-07-11 02:04:40 -0400262 return mainVisible;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800263 }
264
265 @Override
266 public boolean onOptionsItemSelected(MenuItem item) {
267 if (!mAcceptUsersInput) {
268 return true;
269 }
270 switch (item.getItemId()) {
271 case StkApp.MENU_ID_END_SESSION:
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800272 // send session end response.
273 sendResponse(StkAppService.RES_ID_END_SESSION);
Wink Savillee68857d2014-10-17 15:23:05 -0700274 finish();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800275 return true;
Takanori Nakano48544352016-12-02 18:32:59 +0900276 default:
277 break;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800278 }
279 return super.onOptionsItemSelected(item);
280 }
281
282 @Override
Guillaume Lucas82d3e792012-08-03 17:56:34 +0200283 public void onCreateContextMenu(ContextMenu menu, View v,
284 ContextMenuInfo menuInfo) {
Yoshiaki Naka3a980db2019-10-30 17:11:33 +0900285 CatLog.d(LOG_TAG, "onCreateContextMenu");
Guillaume Lucas82d3e792012-08-03 17:56:34 +0200286 boolean helpVisible = false;
287 if (mStkMenu != null) {
288 helpVisible = mStkMenu.helpAvailable;
289 }
290 if (helpVisible) {
Yoshiaki Naka3a980db2019-10-30 17:11:33 +0900291 CatLog.d(LOG_TAG, "add menu");
Guillaume Lucas82d3e792012-08-03 17:56:34 +0200292 menu.add(0, CONTEXT_MENU_HELP, 0, R.string.help);
293 }
294 }
295
296 @Override
297 public boolean onContextItemSelected(MenuItem item) {
298 AdapterView.AdapterContextMenuInfo info;
299 try {
300 info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
301 } catch (ClassCastException e) {
302 return false;
303 }
304 switch (item.getItemId()) {
305 case CONTEXT_MENU_HELP:
Guillaume Lucas82d3e792012-08-03 17:56:34 +0200306 int position = info.position;
Yoshiaki Naka3a980db2019-10-30 17:11:33 +0900307 CatLog.d(LOG_TAG, "Position:" + position);
Guillaume Lucas82d3e792012-08-03 17:56:34 +0200308 Item stkItem = getSelectedItem(position);
309 if (stkItem != null) {
Yoshiaki Naka3a980db2019-10-30 17:11:33 +0900310 CatLog.d(LOG_TAG, "item id:" + stkItem.id);
Guillaume Lucas82d3e792012-08-03 17:56:34 +0200311 sendResponse(StkAppService.RES_ID_MENU_SELECTION, stkItem.id, true);
312 }
313 return true;
314
315 default:
316 return super.onContextItemSelected(item);
317 }
318 }
319
320 @Override
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800321 protected void onSaveInstanceState(Bundle outState) {
Wink Savillee68857d2014-10-17 15:23:05 -0700322 CatLog.d(LOG_TAG, "onSaveInstanceState: " + mSlotId);
Takanori Nakano6c2d4682017-10-19 20:36:50 +0900323 outState.putInt(STATE_KEY, mState);
Takanori Nakano6c2d4682017-10-19 20:36:50 +0900324 outState.putBoolean(ACCEPT_USERS_INPUT_KEY, mAcceptUsersInput);
325 outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent);
Yoshiaki Naka31335342018-03-19 16:24:12 +0900326 outState.putLong(ALARM_TIME_KEY, mAlarmTime);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800327 }
328
329 @Override
330 protected void onRestoreInstanceState(Bundle savedInstanceState) {
Wink Savillee68857d2014-10-17 15:23:05 -0700331 CatLog.d(LOG_TAG, "onRestoreInstanceState: " + mSlotId);
Takanori Nakano6c2d4682017-10-19 20:36:50 +0900332 mState = savedInstanceState.getInt(STATE_KEY);
Takanori Nakano6c2d4682017-10-19 20:36:50 +0900333 mAcceptUsersInput = savedInstanceState.getBoolean(ACCEPT_USERS_INPUT_KEY);
Takanori Nakano3776e2c2016-10-14 16:54:28 +0900334 if (!mAcceptUsersInput) {
335 // Check the latest information as the saved instance state can be outdated.
336 if ((mState == STATE_MAIN) && appService.isMainMenuAvailable(mSlotId)) {
337 mAcceptUsersInput = true;
338 } else {
339 showProgressBar(true);
340 }
341 }
Takanori Nakano6c2d4682017-10-19 20:36:50 +0900342 mIsResponseSent = savedInstanceState.getBoolean(RESPONSE_SENT_KEY);
Yoshiaki Naka31335342018-03-19 16:24:12 +0900343
344 mAlarmTime = savedInstanceState.getLong(ALARM_TIME_KEY, NO_SELECT_ALARM);
345 if (mAlarmTime != NO_SELECT_ALARM) {
346 startTimeOut();
347 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800348 }
Wink Saville79085fc2009-06-09 10:27:23 -0700349
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800350 private void cancelTimeOut() {
Yoshiaki Naka31335342018-03-19 16:24:12 +0900351 if (mAlarmTime != NO_SELECT_ALARM) {
352 CatLog.d(LOG_TAG, "cancelTimeOut - slot id: " + mSlotId);
353 AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
354 am.cancel(mAlarmListener);
355 mAlarmTime = NO_SELECT_ALARM;
356 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800357 }
358
359 private void startTimeOut() {
Yoshiaki Naka31335342018-03-19 16:24:12 +0900360 // No need to set alarm if this is the main menu or device sent TERMINAL RESPONSE already.
361 if (mState != STATE_SECONDARY || mIsResponseSent) {
362 return;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800363 }
Yoshiaki Naka31335342018-03-19 16:24:12 +0900364
365 if (mAlarmTime == NO_SELECT_ALARM) {
366 mAlarmTime = SystemClock.elapsedRealtime() + StkApp.UI_TIMEOUT;
367 }
368
369 CatLog.d(LOG_TAG, "startTimeOut: " + mAlarmTime + "ms, slot id: " + mSlotId);
370 AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
371 am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, mAlarmTime, SELECT_ALARM_TAG,
372 mAlarmListener, null);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800373 }
Wink Saville79085fc2009-06-09 10:27:23 -0700374
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800375 // Bind list adapter to the items list.
376 private void displayMenu() {
377
378 if (mStkMenu != null) {
Pierre Fröjd3e34a8a2010-11-30 15:28:54 +0100379 String title = mStkMenu.title == null ? getString(R.string.app_name) : mStkMenu.title;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800380 // Display title & title icon
381 if (mStkMenu.titleIcon != null) {
382 mTitleIconView.setImageBitmap(mStkMenu.titleIcon);
Umashankar Godachic77445b2018-02-28 02:51:56 +0530383 mTitleIconView.setContentDescription(StkAppService.TEXT_ICON_FROM_COMMAND);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800384 mTitleIconView.setVisibility(View.VISIBLE);
Pierre Fröjd3e34a8a2010-11-30 15:28:54 +0100385 mTitleTextView.setVisibility(View.INVISIBLE);
386 if (!mStkMenu.titleIconSelfExplanatory) {
387 mTitleTextView.setText(title);
388 mTitleTextView.setVisibility(View.VISIBLE);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800389 }
390 } else {
Pierre Fröjd3e34a8a2010-11-30 15:28:54 +0100391 mTitleIconView.setVisibility(View.GONE);
392 mTitleTextView.setVisibility(View.VISIBLE);
393 mTitleTextView.setText(title);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800394 }
395 // create an array adapter for the menu list
396 StkMenuAdapter adapter = new StkMenuAdapter(this,
397 mStkMenu.items, mStkMenu.itemsIconSelfExplanatory);
398 // Bind menu list to the new adapter.
399 setListAdapter(adapter);
400 // Set default item
401 setSelection(mStkMenu.defaultItem);
402 }
403 }
404
Takanori Nakano3776e2c2016-10-14 16:54:28 +0900405 private void showProgressBar(boolean show) {
406 if (show) {
407 mProgressView.setIndeterminate(true);
408 mProgressView.setVisibility(View.VISIBLE);
409 } else {
410 mProgressView.setIndeterminate(false);
411 mProgressView.setVisibility(View.GONE);
412 }
413 }
414
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800415 private void initFromIntent(Intent intent) {
416
417 if (intent != null) {
418 mState = intent.getIntExtra("STATE", STATE_MAIN);
Wink Savillee68857d2014-10-17 15:23:05 -0700419 mSlotId = intent.getIntExtra(StkAppService.SLOT_ID, -1);
420 CatLog.d(LOG_TAG, "slot id: " + mSlotId + ", state: " + mState);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800421 } else {
Wink Savillee68857d2014-10-17 15:23:05 -0700422 CatLog.d(LOG_TAG, "finish!");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800423 finish();
424 }
425 }
426
427 private Item getSelectedItem(int position) {
428 Item item = null;
429 if (mStkMenu != null) {
430 try {
431 item = mStkMenu.items.get(position);
432 } catch (IndexOutOfBoundsException e) {
433 if (StkApp.DBG) {
Wink Savillee68857d2014-10-17 15:23:05 -0700434 CatLog.d(LOG_TAG, "IOOBE Invalid menu");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800435 }
436 } catch (NullPointerException e) {
437 if (StkApp.DBG) {
Wink Savillee68857d2014-10-17 15:23:05 -0700438 CatLog.d(LOG_TAG, "NPE Invalid menu");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800439 }
440 }
441 }
442 return item;
443 }
444
445 private void sendResponse(int resId) {
446 sendResponse(resId, 0, false);
447 }
448
449 private void sendResponse(int resId, int itemId, boolean help) {
Wink Savillee68857d2014-10-17 15:23:05 -0700450 CatLog.d(LOG_TAG, "sendResponse resID[" + resId + "] itemId[" + itemId +
451 "] help[" + help + "]");
Takanori Nakano3776e2c2016-10-14 16:54:28 +0900452
453 // Disallow user operation temporarily until receiving the result of the response.
454 mAcceptUsersInput = false;
455 if (resId == StkAppService.RES_ID_MENU_SELECTION) {
456 showProgressBar(true);
457 }
Yoshiaki Naka31335342018-03-19 16:24:12 +0900458 cancelTimeOut();
Takanori Nakano3776e2c2016-10-14 16:54:28 +0900459
Wink Savillee68857d2014-10-17 15:23:05 -0700460 mIsResponseSent = true;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800461 Bundle args = new Bundle();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800462 args.putInt(StkAppService.RES_ID, resId);
463 args.putInt(StkAppService.MENU_SELECTION, itemId);
464 args.putBoolean(StkAppService.HELP, help);
Takanori Nakano43dacc02018-07-26 11:27:39 +0900465 appService.sendResponse(args, mSlotId);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800466 }
Takanori Nakano3776e2c2016-10-14 16:54:28 +0900467
468 private final BroadcastReceiver mLocalBroadcastReceiver = new BroadcastReceiver() {
469 @Override
470 public void onReceive(Context context, Intent intent) {
471 if (StkAppService.SESSION_ENDED.equals(intent.getAction())) {
472 int slotId = intent.getIntExtra(StkAppService.SLOT_ID, 0);
473 if ((mState == STATE_MAIN) && (mSlotId == slotId)) {
474 mAcceptUsersInput = true;
475 showProgressBar(false);
476 }
477 }
478 }
479 };
Yoshiaki Naka31335342018-03-19 16:24:12 +0900480
481 private final AlarmManager.OnAlarmListener mAlarmListener =
482 new AlarmManager.OnAlarmListener() {
483 @Override
484 public void onAlarm() {
485 CatLog.d(LOG_TAG, "The alarm time is reached");
486 mAlarmTime = NO_SELECT_ALARM;
Yoshiaki Naka31335342018-03-19 16:24:12 +0900487 sendResponse(StkAppService.RES_ID_TIMEOUT);
488 }
489 };
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800490}