Lines Matching defs:attachment

82      * Return a friendly localized file type for this attachment, or the empty string if
87 public static String getDisplayType(final Context context, final Attachment attachment) {
88 if ((attachment.flags & Attachment.FLAG_DUMMY_ATTACHMENT) != 0) {
89 // This is a dummy attachment, display blank for type.
96 final String contentType = attachment.getContentType();
103 String extension = Utils.getFileExtension(attachment.getName());
160 * Cache the file specified by the given attachment. This will attempt to use any
163 * @param attachment Attachment to be cached
166 * @return String file path for the cached attachment
168 // TODO(pwestbro): Once the attachment has a field for the cached path, this method should be
169 // changed to update the attachment, and return a boolean indicating that the attachment has
171 public static String cacheAttachmentUri(Context context, Attachment attachment,
176 if (attachment.size > 0) {
177 final long usableSpace = cacheDir.getUsableSpace() - attachment.size;
179 LogUtils.w(LOG_TAG, "Low memory (%d/%d). Can't cache attachment %s",
180 usableSpace, totalSpace, attachment);
189 file = File.createTempFile(dateFormat.format(new Date()), ".attachment", cacheDir);
191 && attachment.contentUri != null ? (ParcelFileDescriptor) attachmentFds
192 .getParcelable(attachment.contentUri.toString())
198 if (attachment.contentUri == null) {
199 // The contentUri of the attachment is null. This can happen when sending a
202 LogUtils.d(LOG_TAG, "contentUri is null in attachment: %s", attachment);
203 throw new FileNotFoundException("Missing contentUri in attachment");
206 inputStream = context.getContentResolver().openInputStream(attachment.contentUri);
218 throw new IOException("Timed out reading attachment data");
223 LogUtils.d(LOG_TAG, "Cached %s to %s", attachment.contentUri, cachedFileUri);
228 LogUtils.w(LOG_TAG, "Low memory (%d/%d). Can't cache attachment %s",
229 usableSpace, totalSpace, attachment);
238 LogUtils.e(LOG_TAG, e, "Failed to cache attachment %s", attachment);
266 * Checks if the attachment can be downloaded with the current network
269 * @param attachment the attachment to be checked
270 * @return true if the attachment can be downloaded.
272 public static boolean canDownloadAttachment(Context context, Attachment attachment) {
285 return maxBytes == null || attachment == null || attachment.size <= maxBytes;