/**
   * Only used for header binding.
   *
   * @param message the message contents to bind
   */
  public void bind(CellBroadcastMessage message, boolean bSelected, boolean bRead) {
    mCbMessage = message;
    int backgroundId;
    if (bSelected) {
      backgroundId = R.drawable.list_selected_holo_light;
    } else {
      backgroundId =
          message.isRead()
              ? R.drawable.list_item_background_read
              : R.drawable.list_item_background_unread;
    }
    Drawable background = getResources().getDrawable(backgroundId);
    setBackground(background);

    mChannelView.setText(CellBroadcastResources.getDialogTitleResource(message));
    String time = message.getDateString(getContext());
    String splitStr[] = time.split(",");
    if (splitStr != null && splitStr.length == 3) {
      time = time.substring(time.indexOf(",") + 2);
    }
    Log.d("CellBroadcastListItem", "time = " + time);
    mDateView.setText(time);
    mMessageView.setText(message.getMessageBody());
    if (!bRead) {
      mPresenceView.setVisibility(View.VISIBLE);
    } else {
      mPresenceView.setVisibility(View.GONE);
    }
  }
  private static CharSequence formatMessage(CellBroadcastMessage message) {
    String body = message.getMessageBody();

    SpannableStringBuilder buf = new SpannableStringBuilder(body);

    // Unread messages are shown in bold
    if (!message.isRead()) {
      buf.setSpan(
          new StyleSpan(Typeface.BOLD), 0, buf.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return buf;
  }
示例#3
0
 @Override
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   if (CB_AREA_INFO_RECEIVED_ACTION.equals(action)) {
     Bundle extras = intent.getExtras();
     if (extras == null) {
       return;
     }
     CellBroadcastMessage cbMessage = (CellBroadcastMessage) extras.get("message");
     if (cbMessage != null && cbMessage.getServiceCategory() == 50) {
       String latestAreaInfo = cbMessage.getMessageBody();
       updateAreaInfo(latestAreaInfo);
     }
   }
 }
 @Override
 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
   // Speak the date first, then channel name, then message body
   event.getText().add(mCbMessage.getSpokenDateString(getContext()));
   mChannelView.dispatchPopulateAccessibilityEvent(event);
   mMessageView.dispatchPopulateAccessibilityEvent(event);
   return true;
 }
  /**
   * Internal method to insert a new Cell Broadcast into the database and notify observers.
   *
   * @param message the message to insert
   * @return true if the database was updated, false otherwise
   */
  boolean insertNewBroadcast(CellBroadcastMessage message) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    ContentValues cv = message.getContentValues();

    long rowId = db.insert(CellBroadcastDatabaseHelper.TABLE_NAME, null, cv);
    if (rowId != -1) {
      return true;
    } else {
      Log.e(TAG, "failed to insert new broadcast into database");
      return false;
    }
  }