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:04 UTC
[36/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/RenderContext.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/RenderContext.java b/android/sdk/src/main/java/com/taobao/weex/dom/RenderContext.java
new file mode 100644
index 0000000..635039f
--- /dev/null
+++ b/android/sdk/src/main/java/com/taobao/weex/dom/RenderContext.java
@@ -0,0 +1,32 @@
+/*
+ * 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 com.taobao.weex.WXSDKInstance;
+import com.taobao.weex.ui.component.WXComponent;
+
+/**
+ * Created by sospartan on 23/02/2017.
+ */
+
+public interface RenderContext {
+ WXSDKInstance getInstance();
+ WXComponent getComponent(String ref);
+ WXComponent unregisterComponent(String ref);
+}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/SafePutConcurrentHashMap.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/SafePutConcurrentHashMap.java b/android/sdk/src/main/java/com/taobao/weex/dom/SafePutConcurrentHashMap.java
deleted file mode 100644
index 7ada309..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/SafePutConcurrentHashMap.java
+++ /dev/null
@@ -1,51 +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 java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Created by sospartan on 8/23/16.
- */
-public class SafePutConcurrentHashMap<K, V> extends ConcurrentHashMap<K, V> {
-
-
- @Override
- public void putAll(Map<? extends K, ? extends V> m) {
- Iterator<? extends Entry<? extends K, ? extends V>> iterator = m.entrySet().iterator();
- while (iterator.hasNext()) {
- Entry<? extends K, ? extends V> item = iterator.next();
- if (item.getKey() == null || item.getValue() == null) {
- iterator.remove();
- }
- }
-
- super.putAll(m);
- }
-
- @Override
- public V put(K key, V value) {
- if (key == null || value == null) {
- return null;
- }
- return super.put(key, value);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/TextAreaEditTextDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/TextAreaEditTextDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/TextAreaEditTextDomObject.java
deleted file mode 100644
index a6625e3..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/TextAreaEditTextDomObject.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 com.taobao.weex.common.Constants;
-
-/**
- * Created by sospartan on 7/12/16.
- */
-public class TextAreaEditTextDomObject extends BasicEditTextDomObject {
-
- public static final int DEFAULT_ROWS = 2;
- private int mNumberOfLines = DEFAULT_ROWS;
-
- @Override
- protected float getMeasureHeight(){
- return getMeasuredLineHeight() * mNumberOfLines;
- }
-
-
- @Override
- protected void updateStyleAndAttrs() {
- super.updateStyleAndAttrs();
- Object raw = getAttrs().get(Constants.Name.ROWS);
- if (raw == null) {
- return;
- } else if (raw instanceof String) {
- String rowsStr = (String) raw;
- try {
- int lines = Integer.parseInt(rowsStr);
- if (lines > 0) {
- mNumberOfLines = lines;
- }
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- } else if (raw instanceof Integer) {
- mNumberOfLines = (Integer) raw;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java
index 1025584..ab009bd 100644
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java
+++ b/android/sdk/src/main/java/com/taobao/weex/dom/WXAttr.java
@@ -25,7 +25,6 @@ import static java.lang.Boolean.parseBoolean;
import android.support.annotation.NonNull;
import android.support.v4.util.ArrayMap;
import android.text.TextUtils;
-
import com.taobao.weex.common.Constants;
import com.taobao.weex.common.Constants.Name;
import com.taobao.weex.common.WXImageSharpen;
@@ -53,8 +52,7 @@ public class WXAttr implements Map<String, Object>,Cloneable {
/**
* static attrs
* */
- private @NonNull final ArrayMap<String, Object> attr;
-
+ private @NonNull final Map<String, Object> attr;
/**
* dynamic binding attrs, can be null, only weex use
@@ -75,6 +73,10 @@ public class WXAttr implements Map<String, Object>,Cloneable {
attr.putAll(filterBindingStatement(standardMap));
}
+ public WXAttr(@NonNull Map<String,Object> standardMap, int extra){
+ attr = standardMap;
+ }
+
public static String getPrefix(Map<String, Object> attr) {
if (attr == null) {
return null;
@@ -427,7 +429,6 @@ public class WXAttr implements Map<String, Object>,Cloneable {
return attr.values();
}
-
/**
* can by null, in most contion without template list, the value is null
* */
@@ -462,10 +463,10 @@ public class WXAttr implements Map<String, Object>,Cloneable {
Set<Map.Entry<String,Object>> entries = attrs.entrySet();
Iterator<Entry<String,Object>> it = entries.iterator();
while (it.hasNext()){
- Map.Entry<String,Object> entry = it.next();
- if(filterBindingStatement(entry.getKey(), entry.getValue())){
- it.remove();
- }
+ Map.Entry<String,Object> entry = it.next();
+ if(filterBindingStatement(entry.getKey(), entry.getValue())){
+ it.remove();
+ }
}
return attrs;
}
@@ -474,51 +475,51 @@ public class WXAttr implements Map<String, Object>,Cloneable {
* filter dynamic attrs and statements
* */
private boolean filterBindingStatement(String key, Object value) {
- if(COMPONENT_PROPS.equals(key)){
- ELUtils.bindingBlock(value);
- return false;
- }
- for(String exclude : EXCLUDES_BINDING){
- if(key.equals(exclude)){
- return false;
- }
- }
- if(ELUtils.isBinding(value)){
- if(mBindingAttrs == null){
- mBindingAttrs = new ArrayMap<String, Object>();
- }
- value = ELUtils.bindingBlock(value);
- mBindingAttrs.put(key, value);
- return true;
- }
- if(WXStatement.WX_IF.equals(key)){
- if(mStatement == null){
- mStatement = new WXStatement();
- }
- if(value != null) {
- mStatement.put(key, Parser.parse(value.toString()));
- }
- return true;
- }
-
- if(WXStatement.WX_FOR.equals(key)){
- if(mStatement == null){
- mStatement = new WXStatement();
- }
- value = ELUtils.vforBlock(value);
- if(value != null) {
- mStatement.put(key, value);
- return true;
- }
- }
-
- if(WXStatement.WX_ONCE.equals(key)){
- if(mStatement == null){
- mStatement = new WXStatement();
- }
- mStatement.put(key, true);
- }
+ if(COMPONENT_PROPS.equals(key)){
+ ELUtils.bindingBlock(value);
+ return false;
+ }
+ for(String exclude : EXCLUDES_BINDING){
+ if(key.equals(exclude)){
return false;
+ }
+ }
+ if(ELUtils.isBinding(value)){
+ if(mBindingAttrs == null){
+ mBindingAttrs = new ArrayMap<String, Object>();
+ }
+ value = ELUtils.bindingBlock(value);
+ mBindingAttrs.put(key, value);
+ return true;
+ }
+ if(WXStatement.WX_IF.equals(key)){
+ if(mStatement == null){
+ mStatement = new WXStatement();
+ }
+ if(value != null) {
+ mStatement.put(key, Parser.parse(value.toString()));
+ }
+ return true;
+ }
+
+ if(WXStatement.WX_FOR.equals(key)){
+ if(mStatement == null){
+ mStatement = new WXStatement();
+ }
+ value = ELUtils.vforBlock(value);
+ if(value != null) {
+ mStatement.put(key, value);
+ return true;
+ }
+ }
+
+ if(WXStatement.WX_ONCE.equals(key)){
+ if(mStatement == null){
+ mStatement = new WXStatement();
+ }
+ mStatement.put(key, true);
+ }
+ return false;
}
public void skipFilterPutAll(Map<String,Object> attrs){
@@ -533,8 +534,8 @@ public class WXAttr implements Map<String, Object>,Cloneable {
wxAttr.mBindingAttrs = new ArrayMap<>(mBindingAttrs);
}
if (mStatement != null){
- wxAttr.mStatement = new WXStatement(mStatement);
- }
+ wxAttr.mStatement = new WXStatement(mStatement);
+ }
return wxAttr;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXCellDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXCellDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXCellDomObject.java
deleted file mode 100644
index d8ef325..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXCellDomObject.java
+++ /dev/null
@@ -1,124 +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 com.taobao.weex.dom.flex.CSSNode;
-import com.taobao.weex.dom.flex.MeasureOutput;
-import com.taobao.weex.ui.component.WXBasicComponentType;
-import com.taobao.weex.utils.WXLogUtils;
-import com.taobao.weex.utils.WXViewUtils;
-
-/**
- * Created by zhengshihan on 2017/4/11.
- */
-
-public class WXCellDomObject extends WXDomObject {
-
- /** package **/ static final CSSNode.MeasureFunction CELL_MEASURE_FUNCTION = new MeasureFunction() {
- @Override
- public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
- if (node != null) {
- CSSNode parent = node.getParent();
- if (parent != null && parent instanceof WXRecyclerDomObject) {
- WXRecyclerDomObject parentDom = ((WXRecyclerDomObject) parent);
- if(!parentDom.hasPreCalculateCellWidth()) {
- parentDom.preCalculateCellWidth();
- }
- WXDomObject domObject = (WXDomObject) node;
- if (WXBasicComponentType.CELL.equals(domObject.getType())
- || WXBasicComponentType.CELL_SLOT.equals(domObject.getType())) {
- float w = ((WXRecyclerDomObject) parent).getColumnWidth();
- if((w <= 0 || Float.isNaN(w)) && parentDom.getColumnCount() <= 1){
- w = parentDom.getAvailableWidth();
- if(w <= 0 || Float.isNaN(w)){
- w = parentDom.getLayoutWidth();
- if(w <= 0 || Float.isNaN(w)){
- w = WXViewUtils.getRealPxByWidth( parentDom.getViewPortWidth(), parentDom.getViewPortWidth());
- }
- }
- }
- node.setLayoutWidth(w);
- measureOutput.width = w;
- } else if (WXBasicComponentType.HEADER.equals(domObject.getType())){
- float w = parentDom.getAvailableWidth();
- WXLogUtils.d("getAvailableWidth:"+w);
- node.setLayoutWidth(w);
- measureOutput.width = w;
- }
- }else if (node instanceof WXCellDomObject){
- WXCellDomObject slotDomObject = (WXCellDomObject) node;
- WXRecyclerDomObject recyclerDomObject = slotDomObject.getRecyclerDomObject();
- if(recyclerDomObject == null){
- return;
- }
- if(slotDomObject.isSticky()){
- float w = recyclerDomObject.getAvailableWidth();
- if(w <= 0){
- w = recyclerDomObject.getViewPortWidth();
- }
- node.setLayoutWidth(w);
- measureOutput.width = w;
- }else {
- if(!recyclerDomObject.hasPreCalculateCellWidth()){
- recyclerDomObject.preCalculateCellWidth();
- }
- float w = recyclerDomObject.getColumnWidth();
- if((w <= 0 || Float.isNaN(w)) && recyclerDomObject.getColumnCount() <= 1){
- w = recyclerDomObject.getAvailableWidth();
- if(w <= 0 || Float.isNaN(w)){
- w = recyclerDomObject.getLayoutWidth();
- if(w <= 0 || Float.isNaN(w)){
- w = recyclerDomObject.getStyleWidth();
- if(w <= 0 || Float.isNaN(w)){
- w = WXViewUtils.getRealPxByWidth(recyclerDomObject.getViewPortWidth(), recyclerDomObject.getViewPortWidth());
- }
- }
- }
- }
- node.setLayoutWidth(w);
- measureOutput.width = w;
- }
- }
-
- }
- }
- };
-
- public WXCellDomObject() {
- setMeasureFunction(CELL_MEASURE_FUNCTION);
- }
-
-
- public boolean isSticky() {
- return getStyles().isSticky();
- }
- private WXRecyclerDomObject recyclerDomObject;
-
-
-
- public WXRecyclerDomObject getRecyclerDomObject() {
- return recyclerDomObject;
- }
-
- public void setRecyclerDomObject(WXRecyclerDomObject recyclerDomObject) {
- this.recyclerDomObject = recyclerDomObject;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXDomHandler.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomHandler.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXDomHandler.java
deleted file mode 100644
index ceafbdf..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomHandler.java
+++ /dev/null
@@ -1,146 +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.os.Handler;
-import android.os.Message;
-import android.os.SystemClock;
-
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weex.dom.action.Actions;
-import com.taobao.weex.dom.action.TraceableAction;
-
-/**
- * Handler for dom operations.
- */
-public class WXDomHandler implements Handler.Callback {
-
- /**
- * The batch operation in dom thread will run at most once in 16ms.
- */
- public static final int DELAY_TIME = 16;//ms
- public static final int TRANSITION_DELAY_TIME = 2;//2ms, start transition as soon as
-
- private WXDomManager mWXDomManager;
- private boolean mHasBatch = false;
-
- public WXDomHandler(WXDomManager domManager) {
- mWXDomManager = domManager;
- }
-
- @Override
- public boolean handleMessage(Message msg) {
- if (msg == null) {
- return false;
- }
- int what = msg.what;
- Object obj = msg.obj;
- WXDomTask task = null;
-
- if (obj != null && obj instanceof WXDomTask) {
- task = (WXDomTask) obj;
- Object action = ((WXDomTask) obj).args.get(0);
- if (action != null && action instanceof TraceableAction) {
- ((TraceableAction) action).mDomQueueTime = SystemClock.uptimeMillis() - msg.getWhen();
- }
- }
-
- if (!mHasBatch) {
- mHasBatch = true;
- if(what != WXDomHandler.MsgType.WX_DOM_BATCH) {
- int delayTime = DELAY_TIME;
- if(what == MsgType.WX_DOM_TRANSITION_BATCH){
- delayTime = TRANSITION_DELAY_TIME;
- }
- mWXDomManager.sendEmptyMessageDelayed(WXDomHandler.MsgType.WX_DOM_BATCH, delayTime);
- }
- }
- switch (what) {
- case MsgType.WX_EXECUTE_ACTION:
- mWXDomManager.executeAction(task.instanceId, (DOMAction) task.args.get(0), (boolean) task.args.get(1));
- break;
- case MsgType.WX_DOM_UPDATE_STYLE:
- //keep this for direct native call
- mWXDomManager.executeAction(task.instanceId, Actions.getUpdateStyle((String) task.args.get(0),
- (JSONObject) task.args.get(1),
- task.args.size() > 2 && (boolean) task.args.get(2)),false);
- break;
- case MsgType.WX_DOM_BATCH:
-
- mWXDomManager.batch();
- mHasBatch = false;
- break;
- case MsgType.WX_CONSUME_RENDER_TASKS:
- mWXDomManager.consumeRenderTask(task.instanceId);
- break;
- default:
- break;
- }
- return true;
- }
-
-
- public static class MsgType {
-
- @Deprecated
- public static final int WX_DOM_CREATE_BODY = 0x0;
- @Deprecated
- public static final int WX_DOM_UPDATE_ATTRS = 0x01;
- @Deprecated
- public static final int WX_DOM_UPDATE_STYLE = 0x02;
- @Deprecated
- public static final int WX_DOM_ADD_DOM = 0x03;
- @Deprecated
- public static final int WX_DOM_REMOVE_DOM = 0x04;
- @Deprecated
- public static final int WX_DOM_MOVE_DOM = 0x05;
- @Deprecated
- public static final int WX_DOM_ADD_EVENT = 0x06;
- @Deprecated
- public static final int WX_DOM_REMOVE_EVENT = 0x07;
- @Deprecated
- public static final int WX_DOM_SCROLLTO = 0x08;
- @Deprecated
- public static final int WX_DOM_CREATE_FINISH = 0x09;
- @Deprecated
- public static final int WX_DOM_REFRESH_FINISH = 0x0a;
- @Deprecated
- public static final int WX_DOM_UPDATE_FINISH = 0x0b;
- @Deprecated
- public static final int WX_ANIMATION=0xc;
- @Deprecated
- public static final int WX_DOM_ADD_RULE=0xd;
- @Deprecated
- public static final int WX_DOM_INVOKE=0xe;
-
- public static final int WX_EXECUTE_ACTION = 0xfe;
- public static final int WX_DOM_BATCH = 0xff;
- public static final int WX_CONSUME_RENDER_TASKS = 0xfa;
-
-
- public static final int WX_DOM_TRANSITION_BATCH = 0xfb;
-
-
- public static final int WX_DOM_START_BATCH = 0xfc;
-
- @Deprecated
- public static final int WX_COMPONENT_SIZE= 0xff1;
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXDomManager.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomManager.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXDomManager.java
deleted file mode 100644
index af00be9..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomManager.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;
-
-import android.os.Handler;
-import android.os.Message;
-import android.support.annotation.NonNull;
-
-import com.taobao.weex.WXEnvironment;
-import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.WXSDKManager;
-import com.taobao.weex.common.WXErrorCode;
-import com.taobao.weex.common.WXRuntimeException;
-import com.taobao.weex.common.WXThread;
-import com.taobao.weex.dom.action.AbstractAddElementAction;
-import com.taobao.weex.dom.action.TraceableAction;
-import com.taobao.weex.tracing.Stopwatch;
-import com.taobao.weex.tracing.WXTracing;
-import com.taobao.weex.ui.WXRenderManager;
-import com.taobao.weex.utils.WXExceptionUtils;
-import com.taobao.weex.utils.WXLogUtils;
-import com.taobao.weex.utils.WXUtils;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Class for managing dom operation. This class works as the client in the command pattern, it
- * will call {@link DOMActionContextImpl} for creating command object and invoking corresponding
- * operation.
- * Methods in this class normally need to be invoked in dom thread, otherwise, {@link
- * WXRuntimeException} may be thrown.
- */
-public final class WXDomManager {
-
- private WXThread mDomThread;
- /** package **/
- Handler mDomHandler;
- private WXRenderManager mWXRenderManager;
- private ConcurrentHashMap<String, DOMActionContextImpl> mDomRegistries;
-
- public WXDomManager(WXRenderManager renderManager) {
- mWXRenderManager = renderManager;
- mDomRegistries = new ConcurrentHashMap<>();
- mDomThread = new WXThread("WeeXDomThread", new WXDomHandler(this));
- mDomHandler = mDomThread.getHandler();
- }
-
- public void sendEmptyMessageDelayed(int what, long delayMillis) {
- if (mDomHandler == null || mDomThread == null
- || !mDomThread.isWXThreadAlive() || mDomThread.getLooper() == null) {
- return;
- }
- mDomHandler.sendEmptyMessageDelayed(what, delayMillis);
- }
-
- public void sendMessage(Message msg) {
- sendMessageDelayed(msg, 0);
- }
-
- public void sendMessageDelayed(Message msg, long delay) {
- if (msg == null || mDomHandler == null || mDomThread == null
- || !mDomThread.isWXThreadAlive() || mDomThread.getLooper() == null) {
- return;
- }
- mDomHandler.sendMessageDelayed(msg,delay);
- }
-
- /**
- * Remove the specified dom statement. This is called when {@link WXSDKManager} destroy
- * instances.
- * @param instanceId {@link com.taobao.weex.WXSDKInstance#mInstanceId} for the instance
- */
- public void removeDomStatement(String instanceId) {
- if (!WXUtils.isUiThread()) {
- throw new WXRuntimeException("[WXDomManager] removeDomStatement");
- }
- final DOMActionContextImpl statement = mDomRegistries.remove(instanceId);
- if (statement != null) {
- post(new Runnable() {
-
- @Override
- public void run() {
- statement.destroy();
- }
- });
- }
- }
-
- public void post(Runnable task) {
- if (mDomHandler == null || task == null || mDomThread == null || !mDomThread.isWXThreadAlive()
- || mDomThread.getLooper() == null) {
- return;
- }
- mDomHandler.post(WXThread.secure(task));
- }
-
- /**
- * Destroy current instance
- */
- public void destroy() {
- if (mDomThread != null && mDomThread.isWXThreadAlive()) {
- mDomThread.quit();
- }
- if (mDomRegistries != null) {
- mDomRegistries.clear();
- }
- mDomHandler = null;
- mDomThread = null;
- }
-
- private boolean isDomThread() {
- return !WXEnvironment.isApkDebugable() || Thread.currentThread().getId() == mDomThread.getId();
- }
-
- /**
- * Batch the execution of {@link DOMActionContextImpl}
- */
- void batch() {
- throwIfNotDomThread();
- Iterator<Entry<String, DOMActionContextImpl>> iterator = mDomRegistries.entrySet().iterator();
- while (iterator.hasNext()) {
- iterator.next().getValue().batch();
- }
- }
-
- void consumeRenderTask(String instanceId) {
- throwIfNotDomThread();
- DOMActionContextImpl context = mDomRegistries.get(instanceId);
- if(context != null) {
- context.consumeRenderTasks();
- }
- }
-
- private void throwIfNotDomThread(){
- if (!isDomThread()) {
- throw new WXRuntimeException("dom operation must be done in dom thread");
- }
- }
-
- public void executeAction(String instanceId, DOMAction action, boolean createContext) {
- DOMActionContext context = mDomRegistries.get(instanceId);
- if(context == null){
- if(createContext){
- DOMActionContextImpl oldStatement = new DOMActionContextImpl(instanceId, mWXRenderManager);
- mDomRegistries.put(instanceId, oldStatement);
- context = oldStatement;
- }else{
- WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(instanceId);
- if(action != null && instance!= null && !instance.getismIsCommitedDomAtionExp()){
- String className = action.getClass().getSimpleName();
- WXLogUtils.e("WXDomManager", className + " Is Invalid Action");
- if(className.contains("CreateFinishAction")){
- WXExceptionUtils.commitCriticalExceptionRT(instanceId,
- WXErrorCode.WX_KEY_EXCEPTION_DOM_ACTION_FIRST_ACTION,
- "executeAction",
- WXErrorCode.WX_KEY_EXCEPTION_DOM_ACTION_FIRST_ACTION.getErrorMsg() + "|current action is" +className, null);
- instance.setmIsCommitedDomAtionExp(true);
- }
- }
- return;
- }
- }
- long domStart = System.currentTimeMillis();
- long domNanos = System.nanoTime();
- action.executeDom(context);
- if (WXTracing.isAvailable()) {
- domNanos = System.nanoTime() - domNanos;
- if (!(action instanceof AbstractAddElementAction) && action instanceof TraceableAction) {
- WXTracing.TraceEvent domExecuteEvent = WXTracing.newEvent("DomExecute", context.getInstanceId(), ((TraceableAction) action).mTracingEventId);
- domExecuteEvent.duration = Stopwatch.nanosToMillis(domNanos);
- domExecuteEvent.ts = domStart;
- domExecuteEvent.submit();
- }
- }
- }
-
- public DOMActionContext getDomContext(String instanceId){
- return mDomRegistries.get(instanceId);
- }
-
- /**
- * @param action
- * @param createContext only true when create body
- */
- public void postAction(String instanceId,DOMAction action, boolean createContext){
- postActionDelay(instanceId, action, createContext, 0);
- }
-
- /**
- * @param action
- * @param createContext only true when create body
- */
- public void postActionDelay(String instanceId,DOMAction action,
- boolean createContext, long delay){
- if(action == null){
- return;
- }
- Message msg = Message.obtain();
- msg.what = WXDomHandler.MsgType.WX_EXECUTE_ACTION;
- WXDomTask task = new WXDomTask();
- task.instanceId = instanceId;
- task.args = new ArrayList<>();
- task.args.add(action);
- task.args.add(createContext);
- msg.obj = task;
- sendMessageDelayed(msg, delay);
- }
-
- public void postRenderTask(@NonNull String instanceId) {
- Message msg = Message.obtain();
- msg.what = WXDomHandler.MsgType.WX_CONSUME_RENDER_TASKS;
- WXDomTask task = new WXDomTask();
- task.instanceId = instanceId;
- msg.obj = task;
- sendMessage(msg);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXDomModule.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomModule.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXDomModule.java
deleted file mode 100644
index b9bbefd..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomModule.java
+++ /dev/null
@@ -1,175 +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 com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.WXSDKManager;
-import com.taobao.weex.bridge.WXBridgeManager;
-import com.taobao.weex.common.WXModule;
-import com.taobao.weex.dom.action.Action;
-import com.taobao.weex.dom.action.Actions;
-import com.taobao.weex.dom.action.TraceableAction;
-import com.taobao.weex.tracing.Stopwatch;
-import com.taobao.weex.tracing.WXTracing;
-import com.taobao.weex.utils.WXLogUtils;
-
-
-
-/**
- * <p>
- * Module class for dom operation. Methods in this class will run in dom thread by default.
- * Actually, methods in this class are wrapper classes, they just wrap method call info, and hand
- * the wrapped info to the {@link WXDomHandler} for further process. This class is also singleton
- * in the {@link com.taobao.weex.WXSDKInstance}
- * </p>
- * <p>
- * This module is work different with other regular module, method is invoked directly, without reflection.
- * </p>
- */
-public final class WXDomModule extends WXModule {
-
- /** package **/
- // method
- public static final String CREATE_BODY = "createBody";
- public static final String UPDATE_ATTRS = "updateAttrs";
- public static final String UPDATE_STYLE = "updateStyle";
- public static final String REMOVE_ELEMENT = "removeElement";
- public static final String ADD_ELEMENT = "addElement";
- public static final String MOVE_ELEMENT = "moveElement";
- public static final String ADD_EVENT = "addEvent";
- public static final String REMOVE_EVENT = "removeEvent";
- public static final String CREATE_FINISH = "createFinish";
- public static final String REFRESH_FINISH = "refreshFinish";
- public static final String UPDATE_FINISH = "updateFinish";
- public static final String SCROLL_TO_ELEMENT = "scrollToElement";
- public static final String ADD_RULE = "addRule";
-
- public static final String UPDATE_COMPONENT_DATA = "updateComponentData";
-
- public static final String GET_COMPONENT_RECT = "getComponentRect";
-
- public static final String WXDOM = "dom";
-
-
- public static final String INVOKE_METHOD = "invokeMethod";
- /**
- * Methods expose to js. Every method which will be called in js should add to this array.
- */
- public static final String[] METHODS = {CREATE_BODY, UPDATE_ATTRS, UPDATE_STYLE,
- REMOVE_ELEMENT, ADD_ELEMENT, MOVE_ELEMENT, ADD_EVENT, REMOVE_EVENT, CREATE_FINISH,
- REFRESH_FINISH, UPDATE_FINISH, SCROLL_TO_ELEMENT, ADD_RULE,GET_COMPONENT_RECT,
- INVOKE_METHOD};
-
- public WXDomModule(WXSDKInstance instance){
- mWXSDKInstance = instance;
- }
-
- public void callDomMethod(JSONObject task, long... parseNanos) {
- if (task == null) {
- return;
- }
- String method = (String) task.get(WXBridgeManager.METHOD);
- JSONArray args = (JSONArray) task.get(WXBridgeManager.ARGS);
- callDomMethod(method,args,parseNanos);
- }
-
- public Object callDomMethod(String method, JSONArray args, long... parseNanos) {
-
- if (method == null) {
- return null;
- }
- //TODO:add pooling
- try {
- Action action = Actions.get(method,args);
- if(action == null){
- WXLogUtils.e("Unknown dom action "
- + method + " args " + (args == null ? " null" : args.toJSONString()));
- return null;
- }
- if(action instanceof DOMAction){
- postAction((DOMAction)action, CREATE_BODY.equals(method) || ADD_RULE.equals(method));
- }else {
- postAction((RenderAction)action);
- }
-
- if (WXTracing.isAvailable() && action instanceof TraceableAction) {
- //TODO: CHECK AGAIN
- String ref = null;
- String type = null;
- if (args.size() > 0) {
- if (args.size() >= 1) {
- if (args.get(0) instanceof String) {
- ref = args.getString(0);
- } else if (args.get(0) instanceof JSONObject) {
- ref = ((JSONObject) args.get(0)).getString("ref");
- type = ((JSONObject) args.get(0)).getString("type");
- }
- }
-
- if (args.size() >= 2) {
- if (args.get(1) instanceof JSONObject) {
- ref = ((JSONObject) args.get(1)).getString("ref");
- type = ((JSONObject) args.get(1)).getString("type");
- }
- }
- }
- if (parseNanos != null && parseNanos.length == 1) {
- ((TraceableAction) action).mParseJsonNanos = parseNanos[0];
- ((TraceableAction) action).mStartMillis -= Stopwatch.nanosToMillis(parseNanos[0]);
- }
- ((TraceableAction) action).onStartDomExecute(mWXSDKInstance.getInstanceId(), method, ref, type, args.toJSONString());
- }
- } catch (IndexOutOfBoundsException e) {
- // no enougn args
- e.printStackTrace();
- WXLogUtils.e("Dom module call miss arguments.");
- } catch (ClassCastException cce) {
- WXLogUtils.e("Dom module call arguments format error!!");
- }
- return null;
- }
-
- /**
- * invoke dom method
- * @param ref
- * @param method
- * @param args
- */
- public void invokeMethod(String ref, String method, JSONArray args){
- if(ref == null || method == null){
- return;
- }
-
- postAction(Actions.getInvokeMethod(ref,method,args),false);
- }
-
- public void postAction(RenderAction action){
- WXSDKManager.getInstance().getWXRenderManager().runOnThread(mWXSDKInstance.getInstanceId(),action);
- }
-
- /**
- * @param action
- * @param createContext only true when create body
- */
- public void postAction(DOMAction action, boolean createContext){
- WXSDKManager.getInstance().getWXDomManager().postAction(mWXSDKInstance.getInstanceId(),action,createContext);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXDomObject.java
deleted file mode 100644
index 7897d44..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomObject.java
+++ /dev/null
@@ -1,936 +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.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.text.TextUtils;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weex.WXEnvironment;
-import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.WXSDKManager;
-import com.taobao.weex.bridge.WXValidateProcessor;
-import com.taobao.weex.common.Constants;
-import com.taobao.weex.common.Constants.Name;
-import com.taobao.weex.dom.flex.CSSLayoutContext;
-import com.taobao.weex.dom.flex.CSSNode;
-import com.taobao.weex.dom.flex.Spacing;
-import com.taobao.weex.dom.transition.WXTransition;
-import com.taobao.weex.ui.component.WXBasicComponentType;
-import com.taobao.weex.utils.WXLogUtils;
-import com.taobao.weex.utils.WXUtils;
-import com.taobao.weex.utils.WXViewUtils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-
-
-/**
- * WXDomObject contains all the info about the given node, including style, attribute and event.
- * Unlike {@link com.taobao.weex.ui.component.WXComponent}, WXDomObject only contains info about
- * the dom, has nothing to do with rendering.
- * Actually, {@link com.taobao.weex.ui.component.WXComponent} hold references to
- * {@link android.view.View} and {@link WXDomObject}.
- */
-public class WXDomObject extends CSSNode implements Cloneable,ImmutableDomObject {
- public static final String CHILDREN = "children";
- public static final String TYPE = "type";
- public static final String TAG = WXDomObject.class.getSimpleName();
- public static final String ROOT = "_root";
-
- /**
- * Use {@link Name#TRANSFORM} instead.
- */
- @Deprecated
- public static final String TRANSFORM = Name.TRANSFORM;
-
- /**
- * Use {@link Name#TRANSFORM_ORIGIN} instead.
- */
- @Deprecated
- public static final String TRANSFORM_ORIGIN = Name.TRANSFORM_ORIGIN;
- static final WXDomObject DESTROYED = new WXDomObject();
- static{
- DESTROYED.mRef = "_destroyed";
- }
- private AtomicBoolean sDestroy = new AtomicBoolean();
-
- private int mViewPortWidth =750;
-
- private DomContext mDomContext;
-
- /** package **/ String mRef = ROOT;
-
- /** package **/ String mType = WXBasicComponentType.DIV;
-
- /** package **/ WXStyle mStyles;
-
- /** package **/ WXAttr mAttributes;
-
- /** package **/ WXEvent mEvents;
-
- private WXTransition transition;;
-
-
-
-
-
- private List<WXDomObject> mDomChildren;
-
- /** Do not access this field directly. This field will be removed soon. **/
- @Deprecated
- public WXDomObject parent;
-
- private ArrayList<String> fixedStyleRefs;
-
- private boolean mYoung = false;
-
- public long mDomThreadNanos;
- public long mDomThreadTimestamp;
-
- private boolean cloneThis = false;
-
- public int traverseTree(Consumer...consumers){
- long startNanos = System.nanoTime();
- if (consumers == null) {
- return 0;
- }
-
- for (Consumer consumer:consumers){
- consumer.accept(this);
- }
-
- int count = childCount();
- WXDomObject child;
- int maxChildDep = 0;
- for (int i = 0; i < count; ++i) {
- child = getChild(i);
- int depNum = child.traverseTree(consumers);
- maxChildDep= maxChildDep > depNum? maxChildDep:depNum;
- }
- mDomThreadNanos += (System.nanoTime() - startNanos);
- return maxChildDep+1;
- }
-
- /**
- * diff with tranverse tree, only tranverse update tree
- * */
- public void traverseUpdateTree(Consumer...consumers){
- if (consumers == null) {
- return;
- }
- if(!hasUpdate()){
- return;
- }
- for (Consumer consumer:consumers){
- consumer.accept(this);
- }
- int count = childCount();
- WXDomObject child;
- for (int i = 0; i < count; ++i) {
- child = getChild(i);
- child.traverseUpdateTree(consumers);
- }
- }
-
-
- public int getViewPortWidth() {
- return mViewPortWidth;
- }
-
- public void setViewPortWidth(int mViewPortWidth) {
- this.mViewPortWidth = mViewPortWidth;
- }
-
- public String getRef(){
- return mRef;
- }
-
-
- public String getType(){
- return mType;
- }
-
- public @NonNull WXStyle getStyles(){
- if(mStyles == null ){
- mStyles = new WXStyle();
- }
- return mStyles;
- }
-
- public @NonNull WXAttr getAttrs(){
- if(mAttributes == null){
- mAttributes = new WXAttr();
- }
- return mAttributes;
- }
-
- public @NonNull WXEvent getEvents(){
- if(mEvents == null){
- mEvents = new WXEvent();
- }
-
- return mEvents;
- }
-
- public WXTransition getTransition() {
- return transition;
- }
-
- public @NonNull DomContext getDomContext() {
- return mDomContext;
- }
-
- public void clearEvents(){
- if(mEvents != null){
- mEvents.clear();
- }
- }
-
- public static void prepareRoot(WXDomObject domObj,float defaultHeight,float defaultWidth) {
- domObj.mRef = WXDomObject.ROOT;
-
- WXStyle domStyles = domObj.getStyles();
- Map<String, Object> style = new HashMap<>(5);
- if (!domStyles.containsKey(Constants.Name.FLEX_DIRECTION)) {
- style.put(Constants.Name.FLEX_DIRECTION, "column");
- }
-// if (!domStyles.containsKey(Constants.Name.BACKGROUND_COLOR)) {
-// style.put(Constants.Name.BACKGROUND_COLOR, "transparent");
-// }
-
- style.put(Constants.Name.DEFAULT_WIDTH, defaultWidth);
- style.put(Constants.Name.DEFAULT_HEIGHT, defaultHeight);
-
- domObj.updateStyle(style);
- }
-
- protected final void copyFields(WXDomObject dest) {
- dest.cssstyle.copy(this.cssstyle);
- dest.mRef = mRef;
- dest.mType = mType;
- dest.mStyles = mStyles == null ? null : mStyles.clone();//mStyles == null ? null : mStyles.clone();
- dest.mAttributes = mAttributes == null ? null : mAttributes.clone();//mAttrs == null ? null : mAttrs.clone();
- dest.mEvents = mEvents == null ? null : mEvents.clone();
- dest.csslayout.copy(this.csslayout);
- }
-
- /**
- * Parse the jsonObject to {@link WXDomObject} recursively
- * @param map the original JSONObject
- */
- public void parseFromJson(JSONObject map){
- if (map == null || map.size() <= 0) {
- return;
- }
-
- String type = (String) map.get("type");
- this.mType = type;
- this.mRef = (String) map.get("ref");
- Object style = map.get("style");
- if (style != null && style instanceof JSONObject) {
- WXStyle styles = new WXStyle((JSONObject) style,false);
- this.mStyles = styles;
- this.transition = WXTransition.fromMap(styles, this);
- }
- Object attr = map.get("attr");
- if (attr != null && attr instanceof JSONObject) {
- WXAttr attrs = new WXAttr((JSONObject) attr);
- this.mAttributes = attrs;
- }
- Object event = map.get("event");
- if (event != null && event instanceof JSONArray) {
- WXEvent events = new WXEvent();
- JSONArray eventArray = (JSONArray) event;
- int count = eventArray.size();
- for (int i = 0; i < count; i++) {
- Object value = eventArray.get(i);
- events.addEvent(value);
- }
- this.mEvents = events;
- }
-
- }
-
-
-
-
-
- /**
- * Do pre-staff before layout. Subclass may provide different implementation.
- */
- public void layoutBefore() {
-
- }
-
- /**
- * Do post-staff before layout. Subclass may provide different implementation.
- */
- public void layoutAfter(){
-
- }
-
- /**
- * Tell whether this object need to be updated. This is usually called when
- * {@link CSSNode#calculateLayout(CSSLayoutContext)} finishes and new layout has been
- * calculated. This method is a simple wrapper method for {@link #hasNewLayout()} and
- * {@link #isDirty()}.
- * @return true for need update since last update.
- */
- public final boolean hasUpdate() {
- return hasNewLayout() || isDirty();
- }
-
- /**
- * Mark the current node is young and unconsumed.
- */
- void young() {
- mYoung = true;
- }
-
- /**
- * Mark the current node is old and consumed.
- */
- void old() {
- mYoung = false;
- }
-
- /**
- * Tell whether this node is consumed since last layout.
- * @return true for consumed, false for not.
- */
- boolean isYoung() {
- return mYoung;
- }
-
- /**
- * Mark the update has been seen. After this method call, following call for {@link
- * #hasUpdate()} will return false. This method is also a wrapper for {@link #markUpdateSeen()}
- */
- public final void markUpdateSeen() {
- if (hasNewLayout()) {
- markLayoutSeen();
- }
- }
-
- @Override
- public void setStyleHeight(float height) {
- if(getAttrs().containsKey(Name.OVERFLOW_HIDDEN_HEIGHT)){
- super.setStyleHeight(height);
- super.setMaxHeight(height);
- }else{
- super.setStyleHeight(height);
- }
- }
-
- @Override
- public void setStyleWidth(float width) {
- if(getAttrs().containsKey(Name.OVERFLOW_HIDDEN_WIDTH)){
- super.setStyleWidth(width);
- super.setMaxWidth(width);
- }else{
- super.setStyleWidth(width);
- }
- }
-
- public boolean isFixed() {
- return mStyles == null ? false : mStyles.isFixed();
- }
-
- public boolean canRecycled() {
- return mAttributes == null ? false : mAttributes.canRecycled();
- }
-
- public Object getExtra() {
- return null;
- }
-
- public void remove(WXDomObject child) {
- if (child == null || mDomChildren == null || sDestroy.get()) {
- return;
- }
-
- int index = mDomChildren.indexOf(child);
- removeFromDom(child);
- if (index != -1) {
- super.removeChildAt(index);
- }
- }
-
- public void removeFromDom(WXDomObject child) {
- if (child == null || mDomChildren == null || sDestroy.get()) {
- return;
- }
-
- int index = mDomChildren.indexOf(child);
- if (index == -1) {
- WXLogUtils.e("[WXDomObject] remove function error");
- return;
- }
- mDomChildren.remove(index).parent = null;
- }
-
- public int index(WXDomObject child) {
- if (child == null || mDomChildren == null || sDestroy.get()) {
- return -1;
- }
- return mDomChildren.indexOf(child);
- }
-
- /**
- * Add the given WXDomObject as this object's child at specified index.
- * @param child the child to be added
- * @param index the index of child to be added. If the index is -1, the child will be added
- * as the last child of current dom object.
- */
- public void add(WXDomObject child, int index) {
- if (child == null || index < -1 || sDestroy.get()) {
- return;
- }
- if (mDomChildren == null) {
- mDomChildren = new ArrayList<>();
- }
-
- int count = mDomChildren.size();
- index = index >= count ? -1 : index;
- if (index == -1) {
- mDomChildren.add(child);
- super.addChildAt(child, super.getChildCount());
- } else {
- mDomChildren.add(index, child);
- super.addChildAt(child, index);
- }
- child.parent = this;
- }
-
- @Deprecated
- public void add2Dom(WXDomObject child, int index) {
- if (child == null || index < -1 || sDestroy.get()) {
- return;
- }
-
- int count = super.getChildCount();
- index = index >= count ? -1 : index;
- if (index == -1) {
- super.addChildAt(child, super.getChildCount());
- } else {
- super.addChildAt(child, index);
- }
- child.parent = this;
- }
-
- public WXDomObject getChild(int index) {
- if (mDomChildren == null || sDestroy.get()) {
- return null;
- }
- return mDomChildren.get(index);
- }
-
- /**
- * Add the given event for current object.
- * @param e
- */
- public void addEvent(String e) {
- if (TextUtils.isEmpty(e)) {
- return;
- }
- if (mEvents == null) {
- mEvents = new WXEvent();
- }
- if (containsEvent(e)) {
- return;
- }
- mEvents.add(e);
- }
-
- public boolean containsEvent(String e) {
- if (mEvents == null) {
- return false;
- }
- return mEvents.contains(e);
- }
-
- public void removeEvent(String e) {
- if (TextUtils.isEmpty(e)) {
- return;
- }
- if (mEvents == null) {
- return;
- }
- mEvents.remove(e);
- }
-
- public void updateAttr(Map<String, Object> updates) {
- if(!diffUpdates(updates, getAttrs())){
- return;
- }
- if (mAttributes == null) {
- mAttributes = new WXAttr();
- }
- mAttributes.skipFilterPutAll(updates);
- if(hasNewLayout()){
- markUpdateSeen();
- }
- if(shouldDirty(updates)) {
- super.dirty();
- }
- }
-
- public void updateStyle(Map<String, Object> styles){
- updateStyle(styles,false);
- }
-
- public void updateStyle(Map<String, Object> updates, boolean byPesudo) {
- /**
- * filter transform property
- * */
- if(transition != null){
- transition.updateTranstionParams(updates);
- if(transition.hasTransitionProperty(updates)){
- transition.startTransition(updates);
- }
- }
- /**
- * diff styles
- * */
- if(!diffUpdates(updates, getStyles())){
- return;
- }
-
- if(mStyles == null) {
- mStyles = new WXStyle();
- }
- mStyles.putAll(updates,byPesudo);
- if(transition == null){
- this.transition = WXTransition.fromMap(mStyles, this);
- }
- if(shouldDirty(updates)) {
- super.dirty();
- }
- }
-
-
- public void applyStyle(Map<String, Object> styles){
- applyStyleToNode(styles);
- }
-
- void applyStyleToNode() {
- applyStyleToNode(getStyles());
- }
-
- /** package **/ void applyStyleToNode(Map<String, Object> updates) {
- if(updates.size() == 0){
- return;
- }
- WXStyle stylesMap = getStyles();
- int vp = getViewPortWidth();
- if (!stylesMap.isEmpty()) {
- for(Map.Entry<String,Object> item: updates.entrySet()) {
- switch (item.getKey()) {
- case Constants.Name.ALIGN_ITEMS:
- setAlignItems(stylesMap.getAlignItems());
- break;
- case Constants.Name.ALIGN_SELF:
- setAlignSelf(stylesMap.getAlignSelf());
- break;
- case Constants.Name.FLEX:
- setFlex(stylesMap.getFlex());
- break;
- case Constants.Name.FLEX_DIRECTION:
- setFlexDirection(stylesMap.getFlexDirection());
- break;
- case Constants.Name.JUSTIFY_CONTENT:
- setJustifyContent(stylesMap.getJustifyContent());
- break;
- case Constants.Name.FLEX_WRAP:
- setWrap(stylesMap.getCSSWrap());
- break;
- case Constants.Name.MIN_WIDTH:
- setMinWidth(WXViewUtils.getRealPxByWidth(stylesMap.getMinWidth(vp),vp));
- break;
- case Constants.Name.MIN_HEIGHT:
- setMinHeight(WXViewUtils.getRealPxByWidth(stylesMap.getMinHeight(vp),vp));
- break;
- case Constants.Name.MAX_WIDTH:
- setMaxWidth(WXViewUtils.getRealPxByWidth(stylesMap.getMaxWidth(vp),vp));
- break;
- case Constants.Name.MAX_HEIGHT:
- setMaxHeight(WXViewUtils.getRealPxByWidth(stylesMap.getMaxHeight(vp),vp));
- break;
- case Constants.Name.DEFAULT_HEIGHT:
- case Constants.Name.HEIGHT:
- setStyleHeight(WXViewUtils.getRealPxByWidth(stylesMap.containsKey(Constants.Name.HEIGHT)?stylesMap.getHeight(vp):stylesMap.getDefaultHeight(),vp));
- break;
- case Constants.Name.WIDTH:
- case Constants.Name.DEFAULT_WIDTH:
- setStyleWidth(WXViewUtils.getRealPxByWidth(stylesMap.containsKey(Constants.Name.WIDTH)?stylesMap.getWidth(vp):stylesMap.getDefaultWidth(),vp));
- break;
- case Constants.Name.POSITION:
- setPositionType(stylesMap.getPosition());
- break;
- case Constants.Name.LEFT:
- setPositionLeft(WXViewUtils.getRealPxByWidth(stylesMap.getLeft(vp),vp));
- break;
- case Constants.Name.TOP:
- setPositionTop(WXViewUtils.getRealPxByWidth(stylesMap.getTop(vp),vp));
- break;
- case Constants.Name.RIGHT:
- setPositionRight(WXViewUtils.getRealPxByWidth(stylesMap.getRight(vp),vp));
- break;
- case Constants.Name.BOTTOM:
- setPositionBottom(WXViewUtils.getRealPxByWidth(stylesMap.getBottom(vp),vp));
- break;
- case Constants.Name.MARGIN:
- setMargin(Spacing.ALL, WXViewUtils.getRealPxByWidth(stylesMap.getMargin(vp), vp));
- break;
- case Constants.Name.MARGIN_LEFT:
- setMargin(Spacing.LEFT, WXViewUtils.getRealPxByWidth(stylesMap.getMarginLeft(vp), vp));
- break;
- case Constants.Name.MARGIN_TOP:
- setMargin(Spacing.TOP, WXViewUtils.getRealPxByWidth(stylesMap.getMarginTop(vp), vp));
- break;
- case Constants.Name.MARGIN_RIGHT:
- setMargin(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(stylesMap.getMarginRight(vp), vp));
- break;
- case Constants.Name.MARGIN_BOTTOM:
- setMargin(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(stylesMap.getMarginBottom(vp), vp));
- break;
- case Constants.Name.BORDER_WIDTH:
- setBorder(Spacing.ALL, WXViewUtils.getRealPxByWidth(stylesMap.getBorderWidth(vp), vp));
- break;
- case Constants.Name.BORDER_TOP_WIDTH:
- setBorder(Spacing.TOP, WXViewUtils.getRealPxByWidth(stylesMap.getBorderTopWidth(vp), vp));
- break;
- case Constants.Name.BORDER_RIGHT_WIDTH:
- setBorder(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(stylesMap.getBorderRightWidth(vp), vp));
- break;
- case Constants.Name.BORDER_BOTTOM_WIDTH:
- setBorder(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(stylesMap.getBorderBottomWidth(vp), vp));
- break;
- case Constants.Name.BORDER_LEFT_WIDTH:
- setBorder(Spacing.LEFT, WXViewUtils.getRealPxByWidth(stylesMap.getBorderLeftWidth(vp), vp));
- break;
- case Constants.Name.PADDING:
- setPadding(Spacing.ALL, WXViewUtils.getRealPxByWidth(stylesMap.getPadding(vp), vp));
- break;
- case Constants.Name.PADDING_LEFT:
- setPadding(Spacing.LEFT, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingLeft(vp), vp));
- break;
- case Constants.Name.PADDING_TOP:
- setPadding(Spacing.TOP, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingTop(vp), vp));
- break;
- case Constants.Name.PADDING_RIGHT:
- setPadding(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingRight(vp), vp));
- break;
- case Constants.Name.PADDING_BOTTOM:
- setPadding(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(stylesMap.getPaddingBottom(vp), vp));
- break;
- }
- }
- }
- }
-
- public int childCount() {
- return mDomChildren == null ? 0 : mDomChildren.size();
- }
-
- public void hide() {
- setVisible(false);
- }
-
- public void show() {
- setVisible(true);
- }
-
- public boolean isVisible() {
- return super.isShow();
- }
-
- /**
- * Clone the current object. This is not a deep copy, only shadow copy of some reference.
- * @return The result object of clone.
- */
- @Override
- public WXDomObject clone() {
- if (sDestroy.get()) {
- return null;
- }
- if(isCloneThis()){
- return this;
- }
- WXDomObject dom = null;
- try {
- dom = WXDomObjectFactory.newInstance(mType);
- copyFields(dom);
- } catch (Exception e) {
- if (WXEnvironment.isApkDebugable()) {
- WXLogUtils.e("WXDomObject clone error: ", e);
- }
- }
-
- return dom;
- }
-
- public boolean isDestroy(){
- if(sDestroy == null){
- return true;
- }
- return sDestroy.get();
- }
-
- public void destroy() {
- sDestroy.set(true);
- if (mStyles != null) {
- mStyles.clear();
- }
- if (mAttributes != null) {
- mAttributes.clear();
- }
- if (mEvents != null) {
- mEvents.clear();
- }
- if (mDomChildren != null) {
- int count = mDomChildren.size();
- for (int i = 0; i < count; ++i) {
- mDomChildren.get(i).destroy();
- }
- mDomChildren.clear();
- }
- mDomContext = null;
- }
-
- /** package **/
- /**
- * Get default style map for component.
- * @return
- */
- protected Map<String,String> getDefaultStyle(){
- return null;
- }
-
- public ArrayList<String> getFixedStyleRefs() {
- return fixedStyleRefs;
- }
-
- public void add2FixedDomList(String ref) {
- if (fixedStyleRefs == null) {
- fixedStyleRefs = new ArrayList<>();
- }
- fixedStyleRefs.add(ref);
- }
-
- public String dumpDomTree() {
- return mRef + ": " + toString();
- }
-
- /**
- * Parse the jsonObject to {@link WXDomObject} recursively
- * @param json the original JSONObject
- * @return Dom Object corresponding to the JSONObject.
- */
- public static @Nullable WXDomObject parse(JSONObject json, WXSDKInstance wxsdkInstance) {
- return parse(json, wxsdkInstance, null);
- }
-
- public static @Nullable WXDomObject parse(JSONObject json, WXSDKInstance wxsdkInstance, WXDomObject parentDomObject){
- long startNanos = System.nanoTime();
- long timestamp = System.currentTimeMillis();
- if (json == null || json.size() <= 0) {
- return null;
- }
-
- String type = (String) json.get(TYPE);
-
- if (wxsdkInstance.isNeedValidate()) {
- WXValidateProcessor processor = WXSDKManager.getInstance()
- .getValidateProcessor();
- if (processor != null) {
- WXValidateProcessor.WXComponentValidateResult result = processor
- .onComponentValidate(wxsdkInstance, type, parentDomObject);
- if (result != null && !result.isSuccess) {
- type = TextUtils.isEmpty(result.replacedComponent) ? WXBasicComponentType.DIV
- : result.replacedComponent;
- json.put(TYPE, type);
- if (result.validateInfo != null) {
- String tag = "[WXDomObject]onComponentValidate failure. >>> " + result.validateInfo.toJSONString();
- WXLogUtils.e(tag);
- }
- } else if (result == null){
- return null;
- }
- }
- }
-
- WXDomObject domObject = WXDomObjectFactory.newInstance(type);
-
- domObject.setViewPortWidth(wxsdkInstance.getInstanceViewPortWidth());
-
- if(domObject == null){
- return null;
- }
- domObject.parseFromJson(json);
- domObject.mDomContext = wxsdkInstance;
- domObject.parent = parentDomObject;
-
- Object children = json.get(CHILDREN);
- if (children != null && children instanceof JSONArray) {
- JSONArray childrenArray = (JSONArray) children;
- int count = childrenArray.size();
- for (int i = 0; i < count; ++i) {
- domObject.add(parse(childrenArray.getJSONObject(i),wxsdkInstance, domObject),-1);
- }
- }
-
- domObject.mDomThreadNanos = System.nanoTime() - startNanos;
- domObject.mDomThreadTimestamp = timestamp;
- return domObject;
- }
-
- public interface Consumer{
- void accept(WXDomObject dom);
- }
-
- public boolean isCloneThis() {
- return cloneThis;
- }
-
- public void setCloneThis(boolean cloneThis) {
- this.cloneThis = cloneThis;
- }
-
- /**
- * diff updates with source, return same value with source on updates map
- * if has update return true, else return false;
- * */
- private static boolean diffUpdates(Map<String,Object> updates, Map<String,Object> source){
- if(updates == null){
- return false;
- }
- /**
- Set<Map.Entry<String,Object>> entries = updates.entrySet();
- Iterator<Map.Entry<String,Object>> it = entries.iterator();
- while (it.hasNext()){
- Map.Entry<String,Object> entry = it.next();
- Object old = source.get(entry.getKey());
- if(entry.getValue() == old){
- it.remove();
- continue;
- }
- if(old == null){
- continue;
- }
- if(old.equals(entry.getValue())){
- it.remove();
- continue;
- }
- }*/
- return updates.size() > 0;
- }
-
- private static boolean shouldDirty(Map<String,Object> updates){
- if(updates.size() > 0){
- return true;
- }
- Set<Map.Entry<String, Object>> entries = updates.entrySet();
- for(Map.Entry<String, Object> entry : entries){
- if(dirtyStyle.contains(entry.getKey())){
- return true;
- }
- }
- return false;
- }
-
- private static final Set<String> dirtyStyle = new HashSet<>();
- static {
- dirtyStyle.add(Name.DEFAULT_HEIGHT);
- dirtyStyle.add(Name.DEFAULT_WIDTH);
- dirtyStyle.add(Name.WIDTH);
- dirtyStyle.add(Name.MIN_WIDTH);
- dirtyStyle.add(Name.MAX_WIDTH);
- dirtyStyle.add(Name.HEIGHT);
- dirtyStyle.add(Name.MIN_HEIGHT);
- dirtyStyle.add(Name.MAX_HEIGHT);
- dirtyStyle.add(Name.ALIGN_ITEMS);
- dirtyStyle.add(Name.ALIGN_SELF);
- dirtyStyle.add(Name.FLEX);
- dirtyStyle.add(Name.FLEX_DIRECTION);
- dirtyStyle.add(Name.JUSTIFY_CONTENT);
- dirtyStyle.add(Name.FLEX_WRAP);
- dirtyStyle.add(Name.MARGIN);
- dirtyStyle.add(Name.MARGIN_TOP);
- dirtyStyle.add(Name.MARGIN_LEFT);
- dirtyStyle.add(Name.MARGIN_RIGHT);
- dirtyStyle.add(Name.MARGIN_BOTTOM);
- dirtyStyle.add(Name.PADDING);
- dirtyStyle.add(Name.PADDING_TOP);
- dirtyStyle.add(Name.PADDING_LEFT);
- dirtyStyle.add(Name.PADDING_RIGHT);
- dirtyStyle.add(Name.PADDING_BOTTOM);
- dirtyStyle.add(Name.LEFT);
- dirtyStyle.add(Name.TOP);
- dirtyStyle.add(Name.RIGHT);
- dirtyStyle.add(Name.BOTTOM);
- dirtyStyle.add(Name.BORDER_WIDTH);
- dirtyStyle.add(Name.BORDER_TOP_WIDTH);
- dirtyStyle.add(Name.BORDER_RIGHT_WIDTH);
- dirtyStyle.add(Name.BORDER_BOTTOM_WIDTH);
- dirtyStyle.add(Name.BORDER_LEFT_WIDTH);
-
- dirtyStyle.add(Name.POSITION);
- dirtyStyle.add(Name.TEXT_DECORATION);
- dirtyStyle.add(Name.TEXT_ALIGN);
- dirtyStyle.add(Name.FONT_WEIGHT);
- dirtyStyle.add(Name.FONT_STYLE);
- dirtyStyle.add(Name.FONT_SIZE);
- dirtyStyle.add(Name.COLOR);
- dirtyStyle.add(Name.LINES);
- dirtyStyle.add(Name.FONT_FAMILY);
- dirtyStyle.add(Name.TEXT_OVERFLOW);
- dirtyStyle.add(Name.ELLIPSIS);
- dirtyStyle.add(Name.LINE_HEIGHT);
- dirtyStyle.add(Name.VALUE);
- dirtyStyle.add(Name.OVERFLOW);
- dirtyStyle.add(Name.SINGLELINE);
- dirtyStyle.add(Name.MAX_LENGTH);
- dirtyStyle.add(Name.MAXLENGTH);
- dirtyStyle.add(Name.ROWS);
- dirtyStyle.add(Name.VISIBILITY);
- dirtyStyle.add(Name.ITEM_SIZE);
- dirtyStyle.add(Name.DISPLAY);
- dirtyStyle.add(Name.RESIZE);
- dirtyStyle.add(Name.FONT_FACE);
- dirtyStyle.add(Name.MAX);
- dirtyStyle.add(Name.MIN);
- dirtyStyle.add(Name.FONT_FACE);
-
- }
-
- public static void addDirtyKey(String key){
- dirtyStyle.add(key);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXDomObjectFactory.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomObjectFactory.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXDomObjectFactory.java
deleted file mode 100644
index 77bd8dd..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomObjectFactory.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.support.annotation.Nullable;
-import android.text.TextUtils;
-
-import com.taobao.weex.WXEnvironment;
-import com.taobao.weex.utils.WXLogUtils;
-
-/**
- * Factory class for creating {@link WXDomObject}
- */
-public class WXDomObjectFactory {
-
- public static @Nullable WXDomObject newInstance(String type) {
- if (TextUtils.isEmpty(type)) {
- return null;
- }
-
- Class<? extends WXDomObject> clazz = WXDomRegistry.getDomObjectClass(type);
- if (clazz == null) {
- if (WXEnvironment.isApkDebugable()) {
- String tag = "WXDomObjectFactory error type:[" +
- type + "]" + " class not found";
- WXLogUtils.e(tag);
- }
- }
-
- try {
- if (WXDomObject.class.isAssignableFrom(clazz)) {
- WXDomObject domObject = clazz.getConstructor()
- .newInstance();
- return domObject;
- }
- } catch (Exception e) {
- WXLogUtils.e("WXDomObjectFactory Exception type:[" + type + "] ", e);
- }
-
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXDomRegistry.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomRegistry.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXDomRegistry.java
deleted file mode 100644
index df495a8..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomRegistry.java
+++ /dev/null
@@ -1,59 +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.text.TextUtils;
-
-import com.taobao.weex.WXEnvironment;
-import com.taobao.weex.common.WXException;
-import com.taobao.weex.utils.WXLogUtils;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class WXDomRegistry {
-
- public static Class<? extends WXDomObject> mDefaultClass = WXDomObject.class;
- private static Map<String, Class<? extends WXDomObject>> sDom = new HashMap<>();
-
- public static boolean registerDomObject(String type, Class<? extends WXDomObject> clazz) throws WXException {
- if (clazz == null || TextUtils.isEmpty(type)) {
- return false;
- }
-
- if (sDom.containsKey(type)) {
- if (WXEnvironment.isApkDebugable()) {
- throw new WXException("WXDomRegistry had duplicate Dom:" + type);
- } else {
- WXLogUtils.e("WXDomRegistry had duplicate Dom: " + type);
- return false;
- }
- }
- sDom.put(type, clazz);
- return true;
- }
-
- public static Class<? extends WXDomObject> getDomObjectClass(String type) {
- if (TextUtils.isEmpty(type)) {
- return mDefaultClass;
- }
- Class<? extends WXDomObject> clazz = sDom.get(type);
- return clazz == null ? mDefaultClass : clazz;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXDomTask.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomTask.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXDomTask.java
deleted file mode 100644
index 140b668..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXDomTask.java
+++ /dev/null
@@ -1,34 +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 com.taobao.weex.common.IWXTask;
-
-import java.util.List;
-
-/**
- * Wrapper class for storing info about dom operation. Used when {@link WXDomModule} communicate
- * with handler.
- */
-public class WXDomTask implements IWXTask {
-
- public String instanceId;
- public List<Object> args;
- public long startTime = System.nanoTime();
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java
index 3e99cfa..7a77fa9 100644
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java
+++ b/android/sdk/src/main/java/com/taobao/weex/dom/WXEvent.java
@@ -35,7 +35,6 @@ public class WXEvent extends ArrayList<String> implements Serializable, Cloneabl
private static final long serialVersionUID = -8186587029452440107L;
-
/**
* event data format
* {
@@ -58,6 +57,7 @@ public class WXEvent extends ArrayList<String> implements Serializable, Cloneabl
private ArrayMap mEventBindingArgs;
private ArrayMap<String, List<Object>> mEventBindingArgsValues;
+
@Override
public void clear() {
if(mEventBindingArgs != null){
@@ -146,8 +146,6 @@ public class WXEvent extends ArrayList<String> implements Serializable, Cloneabl
}
}
-
-
@Override
public WXEvent clone() {
WXEvent event = new WXEvent();
@@ -158,6 +156,4 @@ public class WXEvent extends ArrayList<String> implements Serializable, Cloneabl
event.mEventBindingArgsValues = null; //this should not be clone, it dynamic args
return event;
}
-
-
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/dom/WXListDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXListDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXListDomObject.java
deleted file mode 100644
index 09b3b43..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXListDomObject.java
+++ /dev/null
@@ -1,51 +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 com.taobao.weex.ui.component.WXBasicComponentType;
-
-import java.util.Map;
-
-public class WXListDomObject extends WXDomObject {
-
- @Override
- protected Map<String, String> getDefaultStyle() {
- Map<String,String> map = new ArrayMap<>();
-
- boolean isVertical = true;
- if (parent != null) {
- if (parent.getType() != null) {
- if (parent.getType().equals(WXBasicComponentType.HLIST)) {
- 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/WXRecyclerDomObject.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java b/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
deleted file mode 100644
index daf3850..0000000
--- a/android/sdk/src/main/java/com/taobao/weex/dom/WXRecyclerDomObject.java
+++ /dev/null
@@ -1,281 +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.WXEnvironment;
-import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.flex.Spacing;
-import com.taobao.weex.ui.component.WXBasicComponentType;
-import com.taobao.weex.utils.WXLogUtils;
-import com.taobao.weex.utils.WXUtils;
-import com.taobao.weex.utils.WXViewUtils;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-
-/**
- * Created by zhengshihan on 2017/2/21.
- */
-public class WXRecyclerDomObject extends WXDomObject{
-
-
- private int mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
- private float mColumnWidth = Constants.Value.AUTO;
- private float mColumnGap = Constants.Value.COLUMN_GAP_NORMAL;
- private float mAvailableWidth = 0;
- private boolean mIsPreCalculateCellWidth =false;
-
- private float mLeftGap = 0;
- private float mRightGap = 0;
-
- private float[] spanOffsets;
-
- /**cell-slot not on the tree */
- private List<WXCellDomObject> cellList;
-
-
- public float getAvailableWidth() {
- return WXViewUtils.getRealPxByWidth(mAvailableWidth, getViewPortWidth());
- }
-
- public int getLayoutType(){
- return getAttrs().getLayoutType();
- }
-
- public float getColumnGap() {
- return WXViewUtils.getRealPxByWidth(mColumnGap, getViewPortWidth());
- }
-
-
- public int getColumnCount() {
- return mColumnCount;
- }
-
- public float getColumnWidth() {
- return WXViewUtils.getRealPxByWidth(mColumnWidth,getViewPortWidth());
- }
-
- public float getLeftGap() {
- return WXViewUtils.getRealPxByWidth(mLeftGap,getViewPortWidth());
- }
-
- public float getRightGap() {
- return WXViewUtils.getRealPxByWidth(mRightGap,getViewPortWidth());
- }
-
- @Override
- public void add(WXDomObject child, int index) {
- if(WXBasicComponentType.CELL_SLOT.equals(child.getType())
- && child instanceof WXCellDomObject){
- if(cellList == null){
- cellList = Collections.synchronizedList(new ArrayList<WXCellDomObject>());
- }
- cellList.add((WXCellDomObject)child);
- }else{
- super.add(child, index);
- }
-
- if (WXBasicComponentType.CELL.equals(child.getType())
- || WXBasicComponentType.CELL_SLOT.equals(child.getType())) {
- if (!mIsPreCalculateCellWidth) {
- preCalculateCellWidth();
- }
- if(mColumnWidth!=0 && mColumnWidth!= Float.NaN) {
- child.getStyles().put(Constants.Name.WIDTH, mColumnWidth);
- }
- }
- }
-
- @Override
- public void remove(WXDomObject child) {
- if(cellList != null){
- cellList.remove(child);
- }
- super.remove(child);
- }
-
- @Override
- public void removeFromDom(WXDomObject child) {
- if(cellList != null){
- cellList.remove(child);
- }
- super.removeFromDom(child);
- }
-
- @Override
- public float getStyleWidth() {
- float width = super.getStyleWidth();
- if (Float.isNaN(width) || width <= 0){
- width = super.getLayoutWidth();
- if (Float.isNaN(width) || width <= 0){
- if(getStyles().containsKey(Constants.Name.WIDTH)) {
- width = WXViewUtils.getRealPxByWidth(getStyles().containsKey(Constants.Name.WIDTH) ? getStyles().getWidth(getViewPortWidth()) : getStyles().getDefaultWidth(), getViewPortWidth());
- }
- if (Float.isNaN(width) || width <= 0){
- if(getParent() != null){
- width = getParent().getLayoutWidth();
- }
- }
- }
- }
- if (Float.isNaN(width) || width <= 0){
- width = WXViewUtils.getRealPxByWidth(getViewPortWidth(), getViewPortWidth());
- }
- return width;
- }
-
-
-
-
- public void preCalculateCellWidth(){
-
- if (getAttrs() != null) {
- mColumnCount = getAttrs().getColumnCount();
- mColumnWidth = getAttrs().getColumnWidth();
- mColumnGap = getAttrs().getColumnGap();
- mLeftGap = WXUtils.getFloat(getAttrs().get(Constants.Name.LEFT_GAP),0.0f);
- mRightGap = WXUtils.getFloat(getAttrs().get(Constants.Name.RIGHT_GAP),0.0f);
-
- mAvailableWidth = getStyleWidth()-getPadding().get(Spacing.LEFT)-getPadding().get(Spacing.RIGHT);
- mAvailableWidth = WXViewUtils.getWebPxByWidth(mAvailableWidth,getViewPortWidth());
-
- if (Constants.Value.AUTO == mColumnCount && Constants.Value.AUTO == mColumnWidth) {
- mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
- } else if (Constants.Value.AUTO == mColumnWidth && Constants.Value.AUTO != mColumnCount) {
- mColumnWidth = (mAvailableWidth - mLeftGap - mRightGap - ((mColumnCount - 1) * mColumnGap)) / mColumnCount;
- mColumnWidth = mColumnWidth > 0 ? mColumnWidth :0;
- } else if (Constants.Value.AUTO != mColumnWidth && Constants.Value.AUTO == mColumnCount) {
- mColumnCount = Math.round((mAvailableWidth + mColumnGap) / (mColumnWidth + mColumnGap)-0.5f);
- mColumnCount = mColumnCount > 0 ? mColumnCount :1;
- if (mColumnCount <= 0)
- mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
- mColumnWidth =((mAvailableWidth + mColumnGap - mLeftGap - mRightGap) / mColumnCount) - mColumnGap;
- } else if(Constants.Value.AUTO != mColumnWidth && Constants.Value.AUTO != mColumnCount){
- int columnCount = Math.round((mAvailableWidth + mColumnGap - mLeftGap - mRightGap) / (mColumnWidth + mColumnGap)-0.5f);
- mColumnCount = columnCount > mColumnCount ? mColumnCount :columnCount;
- if (mColumnCount <= 0)
- mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
- mColumnWidth = ((mAvailableWidth + mColumnGap - mLeftGap - mRightGap) / mColumnCount) - mColumnGap;
- }
- calcSpanOffset();
- mIsPreCalculateCellWidth = true;
- if(WXEnvironment.isApkDebugable()) {
- WXLogUtils.d("preCalculateCellWidth mColumnGap :" + mColumnGap + " mColumnWidth:" + mColumnWidth + " mColumnCount:" + mColumnCount);
- }
- }
- }
-
- public boolean hasPreCalculateCellWidth(){
- return mIsPreCalculateCellWidth;
- }
-
- public void updateRecyclerAttr(){
- preCalculateCellWidth();
- if(mColumnWidth ==0 && mColumnWidth == Float.NaN){
- WXLogUtils.w("preCalculateCellWidth mColumnGap :" + mColumnGap + " mColumnWidth:" + mColumnWidth + " mColumnCount:" + mColumnCount);
- return;
- }
- int count = getChildCount();
- for(int i=0;i<count; i++){
- WXDomObject domObject = getChild(i);
- if(WXBasicComponentType.CELL.equals(domObject.getType())) {
- getChild(i).getStyles().put(Constants.Name.WIDTH, mColumnWidth);
- }
- }
- }
-
- @Override
- public void updateAttr(Map<String, Object> attrs) {
- super.updateAttr(attrs);
- if(attrs.containsKey(Constants.Name.COLUMN_COUNT)
- || attrs.containsKey(Constants.Name.COLUMN_GAP)
- || attrs.containsKey(Constants.Name.COLUMN_WIDTH)){
- updateRecyclerAttr();
- }
- }
-
- @Override
- protected Map<String, String> getDefaultStyle() {
- Map<String,String> map = new ArrayMap<>();
-
- boolean isVertical = true;
- if (parent != null) {
- if (parent.getType() != null) {
- if (parent.getType().equals(WXBasicComponentType.HLIST)) {
- isVertical = false;
- }else{
- if(getOrientation() == Constants.Orientation.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;
- }
-
-
- public int getOrientation(){
- String direction = (String) getAttrs().get(Constants.Name.SCROLL_DIRECTION);
- if(Constants.Value.HORIZONTAL.equals(direction)){
- return Constants.Orientation.HORIZONTAL;
- }
- return Constants.Orientation.VERTICAL;
- }
-
- @Override
- public WXDomObject clone() {
- if(isCloneThis()){
- return this;
- }
- WXRecyclerDomObject domObject = (WXRecyclerDomObject) super.clone();
- domObject.cellList = cellList;
- return domObject;
- }
-
- public void calcSpanOffset(){
- if(mLeftGap > 0 || mRightGap > 0){
- if(spanOffsets == null || spanOffsets.length != mColumnCount){
- spanOffsets = new float[mColumnCount];
- }
- for(int i=0; i<mColumnCount; i++){
- spanOffsets[i] = mLeftGap + i*((mColumnWidth + mColumnGap) - (mAvailableWidth + mColumnGap)/mColumnCount);
- }
- }
- }
-
- public float[] getSpanOffsets() {
- return spanOffsets;
- }
-
- public List<WXCellDomObject> getCellList() {
- return cellList;
- }
-}