diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-20 07:38:33 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-20 07:38:33 -0800 |
commit | c4ef8241b05b9266de77defcfdf1154f400c77f4 (patch) | |
tree | 85971c26d631be25a952d7501ea248689cb69509 /src/com/android/camera/MenuHelper.java | |
parent | d8bccef54d490ce562e61fc907201da0c666314e (diff) | |
download | LegacyCamera-c4ef8241b05b9266de77defcfdf1154f400c77f4.zip LegacyCamera-c4ef8241b05b9266de77defcfdf1154f400c77f4.tar.gz LegacyCamera-c4ef8241b05b9266de77defcfdf1154f400c77f4.tar.bz2 |
auto import from //branches/cupcake/...@132569
Diffstat (limited to 'src/com/android/camera/MenuHelper.java')
-rw-r--r-- | src/com/android/camera/MenuHelper.java | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/com/android/camera/MenuHelper.java b/src/com/android/camera/MenuHelper.java index 2aedb02..ffb99ef 100644 --- a/src/com/android/camera/MenuHelper.java +++ b/src/com/android/camera/MenuHelper.java @@ -16,6 +16,7 @@ package com.android.camera; +import java.io.Closeable; import java.util.ArrayList; import android.app.Activity; @@ -101,6 +102,25 @@ public class MenuHelper { public void run(Uri uri, ImageManager.IImage image); } + private static void closeSilently(Closeable target) { + try { + if (target != null) target.close(); + } catch (Throwable t) { + // ignore all exceptions, that's what silently means + } + } + + public static long getImageFileSize(ImageManager.IImage image) { + java.io.InputStream data = image.fullSizeImageData(); + try { + return data.available(); + } catch (java.io.IOException ex) { + return -1; + } finally { + closeSilently(data); + } + } + static MenuItemsResult addImageMenuItems( Menu menu, int inclusions, @@ -264,17 +284,9 @@ public class MenuHelper { TextView textView = (TextView) d.findViewById(R.id.details_image_title); textView.setText(image.getDisplayName()); - java.io.InputStream data = image.fullSizeImageData(); - String lengthString = ""; - try { - long length = data.available(); - lengthString = - android.text.format.Formatter.formatFileSize(activity, length); - data.close(); - } catch (java.io.IOException ex) { - - } finally { - } + long length = getImageFileSize(image); + String lengthString = lengthString = length < 0 ? "" + : android.text.format.Formatter.formatFileSize(activity, length); ((TextView)d.findViewById(R.id.details_file_size_value)) .setText(lengthString); |