Exemplo n.º 1
0
  /**
   * Sets the image of the attachment view.
   *
   * @param imageBitmap the bitmap
   */
  public void setAttachment(Bitmap imageBitmap) {
    if (imageBitmap == null) {
      clearAttachment();
    } else {
      AnalyticsManager.getInstance()
          .sendEvent(
              AnalyticsManager.CATEGORY_MESSAGES, AnalyticsManager.ACTION_ATTACH_IMAGE, mLabel);

      mAttachment.setImageBitmap(imageBitmap);
      mAttachmentLayout.setVisibility(View.VISIBLE);
      updateButtonState();
    }
  }
Exemplo n.º 2
0
  /**
   * Sets the button image based on the length of the reply text, and whether or not the drawable is
   * set.
   */
  private void updateButtonState(int length) {
    SendButtonState buttonState;

    if (mAttachmentPanel.getVisibility() == View.VISIBLE) {
      buttonState = SendButtonState.CLOSE;
    } else if (length > 0 || mAttachment.hasAttachment()) {
      buttonState = SendButtonState.SEND;
    } else {
      buttonState = SendButtonState.ATTACH;
    }

    updateButtonState(buttonState);
  }
Exemplo n.º 3
0
  private void handleComposeButtonClick() {
    switch (mButtonState) {
      case ATTACH:
        mAttachmentPanel.setVisibility(VISIBLE);
        updateButtonState();
        break;

      case SEND:
        // If the API version is less than KitKat, they can send an SMS; so do this.
        if (Build.VERSION.SDK_INT < 19) {
          if (mDelayedMessagingEnabled) {
            sendDelayedSms();
          } else {
            sendSms();
          }
        } else {
          // Otherwise... check if we're not the default SMS app
          boolean isDefaultSmsApp = Utils.isDefaultSmsApp(mContext);

          // Now make sure that a client hasn't blocked sending, i.e. in the welcome
          // screen when we have a demo conversation.
          if (mIsSendingBlocked) {
            // Show the sending blocked message (if it exists)
            Toast.makeText(mContext, mSendingBlockedMessage, Toast.LENGTH_SHORT).show();

          } else if (!isDefaultSmsApp) {
            // Ask to become the default SMS app
            new DefaultSmsHelper(mContext, R.string.not_default_send).showIfNotDefault(this);

          } else if (!TextUtils.isEmpty(mReplyText.getText()) || mAttachment.hasAttachment()) {
            if (mDelayedMessagingEnabled) {
              sendDelayedSms();
            } else {
              sendSms();
            }
          }
        }
        break;

      case CLOSE:
        mAttachmentPanel.setVisibility(GONE);
        updateButtonState();
        break;

      case CANCEL:
        mSendingCancelled = true;
        mProgressAnimator.end();
        // updateButtonState();
        break;
    }
  }
Exemplo n.º 4
0
 /** Clears the image from the attachment view. */
 public void clearAttachment() {
   mAttachment.setImageBitmap(null);
   mAttachmentLayout.setVisibility(View.GONE);
   updateButtonState();
 }
Exemplo n.º 5
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();
    }
  }