| 1 | package io.github.leexeo.cage.mobile; |
| 2 | |
| 3 | import android.app.Activity; |
| 4 | import android.content.res.Configuration; |
| 5 | import android.view.View; |
| 6 | |
| 7 | final class MobileTheme { |
| 8 | final boolean dark; |
| 9 | final int bg, panel, ink, muted, line, soft, action, onAction; |
| 10 | |
| 11 | private MobileTheme(boolean dark) { |
| 12 | this.dark = dark; |
| 13 | bg = dark ? 0xff191a18 : 0xfffaf9f6; |
| 14 | panel = dark ? 0xff252623 : 0xffffffff; |
| 15 | ink = dark ? 0xfff6f5ef : 0xff292a27; |
| 16 | muted = dark ? 0xffb5b6af : 0xff62645e; |
| 17 | line = dark ? 0xff44463f : 0xffdeded6; |
| 18 | soft = dark ? 0xff32342f : 0xffeeeee8; |
| 19 | action = ink; |
| 20 | onAction = bg; |
| 21 | } |
| 22 | |
| 23 | static MobileTheme apply(Activity activity, String mode) { |
| 24 | int night = activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; |
| 25 | boolean dark = "dark".equals(mode) || (!"light".equals(mode) && night == Configuration.UI_MODE_NIGHT_YES); |
| 26 | activity.setTheme(dark ? android.R.style.Theme_Material_NoActionBar : android.R.style.Theme_Material_Light_NoActionBar); |
| 27 | MobileTheme theme = new MobileTheme(dark); |
| 28 | activity.getWindow().setStatusBarColor(theme.bg); |
| 29 | activity.getWindow().setNavigationBarColor(theme.bg); |
| 30 | activity.getWindow().getDecorView().setSystemUiVisibility(dark ? 0 : |
| 31 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); |
| 32 | return theme; |
| 33 | } |
| 34 | } |