From b48ca1b4cc9c754b87602dc43db3ad344ee1f1ee Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 8 Jul 2019 22:22:23 +0200 Subject: [PATCH] add "Show on map" item at photo video activity --- .../pro/activities/PhotoVideoActivity.kt | 7 ++++ .../pro/activities/ViewPagerActivity.kt | 30 ++--------------- .../gallery/pro/extensions/Activity.kt | 32 +++++++++++++++++++ app/src/main/res/menu/photo_video_menu.xml | 4 +++ 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt index f8746bfa9..80e922610 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt @@ -247,6 +247,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList findItem(R.id.menu_edit).isVisible = mMedium?.isImage() == true && mUri?.scheme == "file" && visibleBottomActions and BOTTOM_ACTION_EDIT == 0 findItem(R.id.menu_properties).isVisible = mUri?.scheme == "file" && visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0 findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0 + findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0 } return true @@ -263,6 +264,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList R.id.menu_share -> sharePath(mUri!!.toString()) R.id.menu_edit -> openEditor(mUri!!.toString()) R.id.menu_properties -> showProperties() + R.id.menu_show_on_map -> showFileOnMap(mUri!!.toString()) else -> return super.onOptionsItemSelected(item) } return true @@ -320,6 +322,11 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList bottom_set_as.setOnClickListener { setAs(mUri!!.toString()) } + + bottom_show_on_map.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP != 0) + bottom_show_on_map.setOnClickListener { + showFileOnMap(mUri!!.toString()) + } } override fun fragmentClicked() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index b07f83e3b..db5f4d639 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -210,7 +210,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.id.menu_print -> printFile() R.id.menu_edit -> openEditor(getCurrentPath()) R.id.menu_properties -> showProperties() - R.id.menu_show_on_map -> showOnMap() + R.id.menu_show_on_map -> showFileOnMap(getCurrentPath()) R.id.menu_rotate_right -> rotateImage(90) R.id.menu_rotate_left -> rotateImage(-90) R.id.menu_rotate_one_eighty -> rotateImage(180) @@ -701,32 +701,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - private fun showOnMap() { - val exif = try { - ExifInterface(getCurrentPath()) - } catch (e: Exception) { - showErrorToast(e) - return - } - - val latLon = FloatArray(2) - if (exif.getLatLong(latLon)) { - val uriBegin = "geo:${latLon[0]},${latLon[1]}" - val query = "${latLon[0]}, ${latLon[1]}" - val encodedQuery = Uri.encode(query) - val uriString = "$uriBegin?q=$encodedQuery&z=16" - val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uriString)) - val packageManager = packageManager - if (intent.resolveActivity(packageManager) != null) { - startActivity(intent) - } else { - toast(R.string.no_app_found) - } - } else { - toast(R.string.unknown_location) - } - } - private fun initBottomActionsLayout() { bottom_actions.layoutParams.height = resources.getDimension(R.dimen.bottom_actions_height).toInt() + navigationBarHeight if (config.bottomActions) { @@ -786,7 +760,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View bottom_show_on_map.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP != 0) bottom_show_on_map.setOnClickListener { - showOnMap() + showFileOnMap(getCurrentPath()) } bottom_toggle_file_visibility.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY != 0) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index d47dda614..07615227b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -10,6 +10,7 @@ import android.graphics.Matrix import android.graphics.drawable.Drawable import android.graphics.drawable.LayerDrawable import android.media.ExifInterface +import android.net.Uri import android.os.Build import android.provider.MediaStore import android.util.DisplayMetrics @@ -540,3 +541,34 @@ fun Activity.getShortcutImage(tmb: String, drawable: Drawable, callback: () -> U } } } + +@TargetApi(Build.VERSION_CODES.N) +fun Activity.showFileOnMap(path: String) { + val exif = try { + if (path.startsWith("content://") && isNougatPlus()) { + ExifInterface(contentResolver.openInputStream(Uri.parse(path))) + } else { + ExifInterface(path) + } + } catch (e: Exception) { + showErrorToast(e) + return + } + + val latLon = FloatArray(2) + if (exif.getLatLong(latLon)) { + val uriBegin = "geo:${latLon[0]},${latLon[1]}" + val query = "${latLon[0]}, ${latLon[1]}" + val encodedQuery = Uri.encode(query) + val uriString = "$uriBegin?q=$encodedQuery&z=16" + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uriString)) + val packageManager = packageManager + if (intent.resolveActivity(packageManager) != null) { + startActivity(intent) + } else { + toast(R.string.no_app_found) + } + } else { + toast(R.string.unknown_location) + } +} diff --git a/app/src/main/res/menu/photo_video_menu.xml b/app/src/main/res/menu/photo_video_menu.xml index c93bc2464..1a5913f9f 100644 --- a/app/src/main/res/menu/photo_video_menu.xml +++ b/app/src/main/res/menu/photo_video_menu.xml @@ -25,4 +25,8 @@ android:id="@+id/menu_open_with" android:title="@string/open_with" app:showAsAction="never"/> +