Пример #1
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;
    }
Пример #2
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();
    }
  }