summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorJake Hamby <jhamby@google.com>2012-08-27 12:30:35 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-08-27 12:30:35 -0700
commitc945c45175e820946c0ad5cb5f77e464828a85da (patch)
tree1439986a08a76edfbd20386ca9fe98c6d0778de5 /src/com/android
parent500f2c6529ebb7f7a5c33fbfbc1742a1d9fd07a9 (diff)
parenta93243d13ef0c0b29d871d483642e39c01db7c26 (diff)
downloadandroid_packages_apps_CellBroadcastReceiver-c945c45175e820946c0ad5cb5f77e464828a85da.tar.gz
android_packages_apps_CellBroadcastReceiver-c945c45175e820946c0ad5cb5f77e464828a85da.tar.bz2
android_packages_apps_CellBroadcastReceiver-c945c45175e820946c0ad5cb5f77e464828a85da.zip
am a93243d1: Add "View details" context menu to CMAS alert list view.
* commit 'a93243d13ef0c0b29d871d483642e39c01db7c26': Add "View details" context menu to CMAS alert list view.
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java3
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java18
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java5
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastResources.java106
4 files changed, 78 insertions, 54 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java
index 641fad21..a8337f30 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java
@@ -132,8 +132,7 @@ public class CellBroadcastAlertFullScreen extends Activity {
int titleId = CellBroadcastResources.getDialogTitleResource(message);
setTitle(titleId);
((TextView) findViewById(R.id.alertTitle)).setText(titleId);
- ((TextView) findViewById(R.id.message)).setText(
- CellBroadcastResources.getFormattedMessageBody(this, message));
+ ((TextView) findViewById(R.id.message)).setText(message.getMessageBody());
/* dismiss button: close notification */
findViewById(R.id.dismissButton).setOnClickListener(
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java b/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java
index 20875b61..112cb92a 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java
@@ -79,7 +79,7 @@ public class CellBroadcastListActivity extends Activity {
// IDs of the context menu items (package local, accessed from inner DeleteThreadListener).
static final int MENU_DELETE = 0;
- static final int MENU_VIEW = 1;
+ static final int MENU_VIEW_DETAILS = 1;
// This is the Adapter being used to display the list's data.
CursorAdapter mAdapter;
@@ -163,13 +163,23 @@ public class CellBroadcastListActivity extends Activity {
startActivity(i);
}
+ private void showBroadcastDetails(CellBroadcastMessage cbm) {
+ // show dialog with delivery date/time and alert details
+ CharSequence details = CellBroadcastResources.getMessageDetails(getActivity(), cbm);
+ new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.view_details_title)
+ .setMessage(details)
+ .setCancelable(true)
+ .show();
+ }
+
private final OnCreateContextMenuListener mOnCreateContextMenuListener =
new OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle(R.string.message_options);
- menu.add(0, MENU_VIEW, 0, R.string.menu_view);
+ menu.add(0, MENU_VIEW_DETAILS, 0, R.string.menu_view_details);
menu.add(0, MENU_DELETE, 0, R.string.menu_delete);
}
};
@@ -187,8 +197,8 @@ public class CellBroadcastListActivity extends Activity {
Telephony.CellBroadcasts._ID)), isUnread);
break;
- case MENU_VIEW:
- showDialogAndMarkRead(CellBroadcastMessage.createFromCursor(cursor));
+ case MENU_VIEW_DETAILS:
+ showBroadcastDetails(CellBroadcastMessage.createFromCursor(cursor));
break;
default:
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java b/src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java
index 1f7da32a..7db5fd2a 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastListItem.java
@@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable;
import android.telephony.CellBroadcastMessage;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
+import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityEvent;
import android.widget.RelativeLayout;
@@ -80,8 +81,8 @@ public class CellBroadcastListItem extends RelativeLayout {
// Unread messages are shown in bold
if (!message.isRead()) {
- buf.setSpan(Typeface.DEFAULT_BOLD, 0, buf.length(),
- Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+ buf.setSpan(new StyleSpan(Typeface.BOLD), 0, buf.length(),
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return buf;
}
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastResources.java b/src/com/android/cellbroadcastreceiver/CellBroadcastResources.java
index fc4b2d16..fedd1533 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastResources.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastResources.java
@@ -23,70 +23,84 @@ import android.telephony.SmsCbCmasInfo;
import android.telephony.SmsCbEtwsInfo;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
+import android.text.style.StyleSpan;
/**
* Returns the string resource ID's for CMAS and ETWS emergency alerts.
*/
public class CellBroadcastResources {
+ private CellBroadcastResources() {
+ }
+
/**
- * Returns a styled CharSequence containing the message body and optional CMAS alert headers.
+ * Returns a styled CharSequence containing the message date/time and alert details.
* @param context a Context for resource string access
* @return a CharSequence for display in the broadcast alert dialog
*/
- public static CharSequence getFormattedMessageBody(Context context, CellBroadcastMessage cbm) {
+ public static CharSequence getMessageDetails(Context context, CellBroadcastMessage cbm) {
+ SpannableStringBuilder buf = new SpannableStringBuilder();
+
+ // Alert date/time
+ int start = buf.length();
+ buf.append(context.getString(R.string.delivery_time_heading));
+ int end = buf.length();
+ buf.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ buf.append(" ");
+ buf.append(cbm.getDateString(context));
+
if (cbm.isCmasMessage()) {
- SmsCbCmasInfo cmasInfo = cbm.getCmasWarningInfo();
- SpannableStringBuilder buf = new SpannableStringBuilder();
-
- // CMAS category
- int categoryId = getCmasCategoryResId(cmasInfo);
- if (categoryId != 0) {
- buf.append(context.getText(R.string.cmas_category_heading));
- buf.append(context.getText(categoryId));
- buf.append('\n');
- }
+ // CMAS category, response type, severity, urgency, certainty
+ appendCmasAlertDetails(context, buf, cbm.getCmasWarningInfo());
+ }
- // CMAS response type
- int responseId = getCmasResponseResId(cmasInfo);
- if (responseId != 0) {
- buf.append(context.getText(R.string.cmas_response_heading));
- buf.append(context.getText(responseId));
- buf.append('\n');
- }
+ return buf;
+ }
- // CMAS severity
- int severityId = getCmasSeverityResId(cmasInfo);
- if (severityId != 0) {
- buf.append(context.getText(R.string.cmas_severity_heading));
- buf.append(context.getText(severityId));
- buf.append('\n');
- }
+ private static void appendCmasAlertDetails(Context context, SpannableStringBuilder buf,
+ SmsCbCmasInfo cmasInfo) {
+ // CMAS category
+ int categoryId = getCmasCategoryResId(cmasInfo);
+ if (categoryId != 0) {
+ appendMessageDetail(context, buf, R.string.cmas_category_heading, categoryId);
+ }
- // CMAS urgency
- int urgencyId = getCmasUrgencyResId(cmasInfo);
- if (urgencyId != 0) {
- buf.append(context.getText(R.string.cmas_urgency_heading));
- buf.append(context.getText(urgencyId));
- buf.append('\n');
- }
+ // CMAS response type
+ int responseId = getCmasResponseResId(cmasInfo);
+ if (responseId != 0) {
+ appendMessageDetail(context, buf, R.string.cmas_response_heading, responseId);
+ }
- // CMAS certainty
- int certaintyId = getCmasCertaintyResId(cmasInfo);
- if (certaintyId != 0) {
- buf.append(context.getText(R.string.cmas_certainty_heading));
- buf.append(context.getText(certaintyId));
- buf.append('\n');
- }
+ // CMAS severity
+ int severityId = getCmasSeverityResId(cmasInfo);
+ if (severityId != 0) {
+ appendMessageDetail(context, buf, R.string.cmas_severity_heading, severityId);
+ }
- // Style all headings in bold
- buf.setSpan(Typeface.DEFAULT_BOLD, 0, buf.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+ // CMAS urgency
+ int urgencyId = getCmasUrgencyResId(cmasInfo);
+ if (urgencyId != 0) {
+ appendMessageDetail(context, buf, R.string.cmas_urgency_heading, urgencyId);
+ }
- buf.append(cbm.getMessageBody());
- return buf;
- } else {
- return cbm.getMessageBody();
+ // CMAS certainty
+ int certaintyId = getCmasCertaintyResId(cmasInfo);
+ if (certaintyId != 0) {
+ appendMessageDetail(context, buf, R.string.cmas_certainty_heading, certaintyId);
+ }
+ }
+
+ private static void appendMessageDetail(Context context, SpannableStringBuilder buf,
+ int typeId, int valueId) {
+ if (buf.length() != 0) {
+ buf.append("\n");
}
+ int start = buf.length();
+ buf.append(context.getString(typeId));
+ int end = buf.length();
+ buf.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ buf.append(" ");
+ buf.append(context.getString(valueId));
}
/**