Browse Source

add example for leaflet in WebView

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 4 years ago
parent
commit
1e2960a72a

+ 4 - 0
app/src/main/AndroidManifest.xml

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

+ 38 - 0
app/src/main/assets/index.html

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

+ 32 - 0
app/src/main/java/com/nextcloud/talk/activities/LeafletWebView.kt

@@ -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");
+
+    }
+}

+ 14 - 8
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -77,6 +77,7 @@ import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber
 import com.facebook.imagepipeline.image.CloseableImage
 import com.google.android.flexbox.FlexboxLayout
 import com.nextcloud.talk.R
+import com.nextcloud.talk.activities.LeafletWebView
 import com.nextcloud.talk.activities.MagicCallActivity
 import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder
 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.bundle.BundleKeys
 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_TOKEN
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_USER_ENTITY
@@ -797,13 +797,19 @@ class ChatController(args: Bundle) :
     fun showShareLocationScreen(){
         Log.d(TAG, "showShareLocationScreen")
 
-        val bundle = Bundle()
-        bundle.putBoolean(KEY_NEW_CONVERSATION, true)
-        router.pushController(
-            RouterTransaction.with(LocationController(bundle))
-                .pushChangeHandler(HorizontalChangeHandler())
-                .popChangeHandler(HorizontalChangeHandler())
-        )
+        // val bundle = Bundle()
+        // bundle.putBoolean(KEY_NEW_CONVERSATION, true)
+        // router.pushController(
+        //     RouterTransaction.with(LocationController(bundle))
+        //         .pushChangeHandler(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() {

+ 13 - 0
app/src/main/res/layout/leaflet_webview.xml

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