diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 49905d152..6baeb822d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -86,6 +86,14 @@
android:name="android.hardware.usb.host"
android:required="false" />
+
+
+
+
+
+
+
+
GPSFormat.toDEC(latitude, longitude)
- GpsCoordinateFormat.DMS_VALUE -> GPSFormat.toDMS(latitude, longitude)
- GpsCoordinateFormat.UTM_VALUE -> GPSFormat.toUTM(latitude, longitude)
- GpsCoordinateFormat.MGRS_VALUE -> GPSFormat.toMGRS(latitude, longitude)
- else -> GPSFormat.toDEC(latitude, longitude)
- }
- append(gpsString)
- }
- pop()
- }
- val clipboard: Clipboard = LocalClipboard.current
- val coroutineScope = rememberCoroutineScope()
+
+ val annotatedString = rememberAnnotatedString(latitude, longitude, format, nodeName, style)
+
Text(
modifier = modifier.combinedClickable(
onClick = {
- annotatedString.getStringAnnotations(
- tag = "gps",
- start = 0,
- end = annotatedString.length
- ).firstOrNull()?.let {
- try {
- uriHandler.openUri(it.item)
- } catch (ex: ActivityNotFoundException) {
- debug("No application found: $ex")
- }
- }
+ handleClick(context, annotatedString)
},
onLongClick = {
coroutineScope.launch {
- clipboard.setClipEntry(ClipEntry(ClipData.newPlainText("", annotatedString)))
+ clipboard.setClipEntry(
+ ClipEntry(
+ ClipData.newPlainText("", annotatedString)
+ )
+ )
debug("Copied to clipboard")
}
}
@@ -109,6 +88,60 @@ fun LinkedCoordinates(
)
}
+@Composable
+private fun rememberAnnotatedString(
+ latitude: Double,
+ longitude: Double,
+ format: Int,
+ nodeName: String,
+ style: SpanStyle
+) = buildAnnotatedString {
+ pushStringAnnotation(
+ tag = "gps",
+ annotation = "geo:0,0?q=$latitude,$longitude&z=17&label=${
+ URLEncoder.encode(nodeName, "utf-8")
+ }"
+ )
+ withStyle(style = style) {
+ val gpsString = when (format) {
+ GpsCoordinateFormat.DEC_VALUE -> GPSFormat.toDEC(latitude, longitude)
+ GpsCoordinateFormat.DMS_VALUE -> GPSFormat.toDMS(latitude, longitude)
+ GpsCoordinateFormat.UTM_VALUE -> GPSFormat.toUTM(latitude, longitude)
+ GpsCoordinateFormat.MGRS_VALUE -> GPSFormat.toMGRS(latitude, longitude)
+ else -> GPSFormat.toDEC(latitude, longitude)
+ }
+ append(gpsString)
+ }
+ pop()
+}
+
+private fun handleClick(context: android.content.Context, annotatedString: androidx.compose.ui.text.AnnotatedString) {
+ annotatedString.getStringAnnotations(
+ tag = "gps",
+ start = 0,
+ end = annotatedString.length
+ ).firstOrNull()?.let {
+ val uri = it.item.toUri()
+ val intent = Intent(Intent.ACTION_VIEW, uri).apply {
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
+
+ try {
+ if (intent.resolveActivity(context.packageManager) != null) {
+ context.startActivity(intent)
+ } else {
+ Toast.makeText(
+ context,
+ "No application available to open this location!",
+ Toast.LENGTH_LONG
+ ).show()
+ }
+ } catch (ex: ActivityNotFoundException) {
+ debug("Failed to open geo intent: $ex")
+ }
+ }
+}
+
@PreviewLightDark
@Composable
fun LinkedCoordinatesPreview(