From 764167cd0542a766cafce2f30c7aba1cf9d4ea20 Mon Sep 17 00:00:00 2001 From: Kazuhiro Ondo Date: Fri, 21 Oct 2011 16:05:05 -0500 Subject: Add support of dislaying Alpha tag for BIP commands Display dialogs when BIP related proactive commands are received. "Open Channel" command will requre user input and a response will be sent to Cat Service. "Close Channel", "Send Data" and "Receive Data" command will just show an alart dialog to notify the event to the user. Bug:5165510 Change-Id: I350bdc7dfee2947cc0a4c7771ab4972e768c6ff9 --- src/com/android/stk/StkAppService.java | 129 +++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'src/com') diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java index 54698dc..3289918 100644 --- a/src/com/android/stk/StkAppService.java +++ b/src/com/android/stk/StkAppService.java @@ -16,11 +16,13 @@ package com.android.stk; +import android.app.AlertDialog; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -32,6 +34,8 @@ import android.telephony.TelephonyManager; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; +import android.view.Window; +import android.view.WindowManager; import android.widget.ImageView; import android.widget.RemoteViews; import android.widget.TextView; @@ -90,6 +94,7 @@ public class StkAppService extends Service implements Runnable { static final String INPUT = "input"; static final String HELP = "help"; static final String CONFIRMATION = "confirm"; + static final String CHOICE = "choice"; // operations ids for different service functionality. static final int OP_CMD = 1; @@ -104,12 +109,16 @@ public class StkAppService extends Service implements Runnable { static final int RES_ID_INPUT = 12; static final int RES_ID_CONFIRM = 13; static final int RES_ID_DONE = 14; + static final int RES_ID_CHOICE = 15; static final int RES_ID_TIMEOUT = 20; static final int RES_ID_BACKWARD = 21; static final int RES_ID_END_SESSION = 22; static final int RES_ID_EXIT = 23; + static final int YES = 1; + static final int NO = 0; + private static final String PACKAGE_NAME = "com.android.stk"; private static final String MENU_ACTIVITY_NAME = PACKAGE_NAME + ".StkMenuActivity"; @@ -323,6 +332,9 @@ public class StkAppService extends Service implements Runnable { case SEND_USSD: case SET_UP_IDLE_MODE_TEXT: case SET_UP_MENU: + case CLOSE_CHANNEL: + case RECEIVE_DATA: + case SEND_DATA: return false; } @@ -438,6 +450,29 @@ public class StkAppService extends Service implements Runnable { case PLAY_TONE: launchToneDialog(); break; + case OPEN_CHANNEL: + launchOpenChannelDialog(); + break; + case CLOSE_CHANNEL: + case RECEIVE_DATA: + case SEND_DATA: + TextMessage m = mCurrentCmd.geTextMessage(); + + if ((m != null) && (m.text == null)) { + switch(cmdMsg.getCmdType()) { + case CLOSE_CHANNEL: + m.text = getResources().getString(R.string.default_close_channel_msg); + break; + case RECEIVE_DATA: + m.text = getResources().getString(R.string.default_receive_data_msg); + break; + case SEND_DATA: + m.text = getResources().getString(R.string.default_send_data_msg); + break; + } + } + launchTransientEventMessage(); + break; } if (!waitForUsersResponse) { @@ -542,6 +577,18 @@ public class StkAppService extends Service implements Runnable { resMsg.setResultCode(ResultCode.NO_RESPONSE_FROM_USER); } break; + case RES_ID_CHOICE: + int choice = args.getInt(CHOICE); + CatLog.d(this, "User Choice=" + choice); + switch (choice) { + case YES: + resMsg.setResultCode(ResultCode.OK); + break; + case NO: + resMsg.setResultCode(ResultCode.USER_NOT_ACCEPT); + break; + } + break; default: CatLog.d(this, "Unknown result id"); return; @@ -764,6 +811,88 @@ public class StkAppService extends Service implements Runnable { startActivity(newIntent); } + private void launchOpenChannelDialog() { + TextMessage msg = mCurrentCmd.geTextMessage(); + if (msg == null) { + CatLog.d(this, "msg is null, return here"); + return; + } + + msg.title = getResources().getString(R.string.stk_dialog_title); + if (msg.text == null) { + msg.text = getResources().getString(R.string.default_open_channel_msg); + } + + final AlertDialog dialog = new AlertDialog.Builder(mContext) + .setIconAttribute(android.R.attr.alertDialogIcon) + .setTitle(msg.title) + .setMessage(msg.text) + .setCancelable(false) + .setPositiveButton(getResources().getString(R.string.stk_dialog_accept), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + Bundle args = new Bundle(); + args.putInt(RES_ID, RES_ID_CHOICE); + args.putInt(CHOICE, YES); + Message message = mServiceHandler.obtainMessage(); + message.arg1 = OP_RESPONSE; + message.obj = args; + mServiceHandler.sendMessage(message); + } + }) + .setNegativeButton(getResources().getString(R.string.stk_dialog_reject), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + Bundle args = new Bundle(); + args.putInt(RES_ID, RES_ID_CHOICE); + args.putInt(CHOICE, NO); + Message message = mServiceHandler.obtainMessage(); + message.arg1 = OP_RESPONSE; + message.obj = args; + mServiceHandler.sendMessage(message); + } + }) + .create(); + + dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + if (!mContext.getResources().getBoolean( + com.android.internal.R.bool.config_sf_slowBlur)) { + dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); + } + + dialog.show(); + } + + private void launchTransientEventMessage() { + TextMessage msg = mCurrentCmd.geTextMessage(); + if (msg == null) { + CatLog.d(this, "msg is null, return here"); + return; + } + + msg.title = getResources().getString(R.string.stk_dialog_title); + + final AlertDialog dialog = new AlertDialog.Builder(mContext) + .setIconAttribute(android.R.attr.alertDialogIcon) + .setTitle(msg.title) + .setMessage(msg.text) + .setCancelable(false) + .setPositiveButton(getResources().getString(android.R.string.ok), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + } + }) + .create(); + + dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + if (!mContext.getResources().getBoolean( + com.android.internal.R.bool.config_sf_slowBlur)) { + dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); + } + + dialog.show(); + } + private String getItemName(int itemId) { Menu menu = mCurrentCmd.getMenu(); if (menu == null) { -- cgit v1.1