add example for leaflet in WebView

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-05-26 22:20:23 +02:00 committed by Andy Scherzinger
parent 73becd432d
commit 1e2960a72a
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
5 changed files with 101 additions and 8 deletions

View File

@ -141,6 +141,10 @@
android:configChanges="orientation|keyboardHidden|screenSize"> android:configChanges="orientation|keyboardHidden|screenSize">
</activity> </activity>
<activity
android:name=".activities.LeafletWebView">
</activity>
<receiver android:name=".receivers.PackageReplacedReceiver"> <receiver android:name=".receivers.PackageReplacedReceiver">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />

View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-Type' content='text/html; charset=UTF-8' />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<style>
html, body, #map {
height: 100%;
}
body {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<script>
var queryString = window.location.search;
queryString = queryString.substring(1);
var coords = queryString.split(",");
var map = L.map('map', { zoomControl: false }).setView([coords[0], coords[1]], 13);
map.dragging.disable();
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([coords[0], coords[1]]).addTo(map)
.bindPopup('popup')
.openPopup();
</script>
</body>
</html>

View File

@ -0,0 +1,32 @@
package com.nextcloud.talk.activities
import android.annotation.SuppressLint
import android.os.Bundle
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
import com.nextcloud.talk.databinding.LeafletWebviewBinding
class LeafletWebView : AppCompatActivity() {
lateinit var binding: LeafletWebviewBinding
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = LeafletWebviewBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.webview.settings.javaScriptEnabled = true
binding.webview.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
view?.loadUrl(url)
return true
}
}
binding.webview.loadUrl("file:///android_asset/index.html?51.5263,13.0384");
}
}

View File

@ -77,6 +77,7 @@ import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
import com.facebook.imagepipeline.image.CloseableImage import com.facebook.imagepipeline.image.CloseableImage
import com.google.android.flexbox.FlexboxLayout import com.google.android.flexbox.FlexboxLayout
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.activities.LeafletWebView
import com.nextcloud.talk.activities.MagicCallActivity import com.nextcloud.talk.activities.MagicCallActivity
import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder
import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder
@ -121,7 +122,6 @@ import com.nextcloud.talk.utils.NotificationUtils
import com.nextcloud.talk.utils.UriUtils import com.nextcloud.talk.utils.UriUtils
import com.nextcloud.talk.utils.bundle.BundleKeys import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACTIVE_CONVERSATION
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_NEW_CONVERSATION
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
@ -797,13 +797,19 @@ class ChatController(args: Bundle) :
fun showShareLocationScreen(){ fun showShareLocationScreen(){
Log.d(TAG, "showShareLocationScreen") Log.d(TAG, "showShareLocationScreen")
val bundle = Bundle() // val bundle = Bundle()
bundle.putBoolean(KEY_NEW_CONVERSATION, true) // bundle.putBoolean(KEY_NEW_CONVERSATION, true)
router.pushController( // router.pushController(
RouterTransaction.with(LocationController(bundle)) // RouterTransaction.with(LocationController(bundle))
.pushChangeHandler(HorizontalChangeHandler()) // .pushChangeHandler(HorizontalChangeHandler())
.popChangeHandler(HorizontalChangeHandler()) // .popChangeHandler(HorizontalChangeHandler())
) // )
val leafletIntent = Intent(context, LeafletWebView::class.java)
leafletIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// fullScreenImageIntent.putExtra("FILE_NAME", filename)
// fullScreenImageIntent.putExtra("IS_GIF", isGif(mimetype))
context!!.startActivity(leafletIntent)
} }
private fun showConversationInfoScreen() { private fun showConversationInfoScreen() {

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>