com.taobao.weex.dom.flex.Spacing Java Examples

The following examples show how to use com.taobao.weex.dom.flex.Spacing. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BorderUtil.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
static <T> void updateSparseArray(@NonNull SparseArray<T> array, int position, T value,
                           boolean borderRadius) {
  if (borderRadius) {
    if (position == BorderDrawable.BORDER_RADIUS_ALL) {
      array.put(BorderDrawable.BORDER_RADIUS_ALL, value);
      array.put(BorderDrawable.BORDER_TOP_LEFT_RADIUS, value);
      array.put(BorderDrawable.BORDER_TOP_RIGHT_RADIUS, value);
      array.put(BorderDrawable.BORDER_BOTTOM_LEFT_RADIUS, value);
      array.put(BorderDrawable.BORDER_BOTTOM_RIGHT_RADIUS, value);
    } else {
      array.put(position, value);
    }
  } else {
    if (position == Spacing.ALL) {
      array.put(Spacing.ALL, value);
      array.put(Spacing.TOP, value);
      array.put(Spacing.LEFT, value);
      array.put(Spacing.RIGHT, value);
      array.put(Spacing.BOTTOM, value);
    } else {
      array.put(position, value);
    }
  }
}
 
Example #2
Source File: UpdateStyleAction.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void executeRender(RenderActionContext context) {
  WXComponent component = context.getComponent(mRef);
  if (component == null) {
    return;
  }
  component.updateProperties(mData);

  if (mData.containsKey(Constants.Name.PADDING) ||
      mData.containsKey(Constants.Name.PADDING_TOP) ||
      mData.containsKey(Constants.Name.PADDING_LEFT) ||
      mData.containsKey(Constants.Name.PADDING_RIGHT) ||
      mData.containsKey(Constants.Name.PADDING_BOTTOM) ||
      mData.containsKey(Constants.Name.BORDER_WIDTH)) {
    Spacing padding = mPadding;
    Spacing border = mBorder;
    component.setPadding(padding, border);
  }
}
 
Example #3
Source File: WXDomUtils.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Get the content width of the dom.
 * @return the width of the dom that excludes left-padding, left-border-width,
 * right-border-width and right-padding.
 */
public static float getContentWidth(ImmutableDomObject domObject) {
  float rawWidth = domObject.getLayoutWidth();
  float leftPadding, rightPadding, leftBorder, rightBorder;
  Spacing padding = domObject.getPadding();
  Spacing border = domObject.getBorder();

  if (!CSSConstants.isUndefined((leftPadding = padding.get(Spacing.LEFT)))) {
    rawWidth -= leftPadding;
  }
  if (!CSSConstants.isUndefined((rightPadding = padding.get(Spacing.RIGHT)))) {
    rawWidth -= rightPadding;
  }

  if (!CSSConstants.isUndefined(leftBorder = border.get(Spacing.LEFT))) {
    rawWidth -= leftBorder;
  }
  if (!CSSConstants.isUndefined(rightBorder = border.get(Spacing.RIGHT))) {
    rawWidth -= rightBorder;
  }
  return rawWidth;
}
 
Example #4
Source File: WXDomStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Create the command object for updating style and put it the queue. If the given style
 * contains border-width and padding that will affect layout, then a command object for reset
 * padding will also be created.
 * @param domObject the given dom object
 * @param update the given style.
 */
private void updateStyle(final WXDomObject domObject, final Map<String, Object> update) {
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.updateStyle(mInstanceId, domObject.ref, update);
    }
  });
  if (update.containsKey("padding") || update.containsKey("paddingTop") ||
      update.containsKey("paddingLeft") ||
      update.containsKey("paddingRight") ||
      update.containsKey("paddingBottom") || update.containsKey("borderWidth")) {
    mNormalTasks.add(new IWXRenderTask() {

      @Override
      public void execute() {
        Spacing padding = domObject.getPadding();
        Spacing border = domObject.getBorder();
        mWXRenderManager.setPadding(mInstanceId, domObject.ref, padding, border);
      }
    });
  }
}
 
Example #5
Source File: WXDomUtils.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Get the content height of the dom.
 * @return the height of the dom that excludes top-padding, top-border-width, bottom-padding
 * and bottom-border-width.
 */
public static float getContentHeight(ImmutableDomObject domObject) {
  float rawHeight = domObject.getLayoutHeight();
  float topPadding, bottomPadding, topBorder, bottomBorder;
  Spacing padding = domObject.getPadding();
  Spacing border = domObject.getBorder();

  if (!CSSConstants.isUndefined((topPadding = padding.get(Spacing.TOP)))) {
    rawHeight -= topPadding;
  }
  if (!CSSConstants.isUndefined((bottomPadding = padding.get(Spacing.BOTTOM)))) {
    rawHeight -= bottomPadding;
  }

  if (!CSSConstants.isUndefined(topBorder = border.get(Spacing.TOP))) {
    rawHeight -= topBorder;
  }
  if (!CSSConstants.isUndefined(bottomBorder = border.get(Spacing.BOTTOM))) {
    rawHeight -= bottomBorder;
  }
  return rawHeight;
}
 
Example #6
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public void setBorderWidth(String key, float borderWidth) {
  if (borderWidth >= 0) {
    switch (key) {
      case Constants.Name.BORDER_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.ALL, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getInstanceViewPortWidth()));
        break;
      case Constants.Name.BORDER_TOP_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.TOP, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getInstanceViewPortWidth()));
        break;
      case Constants.Name.BORDER_RIGHT_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.RIGHT, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getInstanceViewPortWidth()));
        break;
      case Constants.Name.BORDER_BOTTOM_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.BOTTOM, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getInstanceViewPortWidth()));
        break;
      case Constants.Name.BORDER_LEFT_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.LEFT, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getInstanceViewPortWidth()));
        break;
    }
  }
}
 
Example #7
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public void setBorderStyle(String key, String borderStyle) {
  if(!TextUtils.isEmpty(borderStyle)){
    switch (key){
      case Constants.Name.BORDER_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.ALL,borderStyle);
        break;
      case Constants.Name.BORDER_RIGHT_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.RIGHT,borderStyle);
        break;
      case Constants.Name.BORDER_BOTTOM_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.BOTTOM,borderStyle);
        break;
      case Constants.Name.BORDER_LEFT_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.LEFT,borderStyle);
        break;
      case Constants.Name.BORDER_TOP_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.TOP,borderStyle);
        break;
    }
  }
}
 
Example #8
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public void setBorderColor(String key, String borderColor) {
  if (!TextUtils.isEmpty(borderColor)) {
    int colorInt = WXResourceUtils.getColor(borderColor);
    if (colorInt != Integer.MIN_VALUE) {
      switch (key) {
        case Constants.Name.BORDER_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.ALL, colorInt);
          break;
        case Constants.Name.BORDER_TOP_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.TOP, colorInt);
          break;
        case Constants.Name.BORDER_RIGHT_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.RIGHT, colorInt);
          break;
        case Constants.Name.BORDER_BOTTOM_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.BOTTOM, colorInt);
          break;
        case Constants.Name.BORDER_LEFT_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.LEFT, colorInt);
          break;
      }
    }
  }
}
 
Example #9
Source File: WXComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
public void setBorderColor(String key, String borderColor) {
  if (!TextUtils.isEmpty(borderColor)) {
    int colorInt = WXResourceUtils.getColor(borderColor);
    if (colorInt != Integer.MIN_VALUE) {
      switch (key) {
        case Constants.Name.BORDER_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.ALL, colorInt);
          break;
        case Constants.Name.BORDER_TOP_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.TOP, colorInt);
          break;
        case Constants.Name.BORDER_RIGHT_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.RIGHT, colorInt);
          break;
        case Constants.Name.BORDER_BOTTOM_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.BOTTOM, colorInt);
          break;
        case Constants.Name.BORDER_LEFT_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.LEFT, colorInt);
          break;
      }
    }
  }
}
 
Example #10
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void updateProperties(Map<String, Object> props) {
  super.updateProperties(props);
  if(props.containsKey(Constants.Name.PADDING)
          ||props.containsKey(Constants.Name.PADDING_LEFT)
          || props.containsKey(Constants.Name.PADDING_RIGHT)){

    if(mPaddingLeft !=mDomObject.getPadding().get(Spacing.LEFT)
            || mPaddingRight !=mDomObject.getPadding().get(Spacing.RIGHT)) {

      markComponentUsable();
      updateRecyclerAttr();
      WXRecyclerView wxRecyclerView = getHostView().getInnerView();
      wxRecyclerView.initView(getContext(), mLayoutType, mColumnCount, mColumnGap, getOrientation());
    }
  }

}
 
Example #11
Source File: WXComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
public void setBorderStyle(String key, String borderStyle) {
  if(!TextUtils.isEmpty(borderStyle)){
    switch (key){
      case Constants.Name.BORDER_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.ALL,borderStyle);
        break;
      case Constants.Name.BORDER_RIGHT_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.RIGHT,borderStyle);
        break;
      case Constants.Name.BORDER_BOTTOM_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.BOTTOM,borderStyle);
        break;
      case Constants.Name.BORDER_LEFT_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.LEFT,borderStyle);
        break;
      case Constants.Name.BORDER_TOP_STYLE:
        getOrCreateBorder().setBorderStyle(Spacing.TOP,borderStyle);
        break;
    }
  }
}
 
Example #12
Source File: WXComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
public void setBorderWidth(String key, float borderWidth) {
  if (borderWidth >= 0) {
    switch (key) {
      case Constants.Name.BORDER_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.ALL, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getViewPortWidth()));
        break;
      case Constants.Name.BORDER_TOP_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.TOP, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getViewPortWidth()));
        break;
      case Constants.Name.BORDER_RIGHT_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.RIGHT, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getViewPortWidth()));
        break;
      case Constants.Name.BORDER_BOTTOM_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.BOTTOM, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getViewPortWidth()));
        break;
      case Constants.Name.BORDER_LEFT_WIDTH:
        getOrCreateBorder().setBorderWidth(Spacing.LEFT, WXViewUtils.getRealSubPxByWidth(borderWidth,getInstance().getViewPortWidth()));
        break;
    }
  }
}
 
Example #13
Source File: BorderUtil.java    From weex-uikit with MIT License 6 votes vote down vote up
static <T> void updateSparseArray(@NonNull SparseArray<T> array, int position, T value,
                           boolean borderRadius) {
  if (borderRadius) {
    if (position == BorderDrawable.BORDER_RADIUS_ALL) {
      array.put(BorderDrawable.BORDER_RADIUS_ALL, value);
      array.put(BorderDrawable.BORDER_TOP_LEFT_RADIUS, value);
      array.put(BorderDrawable.BORDER_TOP_RIGHT_RADIUS, value);
      array.put(BorderDrawable.BORDER_BOTTOM_LEFT_RADIUS, value);
      array.put(BorderDrawable.BORDER_BOTTOM_RIGHT_RADIUS, value);
    } else {
      array.put(position, value);
    }
  } else {
    if (position == Spacing.ALL) {
      array.put(Spacing.ALL, value);
      array.put(Spacing.TOP, value);
      array.put(Spacing.LEFT, value);
      array.put(Spacing.RIGHT, value);
      array.put(Spacing.BOTTOM, value);
    } else {
      array.put(position, value);
    }
  }
}
 
Example #14
Source File: WXDomUtils.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Get the content width of the dom.
 * @return the width of the dom that excludes left-padding, left-border-width,
 * right-border-width and right-padding.
 */
public static float getContentWidth(ImmutableDomObject domObject) {
  float rawWidth = domObject.getLayoutWidth();
  float leftPadding, rightPadding, leftBorder, rightBorder;
  Spacing padding = domObject.getPadding();
  Spacing border = domObject.getBorder();

  if (!CSSConstants.isUndefined((leftPadding = padding.get(Spacing.LEFT)))) {
    rawWidth -= leftPadding;
  }
  if (!CSSConstants.isUndefined((rightPadding = padding.get(Spacing.RIGHT)))) {
    rawWidth -= rightPadding;
  }

  if (!CSSConstants.isUndefined(leftBorder = border.get(Spacing.LEFT))) {
    rawWidth -= leftBorder;
  }
  if (!CSSConstants.isUndefined(rightBorder = border.get(Spacing.RIGHT))) {
    rawWidth -= rightBorder;
  }
  return rawWidth;
}
 
Example #15
Source File: WXDomUtils.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Get the content height of the dom.
 * @return the height of the dom that excludes top-padding, top-border-width, bottom-padding
 * and bottom-border-width.
 */
public static float getContentHeight(ImmutableDomObject domObject) {
  float rawHeight = domObject.getLayoutHeight();
  float topPadding, bottomPadding, topBorder, bottomBorder;
  Spacing padding = domObject.getPadding();
  Spacing border = domObject.getBorder();

  if (!CSSConstants.isUndefined((topPadding = padding.get(Spacing.TOP)))) {
    rawHeight -= topPadding;
  }
  if (!CSSConstants.isUndefined((bottomPadding = padding.get(Spacing.BOTTOM)))) {
    rawHeight -= bottomPadding;
  }

  if (!CSSConstants.isUndefined(topBorder = border.get(Spacing.TOP))) {
    rawHeight -= topBorder;
  }
  if (!CSSConstants.isUndefined(bottomBorder = border.get(Spacing.BOTTOM))) {
    rawHeight -= bottomBorder;
  }
  return rawHeight;
}
 
Example #16
Source File: WXRenderStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * set padding style of View
 */
void setPadding(String ref, Spacing padding, Spacing border) {
  WXComponent component = mRegistry.get(ref);
  if (component == null) {
    return;
  }
  component.setPadding(padding, border);
}
 
Example #17
Source File: BorderDrawableTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Test
public void testIsRounded(){
  BorderDrawable none = new BorderDrawable();
  assertThat(none.isRounded(), is(false));

  BorderDrawable full = new BorderDrawable();
  full.setBorderRadius(Spacing.ALL, 12);
  assertThat(full.isRounded(), is(true));

  BorderDrawable noneAndPart = new BorderDrawable();
  noneAndPart.setBorderRadius(BorderDrawable.BORDER_TOP_LEFT_RADIUS, 5);
  noneAndPart.setBorderRadius(BorderDrawable.BORDER_BOTTOM_RIGHT_RADIUS, 12);
  assertThat(noneAndPart.isRounded(), is(true));

  BorderDrawable fullAndPart = new BorderDrawable();
  fullAndPart.setBorderRadius(BorderDrawable.BORDER_RADIUS_ALL, 0);
  fullAndPart.setBorderRadius(BorderDrawable.BORDER_TOP_LEFT_RADIUS, 12);
  fullAndPart.setBorderRadius(BorderDrawable.BORDER_BOTTOM_RIGHT_RADIUS, 19);
  assertThat(fullAndPart.isRounded(), is(true));

  BorderDrawable partAndFull = new BorderDrawable();
  partAndFull.setBorderRadius(BorderDrawable.BORDER_TOP_LEFT_RADIUS, 12);
  partAndFull.setBorderRadius(BorderDrawable.BORDER_RADIUS_ALL, 0);
  assertThat(partAndFull.isRounded(), is(true));

  BorderDrawable zeroAll = new BorderDrawable();
  zeroAll.setBorderRadius(BorderDrawable.BORDER_RADIUS_ALL, 0);
  assertThat(zeroAll.isRounded(), is(false));

  BorderDrawable zeroPart = new BorderDrawable();
  zeroPart.setBorderRadius(BorderDrawable.BORDER_TOP_LEFT_RADIUS, 0);
  assertThat(zeroPart.isRounded(), is(false));
}
 
Example #18
Source File: WXDivTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject divDom = new WXDomObject();
    WXDomObject spy = Mockito.spy(divDom);
    Mockito.when(spy.getPadding()).thenReturn(new Spacing());
    Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
    Mockito.when(spy.clone()).thenReturn(divDom);
    TestDomObject.setRef(divDom,"1");
    mWXDiv = new WXDiv(instance, divDom, null);
    mWXDiv.initView();
}
 
Example #19
Source File: CSSTransformFromStyle.java    From weex with Apache License 2.0 5 votes vote down vote up
public static void transformStyle(WXDomObject node) {
  if (node != null && node.style != null && !node.style.isEmpty()) {
    node.setAlignItems(node.style.getAlignItems());
    node.setAlignSelf(node.style.getAlignSelf());
    node.setFlex(node.style.getFlex());
    node.setFlexDirection(node.style.getFlexDirection());
    node.setJustifyContent(node.style.getJustifyContent());
    node.setWrap(node.style.getCSSWrap());

    node.setMinWidth(WXViewUtils.getRealPxByWidth(node.style.getMinWidth()));
    node.setMaxWidth(WXViewUtils.getRealPxByWidth(node.style.getMaxWidth()));
    node.setMinHeight(WXViewUtils.getRealPxByWidth(node.style.getMinHeight()));
    node.setMaxHeight(WXViewUtils.getRealPxByWidth(node.style.getMaxHeight()));

    node.setMargin(Spacing.LEFT, WXViewUtils.getRealPxByWidth(node.style.getMarginLeft()));
    node.setMargin(Spacing.TOP, WXViewUtils.getRealPxByWidth(node.style.getMarginTop()));
    node.setMargin(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(node.style.getMarginRight()));
    node.setMargin(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(node.style.getMarginBottom()));

    node.setPadding(Spacing.LEFT, WXViewUtils.getRealPxByWidth(node.style.getPaddingLeft()));
    node.setPadding(Spacing.TOP, WXViewUtils.getRealPxByWidth(node.style.getPaddingTop()));
    node.setPadding(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(node.style.getPaddingRight()));
    node.setPadding(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(node.style.getPaddingBottom()));

    node.setPositionType(node.style.getPosition());
    node.setPositionLeft(WXViewUtils.getRealPxByWidth(node.style.getLeft()));
    node.setPositionTop(WXViewUtils.getRealPxByWidth(node.style.getTop()));
    node.setPositionRight(WXViewUtils.getRealPxByWidth(node.style.getRight()));
    node.setPositionBottom(WXViewUtils.getRealPxByWidth(node.style.getBottom()));

    node.setBorder(Spacing.TOP, WXViewUtils.getRealPxByWidth(node.style.getBorderTopWidth()));
    node.setBorder(Spacing.RIGHT, WXViewUtils.getRealPxByWidth(node.style.getBorderRightWidth()));
    node.setBorder(Spacing.BOTTOM, WXViewUtils.getRealPxByWidth(node.style.getBorderBottomWidth()));
    node.setBorder(Spacing.LEFT, WXViewUtils.getRealPxByWidth(node.style.getBorderLeftWidth()));

    node.setStyleHeight(WXViewUtils.getRealPxByWidth(node.style.getHeight()));
    node.setStyleWidth(WXViewUtils.getRealPxByWidth(node.style.getWidth()));
  }
}
 
Example #20
Source File: WXDivTest.java    From weex-uikit with MIT License 5 votes vote down vote up
@Test
public void testAddChild(){
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject testDom = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom.clone()).thenReturn(testDom);
    TestDomObject.setRef(testDom,"2");
    WXText child1 = new WXText(instance, testDom, mWXDiv);
    child1.initView();

    mWXDiv.addChild(child1, 0);

    assertEquals(1, mWXDiv.childCount());

    WXDomObject testDom2 = Mockito.spy(new WXDomObject());
    Mockito.when(testDom2.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom2.clone()).thenReturn(testDom2);
    TestDomObject.setRef(testDom2,"3");
    child2 = new WXText(instance, testDom2, mWXDiv);
    child2.initView();

    mWXDiv.addChild(child2, -1);

    assertEquals(2, mWXDiv.childCount());
    assertEquals(child2, mWXDiv.getChild(1));

    WXDomObject testDom3 = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom3.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom3.clone()).thenReturn(testDom3);
    TestDomObject.setRef(testDom3,"4");
    WXText child3 = new WXText(instance, testDom3, mWXDiv);
    child3.initView();

    mWXDiv.addChild(child3, 1);

    assertEquals(3, mWXDiv.childCount());
    assertEquals(child3, mWXDiv.getChild(1));
}
 
Example #21
Source File: WXTextDomObject.java    From weex with Apache License 2.0 5 votes vote down vote up
private float getTextContentWidth(){
  float rawWidth=getLayoutWidth(), left, right;
  Spacing padding=getPadding();
  if(!CSSConstants.isUndefined((left=padding.get(Spacing.LEFT)))){
    rawWidth-=left;
  }
  if(!CSSConstants.isUndefined((right=padding.get(Spacing.RIGHT)))){
    rawWidth-=right;
  }
  return rawWidth;
}
 
Example #22
Source File: WXRenderStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * set padding style of View
 */
void setPadding(String ref, Spacing padding, Spacing border) {
  WXComponent component = mRegistry.get(ref);
  if (component == null) {
    return;
  }
  component.setPadding(padding, border);
}
 
Example #23
Source File: WXDivTest.java    From weex with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddChild(){
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject testDom = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom.clone()).thenReturn(testDom);
    testDom.ref = "2";
    WXText child1 = new WXText(instance, testDom, mWXDiv, false);
    child1.initView();

    mWXDiv.addChild(child1, 0);

    assertEquals(1, mWXDiv.childCount());

    WXDomObject testDom2 = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom2.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom2.clone()).thenReturn(testDom2);
    testDom2.ref = "3";
    child2 = new WXText(instance, testDom2, mWXDiv, false);
    child2.initView();

    mWXDiv.addChild(child2, -1);

    assertEquals(2, mWXDiv.childCount());
    assertEquals(child2, mWXDiv.getChild(1));

    WXDomObject testDom3 = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom3.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom3.clone()).thenReturn(testDom3);
    testDom3.ref = "4";
    WXText child3 = new WXText(instance, testDom3, mWXDiv, false);
    child3.initView();

    mWXDiv.addChild(child3, 1);

    assertEquals(3, mWXDiv.childCount());
    assertEquals(child3, mWXDiv.getChild(1));
}
 
Example #24
Source File: BorderUtil.java    From weex-uikit with MIT License 5 votes vote down vote up
static void updateSparseArray(@NonNull SparseIntArray array, int position, int value) {
  if (position == Spacing.ALL) {
    array.put(Spacing.ALL, value);
    array.put(Spacing.TOP, value);
    array.put(Spacing.LEFT, value);
    array.put(Spacing.RIGHT, value);
    array.put(Spacing.BOTTOM, value);
  } else {
    array.put(position, value);
  }
}
 
Example #25
Source File: WXTextTest.java    From weex with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WXEnvironment.sApplication = RuntimeEnvironment.application;
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    mParentDomObj = Mockito.mock(WXDomObject.class);
    Mockito.when(mParentDomObj.getPadding()).thenReturn(new Spacing());
    Mockito.when(mParentDomObj.getBorder()).thenReturn(new Spacing());
    Mockito.when(mParentDomObj.clone()).thenReturn(mParentDomObj);
    mParentDomObj.ref = "_root";

    mDomObject = Mockito.mock(WXTextDomObject.class);
    mDomObject.ref = "1";
    mDomObject.addEvent(WXEventType.CLICK);
    Mockito.when(mDomObject.clone()).thenReturn(mDomObject);
    Mockito.when(mDomObject.getPadding()).thenReturn(new Spacing());
    Mockito.when(mDomObject.getBorder()).thenReturn(new Spacing());
    Mockito.when(mDomObject.getMargin()).thenReturn(new Spacing());
    Mockito.when(mDomObject.getLayoutWidth()).thenReturn(100f);
    Mockito.when(mDomObject.getLayoutHeight()).thenReturn(100f);

    mParent = new WXDiv(instance, mParentDomObj, null, false);
    mParent.createView(null, -1);
    mWXText = new WXText(instance, mDomObject, mParent, false);
    mWXText.setHolder(new ComponentHolder(WXText.class));
    assertNotNull(instance.getContext());
}
 
Example #26
Source File: BorderDrawable.java    From weex-uikit with MIT License 5 votes vote down vote up
private void drawBorders(Canvas canvas) {
  RectF rectBounds = new RectF(getBounds());
  BorderCorner topLeft = new TopLeftCorner(
      getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_LEFT_RADIUS),
      getBorderWidth(Spacing.LEFT),
      getBorderWidth(Spacing.TOP),
      rectBounds);
  BorderCorner topRight = new TopRightCorner(
      getBorderRadius(mOverlappingBorderRadius, BORDER_TOP_RIGHT_RADIUS),
      getBorderWidth(Spacing.TOP),
      getBorderWidth(Spacing.RIGHT),
      rectBounds);
  BorderCorner bottomRight = new BottomRightCorner(
      getBorderRadius(mOverlappingBorderRadius, BORDER_BOTTOM_RIGHT_RADIUS),
      getBorderWidth(Spacing.RIGHT),
      getBorderWidth(Spacing.BOTTOM),
      rectBounds);
  BorderCorner bottomLeft = new BottomLeftCorner(
      getBorderRadius(mOverlappingBorderRadius, BORDER_BOTTOM_LEFT_RADIUS),
      getBorderWidth(Spacing.BOTTOM),
      getBorderWidth(Spacing.LEFT),
      rectBounds);
  drawOneSide(canvas, new BorderEdge(topLeft, topRight, Spacing.TOP,
                                     getBorderWidth(Spacing.TOP)));
  drawOneSide(canvas, new BorderEdge(topRight, bottomRight, Spacing.RIGHT,
                                     getBorderWidth(Spacing.RIGHT)));
  drawOneSide(canvas, new BorderEdge(bottomRight, bottomLeft, Spacing.BOTTOM,
                                     getBorderWidth(Spacing.BOTTOM)));
  drawOneSide(canvas, new BorderEdge(bottomLeft, topLeft, Spacing.LEFT,
                                     getBorderWidth(Spacing.LEFT)));
}
 
Example #27
Source File: BorderDrawable.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Process overlapping curve according to https://www.w3.org/TR/css3-background/#corner-overlap .
 */
private void prepareBorderRadius(@NonNull RectF borderBox) {
  if (mBorderRadius != null) {
    float factor = getScaleFactor(borderBox);
    if (mOverlappingBorderRadius == null) {
      mOverlappingBorderRadius = new SparseArray<>(5);
      mOverlappingBorderRadius.put(Spacing.ALL, 0f);
    }
    if (!Float.isNaN(factor) && factor < 1) {
      mOverlappingBorderRadius.put(BORDER_TOP_LEFT_RADIUS,
                                   getBorderRadius(mBorderRadius, BORDER_TOP_LEFT_RADIUS) *
                                   factor);
      mOverlappingBorderRadius.put(BORDER_TOP_RIGHT_RADIUS,
                                   getBorderRadius(mBorderRadius, BORDER_TOP_RIGHT_RADIUS) *
                                   factor);
      mOverlappingBorderRadius.put(BORDER_BOTTOM_RIGHT_RADIUS,
                                   getBorderRadius(mBorderRadius, BORDER_BOTTOM_RIGHT_RADIUS) *
                                   factor);
      mOverlappingBorderRadius.put(BORDER_BOTTOM_LEFT_RADIUS,
                                   getBorderRadius(mBorderRadius, BORDER_BOTTOM_LEFT_RADIUS) *
                                   factor);
    } else {
      mOverlappingBorderRadius.put(BORDER_TOP_LEFT_RADIUS,
                                   getBorderRadius(mBorderRadius, BORDER_TOP_LEFT_RADIUS));
      mOverlappingBorderRadius.put(BORDER_TOP_RIGHT_RADIUS,
                                   getBorderRadius(mBorderRadius, BORDER_TOP_RIGHT_RADIUS));
      mOverlappingBorderRadius.put(BORDER_BOTTOM_RIGHT_RADIUS,
                                   getBorderRadius(mBorderRadius, BORDER_BOTTOM_RIGHT_RADIUS));
      mOverlappingBorderRadius.put(BORDER_BOTTOM_LEFT_RADIUS,
                                   getBorderRadius(mBorderRadius, BORDER_BOTTOM_LEFT_RADIUS));
    }
  }
}
 
Example #28
Source File: BorderDrawable.java    From weex-uikit with MIT License 5 votes vote down vote up
public void setBorderRadius(int position, float radius) {
  if (mBorderRadius == null) {
    mBorderRadius = new SparseArray<>(5);
    mBorderRadius.put(Spacing.ALL, DEFAULT_BORDER_RADIUS);
  }
  if (!FloatUtil.floatsEqual(getBorderRadius(mBorderRadius, position), radius)) {
    BorderUtil.updateSparseArray(mBorderRadius, position, radius, true);
    mNeedUpdatePath = true;
    invalidateSelf();
  }
}
 
Example #29
Source File: BorderDrawable.java    From weex-uikit with MIT License 5 votes vote down vote up
public void setBorderWidth(int position, float width) {
  if (mBorderWidth == null) {
    mBorderWidth = new SparseArray<>(5);
    mBorderWidth.put(Spacing.ALL, DEFAULT_BORDER_WIDTH);
  }
  if (!FloatUtil.floatsEqual(getBorderWidth(position), width)) {
    BorderUtil.updateSparseArray(mBorderWidth, position, width);
    mBorderWidth.put(position, width);
    mNeedUpdatePath = true;
    invalidateSelf();
  }
}
 
Example #30
Source File: WXDivTest.java    From weex with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);

    WXDomObject divDom = Mockito.mock(WXDomObject.class);
    Mockito.when(divDom.getPadding()).thenReturn(new Spacing());
    Mockito.when(divDom.clone()).thenReturn(divDom);
    divDom.ref = "1";

    mWXDiv = new WXDiv(instance, divDom, null, false);
    mWXDiv.initView();
}