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 |
| 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 | |
| 17 | package com.android.stk; |
| 18 | |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 19 | import android.app.ActionBar; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 20 | import android.app.ListActivity; |
| 21 | import android.content.Context; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.os.Bundle; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 24 | import android.view.View; |
| 25 | import android.view.KeyEvent; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 26 | import android.widget.ImageView; |
| 27 | import android.widget.ListView; |
| 28 | import android.widget.TextView; |
| 29 | import android.graphics.Bitmap; |
| 30 | import android.graphics.BitmapFactory; |
| 31 | |
| 32 | import com.android.internal.telephony.cat.Item; |
| 33 | import com.android.internal.telephony.cat.Menu; |
| 34 | import com.android.internal.telephony.cat.CatLog; |
| 35 | import com.android.internal.telephony.PhoneConstants; |
| 36 | |
| 37 | import android.telephony.TelephonyManager; |
| 38 | |
| 39 | import java.util.ArrayList; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 42 | * Launcher class. Serve as the app's MAIN activity, send an intent to the |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 43 | * StkAppService and finish. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 44 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 45 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 46 | public class StkLauncherActivity extends ListActivity { |
| 47 | private TextView mTitleTextView = null; |
| 48 | private ImageView mTitleIconView = null; |
| 49 | private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); |
| 50 | private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); |
| 51 | private ArrayList<Item> mStkMenuList = null; |
| 52 | private int mSingleSimId = -1; |
| 53 | private Context mContext = null; |
| 54 | private TelephonyManager mTm = null; |
| 55 | private Bitmap mBitMap = null; |
| 56 | private boolean mAcceptUsersInput = true; |
| 57 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 58 | @Override |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 59 | public void onCreate(Bundle icicle) { |
| 60 | super.onCreate(icicle); |
| 61 | CatLog.d(LOG_TAG, "onCreate+"); |
| 62 | mContext = getBaseContext(); |
| 63 | mTm = (TelephonyManager) mContext.getSystemService( |
| 64 | Context.TELEPHONY_SERVICE); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 65 | |
| 66 | ActionBar actionBar = getActionBar(); |
| 67 | actionBar.setCustomView(R.layout.stk_title); |
| 68 | actionBar.setDisplayShowCustomEnabled(true); |
| 69 | |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 70 | setContentView(R.layout.stk_menu_list); |
| 71 | mTitleTextView = (TextView) findViewById(R.id.title_text); |
| 72 | mTitleIconView = (ImageView) findViewById(R.id.title_icon); |
| 73 | mTitleTextView.setText(R.string.app_name); |
| 74 | mBitMap = BitmapFactory.decodeResource(getResources(), |
Joey | 2a7477f | 2018-02-13 18:43:21 +0200 | [diff] [blame] | 75 | R.mipmap.ic_launcher); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 76 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 77 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 78 | @Override |
| 79 | protected void onNewIntent(Intent intent) { |
| 80 | super.onNewIntent(intent); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | protected void onListItemClick(ListView l, View v, int position, long id) { |
| 85 | super.onListItemClick(l, v, position, id); |
| 86 | if (!mAcceptUsersInput) { |
| 87 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 88 | return; |
| 89 | } |
| 90 | int simCount = TelephonyManager.from(mContext).getSimCount(); |
| 91 | Item item = getSelectedItem(position); |
| 92 | if (item == null) { |
| 93 | CatLog.d(LOG_TAG, "Item is null"); |
| 94 | return; |
| 95 | } |
| 96 | CatLog.d(LOG_TAG, "launch stk menu id: " + item.id); |
| 97 | if (item.id >= PhoneConstants.SIM_ID_1 && item.id < simCount) { |
| 98 | mAcceptUsersInput = false; |
| 99 | launchSTKMainMenu(item.id); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 105 | CatLog.d(LOG_TAG, "mAcceptUsersInput: " + mAcceptUsersInput); |
| 106 | if (!mAcceptUsersInput) { |
| 107 | return true; |
| 108 | } |
| 109 | switch (keyCode) { |
| 110 | case KeyEvent.KEYCODE_BACK: |
| 111 | CatLog.d(LOG_TAG, "KEYCODE_BACK."); |
| 112 | mAcceptUsersInput = false; |
| 113 | finish(); |
| 114 | return true; |
| 115 | } |
| 116 | return super.onKeyDown(keyCode, event); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void onResume() { |
| 121 | super.onResume(); |
| 122 | CatLog.d(LOG_TAG, "onResume"); |
| 123 | mAcceptUsersInput = true; |
| 124 | int itemSize = addStkMenuListItems(); |
| 125 | if (itemSize == 0) { |
| 126 | CatLog.d(LOG_TAG, "item size = 0 so finish."); |
| 127 | finish(); |
| 128 | } else if (itemSize == 1) { |
| 129 | launchSTKMainMenu(mSingleSimId); |
| 130 | finish(); |
| 131 | } else { |
| 132 | CatLog.d(LOG_TAG, "resume to show multiple stk list."); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public void onPause() { |
| 138 | super.onPause(); |
| 139 | CatLog.d(LOG_TAG, "onPause"); |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void onDestroy() { |
| 144 | super.onDestroy(); |
| 145 | CatLog.d(LOG_TAG, "onDestroy"); |
| 146 | } |
| 147 | |
| 148 | private Item getSelectedItem(int position) { |
| 149 | Item item = null; |
| 150 | if (mStkMenuList != null) { |
| 151 | try { |
| 152 | item = mStkMenuList.get(position); |
| 153 | } catch (IndexOutOfBoundsException e) { |
| 154 | if (StkApp.DBG) { |
| 155 | CatLog.d(LOG_TAG, "IOOBE Invalid menu"); |
| 156 | } |
| 157 | } catch (NullPointerException e) { |
| 158 | if (StkApp.DBG) { |
| 159 | CatLog.d(LOG_TAG, "NPE Invalid menu"); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | return item; |
| 164 | } |
| 165 | |
| 166 | private int addStkMenuListItems() { |
Takanori Nakano | 89e5d46 | 2016-03-31 20:10:30 +0900 | [diff] [blame] | 167 | StkAppService appService = StkAppService.getInstance(); |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 168 | if (appService == null) { |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | String appName = mContext.getResources().getString(R.string.app_name); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 173 | String stkItemName = null; |
| 174 | int simCount = TelephonyManager.from(mContext).getSimCount(); |
| 175 | mStkMenuList = new ArrayList<Item>(); |
| 176 | |
| 177 | CatLog.d(LOG_TAG, "simCount: " + simCount); |
| 178 | for (int i = 0; i < simCount; i++) { |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 179 | // Check if the card is inserted. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 180 | if (mTm.hasIccCard(i)) { |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 181 | Menu menu = appService.getMainMenu(i); |
| 182 | // Check if the card has a main menu. |
| 183 | if (menu != null) { |
| 184 | CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " is add to menu."); |
| 185 | mSingleSimId = i; |
| 186 | stkItemName = new StringBuilder(menu.title == null ? appName : menu.title) |
| 187 | .append(" ").append(Integer.toString(i + 1)).toString(); |
Takanori Nakano | c8054ba | 2016-08-15 19:18:16 +0900 | [diff] [blame] | 188 | // Display the default application icon if there is no icon specified by SET-UP |
| 189 | // MENU command nor preset. |
| 190 | Bitmap icon = mBitMap; |
| 191 | if (menu.titleIcon != null) { |
| 192 | icon = menu.titleIcon; |
| 193 | if (menu.titleIconSelfExplanatory) { |
| 194 | stkItemName = null; |
| 195 | } |
| 196 | } |
| 197 | Item item = new Item(i, stkItemName, icon); |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 198 | mStkMenuList.add(item); |
| 199 | } else { |
| 200 | CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " does not have main menu."); |
| 201 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 202 | } else { |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 203 | CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " is not inserted."); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | if (mStkMenuList != null && mStkMenuList.size() > 0) { |
| 207 | if (mStkMenuList.size() > 1) { |
| 208 | StkMenuAdapter adapter = new StkMenuAdapter(this, |
| 209 | mStkMenuList, false); |
| 210 | // Bind menu list to the new adapter. |
| 211 | this.setListAdapter(adapter); |
| 212 | } |
| 213 | return mStkMenuList.size(); |
| 214 | } else { |
| 215 | CatLog.d(LOG_TAG, "No stk menu item add."); |
| 216 | return 0; |
| 217 | } |
| 218 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 219 | private void launchSTKMainMenu(int slodId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 220 | Bundle args = new Bundle(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 221 | CatLog.d(LOG_TAG, "launchSTKMainMenu."); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 222 | args.putInt(StkAppService.OPCODE, StkAppService.OP_LAUNCH_APP); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 223 | args.putInt(StkAppService.SLOT_ID |
| 224 | , PhoneConstants.SIM_ID_1 + slodId); |
| 225 | startService(new Intent(this, StkAppService.class) |
| 226 | .putExtras(args)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 227 | } |
| 228 | } |