private void populateContextMenu(ContextMenu menu) {
   final Message m = this.selectedMessage;
   if (m.getType() != Message.TYPE_STATUS) {
     activity.getMenuInflater().inflate(R.menu.message_context, menu);
     menu.setHeaderTitle(R.string.message_options);
     MenuItem copyText = menu.findItem(R.id.copy_text);
     MenuItem shareWith = menu.findItem(R.id.share_with);
     MenuItem sendAgain = menu.findItem(R.id.send_again);
     MenuItem copyUrl = menu.findItem(R.id.copy_url);
     MenuItem downloadFile = menu.findItem(R.id.download_file);
     MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
     if ((m.getType() == Message.TYPE_TEXT || m.getType() == Message.TYPE_PRIVATE)
         && m.getTransferable() == null
         && !GeoHelper.isGeoUri(m.getBody())
         && m.treatAsDownloadable() != Message.Decision.MUST) {
       copyText.setVisible(true);
     }
     if ((m.getType() != Message.TYPE_TEXT
             && m.getType() != Message.TYPE_PRIVATE
             && m.getTransferable() == null)
         || (GeoHelper.isGeoUri(m.getBody()))) {
       shareWith.setVisible(true);
     }
     if (m.getStatus() == Message.STATUS_SEND_FAILED) {
       sendAgain.setVisible(true);
     }
     if (m.hasFileOnRemoteHost()
         || GeoHelper.isGeoUri(m.getBody())
         || m.treatAsDownloadable() == Message.Decision.MUST) {
       copyUrl.setVisible(true);
     }
     if (m.getType() == Message.TYPE_TEXT
         && m.getTransferable() == null
         && m.treatAsDownloadable() != Message.Decision.NEVER) {
       downloadFile.setVisible(true);
       downloadFile.setTitle(
           activity.getString(
               R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
     }
     if ((m.getTransferable() != null && !(m.getTransferable() instanceof TransferablePlaceholder))
         || (m.isFileOrImage()
             && (m.getStatus() == Message.STATUS_WAITING
                 || m.getStatus() == Message.STATUS_OFFERED))) {
       cancelTransmission.setVisible(true);
     }
   }
 }
 private void copyUrl(Message message) {
   final String url;
   final int resId;
   if (GeoHelper.isGeoUri(message.getBody())) {
     resId = R.string.location;
     url = message.getBody();
   } else if (message.hasFileOnRemoteHost()) {
     resId = R.string.file_url;
     url = message.getFileParams().url.toString();
   } else {
     url = message.getBody().trim();
     resId = R.string.file_url;
   }
   if (activity.copyTextToClipboard(url, resId)) {
     Toast.makeText(activity, R.string.url_copied_to_clipboard, Toast.LENGTH_SHORT).show();
   }
 }
Exemplo n.º 3
0
 public Message findSentMessageWithBody(String body) {
   synchronized (this.messages) {
     for (int i = this.messages.size() - 1; i >= 0; --i) {
       Message message = this.messages.get(i);
       if (message.getStatus() == Message.STATUS_UNSEND
           || message.getStatus() == Message.STATUS_SEND) {
         String otherBody;
         if (message.hasFileOnRemoteHost()) {
           otherBody = message.getFileParams().url.toString();
         } else {
           otherBody = message.body;
         }
         if (otherBody != null && otherBody.equals(body)) {
           return message;
         }
       }
     }
     return null;
   }
 }
Exemplo n.º 4
0
  @Nullable
  public XmppAxolotlMessage encrypt(Message message) {
    XmppAxolotlMessage axolotlMessage = buildHeader(message.getContact());

    if (axolotlMessage != null) {
      final String content;
      if (message.hasFileOnRemoteHost()) {
        content = message.getFileParams().url.toString();
      } else {
        content = message.getBody();
      }
      try {
        axolotlMessage.encrypt(content);
      } catch (CryptoFailedException e) {
        Log.w(
            Config.LOGTAG, getLogprefix(account) + "Failed to encrypt message: " + e.getMessage());
        return null;
      }
    }

    return axolotlMessage;
  }