add "Show on map" item at photo video activity

This commit is contained in:
tibbi 2019-07-08 22:22:23 +02:00
parent 0acafd7435
commit b48ca1b4cc
4 changed files with 45 additions and 28 deletions

View File

@ -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() {

View File

@ -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)

View File

@ -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)
}
}

View File

@ -25,4 +25,8 @@
android:id="@+id/menu_open_with"
android:title="@string/open_with"
app:showAsAction="never"/>
<item
android:id="@+id/menu_show_on_map"
android:title="@string/show_on_map"
app:showAsAction="never"/>
</menu>