diff options
author | Wink Saville <wink@google.com> | 2014-10-17 15:23:05 -0700 |
---|---|---|
committer | Wink Saville <wink@google.com> | 2014-10-20 10:37:11 -0700 |
commit | e68857da85f6fb0964da9d58a7cbfcc0348065c6 (patch) | |
tree | 85998dd915dc286cc77067cd69c3bf33acc82027 /src/com/android/stk/StkLauncherActivity.java | |
parent | 201329761cb19876732c06403e3137c38ad06425 (diff) | |
download | Stk-e68857da85f6fb0964da9d58a7cbfcc0348065c6.tar.gz |
STK App DSDS support
Change-Id: I8d0a9ac406327fa91d78119df2953a417b4e4cb6
Diffstat (limited to 'src/com/android/stk/StkLauncherActivity.java')
-rwxr-xr-x[-rw-r--r--] | src/com/android/stk/StkLauncherActivity.java | 212 |
1 files changed, 205 insertions, 7 deletions
diff --git a/src/com/android/stk/StkLauncherActivity.java b/src/com/android/stk/StkLauncherActivity.java index 194870e..9066c3e 100644..100755 --- a/src/com/android/stk/StkLauncherActivity.java +++ b/src/com/android/stk/StkLauncherActivity.java @@ -16,24 +16,222 @@ package com.android.stk; -import android.app.Activity; +import android.app.ListActivity; +import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.view.View; +import android.view.KeyEvent; +import android.view.Window; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; + +import com.android.internal.telephony.cat.Item; +import com.android.internal.telephony.cat.Menu; +import com.android.internal.telephony.cat.CatLog; +import com.android.internal.telephony.PhoneConstants; + +import android.telephony.TelephonyManager; + +import java.util.ArrayList; /** * Launcher class. Serve as the app's MAIN activity, send an intent to the * StkAppService and finish. * */ -public class StkLauncherActivity extends Activity { +public class StkLauncherActivity extends ListActivity { + private TextView mTitleTextView = null; + private ImageView mTitleIconView = null; + private static final String className = new Object(){}.getClass().getEnclosingClass().getName(); + private static final String LOG_TAG = className.substring(className.lastIndexOf('.') + 1); + private ArrayList<Item> mStkMenuList = null; + private int mSingleSimId = -1; + private Context mContext = null; + private TelephonyManager mTm = null; + private Bitmap mBitMap = null; + private boolean mAcceptUsersInput = true; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + CatLog.d(LOG_TAG, "onCreate+"); + mContext = getBaseContext(); + mTm = (TelephonyManager) mContext.getSystemService( + Context.TELEPHONY_SERVICE); + //Check if needs to show the menu list. + if (isShowSTKListMenu()) { + requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.stk_menu_list); + mTitleTextView = (TextView) findViewById(R.id.title_text); + mTitleIconView = (ImageView) findViewById(R.id.title_icon); + mTitleTextView.setText(R.string.app_name); + mBitMap = BitmapFactory.decodeResource(getResources(), + R.drawable.ic_launcher_sim_toolkit); + } else { + //launch stk menu activity for the SIM. + if (mSingleSimId < 0) { + finish(); + } + } + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + super.onListItemClick(l, v, position, id); + if (!mAcceptUsersInput) { + CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); + return; + } + int simCount = TelephonyManager.from(mContext).getSimCount(); + Item item = getSelectedItem(position); + if (item == null) { + CatLog.d(LOG_TAG, "Item is null"); + return; + } + CatLog.d(LOG_TAG, "launch stk menu id: " + item.id); + if (item.id >= PhoneConstants.SIM_ID_1 && item.id < simCount) { + mAcceptUsersInput = false; + launchSTKMainMenu(item.id); + } + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + CatLog.d(LOG_TAG, "mAcceptUsersInput: " + mAcceptUsersInput); + if (!mAcceptUsersInput) { + return true; + } + switch (keyCode) { + case KeyEvent.KEYCODE_BACK: + CatLog.d(LOG_TAG, "KEYCODE_BACK."); + mAcceptUsersInput = false; + finish(); + return true; + } + return super.onKeyDown(keyCode, event); + } + + @Override + public void onResume() { + super.onResume(); + CatLog.d(LOG_TAG, "onResume"); + mAcceptUsersInput = true; + int itemSize = addStkMenuListItems(); + if (itemSize == 0) { + CatLog.d(LOG_TAG, "item size = 0 so finish."); + finish(); + } else if (itemSize == 1) { + launchSTKMainMenu(mSingleSimId); + finish(); + } else { + CatLog.d(LOG_TAG, "resume to show multiple stk list."); + } + } + @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public void onPause() { + super.onPause(); + CatLog.d(LOG_TAG, "onPause"); + } + + @Override + public void onDestroy() { + super.onDestroy(); + CatLog.d(LOG_TAG, "onDestroy"); + } + private Item getSelectedItem(int position) { + Item item = null; + if (mStkMenuList != null) { + try { + item = mStkMenuList.get(position); + } catch (IndexOutOfBoundsException e) { + if (StkApp.DBG) { + CatLog.d(LOG_TAG, "IOOBE Invalid menu"); + } + } catch (NullPointerException e) { + if (StkApp.DBG) { + CatLog.d(LOG_TAG, "NPE Invalid menu"); + } + } + } + return item; + } + + private int addStkMenuListItems() { + String appName = mContext.getResources().getString(R.string.app_name); + String stkItemName = null; + int simCount = TelephonyManager.from(mContext).getSimCount(); + mStkMenuList = new ArrayList<Item>(); + + CatLog.d(LOG_TAG, "simCount: " + simCount); + for (int i = 0; i < simCount; i++) { + //Check if the card is inserted. + if (mTm.hasIccCard(i)) { + CatLog.d(LOG_TAG, "SIM " + i + " add to menu."); + mSingleSimId = i; + stkItemName = new StringBuilder(appName).append(" ") + .append(Integer.toString(i + 1)).toString(); + Item item = new Item(i + 1, stkItemName, mBitMap); + item.id = i; + mStkMenuList.add(item); + } else { + CatLog.d(LOG_TAG, "SIM " + i + " is not inserted."); + } + } + if (mStkMenuList != null && mStkMenuList.size() > 0) { + if (mStkMenuList.size() > 1) { + StkMenuAdapter adapter = new StkMenuAdapter(this, + mStkMenuList, false); + // Bind menu list to the new adapter. + this.setListAdapter(adapter); + } + return mStkMenuList.size(); + } else { + CatLog.d(LOG_TAG, "No stk menu item add."); + return 0; + } + } + private boolean isShowSTKListMenu() { + int simCount = TelephonyManager.from(mContext).getSimCount(); + int simInsertedCount = 0; + int insertedSlotId = -1; + + CatLog.d(LOG_TAG, "simCount: " + simCount); + for (int i = 0; i < simCount; i++) { + //Check if the card is inserted. + if (mTm.hasIccCard(i)) { + CatLog.d(LOG_TAG, "SIM " + i + " is inserted."); + mSingleSimId = i; + simInsertedCount++; + } else { + CatLog.d(LOG_TAG, "SIM " + i + " is not inserted."); + } + } + if (simInsertedCount > 1) { + return true; + } else { + //No card or only one card. + CatLog.d(LOG_TAG, "do not show stk list menu."); + return false; + } + } + private void launchSTKMainMenu(int slodId) { Bundle args = new Bundle(); + CatLog.d(LOG_TAG, "launchSTKMainMenu."); args.putInt(StkAppService.OPCODE, StkAppService.OP_LAUNCH_APP); - startService(new Intent(this, StkAppService.class).putExtras(args)); - - finish(); + args.putInt(StkAppService.SLOT_ID + , PhoneConstants.SIM_ID_1 + slodId); + startService(new Intent(this, StkAppService.class) + .putExtras(args)); } } |