예제 #1
0
 @Override
 protected void onStart() {
   super.onStart();
   // Only mark screen if the screen is on. onStart() is still called if the app is in the
   // foreground and the screen is off
   // TODO this solution doesn't work if the activity is in the foreground but the lockscreen is on
   if (isScreenOn()) {
     SmsHelper.markSmsSeen(this);
     SmsHelper.markMmsSeen(this);
     NotificationManager.update(this);
   }
 }
예제 #2
0
    @Override
    protected Void doInBackground(Uri... params) {

      if (params.length < 1) {
        Log.e(TAG, "ImageLoaderTask called with no Uri");
        return null;
      }

      try {
        Uri uri = params[0];

        // Decode the image from the Uri into a bitmap [1], and shrink it
        // according to the user's settings.
        // [1]:
        // http://stackoverflow.com/questions/13930009/how-can-i-get-an-image-from-another-application
        InputStream inputStream = mContext.getContentResolver().openInputStream(uri);
        Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

        long maxAttachmentSize = SmsHelper.getSendSettings(mContext).getMaxAttachmentSize();
        bitmap = ImageUtils.shrink(bitmap, 90, maxAttachmentSize);

        // Now, rotation the bitmap according to the Exif data.
        final int rotation = ImageUtils.getOrientation(mContext, uri);
        Matrix matrix = new Matrix();
        matrix.postRotate(rotation);
        bitmap =
            Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

        // Can't post UI updates on a background thread.
        final Bitmap imageBitmap = bitmap;
        mHandler.post(
            new Runnable() {
              @Override
              public void run() {
                setAttachment(imageBitmap);
              }
            });

      } catch (FileNotFoundException | NullPointerException e) {
        // Make a toast to the user that the file they've requested to view
        // isn't available.
        mHandler.post(
            new Runnable() {
              @Override
              public void run() {
                Toast.makeText(
                        mContext, mRes.getString(R.string.error_file_not_found), Toast.LENGTH_SHORT)
                    .show();
              }
            });
      }
      return null;
    }
예제 #3
0
  public static Intent createAddContactIntent(String address) {
    // address must be a single recipient
    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
    if (SmsHelper.isEmailAddress(address)) {
      intent.putExtra(ContactsContract.Intents.Insert.EMAIL, address);
    } else {
      intent.putExtra(ContactsContract.Intents.Insert.PHONE, address);
      intent.putExtra(
          ContactsContract.Intents.Insert.PHONE_TYPE,
          ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE);
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    return intent;
  }
예제 #4
0
  public void sendSms() {
    String body = mReplyText.getText().toString();

    final Drawable attachment;
    if (mAttachment.hasAttachment()) {
      attachment = mAttachment.getDrawable();
    } else {
      attachment = null;
    }
    clearAttachment();

    String[] recipients = null;
    if (mConversation != null) {
      recipients = mConversation.getRecipients().getNumbers();
      for (int i = 0; i < recipients.length; i++) {
        recipients[i] = PhoneNumberUtils.stripSeparators(recipients[i]);
      }
    } else if (mRecipientProvider != null) {
      recipients = mRecipientProvider.getRecipientAddresses();
    }

    // If we have some recipients, send the message!
    if (recipients != null && recipients.length > 0) {
      mReplyText.setText("");

      AnalyticsManager.getInstance()
          .sendEvent(
              AnalyticsManager.CATEGORY_MESSAGES, AnalyticsManager.ACTION_SEND_MESSAGE, mLabel);

      Transaction sendTransaction = new Transaction(mContext, SmsHelper.getSendSettings(mContext));

      com.moez.QKSMS.mmssms.Message message = new com.moez.QKSMS.mmssms.Message(body, recipients);
      message.setType(com.moez.QKSMS.mmssms.Message.TYPE_SMSMMS);
      if (attachment != null) {
        message.setImage(ImageUtils.drawableToBitmap(attachment));
      }

      // Notify the listener about the new text message
      if (mOnSendListener != null) {
        mOnSendListener.onSend(recipients, message.getSubject());
      }

      long threadId = mConversation != null ? mConversation.getThreadId() : 0;
      if (!message.toString().equals("")) {
        sendTransaction.sendNewMessage(message, threadId);
      }
      NotificationManager.update(mContext);

      if (mConversationLegacy != null) {
        mConversationLegacy.markRead();
      }

      // Reset the image button state
      updateButtonState();

      // Otherwise, show a toast to the user to prompt them to add recipients.
    } else {
      Toast.makeText(mContext, mRes.getString(R.string.error_no_recipients), Toast.LENGTH_SHORT)
          .show();
    }
  }
예제 #5
0
    public void onItemLoaded(Object result, Throwable exception) {
      if (exception != null) {
        Log.e(TAG, "PduLoadedMessageItemCallback PDU couldn't be loaded: ", exception);
        return;
      }
      if (mItemLoadedFuture != null) {
        synchronized (mItemLoadedFuture) {
          mItemLoadedFuture.setIsDone(true);
        }
      }
      PduLoaderManager.PduLoaded pduLoaded = (PduLoaderManager.PduLoaded) result;
      long timestamp = 0L;
      if (PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND == mMessageType) {
        mDeliveryStatus = DeliveryStatus.NONE;
        NotificationInd notifInd = (NotificationInd) pduLoaded.mPdu;
        interpretFrom(notifInd.getFrom(), mMessageUri);
        // Borrow the mBody to hold the URL of the message.
        mBody = new String(notifInd.getContentLocation());
        mMessageSize = (int) notifInd.getMessageSize();
        timestamp = notifInd.getExpiry() * 1000L;
      } else {
        MultimediaMessagePdu msg = (MultimediaMessagePdu) pduLoaded.mPdu;
        mSlideshow = pduLoaded.mSlideshow;
        mAttachmentType = SmsHelper.getAttachmentType(mSlideshow, msg);

        if (mMessageType == PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF) {
          if (msg == null) {
            interpretFrom(null, mMessageUri);
          } else {
            RetrieveConf retrieveConf = (RetrieveConf) msg;
            interpretFrom(retrieveConf.getFrom(), mMessageUri);
            timestamp = retrieveConf.getDate() * 1000L;
          }
        } else {
          // Use constant string for outgoing messages
          mContact = mAddress = mContext.getString(R.string.messagelist_sender_self);
          timestamp = msg == null ? 0 : msg.getDate() * 1000L;
        }

        SlideModel slide = mSlideshow == null ? null : mSlideshow.get(0);
        if ((slide != null) && slide.hasText()) {
          TextModel tm = slide.getText();
          mBody = tm.getText();
          mTextContentType = tm.getContentType();
        }

        mMessageSize = mSlideshow == null ? 0 : mSlideshow.getTotalMessageSize();

        mDeliveryStatus = getDeliveryStatus(mDeliveryStatusString);
        mReadReport = getReadReport(mReadReportString);
      }
      if (!isOutgoingMessage()) {
        if (PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND == mMessageType) {
          mTimestamp =
              mContext.getString(
                  R.string.expire_on, DateFormatter.getMessageTimestamp(mContext, timestamp));
        } else {
          mTimestamp = DateFormatter.getMessageTimestamp(mContext, timestamp);
        }
      }
      if (mPduLoadedCallback != null) {
        mPduLoadedCallback.onPduLoaded(MessageItem.this);
      }
    }
예제 #6
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);
    }
  }