Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit c28538b

Browse files
committed
I said Androidacy I was going to add that.
1 parent 897c99b commit c28538b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.fox2code.mmm.androidacy;
22

3+
import android.content.res.Resources;
34
import android.net.Uri;
45
import android.os.Build;
56
import android.util.Log;
7+
import android.util.TypedValue;
68
import android.webkit.JavascriptInterface;
79
import android.widget.Button;
810
import android.widget.Toast;
911

1012
import androidx.annotation.Keep;
1113
import androidx.appcompat.app.AlertDialog;
14+
import androidx.core.graphics.ColorUtils;
1215

1316
import com.fox2code.mmm.BuildConfig;
1417
import com.fox2code.mmm.MainApplication;
@@ -435,6 +438,54 @@ public int getEffectiveCompatMode() {
435438
return this.effectiveCompatMode;
436439
}
437440

441+
/**
442+
* Return current theme accent color
443+
*/
444+
@JavascriptInterface
445+
public int getAccentColor() {
446+
Resources.Theme theme = this.activity.getTheme();
447+
TypedValue typedValue = new TypedValue();
448+
theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
449+
if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
450+
typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
451+
return typedValue.data;
452+
}
453+
theme.resolveAttribute(android.R.attr.colorAccent, typedValue, true);
454+
return typedValue.data;
455+
}
456+
457+
/**
458+
* Return current theme foreground color
459+
*/
460+
@JavascriptInterface
461+
public int getForegroundColor() {
462+
Resources.Theme theme = this.activity.getTheme();
463+
TypedValue typedValue = new TypedValue();
464+
theme.resolveAttribute(R.attr.colorOnPrimary, typedValue, true);
465+
if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
466+
typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
467+
return typedValue.data;
468+
}
469+
theme.resolveAttribute(android.R.attr.foreground, typedValue, true);
470+
return typedValue.data;
471+
}
472+
473+
/**
474+
* Return current theme background color
475+
*/
476+
@JavascriptInterface
477+
public int getBackgroundColor() {
478+
Resources.Theme theme = this.activity.getTheme();
479+
TypedValue typedValue = new TypedValue();
480+
theme.resolveAttribute(R.attr.backgroundColor, typedValue, true);
481+
if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT &&
482+
typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
483+
return typedValue.data;
484+
}
485+
theme.resolveAttribute(android.R.attr.background, typedValue, true);
486+
return typedValue.data;
487+
}
488+
438489
// Androidacy feature level declaration method
439490

440491
@JavascriptInterface

0 commit comments

Comments
 (0)