예제 #1
0
  // Prepare notification data and display it.
  private void doNotification(Context context, Long messageId, Bitmap srcPhoto) {

    ChatMsgBaseInfo message = WalkArroundMsgManager.getInstance(context).getMessageById(messageId);

    if (message == null) {
      return;
    }

    ContactInfo contact =
        ContactsManager.getInstance(context).getContactByUsrObjId(message.getContact());

    Intent intent = new Intent();
    intent.setClass(context.getApplicationContext(), BuildMessageActivity.class);
    intent.putExtra(BuildMessageActivity.INTENT_RECEIVER_EDITABLE, false);
    intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_RECEIVER, message.getContact());
    intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_THREAD_ID, message.getMsgThreadId());
    intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_TYPE, message.getChatType());

    // TODO: contact should write to DB & we should crate a content provider for those contacts.
    if (contact != null) {
      intent.putExtra(BuildMessageActivity.INTENT_CONVERSATION_DISPLAY_NAME, contact.getUsername());
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, (int) message.getMsgThreadId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // If the contact is null, set the user name as empty.
    String displayName = (contact == null ? "" : contact.getUsername());
    message.setData(MessageUtil.getDisplayStr(context, displayName, message));
    Notification notification = new Notification();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.icon = R.drawable.msg_notify_icon;

    // TODO: Add Emoji parser later.
    notification.tickerText = EmojiParser.getInstance(context).getSmileyText(message.getData());
    notification.tickerText = message.getData();

    if (Build.VERSION.SDK_INT == 19) {
      contentIntent.cancel();
      contentIntent =
          PendingIntent.getActivity(
              context, (int) message.getMsgThreadId(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }
    notification.contentIntent = contentIntent;
    notification.contentView = new RemoteViews(context.getPackageName(), R.layout.msg_notify_panel);
    //        notification.defaults=Notification.DEFAULT_SOUND;
    initNotifyView(context, notification.contentView, message, contact, srcPhoto);
    try {
      String number = (contact == null ? DEFAULT_NOTIFICATION_ID : contact.getMobilePhoneNumber());
      int startPos = number.length() > 5 ? number.length() - 5 : 0;
      int id = Integer.parseInt(number.substring(startPos));
      NotificationManager manager =
          (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      manager.notify(number, id, notification);
    } catch (NumberFormatException e) {
      sLogger.e("notification NumberFormatException:" + e.getMessage());
    }
  }
예제 #2
0
  // Init notification UI.
  private void initNotifyView(
      Context context,
      RemoteViews panelView,
      ChatMsgBaseInfo message,
      ContactInfo contact,
      Bitmap srcPhoto) {
    if (contact != null) {
      Bitmap photo = ImageLoaderManager.createCircleImage(srcPhoto);
      if (photo != null) {
        panelView.setViewVisibility(R.id.notify_profile_logogram_tv, View.GONE);
        panelView.setViewVisibility(R.id.notify_profile_iv, View.VISIBLE);
        panelView.setImageViewBitmap(R.id.notify_profile_iv, photo);
      } else {
        panelView.setViewVisibility(R.id.notify_profile_iv, View.VISIBLE);
        panelView.setImageViewResource(
            R.id.notify_profile_iv, CommonUtils.getPhotoBgResId(contact.getUsername()));
        panelView.setViewVisibility(R.id.notify_profile_logogram_tv, View.VISIBLE);
        panelView.setTextViewText(
            R.id.notify_profile_logogram_tv,
            contact.getUsername().substring(contact.getUsername().length() - 1));
      }
      panelView.setTextViewText(R.id.notify_sender_tv, contact.getUsername());
    } else {
      panelView.setTextViewText(R.id.notify_sender_tv, message.getContact());
      panelView.setViewVisibility(R.id.notify_profile_logogram_tv, View.GONE);
      panelView.setViewVisibility(R.id.notify_profile_iv, View.VISIBLE);
      panelView.setImageViewResource(R.id.notify_profile_iv, R.drawable.contact_default_profile);
    }

    // TODO: ADD Emoji parser later.
    // panelView.setTextViewText(R.id.notify_msg_content_tv,
    // EmojiParser.getInstance(context).getSmileyText(message.getData()));
    panelView.setTextViewText(R.id.notify_msg_content_tv, message.getData());
    panelView.setTextViewText(
        R.id.notify_time_tv, TimeFormattedUtil.getDetailDisplayTime(context, message.getTime()));
  }