Exemple #1
0
  private void attachFromCamera() {

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

    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (cameraIntent.resolveActivity(mContext.getPackageManager()) != null) {

      File file = null;
      try {
        file = createImageFile();
      } catch (IOException e) {
        e.printStackTrace();
      }

      if (file != null) {
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
        mActivityLauncher.startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA);
      }
    } else {
      // Send a toast saying there was a camera error
      if (mContext != null) {
        String message = mContext.getResources().getString(R.string.attachment_camera_error);
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
      }
    }
  }
Exemple #2
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();
    }
  }
Exemple #3
0
  private void chooseAttachmentFromGallery() {

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

    try {
      Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
      photoPickerIntent.setType("image/*");
      mActivityLauncher.startActivityForResult(photoPickerIntent, REQUEST_CODE_IMAGE);
    } catch (ActivityNotFoundException e) {
      // Send a toast saying no picture apps
      if (mContext != null) {
        String message = mContext.getResources().getString(R.string.attachment_app_not_found);
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
      }
    }
  }
Exemple #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();
    }
  }