@Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mCursor = data;
    mFavorites.removeAllViews();

    LayoutInflater inflater = LayoutInflater.from(mContext);

    if (data.moveToFirst()) {
      do {
        // only add them to the favorites list if they have a phone number
        if (mCursor.getInt(ContactHelper.Favorites.HAS_PHONE_NUMBER) > 0) {

          final String photoUri = mCursor.getString(ContactHelper.Favorites.PHOTO_THUMBNAIL_URI);
          final Contact contact =
              Contact.get(
                  ContactHelper.getPhoneNumber(
                      mContext, mCursor.getString(ContactHelper.Favorites.ID)),
                  true);

          final View.OnClickListener onClickListener =
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  collapse();
                  mRecipients.submitItem(
                      contact.getName(),
                      contact.getNumber(),
                      photoUri == null ? null : Uri.parse(photoUri));
                  mComposeView.requestReplyTextFocus();
                }
              };

          View view = inflater.inflate(R.layout.view_favorite_contact, null);
          view.setOnClickListener(onClickListener);

          AvatarView avatar = (AvatarView) view.findViewById(R.id.avatar);
          avatar.setOnClickListener(onClickListener);
          avatar.setImageDrawable(contact.getAvatar(mContext, null));
          avatar.setContactName(contact.getName());

          QKTextView name = (QKTextView) view.findViewById(R.id.name);
          name.setOnClickListener(onClickListener);
          name.setText(contact.getName());

          mFavorites.addView(view);
        }
      } while (data.moveToNext());
    }

    if (mFavorites.getChildCount() > 0) {
      mFavoritesBackground.setVisibility(View.VISIBLE);
    }
  }
Example #2
0
 private void interpretFrom(EncodedStringValue from, Uri messageUri) {
   if (from != null) {
     mAddress = from.getString();
   } else {
     // In the rare case when getting the "from" address from the pdu fails,
     // (e.g. from == null) fall back to a slower, yet more reliable method of
     // getting the address from the "addr" table. This is what the Messaging
     // notification system uses.
     mAddress = AddressUtils.getFrom(mContext, messageUri);
   }
   mContact = TextUtils.isEmpty(mAddress) ? "" : Contact.get(mAddress, false).getName();
 }
Example #3
0
  @SuppressLint("NewApi")
  public MessageItem(
      Context context,
      String type,
      final Cursor cursor,
      final MessageColumns.ColumnsMap columnsMap,
      Pattern highlight,
      boolean canBlock)
      throws MmsException {
    mContext = context;
    mMsgId = cursor.getLong(columnsMap.mColumnMsgId);
    mHighlight = highlight;
    mType = type;
    mColumnsMap = columnsMap;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);

    if ("sms".equals(type)) {
      mReadReport = false; // No read reports in sms

      long status = cursor.getLong(columnsMap.mColumnSmsStatus);
      if (status == Sms.STATUS_NONE) {
        // No delivery report requested
        mDeliveryStatus = DeliveryStatus.NONE;
      } else if (status >= Sms.STATUS_FAILED) {
        // Failure
        mDeliveryStatus = DeliveryStatus.FAILED;
      } else if (status >= Sms.STATUS_PENDING) {
        // Pending
        mDeliveryStatus = DeliveryStatus.PENDING;
      } else {
        // Success
        mDeliveryStatus = DeliveryStatus.RECEIVED;
      }

      mMessageUri = ContentUris.withAppendedId(Sms.CONTENT_URI, mMsgId);
      // Set contact and message body
      mBoxId = cursor.getInt(columnsMap.mColumnSmsType);
      mAddress = cursor.getString(columnsMap.mColumnSmsAddress);
      if (SmsHelper.isOutgoingFolder(mBoxId)) {
        String meString = context.getString(R.string.messagelist_sender_self);

        mContact = meString;
      } else {
        // For incoming messages, the ADDRESS field contains the sender.
        mContact = Contact.get(mAddress, canBlock).getName();
      }
      mBody = cursor.getString(columnsMap.mColumnSmsBody);
      mBody = FormatterFactory.format(mBody);

      // Unless the message is currently in the progress of being sent, it gets a time stamp.
      if (!isOutgoingMessage()) {
        // Set "received" or "sent" time stamp
        boolean sent = prefs.getBoolean(QKPreference.SENT_TIMESTAMPS.getKey(), false) && !isMe();
        mDate = cursor.getLong(sent ? columnsMap.mColumnSmsDateSent : columnsMap.mColumnSmsDate);
        mTimestamp = DateFormatter.getMessageTimestamp(context, mDate);
      }

      mLocked = cursor.getInt(columnsMap.mColumnSmsLocked) != 0;
      mErrorCode = cursor.getInt(columnsMap.mColumnSmsErrorCode);
    } else if ("mms".equals(type)) {
      mMessageUri = ContentUris.withAppendedId(Mms.CONTENT_URI, mMsgId);
      mBoxId = cursor.getInt(columnsMap.mColumnMmsMessageBox);
      // If we can block, get the address immediately from the "addr" table.
      if (canBlock) {
        mAddress = AddressUtils.getFrom(mContext, mMessageUri);
      }
      mMessageType = cursor.getInt(columnsMap.mColumnMmsMessageType);
      mErrorType = cursor.getInt(columnsMap.mColumnMmsErrorType);
      String subject = cursor.getString(columnsMap.mColumnMmsSubject);
      if (!TextUtils.isEmpty(subject)) {
        EncodedStringValue v =
            new EncodedStringValue(
                cursor.getInt(columnsMap.mColumnMmsSubjectCharset), PduPersister.getBytes(subject));
        mSubject = SmsHelper.cleanseMmsSubject(context, v.getString());
      }
      mLocked = cursor.getInt(columnsMap.mColumnMmsLocked) != 0;
      mSlideshow = null;
      mDeliveryStatusString = cursor.getString(columnsMap.mColumnMmsDeliveryReport);
      mReadReportString = cursor.getString(columnsMap.mColumnMmsReadReport);
      mBody = null;
      mMessageSize = 0;
      mTextContentType = null;
      // Initialize the time stamp to "" instead of null
      mTimestamp = "";
      mMmsStatus = cursor.getInt(columnsMap.mColumnMmsStatus);
      mAttachmentType =
          cursor.getInt(columnsMap.mColumnMmsTextOnly) != 0
              ? SmsHelper.TEXT
              : ATTACHMENT_TYPE_NOT_LOADED;

      // Start an async load of the pdu. If the pdu is already loaded, the callback
      // will get called immediately
      boolean loadSlideshow = mMessageType != PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND;

      mItemLoadedFuture =
          QKSMSApp.getApplication()
              .getPduLoaderManager()
              .getPdu(mMessageUri, loadSlideshow, new PduLoadedMessageItemCallback());

    } else {
      throw new MmsException("Unknown type of the message: " + type);
    }
  }