Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de3b706d authored by Fahim's avatar Fahim
Browse files

enable dark-mode for licencePage

- add androidx.webkit dependency to support dark mode on webView
- set dark-mode setup for webView in licence page
parent 3fcfffec
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -34,5 +34,6 @@ LOCAL_STATIC_JAVA_LIBRARIES := cr
LOCAL_STATIC_ANDROID_LIBRARIES += androidx.legacy_legacy-support-v4
LOCAL_STATIC_ANDROID_LIBRARIES += androidx.gridlayout_gridlayout
LOCAL_STATIC_ANDROID_LIBRARIES += androidx.recyclerview_recyclerview
LOCAL_STATIC_ANDROID_LIBRARIES += androidx.webkit_webkit

include $(BUILD_PACKAGE)
+25 −0
Original line number Diff line number Diff line
package com.android.calculator2;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.WebView;

import androidx.webkit.WebViewFeature;
import androidx.webkit.WebSettingsCompat;

public class Licenses extends Activity {

    private static final String LICENSE_URL = "file:///android_asset/licenses.html";
@@ -17,6 +22,18 @@ public class Licenses extends Activity {
        webView.loadUrl(LICENSE_URL);

        setContentView(webView);

        handleDayNightMode(webView);
    }

    private void handleDayNightMode(WebView webView) {
        if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
            if (isInDarkMode()) {
                WebSettingsCompat.setForceDark(webView.getSettings(), WebSettingsCompat.FORCE_DARK_ON);
            } else {
                WebSettingsCompat.setForceDark(webView.getSettings(), WebSettingsCompat.FORCE_DARK_AUTO);
            }
        }
    }

    @Override
@@ -27,4 +44,12 @@ public class Licenses extends Activity {
        }
        return super.onOptionsItemSelected(item);
    }

    private boolean isInDarkMode() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
            int nightModeFlags = getApplication().getApplicationContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
            return nightModeFlags == Configuration.UI_MODE_NIGHT_YES;
        }
        return false;
    }
}