You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2018/04/28 06:54:03 UTC
[35/48] incubator-weex git commit: * [android] Merge WeexCore-master
to master.
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXScrollerDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXScrollerDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXScrollerDomObject.java
deleted file mode 100644
index 6ff548e..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXScrollerDomObject.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom;
-
-import android.support.v4.util.ArrayMap;
-
-import com.taobao.weex.common.Constants;
-
-import java.util.Map;
-
-public class WXScrollerDomObject extends WXDomObject {
-
- @Override
- protected Map<String, String> getDefaultStyle() {
- Map<String, String> map = new ArrayMap<>();
-
- boolean isVertical = true;
- if (parent != null) {
- String direction = (String) parent.getAttrs().get(Constants.Name.SCROLL_DIRECTION);
- if (direction != null && direction.equals("horizontal")) {
- isVertical = false;
- }
- }
-
- String prop = isVertical?Constants.Name.HEIGHT:Constants.Name.WIDTH;
- if (getStyles().get(prop) == null &&
- getStyles().get(Constants.Name.FLEX) == null) {
- map.put(Constants.Name.FLEX, "1");
- }
-
- return map;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java
index ff1842a..393a435 100644
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java
+++ b/android/sdk/src/main/java/com/taobao/weex/dom/WXStyle.java
@@ -24,29 +24,17 @@ import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
import android.text.Layout;
import android.text.TextUtils;
-
import com.taobao.weex.common.Constants;
import com.taobao.weex.dom.binding.ELUtils;
-import com.taobao.weex.dom.binding.WXStatement;
-import com.taobao.weex.dom.flex.CSSAlign;
-import com.taobao.weex.dom.flex.CSSFlexDirection;
-import com.taobao.weex.dom.flex.CSSJustify;
-import com.taobao.weex.dom.flex.CSSPositionType;
-import com.taobao.weex.dom.flex.CSSWrap;
-import com.taobao.weex.el.parse.Parser;
import com.taobao.weex.ui.component.WXText;
import com.taobao.weex.ui.component.WXTextDecoration;
import com.taobao.weex.utils.WXUtils;
import com.taobao.weex.utils.WXViewUtils;
-
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import static com.taobao.weex.dom.binding.ELUtils.COMPONENT_PROPS;
-import static com.taobao.weex.dom.binding.ELUtils.EXCLUDES_BINDING;
-
/**
* Store value of component style
*
@@ -56,9 +44,14 @@ public class WXStyle implements Map<String, Object>,Cloneable {
private static final long serialVersionUID = 611132641365274134L;
public static final int UNSET = -1;
- private @NonNull final Map<String,Object> mStyles;
- private Map<String,Map<String,Object>> mPesudoStyleMap = new ArrayMap<>();// clz_group:{styleMap}
- private Map<String,Object> mPesudoResetStyleMap = new ArrayMap<>();
+ @NonNull
+ private final Map<String,Object> mStyles;
+
+ @Nullable
+ private Map<String,Map<String,Object>> mPesudoStyleMap;// clz_group:{styleMap}
+
+ @Nullable
+ private Map<String,Object> mPesudoResetStyleMap;
/**
* dynamic binding attrs, can be null, only weex use
@@ -69,6 +62,11 @@ public class WXStyle implements Map<String, Object>,Cloneable {
mStyles = new ArrayMap<>();
}
+ public WXStyle(Map<String, Object> styles){
+ this.mStyles = styles;
+ processPesudoClasses(this.mStyles);
+ }
+
public WXStyle(Map<String, Object> mStyles, boolean byPesudo) {
this();
this.putAll(filterBindingStyles(mStyles), byPesudo);
@@ -216,118 +214,7 @@ public class WXStyle implements Map<String, Object>,Cloneable {
}
return (int) WXViewUtils.getRealPxByWidth(lineHeight,viewPortW);
}
- /*
- * flexbox
- **/
- public CSSAlign getAlignItems() {
- Object alignItems = get(Constants.Name.ALIGN_ITEMS);
- if (alignItems == null) {
- return CSSAlign.STRETCH;
- }
- return CSSAlignConvert.convert2AlignItems(alignItems.toString().trim());
- }
-
- public CSSAlign getAlignSelf() {
- Object alignSelf = get(Constants.Name.ALIGN_SELF);
- if (alignSelf == null) {
- return CSSAlign.AUTO;
- }
- return CSSAlignConvert.convert2AlignSelf(alignSelf.toString().trim());
- }
-
- public float getFlex() {
- return WXUtils.getFloat(get(Constants.Name.FLEX));
- }
-
- public CSSFlexDirection getFlexDirection() {
- Object flexDirection = get(Constants.Name.FLEX_DIRECTION);
- if (flexDirection == null) {
- return CSSFlexDirection.COLUMN;
- }
- return CSSFlexDirectionConvert.convert(flexDirection.toString().trim());
- }
-
- public CSSJustify getJustifyContent() {
- Object justifyContent = get(Constants.Name.JUSTIFY_CONTENT);
- if (justifyContent == null) {
- return CSSJustify.FLEX_START;
- }
- return CSSJustifyConvert.convert(justifyContent.toString().trim());
- }
-
- public CSSWrap getCSSWrap() {
- Object cssWrap = get(Constants.Name.FLEX_WRAP);
- if (cssWrap == null) {
- return CSSWrap.NOWRAP;
- }
- return CSSWrapConvert.convert(cssWrap.toString().trim());
- }
-
- /*
- * base
- * @see getWidth(int viewport)
- **/
- @Deprecated
- public float getWidth() {
- return WXUtils.getFloat(get(Constants.Name.WIDTH));
- }
-
- public float getDefaultWidth() {
- return WXUtils.getFloat(get(Constants.Name.DEFAULT_WIDTH));
- }
-
- public float getMinWidth() {
- return WXUtils.getFloat(get(Constants.Name.MIN_WIDTH));
- }
-
- public float getMaxWidth() {
- return WXUtils.getFloat(get(Constants.Name.MAX_WIDTH));
- }
-
- @Deprecated
- public float getHeight() {
- return WXUtils.getFloat(get(Constants.Name.HEIGHT));
- }
-
- public float getDefaultHeight() {
- return WXUtils.getFloat(get(Constants.Name.DEFAULT_HEIGHT));
- }
-
- public float getMinHeight() {
- return WXUtils.getFloat(get(Constants.Name.MIN_HEIGHT));
- }
-
- public float getMaxHeight() {
- return WXUtils.getFloat(get(Constants.Name.MAX_HEIGHT));
- }
-
-
- public float getWidth(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.WIDTH), viewport);
- }
-
- public float getMinWidth(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.MIN_WIDTH), viewport);
- }
-
- public float getMaxWidth(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.MAX_WIDTH), viewport);
- }
-
- public float getHeight(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.HEIGHT), viewport);
- }
-
- public float getMinHeight(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.MIN_HEIGHT), viewport);
- }
- public float getMaxHeight(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.MAX_HEIGHT), viewport);
- }
- /*
- * border
- **/
public float getBorderRadius() {
float temp = WXUtils.getFloat(get(Constants.Name.BORDER_RADIUS));
if (WXUtils.isUndefined(temp)) {
@@ -336,47 +223,6 @@ public class WXStyle implements Map<String, Object>,Cloneable {
return temp;
}
- private float getBorderWidth(String key) {
- float temp = WXUtils.getFloat(get(key));
- if (WXUtils.isUndefined(temp)) {
- return getBorderWidth();
- }
- return temp;
- }
-
- private float getBorderWidth(String key, int viewport) {
- float temp = WXUtils.getFloatByViewport(get(key), viewport);
- if (WXUtils.isUndefined(temp)) {
- return getBorderWidth(viewport);
- }
- return temp;
- }
- //TODO fix : only when set backgroundColor
- @Deprecated
- public float getBorderWidth() {
- return WXUtils.getFloat(get(Constants.Name.BORDER_WIDTH));
- }
-
- public float getBorderWidth(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.BORDER_WIDTH), viewport);
- }
-
- public float getBorderRightWidth(int viewport) {
- return getBorderWidth(Constants.Name.BORDER_RIGHT_WIDTH, viewport);
- }
-
- public float getBorderTopWidth(int viewport) {
- return getBorderWidth(Constants.Name.BORDER_TOP_WIDTH, viewport);
- }
-
- public float getBorderBottomWidth(int viewport) {
- return getBorderWidth(Constants.Name.BORDER_BOTTOM_WIDTH, viewport);
- }
-
- public float getBorderLeftWidth(int viewport) {
- return getBorderWidth(Constants.Name.BORDER_LEFT_WIDTH, viewport);
- }
-
public String getBorderColor() {
Object color = get(Constants.Name.BORDER_COLOR);
return color == null ? null : color.toString();
@@ -387,176 +233,6 @@ public class WXStyle implements Map<String, Object>,Cloneable {
return borderStyle == null ? null : borderStyle.toString();
}
- @Deprecated
- public float getMargin(){
- return WXUtils.getFloat(get(Constants.Name.MARGIN));
- }
-
- @Deprecated
- public float getPadding(){
- return WXUtils.getFloat(get(Constants.Name.PADDING));
- }
-
- public float getMargin(int viewport){
- return WXUtils.getFloatByViewport(get(Constants.Name.MARGIN), viewport);
- }
-
- public float getPadding(int viewport){
- return WXUtils.getFloatByViewport(get(Constants.Name.PADDING), viewport);
- }
-
- /*
- * margin
- **/
- public float getMarginTop() {
- float temp = WXUtils.getFloat(get(Constants.Name.MARGIN_TOP));
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloat(get(Constants.Name.MARGIN));
- }
- return temp;
- }
-
- public float getMarginLeft() {
- float temp = WXUtils.getFloat(get(Constants.Name.MARGIN_LEFT));
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloat(get(Constants.Name.MARGIN));
- }
- return temp;
- }
-
- public float getMarginRight() {
- float temp = WXUtils.getFloat(get(Constants.Name.MARGIN_RIGHT));
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloat(get(Constants.Name.MARGIN));
- }
- return temp;
- }
-
- public float getMarginBottom() {
- float temp = WXUtils.getFloat(get(Constants.Name.MARGIN_BOTTOM));
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloat(get(Constants.Name.MARGIN));
- }
- return temp;
- }
-
- /*
- * margin
- **/
- public float getMarginTop(int viewport) {
- float temp = WXUtils.getFloatByViewport(get(Constants.Name.MARGIN_TOP), viewport);
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloatByViewport(get(Constants.Name.MARGIN), viewport);
- }
- return temp;
- }
-
- public float getMarginLeft(int viewport) {
- float temp = WXUtils.getFloatByViewport(get(Constants.Name.MARGIN_LEFT), viewport);
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloatByViewport(get(Constants.Name.MARGIN), viewport);
- }
- return temp;
- }
-
- public float getMarginRight(int viewport) {
- float temp = WXUtils.getFloatByViewport(get(Constants.Name.MARGIN_RIGHT), viewport);
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloatByViewport(get(Constants.Name.MARGIN), viewport);
- }
- return temp;
- }
-
- public float getMarginBottom(int viewport) {
- float temp = WXUtils.getFloatByViewport(get(Constants.Name.MARGIN_BOTTOM), viewport);
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloatByViewport(get(Constants.Name.MARGIN), viewport);
- }
- return temp;
- }
-
- /*
- * padding
- **/
- public float getPaddingTop() {
- float temp = WXUtils.getFloat(get(Constants.Name.PADDING_TOP));
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloat(get(Constants.Name.PADDING));
- }
- return temp;
- }
-
- public float getPaddingLeft() {
- float temp = WXUtils.getFloat(get(Constants.Name.PADDING_LEFT));
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloat(get(Constants.Name.PADDING));
- }
- return temp;
- }
-
- public float getPaddingRight() {
- float temp = WXUtils.getFloat(get(Constants.Name.PADDING_RIGHT));
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloat(get(Constants.Name.PADDING));
- }
- return temp;
- }
-
- public float getPaddingBottom() {
- float temp = WXUtils.getFloat(get(Constants.Name.PADDING_BOTTOM));
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloat(get(Constants.Name.PADDING));
- }
- return temp;
- }
-
-
- /*
- * padding
- **/
- public float getPaddingTop(int viewport) {
- float temp = WXUtils.getFloatByViewport(get(Constants.Name.PADDING_TOP), viewport);
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloatByViewport(get(Constants.Name.PADDING), viewport);
- }
- return temp;
- }
-
- public float getPaddingLeft(int viewport) {
- float temp = WXUtils.getFloatByViewport(get(Constants.Name.PADDING_LEFT), viewport);
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloatByViewport(get(Constants.Name.PADDING), viewport);
- }
- return temp;
- }
-
- public float getPaddingRight(int viewport) {
- float temp = WXUtils.getFloatByViewport(get(Constants.Name.PADDING_RIGHT), viewport);
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloatByViewport(get(Constants.Name.PADDING), viewport);
- }
- return temp;
- }
-
- public float getPaddingBottom(int viewport) {
- float temp = WXUtils.getFloatByViewport(get(Constants.Name.PADDING_BOTTOM), viewport);
- if (WXUtils.isUndefined(temp)) {
- temp = WXUtils.getFloatByViewport(get(Constants.Name.PADDING), viewport);
- }
- return temp;
- }
-
- /*
- * position
- **/
- public CSSPositionType getPosition() {
- Object position = get(Constants.Name.POSITION);
- if (position == null) {
- return CSSPositionType.RELATIVE;
- }
- return CSSPositionTypeConvert.convert(position.toString().trim());
- }
-
public boolean isSticky() {
Object position = get(Constants.Name.POSITION);
if (position == null) {
@@ -574,35 +250,35 @@ public class WXStyle implements Map<String, Object>,Cloneable {
}
public float getLeft() {
- return WXUtils.getFloat(get(Constants.Name.LEFT));
- }
-
- public float getTop() {
- return WXUtils.getFloat(get(Constants.Name.TOP));
+ float temp = WXUtils.getFloat(get(Constants.Name.LEFT));
+ if (WXUtils.isUndefined(temp)) {
+ return Float.NaN;
+ }
+ return temp;
}
public float getRight() {
- return WXUtils.getFloat(get(Constants.Name.RIGHT));
- }
-
- public float getBottom() {
- return WXUtils.getFloat(get(Constants.Name.BOTTOM));
- }
-
- public float getLeft(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.LEFT), viewport);
- }
-
- public float getTop(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.TOP), viewport);
+ float temp = WXUtils.getFloat(get(Constants.Name.RIGHT));
+ if (WXUtils.isUndefined(temp)) {
+ return Float.NaN;
+ }
+ return temp;
}
- public float getRight(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.RIGHT), viewport);
+ public float getTop() {
+ float temp = WXUtils.getFloat(get(Constants.Name.TOP));
+ if (WXUtils.isUndefined(temp)) {
+ return Float.NaN;
+ }
+ return temp;
}
- public float getBottom(int viewport) {
- return WXUtils.getFloatByViewport(get(Constants.Name.BOTTOM), viewport);
+ public float getBottom() {
+ float temp = WXUtils.getFloat(get(Constants.Name.BOTTOM));
+ if (WXUtils.isUndefined(temp)) {
+ return Float.NaN;
+ }
+ return temp;
}
/*
@@ -700,48 +376,59 @@ public class WXStyle implements Map<String, Object>,Cloneable {
public void putAll(Map<? extends String, ?> map, boolean byPesudo) {
this.mStyles.putAll(map);
if (!byPesudo) {
- this.mPesudoResetStyleMap.putAll(map);
processPesudoClasses(map);
}
}
public Map<String, Object> getPesudoResetStyles() {
+ if(mPesudoResetStyleMap == null){
+ mPesudoResetStyleMap = new ArrayMap<>();
+ }
return mPesudoResetStyleMap;
}
public Map<String, Map<String, Object>> getPesudoStyles() {
+ if(mPesudoStyleMap == null){
+ mPesudoStyleMap = new ArrayMap<>();
+ }
return mPesudoStyleMap;
}
<T extends String, V> void processPesudoClasses(Map<T, V> styles) {
- Iterator<Map.Entry<T, V>> iterator = styles.entrySet().iterator();
- Map<String, Map<String, Object>> pesudoStyleMap = mPesudoStyleMap;
- while (iterator.hasNext()) {
- Map.Entry<T, V> entry = iterator.next();
+ Map<String, Object> tempMap = null;
+ for(Map.Entry<T, V> entry:styles.entrySet()){
//Key Format: "style-prop:pesudo_clz1:pesudo_clz2"
String key = entry.getKey();
int i;
if ((i = key.indexOf(":")) > 0) {
+ initPesudoMapsIfNeed(styles);
String clzName = key.substring(i);
if (clzName.equals(Constants.PSEUDO.ENABLED)) {
//enabled, use as regular style
String styleKey = key.substring(0, i);
- this.mStyles.put(styleKey, entry.getValue());
- this.mPesudoResetStyleMap.put(styleKey, entry.getValue());
+ if(tempMap == null){
+ tempMap = new ArrayMap<>();
+ }
+ tempMap.put(styleKey, entry.getValue());
+ mPesudoResetStyleMap.put(styleKey, entry.getValue());
continue;
} else {
clzName = clzName.replace(Constants.PSEUDO.ENABLED, "");//remove ':enabled' which is ignored
}
- Map<String, Object> stylesMap = pesudoStyleMap.get(clzName);
+ Map<String, Object> stylesMap = mPesudoStyleMap.get(clzName);
if (stylesMap == null) {
stylesMap = new ArrayMap<>();
- pesudoStyleMap.put(clzName, stylesMap);
+ mPesudoStyleMap.put(clzName, stylesMap);
}
stylesMap.put(key.substring(0, i), entry.getValue());
}
}
+
+ if (tempMap != null && !tempMap.isEmpty()) {
+ this.mStyles.putAll(tempMap);
+ }
}
@Override
@@ -764,18 +451,34 @@ public class WXStyle implements Map<String, Object>,Cloneable {
protected WXStyle clone(){
WXStyle style = new WXStyle();
style.mStyles.putAll(this.mStyles);
- style.mBindingStyle = mBindingStyle;
- for(Entry<String,Map<String,Object>> entry:this.mPesudoStyleMap.entrySet()){
- Map<String,Object> valueClone = new ArrayMap<>();
- valueClone.putAll(entry.getValue());
- style.mPesudoStyleMap.put(entry.getKey(),valueClone);
+ if(mPesudoStyleMap != null) {
+ style.mPesudoStyleMap = new ArrayMap<>();
+ for (Entry<String, Map<String, Object>> entry : this.mPesudoStyleMap.entrySet()) {
+ Map<String, Object> valueClone = new ArrayMap<>();
+ valueClone.putAll(entry.getValue());
+ style.mPesudoStyleMap.put(entry.getKey(), valueClone);
+ }
}
- style.mPesudoResetStyleMap.putAll(this.mPesudoResetStyleMap);
+ if(mPesudoResetStyleMap!=null) {
+ style.mPesudoResetStyleMap = new ArrayMap<>();
+ style.mPesudoResetStyleMap.putAll(this.mPesudoResetStyleMap);
+ }
return style;
}
+ private void initPesudoMapsIfNeed(Map<? extends String, ?> styles){
+ if(mPesudoStyleMap == null){
+ mPesudoStyleMap = new ArrayMap<>();
+ }
+ if(mPesudoResetStyleMap == null){
+ mPesudoResetStyleMap = new ArrayMap<>();
+ }
+ if(mPesudoResetStyleMap.isEmpty()){
+ mPesudoResetStyleMap.putAll(styles);
+ }
+ }
/**
* filter dynamic state ment
@@ -800,12 +503,12 @@ public class WXStyle implements Map<String, Object>,Cloneable {
* */
private boolean filterBindingStyle(String key, Object value) {
if(ELUtils.isBinding(value)){
- if(mBindingStyle == null){
- mBindingStyle = new ArrayMap<String, Object>();
- }
- value = ELUtils.bindingBlock(value);
- mBindingStyle.put(key, value);
- return true;
+ if(mBindingStyle == null){
+ mBindingStyle = new ArrayMap<String, Object>();
+ }
+ value = ELUtils.bindingBlock(value);
+ mBindingStyle.put(key, value);
+ return true;
}
return false;
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXSwitchDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXSwitchDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXSwitchDomObject.java
deleted file mode 100644
index b335f31..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXSwitchDomObject.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom;
-
-import android.content.Context;
-import android.view.View.MeasureSpec;
-import com.taobao.weex.dom.flex.CSSNode;
-import com.taobao.weex.dom.flex.MeasureOutput;
-import com.taobao.weex.ui.view.WXSwitchView;
-import com.taobao.weex.utils.WXLogUtils;
-
-public class WXSwitchDomObject extends WXDomObject {
-
- private static final MeasureFunction SWITCH_MEASURE_FUNCTION = new MeasureFunction() {
-
- @Override
- public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
- try {
- Context context=((WXDomObject) node).getDomContext().getUIContext();
- WXSwitchView wxSwitchView = new WXSwitchView(context);
- int widthSpec, heightSpec;
- heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
- if (Float.isNaN(width)) {
- widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
- } else {
- widthSpec = MeasureSpec.makeMeasureSpec((int) width, MeasureSpec.AT_MOST);
- }
- wxSwitchView.measure(widthSpec, heightSpec);
- measureOutput.width = wxSwitchView.getMeasuredWidth();
- measureOutput.height = wxSwitchView.getMeasuredHeight();
- } catch (RuntimeException e) {
- WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
- }
- }
- };
-
- public WXSwitchDomObject() {
- super();
- setMeasureFunction(SWITCH_MEASURE_FUNCTION);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXTextDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXTextDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXTextDomObject.java
deleted file mode 100644
index f276924..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXTextDomObject.java
+++ /dev/null
@@ -1,601 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.graphics.Canvas;
-import android.graphics.Typeface;
-import android.os.Build;
-import android.os.Looper;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.v4.content.LocalBroadcastManager;
-import android.text.Editable;
-import android.text.Layout;
-import android.text.Spannable;
-import android.text.SpannableString;
-import android.text.SpannableStringBuilder;
-import android.text.Spanned;
-import android.text.SpannedString;
-import android.text.StaticLayout;
-import android.text.TextPaint;
-import android.text.TextUtils;
-import android.text.style.AbsoluteSizeSpan;
-import android.text.style.AlignmentSpan;
-import android.text.style.ForegroundColorSpan;
-
-import com.taobao.weex.WXEnvironment;
-import com.taobao.weex.WXSDKManager;
-import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.flex.CSSConstants;
-import com.taobao.weex.dom.flex.CSSNode;
-import com.taobao.weex.dom.flex.FloatUtil;
-import com.taobao.weex.dom.flex.MeasureOutput;
-import com.taobao.weex.dom.text.FontBroadcastReceiver;
-import com.taobao.weex.ui.component.WXText;
-import com.taobao.weex.ui.component.WXTextDecoration;
-import com.taobao.weex.utils.StaticLayoutProxy;
-import com.taobao.weex.utils.TypefaceUtil;
-import com.taobao.weex.utils.WXDomUtils;
-import com.taobao.weex.utils.WXLogUtils;
-import com.taobao.weex.utils.WXResourceUtils;
-import com.taobao.weex.utils.WXUtils;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicReference;
-
-import static com.taobao.weex.dom.WXStyle.UNSET;
-
-/**
- * Class for calculating a given text's height and width. The calculating of width and height of
- * text is done by {@link Layout}.
- */
-public class WXTextDomObject extends WXDomObject {
-
- /**
- * Command object for setSpan
- */
- private static class SetSpanOperation {
-
- protected final int start, end, flag;
- protected final Object what;
-
- SetSpanOperation(int start, int end, Object what) {
- this(start, end, what, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
- }
-
- SetSpanOperation(int start, int end, Object what, int flag) {
- this.start = start;
- this.end = end;
- this.what = what;
- this.flag = flag;
- }
-
- public void execute(Spannable sb) {
- sb.setSpan(what, start, end, flag);
- }
- }
-
- /**
- * Object for calculating text's width and height. This class is an anonymous class of
- * implementing {@link com.taobao.weex.dom.flex.CSSNode.MeasureFunction}
- */
- /** package **/ static final CSSNode.MeasureFunction TEXT_MEASURE_FUNCTION = new CSSNode.MeasureFunction() {
- @Override
- public void measure(CSSNode node, float width, @NonNull MeasureOutput measureOutput) {
- WXTextDomObject textDomObject = (WXTextDomObject) node;
- if (CSSConstants.isUndefined(width)) {
- width = node.cssstyle.maxWidth;
- }
- boolean forceWidth = false;
- if(width > 0){
- if(node.getParent() != null && textDomObject.mAlignment == Layout.Alignment.ALIGN_CENTER){
- forceWidth = FloatUtil.floatsEqual(width, node.getParent().getLayoutWidth());
- }
- }
- textDomObject.hasBeenMeasured = true;
- width = textDomObject.getTextWidth(textDomObject.mTextPaint,width, forceWidth);
- if(width > 0 && textDomObject.mText != null) {
- textDomObject.layout = textDomObject.createLayout(width, true, null);
- textDomObject.previousWidth = textDomObject.layout.getWidth();
- measureOutput.height = textDomObject.layout.getHeight();
- measureOutput.width = textDomObject.previousWidth;
- }else{
- measureOutput.height = 0;
- measureOutput.width = 0;
- }
- }
- };
-
-
- private static final Canvas DUMMY_CANVAS = new Canvas();
- private static final String ELLIPSIS = "\u2026";
- private boolean mIsColorSet = false;
- private boolean hasBeenMeasured = false;
- private int mColor;
- /**
- * mFontStyle can be {@link Typeface#NORMAL} or {@link Typeface#ITALIC}.
- */
- private int mFontStyle = UNSET;
- /**
- * mFontWeight can be {@link Typeface#NORMAL} or {@link Typeface#BOLD}.
- */
- private int mFontWeight = UNSET;
- private int mNumberOfLines = UNSET;
- private int mFontSize = UNSET;
- private int mLineHeight = UNSET;
- private boolean mIncludeFontPadding = false;
- private float previousWidth = Float.NaN;
- private String mFontFamily = WXEnvironment.getGlobalFontFamilyName();
- private String mText = null;
- private TextUtils.TruncateAt textOverflow;
- private Layout.Alignment mAlignment;
- private WXTextDecoration mTextDecoration = WXTextDecoration.NONE;
- private TextPaint mTextPaint = new TextPaint();
- private @Nullable Spanned spanned;
- private @Nullable Layout layout;
- private AtomicReference<Layout> atomicReference = new AtomicReference<>();
-
- private BroadcastReceiver mTypefaceObserver;
-
- /**
- * Create an instance of current class, and set {@link #TEXT_MEASURE_FUNCTION} as the
- * measureFunction
- * @see CSSNode#setMeasureFunction(MeasureFunction)
- */
- public WXTextDomObject() {
- super();
- mTextPaint.setFlags(TextPaint.ANTI_ALIAS_FLAG);
- setMeasureFunction(TEXT_MEASURE_FUNCTION);
- registerTypefaceObserverIfNeed(WXStyle.getFontFamily(getStyles()));
- }
-
- public TextPaint getTextPaint() {
- return mTextPaint;
- }
-
- /**
- * Prepare the text {@link Spanned} for calculating text's size. This is done by setting
- * various text span to the text.
- * @see android.text.style.CharacterStyle
- */
- @Override
- public void layoutBefore() {
- hasBeenMeasured = false;
- updateStyleAndText();
- spanned = createSpanned(mText);
- if(hasNewLayout()){
- if(WXEnvironment.isApkDebugable()) {
- WXLogUtils.d("Previous csslayout was ignored! markLayoutSeen() never called");
- }
- markUpdateSeen();
- }
- super.dirty();
- super.layoutBefore();
- }
-
- @Override
- public void layoutAfter() {
- if (hasBeenMeasured) {
- if (layout != null &&
- !FloatUtil.floatsEqual(WXDomUtils.getContentWidth(this), previousWidth)) {
- recalculateLayout();
- }
- } else {
- updateStyleAndText();
- recalculateLayout();
- }
- hasBeenMeasured = false;
- if (layout != null && !layout.equals(atomicReference.get()) &&
- Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- if(Thread.currentThread() != Looper.getMainLooper().getThread()){
- warmUpTextLayoutCache(layout);
- }
- }
- swap();
- super.layoutAfter();
- }
-
- @Override
- public Layout getExtra() {
- return atomicReference.get();
- }
-
- @Override
- public void updateAttr(Map<String, Object> attrs) {
- swap();
- super.updateAttr(attrs);
- if (attrs.containsKey(Constants.Name.VALUE)) {
- mText = WXAttr.getValue(attrs);
- }
- }
-
- @Override
- public void updateStyle(Map<String, Object> styles) {
- swap();
- super.updateStyle(styles);
- updateStyleImp(styles);
- }
-
- @Override
- public WXTextDomObject clone() {
- if(isCloneThis()){
- return this;
- }
- WXTextDomObject dom = null;
- try {
- dom = new WXTextDomObject();
- copyFields(dom);
- dom.hasBeenMeasured = hasBeenMeasured;
- dom.atomicReference = new AtomicReference<>(atomicReference.get());
- } catch (Exception e) {
- if (WXEnvironment.isApkDebugable()) {
- WXLogUtils.e("WXTextDomObject clone error: ", e);
- }
- }
- if (dom != null) {
- dom.spanned = spanned;
- }
- return dom;
- }
-
- /**
- * RecalculateLayout.
- */
- private void recalculateLayout() {
- float contentWidth = WXDomUtils.getContentWidth(this);
- if (contentWidth > 0) {
- spanned = createSpanned(mText);
- if(mText != null){
- layout = createLayout(contentWidth, true, layout);
- previousWidth = layout.getWidth();
- }else{
- previousWidth = 0;
- }
- }
- }
-
- /**
- * Update style and text.
- */
- private void updateStyleAndText() {
- updateStyleImp(getStyles());
- if (getAttrs() != null && getAttrs().containsKey(Constants.Name.INCLUDE_FONT_PADDING)) {
- mIncludeFontPadding = WXUtils.getBoolean(getAttrs().get(Constants.Name.INCLUDE_FONT_PADDING), false);
- }
- mText = WXAttr.getValue(getAttrs());
- }
-
- /**
- * Record the property according to the given style
- * @param style the give style.
- */
- private void updateStyleImp(Map<String, Object> style) {
- if (style != null) {
- if (style.containsKey(Constants.Name.LINES)) {
- int lines = WXStyle.getLines(style);
- mNumberOfLines = lines > 0 ? lines : UNSET;
- }
- if (style.containsKey(Constants.Name.FONT_SIZE)) {
- mFontSize = WXStyle.getFontSize(style,getViewPortWidth());
- }
- if (style.containsKey(Constants.Name.FONT_WEIGHT)) {
- mFontWeight = WXStyle.getFontWeight(style);
- }
- if (style.containsKey(Constants.Name.FONT_STYLE)) {
- mFontStyle = WXStyle.getFontStyle(style);
- }
- if (style.containsKey(Constants.Name.COLOR)) {
- mColor = WXResourceUtils.getColor(WXStyle.getTextColor(style));
- mIsColorSet = mColor != Integer.MIN_VALUE;
- }
- if (style.containsKey(Constants.Name.TEXT_DECORATION)) {
- mTextDecoration = WXStyle.getTextDecoration(style);
- }
- if (style.containsKey(Constants.Name.FONT_FAMILY)) {
- mFontFamily = WXStyle.getFontFamily(style);
- }
- mAlignment = WXStyle.getTextAlignment(style);
- textOverflow = WXStyle.getTextOverflow(style);
- int lineHeight = WXStyle.getLineHeight(style,getViewPortWidth());
- if (lineHeight != UNSET) {
- mLineHeight = lineHeight;
- }
- registerTypefaceObserverIfNeed(mFontFamily);
- }
- }
-
- /**
- * Update layout according to {@link #mText} and span
- * @param width the specified width.
- * @param forceWidth If true, force the text width to the specified width, otherwise, text width
- * may equals to or be smaller than the specified width.
- * @param previousLayout the result of previous layout, could be null.
- */
- private
- @NonNull
- Layout createLayout(float width, boolean forceWidth, @Nullable Layout previousLayout) {
- float textWidth;
- textWidth = getTextWidth(mTextPaint, width, forceWidth);
- Layout layout;
- if (!FloatUtil.floatsEqual(previousWidth, textWidth) || previousLayout == null) {
- boolean forceRtl = false;
- Object direction = getStyles().get(Constants.Name.DIRECTION);
- if (direction != null && "text".equals(mType)) {
- forceRtl = direction.equals(Constants.Name.RTL);
- }
- layout = StaticLayoutProxy.create(spanned, mTextPaint, (int) Math.ceil(textWidth),
- Layout.Alignment.ALIGN_NORMAL, 1, 0, mIncludeFontPadding, forceRtl);
- } else {
- layout = previousLayout;
- }
- if (mNumberOfLines != UNSET && mNumberOfLines > 0 && mNumberOfLines < layout.getLineCount()) {
- int lastLineStart, lastLineEnd;
- lastLineStart = layout.getLineStart(mNumberOfLines - 1);
- lastLineEnd = layout.getLineEnd(mNumberOfLines - 1);
- if (lastLineStart < lastLineEnd) {
- SpannableStringBuilder builder = null;
- if(lastLineStart > 0) {
- builder = new SpannableStringBuilder(spanned.subSequence(0, lastLineStart));
- }else{
- builder = new SpannableStringBuilder();
- }
- Editable lastLine = new SpannableStringBuilder(spanned.subSequence(lastLineStart, lastLineEnd));
- builder.append(truncate(lastLine, mTextPaint, (int) Math.ceil(textWidth), textOverflow));
- adjustSpansRange(spanned, builder);
- spanned = builder;
- return new StaticLayout(spanned, mTextPaint, (int) Math.ceil(textWidth),
- Layout.Alignment.ALIGN_NORMAL, 1, 0, mIncludeFontPadding);
- }
- }
- return layout;
- }
-
- /**
- * Truncate the source span to the specified lines.
- * Caller of this method must ensure that the lines of text is <strong>greater than desired lines and need truncate</strong>.
- * Otherwise, unexpected behavior may happen.
- * @param source The source span.
- * @param paint the textPaint
- * @param desired specified lines.
- * @param truncateAt truncate method, null value means clipping overflow text directly, non-null value means using ellipsis strategy to clip
- * @return The spans after clipped.
- */
- private
- @NonNull
- Spanned truncate(@Nullable Editable source, @NonNull TextPaint paint,
- int desired, @Nullable TextUtils.TruncateAt truncateAt) {
- Spanned ret = new SpannedString("");
- if (!TextUtils.isEmpty(source) && source.length() > 0) {
- if (truncateAt != null) {
- source.append(ELLIPSIS);
- Object[] spans = source.getSpans(0, source.length(), Object.class);
- for(Object span:spans){
- int start = source.getSpanStart(span);
- int end = source.getSpanEnd(span);
- if(start == 0 && end == source.length()-1){
- source.removeSpan(span);
- source.setSpan(span, 0, source.length(), source.getSpanFlags(span));
- }
- }
- }
-
- StaticLayout layout;
- int startOffset;
-
- while (source.length() > 1) {
- startOffset = source.length() -1;
- if (truncateAt != null) {
- startOffset -= 1;
- }
- source.delete(startOffset, startOffset+1);
- layout = new StaticLayout(source, paint, desired, Layout.Alignment.ALIGN_NORMAL, 1, 0, mIncludeFontPadding);
- if (layout.getLineCount() <= 1) {
- ret = source;
- break;
- }
- }
- }
- return ret;
- }
-
- /**
- * Adjust span range after truncate due to the wrong span range during span copy and slicing.
- * @param beforeTruncate The span before truncate
- * @param afterTruncate The span after truncate
- */
- private void adjustSpansRange(@NonNull Spanned beforeTruncate, @NonNull Spannable afterTruncate){
- Object[] spans = beforeTruncate.getSpans(0, beforeTruncate.length(), Object.class);
- for(Object span:spans){
- int start = beforeTruncate.getSpanStart(span);
- int end = beforeTruncate.getSpanEnd(span);
- if(start == 0 && end == beforeTruncate.length()){
- afterTruncate.removeSpan(span);
- afterTruncate.setSpan(span, 0, afterTruncate.length(), beforeTruncate.getSpanFlags(span));
- }
- }
- }
-
- /**
- * Get text width according to constrain of outerWidth with and forceToDesired
- * @param textPaint paint used to measure text
- * @param outerWidth the width that css-layout desired.
- * @param forceToDesired if set true, the return value will be outerWidth, no matter what the width
- * of text is.
- * @return if forceToDesired is false, it will be the minimum value of the width of text and
- * outerWidth in case of outerWidth is defined, in other case, it will be outer width.
- */
- float getTextWidth(TextPaint textPaint,float outerWidth, boolean forceToDesired) {
- if(mText == null){
- if(forceToDesired){
- return outerWidth;
- }
- return 0;
- }
- float textWidth;
- if (forceToDesired) {
- textWidth = outerWidth;
- } else {
- float desiredWidth = Layout.getDesiredWidth(spanned, textPaint);
- if (CSSConstants.isUndefined(outerWidth) || desiredWidth < outerWidth) {
- textWidth = desiredWidth;
- } else {
- textWidth = outerWidth;
- }
- }
- return textWidth;
- }
-
- /**
- * Update {@link #spanned} according to the give charSequence and styles
- * @param text the give raw text.
- * @return an Spanned contains text and spans
- */
- protected
- @NonNull
- Spanned createSpanned(String text) {
- if (!TextUtils.isEmpty(text)) {
- SpannableString spannable = new SpannableString(text);
- updateSpannable(spannable, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
- return spannable;
- }
- return new SpannableString("");
- }
-
- protected void updateSpannable(Spannable spannable, int spanFlag) {
- List<SetSpanOperation> ops = createSetSpanOperation(spannable.length(), spanFlag);
- if (mFontSize == UNSET) {
- ops.add(new SetSpanOperation(0, spannable.length(),
- new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE), spanFlag));
- }
- Collections.reverse(ops);
- for (SetSpanOperation op : ops) {
- op.execute(spannable);
- }
- }
-
- /**
- * Create a task list which contains {@link SetSpanOperation}. The task list will be executed
- * in other method.
- * @param end the end character of the text.
- * @return a task list which contains {@link SetSpanOperation}.
- */
- private List<SetSpanOperation> createSetSpanOperation(int end, int spanFlag) {
- List<SetSpanOperation> ops = new LinkedList<>();
- int start = 0;
- if (end >= start) {
- if (mTextDecoration == WXTextDecoration.UNDERLINE || mTextDecoration == WXTextDecoration.LINETHROUGH) {
- ops.add(new SetSpanOperation(start, end, new TextDecorationSpan(mTextDecoration), spanFlag));
- }
- if (mIsColorSet) {
- ops.add(new SetSpanOperation(start, end,
- new ForegroundColorSpan(mColor), spanFlag));
- }
- if (mFontSize != UNSET) {
- ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(mFontSize), spanFlag));
- }
- if (mFontStyle != UNSET
- || mFontWeight != UNSET
- || mFontFamily != null) {
- ops.add(new SetSpanOperation(start, end,
- new WXCustomStyleSpan(mFontStyle, mFontWeight, mFontFamily),
- spanFlag));
- }
- ops.add(new SetSpanOperation(start, end, new AlignmentSpan.Standard(mAlignment), spanFlag));
- if (mLineHeight != UNSET) {
- ops.add(new SetSpanOperation(start, end, new WXLineHeightSpan(mLineHeight), spanFlag));
- }
- }
- return ops;
- }
-
- /**
- * Move the reference of current layout to the {@link AtomicReference} for further use,
- * then clear current layout.
- */
- private void swap() {
- if (layout != null) {
- atomicReference.set(layout);
- layout = null;
- mTextPaint = new TextPaint(mTextPaint);
- }
- hasBeenMeasured = false;
- }
-
- /**
- * As warming up TextLayoutCache done in the DOM thread may manipulate UI operation,
- there may be some exception, in which case the exception is ignored. After all,
- this is just a warm up operation.
- * @return false for warm up failure, otherwise returns true.
- */
- private boolean warmUpTextLayoutCache(Layout layout) {
- boolean result;
- try {
- layout.draw(DUMMY_CANVAS);
- result = true;
- } catch (Exception e) {
- WXLogUtils.eTag(TAG, e);
- result = false;
- }
- return result;
- }
-
- @Override
- public void destroy() {
- if (WXEnvironment.getApplication() != null && mTypefaceObserver != null) {
- WXLogUtils.d("WXText", "Unregister the typeface observer");
- LocalBroadcastManager.getInstance(WXEnvironment.getApplication()).unregisterReceiver(mTypefaceObserver);
- mTypefaceObserver = null;
- }
- super.destroy();
- }
-
- @Override
- protected void finalize() throws Throwable {
- if(!isDestroy()){
- destroy();
- }
- super.finalize();
- }
-
- private void registerTypefaceObserverIfNeed(String desiredFontFamily) {
- if(TextUtils.isEmpty(desiredFontFamily)){
- return;
- }
- if (WXEnvironment.getApplication() == null) {
- WXLogUtils.w("WXText", "ApplicationContent is null on register typeface observer");
- return;
- }
- mFontFamily = desiredFontFamily;
- if (mTypefaceObserver != null) {
- return;
- }
- mTypefaceObserver = new FontBroadcastReceiver(this, mFontFamily);
- if(WXEnvironment.isApkDebugable()) {
- WXLogUtils.d("WXText", "Font family register " + desiredFontFamily + " is available" + getRef());
- }
- LocalBroadcastManager.getInstance(WXEnvironment.getApplication()).registerReceiver(mTypefaceObserver, new IntentFilter(TypefaceUtil.ACTION_TYPE_FACE_AVAILABLE));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/action/AbstractAddElementAction.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/action/AbstractAddElementAction.java b/android/sdk/src/main/java/com/taobao/weex/dom/action/AbstractAddElementAction.java
deleted file mode 100644
index 08ca2e3..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/action/AbstractAddElementAction.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom.action;
-
-
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weex.WXEnvironment;
-import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.adapter.IWXUserTrackAdapter;
-import com.taobao.weex.common.WXErrorCode;
-import com.taobao.weex.dom.DOMAction;
-import com.taobao.weex.dom.DOMActionContext;
-import com.taobao.weex.dom.RenderAction;
-import com.taobao.weex.dom.WXCellDomObject;
-import com.taobao.weex.dom.WXDomObject;
-import com.taobao.weex.tracing.Stopwatch;
-import com.taobao.weex.tracing.WXTracing;
-import com.taobao.weex.ui.component.WXBasicComponentType;
-import com.taobao.weex.ui.component.WXComponent;
-import com.taobao.weex.ui.component.WXComponentFactory;
-import com.taobao.weex.ui.component.WXVContainer;
-import com.taobao.weex.utils.WXExceptionUtils;
-import com.taobao.weex.utils.WXLogUtils;
-
-import java.util.List;
-
-/**
- * Created by sospartan on 22/02/2017.
- */
-
-public abstract class AbstractAddElementAction extends TraceableAction implements DOMAction, RenderAction {
-
- protected WXComponent generateComponentTree(DOMActionContext context, WXDomObject dom, WXVContainer parent) {
- if (dom == null) {
- return null;
- }
- long startNanos = System.nanoTime();
- WXComponent component = WXComponentFactory.newInstance(context.getInstance(), dom, parent);
- if (component != null) {
- component.mTraceInfo.domThreadStart = dom.mDomThreadTimestamp;
- component.mTraceInfo.rootEventId = mTracingEventId;
- component.mTraceInfo.domQueueTime = mDomQueueTime;
- }
-
- context.registerComponent(dom.getRef(), component);
- if (component instanceof WXVContainer) {
- WXVContainer parentC = (WXVContainer) component;
- int count = dom.childCount();
- WXDomObject child = null;
- for (int i = 0; i < count; ++i) {
- child = dom.getChild(i);
- if (child != null) {
- WXComponent createdComponent = generateComponentTree(context, child, parentC);
- if(createdComponent != null) {
- parentC.addChild(createdComponent);
- }else{
- WXLogUtils.e("[generateComponentTree] " + getStatementName() + " create dom component failed name " + child.getType());
- WXExceptionUtils.commitCriticalExceptionRT(context.getInstanceId(), getErrorCode(), "generateComponentTree", " create dom component failed name " + child.getType(), null);
- }
- }
- }
- }
- if (component != null) {
- component.mTraceInfo.domThreadNanos = System.nanoTime() - startNanos;
- }
- return component;
- }
-
- /**
- * Add DOM node.
- */
- protected void addDomInternal(DOMActionContext context, JSONObject dom) {
- if (context.isDestory()) {
- return;
- }
-
- WXSDKInstance instance = context.getInstance();
- if (instance == null) {
- return;
- }
- String errMsg = getErrorMsg();
-
- if (dom == null) {
-// instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
- WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), getErrorCode(), "addDomInternal", errMsg, null);
- }
-
- //only non-root has parent.
- Stopwatch.tick();
- WXDomObject domObject = WXDomObject.parse(dom, instance, null);
- Stopwatch.split("parseDomObject");
-
- if (domObject == null || context.getDomByRef(domObject.getRef()) != null) {
- WXLogUtils.e("[DOMActionContextImpl] " + getStatementName() + " error,DOM object is null or already registered!!");
-// instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
- WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), getErrorCode(), "addDomInternal", errMsg, null);
- return;
- }
- appendDomToTree(context, domObject);
- Stopwatch.split("appendDomToTree");
-
- int maxDomDep = domObject.traverseTree(
- context.getAddDOMConsumer(),
- context.getApplyStyleConsumer()
- );
-
- if (instance.getMaxDomDeep()< maxDomDep){
- instance.setMaxDomDeep(maxDomDep);
- }
-
- Stopwatch.split("traverseTree");
-
-
- //Create component in dom thread
- WXComponent component = createComponent(context, domObject);
- if (component == null) {
-// instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
- //stop redner, some fatal happened.
-// errMsg = "component == null";
-// WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(), errCode, "addDomInternal", errMsg, null);
- return;
- }
- Stopwatch.split("createComponent");
-
- boolean needAddDomInfo = true;
- if(domObject.getType().equals(WXBasicComponentType.CELL_SLOT)
- && domObject instanceof WXCellDomObject){
- needAddDomInfo = false;
- }
-
- if(needAddDomInfo) {
- context.addDomInfo(domObject.getRef(), component);
- }
-
-
- context.postRenderTask(this);
-
- addAnimationForDomTree(context, domObject);
-
-// instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
- if (WXTracing.isAvailable()) {
- List<Stopwatch.ProcessEvent> events = Stopwatch.getProcessEvents();
- for (Stopwatch.ProcessEvent event : events) {
- submitPerformance(event.fname, "X", context.getInstanceId(), event.duration, event.startMillis, true);
- }
- }
- }
-
- public void addAnimationForDomTree(DOMActionContext context, WXDomObject domObject) {
- context.addAnimationForElement(domObject.getRef(), domObject.getStyles());
- for (int i = 0; i < domObject.childCount(); i++) {
- addAnimationForDomTree(context, domObject.getChild(i));
- }
- }
-
- protected abstract WXComponent createComponent(DOMActionContext context, WXDomObject domObject);
-
- protected abstract void appendDomToTree(DOMActionContext context, WXDomObject domObject);
-
- protected abstract String getStatementName();
-
- protected abstract WXErrorCode getErrorCode();
-
- protected abstract String getErrorMsg();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/action/AbstractLayoutFinishAction.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/action/AbstractLayoutFinishAction.java b/android/sdk/src/main/java/com/taobao/weex/dom/action/AbstractLayoutFinishAction.java
deleted file mode 100644
index 77c67df..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/action/AbstractLayoutFinishAction.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom.action;
-
-import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.adapter.IWXUserTrackAdapter;
-import com.taobao.weex.common.WXErrorCode;
-import com.taobao.weex.dom.DOMAction;
-import com.taobao.weex.dom.DOMActionContext;
-import com.taobao.weex.dom.RenderAction;
-import com.taobao.weex.dom.WXDomObject;
-
-/**
- * Created by sospartan on 02/03/2017.
- */
-abstract class AbstractLayoutFinishAction extends TraceableAction implements DOMAction, RenderAction {
-
- protected int mLayoutWidth;
- protected int mLayoutHeight;
-
- @Override
- public void executeDom(DOMActionContext context) {
- if (context.isDestory()) {
- return;
- }
-
- WXDomObject root = context.getDomByRef(WXDomObject.ROOT);
- if(root == null){
- return;
- }
- mLayoutHeight = (int)root.getLayoutHeight();
- mLayoutWidth = (int)root.getLayoutWidth();
- context.postRenderTask(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/action/Action.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/action/Action.java b/android/sdk/src/main/java/com/taobao/weex/dom/action/Action.java
deleted file mode 100644
index c29f2b5..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/action/Action.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom.action;
-
-/**
- * Created by sospartan on 16/03/2017.
- */
-
-public interface Action {
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/action/Actions.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/action/Actions.java b/android/sdk/src/main/java/com/taobao/weex/dom/action/Actions.java
deleted file mode 100644
index 3f464bc..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/action/Actions.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom.action;
-
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weex.bridge.Invoker;
-import com.taobao.weex.common.WXModule;
-import com.taobao.weex.dom.DOMAction;
-import com.taobao.weex.dom.RenderAction;
-import com.taobao.weex.ui.animation.WXAnimationBean;
-
-import static com.taobao.weex.dom.WXDomModule.ADD_ELEMENT;
-import static com.taobao.weex.dom.WXDomModule.ADD_EVENT;
-import static com.taobao.weex.dom.WXDomModule.ADD_RULE;
-import static com.taobao.weex.dom.WXDomModule.CREATE_BODY;
-import static com.taobao.weex.dom.WXDomModule.CREATE_FINISH;
-import static com.taobao.weex.dom.WXDomModule.GET_COMPONENT_RECT;
-import static com.taobao.weex.dom.WXDomModule.INVOKE_METHOD;
-import static com.taobao.weex.dom.WXDomModule.MOVE_ELEMENT;
-import static com.taobao.weex.dom.WXDomModule.REFRESH_FINISH;
-import static com.taobao.weex.dom.WXDomModule.REMOVE_ELEMENT;
-import static com.taobao.weex.dom.WXDomModule.REMOVE_EVENT;
-import static com.taobao.weex.dom.WXDomModule.SCROLL_TO_ELEMENT;
-import static com.taobao.weex.dom.WXDomModule.UPDATE_ATTRS;
-import static com.taobao.weex.dom.WXDomModule.UPDATE_COMPONENT_DATA;
-import static com.taobao.weex.dom.WXDomModule.UPDATE_FINISH;
-import static com.taobao.weex.dom.WXDomModule.UPDATE_STYLE;
-
-/**
- * Created by sospartan on 01/03/2017.
- */
-
-public class Actions {
-
- public static Action get(String actionName,JSONArray args){
- switch (actionName) {
- case CREATE_BODY:
- if (args == null) {
- return null;
- }
- return new CreateBodyAction(args.getJSONObject(0));
- case UPDATE_ATTRS:
- if (args == null) {
- return null;
- }
- return new UpdateAttributeAction(args.getString(0),args.getJSONObject(1));
- case UPDATE_STYLE:
- if (args == null) {
- return null;
- }
- return new UpdateStyleAction(args.getString(0),args.getJSONObject(1));
- case REMOVE_ELEMENT:
- if (args == null) {
- return null;
- }
- return new RemoveElementAction(args.getString(0));
- case ADD_ELEMENT:
- if (args == null) {
- return null;
- }
- return new AddElementAction(args.getJSONObject(1),args.getString(0),args.getInteger(2));
- case MOVE_ELEMENT:
- if (args == null) {
- return null;
- }
- return new MoveElementAction(args.getString(0),args.getString(1),args.getInteger(2));
- case ADD_EVENT:
- if (args == null) {
- return null;
- }
- return new AddEventAction(args.getString(0),args.get(1));
- case REMOVE_EVENT:
- if (args == null) {
- return null;
- }
- return new RemoveEventAction(args.getString(0),args.get(1));
- case CREATE_FINISH:
- return new CreateFinishAction();
- case REFRESH_FINISH:
- return new RefreshFinishAction();
- case UPDATE_FINISH:
- return new UpdateFinishAction();
- case SCROLL_TO_ELEMENT:
- if (args == null) {
- return null;
- }
- String ref = args.size() >= 1 ? args.getString(0) : null;
- JSONObject options = args.size() >= 2 ? args.getJSONObject(1) : null;
- return new ScrollToElementAction(ref, options);
- case ADD_RULE:
- if (args == null) {
- return null;
- }
- return new AddRuleAction(args.getString(0),args.getJSONObject(1));
- case GET_COMPONENT_RECT:
- if(args == null){
- return null;
- }
- return new GetComponentRectAction(args.getString(0),args.getString(1));
- case INVOKE_METHOD:
- if(args == null){
- return null;
- }
- return new InvokeMethodAction(args.getString(0),args.getString(1),args.getJSONArray(2));
- case UPDATE_COMPONENT_DATA:
- if(args == null || args.size() < 3){
- return null;
- }
- return new UpdateComponentDataAction(args.getString(0), args.getJSONObject(1), args.getString(2));
- }
-
- return null;
- }
-
-
- public static DOMAction getInvokeMethod(String ref,String method,JSONArray args){
- return new InvokeMethodAction(ref,method,args);
- }
-
- /**
- * getCreateBody
- * @param data json
- * @return DOMAction
- */
- public static DOMAction getCreateBody(JSONObject data) {
- return new CreateBodyAction(data);
- }
-
- /**
- * getUpdateFinish
- * @return DOMAction
- */
- public static DOMAction getUpdateFinish() {
- return new UpdateFinishAction();
- }
-
- /**
- * getRefreshFinish
- * @return DOMAction
- */
- public static DOMAction getRefreshFinish() {
- return new RefreshFinishAction();
- }
-
- /**
- * getCreateFinish
- * @return DOMAction
- */
- public static DOMAction getCreateFinish() {
- return new CreateFinishAction();
- }
-
- public static DOMAction getUpdateAttrs(String ref, JSONObject data) {
- return new UpdateAttributeAction(ref, data);
- }
-
- public static DOMAction getRemoveElement(String ref) {
- return new RemoveElementAction(ref);
- }
-
- public static DOMAction getMoveElement(String ref, String parentref, int index) {
- return new MoveElementAction(ref, parentref, index);
- }
-
- /**
- * Bridge will get this action directly.
- * @param data
- * @param parentRef
- * @param index
- * @return
- */
- public static DOMAction getAddElement(JSONObject data, String parentRef, int index){
- return new AddElementAction(data, parentRef, index);
- }
-
- public static DOMAction getUpdateStyle(String ref, JSONObject data, boolean byPesudo){
- return new UpdateStyleAction(ref, data, byPesudo);
- }
-
- public static DOMAction getAddEvent(String ref, String event) {
- return new AddEventAction(ref, event);
- }
-
- public static DOMAction getRemoveEvent(String ref, String event) {
- return new RemoveEventAction(ref, event);
- }
-
-
- public static DOMAction getAnimationAction(@NonNull final String ref, @NonNull JSONObject animation,
- @Nullable final String callBack){
- return new AnimationAction(ref, animation, callBack);
- }
-
- public static RenderAction getAnimationAction(@NonNull String ref,
- @NonNull final WXAnimationBean animationBean){
- return new AnimationAction(ref, animationBean);
- }
-
- public static RenderAction getAnimationAction(@NonNull String ref,
- @NonNull final WXAnimationBean animationBean,
- @Nullable String callback){
- return new AnimationAction(ref, animationBean, callback);
- }
-
- public static DOMAction getModuleInvocationAction(@NonNull WXModule wxModule, @NonNull JSONArray args,
- @NonNull Invoker invoker) {
- return new ModuleInvocationAction(wxModule, args, invoker);
- }
-
- public static DOMAction getExecutableRenderAction(@NonNull Runnable runnable) {
- return new ExecutableRenderAction(runnable);
- }
-
- public static DOMAction getReloadPage(String instanceId, boolean relaod) {
- return new ReloadPageAction(instanceId, relaod);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/action/AddElementAction.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/action/AddElementAction.java b/android/sdk/src/main/java/com/taobao/weex/dom/action/AddElementAction.java
deleted file mode 100644
index 00bccce..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/action/AddElementAction.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom.action;
-
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.common.WXErrorCode;
-import com.taobao.weex.dom.DOMActionContext;
-import com.taobao.weex.dom.RenderActionContext;
-import com.taobao.weex.dom.WXCellDomObject;
-import com.taobao.weex.dom.WXDomObject;
-import com.taobao.weex.tracing.Stopwatch;
-import com.taobao.weex.tracing.WXTracing;
-import com.taobao.weex.ui.component.ComponentUtils;
-import com.taobao.weex.ui.component.WXBasicComponentType;
-import com.taobao.weex.ui.component.WXComponent;
-import com.taobao.weex.ui.component.WXVContainer;
-import com.taobao.weex.utils.WXLogUtils;
-
-import java.util.List;
-
-/**
- * Created by sospartan on 22/02/2017.
- */
-
-final class AddElementAction extends AbstractAddElementAction {
- private final String mParentRef;
- private final int mAddIndex;
- private final JSONObject mData;
- private StringBuilder mErrMsg = new StringBuilder("AddElementAction Error:");
-
- private String mRef;
-
-
- AddElementAction(JSONObject data, String parentRef, int index) {
- mParentRef = parentRef;
- mAddIndex = index;
- mData = data;
- }
-
- @Override
- protected WXComponent createComponent(DOMActionContext context, WXDomObject domObject) {
- WXComponent comp = context.getCompByRef(mParentRef);
- if (comp == null || !(comp instanceof WXVContainer)) {
- mErrMsg.append("WXComponent comp = context.getCompByRef(mParentRef) is null or \n")
- .append("!(comp instanceof WXVContainer)");
- return null;
- }
- if(domObject.getType().equals(WXBasicComponentType.CELL_SLOT)
- && domObject instanceof WXCellDomObject){
- return ComponentUtils.buildTree(domObject, (WXVContainer) comp);
- }
- return generateComponentTree(context, domObject, (WXVContainer) comp);
- }
-
- @Override
- protected void appendDomToTree(DOMActionContext context, WXDomObject domObject) {
- long startNanos = System.nanoTime();
- WXDomObject parent;
- mRef = domObject.getRef();
- if ((parent = context.getDomByRef(mParentRef)) == null) {
- mErrMsg.append("parent = context.getDomByRef(mParentRef)) == null");
-// context.getInstance().commitUTStab(IWXUserTrackAdapter.DOM_MODULE, getErrorCode());
- return;
- } else {
- //non-root and parent exist
- parent.add(domObject, mAddIndex);
- }
- domObject.mDomThreadNanos += (System.nanoTime() - startNanos);
- }
-
- @Override
- protected String getStatementName() {
- return "addDom";
- }
-
- @Override
- protected WXErrorCode getErrorCode() {
- return WXErrorCode.WX_KEY_EXCEPTION_DOM_ADD_ELEMENT;
- }
-
- @Override
- protected String getErrorMsg() {
- return mErrMsg.toString();
- }
-
- @Override
- public void executeDom(DOMActionContext context) {
- addDomInternal(context, mData);
- }
-
- @Override
- public void executeRender(RenderActionContext context) {
- WXComponent component = context.getComponent(mRef);
- WXSDKInstance instance = context.getInstance();
- if (instance == null || instance.getContext() == null) {
- WXLogUtils.e("instance is null or instance is destroy!");
- mErrMsg.append("instance is null or instance is destroy!");
- return;
- }
- try {
- WXVContainer parent = (WXVContainer) context.getComponent(mParentRef);
- if (parent == null || component == null) {
- mErrMsg.append("parent == null || component == null")
- .append("parent=" + parent).append("component=" + component);
- return;
- }
-
- Stopwatch.tick();
- parent.addChild(component, mAddIndex);
- parent.createChildViewAt(mAddIndex);
- Stopwatch.split("createViewTree");
-
- component.applyLayoutAndEvent(component);
- Stopwatch.split("applyLayoutAndEvent");
-
- component.bindData(component);
- Stopwatch.split("bindData");
-
- if (WXTracing.isAvailable()) {
- String instanceId = context.getInstance().getInstanceId();
- List<Stopwatch.ProcessEvent> splits = Stopwatch.getProcessEvents();
- for (Stopwatch.ProcessEvent event : splits) {
- submitPerformance(event.fname, "X", instanceId, event.duration, event.startMillis, true);
- }
- }
- component.mTraceInfo.uiQueueTime = mUIQueueTime;
- if (component.isLazy()) {
- component.onRenderFinish(WXComponent.STATE_DOM_FINISH);
- } else {
- component.onRenderFinish(WXComponent.STATE_ALL_FINISH);
- }
- } catch (Exception e) {
- WXLogUtils.e("add component failed.", e);
- mErrMsg.append("add component failed.").append(WXLogUtils.getStackTrace(e));
- }
- instance.onElementChange();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/action/AddEventAction.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/action/AddEventAction.java b/android/sdk/src/main/java/com/taobao/weex/dom/action/AddEventAction.java
deleted file mode 100644
index 58ccf6a..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/action/AddEventAction.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom.action;
-
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.adapter.IWXUserTrackAdapter;
-import com.taobao.weex.common.WXErrorCode;
-import com.taobao.weex.dom.DOMAction;
-import com.taobao.weex.dom.DOMActionContext;
-import com.taobao.weex.dom.RenderAction;
-import com.taobao.weex.dom.RenderActionContext;
-import com.taobao.weex.dom.WXDomObject;
-import com.taobao.weex.dom.WXEvent;
-import com.taobao.weex.tracing.Stopwatch;
-import com.taobao.weex.tracing.WXTracing;
-import com.taobao.weex.ui.component.WXComponent;
-import com.taobao.weex.utils.WXExceptionUtils;
-
-import java.util.List;
-
-/**
- * Created by sospartan on 01/03/2017.
- */
-class AddEventAction extends TraceableAction implements DOMAction, RenderAction {
- private final String mRef;
- private final Object mEvent;
-
- private WXDomObject mUpdatedDom;
-
- AddEventAction(String ref, Object event) {
- mRef = ref;
- mEvent = event;
- }
-
- @Override
- public void executeDom(DOMActionContext context) {
- if (context.isDestory()) {
- return;
- }
-
- Stopwatch.tick();
- WXSDKInstance instance = context.getInstance();
- WXDomObject domObject = context.getDomByRef(mRef);
- if (domObject == null) {
- if (instance != null) {
- String event = JSONObject.toJSONString(mEvent);
- StringBuilder sbErr = new StringBuilder()
- .append("|mRef==" + mRef)
- .append("|mEvent=" + event)
- .append("|instance id = " + instance.getInstanceId())
- .append("|context = " + context.toString());
-
- if(!"_documentElement".equals(mRef)){//Rax framework
- WXExceptionUtils.commitCriticalExceptionRT(instance.getInstanceId(),
- WXErrorCode.WX_KEY_EXCEPTION_DOM_ADD_EVENT,
- "addEvent",
- WXErrorCode.WX_KEY_EXCEPTION_DOM_ADD_EVENT.getErrorMsg() + "| domObject is null |"
- +sbErr.toString(),null);
- }
- }
- return;
- }
-
- domObject.getEvents().addEvent(mEvent);
- mUpdatedDom = domObject;
- if (WXTracing.isAvailable() && mBeginEvent != null) {
- submitPerformance("addEventToDom", "X", instance.getInstanceId(), Stopwatch.tack(), Stopwatch.lastTickStamp(), true);
- }
-
- context.postRenderTask(this);
- }
-
- @Override
- public void executeRender(RenderActionContext context) {
- WXComponent comp = context.getComponent(mRef);
- if(comp != null){
- //sync dom change to component
- Stopwatch.tick();
- comp.updateDom(mUpdatedDom);
- Stopwatch.split("updateDom");
- comp.addEvent(mEvent);
- Stopwatch.split("addEventToComponent");
-
- if (WXTracing.isAvailable() && mBeginEvent != null) {
- List<Stopwatch.ProcessEvent> events = Stopwatch.getProcessEvents();
- for (Stopwatch.ProcessEvent event : events) {
- submitPerformance(event.fname, "X", comp.getInstanceId(), event.duration, event.startMillis, true);
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/action/AddRuleAction.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/action/AddRuleAction.java b/android/sdk/src/main/java/com/taobao/weex/dom/action/AddRuleAction.java
deleted file mode 100644
index 6f063d3..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/action/AddRuleAction.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.taobao.weex.dom.action;
-
-import android.text.TextUtils;
-
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.DOMAction;
-import com.taobao.weex.dom.DOMActionContext;
-import com.taobao.weex.utils.FontDO;
-import com.taobao.weex.utils.TypefaceUtil;
-
-/**
- * Created by sospartan on 02/03/2017.
- */
-final class AddRuleAction implements DOMAction {
- private final String mType;
- private final JSONObject mData;
-
- public AddRuleAction(String type, JSONObject data) {
- this.mType = type;
- this.mData = data;
- }
-
- @Override
- public void executeDom(DOMActionContext context) {
- if (Constants.Name.FONT_FACE.equals(mType)) {
- FontDO fontDO = parseFontDO(mData, context.getInstance());
- if (fontDO != null && !TextUtils.isEmpty(fontDO.getFontFamilyName())) {
- FontDO cacheFontDO = TypefaceUtil.getFontDO(fontDO.getFontFamilyName());
- if (cacheFontDO == null || !TextUtils.equals(cacheFontDO.getUrl(), fontDO.getUrl())) {
- TypefaceUtil.putFontDO(fontDO);
- TypefaceUtil.loadTypeface(fontDO);
- } else {
- TypefaceUtil.loadTypeface(cacheFontDO);
- }
- }
- }
- }
-
- private FontDO parseFontDO(JSONObject jsonObject,WXSDKInstance instance) {
- if(jsonObject == null) {
- return null;
- }
- String src = jsonObject.getString(Constants.Name.SRC);
- String name = jsonObject.getString(Constants.Name.FONT_FAMILY);
-
- return new FontDO(name, src,instance);
- }
-}