diff options
author | Wu-cheng Li <wuchengli@google.com> | 2011-05-13 15:18:10 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2011-05-17 15:44:34 +0800 |
commit | 8ab2b624d51b3b8254ece98c46a7e22a6fb5d4aa (patch) | |
tree | 9a62692e59dcfbc8b48e78cfb71e69bfdb7edb4c /src/com/android/camera/Util.java | |
parent | 9e1fcfe35695fd1e71d6c86f28075ca356e5bad5 (diff) | |
download | packages_apps_LegacyCamera-8ab2b624d51b3b8254ece98c46a7e22a6fb5d4aa.zip packages_apps_LegacyCamera-8ab2b624d51b3b8254ece98c46a7e22a6fb5d4aa.tar.gz packages_apps_LegacyCamera-8ab2b624d51b3b8254ece98c46a7e22a6fb5d4aa.tar.bz2 |
Refactor RotateImageView and thumbnail.
Change-Id: Ic435b7cd97ba775ec8f4b8342a1d4d25e2a5120c
Diffstat (limited to 'src/com/android/camera/Util.java')
-rw-r--r-- | src/com/android/camera/Util.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java index 5d4f9b0..bf33dc9 100644 --- a/src/com/android/camera/Util.java +++ b/src/com/android/camera/Util.java @@ -18,14 +18,19 @@ package com.android.camera; import android.app.Activity; import android.app.AlertDialog; +import android.content.ActivityNotFoundException; import android.content.Context; +import android.content.ContentResolver; import android.content.DialogInterface; +import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.hardware.Camera; import android.hardware.Camera.Parameters; import android.hardware.Camera.Size; +import android.net.Uri; +import android.os.ParcelFileDescriptor; import android.telephony.TelephonyManager; import android.util.Log; import android.view.Display; @@ -35,6 +40,7 @@ import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import java.io.Closeable; +import java.io.IOException; import java.lang.reflect.Method; import java.util.List; import java.util.StringTokenizer; @@ -399,4 +405,37 @@ public class Util { return x >= mLocation[0] && x < (mLocation[0] + v.getWidth()) && y >= mLocation[1] && y < (mLocation[1] + v.getHeight()); } + + public static boolean isUriValid(Uri uri, ContentResolver resolver) { + if (uri == null) return false; + + try { + ParcelFileDescriptor pfd = resolver.openFileDescriptor(uri, "r"); + if (pfd == null) { + Log.e(TAG, "Fail to open URI. URI=" + uri); + return false; + } + pfd.close(); + } catch (IOException ex) { + return false; + } + return true; + } + + public static void viewUri(Uri uri, Context context) { + if (!isUriValid(uri, context.getContentResolver())) { + Log.e(TAG, "Uri invalid. uri=" + uri); + return; + } + + try { + context.startActivity(new Intent(Util.REVIEW_ACTION, uri)); + } catch (ActivityNotFoundException ex) { + try { + context.startActivity(new Intent(Intent.ACTION_VIEW, uri)); + } catch (ActivityNotFoundException e) { + Log.e(TAG, "review image fail. uri=" + uri, e); + } + } + } } |