From c28538b7e95142e920272c8b5f38876ff910add8 Mon Sep 17 00:00:00 2001 From: Fox2Code Date: Thu, 12 May 2022 15:51:59 +0200 Subject: [PATCH] I said Androidacy I was going to add that. --- .../mmm/androidacy/AndroidacyWebAPI.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java index cc3402b..1ee1aaf 100644 --- a/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java +++ b/app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java @@ -1,14 +1,17 @@ package com.fox2code.mmm.androidacy; +import android.content.res.Resources; import android.net.Uri; import android.os.Build; import android.util.Log; +import android.util.TypedValue; import android.webkit.JavascriptInterface; import android.widget.Button; import android.widget.Toast; import androidx.annotation.Keep; import androidx.appcompat.app.AlertDialog; +import androidx.core.graphics.ColorUtils; import com.fox2code.mmm.BuildConfig; import com.fox2code.mmm.MainApplication; @@ -435,6 +438,54 @@ public class AndroidacyWebAPI { return this.effectiveCompatMode; } + /** + * Return current theme accent color + */ + @JavascriptInterface + public int getAccentColor() { + Resources.Theme theme = this.activity.getTheme(); + TypedValue typedValue = new TypedValue(); + theme.resolveAttribute(R.attr.colorPrimary, typedValue, true); + if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && + typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + return typedValue.data; + } + theme.resolveAttribute(android.R.attr.colorAccent, typedValue, true); + return typedValue.data; + } + + /** + * Return current theme foreground color + */ + @JavascriptInterface + public int getForegroundColor() { + Resources.Theme theme = this.activity.getTheme(); + TypedValue typedValue = new TypedValue(); + theme.resolveAttribute(R.attr.colorOnPrimary, typedValue, true); + if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && + typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + return typedValue.data; + } + theme.resolveAttribute(android.R.attr.foreground, typedValue, true); + return typedValue.data; + } + + /** + * Return current theme background color + */ + @JavascriptInterface + public int getBackgroundColor() { + Resources.Theme theme = this.activity.getTheme(); + TypedValue typedValue = new TypedValue(); + theme.resolveAttribute(R.attr.backgroundColor, typedValue, true); + if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && + typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { + return typedValue.data; + } + theme.resolveAttribute(android.R.attr.background, typedValue, true); + return typedValue.data; + } + // Androidacy feature level declaration method @JavascriptInterface