Skip to content

Commit

Permalink
V0.10.0 stable 750 adapter (#83)
Browse files Browse the repository at this point in the history
* * [android] support  setViewport  to different device  screen

* *[android] add unit test case

* * [android] add Meta Module unit test

* * [android] Deprecated the  sDefaultWidth of WXEnvironment

* * [android] retain  old api and mark Deprecated

* * [android] add mViewPortWidth setter and getter

* * [android] add getInstanceViewPortWidth by InstanceId

* * [android] code style fix

* * [android ] adjust code style
  • Loading branch information
zshshr authored and sospartan committed Dec 22, 2016
1 parent 7110389 commit 7cfe975
Show file tree
Hide file tree
Showing 24 changed files with 14,072 additions and 129 deletions.
13,399 changes: 13,392 additions & 7 deletions android/sdk/assets/main.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public class WXEnvironment {
public static String WXSDK_VERSION = BuildConfig.buildVersion;
public static Application sApplication;
public static final String DEV_Id = getDevId();
@Deprecated
public static int sDefaultWidth = 750;
public volatile static boolean JsFrameworkInit = false;

Expand Down
3 changes: 3 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
import com.taobao.weex.common.WXModule;
import com.taobao.weex.dom.*;
import com.taobao.weex.ui.*;
import com.taobao.weex.ui.module.WXMetaModule;
import com.taobao.weex.ui.module.WXModalUIModule;
import com.taobao.weex.http.WXStreamModule;
import com.taobao.weex.ui.animation.WXAnimationModule;
Expand Down Expand Up @@ -339,6 +340,8 @@ private static void register() {
registerModule("clipboard", WXClipboardModule.class, true);
registerModule("globalEvent",WXGlobalEventModule.class);
registerModule("picker", WXPickersModule.class);
registerModule("meta", WXMetaModule.class,true);


registerDomObject(WXBasicComponentType.INDICATOR, WXIndicator.IndicatorDomNode.class);
registerDomObject(WXBasicComponentType.TEXT, WXTextDomObject.class);
Expand Down
17 changes: 15 additions & 2 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ public class WXSDKInstance implements IWXActivityStateListener,DomContext, View.
private boolean isCommit=false;
private WXGlobalEventReceiver mGlobalEventReceiver=null;

/*
* store custom ViewPort Width
*/
public void setViewPortWidth(int mViewPortWidth) {
this.mViewPortWidth = mViewPortWidth;
}

public int getViewPortWidth() {
return mViewPortWidth;
}

private int mViewPortWidth = 750;

/**
* Render strategy.
*/
Expand Down Expand Up @@ -1241,8 +1254,8 @@ public void setSize(int width, int height) {
if (width < 0 || height < 0 || isDestroy || !mRendered) {
return;
}
float realWidth = WXViewUtils.getWebPxByWidth(width);
float realHeight = WXViewUtils.getWebPxByWidth(height);
float realWidth = WXViewUtils.getWebPxByWidth(width,getViewPortWidth());
float realHeight = WXViewUtils.getWebPxByWidth(height,getViewPortWidth());

View godView = mRenderContainer;
if (godView != null) {
Expand Down
4 changes: 4 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public static WXSDKManager getInstance() {
return sManager;
}

public static int getInstanceViewPortWidth(String instanceId){
return getInstance().getSDKInstance(instanceId).getViewPortWidth();
}

static void setInstance(WXSDKManager manager){
sManager = manager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public class BasicEditTextDomObject extends WXDomObject {

public BasicEditTextDomObject() {
super();
mPaint.setTextSize(WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE));
mPaint.setTextSize(WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE,getViewPortWidth()));
setMeasureFunction(new MeasureFunction() {
@Override
public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
Expand Down Expand Up @@ -260,7 +260,7 @@ protected void updateStyleAndAttrs() {
int fontSize = UNSET, fontStyle = UNSET, fontWeight = UNSET;
String fontFamily = null;
if (getStyles().containsKey(Constants.Name.FONT_SIZE)) {
fontSize = WXStyle.getFontSize(getStyles());
fontSize = WXStyle.getFontSize(getStyles(),getViewPortWidth());
}

if (getStyles().containsKey(Constants.Name.FONT_FAMILY)) {
Expand All @@ -275,7 +275,7 @@ protected void updateStyleAndAttrs() {
fontWeight = WXStyle.getFontWeight(getStyles());
}

int lineHeight = WXStyle.getLineHeight(getStyles());
int lineHeight = WXStyle.getLineHeight(getStyles(),getViewPortWidth());
if (lineHeight != UNSET)
mLineHeight = lineHeight;

Expand Down
12 changes: 6 additions & 6 deletions android/sdk/src/main/java/com/taobao/weex/dom/WXDomModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,12 @@ public void getComponentRect(String ref, String callback) {
Map<String, String> sizes = new HashMap<>();
Rect rect=new Rect();
((View)mWXSDKInstance.getRootView().getParent()).getGlobalVisibleRect(rect);
sizes.put("width", String.valueOf(WXViewUtils.getWebPxByWidth(rect.width())));
sizes.put("height", String.valueOf(WXViewUtils.getWebPxByWidth(rect.height())));
sizes.put("bottom",String.valueOf(WXViewUtils.getWebPxByWidth(rect.bottom)));
sizes.put("left",String.valueOf(WXViewUtils.getWebPxByWidth(rect.left)));
sizes.put("right",String.valueOf(WXViewUtils.getWebPxByWidth(rect.right)));
sizes.put("top",String.valueOf(WXViewUtils.getWebPxByWidth(rect.top)));
sizes.put("width", String.valueOf(WXViewUtils.getWebPxByWidth(rect.width(),mWXSDKInstance.getViewPortWidth())));
sizes.put("height", String.valueOf(WXViewUtils.getWebPxByWidth(rect.height(),mWXSDKInstance.getViewPortWidth())));
sizes.put("bottom",String.valueOf(WXViewUtils.getWebPxByWidth(rect.bottom,mWXSDKInstance.getViewPortWidth())));
sizes.put("left",String.valueOf(WXViewUtils.getWebPxByWidth(rect.left,mWXSDKInstance.getViewPortWidth())));
sizes.put("right",String.valueOf(WXViewUtils.getWebPxByWidth(rect.right,mWXSDKInstance.getViewPortWidth())));
sizes.put("top",String.valueOf(WXViewUtils.getWebPxByWidth(rect.top,mWXSDKInstance.getViewPortWidth())));
options.put("size", sizes);
options.put("result", true);
WXSDKManager.getInstance().callback(mWXSDKInstance.getInstanceId(), callback, options);
Expand Down
65 changes: 39 additions & 26 deletions android/sdk/src/main/java/com/taobao/weex/dom/WXDomObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ public class WXDomObject extends CSSNode implements Cloneable,ImmutableDomObject
public static final String TRANSFORM_ORIGIN = "transformOrigin";
private AtomicBoolean sDestroy = new AtomicBoolean();

private int mViewPortWidth =750;

private DomContext mDomContext;

/** package **/ String mRef = ROOT;
Expand Down Expand Up @@ -282,6 +284,14 @@ public class WXDomObject extends CSSNode implements Cloneable,ImmutableDomObject
}


public int getViewPortWidth() {
return mViewPortWidth;
}

public void setViewPortWidth(int mViewPortWidth) {
this.mViewPortWidth = mViewPortWidth;
}

public String getRef(){
return mRef;
}
Expand Down Expand Up @@ -616,84 +626,84 @@ public void updateStyle(Map<String, Object> styles) {
setWrap(stylesMap.getCSSWrap());
break;
case Constants.Name.MIN_WIDTH:
setMinWidth(WXViewUtils.getRealPxByWidth(stylesMap.getMinWidth()));
setMinWidth(WXViewUtils.getRealPxByWidth(stylesMap.getMinWidth(),getViewPortWidth()));
break;
case Constants.Name.MIN_HEIGHT:
setMinHeight(WXViewUtils.getRealPxByWidth(stylesMap.getMinHeight()));
setMinHeight(WXViewUtils.getRealPxByWidth(stylesMap.getMinHeight(),getViewPortWidth()));
break;
case Constants.Name.MAX_WIDTH:
setMaxWidth(WXViewUtils.getRealPxByWidth(stylesMap.getMaxWidth()));
setMaxWidth(WXViewUtils.getRealPxByWidth(stylesMap.getMaxWidth(),getViewPortWidth()));
break;
case Constants.Name.MAX_HEIGHT:
setMaxHeight(WXViewUtils.getRealPxByWidth(stylesMap.getMaxHeight()));
setMaxHeight(WXViewUtils.getRealPxByWidth(stylesMap.getMaxHeight(),getViewPortWidth()));
break;
case Constants.Name.DEFAULT_HEIGHT:
case Constants.Name.HEIGHT:
setStyleHeight(WXViewUtils.getRealPxByWidth(stylesMap.containsKey(Constants.Name.HEIGHT)?stylesMap.getHeight():stylesMap.getDefaultHeight()));
setStyleHeight(WXViewUtils.getRealPxByWidth(stylesMap.containsKey(Constants.Name.HEIGHT)?stylesMap.getHeight():stylesMap.getDefaultHeight(),getViewPortWidth()));
break;
case Constants.Name.WIDTH:
case Constants.Name.DEFAULT_WIDTH:
setStyleWidth(WXViewUtils.getRealPxByWidth(stylesMap.containsKey(Constants.Name.WIDTH)?stylesMap.getWidth():stylesMap.getDefaultWidth()));
setStyleWidth(WXViewUtils.getRealPxByWidth(stylesMap.containsKey(Constants.Name.WIDTH)?stylesMap.getWidth():stylesMap.getDefaultWidth(),getViewPortWidth()));
break;
case Constants.Name.POSITION:
setPositionType(stylesMap.getPosition());
break;
case Constants.Name.LEFT:
setPositionLeft(WXViewUtils.getRealPxByWidth(stylesMap.getLeft()));
setPositionLeft(WXViewUtils.getRealPxByWidth(stylesMap.getLeft(),getViewPortWidth()));
break;
case Constants.Name.TOP:
setPositionTop(WXViewUtils.getRealPxByWidth(stylesMap.getTop()));
setPositionTop(WXViewUtils.getRealPxByWidth(stylesMap.getTop(),getViewPortWidth()));
break;
case Constants.Name.RIGHT:
setPositionRight(WXViewUtils.getRealPxByWidth(stylesMap.getRight()));
setPositionRight(WXViewUtils.getRealPxByWidth(stylesMap.getRight(),getViewPortWidth()));
break;
case Constants.Name.BOTTOM:
setPositionBottom(WXViewUtils.getRealPxByWidth(stylesMap.getBottom()));
setPositionBottom(WXViewUtils.getRealPxByWidth(stylesMap.getBottom(),getViewPortWidth()));
break;
case Constants.Name.MARGIN:
setMargin(Spacing.ALL, WXViewUtils.getRealPxByWidth(stylesMap.getMargin()));
setMargin(Spacing.ALL, WXViewUtils.getRealPxByWidth(stylesMap.getMargin(),getViewPortWidth()));
break;
case Constants.Name.MARGIN_LEFT:
setMargin(Spacing.LEFT, WXViewUtils.getRealPxByWidth(stylesMap.getMarginLeft()));
setMargin(Spacing.LEFT, WXViewUtils.getRealPxByWidth(stylesMap.getMarginLeft(),getViewPortWidth()));
break;
case Constants.Name.MARGIN_TOP:
setMargin(Spacing.TOP, WXViewUtils.getRealPxByWidth(stylesMap.getMarginTop()));
setMargin(Spacing.TOP, WXViewUtils.getRealPxByWidth(stylesMap.getMarginTop(),getViewPortWidth()));
break;
case Constants.Name.MARGIN_RIGHT:
setMargin(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(stylesMap.getMarginRight()));
setMargin(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(stylesMap.getMarginRight(),getViewPortWidth()));
break;
case Constants.Name.MARGIN_BOTTOM:
setMargin(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(stylesMap.getMarginBottom()));
setMargin(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(stylesMap.getMarginBottom(),getViewPortWidth()));
break;
case Constants.Name.BORDER_WIDTH:
setBorder(Spacing.ALL, WXViewUtils.getRealPxByWidth(stylesMap.getBorderWidth()));
setBorder(Spacing.ALL, WXViewUtils.getRealPxByWidth(stylesMap.getBorderWidth(),getViewPortWidth()));
break;
case Constants.Name.BORDER_TOP_WIDTH:
setBorder(Spacing.TOP, WXViewUtils.getRealPxByWidth(stylesMap.getBorderTopWidth()));
setBorder(Spacing.TOP, WXViewUtils.getRealPxByWidth(stylesMap.getBorderTopWidth(),getViewPortWidth()));
break;
case Constants.Name.BORDER_RIGHT_WIDTH:
setBorder(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(stylesMap.getBorderRightWidth()));
setBorder(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(stylesMap.getBorderRightWidth(),getViewPortWidth()));
break;
case Constants.Name.BORDER_BOTTOM_WIDTH:
setBorder(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(stylesMap.getBorderBottomWidth()));
setBorder(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(stylesMap.getBorderBottomWidth(),getViewPortWidth()));
break;
case Constants.Name.BORDER_LEFT_WIDTH:
setBorder(Spacing.LEFT, WXViewUtils.getRealPxByWidth(stylesMap.getBorderLeftWidth()));
setBorder(Spacing.LEFT, WXViewUtils.getRealPxByWidth(stylesMap.getBorderLeftWidth(),getViewPortWidth()));
break;
case Constants.Name.PADDING:
setPadding(Spacing.ALL, WXViewUtils.getRealPxByWidth(stylesMap.getPadding()));
setPadding(Spacing.ALL, WXViewUtils.getRealPxByWidth(stylesMap.getPadding(),getViewPortWidth()));
break;
case Constants.Name.PADDING_LEFT:
setPadding(Spacing.LEFT, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingLeft()));
setPadding(Spacing.LEFT, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingLeft(),getViewPortWidth()));
break;
case Constants.Name.PADDING_TOP:
setPadding(Spacing.TOP, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingTop()));
setPadding(Spacing.TOP, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingTop(),getViewPortWidth()));
break;
case Constants.Name.PADDING_RIGHT:
setPadding(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingRight()));
setPadding(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingRight(),getViewPortWidth()));
break;
case Constants.Name.PADDING_BOTTOM:
setPadding(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingBottom()));
setPadding(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingBottom(),getViewPortWidth()));
break;
}
}
Expand Down Expand Up @@ -788,13 +798,16 @@ public String dumpDomTree() {
* @param json the original JSONObject
* @return Dom Object corresponding to the JSONObject.
*/
public static @Nullable WXDomObject parse(JSONObject json, WXSDKInstance wxsdkInstance){
public static @Nullable WXDomObject parse(JSONObject json, WXSDKInstance wxsdkInstance){
if (json == null || json.size() <= 0) {
return null;
}

String type = (String) json.get(TYPE);
WXDomObject domObject = WXDomObjectFactory.newInstance(type);

domObject.setViewPortWidth(wxsdkInstance.getViewPortWidth());

if(domObject == null){
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ private void addDomInternal(JSONObject dom,boolean isRoot, String parentRef, fin
}
if (isRoot) {
WXDomObject.prepareRoot(domObject,
WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexHeight(mInstanceId)),
WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexWidth(mInstanceId)));
WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexHeight(mInstanceId),WXSDKManager.getInstanceViewPortWidth(mInstanceId)),
WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexWidth(mInstanceId),WXSDKManager.getInstanceViewPortWidth(mInstanceId)));
} else if ((parent = mRegistry.get(parentRef)) == null) {
instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
return;
Expand Down Expand Up @@ -1150,7 +1150,7 @@ private WXAnimationBean createAnimationBean(String ref, String animation){
int width=(int)domObject.getLayoutWidth();
int height=(int)domObject.getLayoutHeight();
animationBean.styles.init(animationBean.styles.transformOrigin,
animationBean.styles.transform,width,height);
animationBean.styles.transform,width,height,WXSDKManager.getInstance().getSDKInstance(mInstanceId).getViewPortWidth());
}
return animationBean;
} catch (RuntimeException e) {
Expand All @@ -1170,7 +1170,7 @@ private WXAnimationBean createAnimationBean(String ref,Map<String, Object> style
int width = (int) domObject.getLayoutWidth();
int height = (int) domObject.getLayoutHeight();
animationBean.styles = new WXAnimationBean.Style();
animationBean.styles.init(transformOrigin, (String) transform, width, height);
animationBean.styles.init(transformOrigin, (String) transform, width, height,WXSDKManager.getInstance().getSDKInstance(mInstanceId).getViewPortWidth());
return animationBean;
}
}catch (RuntimeException e){
Expand Down
10 changes: 5 additions & 5 deletions android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,15 @@ public static int getFontStyle(Map<String, Object> style) {
return typeface;
}

public static int getFontSize(Map<String, Object> style) {
public static int getFontSize(Map<String, Object> style,int viewPortW) {
if (style == null) {
return (int) WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE);
return (int) WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE,viewPortW);
}
int fontSize = WXUtils.getInt(style.get(Constants.Name.FONT_SIZE));
if (fontSize <= 0) {
fontSize = WXText.sDEFAULT_SIZE;
}
return (int) WXViewUtils.getRealPxByWidth(fontSize);
return (int) WXViewUtils.getRealPxByWidth(fontSize,viewPortW);
}

public static String getFontFamily(Map<String, Object> style) {
Expand Down Expand Up @@ -380,7 +380,7 @@ public static int getLines(Map<String, Object> style) {
return WXUtils.getInt(style.get(Constants.Name.LINES));
}

public static int getLineHeight(Map<String, Object> style){
public static int getLineHeight(Map<String, Object> style,int viewPortW){
if (style == null) {
return UNSET;
}
Expand All @@ -389,7 +389,7 @@ public static int getLineHeight(Map<String, Object> style){
lineHeight = UNSET;
return lineHeight;
}
return (int) WXViewUtils.getRealPxByWidth(lineHeight);
return (int) WXViewUtils.getRealPxByWidth(lineHeight,viewPortW);
}
/*
* flexbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private void updateStyleImp(Map<String, Object> style) {
}
}
if (style.containsKey(Constants.Name.FONT_SIZE)) {
mFontSize = WXStyle.getFontSize(style);
mFontSize = WXStyle.getFontSize(style,getViewPortWidth());
}
if (style.containsKey(Constants.Name.FONT_WEIGHT)) {
mFontWeight = WXStyle.getFontWeight(style);
Expand All @@ -271,7 +271,7 @@ private void updateStyleImp(Map<String, Object> style) {
}
mAlignment = WXStyle.getTextAlignment(style);
textOverflow = WXStyle.getTextOverflow(style);
int lineHeight = WXStyle.getLineHeight(style);
int lineHeight = WXStyle.getLineHeight(style,getViewPortWidth());
if (lineHeight != UNSET) {
mLineHeight = lineHeight;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void scrollTo(String ref, Map<String, Object> options) {
String offset = options.get("offset") == null ? "0" : options.get("offset").toString();
if (offset != null) {
try {
offsetFloat = WXViewUtils.getRealPxByWidth(Float.parseFloat(offset));
offsetFloat = WXViewUtils.getRealPxByWidth(Float.parseFloat(offset),mWXSDKInstance.getViewPortWidth());
}catch (Exception e ){
WXLogUtils.e("Float parseFloat error :"+e.getMessage());
}
Expand Down Expand Up @@ -551,12 +551,12 @@ public void getComponentSize(String ref, String callback) {
if (component != null) {
Map<String, String> size = new HashMap<>();
Rect sizes = component.getComponentSize();
size.put("width", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.width())));
size.put("height", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.height())));
size.put("bottom",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.bottom)));
size.put("left",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.left)));
size.put("right",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.right)));
size.put("top",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.top)));
size.put("width", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.width(),mWXSDKInstance.getViewPortWidth())));
size.put("height", String.valueOf(WXViewUtils.getWebPxByWidth(sizes.height(),mWXSDKInstance.getViewPortWidth())));
size.put("bottom",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.bottom,mWXSDKInstance.getViewPortWidth())));
size.put("left",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.left,mWXSDKInstance.getViewPortWidth())));
size.put("right",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.right,mWXSDKInstance.getViewPortWidth())));
size.put("top",String.valueOf(WXViewUtils.getWebPxByWidth(sizes.top,mWXSDKInstance.getViewPortWidth())));
options.put("size", size);
options.put("result", true);
} else {
Expand Down
Loading

0 comments on commit 7cfe975

Please sign in to comment.