[Android] Revert using a layout, manage background properly and set margins in Webview

Nicolas Pomepuy git at videolan.org
Fri Jun 5 10:16:40 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun  4 08:08:47 2020 +0200| [3ab6847b753dfb910ceedffc4fc9e5025e7ee5f7] | committer: Nicolas Pomepuy

Revert using a layout, manage background properly and set margins in Webview

(cherry picked from commit e7baaa72589783915c8919e240f00158919597ee)

> https://code.videolan.org/videolan/vlc-android/commit/3ab6847b753dfb910ceedffc4fc9e5025e7ee5f7
---

 .../java/org/videolan/television/ui/LicenceActivity.kt  | 17 ++++++++++++-----
 .../java/org/videolan/television/ui/MainTvFragment.kt   |  2 +-
 application/vlc-android/assets/licence_dark_tv.css      |  1 +
 3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt b/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt
index bf7334783..9d38e7f41 100644
--- a/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/LicenceActivity.kt
@@ -3,8 +3,11 @@ package org.videolan.television.ui
 import android.annotation.SuppressLint
 import android.os.Bundle
 import android.util.Base64
+import android.view.View
 import android.webkit.WebView
 import android.webkit.WebViewClient
+import android.widget.FrameLayout
+import androidx.core.content.ContextCompat
 import androidx.fragment.app.FragmentActivity
 import org.videolan.resources.util.applyOverscanMargin
 import org.videolan.vlc.R
@@ -14,26 +17,30 @@ class LicenceActivity : FragmentActivity() {
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
-        setContentView(org.videolan.television.R.layout.about_licence)
+        val backgroundColor = ContextCompat.getColor(this, R.color.grey850)
 
-        val webView = findViewById<WebView>(R.id.webview)
+        val webView = WebView(this)
         val revision = getString(R.string.build_revision)
         webView.loadUrl("file:///android_asset/licence.htm")
+        webView.setBackgroundColor(backgroundColor)
 
         webView.webViewClient = object : WebViewClient() {
 
             override fun onPageFinished(view: WebView, url: String) {
                 if (url.startsWith("file:///android_asset")) {
                     // Inject CSS when page is done loading
-                    injectCSS(view, "licence_dark.css")
+                    injectCSS(view, "licence_dark_tv.css")
                     injectCommitRevision(view, revision)
                 }
                 super.onPageFinished(view, url)
 
             }
         }
-
-        applyOverscanMargin(this)
+        setContentView(webView)
+        (webView.layoutParams as? FrameLayout.LayoutParams)?.let {
+            it.setMargins(0,0,0,0)
+        }
+        (webView.parent as View).setBackgroundColor(backgroundColor)
     }
 
     @SuppressLint("SetJavaScriptEnabled")
diff --git a/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt b/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
index 275b5f673..52552c63d 100644
--- a/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/MainTvFragment.kt
@@ -301,7 +301,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
                         }
                     }
                     ID_ABOUT_TV -> activity.startActivity(Intent(activity, AboutActivity::class.java))
-                    ID_LICENCE -> startActivity(Intent(activity, LicenceActivity::class.java))
+                    ID_LICENCE -> activity.startActivity(Intent(activity, LicenceActivity::class.java))
                 }
             }
             HEADER_NOW_PLAYING -> {
diff --git a/application/vlc-android/assets/licence_dark_tv.css b/application/vlc-android/assets/licence_dark_tv.css
new file mode 100644
index 000000000..096192465
--- /dev/null
+++ b/application/vlc-android/assets/licence_dark_tv.css
@@ -0,0 +1 @@
+html,body{color:#fafafa;background:#323232;margin-left:50px;margin-right:50px;margin-top:20px; margin-bottom20px;}a:link {color: #ff7d00;}a:visited {color: #ffca7d;}
\ No newline at end of file



More information about the Android mailing list