[Android] Remote access: manage icon tint

Nicolas Pomepuy git at videolan.org
Wed Feb 28 10:33:46 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Feb  9 10:28:42 2024 +0100| [04095418102c8ebbaabe5abded6abd5d2c737b3c] | committer: Nicolas Pomepuy

Remote access: manage icon tint

> https://code.videolan.org/videolan/vlc-android/commit/04095418102c8ebbaabe5abded6abd5d2c737b3c
---

 .../main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt  | 9 ++++++++-
 buildsystem/network-sharing-server/src/plugins/api.js            | 4 +++-
 buildsystem/network-sharing-server/src/plugins/vlcUtils.js       | 4 ++--
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
index dbb2ac1697..954d0e7a2d 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
@@ -30,6 +30,7 @@ import android.net.Uri
 import android.os.Build
 import android.text.format.Formatter
 import android.util.Log
+import androidx.core.content.ContextCompat
 import androidx.core.net.toUri
 import androidx.lifecycle.LiveData
 import com.google.gson.Gson
@@ -98,6 +99,7 @@ import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.gui.helpers.AudioUtil
 import org.videolan.vlc.gui.helpers.BitmapUtil
 import org.videolan.vlc.gui.helpers.getBitmapFromDrawable
+import org.videolan.vlc.gui.helpers.getColoredBitmapFromColor
 import org.videolan.vlc.gui.preferences.search.PreferenceParser
 import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.providers.BrowserProvider
@@ -265,6 +267,7 @@ fun Route.setupRouting(appContext: Context, scope: CoroutineScope) {
     get("/icon") {
         val idString = call.request.queryParameters["id"]
         val width = call.request.queryParameters["width"]?.toInt() ?: 32
+        val preventTint = call.request.queryParameters["preventTint"]?.toBoolean() ?: false
 
         val id = try {
             appContext.resIdByName(idString, "drawable")
@@ -277,8 +280,12 @@ fun Route.setupRouting(appContext: Context, scope: CoroutineScope) {
             call.respond(HttpStatusCode.NotFound)
             return at get
         }
+        val bmp = if (preventTint)
+            BitmapUtil.vectorToBitmap(appContext, id, width, width)
+        else
+            appContext.getColoredBitmapFromColor(id, ContextCompat.getColor(appContext, R.color.black), width, width)
 
-        BitmapUtil.encodeImage(BitmapUtil.vectorToBitmap(appContext, id, width, width), true)?.let {
+        BitmapUtil.encodeImage(bmp, true)?.let {
 
             call.respondBytes(ContentType.Image.PNG) { it }
             return at get
diff --git a/buildsystem/network-sharing-server/src/plugins/api.js b/buildsystem/network-sharing-server/src/plugins/api.js
index e7bf073f79..24f622fa99 100644
--- a/buildsystem/network-sharing-server/src/plugins/api.js
+++ b/buildsystem/network-sharing-server/src/plugins/api.js
@@ -112,12 +112,14 @@ export const vlcApi = {
      * Retrieve the app asset icon API URL
      * @param {Number} id the asset id 
      * @param {Number} width the img width
+     * @param {Boolean} preventTint if true, preserve the source colors
      * @returns the URL
      */
-    appAsset: (id, width) => {
+    appAsset: (id, width, preventTint) => {
         const params = {}
         if (id) params.id = id
         if (width) params.width = width
+        if (preventTint) params.preventTint = preventTint
         return `${API_URL}icon?${new URLSearchParams(params).toString()}`
     },
     /**
diff --git a/buildsystem/network-sharing-server/src/plugins/vlcUtils.js b/buildsystem/network-sharing-server/src/plugins/vlcUtils.js
index 4b4a72c728..d39dd99dbc 100644
--- a/buildsystem/network-sharing-server/src/plugins/vlcUtils.js
+++ b/buildsystem/network-sharing-server/src/plugins/vlcUtils.js
@@ -15,9 +15,9 @@ export default {
             const hours = Math.floor((ms / (3600 * 1000)) % 3600)
             return `${hours == 0 ? '' : hours + ":"}${hours == 0 && minutes < 10 ? minutes : minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`
         }
-        app.config.globalProperties.$getAppAsset = (name, width) => {
+        app.config.globalProperties.$getAppAsset = (name, width, preventTint) => {
             if (width < 0 || width === undefined) width = 24
-            return vlcApi.appAsset(name, width)
+            return vlcApi.appAsset(name, width, preventTint)
         }
 
         app.config.globalProperties.$getImageUrl = (media, mediaType) => {



More information about the Android mailing list