http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionAddRule.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionAddRule.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionAddRule.java new file mode 100644 index 0000000..0f74e2b --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionAddRule.java @@ -0,0 +1,78 @@ +/** + * 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.ui.action; + +import android.text.TextUtils; + +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.common.Constants; +import com.taobao.weex.utils.FontDO; +import com.taobao.weex.utils.TypefaceUtil; + +/** + * Created by listen on 18/01/10. + */ +public class ActionAddRule implements IExecutable { + + private final String mPageId; + private final String mType; + private final JSONObject mData; + + public ActionAddRule(String pageId, String type, JSONObject data) { + this.mPageId = pageId; + this.mType = type; + this.mData = data; + } + + @Override + public void executeAction() { + WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(mPageId); + if (instance == null || instance.isDestroy()) { + return; + } + + if (!Constants.Name.FONT_FACE.equals(mType)) { + return; + } + + FontDO fontDO = parseFontDO(mData, instance); + 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); + } +}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionGetComponentRect.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionGetComponentRect.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionGetComponentRect.java new file mode 100644 index 0000000..75b543f --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionGetComponentRect.java @@ -0,0 +1,120 @@ +/** + * 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.ui.action; + +import android.graphics.Rect; +import android.support.annotation.NonNull; +import android.text.TextUtils; +import android.view.View; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.bridge.JSCallback; +import com.taobao.weex.bridge.SimpleJSCallback; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.utils.WXViewUtils; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by listen on 18/01/10. + */ +public class ActionGetComponentRect extends BasicGraphicAction { + + private final String mCallback; + + public ActionGetComponentRect(String pageId, String ref, String callback) { + super(pageId, ref); + this.mCallback = callback; + } + + @Override + public void executeAction() { + WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null || instance.isDestroy()) { + return; + } + + JSCallback jsCallback = new SimpleJSCallback(instance.getInstanceId(), mCallback); + + if (TextUtils.isEmpty(getRef())) { + Map<String, Object> options = new HashMap<>(); + options.put("result", false); + options.put("errMsg", "Illegal parameter"); + jsCallback.invoke(options); + } else if ("viewport".equalsIgnoreCase(getRef())) { + callbackViewport(instance, jsCallback); + } else { + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + + Map<String, Object> options = new HashMap<>(); + if (component != null) { + int viewPort = instance.getInstanceViewPortWidth(); + Map<String, Float> size = new HashMap<>(); + Rect sizes = component.getComponentSize(); + size.put("width", getWebPxValue(sizes.width(),viewPort)); + size.put("height", getWebPxValue(sizes.height(),viewPort)); + size.put("bottom", getWebPxValue(sizes.bottom,viewPort)); + size.put("left", getWebPxValue(sizes.left,viewPort)); + size.put("right", getWebPxValue(sizes.right,viewPort)); + size.put("top", getWebPxValue(sizes.top,viewPort)); + options.put("size", size); + options.put("result", true); + } else { + options.put("errMsg", "Component does not exist"); + } + jsCallback.invoke(options); + } + } + + private void callbackViewport(WXSDKInstance instance, JSCallback jsCallback) { + View container; + if ((container = instance.getContainerView()) != null) { + Map<String, Object> options = new HashMap<>(); + Map<String, Float> sizes = new HashMap<>(); + int[] location = new int[2]; + instance.getContainerView().getLocationOnScreen(location); + int viewport = instance.getInstanceViewPortWidth(); + sizes.put("left", 0f); + sizes.put("top", 0f); + sizes.put("right", getWebPxValue(container.getWidth(),viewport)); + sizes.put("bottom", getWebPxValue(container.getHeight(),viewport)); + sizes.put("width", getWebPxValue(container.getWidth(),viewport)); + sizes.put("height", getWebPxValue(container.getHeight(),viewport)); + options.put("size", sizes); + options.put("result", true); + jsCallback.invoke(options); + } else { + Map<String, Object> options = new HashMap<>(); + options.put("result", false); + options.put("errMsg", "Component does not exist"); + jsCallback.invoke(options); + } + } + + @NonNull + private float getWebPxValue(int value,int viewport) { + return WXViewUtils.getWebPxByWidth(value, viewport); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java new file mode 100644 index 0000000..f078d1b --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionInvokeMethod.java @@ -0,0 +1,54 @@ +/** + * 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.ui.action; + +import com.alibaba.fastjson.JSONArray; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.utils.WXLogUtils; + +/** + * Created by listen on 18/01/10. + */ +public class ActionInvokeMethod implements IExecutable { + + private static final String TAG = "ActionInvokeMethod"; + + private final String mMethod; + private final JSONArray mArgs; + private String mPageId; + private String mRef; + + public ActionInvokeMethod(String pageId, String ref, String method, JSONArray args) { + this.mPageId = pageId; + this.mRef = ref; + this.mMethod = method; + this.mArgs = args; + } + + @Override + public void executeAction() { + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(mPageId, mRef); + if(component == null){ + WXLogUtils.e(TAG,"target component not found."); + return; + } + component.invoke(mMethod,mArgs); + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionReloadPage.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionReloadPage.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionReloadPage.java new file mode 100644 index 0000000..42705f6 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/ActionReloadPage.java @@ -0,0 +1,49 @@ +/** + * 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.ui.action; + +import android.util.Log; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; + +/** + * Created by listen on 18/01/09. + */ +public class ActionReloadPage implements IExecutable { + + private final String TAG = "ReloadPageAction"; + private boolean mReloadThis; + private String mPageId; + + public ActionReloadPage(String pageId, boolean reloadThis) { + this.mPageId = pageId; + this.mReloadThis = reloadThis; + } + + @Override + public void executeAction() { + final WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(mPageId); + if (instance != null) { + instance.reloadPage(mReloadThis); + } else { + Log.e(TAG, "ReloadPageAction executeDom reloadPage instance is null"); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicComponentData.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicComponentData.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicComponentData.java new file mode 100644 index 0000000..b544cb9 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicComponentData.java @@ -0,0 +1,265 @@ +/** + * 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.ui.action; + +import android.support.annotation.NonNull; +import android.view.View; + +import com.taobao.weex.common.Constants; +import com.taobao.weex.dom.CSSShorthand; +import com.taobao.weex.dom.WXAttr; +import com.taobao.weex.dom.WXEvent; +import com.taobao.weex.dom.WXStyle; +import com.taobao.weex.utils.WXUtils; + +import java.util.Map; +import java.util.Set; + +public class BasicComponentData<T extends View> { + + public String mRef; + public String mComponentType; + public String mParentRef; + private WXStyle mStyles; + private WXAttr mAttributes; + private WXEvent mEvents; + private CSSShorthand mMargins; + private CSSShorthand mPaddings; + private CSSShorthand mBorders; + + public BasicComponentData(String ref, String componentType, String parentRef) { + this.mRef = ref; + this.mComponentType = componentType; + this.mParentRef = parentRef; + } + + public void addStyle(Map<String, Object> styles) { + addStyle(styles, false); + } + + public final void addStyle(Map<String, Object> styles, boolean byPesudo) { + if (styles == null || styles.isEmpty()) { + return; + } + if (mStyles == null) { + mStyles = new WXStyle(styles); + } + else { + mStyles.putAll(styles, byPesudo); + } + } + + public final void addAttr(Map<String, Object> attrs) { + if (attrs == null || attrs.isEmpty()) { + return; + } + if (mAttributes == null) { + mAttributes = new WXAttr(attrs, 0); + } + else { + mAttributes.putAll(attrs); + } + } + + public final void addEvent(Set<String> events) { + if (events == null || events.isEmpty()) { + return; + } + if (mEvents == null) { + mEvents = new WXEvent(); + } + mEvents.addAll(events); + } + + public final void addShorthand(float[] shorthand, CSSShorthand.TYPE type) { + if (shorthand.length == 4) { + switch (type) { + case MARGIN: + if(mMargins == null){ + mMargins = new CSSShorthand(shorthand); + } + else{ + mMargins.replace(shorthand); + } + break; + case PADDING: + if(mPaddings == null){ + mPaddings = new CSSShorthand(shorthand); + } + else{ + mPaddings.replace(shorthand); + } + break; + case BORDER: + if(mBorders == null){ + mBorders = new CSSShorthand(shorthand); + } + else{ + mBorders.replace(shorthand); + } + break; + } + } + } + + public final void addShorthand(Map<String, String> shorthand) { + if (shorthand != null && !shorthand.isEmpty()) { + for (Map.Entry<String, String> item : shorthand.entrySet()) { + String key = item.getKey(); + switch (key) { + case Constants.Name.MARGIN: + addMargin(CSSShorthand.EDGE.ALL, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.MARGIN_LEFT: + addMargin(CSSShorthand.EDGE.LEFT, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.MARGIN_TOP: + addMargin(CSSShorthand.EDGE.TOP, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.MARGIN_RIGHT: + addMargin(CSSShorthand.EDGE.RIGHT, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.MARGIN_BOTTOM: + addMargin(CSSShorthand.EDGE.BOTTOM,WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.BORDER_WIDTH: + addBorder(CSSShorthand.EDGE.ALL, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.BORDER_TOP_WIDTH: + addBorder(CSSShorthand.EDGE.TOP, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.BORDER_RIGHT_WIDTH: + addBorder(CSSShorthand.EDGE.RIGHT, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.BORDER_BOTTOM_WIDTH: + addBorder(CSSShorthand.EDGE.BOTTOM, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.BORDER_LEFT_WIDTH: + addBorder(CSSShorthand.EDGE.LEFT, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.PADDING: + addPadding(CSSShorthand.EDGE.ALL, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.PADDING_LEFT: + addPadding(CSSShorthand.EDGE.LEFT, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.PADDING_TOP: + addPadding(CSSShorthand.EDGE.TOP, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.PADDING_RIGHT: + addPadding(CSSShorthand.EDGE.RIGHT, WXUtils.fastGetFloat(shorthand.get(key))); + break; + case Constants.Name.PADDING_BOTTOM: + addPadding(CSSShorthand.EDGE.BOTTOM, WXUtils.fastGetFloat(shorthand.get(key))); + break; + } + } + } + } + + private void addMargin(CSSShorthand.EDGE spacingType, float margin) { + if (mMargins == null) { + mMargins = new CSSShorthand(); + } + mMargins.set(spacingType, margin); + } + + private void addPadding(CSSShorthand.EDGE spacingType, float padding) { + if (mPaddings == null) { + mPaddings = new CSSShorthand(); + } + mPaddings.set(spacingType, padding); + } + + private void addBorder(CSSShorthand.EDGE spacingType, float border) { + if (mBorders == null) { + mBorders = new CSSShorthand(); + } + mBorders.set(spacingType, border); + } + + public final @NonNull + WXStyle getStyles() { + if (mStyles == null) { + mStyles = new WXStyle(); + } + return mStyles; + } + + public final @NonNull + WXAttr getAttrs() { + if (mAttributes == null) { + mAttributes = new WXAttr(); + } + return mAttributes; + } + + public final @NonNull + WXEvent getEvents() { + if (mEvents == null) { + mEvents = new WXEvent(); + } + return mEvents; + } + + /** + * Get this node's margin, as defined by cssstyle + default margin. + */ + public final @NonNull + CSSShorthand getMargin() { + if (mMargins == null) { + mMargins = new CSSShorthand(); + } + return mMargins; + } + + /** + * Get this node's padding, as defined by cssstyle + default padding. + */ + public final @NonNull + CSSShorthand getPadding() { + if (mPaddings == null) { + mPaddings = new CSSShorthand(); + } + return mPaddings; + } + + /** + * Get this node's border, as defined by cssstyle. + */ + public @NonNull + CSSShorthand getBorder() { + if (mBorders == null) { + mBorders = new CSSShorthand(); + } + return mBorders; + } + + public final void setMargins(@NonNull CSSShorthand mMargins) { + this.mMargins = mMargins; + } + + public final void setPaddings(@NonNull CSSShorthand mPaddings) { + this.mPaddings = mPaddings; + } + + public final void setBorders(@NonNull CSSShorthand mBorders) { + this.mBorders = mBorders; + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicGraphicAction.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicGraphicAction.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicGraphicAction.java new file mode 100644 index 0000000..2a37aa3 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/BasicGraphicAction.java @@ -0,0 +1,69 @@ +/** + * 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.ui.action; + +import android.text.TextUtils; +import com.taobao.weex.WXEnvironment; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.utils.WXLogUtils; + +public abstract class BasicGraphicAction implements IExecutable, Runnable { + + private final String mPageId; + private final String mRef; + + public BasicGraphicAction(String pageId, String ref) { + this.mPageId = pageId; + this.mRef = ref; + } + + public final String getPageId() { + return mPageId; + } + + public final String getRef() { + return mRef; + } + + public void executeActionOnRender() { + if (TextUtils.isEmpty(mPageId)) { + WXLogUtils.e("[BasicGraphicAction] pageId can not be null"); + if (WXEnvironment.isApkDebugable()) { + throw new RuntimeException("["+getClass().getName()+"] pageId can not be null"); + } + return; + } + WXSDKManager.getInstance().getWXRenderManager().postGraphicAction(mPageId, this); + } + + @Override + public void run() { + try { + executeAction(); + } catch (Throwable e) { + //catch everything may throw from exection. + if (WXEnvironment.isApkDebugable()) { + WXLogUtils.e("BasicGraphicAction", + "SafeRunnable run throw expection:" + e.getMessage()); + throw e; + } + WXLogUtils.w("BasicGraphicAction", e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java new file mode 100644 index 0000000..a26c39e --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAbstractAddElement.java @@ -0,0 +1,94 @@ +/** + * 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.ui.action; + +import android.support.v4.util.ArrayMap; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.common.Constants; +import com.taobao.weex.dom.CSSShorthand; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXComponentFactory; +import com.taobao.weex.ui.component.WXVContainer; +import java.util.Map; +import java.util.Set; + +public abstract class GraphicActionAbstractAddElement extends BasicGraphicAction { + + protected String mComponentType; + protected String mParentRef; + protected int mIndex = -1; + protected Map<String, String> mStyle; + protected Map<String, String> mAttributes; + protected Set<String> mEvents; + protected float[] mMargins; + protected float[] mPaddings; + protected float[] mBorders; + + public GraphicActionAbstractAddElement(String pageId, String ref) { + super(pageId, ref); + } + + protected WXComponent createComponent(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) { + if (basicComponentData != null) { + basicComponentData.addStyle(mStyle); + basicComponentData.addAttr(mAttributes); + basicComponentData.addEvent(mEvents); + basicComponentData.addShorthand(mMargins, CSSShorthand.TYPE.MARGIN); + basicComponentData.addShorthand(mPaddings, CSSShorthand.TYPE.PADDING); + basicComponentData.addShorthand(mBorders, CSSShorthand.TYPE.BORDER); + } + + WXComponent component = WXComponentFactory.newInstance(instance, parent, basicComponentData); + WXSDKManager.getInstance().getWXRenderManager().registerComponent(getPageId(), getRef(), component); + if(mStyle.containsKey(Constants.Name.TRANSFORM)) { + Map<String, Object> animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, mStyle.get(Constants.Name.TRANSFORM)); + animationMap + .put(Constants.Name.TRANSFORM_ORIGIN, mStyle.get(Constants.Name.TRANSFORM_ORIGIN)); + component.addAnimationForElement(animationMap); + } + WXSDKManager.getInstance().getSDKInstance(getPageId()).callActionAddElementCount(); + return component; + } + + public String getComponentType() { + return mComponentType; + } + + public String getParentRef() { + return mParentRef; + } + + public int getIndex() { + return mIndex; + } + + public Map<String, String> getStyle() { + return mStyle; + } + + public Map<String, String> getAttributes() { + return mAttributes; + } + + public Set<String> getEvents() { + return mEvents; + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java new file mode 100644 index 0000000..aa60a73 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddElement.java @@ -0,0 +1,115 @@ +/** + * 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.ui.action; + +import android.support.annotation.RestrictTo; +import android.support.annotation.RestrictTo.Scope; +import android.support.annotation.WorkerThread; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.dom.transition.WXTransition; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXVContainer; +import com.taobao.weex.utils.WXLogUtils; + +import java.util.Map; +import java.util.Set; + +public class GraphicActionAddElement extends GraphicActionAbstractAddElement { + + private WXVContainer parent; + private WXComponent child; + private GraphicPosition layoutPosition; + private GraphicSize layoutSize; + + public GraphicActionAddElement(String pageId, String ref, + String componentType, String parentRef, + int index, + Map<String, String> style, + Map<String, String> attributes, + Set<String> events, + float[] margins, + float[] paddings, + float[] borders) { + super(pageId, ref); + this.mComponentType = componentType; + this.mParentRef = parentRef; + this.mIndex = index; + this.mStyle = style; + this.mAttributes = attributes; + this.mEvents = events; + this.mPaddings = paddings; + this.mMargins = margins; + this.mBorders = borders; + + WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null || instance.getContext() == null) { + return; + } + + parent = (WXVContainer) WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentRef); + BasicComponentData basicComponentData = new BasicComponentData(ref, mComponentType, mParentRef); + child = createComponent(instance, parent, basicComponentData); + child.setTransition(WXTransition.fromMap(child.getStyles(), child)); + + if (child == null || parent == null) { + return; + } + + } + + @RestrictTo(Scope.LIBRARY) + @WorkerThread + public void setSize(GraphicSize graphicSize){ + this.layoutSize = graphicSize; + } + + @RestrictTo(Scope.LIBRARY) + @WorkerThread + public void setPosition(GraphicPosition position){ + this.layoutPosition = position; + } + + @RestrictTo(Scope.LIBRARY) + @WorkerThread + public void setIndex(int index){ + mIndex = index; + } + + @Override + public void executeAction() { + try { + parent.addChild(child, mIndex); + parent.createChildViewAt(mIndex); + + long start = System.currentTimeMillis(); + if(layoutPosition !=null && layoutSize != null) { + child.updateDemission(layoutSize, layoutPosition); + } + child.applyLayoutAndEvent(child); + WXSDKManager.getInstance().getSDKInstance(getPageId()).callLayoutaAplyLayoutAndEventTime(System.currentTimeMillis() - start); + + start = System.currentTimeMillis(); + child.bindData(child); + WXSDKManager.getInstance().getSDKInstance(getPageId()).callLayoutBindDataCoreTime(System.currentTimeMillis() - start); + } catch (Exception e) { + WXLogUtils.e("add component failed.", e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java new file mode 100644 index 0000000..824b347 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAddEvent.java @@ -0,0 +1,53 @@ +/** + * 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.ui.action; + +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.dom.WXEvent; +import com.taobao.weex.tracing.Stopwatch; +import com.taobao.weex.ui.component.WXComponent; + +/** + * Created by listen on 18/01/11. + */ +public class GraphicActionAddEvent extends BasicGraphicAction { + + private final String mEvent; + + public GraphicActionAddEvent(String pageId, String ref, Object event) { + super(pageId, ref); + this.mEvent = WXEvent.getEventName(event); + } + + @Override + public void executeAction() { + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + + Stopwatch.tick(); + if (!component.getEvents().contains(mEvent)) { + component.getEvents().addEvent(mEvent); + } + component.addEvent(mEvent); + Stopwatch.split("addEventToComponent"); + + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java new file mode 100644 index 0000000..c8b0a04 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionAnimation.java @@ -0,0 +1,266 @@ +/** + * 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.ui.action; + +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ArgbEvaluator; +import android.animation.ObjectAnimator; +import android.animation.PropertyValuesHolder; +import android.graphics.drawable.ColorDrawable; +import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.view.animation.PathInterpolatorCompat; +import android.text.TextUtils; +import android.util.Pair; +import android.view.View; +import android.view.ViewGroup; +import android.view.animation.AccelerateDecelerateInterpolator; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.DecelerateInterpolator; +import android.view.animation.Interpolator; +import android.view.animation.LinearInterpolator; + +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.animation.BackgroundColorProperty; +import com.taobao.weex.ui.animation.HeightProperty; +import com.taobao.weex.ui.animation.WXAnimationBean; +import com.taobao.weex.ui.animation.WXAnimationModule; +import com.taobao.weex.ui.animation.WidthProperty; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.view.border.BorderDrawable; +import com.taobao.weex.utils.SingleFunctionParser; +import com.taobao.weex.utils.WXLogUtils; +import com.taobao.weex.utils.WXResourceUtils; +import com.taobao.weex.utils.WXUtils; +import com.taobao.weex.utils.WXViewUtils; + +import java.util.HashMap; +import java.util.List; + +public class GraphicActionAnimation extends BasicGraphicAction { + + private final static String TAG = "GraphicActionAnimation"; + + @Nullable + private + final String callback; + + @Nullable + private + WXAnimationBean mAnimationBean; + + public GraphicActionAnimation(@NonNull String pageId, @NonNull String ref, @NonNull WXAnimationBean animationBean) { + super(pageId, ref); + this.callback = null; + this.mAnimationBean = animationBean; + } + + public GraphicActionAnimation(@NonNull String pageId, @NonNull String ref, @Nullable String animation, + @Nullable final String callBack) { + super(pageId, ref); + this.callback = callBack; + if (!TextUtils.isEmpty(animation)) { + this.mAnimationBean = JSONObject.parseObject(animation, WXAnimationBean.class); + } + } + public GraphicActionAnimation(@NonNull String pageId, @NonNull String ref, @NonNull WXAnimationBean animationBean, + @Nullable final String callBack) { + super(pageId, ref); + this.mAnimationBean = animationBean; + this.callback = callBack; + } + + @Override + public void executeAction() { + if (null == mAnimationBean) { + return; + } + + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + + WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null) { + return; + } + + if (null != mAnimationBean.styles) { + mAnimationBean.styles.init(mAnimationBean.styles.transformOrigin, + mAnimationBean.styles.transform, (int) component.getLayoutWidth(), (int) component.getLayoutHeight(), + instance.getInstanceViewPortWidth()); + startAnimation(instance, component); + } + } + + private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) { + if (component != null) { + if (mAnimationBean != null) { + component.setNeedLayoutOnAnimation(mAnimationBean.needLayout); + } + if (component.getHostView() == null) { + WXAnimationModule.AnimationHolder holder = new WXAnimationModule.AnimationHolder(mAnimationBean, callback); + component.postAnimation(holder); + } else { + try { + Animator animator = createAnimator(component.getHostView(), instance + .getInstanceViewPortWidth()); + if (animator != null) { + Animator.AnimatorListener animatorCallback = createAnimatorListener(instance, callback); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && component + .isLayerTypeEnabled() ) { + component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null); + } + Interpolator interpolator = createTimeInterpolator(); + if (animatorCallback != null) { + animator.addListener(animatorCallback); + } + if (interpolator != null) { + animator.setInterpolator(interpolator); + } + component.getHostView().setCameraDistance(mAnimationBean.styles.getCameraDistance()); + animator.setDuration(mAnimationBean.duration); + animator.start(); + } + } catch (RuntimeException e) { + WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e)); + } + } + } + } + + private + @Nullable + ObjectAnimator createAnimator(final View target, final int viewPortWidth) { + if (target == null) { + return null; + } + WXAnimationBean.Style style = mAnimationBean.styles; + if (style != null) { + ObjectAnimator animator; + List<PropertyValuesHolder> holders = style.getHolders(); + if (!TextUtils.isEmpty(style.backgroundColor)) { + BorderDrawable borderDrawable; + if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) { + holders.add(PropertyValuesHolder.ofObject( + new BackgroundColorProperty(), new ArgbEvaluator(), + borderDrawable.getColor(), + WXResourceUtils.getColor(style.backgroundColor))); + } else if (target.getBackground() instanceof ColorDrawable) { + holders.add(PropertyValuesHolder.ofObject( + new BackgroundColorProperty(), new ArgbEvaluator(), + ((ColorDrawable) target.getBackground()).getColor(), + WXResourceUtils.getColor(style.backgroundColor))); + } + } + + if (target.getLayoutParams() != null && + (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) { + ViewGroup.LayoutParams layoutParams = target.getLayoutParams(); + if (!TextUtils.isEmpty(style.width)) { + holders.add(PropertyValuesHolder.ofInt(new WidthProperty(), layoutParams.width, + (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth))); + } + if (!TextUtils.isEmpty(style.height)) { + holders.add(PropertyValuesHolder.ofInt(new HeightProperty(), layoutParams.height, + (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth))); + } + } + + if (style.getPivot() != null) { + Pair<Float, Float> pair = style.getPivot(); + target.setPivotX(pair.first); + target.setPivotY(pair.second); + } + animator = ObjectAnimator.ofPropertyValuesHolder( + target, holders.toArray(new PropertyValuesHolder[holders.size()])); + animator.setStartDelay(mAnimationBean.delay); + return animator; + } else { + return null; + } + } + + private + @Nullable + Animator.AnimatorListener createAnimatorListener(final WXSDKInstance instance, @Nullable final String callBack) { + if (!TextUtils.isEmpty(callBack)) { + return new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + if (instance == null || instance.isDestroy()) { + WXLogUtils.e("RenderContextImpl-onAnimationEnd WXSDKInstance == null NPE or instance is destroyed"); + } else { + WXSDKManager.getInstance().callback(instance.getInstanceId(), + callBack, + new HashMap<String, Object>()); + } + } + }; + } else { + return null; + } + } + + private + @Nullable + Interpolator createTimeInterpolator() { + String interpolator = mAnimationBean.timingFunction; + if (!TextUtils.isEmpty(interpolator)) { + switch (interpolator) { + case WXAnimationBean.EASE_IN: + return new AccelerateInterpolator(); + case WXAnimationBean.EASE_OUT: + return new DecelerateInterpolator(); + case WXAnimationBean.EASE_IN_OUT: + return new AccelerateDecelerateInterpolator(); + case WXAnimationBean.LINEAR: + return new LinearInterpolator(); + default: + //Parse cubic-bezier + try { + SingleFunctionParser<Float> parser = new SingleFunctionParser<>( + mAnimationBean.timingFunction, + new SingleFunctionParser.FlatMapper<Float>() { + @Override + public Float map(String raw) { + return Float.parseFloat(raw); + } + }); + List<Float> params = parser.parse(WXAnimationBean.CUBIC_BEZIER); + if (params != null && params.size() == WXAnimationBean.NUM_CUBIC_PARAM) { + return PathInterpolatorCompat.create( + params.get(0), params.get(1), params.get(2), params.get(3)); + } else { + return null; + } + } catch (RuntimeException e) { + return null; + } + } + } + return null; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java new file mode 100644 index 0000000..f59b0e1 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateBody.java @@ -0,0 +1,99 @@ +/** + * 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.ui.action; + +import android.widget.ScrollView; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.common.WXRenderStrategy; +import com.taobao.weex.dom.transition.WXTransition; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXScroller; +import com.taobao.weex.utils.WXLogUtils; + +import java.util.Map; +import java.util.Set; + +public class GraphicActionCreateBody extends GraphicActionAbstractAddElement { + + private WXSDKInstance instance; + private WXComponent component; + + public GraphicActionCreateBody(String pageId, String ref, + String componentType, + Map<String, String> style, + Map<String, String> attributes, + Set<String> events, + float[] margins, + float[] paddings, + float[] borders) { + super(pageId, ref); + this.mComponentType = componentType; + this.mStyle = style; + this.mAttributes = attributes; + this.mEvents = events; + this.mMargins = margins; + this.mPaddings = paddings; + this.mBorders = borders; + + instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null || instance.getContext() == null) { + return; + } + + BasicComponentData basicComponentData = new BasicComponentData(getRef(), mComponentType, null); + component = createComponent(instance, null, basicComponentData); + if (component == null) { + return; + } + component.setTransition(WXTransition.fromMap(component.getStyles(), component)); + + } + + @Override + public void executeAction() { + try { + component.createView(); + + long start = System.currentTimeMillis(); + component.applyLayoutAndEvent(component); + WXSDKManager.getInstance().getSDKInstance(getPageId()).callLayoutaAplyLayoutAndEventTime(System.currentTimeMillis() - start); + + start = System.currentTimeMillis(); + component.bindData(component); + WXSDKManager.getInstance().getSDKInstance(getPageId()).callLayoutBindDataCoreTime(System.currentTimeMillis() - start); + + if (component instanceof WXScroller) { + WXScroller scroller = (WXScroller) component; + if (scroller.getInnerView() instanceof ScrollView) { + instance.setRootScrollView((ScrollView) scroller.getInnerView()); + } + } + + instance.onRootCreated(component); + + if (instance.getRenderStrategy() != WXRenderStrategy.APPEND_ONCE) { + instance.onCreateFinish(); + } + } catch (Exception e) { + WXLogUtils.e("create body failed.", e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java new file mode 100644 index 0000000..2b43eb1 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionCreateFinish.java @@ -0,0 +1,70 @@ +/** + * 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.ui.action; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.common.WXRenderStrategy; +import com.taobao.weex.ui.component.WXComponent; + +/** + * Created by listen on 18/01/09. + */ +public class GraphicActionCreateFinish extends BasicGraphicAction { + + private int mLayoutWidth; + private int mLayoutHeight; + + public GraphicActionCreateFinish(String pageId) { + super(pageId, ""); + final WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(pageId); + if (instance == null) { + return; + } + WXComponent component = instance.getRootComponent(); + if (null != component) { + this.mLayoutWidth = (int) component.getLayoutWidth(); + this.mLayoutHeight = (int) component.getLayoutHeight(); + } + + // todo add LayoutFinishListener +// final LayoutFinishListener listener; +// if(instance != null && (listener = instance.getLayoutFinishListener()) != null) { +// WXSDKManager.getInstance().getWXRenderManager().postOnUiThread(WXThread.secure(new Runnable() { +// @Override +// public void run() { +// listener.onLayoutFinish(instance); +// } +// }),0); +// } + } + + @Override + public void executeAction() { + final WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null || instance.getContext() == null) { + return; + } + + if (instance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) { + instance.onCreateFinish(); + } + instance.onRenderSuccess(mLayoutWidth, mLayoutHeight); + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java new file mode 100644 index 0000000..777df14 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionLayout.java @@ -0,0 +1,51 @@ +/** + * 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.ui.action; + +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.WXComponent; + +public class GraphicActionLayout extends BasicGraphicAction { + + private final GraphicPosition mLayoutPosition; + private final GraphicSize mLayoutSize; + + public GraphicActionLayout(String pageId, String ref, GraphicPosition layoutPosition, GraphicSize layoutSize) { + super(pageId, ref); + this.mLayoutPosition = layoutPosition; + this.mLayoutSize = layoutSize; + } + + @Override + public void executeAction() { + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + + long start = System.currentTimeMillis(); + component.updateDemission(mLayoutSize, mLayoutPosition); + WXSDKManager.getInstance().getSDKInstance(getPageId()).callLayoutUpdateDemissionTime(System.currentTimeMillis() - start); + + component.setLayout(component); + component.setPadding(component.getPadding(), component.getBorder()); + + WXSDKManager.getInstance().getSDKInstance(getPageId()).callActionLayoutCount(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java new file mode 100644 index 0000000..ac6474b --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionMoveElement.java @@ -0,0 +1,52 @@ +/** + * 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.ui.action; + +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXVContainer; + +public class GraphicActionMoveElement extends BasicGraphicAction { + + private String mParentref; + private int mIndex; + + public GraphicActionMoveElement(String pageId, String ref, String parentRef, int index) { + super(pageId, ref); + this.mParentref = parentRef; + this.mIndex = index; + } + + @Override + public void executeAction() { + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + WXVContainer oldParent = component.getParent(); + WXComponent newParent = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), mParentref); + if (component == null || oldParent == null + || newParent == null || !(newParent instanceof WXVContainer)) { + return; + } + + oldParent.remove(component, false); + ((WXVContainer) newParent).addChild(component, mIndex); + if (!component.isVirtualComponent()) { + ((WXVContainer) newParent).addSubView(component.getHostView(), mIndex); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java new file mode 100644 index 0000000..efdb309 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRefreshFinish.java @@ -0,0 +1,55 @@ +/** + * 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.ui.action; + +import com.taobao.weex.WXSDKInstance; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.WXComponent; + +/** + * Created by listen on 18/01/09. + */ +public class GraphicActionRefreshFinish extends BasicGraphicAction { + + private int mLayoutWidth; + private int mLayoutHeight; + + public GraphicActionRefreshFinish(String pageId) { + super(pageId, ""); + final WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(pageId); + if (instance == null) { + return; + } + WXComponent component = instance.getRootComponent(); + if (null != component) { + this.mLayoutWidth = (int) component.getLayoutWidth(); + this.mLayoutHeight = (int) component.getLayoutHeight(); + } + } + + @Override + public void executeAction() { + final WXSDKInstance instance = WXSDKManager.getInstance().getWXRenderManager().getWXSDKInstance(getPageId()); + if (instance == null || instance.getContext() == null) { + return; + } + + instance.onRefreshSuccess(mLayoutWidth, mLayoutHeight); + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java new file mode 100644 index 0000000..36d31dd --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveElement.java @@ -0,0 +1,56 @@ +/** + * 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.ui.action; + +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.WXComponent; +import com.taobao.weex.ui.component.WXVContainer; + +public class GraphicActionRemoveElement extends BasicGraphicAction { + + public GraphicActionRemoveElement(String pageId, String ref) { + super(pageId, ref); + } + + @Override + public void executeAction() { + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null || component.getParent() == null) { + return; + } + clearRegistryForComponent(component); + WXVContainer parent = component.getParent(); + parent.remove(component, true); + } + + private void clearRegistryForComponent(WXComponent component) { + WXComponent removedComponent = WXSDKManager.getInstance().getWXRenderManager().unregisterComponent(getPageId(), getRef()); + if (removedComponent != null) { + removedComponent.removeAllEvent(); + removedComponent.removeStickyStyle(); + } + if (component instanceof WXVContainer) { + WXVContainer container = (WXVContainer) component; + int count = container.childCount(); + for (int i = count - 1; i >= 0; --i) { + clearRegistryForComponent(container.getChild(i)); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java new file mode 100644 index 0000000..36fd284 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionRemoveEvent.java @@ -0,0 +1,49 @@ +/** + * 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.ui.action; + +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.dom.WXEvent; +import com.taobao.weex.tracing.Stopwatch; +import com.taobao.weex.ui.component.WXComponent; + +/** + * Created by listen on 18/01/11. + */ +public class GraphicActionRemoveEvent extends BasicGraphicAction { + + private final String mEvent; + + public GraphicActionRemoveEvent(String pageId, String ref, Object event) { + super(pageId, ref); + this.mEvent = WXEvent.getEventName(event); + } + + @Override + public void executeAction() { + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + + Stopwatch.tick(); + component.removeEvent(mEvent); + Stopwatch.split("removeEventFromComponent"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java new file mode 100644 index 0000000..144c61e --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionScrollToElement.java @@ -0,0 +1,51 @@ +/** + * 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.ui.action; + +import com.alibaba.fastjson.JSONObject; +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.Scrollable; +import com.taobao.weex.ui.component.WXComponent; + +/** + * Created by listen on 18/01/09. + */ +public class GraphicActionScrollToElement extends BasicGraphicAction { + + private final JSONObject mOptions; + + public GraphicActionScrollToElement(String pageId, String ref, JSONObject options) { + super(pageId, ref); + this.mOptions = options; + } + + @Override + public void executeAction() { + WXComponent component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + + Scrollable scroller = component.getParentScroller(); + if (scroller == null) { + return; + } + scroller.scrollTo(component, mOptions); + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java new file mode 100644 index 0000000..64f3fdd --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateAttr.java @@ -0,0 +1,52 @@ +/** + * 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.ui.action; + +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.ui.component.WXComponent; + +import java.util.Map; + +public class GraphicActionUpdateAttr extends BasicGraphicAction { + + private Map<String, String> mAttrs; + private WXComponent component; + + public GraphicActionUpdateAttr(String pageId, String ref, + Map<String, String> attrs) { + super(pageId, ref); + this.mAttrs = attrs; + + component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + if (mAttrs != null) { + component.addAttr(mAttrs); + } + } + + @Override + public void executeAction() { + if (component == null) { + return; + } + component.updateAttrs(mAttrs); + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java new file mode 100644 index 0000000..90525e7 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicActionUpdateStyle.java @@ -0,0 +1,134 @@ +/** + * 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.ui.action; + +import android.support.v4.util.ArrayMap; + +import com.taobao.weex.WXSDKManager; +import com.taobao.weex.bridge.WXBridgeManager; +import com.taobao.weex.common.Constants; +import com.taobao.weex.dom.CSSShorthand; +import com.taobao.weex.dom.transition.WXTransition; +import com.taobao.weex.ui.component.WXComponent; + +import java.util.Map; + +public class GraphicActionUpdateStyle extends BasicGraphicAction { + + private Map<String, Object> mStyle; + private WXComponent component; + private boolean mIsCausedByPesudo; + + public GraphicActionUpdateStyle(String pageId, String ref, + Map<String, Object> style, + Map<String, String> paddings, + Map<String, String> margins, + Map<String, String> borders) { + this(pageId, ref, style, paddings, margins, borders, false); + } + + public GraphicActionUpdateStyle(String pageId, String ref, + Map<String, Object> style, + CSSShorthand paddings, + CSSShorthand margins, + CSSShorthand borders, boolean byPesudo) { + super(pageId, ref); + this.mStyle = style; + this.mIsCausedByPesudo = byPesudo; + + component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + if (null != mStyle) { + component.addStyle(mStyle, mIsCausedByPesudo); + if(style.containsKey(Constants.Name.TRANSFORM)) { + Map<String, Object> animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); + animationMap + .put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); + component.addAnimationForElement(animationMap); + } + } + + if (null != paddings) { + component.setPaddings(paddings); + } + + if (null != margins) { + component.setMargins(margins); + } + + if (null != borders) { + component.setBorders(borders); + } + } + + public GraphicActionUpdateStyle(String pageId, String ref, + Map<String, Object> style, + Map<String, String> paddings, + Map<String, String> margins, + Map<String, String> borders, boolean byPesudo) { + super(pageId, ref); + this.mStyle = style; + this.mIsCausedByPesudo = byPesudo; + + component = WXSDKManager.getInstance().getWXRenderManager().getWXComponent(getPageId(), getRef()); + if (component == null) { + return; + } + if (null != mStyle) { + component.addStyle(mStyle, mIsCausedByPesudo); + Map<String, Object> animationMap = new ArrayMap<>(2); + animationMap.put(Constants.Name.TRANSFORM, style.get(Constants.Name.TRANSFORM)); + animationMap.put(Constants.Name.TRANSFORM_ORIGIN, style.get(Constants.Name.TRANSFORM_ORIGIN)); + component.addAnimationForElement(animationMap); + WXBridgeManager.getInstance().markDirty(component.getInstanceId(), component.getRef(), true); + } + + if (null != paddings) { + component.addShorthand(paddings); + } + + if (null != margins) { + component.addShorthand(margins); + } + + if (null != borders) { + component.addShorthand(borders); + } + } + + @Override + public void executeAction() { + if (component == null) { + return; + } + if(component.getTransition() != null){ + component.getTransition().updateTranstionParams(mStyle); + if(component.getTransition().hasTransitionProperty(mStyle)){ + component.getTransition().startTransition(mStyle); + } + } else { + component.setTransition(WXTransition.fromMap(mStyle, component)); + component.updateStyles(mStyle); + } + } +} + http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicPosition.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicPosition.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicPosition.java new file mode 100644 index 0000000..9cb0e2d --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicPosition.java @@ -0,0 +1,66 @@ +/** + * 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.ui.action; + +public class GraphicPosition { + + private float mLeft; + private float mTop; + private float mRight; + private float mBottom; + + public GraphicPosition(float left, float top, float right, float bottom) { + this.mLeft = left; + this.mTop = top; + this.mRight = right; + this.mBottom = bottom; + } + + public float getLeft() { + return mLeft; + } + + public void setLeft(float left) { + this.mLeft = left; + } + + public float getTop() { + return mTop; + } + + public void setTop(float top) { + this.mTop = top; + } + + public float getRight() { + return mRight; + } + + public void setRight(float right) { + this.mRight = right; + } + + public float getBottom() { + return mBottom; + } + + public void setBottom(float bottom) { + this.mBottom = bottom; + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicSize.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicSize.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicSize.java new file mode 100644 index 0000000..371b196 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/GraphicSize.java @@ -0,0 +1,46 @@ +/** + * 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.ui.action; + +public class GraphicSize { + + private float mWidth; + private float mHeight; + + public GraphicSize(float width, float height) { + this.mWidth = width; + this.mHeight = height; + } + + public float getWidth() { + return mWidth; + } + + public void setWidth(float width) { + this.mWidth = width; + } + + public float getHeight() { + return mHeight; + } + + public void setHeight(float height) { + this.mHeight = height; + } +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/action/IExecutable.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/action/IExecutable.java b/android/sdk/src/main/java/com/taobao/weex/ui/action/IExecutable.java new file mode 100644 index 0000000..399d249 --- /dev/null +++ b/android/sdk/src/main/java/com/taobao/weex/ui/action/IExecutable.java @@ -0,0 +1,25 @@ +/** + * 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.ui.action; + +public interface IExecutable { + + void executeAction(); + +} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/ui/animation/TransformParser.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/animation/TransformParser.java b/android/sdk/src/main/java/com/taobao/weex/ui/animation/TransformParser.java index decc78e..34e4ee4 100644 --- a/android/sdk/src/main/java/com/taobao/weex/ui/animation/TransformParser.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/animation/TransformParser.java @@ -29,8 +29,6 @@ import android.view.View; import com.taobao.weex.WXEnvironment; import com.taobao.weex.common.Constants; -import com.taobao.weex.ui.animation.CameraDistanceProperty; -import com.taobao.weex.ui.animation.WXAnimationBean; import com.taobao.weex.utils.FunctionParser; import com.taobao.weex.utils.WXDataStructureUtil; import com.taobao.weex.utils.WXUtils; @@ -102,7 +100,7 @@ public class TransformParser { } public static Map<Property<View,Float>, Float> parseTransForm(@Nullable String rawTransform, final int width, - final int height, final int viewportW) { + final int height, final int viewportW) { if (!TextUtils.isEmpty(rawTransform)) { FunctionParser<Property<View,Float>, Float> parser = new FunctionParser<> (rawTransform, new FunctionParser.Mapper<Property<View,Float>, Float>() { @@ -116,7 +114,7 @@ public class TransformParser { return new HashMap<>(); } - private Map<Property<View,Float>, Float> convertParam(int width, int height,int viewportW, + private Map<Property<View,Float>, Float> convertParam(int width, int height, int viewportW, @NonNull List<Property<View,Float>> propertyList, @NonNull List<String> rawValue) { @@ -157,7 +155,8 @@ public class TransformParser { return convertedList; } - private @NonNull List<Float> parseRotationZ(@NonNull List<String> rawValue) { + private @NonNull + List<Float> parseRotationZ(@NonNull List<String> rawValue) { List<Float> convertedList = new ArrayList<>(1); int suffix; for (String raw : rawValue) { @@ -178,7 +177,7 @@ public class TransformParser { */ private List<Float> parseTranslation(List<Property<View,Float>> propertyList, int width, int height, - @NonNull List<String> rawValue,int viewportW) { + @NonNull List<String> rawValue, int viewportW) { List<Float> convertedList = new ArrayList<>(2); String first = rawValue.get(0); if (propertyList.size() == 1) { @@ -190,7 +189,7 @@ public class TransformParser { } private void parseSingleTranslation(List<Property<View,Float>> propertyList, int width, int height, - List<Float> convertedList, String first,int viewportW) { + List<Float> convertedList, String first, int viewportW) { if (propertyList.contains(View.TRANSLATION_X)) { convertedList.add(parsePercentOrPx(first, width,viewportW)); } else if (propertyList.contains(View.TRANSLATION_Y)) { @@ -200,7 +199,7 @@ public class TransformParser { private void parseDoubleTranslation(int width, int height, @NonNull List<String> rawValue, - List<Float> convertedList, String first,int viewportW) { + List<Float> convertedList, String first, int viewportW) { String second; if (rawValue.size() == 1) { second = first; @@ -212,7 +211,7 @@ public class TransformParser { } private Float parseCameraDistance(List<String> rawValue){ - float ret=Float.MAX_VALUE; + float ret= Float.MAX_VALUE; if(rawValue.size() == 1){ float value = WXViewUtils.getRealPxByWidth(WXUtils.getFloat(rawValue.get(0)), viewportW); float scale = WXEnvironment.getApplication().getResources().getDisplayMetrics().density; @@ -250,12 +249,12 @@ public class TransformParser { return null; } - private static Pair<Float, Float> parsePivot(@NonNull List<String> list, int width, int height,int viewportW) { + private static Pair<Float, Float> parsePivot(@NonNull List<String> list, int width, int height, int viewportW) { return new Pair<>( parsePivotX(list.get(0), width,viewportW), parsePivotY(list.get(1), height,viewportW)); } - private static float parsePivotX(String x, int width,int viewportW) { + private static float parsePivotX(String x, int width, int viewportW) { String value = x; if (WXAnimationBean.Style.LEFT.equals(x)) { value = ZERO; @@ -267,7 +266,7 @@ public class TransformParser { return parsePercentOrPx(value, width,viewportW); } - private static float parsePivotY(String y, int height,int viewportW) { + private static float parsePivotY(String y, int height, int viewportW) { String value = y; if (WXAnimationBean.Style.TOP.equals(y)) { value = ZERO; @@ -279,7 +278,7 @@ public class TransformParser { return parsePercentOrPx(value, height,viewportW); } - private static float parsePercentOrPx(String raw, int unit,int viewportW) { + private static float parsePercentOrPx(String raw, int unit, int viewportW) { final int precision = 1; int suffix; if ((suffix = raw.lastIndexOf(WXUtils.PERCENT)) != -1) {
