Skip to content

Commit

Permalink
* [android] move indicator layout logic to subclass;seperate fixed la…
Browse files Browse the repository at this point in the history
…yout logic
  • Loading branch information
sospartan committed Oct 11, 2016
1 parent 0e30cf9 commit fc2a009
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fc2a009

Please sign in to comment.