Skip to content

Commit

Permalink
feat(android): night mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
longchen authored and siguangli committed Jan 29, 2021
1 parent 1cec91b commit 594ac24
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
Expand Down Expand Up @@ -112,7 +113,7 @@ public boolean handleMessage(Message msg)
{
mHippyBridge = new HippyBridgeImpl(mContext, HippyBridgeManagerImpl.this,
mBridgeType == BRIDGE_TYPE_SINGLE_THREAD, !mEnableHippyBuffer, this.mIsDevModule, this.mDebugServerHost);

mHippyBridge.initJSBridge(getGlobalConfigs(), new NativeCallback(mHandler) {
@Override
public void Call(long value, Message msg, String action) {
Expand Down Expand Up @@ -552,6 +553,7 @@ String getGlobalConfigs() {
platformParams.pushString("PackageName", (packageName == null) ? "" : packageName);
platformParams.pushString("VersionName", (versionName == null) ? "" : versionName);
platformParams.pushInt("APILevel", Build.VERSION.SDK_INT);
platformParams.pushBoolean("NightMode", getNightMode());
globalParams.pushMap("Platform", platformParams);

HippyMap tkd = new HippyMap();
Expand All @@ -563,6 +565,24 @@ String getGlobalConfigs() {
return ArgumentUtils.objectToJson(globalParams);
}

private boolean getNightMode() {
int currentNightMode = mContext.getGlobalConfigs().getContext().getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
case Configuration.UI_MODE_NIGHT_UNDEFINED:
// We don't know what mode we're in, assume notnight
return false;
case Configuration.UI_MODE_NIGHT_NO:
// Night mode is not active, we're in day time
return false;
case Configuration.UI_MODE_NIGHT_YES:
// Night mode is active, we're at night!
return true;
default:
return false;
}
}

@Override
public HippyThirdPartyAdapter getThirdPartyAdapter() {
return mThirdPartyAdapter;
Expand Down

0 comments on commit 594ac24

Please sign in to comment.