From fc2a009ec3a05f3a428dab815815e9552daf1591 Mon Sep 17 00:00:00 2001 From: sospartan Date: Tue, 11 Oct 2016 15:43:27 +0800 Subject: [PATCH] * [android] move indicator layout logic to subclass;seperate fixed layout logic --- .../taobao/weex/ui/component/WXComponent.java | 61 +++++++++---------- .../taobao/weex/ui/component/WXIndicator.java | 8 +++ 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java index dfa244d221..45d5c0d250 100755 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXComponent.java @@ -152,7 +152,6 @@ import com.taobao.weex.dom.flex.Spacing; import com.taobao.weex.ui.IFComponentHolder; import com.taobao.weex.ui.component.list.WXListComponent; -import com.taobao.weex.ui.view.WXCircleIndicator; import com.taobao.weex.ui.view.border.BorderDrawable; import com.taobao.weex.ui.view.gesture.WXGesture; import com.taobao.weex.ui.view.gesture.WXGestureObservable; @@ -437,37 +436,11 @@ public final void setLayout(WXDomObject domObject) { realWidth = measureOutput.width; realHeight = measureOutput.height; - if (mHost instanceof WXCircleIndicator) { - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(realWidth, realHeight); - params.setMargins(realLeft, realTop, realRight, realBottom); - mHost.setLayoutParams(params); - return; - } - //fixed style - if (mDomObj.isFixed() && mInstance.getRootView() != null) { - if (mHost.getParent() instanceof ViewGroup) { - ViewGroup viewGroup = (ViewGroup) mHost.getParent(); - viewGroup.removeView(mHost); - } - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - - params.width = realWidth; - params.height = realHeight; - params.setMargins(realLeft, realTop, realRight, realBottom); - mHost.setLayoutParams(params); - mInstance.addFixedView(mHost); - - if (WXEnvironment.isApkDebugable()) { - WXLogUtils.d("Weex_Fixed_Style", "WXComponent:setLayout :" + realLeft + " " + realTop + " " + realWidth + " " + realHeight); - WXLogUtils.d("Weex_Fixed_Style", "WXComponent:setLayout Left:" + mDomObj.getStyles().getLeft() + " " + (int) mDomObj.getStyles().getTop()); - } - return; - } - - ViewGroup.LayoutParams lp = mParent.getChildLayoutParams(mHost,realWidth, realHeight, realLeft,realRight,realTop,realBottom); - if(lp != null) { - mHost.setLayoutParams(lp); + if (mDomObj.isFixed()) { + setFixedHostLayoutParams(mHost,realWidth,realHeight,realLeft,realRight,realTop,realBottom); + }else { + setHostLayoutParams(mHost, realWidth, realHeight, realLeft, realRight, realTop, realBottom); } mPreRealWidth = realWidth; @@ -476,6 +449,32 @@ public final void setLayout(WXDomObject domObject) { mPreRealTop = realTop; } + protected void setHostLayoutParams(T host, int width, int height, int left, int right, int top, int bottom){ + ViewGroup.LayoutParams lp = mParent.getChildLayoutParams(host,width, height, left,right,top,bottom); + if(lp != null) { + mHost.setLayoutParams(lp); + } + } + + private void setFixedHostLayoutParams(T host, int width, int height, int left, int right, int top, int bottom){ + if (host.getParent() instanceof ViewGroup) { + ViewGroup viewGroup = (ViewGroup) host.getParent(); + viewGroup.removeView(host); + } + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + + params.width = width; + params.height = height; + params.setMargins(left, top, right, bottom); + host.setLayoutParams(params); + mInstance.addFixedView(host); + + if (WXEnvironment.isApkDebugable()) { + WXLogUtils.d("Weex_Fixed_Style", "WXComponent:setLayout :" + left + " " + top + " " + width + " " + height); + WXLogUtils.d("Weex_Fixed_Style", "WXComponent:setLayout Left:" + mDomObj.getStyles().getLeft() + " " + (int) mDomObj.getStyles().getTop()); + } + } + public void setPadding(Spacing padding, Spacing border) { int left = (int) (padding.get(Spacing.LEFT) + border.get(Spacing.LEFT)); int top = (int) (padding.get(Spacing.TOP) + border.get(Spacing.TOP)); diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXIndicator.java b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXIndicator.java index bc5a995790..79941c5c94 100755 --- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXIndicator.java +++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXIndicator.java @@ -208,6 +208,7 @@ import android.support.annotation.NonNull; import android.text.TextUtils; import android.view.View; +import android.widget.FrameLayout; import com.taobao.weex.WXEnvironment; import com.taobao.weex.WXSDKInstance; @@ -240,6 +241,13 @@ public WXIndicator(WXSDKInstance instance, WXDomObject dom, WXVContainer parent, super(instance, dom, parent, isLazy); } + @Override + protected void setHostLayoutParams(WXCircleIndicator host, int width, int height, int left, int right, int top, int bottom) { + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, height); + params.setMargins(left, top, right, bottom); + host.setLayoutParams(params); + } + @Override protected WXCircleIndicator initComponentHostView(@NonNull Context context) { WXCircleIndicator view = new WXCircleIndicator(context);