Java Code Examples for com.taobao.weex.utils.WXViewUtils#getRealPxByWidth()

The following examples show how to use com.taobao.weex.utils.WXViewUtils#getRealPxByWidth() . 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: WXShapeFeature.java    From weex with Apache License 2.0 6 votes vote down vote up
private void initCornerRadius() {
  float radius = 0;
  if (mDom.style != null) {
    radius = mDom.style.getBorderRadius();
  }

  if (WXUtils.isUndefined(radius) || radius <= 0) {
    mCornerRadiusArray = new float[]{0, 0, 0, 0, 0, 0, 0, 0};
    return;
  }
  mHasRadius = true;

  //TODO
  radius = WXViewUtils.getRealPxByWidth(radius);

  float tl = radius;
  float bl = radius;
  float tr = radius;
  float br = radius;
  mCornerRadiusArray = new float[]{tl, tl, tr, tr, br, br, bl, bl};
}
 
Example 2
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoadMore(int offScreenY) {
  try {
    String offset = getDomObject().getAttrs().getLoadMoreOffset();

    if (TextUtils.isEmpty(offset)) {
      offset = "0";
    }
    float offsetParsed = WXViewUtils.getRealPxByWidth(Integer.parseInt(offset),getInstance().getInstanceViewPortWidth());

    if (offScreenY < offsetParsed) {

      if (mListCellCount != mChildren.size()
          || mForceLoadmoreNextTime) {
        fireEvent(Constants.Event.LOADMORE);
        mListCellCount = mChildren.size();
        mForceLoadmoreNextTime = false;
      }
    }
  } catch (Exception e) {
    WXLogUtils.d(TAG + "onLoadMore :", e);
  }
}
 
Example 3
Source File: WXScroller.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void scrollTo(WXComponent component, Map<String, Object> options) {
  float offsetFloat = 0;
  boolean smooth = true;

  if (options != null) {
    String offset = options.get(Constants.Name.OFFSET) == null ? "0" : options.get(Constants.Name.OFFSET).toString();
    smooth = WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
    if (offset != null) {
      try {
        offsetFloat = WXViewUtils.getRealPxByWidth(Float.parseFloat(offset), getInstance().getInstanceViewPortWidth());
      }catch (Exception e ){
        WXLogUtils.e("Float parseFloat error :"+e.getMessage());
      }
    }
  }

  int viewYInScroller=component.getAbsoluteY() - getAbsoluteY();
  int viewXInScroller=component.getAbsoluteX() - getAbsoluteX();

  scrollBy(viewXInScroller - getScrollX() + (int) offsetFloat, viewYInScroller - getScrollY() + (int) offsetFloat, smooth);
}
 
Example 4
Source File: WXShapeFeature.java    From weex with Apache License 2.0 5 votes vote down vote up
public WXShapeFeature(Context context, View view, WXDomObject dom) {
  if (dom == null) {
    return;
  }
  mDom = dom;
  int strokeColor = Color.GRAY;
  mHost = view;

  int type = RoundRectShape;
  initCornerRadius();
  setShape(type);
  mStrokePaint = new Paint();

  mStrokePaint.setStyle(Paint.Style.STROKE);
  mStrokePaint.setAntiAlias(true);
  if (mDom.style != null) {
    String realBgColor = mDom.style.getBorderColor();
    if (!TextUtils.isEmpty(realBgColor)) {
      strokeColor = WXResourceUtils.getColor(realBgColor);
    }
    if (strokeColor == -1) {
      strokeColor = Color.GRAY;
    }
    mStrokeWidth = mDom.style.getBorderWidth();
    if (!WXUtils.isUndefined(mStrokeWidth) && mStrokeWidth > 0) {
      mStrokeEnable = true;
      mStrokeWidth = WXViewUtils.getRealPxByWidth(mStrokeWidth);
      mStrokePaint.setStrokeWidth(mStrokeWidth);
    }
  }

  mStrokePaint.setColor(strokeColor);

  mStrokePath = new Path();
  mRectF = new RectF();
}
 
Example 5
Source File: WXStyle.java    From weex with Apache License 2.0 5 votes vote down vote up
public static int getFontSize(Map<String, Object> style) {
  if (style == null) {
    return (int) WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE);
  }
  int fontSize = WXUtils.getInt(style.get(WXDomPropConstant.WX_FONTSIZE));
  if (fontSize <= 0) {
    fontSize = WXText.sDEFAULT_SIZE;
  }
  return (int) WXViewUtils.getRealPxByWidth(fontSize);
}
 
Example 6
Source File: WXStyle.java    From weex-uikit with MIT License 5 votes vote down vote up
public static int getFontSize(Map<String, Object> style,int viewPortW) {
  if (style == null) {
    return (int) WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE,viewPortW);
  }
  int fontSize = WXUtils.getInt(style.get(Constants.Name.FONT_SIZE));
  if (fontSize <= 0) {
    fontSize = WXText.sDEFAULT_SIZE;
  }
  return (int) WXViewUtils.getRealPxByWidth(fontSize,viewPortW);
}
 
Example 7
Source File: WXStyle.java    From weex with Apache License 2.0 5 votes vote down vote up
public static int getLineHeight(Map<String, Object> style){
  if (style == null) {
    return UNSET;
  }
  int lineHeight = WXUtils.getInt(style.get(WXDomPropConstant.WX_TEXT_LINE_HEIGHT));
  if (lineHeight <= 0) {
    lineHeight = UNSET;
    return lineHeight;
  }
  return (int) WXViewUtils.getRealPxByWidth(lineHeight);
}
 
Example 8
Source File: WXScroller.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Handle loadMore Event.when Scroller has bind loadMore Event and set the attr of loadMoreOffset
 * it will tell the JS to handle the event of onLoadMore;
 * @param scrollView  the WXScrollView
 * @param x the X direction
 * @param y the Y direction
 */
protected void onLoadMore(WXScrollView scrollView, int x, int y) {
  try {
    String offset = getDomObject().getAttrs().getLoadMoreOffset();
    if (TextUtils.isEmpty(offset)) {
      return;
    }
    int offsetInt = (int)WXViewUtils.getRealPxByWidth(Float.parseFloat(offset), getInstance().getInstanceViewPortWidth());

    int contentH = scrollView.getChildAt(0).getHeight();
    int scrollerH = scrollView.getHeight();
    int offScreenY = contentH - y - scrollerH;
    if (offScreenY < offsetInt) {
      if (WXEnvironment.isApkDebugable()) {
        WXLogUtils.d("[WXScroller-onScroll] offScreenY :" + offScreenY);
      }
      if (mContentHeight != contentH || mForceLoadmoreNextTime) {
        fireEvent(Constants.Event.LOADMORE);
        mContentHeight = contentH;
        mForceLoadmoreNextTime = false;
      }
    }
  } catch (Exception e) {
    WXLogUtils.d("[WXScroller-onScroll] ", e);
  }

}
 
Example 9
Source File: WXEmbed.java    From weex-uikit with MIT License 5 votes vote down vote up
public WXEmbed(WXSDKInstance instance, WXDomObject node, WXVContainer parent) {
  super(instance, node, parent);
  mListener = new EmbedRenderListener(this);

  ERROR_IMG_WIDTH = (int) WXViewUtils.getRealPxByWidth(270,instance.getViewPortWidth());
  ERROR_IMG_HEIGHT = (int) WXViewUtils.getRealPxByWidth(260,instance.getViewPortWidth());
  if(instance instanceof EmbedManager) {
    Object itemId = node.getAttrs().get(ITEM_ID);
    if (itemId != null) {
      ((EmbedManager) instance).putEmbed(itemId.toString(), this);
    }
  }
}
 
Example 10
Source File: WXAnimationBean.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private static float parsePercentOrPx(String raw, int unit,int viewportW) {
  final int precision = 1;
  int suffix;
  if ((suffix = raw.lastIndexOf(WXUtils.PERCENT)) != -1) {
    return parsePercent(raw.substring(0, suffix), unit, precision);
  } else if ((suffix = raw.lastIndexOf(PX)) != -1) {
    return WXViewUtils.getRealPxByWidth(WXUtils.fastGetFloat(raw.substring(0, suffix), precision),viewportW);
  }
  return WXViewUtils.getRealPxByWidth(WXUtils.fastGetFloat(raw, precision),viewportW);
}
 
Example 11
Source File: WXSliderNeighbor.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * we need add translation for left and right card view.
 * */
private float calculateTranslation(@NonNull View hostPage) {
    if(!(hostPage instanceof ViewGroup)) {
        return 0;
    }
    View realView = ((ViewGroup)hostPage).getChildAt(0);
    float translation = (hostPage.getMeasuredWidth()-realView.getMeasuredWidth()*mNeighborScale)/4;
    translation += ((hostPage.getMeasuredWidth()-realView.getMeasuredWidth()*WX_DEFAULT_MAIN_NEIGHBOR_SCALE)/2 - WXViewUtils.getRealPxByWidth(mNeighborSpace))/2 ;
    return translation;
}
 
Example 12
Source File: WXStyle.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static int getFontSize(Map<String, Object> style,int viewPortW) {
  if (style == null) {
    return (int) WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE,viewPortW);
  }
  int fontSize = WXUtils.getInt(style.get(Constants.Name.FONT_SIZE));
  if (fontSize <= 0) {
    fontSize = WXText.sDEFAULT_SIZE;
  }
  return (int) WXViewUtils.getRealPxByWidth(fontSize,viewPortW);
}
 
Example 13
Source File: WXSwitchDomObject.java    From weex with Apache License 2.0 4 votes vote down vote up
@Override
public void setMinHeight(float minHeight) {
    super.setMinHeight(WXViewUtils.getRealPxByWidth(FIXED_HEIGHT));
}
 
Example 14
Source File: WXRecyclerDomObject.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public float getColumnWidth() {
    return WXViewUtils.getRealPxByWidth(mColumnWidth,getViewPortWidth());
}
 
Example 15
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@WXComponentProp(name = Constants.Name.OFFSET_ACCURACY)
public void setOffsetAccuracy(int accuracy) {
  float real = WXViewUtils.getRealPxByWidth(accuracy, getInstance().getInstanceViewPortWidth());
  this.mOffsetAccuracy = (int) real;
}
 
Example 16
Source File: WXRenderStatement.java    From weex with Apache License 2.0 4 votes vote down vote up
/**
 * @see com.taobao.weex.dom.WXDomStatement#scrollToDom(String, JSONObject)
 */
void scrollTo(String ref, Map<String, Object> options) {
  WXComponent component = mRegistry.get(ref);
  if (component == null) {
    return;
  }

  int offsetInt = 0;
  if (options != null) {
    String offset = options.get("offset") == null ? "0" : options.get("offset").toString();
    if (offset != null) {
      offsetInt = Integer.parseInt(offset);
    }
  }

  WXScroller scroller = component.getParentScroller();
  if (scroller == null) {
    return;
  }
  int offsetIntF = (int) WXViewUtils.getRealPxByWidth(offsetInt);
  int[] scrollerP = new int[2];
  scroller.getView().getLocationOnScreen(scrollerP);
  if (scrollerP[1] == component.getAbsoluteY() && scroller.getView() instanceof WXScrollView) {
    return;
  }

  if(scrollerP[0] == component.getAbsoluteX() && scroller.getView() instanceof WXHorizontalScrollView){
    return;
  }

  int viewYInScroller=component.getAbsoluteY();
  int viewXInScroller=component.getAbsoluteX();
  WXComponent ancestor=component;
  while((ancestor=ancestor.getParent())!=null){
    if(ancestor instanceof WXScroller){
      viewYInScroller-=ancestor.getAbsoluteY();
      viewXInScroller-=ancestor.getAbsoluteX();
    }
  }
  scroller.scrollBy(scroller.getView().getScrollX()-viewXInScroller-offsetIntF,
                    scroller.getView().getScrollY() - viewYInScroller - offsetIntF);
}
 
Example 17
Source File: WXRecyclerDomObject.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public float getAvailableWidth() {
    return WXViewUtils.getRealPxByWidth(mAvailableWidth,getViewPortWidth());
}
 
Example 18
Source File: WXSvgContainer.java    From Svg-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
@WXComponentProp(name = Constants.Name.HEIGHT)
public void setHeight(int height) {
  mHeight = height;
  getHostView().getLayoutParams().height = (int) WXViewUtils.getRealPxByWidth(height, 750);
}
 
Example 19
Source File: WXSwitchDomObject.java    From weex with Apache License 2.0 4 votes vote down vote up
@Override
public void setStyleWidth(float width) {
    super.setStyleWidth(WXViewUtils.getRealPxByWidth(FIXED_WIDTH));
}
 
Example 20
Source File: WXSvgContainer.java    From Svg-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
@WXComponentProp(name = Constants.Name.WIDTH)
public void setWidth(int width) {
  mWidth = width;
  getHostView().getLayoutParams().width = (int) WXViewUtils.getRealPxByWidth(width, 750);
}