Esempio n. 1
0
  /**
   * Translates Content ID urls (CID urls) into provider queries for the associated attachment. With
   * the attachment in hand, it's trivial to open a stream to the file containing the content of the
   * attachment.
   *
   * @param uri the raw URI from the HTML document in the Webview
   * @param message the message containing the HTML that is being rendered
   * @return a response if a stream to the attachment file can be created from the CID URL;
   *     <tt>null</tt> if it cannot for any reason
   */
  protected final WebResourceResponse loadCIDUri(Uri uri, ConversationMessage message) {
    // if the url is not a CID url, we do nothing
    if (!"cid".equals(uri.getScheme())) {
      return null;
    }

    // cid urls can be translated to content urls
    final String cid = uri.getSchemeSpecificPart();
    if (cid == null) {
      return null;
    }

    if (message.attachmentByCidUri == null) {
      return null;
    }

    final Uri queryUri = Uri.withAppendedPath(message.attachmentByCidUri, cid);
    if (queryUri == null) {
      return null;
    }

    // query for the attachment using its cid
    final ContentResolver cr = getActivity().getContentResolver();
    final Cursor c = cr.query(queryUri, UIProvider.ATTACHMENT_PROJECTION, null, null, null);
    if (c == null) {
      return null;
    }

    // create the attachment from the cursor, if one was found
    final Attachment target;
    try {
      if (!c.moveToFirst()) {
        return null;
      }
      target = new Attachment(c);
    } finally {
      c.close();
    }

    // try to return a response that includes a stream to the attachment data
    try {
      final ParcelFileDescriptor fd = cr.openFileDescriptor(target.contentUri, "r");
      final InputStream stream = new FileInputStream(fd.getFileDescriptor());
      return new WebResourceResponse(target.getContentType(), null, stream);
    } catch (FileNotFoundException e) {
      // if no attachment file was found return null to let webview handle it
      return null;
    }
  }
 public void render(Attachment paramAttachment, boolean paramBoolean) {
   Attachment localAttachment = this.mAttachment;
   this.mAttachment = paramAttachment;
   this.mActionHandler.setAttachment(this.mAttachment);
   if (!paramAttachment.isDownloading()) ;
   for (boolean bool = false; ; bool = this.mSaveClicked) {
     this.mSaveClicked = bool;
     String str = LOG_TAG;
     Object[] arrayOfObject = new Object[6];
     arrayOfObject[0] = paramAttachment.name;
     arrayOfObject[1] = Integer.valueOf(paramAttachment.state);
     arrayOfObject[2] = Integer.valueOf(paramAttachment.destination);
     arrayOfObject[3] = Integer.valueOf(paramAttachment.downloadedSize);
     arrayOfObject[4] = paramAttachment.contentUri;
     arrayOfObject[5] = paramAttachment.contentType;
     LogUtils.d(
         str,
         "got attachment list row: name=%s state/dest=%d/%d dled=%d contentUri=%s MIME=%s",
         arrayOfObject);
     if ((localAttachment == null)
         || (!TextUtils.equals(paramAttachment.name, localAttachment.name)))
       this.mTitle.setText(paramAttachment.name);
     if ((localAttachment == null) || (paramAttachment.size != localAttachment.size)) {
       this.mAttachmentSizeText =
           AttachmentUtils.convertToHumanReadableSize(getContext(), paramAttachment.size);
       this.mDisplayType = AttachmentUtils.getDisplayType(getContext(), paramAttachment);
       updateSubtitleText(null);
     }
     updateActions();
     this.mActionHandler.updateStatus(paramBoolean);
     return;
   }
 }