com.taobao.weex.utils.WXViewUtils Java Examples

The following examples show how to use com.taobao.weex.utils.WXViewUtils. 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: 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 #2
Source File: WXPickersModule.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private TextView makeTitleView(Context context, Map<String, Object> options) {
    String text = getOption(options, KEY_TITLE, null);
    if (text == null) {
        return null;
    }
    TextView textView = new TextView(context);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
    int padding = WXViewUtils.dip2px(12);
    textView.setPadding(padding, padding, padding, padding);
    textView.getPaint().setFakeBoldText(true);
    textView.setBackgroundColor(getColor(options, KEY_TITLE_BACKGROUND_COLOR, Color.TRANSPARENT));
    textView.setTextColor(getColor(options, KEY_TITLE_COLOR, Color.BLACK));
    textView.setText(text);
    return textView;
}
 
Example #3
Source File: WXBridgeManager.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private WXParams assembleDefaultOptions() {
  Map<String, String> config = WXEnvironment.getConfig();
  WXParams wxParams = new WXParams();
  wxParams.setPlatform(config.get(WXConfig.os));
  wxParams.setOsVersion(config.get(WXConfig.sysVersion));
  wxParams.setAppVersion(config.get(WXConfig.appVersion));
  wxParams.setWeexVersion(config.get(WXConfig.weexVersion));
  wxParams.setDeviceModel(config.get(WXConfig.sysModel));
  wxParams.setShouldInfoCollect(config.get("infoCollect"));
  wxParams.setLogLevel(config.get(WXConfig.logLevel));
  String appName = config.get(WXConfig.appName);
  if (!TextUtils.isEmpty(appName)) {
    wxParams.setAppName(appName);
  }
  wxParams.setDeviceWidth(TextUtils.isEmpty(config.get("deviceWidth")) ? String.valueOf(WXViewUtils.getScreenWidth(WXEnvironment.sApplication)) : config.get("deviceWidth"));
  wxParams.setDeviceHeight(TextUtils.isEmpty(config.get("deviceHeight")) ? String.valueOf(WXViewUtils.getScreenHeight(WXEnvironment.sApplication)) : config.get("deviceHeight"));
  wxParams.setOptions(WXEnvironment.getCustomOptions());
  wxParams.setNeedInitV8(WXSDKManager.getInstance().needInitV8());
  return wxParams;
}
 
Example #4
Source File: BorderDrawable.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(@NonNull Canvas canvas) {
  canvas.save();
  updateBorderOutline();
  //Shader uses alpha as well.
  mPaint.setAlpha(255);
  if (mPathForBorderOutline != null) {
    int useColor = WXViewUtils.multiplyColorAlpha(mColor, mAlpha);
    if (mShader != null) {
      mPaint.setShader(mShader);
      mPaint.setStyle(Paint.Style.FILL);
      canvas.drawPath(mPathForBorderOutline, mPaint);
      mPaint.setShader(null);
    } else if ((useColor >>> 24) != 0) {
      mPaint.setColor(useColor);
      mPaint.setStyle(Paint.Style.FILL);
      canvas.drawPath(mPathForBorderOutline, mPaint);
      mPaint.setShader(null);
    }
  }
  mPaint.setStyle(Paint.Style.STROKE);
  mPaint.setStrokeJoin(Paint.Join.ROUND);
  drawBorders(canvas);
  mPaint.setShader(null);
  canvas.restore();
}
 
Example #5
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 #6
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public void setBorderRadius(String key, float borderRadius) {
  if (borderRadius >= 0) {
    switch (key) {
      case Constants.Name.BORDER_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_RADIUS_ALL, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.getInstanceViewPortWidth()));
        break;
      case Constants.Name.BORDER_TOP_LEFT_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_TOP_LEFT_RADIUS, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.getInstanceViewPortWidth()));
        break;
      case Constants.Name.BORDER_TOP_RIGHT_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_TOP_RIGHT_RADIUS, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.getInstanceViewPortWidth()));
        break;
      case Constants.Name.BORDER_BOTTOM_RIGHT_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_BOTTOM_RIGHT_RADIUS, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.getInstanceViewPortWidth()));
        break;
      case Constants.Name.BORDER_BOTTOM_LEFT_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_BOTTOM_LEFT_RADIUS, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.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 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 #8
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private void fireScrollEvent(RecyclerView recyclerView, int offsetX, int offsetY) {
  int contentWidth = recyclerView.getMeasuredWidth() + recyclerView.computeHorizontalScrollRange();
  int contentHeight = recyclerView.computeVerticalScrollRange();

  Map<String, Object> event = new HashMap<>(2);
  Map<String, Object> contentSize = new HashMap<>(2);
  Map<String, Object> contentOffset = new HashMap<>(2);

  contentSize.put(Constants.Name.WIDTH, WXViewUtils.getWebPxByWidth(contentWidth, getInstance().getInstanceViewPortWidth()));
  contentSize.put(Constants.Name.HEIGHT, WXViewUtils.getWebPxByWidth(contentHeight, getInstance().getInstanceViewPortWidth()));

  contentOffset.put(Constants.Name.X, - WXViewUtils.getWebPxByWidth(offsetX, getInstance().getInstanceViewPortWidth()));
  contentOffset.put(Constants.Name.Y, - WXViewUtils.getWebPxByWidth(offsetY, getInstance().getInstanceViewPortWidth()));
  event.put(Constants.Name.CONTENT_SIZE, contentSize);
  event.put(Constants.Name.CONTENT_OFFSET, contentOffset);

  fireEvent(Constants.Event.SCROLL, event);
}
 
Example #9
Source File: WXBridgeManager.java    From weex-uikit with MIT License 6 votes vote down vote up
private WXParams assembleDefaultOptions() {
  Map<String, String> config = WXEnvironment.getConfig();
  WXParams wxParams = new WXParams();
  wxParams.setPlatform(config.get("os"));
  wxParams.setOsVersion(config.get("sysVersion"));
  wxParams.setAppVersion(config.get("appVersion"));
  wxParams.setWeexVersion(config.get("weexVersion"));
  wxParams.setDeviceModel(config.get("sysModel"));
  wxParams.setShouldInfoCollect(config.get("infoCollect"));
  wxParams.setLogLevel(config.get(WXConfig.logLevel));
  String appName = config.get("appName");
  if (!TextUtils.isEmpty(appName)) {
    wxParams.setAppName(appName);
  }
  wxParams.setDeviceWidth(TextUtils.isEmpty(config.get("deviceWidth")) ? String.valueOf(WXViewUtils.getScreenWidth(WXEnvironment.sApplication)) : config.get("deviceWidth"));
  wxParams.setDeviceHeight(TextUtils.isEmpty(config.get("deviceHeight")) ? String.valueOf(WXViewUtils.getScreenHeight(WXEnvironment.sApplication)) : config.get("deviceHeight"));
  wxParams.setOptions(WXEnvironment.getCustomOptions());
  return wxParams;
}
 
Example #10
Source File: WXBridgeManager.java    From weex with Apache License 2.0 6 votes vote down vote up
private WXParams assembleDefaultOptions() {
  Map<String, String> config = WXEnvironment.getConfig();
  WXParams wxParams = new WXParams();
  wxParams.setPlatform(config.get("os"));
  wxParams.setOsVersion(config.get("sysVersion"));
  wxParams.setAppVersion(config.get("appVersion"));
  wxParams.setWeexVersion(config.get("weexVersion"));
  wxParams.setDeviceModel(config.get("sysModel"));
  wxParams.setShouldInfoCollect(config.get("infoCollect"));
  wxParams.setLogLevel(config.get(WXConfig.logLevel));
  String appName = config.get("appName");
  if (!TextUtils.isEmpty(appName)) {
    wxParams.setAppName(appName);
  }
  wxParams.setDeviceWidth(TextUtils.isEmpty(config.get("deviceWidth")) ? String.valueOf(WXViewUtils.getScreenWidth(WXEnvironment.sApplication)) : config.get("deviceWidth"));
  wxParams.setDeviceHeight(TextUtils.isEmpty(config.get("deviceHeight")) ? String.valueOf(WXViewUtils.getScreenHeight(WXEnvironment.sApplication)) : config.get("deviceHeight"));
  return wxParams;
}
 
Example #11
Source File: WXMetaModule.java    From weex-uikit with MIT License 6 votes vote down vote up
@JSMethod(uiThread = false)
public void setViewport(String param) {
    if (!TextUtils.isEmpty(param)) {
        try {
            param = URLDecoder.decode(param, "utf-8");
            JSONObject jsObj = JSON.parseObject(param);
            if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) {
                mWXSDKInstance.setViewPortWidth(WXViewUtils.getScreenWidth(mWXSDKInstance.getContext()));
            } else {
                int width = jsObj.getInteger(WIDTH);
                if (width > 0) {
                    mWXSDKInstance.setViewPortWidth(width);
                }
            }
        } catch (Exception e) {
            WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
        }
    }
}
 
Example #12
Source File: WXRenderStatement.java    From weex-uikit with MIT License 6 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;
  }

  float offsetFloat = 0;
  if (options != null) {
    String offset = options.get("offset") == null ? "0" : options.get("offset").toString();
    if (offset != null) {
      try {
        offsetFloat = WXViewUtils.getRealPxByWidth(Float.parseFloat(offset),mWXSDKInstance.getViewPortWidth());
      }catch (Exception e ){
         WXLogUtils.e("Float parseFloat error :"+e.getMessage());
      }
    }
  }

  Scrollable scroller = component.getParentScroller();
  if (scroller == null) {
    return;
  }
  scroller.scrollTo(component,(int)offsetFloat);
}
 
Example #13
Source File: WXScroller.java    From weex with Apache License 2.0 6 votes vote down vote up
@Override
protected MeasureOutput measure(int width, int height) {
  MeasureOutput measureOutput = new MeasureOutput();
  if (this.mOrientation == WXVContainer.HORIZONTAL) {
    int screenW = WXViewUtils.getScreenWidth(WXEnvironment.sApplication);
    int weexW = WXViewUtils.getWeexWidth(mInstanceId);
    measureOutput.width = width > (weexW >= screenW ? screenW : weexW) ? FrameLayout.LayoutParams.MATCH_PARENT
                                                                       : width;
    measureOutput.height = height;
  } else {
    int screenH = WXViewUtils.getScreenHeight(WXEnvironment.sApplication);
    int weexH = WXViewUtils.getWeexHeight(mInstanceId);
    measureOutput.height = height > (weexH >= screenH ? screenH : weexH) ? FrameLayout.LayoutParams.MATCH_PARENT
                                                                         : height;
    measureOutput.width = width;
  }
  return measureOutput;
}
 
Example #14
Source File: WXScroller.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
protected MeasureOutput measure(int width, int height) {
  MeasureOutput measureOutput = new MeasureOutput();
  if (this.mOrientation == Constants.Orientation.HORIZONTAL) {
    int screenW = WXViewUtils.getScreenWidth(WXEnvironment.sApplication);
    int weexW = WXViewUtils.getWeexWidth(getInstanceId());
    measureOutput.width = width > (weexW >= screenW ? screenW : weexW) ? FrameLayout.LayoutParams.MATCH_PARENT
                                                                       : width;
    measureOutput.height = height;
  } else {
    int screenH = WXViewUtils.getScreenHeight(WXEnvironment.sApplication);
    int weexH = WXViewUtils.getWeexHeight(getInstanceId());
    measureOutput.height = height > (weexH >= screenH ? screenH : weexH) ? FrameLayout.LayoutParams.MATCH_PARENT
                                                                         : height;
    measureOutput.width = width;
  }
  return measureOutput;
}
 
Example #15
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 #16
Source File: BorderDrawable.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
public void draw(@NonNull Canvas canvas) {
  canvas.save();
  updateBorderOutline();
  if (mPathForBorderOutline != null) {
    int useColor = WXViewUtils.multiplyColorAlpha(mColor, mAlpha);
    if (mShader != null) {
      mPaint.setShader(mShader);
      mPaint.setStyle(Paint.Style.FILL);
      canvas.drawPath(mPathForBorderOutline, mPaint);
      mPaint.setShader(null);
    } else if ((useColor >>> 24) != 0) {
      mPaint.setColor(useColor);
      mPaint.setStyle(Paint.Style.FILL);
      canvas.drawPath(mPathForBorderOutline, mPaint);
      mPaint.setShader(null);
    }
  }
  mPaint.setStyle(Paint.Style.STROKE);
  mPaint.setStrokeJoin(Paint.Join.ROUND);
  drawBorders(canvas);
  mPaint.setShader(null);
  canvas.restore();
}
 
Example #17
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
protected void createViewImpl() {
  if (mContext != null) {
    mHost = initComponentHostView(mContext);
    if (mHost == null && !isVirtualComponent()) {
      //compatible
      initView();
    }
    if(mHost != null){
      mHost.setId(WXViewUtils.generateViewId());
      ComponentObserver observer;
      if ((observer = getInstance().getComponentObserver()) != null) {
        observer.onViewCreated(this, mHost);
      }
    }
    onHostViewInitialized(mHost);
  }else{
    WXLogUtils.e("createViewImpl","Context is null");
  }
}
 
Example #18
Source File: WXComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
public void setBorderRadius(String key, float borderRadius) {
  if (borderRadius >= 0) {
    switch (key) {
      case Constants.Name.BORDER_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_RADIUS_ALL, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.getViewPortWidth()));
        break;
      case Constants.Name.BORDER_TOP_LEFT_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_TOP_LEFT_RADIUS, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.getViewPortWidth()));
        break;
      case Constants.Name.BORDER_TOP_RIGHT_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_TOP_RIGHT_RADIUS, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.getViewPortWidth()));
        break;
      case Constants.Name.BORDER_BOTTOM_RIGHT_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_BOTTOM_RIGHT_RADIUS, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.getViewPortWidth()));
        break;
      case Constants.Name.BORDER_BOTTOM_LEFT_RADIUS:
        getOrCreateBorder().setBorderRadius(BorderDrawable.BORDER_BOTTOM_LEFT_RADIUS, WXViewUtils.getRealSubPxByWidth(borderRadius,mInstance.getViewPortWidth()));
        break;
    }
  }
}
 
Example #19
Source File: WXSlider.java    From weex-uikit with MIT License 5 votes vote down vote up
@Override
public void onPageSelected(int pos) {
  if (mAdapter.getRealPosition(pos) == lastPos) {
    return;
  }
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.d("onPageSelected >>>>" + mAdapter.getRealPosition(pos) + " lastPos: " + lastPos);
  }
  if (mAdapter == null || mAdapter.getRealCount() == 0) {
    return;
  }

  int realPosition = mAdapter.getRealPosition(pos);
  if (mChildren == null || realPosition >= mChildren.size()) {
    return;
  }

  if (getDomObject().getEvents().size() == 0) {
    return;
  }
  WXEvent event = getDomObject().getEvents();
  String ref = getDomObject().getRef();
  if (event.contains(Constants.Event.CHANGE) && WXViewUtils.onScreenArea(getHostView())) {
    params.put(INDEX, realPosition);

    Map<String, Object> domChanges = new HashMap<>();
    Map<String, Object> attrsChanges = new HashMap<>();
    attrsChanges.put(INDEX, realPosition);
    domChanges.put("attrs", attrsChanges);
    WXSDKManager.getInstance().fireEvent(getInstanceId(), ref,
        Constants.Event.CHANGE, params, domChanges);
  }

  mViewPager.requestLayout();
  getHostView().invalidate();
  lastPos = mAdapter.getRealPosition(pos);
}
 
Example #20
Source File: WXAnimationBean.java    From weex-uikit with MIT License 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 #21
Source File: WXAttr.java    From weex-uikit with MIT License 5 votes vote down vote up
public float getElevation(int viewPortW) {
  Object obj = get(Constants.Name.ELEVATION);
  float ret = Float.NaN;
  if (obj != null) {
    String number = obj.toString();
    if (!TextUtils.isEmpty(number)) {
      ret = WXViewUtils.getRealSubPxByWidth(WXUtils.getFloat(number),viewPortW);
    } else {
      ret = 0;
    }
  }
  return ret;
}
 
Example #22
Source File: BasicEditTextDomObject.java    From weex-uikit with MIT License 5 votes vote down vote up
public BasicEditTextDomObject() {
  super();
  mPaint.setTextSize(WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE,getViewPortWidth()));
  setMeasureFunction(new MeasureFunction() {
    @Override
    public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
      if (CSSConstants.isUndefined(width)) {
        width = node.cssstyle.maxWidth;
      }
      measureOutput.height = getMeasureHeight();
      measureOutput.width = width;
    }
  });
}
 
Example #23
Source File: WXStyle.java    From weex-uikit with MIT License 5 votes vote down vote up
public static int getLineHeight(Map<String, Object> style,int viewPortW){
  if (style == null) {
    return UNSET;
  }
  int lineHeight = WXUtils.getInt(style.get(Constants.Name.LINE_HEIGHT));
  if (lineHeight <= 0) {
    lineHeight = UNSET;
    return lineHeight;
  }
  return (int) WXViewUtils.getRealPxByWidth(lineHeight,viewPortW);
}
 
Example #24
Source File: WXHttpUtil.java    From weex-uikit with MIT License 5 votes vote down vote up
public static String assembleUserAgent(Context ctx,Map<String, String> config) {
  if (TextUtils.isEmpty(sDefautUA)) {
    StringBuilder builder = new StringBuilder();
    builder.append(config.get(WXConfig.sysModel))
        .append("(Android/")
        .append(config.get(WXConfig.sysVersion))
        .append(")")
        .append(" ")

        .append(TextUtils.isEmpty(config.get(WXConfig.appGroup)) ? "" : config.get(WXConfig.appGroup))
        .append("(")
        .append(TextUtils.isEmpty(config.get(WXConfig.appName)) ? "" : config.get(WXConfig.appName))
        .append("/")
        .append(config.get(WXConfig.appVersion))
        .append(")")
        .append(" ")

        .append("Weex/")
        .append(config.get(WXConfig.weexVersion))
        .append(" ")

        .append(TextUtils.isEmpty(config.get(WXConfig.externalUserAgent)) ? "" : config.get(WXConfig.externalUserAgent))
        .append(TextUtils.isEmpty(config.get(WXConfig.externalUserAgent)) ? "" : " ")

        .append(WXViewUtils.getScreenWidth(ctx) + "x" + WXViewUtils.getScreenHeight(ctx));
    sDefautUA = builder.toString();
  }
  return sDefautUA;
}
 
Example #25
Source File: BasicEditTextDomObject.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public BasicEditTextDomObject() {
  super();
  mPaint.setTextSize(WXViewUtils.getRealPxByWidth(WXText.sDEFAULT_SIZE,getViewPortWidth()));
  setMeasureFunction(new MeasureFunction() {
    @Override
    public void measure(CSSNode node, float width, MeasureOutput measureOutput) {
      if (CSSConstants.isUndefined(width)) {
        width = node.cssstyle.maxWidth;
      }
      measureOutput.height = getMeasureHeight();
      measureOutput.width = width;
    }
  });
}
 
Example #26
Source File: WXAttrTest.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetElevation() {
  int elevation = 100, viewPortW = 750;

  attr.put(Constants.Name.ELEVATION, elevation);
  assertThat(attr.getElevation(viewPortW),
             is(WXViewUtils.getRealSubPxByWidth(elevation, viewPortW)));

  attr.put(Constants.Name.ELEVATION, "");
  assertThat(attr.getElevation(viewPortW), is(0f));

  attr.put(Constants.Name.ELEVATION, "give me a NAN");
  assertThat(attr.getElevation(viewPortW), is(Float.NaN));
}
 
Example #27
Source File: WXSDKInstance.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void setSize(int width, int height) {
  if (width < 0 || height < 0 || isDestroy || !mRendered) {
    return;
  }
  float realWidth = WXViewUtils.getWebPxByWidth(width,getInstanceViewPortWidth());
  float realHeight = WXViewUtils.getWebPxByWidth(height,getInstanceViewPortWidth());

  View godView = mRenderContainer;
  if (godView != null) {
    ViewGroup.LayoutParams layoutParams = godView.getLayoutParams();
    if (layoutParams != null) {
      if(godView.getWidth() != width || godView.getHeight() != height) {
        layoutParams.width = width;
        layoutParams.height = height;
        godView.setLayoutParams(layoutParams);
      }

      JSONObject style = new JSONObject();
      WXComponent rootComponent = mRootComp;

      if(rootComponent == null){
        return;
      }
      style.put(Constants.Name.DEFAULT_WIDTH, realWidth);
      style.put(Constants.Name.DEFAULT_HEIGHT, realHeight);
      updateRootComponentStyle(style);
    }
  }
}
 
Example #28
Source File: WXSliderNeighbor.java    From ucar-weex-core with Apache License 2.0 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() * mCurrentItemScale)/2 - WXViewUtils.getRealPxByWidth(mNeighborSpace, getInstance().getInstanceViewPortWidth()))/2 ;
    return translation;
}
 
Example #29
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Measure the size of the recyclerView.
 *
 * @param width  the expected width
 * @param height the expected height
 * @return the result of measurement
 */
@Override
protected MeasureOutput measure(int width, int height) {
  int screenH = WXViewUtils.getScreenHeight(WXEnvironment.sApplication);
  int weexH = WXViewUtils.getWeexHeight(getInstanceId());
  int outHeight = height > (weexH >= screenH ? screenH : weexH) ? weexH - getAbsoluteY() : height;
  return super.measure((int)(width+mColumnGap), outHeight);
}
 
Example #30
Source File: WXStyle.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static int getLineHeight(Map<String, Object> style,int viewPortW){
  if (style == null) {
    return UNSET;
  }
  int lineHeight = WXUtils.getInt(style.get(Constants.Name.LINE_HEIGHT));
  if (lineHeight <= 0) {
    lineHeight = UNSET;
    return lineHeight;
  }
  return (int) WXViewUtils.getRealPxByWidth(lineHeight,viewPortW);
}