|
1 | 1 | package com.fox2code.mmm.androidacy; |
2 | 2 |
|
| 3 | +import android.content.res.Resources; |
3 | 4 | import android.net.Uri; |
4 | 5 | import android.os.Build; |
5 | 6 | import android.util.Log; |
| 7 | +import android.util.TypedValue; |
6 | 8 | import android.webkit.JavascriptInterface; |
7 | 9 | import android.widget.Button; |
8 | 10 | import android.widget.Toast; |
9 | 11 |
|
10 | 12 | import androidx.annotation.Keep; |
11 | 13 | import androidx.appcompat.app.AlertDialog; |
| 14 | +import androidx.core.graphics.ColorUtils; |
12 | 15 |
|
13 | 16 | import com.fox2code.mmm.BuildConfig; |
14 | 17 | import com.fox2code.mmm.MainApplication; |
@@ -435,6 +438,54 @@ public int getEffectiveCompatMode() { |
435 | 438 | return this.effectiveCompatMode; |
436 | 439 | } |
437 | 440 |
|
| 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 | + |
438 | 489 | // Androidacy feature level declaration method |
439 | 490 |
|
440 | 491 | @JavascriptInterface |
|
0 commit comments