Java Code Examples for com.taobao.weex.WXEnvironment#sDefaultWidth()

The following examples show how to use com.taobao.weex.WXEnvironment#sDefaultWidth() . 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: WXViewUtils.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Convert distance from JS,CSS to native. As the JS considers the width of the screen is 750px.
 * There must be a transform when accessing distance from JS,CSS and use it.
 * Basically, this method calculates a scale factor(ScreenWidth/750) and use apply this scale
 * factor to JS,CSS distance.
 * @param pxValue the raw distance from JS or CSS. The result will be rounded to a closet int.
 * @return the actual distance in the screen.
 */
public static float getRealPxByWidth(float pxValue) {
  if (Float.isNaN(pxValue)) {
    return pxValue;
  }
  if (mUseWebPx) {
    return (float) Math.rint(pxValue);
  } else {
    float realPx = (pxValue * getScreenWidth() / WXEnvironment.sDefaultWidth);
    return realPx > 0.005 && realPx < 1 ? 1 : (float) Math.rint(realPx);
  }
}
 
Example 2
Source File: WXViewUtils.java    From weex with Apache License 2.0 5 votes vote down vote up
public static int getRealPxByWidth2(float pxValue) {
  if (mUseWebPx) {
    return (int) pxValue;
  } else {
    float realPx = (pxValue * getScreenWidth() / WXEnvironment.sDefaultWidth);
    return realPx > 0.005 && realPx < 1 ? 1 : (int) realPx - 1;
  }
}
 
Example 3
Source File: WXViewUtils.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Convert distance from native to JS,CSS. As the JS considers the width of the screen is 750px.
 * There must be a transform when return distance to JS,CSS.
 * Basically, this method calculates a scale factor(ScreenWidth/750) and use apply this scale
 * factor to native distance.
 * @param pxValue the raw distance of native. The result will be rounded to a closet int.
 * @return the distance in JS,CSS where the screenWidth is 750 px.
 */
public static float getWebPxByWidth(float pxValue) {
  if (pxValue < -1.9999 && pxValue > -2.005) {
    return Float.NaN;
  }
  if (mUseWebPx) {
    return pxValue;
  } else {
    float realPx = (pxValue * WXEnvironment.sDefaultWidth / getScreenWidth());
    return realPx > 0.005 && realPx < 1 ? 1 : realPx;
  }
}