Skip to content

Commit

Permalink
[hapjs-platform#635]【1300开源版本】快应用适配系统显示大小调整 (hapjs-platform#636)
Browse files Browse the repository at this point in the history
* [hapjs-platform#635]【1300开源版本】快应用适配系统显示大小调整

* [hapjs-platform#635]【1300开源版本】快应用适配系统显示大小调整

* [hapjs-platform#635]【1300开源版本】快应用适配系统显示大小调整

* [hapjs-platform#635]【1300开源版本】快应用适配系统显示大小调整

* [hapjs-platform#635]【1300开源版本】快应用适配系统显示大小调整

---------

Co-authored-by: gaopeng <[email protected]>
  • Loading branch information
mingcan-mc and gaopeng authored Dec 15, 2023
1 parent b4e7552 commit dcbd020
Show file tree
Hide file tree
Showing 29 changed files with 901 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.Context;
import android.content.res.Configuration;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.WindowInsets;

import org.hapjs.model.AppInfo;
Expand Down Expand Up @@ -157,6 +158,22 @@ public static int dip2Pixel(Context context, int dip) {
return (int) (dip * density + 0.5f);
}

public static int dip2PixelFloat(Context context, float dip) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
float density = displayMetrics.density;
return (int) (dip * density + 0.5f);
}

/**
* dp转px
*
* @param context
* @return
*/
public static int dp2px(Context context, float dpVal) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpVal, context.getResources().getDisplayMetrics());
}

public static int getDestinyDpi() {
DisplayMetrics dm = Runtime.getInstance().getContext().getResources().getDisplayMetrics();
return dm.densityDpi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ public abstract class Component<T extends View>
protected boolean mIsUseInList = false;

private View mFullScreenView;
protected float mMinFontLevel = -1;
protected float mMaxFontLevel = -1;
protected boolean mAutoLineHeight;
protected float mMinShowLevel = -1;
protected float mMaxShowLevel = -1;
protected boolean mIsAutoShowLevel;
protected boolean mIsSysShowLevelChange;
protected float mScaleShowLevel = 1.0f;

public Component(HapEngine hapEngine, Context context, Container parent, int ref, RenderEventCallback callback,
Map<String, Object> savedState) {
Expand Down Expand Up @@ -245,6 +253,7 @@ public T createView() {
onRestoreInstanceState(mSavedState);

configBubbleEventAbove1040(false);
initShowLevel();
}
updateViewId();

Expand Down Expand Up @@ -859,7 +868,7 @@ protected boolean setAttribute(String key, Object attribute) {
case Attributes.Style.PADDING_TOP:
case Attributes.Style.PADDING_RIGHT:
case Attributes.Style.PADDING_BOTTOM:
float padding = Attributes.getFloat(mHapEngine, attribute, 0);
float padding = Attributes.getFloat(mHapEngine, attribute, 0,this);
setPadding(key, padding);
setPaddingExist(key, true);
return true;
Expand Down Expand Up @@ -1778,8 +1787,7 @@ public void setWidth(String widthStr) {
}
} else {
mPercentWidth = -1;
int width =
Attributes.getInt(mHapEngine, widthStr, ViewGroup.LayoutParams.WRAP_CONTENT);
int width = Attributes.getInt(mHapEngine, widthStr, ViewGroup.LayoutParams.WRAP_CONTENT, this);
if (isComponentAdaptiveEnable()) {
mAdaptiveBeforeWidth = width;
width = getAdapterWidth(width);
Expand Down Expand Up @@ -1854,8 +1862,7 @@ public void setHeight(String heightStr) {
}
} else {
mPercentHeight = -1;
int height =
Attributes.getInt(mHapEngine, heightStr, ViewGroup.LayoutParams.WRAP_CONTENT);
int height = Attributes.getInt(mHapEngine, heightStr, ViewGroup.LayoutParams.WRAP_CONTENT, this);
lp.height = height;
if (mNode != null) {
mNode.setHeight(height);
Expand Down Expand Up @@ -1988,7 +1995,7 @@ public void setMargin(String position, Object marginAttr) {
if (Attributes.Style.MARGIN_AUTO.equals(marginAttr) && isParentYogaLayout) {
marginAuto = true;
} else {
margin = Attributes.getInt(mHapEngine, marginAttr, 0);
margin = Attributes.getInt(mHapEngine, marginAttr, 0, this);
}

switch (position) {
Expand Down Expand Up @@ -2892,7 +2899,7 @@ public int getCurStateStyleInt(String key, int defaultValue) {

Object attribute = dataMap.get(getState(key));

return Attributes.getInt(mHapEngine, attribute, defaultValue);
return Attributes.getInt(mHapEngine, attribute, defaultValue, this);
}

@Override
Expand Down Expand Up @@ -3865,7 +3872,7 @@ public void setMargin(String key, Object marginAttr) {
if (Attributes.Style.MARGIN_AUTO.equals(marginAttr)) {
margin = 0.0f;
} else {
margin = Attributes.getFloat(mHapEngine, marginAttr, 0.0f);
margin = Attributes.getFloat(mHapEngine, marginAttr, 0.0f,Component.this);
}
if (FloatUtil.isUndefined(margin)) {
margin = 0.0f;
Expand Down Expand Up @@ -4250,4 +4257,89 @@ public void setFullScreenView(View view) {
public boolean preConsumeEvent(String eventName, Map<String, Object> data, boolean immediately) {
return false;
}

public float getMinFontLevel() {
return mMinFontLevel;
}

public float getMaxFontLevel() {
return mMaxFontLevel;
}

protected Page initFontLevel() {
Page page = getPage();
if (null == page || !page.isTextSizeAdjustAuto()) {
return page;
}
float minFontLevel = -1;
float maxFontLevel = -1;
if (null != mAttrsDomData &&
mAttrsDomData.containsKey(Attributes.Style.KEY_MIN_FONT_LEVEL)) {
minFontLevel = Attributes.getFloat(mHapEngine, mAttrsDomData.get(Attributes.Style.KEY_MIN_FONT_LEVEL), -1);
mMinFontLevel = minFontLevel;
}
if (null != mAttrsDomData &&
mAttrsDomData.containsKey(Attributes.Style.KEY_MAX_FONT_LEVEL)) {
maxFontLevel = Attributes.getFloat(mHapEngine, mAttrsDomData.get(Attributes.Style.KEY_MAX_FONT_LEVEL), -1);
mMaxFontLevel = maxFontLevel;
}
if (null != mAttrsDomData &&
mAttrsDomData.containsKey(Attributes.Style.AUTO_LINE_HEIGHT)) {
mAutoLineHeight = Attributes.getBoolean(mAttrsDomData.get(Attributes.Style.AUTO_LINE_HEIGHT), false);
}
return page;
}

protected void initShowLevel() {
boolean isDefaultSysShowSize = true;
SysOpProvider sysOpProvider = ProviderManager.getDefault().getProvider(SysOpProvider.NAME);
if (null != sysOpProvider) {
isDefaultSysShowSize = !sysOpProvider.isSysShowLevelChange(mContext);
mIsSysShowLevelChange = !isDefaultSysShowSize;
}
if (isDefaultSysShowSize) {
return;
}
if (null != sysOpProvider) {
mScaleShowLevel = sysOpProvider.getScaleShowLevel(mContext);
}

Page page = getPage();
if (null == page || !page.isShowSizeAdjustAuto()) {
return;
}
mIsAutoShowLevel = true;
float minShowLevel = -1;
float maxShowLevel = -1;
if (null != mAttrsDomData &&
mAttrsDomData.containsKey(Attributes.Style.KEY_MIN_SHOW_LEVEL)) {
minShowLevel = Attributes.getFloat(mHapEngine, mAttrsDomData.get(Attributes.Style.KEY_MIN_SHOW_LEVEL), -1);
mMinShowLevel = minShowLevel;
}
if (null != mAttrsDomData &&
mAttrsDomData.containsKey(Attributes.Style.KEY_MAX_SHOW_LEVEL)) {
maxShowLevel = Attributes.getFloat(mHapEngine, mAttrsDomData.get(Attributes.Style.KEY_MAX_SHOW_LEVEL), -1);
mMaxShowLevel = maxShowLevel;
}
}

public boolean isAutoShowLevel() {
return mIsAutoShowLevel;
}

public boolean isSysShowLevelChange() {
return mIsSysShowLevelChange;
}

public float getScaleShowLevel() {
return mScaleShowLevel;
}

public float getMinShowLevel() {
return mMinShowLevel;
}

public float getMaxShowLevel() {
return mMaxShowLevel;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, the hapjs-platform Project Contributors
* Copyright (c) 2023-present, the hapjs-platform Project Contributors
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -17,4 +17,6 @@ public interface ComponentProvider {
* @return true: Android O以下版本Bitmap默认RGB565 false:Android O以下版本Bitmap默认ARGB8888
*/
boolean isDefaultRgb565EnableBelowAndroidO(Context context);

boolean isSysShowSizeChange();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, the hapjs-platform Project Contributors
* Copyright (c) 2023-present, the hapjs-platform Project Contributors
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -12,4 +12,9 @@ public class DefaultComponentProviderImpl implements ComponentProvider {
public boolean isDefaultRgb565EnableBelowAndroidO(Context context) {
return true;
}

@Override
public boolean isSysShowSizeChange() {
return false;
}
}
Loading

0 comments on commit dcbd020

Please sign in to comment.