From ca78969f3612f2898188b8eb9d2895e1e2285a74 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Sat, 31 Aug 2013 20:30:08 +0200 Subject: Gallery: Prevent display "Show on map" menu if no geo view is present Change-Id: I8520bd227295eaa77fd8d63dbd9b5758dbd7bf01 JIRA: CYAN-2005 Issue: https://jira.cyanogenmod.org/browse/CYAN-2005 Signed-off-by: Jorge Ruesga --- src/com/android/gallery3d/app/PhotoPage.java | 2 +- .../android/gallery3d/ui/ActionModeHandler.java | 3 ++- src/com/android/gallery3d/ui/MenuExecutor.java | 5 ++-- src/com/android/gallery3d/util/GalleryUtils.java | 27 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 506d1ca6f..37d2f9e53 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -789,7 +789,7 @@ public class PhotoPage extends ActivityState implements } else if (!mHaveImageEditor) { supportedOperations &= ~MediaObject.SUPPORT_EDIT; } - MenuExecutor.updateMenuOperation(menu, supportedOperations); + MenuExecutor.updateMenuOperation(mActivity.getAndroidContext(), menu, supportedOperations); mCurrentPhoto.getPanoramaSupport(mUpdatePanoramaMenuItemsCallback); } diff --git a/src/com/android/gallery3d/ui/ActionModeHandler.java b/src/com/android/gallery3d/ui/ActionModeHandler.java index 7191599ad..f66ab7167 100644 --- a/src/com/android/gallery3d/ui/ActionModeHandler.java +++ b/src/com/android/gallery3d/ui/ActionModeHandler.java @@ -430,7 +430,8 @@ public class ActionModeHandler implements Callback, PopupList.OnPopupItemClickLi public void run() { mMenuTask = null; if (jc.isCancelled()) return; - MenuExecutor.updateMenuOperation(mMenu, operation); + MenuExecutor.updateMenuOperation( + mActivity.getAndroidContext(), mMenu, operation); MenuExecutor.updateMenuForPanorama(mMenu, supportCallback.mAllPanorama360, supportCallback.mHasPanorama360); if (mSharePanoramaMenuItem != null) { diff --git a/src/com/android/gallery3d/ui/MenuExecutor.java b/src/com/android/gallery3d/ui/MenuExecutor.java index 4285f449e..3dfd7ee51 100644 --- a/src/com/android/gallery3d/ui/MenuExecutor.java +++ b/src/com/android/gallery3d/ui/MenuExecutor.java @@ -156,14 +156,15 @@ public class MenuExecutor { mHandler.sendMessage(mHandler.obtainMessage(MSG_TASK_COMPLETE, result, 0, listener)); } - public static void updateMenuOperation(Menu menu, int supported) { + public static void updateMenuOperation(Context context, Menu menu, int supported) { boolean supportDelete = (supported & MediaObject.SUPPORT_DELETE) != 0; boolean supportRotate = (supported & MediaObject.SUPPORT_ROTATE) != 0; boolean supportCrop = (supported & MediaObject.SUPPORT_CROP) != 0; boolean supportTrim = (supported & MediaObject.SUPPORT_TRIM) != 0; boolean supportShare = (supported & MediaObject.SUPPORT_SHARE) != 0; boolean supportSetAs = (supported & MediaObject.SUPPORT_SETAS) != 0; - boolean supportShowOnMap = (supported & MediaObject.SUPPORT_SHOW_ON_MAP) != 0; + boolean supportShowOnMap = (supported & MediaObject.SUPPORT_SHOW_ON_MAP) != 0 & + GalleryUtils.isGeolocationViewAvailable(context); boolean supportCache = (supported & MediaObject.SUPPORT_CACHE) != 0; boolean supportEdit = (supported & MediaObject.SUPPORT_EDIT) != 0; boolean supportInfo = (supported & MediaObject.SUPPORT_INFO) != 0; diff --git a/src/com/android/gallery3d/util/GalleryUtils.java b/src/com/android/gallery3d/util/GalleryUtils.java index 547e2dda0..c0db5e81a 100644 --- a/src/com/android/gallery3d/util/GalleryUtils.java +++ b/src/com/android/gallery3d/util/GalleryUtils.java @@ -297,6 +297,33 @@ public class GalleryUtils { } } + public static boolean isGeolocationViewAvailable(Context context) { + // 1.- GMM with MapView + ComponentName gmmCompName = new ComponentName(MAPS_PACKAGE_NAME, MAPS_CLASS_NAME); + String gmmUri = formatLatitudeLongitude("http://maps.google.com/maps?f=q&q=(%f,%f)", + 0.0d, 0.0d); + Intent gmmIntent = new Intent(); + gmmIntent.setComponent(gmmCompName); + gmmIntent.setData(Uri.parse(gmmUri)); + gmmIntent.setAction(Intent.ACTION_VIEW); + + // 2.- Geolocation content provider + String geoUri = formatLatitudeLongitude("geo:%f,%f", 0.0d, 0.0d); + Intent geoIntent = new Intent(); + geoIntent.setData(Uri.parse(geoUri)); + geoIntent.setAction(Intent.ACTION_VIEW); + + // Should be one of: gmm or geo content provider + return isIntentResolved(context, gmmIntent) || isIntentResolved(context, geoIntent); + } + + private static boolean isIntentResolved(Context context, Intent intent) { + final PackageManager pckMgr = context.getPackageManager(); + List infos = pckMgr.queryIntentActivities (intent, + PackageManager.GET_RESOLVED_FILTER); + return infos != null && infos.size() > 0; + } + public static void setViewPointMatrix( float matrix[], float x, float y, float z) { // The matrix is -- cgit v1.2.3