feat:Environment add scale
This commit is contained in:
@@ -18,6 +18,7 @@ package pub.doric.engine;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
@@ -99,7 +100,11 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Resources resources = Resources.getSystem();
|
||||
float scale = 0;
|
||||
if (resources.getDisplayMetrics() != null) {
|
||||
scale = resources.getDisplayMetrics().density;
|
||||
}
|
||||
JSONBuilder envObject = new JSONBuilder()
|
||||
.put("platform", "Android")
|
||||
.put("platformVersion", String.valueOf(android.os.Build.VERSION.SDK_INT))
|
||||
@@ -107,7 +112,8 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
||||
.put("appVersion", appVersion)
|
||||
.put("screenWidth", DoricUtils.px2dp(DoricUtils.getScreenWidth()))
|
||||
.put("screenHeight", DoricUtils.px2dp(DoricUtils.getScreenHeight()))
|
||||
.put("statusBarHeight", DoricUtils.px2dp(DoricUtils.getStatusBarHeight(context)))
|
||||
.put("screenScale", scale)
|
||||
.put("statusBarHeight", DoricUtils.px2dp(DoricUtils.getStatusBarHeight()))
|
||||
.put("hasNotch", false)
|
||||
.put("deviceBrand", Build.BRAND)
|
||||
.put("deviceModel", Build.MODEL);
|
||||
|
@@ -43,7 +43,7 @@ public class StatusBarPlugin extends DoricJavaPlugin {
|
||||
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ((BaseDoricNavBar) getDoricContext().getDoricNavBar()).getLayoutParams();
|
||||
if (hidden) {
|
||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
|
||||
lp.topMargin = DoricUtils.getStatusBarHeight(activity);
|
||||
lp.topMargin = DoricUtils.getStatusBarHeight();
|
||||
} else {
|
||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
lp.topMargin = 0;
|
||||
|
@@ -17,6 +17,7 @@ package pub.doric.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Rect;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
@@ -219,21 +220,13 @@ public class DoricUtils {
|
||||
}
|
||||
|
||||
|
||||
public static int getStatusBarHeight(Context context) {
|
||||
Class<?> c = null;
|
||||
Object obj = null;
|
||||
Field field = null;
|
||||
int x = 0, sbar = 0;
|
||||
try {
|
||||
c = Class.forName("com.android.internal.R$dimen");
|
||||
obj = c.newInstance();
|
||||
field = c.getField("status_bar_height");
|
||||
x = Integer.parseInt(field.get(obj).toString());
|
||||
sbar = context.getResources().getDimensionPixelSize(x);
|
||||
} catch (Exception E) {
|
||||
E.printStackTrace();
|
||||
public static int getStatusBarHeight() {
|
||||
int resourceId = Resources.getSystem().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
return Resources.getSystem().getDimensionPixelSize(resourceId);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return sbar;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user