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

The following examples show how to use com.taobao.weex.utils.WXViewUtils#getWebPxByWidth() . 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 ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Trigger a updateStyle invoke to relayout current page
 */
public void notifyNativeSizeChanged(int w, int h) {
  if (!mNeedLayoutOnAnimation) {
    return;
  }

  Message message = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = getInstanceId();
  if (task.args == null) {
    task.args = new ArrayList<>();
  }

  JSONObject style = new JSONObject(2);
  float webW = WXViewUtils.getWebPxByWidth(w);
  float webH = WXViewUtils.getWebPxByWidth(h);

  style.put("width", webW);
  style.put("height", webH);

  task.args.add(getRef());
  task.args.add(style);
  message.obj = task;
  message.what = WXDomHandler.MsgType.WX_DOM_UPDATE_STYLE;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(message);
}
 
Example 2
Source File: WXRecyclerDomObject.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void preCalculateCellWidth(){

        if (getAttrs() != null) {
            mColumnCount = getAttrs().getColumnCount();
            mColumnWidth = getAttrs().getColumnWidth();
            mColumnGap =  getAttrs().getColumnGap();

            mAvailableWidth = getStyleWidth()-getPadding().get(Spacing.LEFT)-getPadding().get(Spacing.RIGHT);
            mAvailableWidth = WXViewUtils.getWebPxByWidth(mAvailableWidth,getViewPortWidth());

            if (Constants.Value.AUTO == mColumnCount && Constants.Value.AUTO == mColumnWidth) {
                mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
            } else if (Constants.Value.AUTO == mColumnWidth && Constants.Value.AUTO != mColumnCount) {
                mColumnWidth = (mAvailableWidth - ((mColumnCount - 1) * mColumnGap)) / mColumnCount;
                mColumnWidth = mColumnWidth > 0 ? mColumnWidth :0;
            } else if (Constants.Value.AUTO != mColumnWidth && Constants.Value.AUTO == mColumnCount) {
                mColumnCount = Math.round((mAvailableWidth + mColumnGap) / (mColumnWidth + mColumnGap)-0.5f);
                mColumnCount = mColumnCount > 0 ? mColumnCount :1;
                if (mColumnCount <= 0)
                    mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
                mColumnWidth =((mAvailableWidth + mColumnGap) / mColumnCount) - mColumnGap;
            } else if(Constants.Value.AUTO != mColumnWidth && Constants.Value.AUTO != mColumnCount){
                int columnCount = Math.round((mAvailableWidth + mColumnGap) / (mColumnWidth + mColumnGap)-0.5f);
                mColumnCount = columnCount > mColumnCount ? mColumnCount :columnCount;
                if (mColumnCount <= 0)
                    mColumnCount = Constants.Value.COLUMN_COUNT_NORMAL;
                mColumnWidth= ((mAvailableWidth + mColumnGap) / mColumnCount) - mColumnGap;
            }
            mIsPreCalculateCellWidth = true;
            if(WXEnvironment.isApkDebugable()) {
                WXLogUtils.d("preCalculateCellWidth mColumnGap :" + mColumnGap + " mColumnWidth:" + mColumnWidth + " mColumnCount:" + mColumnCount);
            }
        }
    }
 
Example 3
Source File: WXGesture.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Get event location in Screen's coordinate, e.g. root(global) coordinate.
 * @param eventX {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @param eventY {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @return the eventLocation in screen's coordinate
 * @see {@link #getEventLocInScreenCoordinate(MotionEvent, int, int)}
 */
@NonNull
private PointF getEventLocInScreenCoordinate(float eventX, float eventY) {
  globalRect.set(0, 0, 0, 0);
  globalOffset.set(0, 0);
  globalEventOffset.set((int) eventX, (int) eventY);
  component.getRealView().getGlobalVisibleRect(globalRect, globalOffset);
  globalEventOffset.offset(globalOffset.x, globalOffset.y);
  return new PointF(WXViewUtils.getWebPxByWidth(globalEventOffset.x,component.getInstance().getInstanceViewPortWidth()),
                    WXViewUtils.getWebPxByWidth(globalEventOffset.y,component.getInstance().getInstanceViewPortWidth()));
}
 
Example 4
Source File: WXGesture.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Get event's location in Document's (Page) coordinate.
 * @param eventX {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @param eventY {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @return the event location in page's coordinate.
 * @see {@link #getEventLocInPageCoordinate(MotionEvent, int, int)}
 */
@NonNull
private PointF getEventLocInPageCoordinate(float eventX, float eventY) {
  locEventOffset.set(eventX, eventY);
  locLeftTop.set(0, 0);
  component.computeVisiblePointInViewCoordinate(locLeftTop);
  locEventOffset.offset(locLeftTop.x, locLeftTop.y);
  return new PointF(WXViewUtils.getWebPxByWidth(locEventOffset.x,component.getInstance().getInstanceViewPortWidth()),
                    WXViewUtils.getWebPxByWidth(locEventOffset.y,component.getInstance().getInstanceViewPortWidth()));
}
 
Example 5
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 6
Source File: WXGesture.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Get event location in Screen's coordinate, e.g. root(global) coordinate.
 * @param eventX {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @param eventY {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @return the eventLocation in screen's coordinate
 * @see {@link #getEventLocInScreenCoordinate(MotionEvent, int, int)}
 */
@NonNull
private PointF getEventLocInScreenCoordinate(float eventX, float eventY) {
  globalRect.set(0, 0, 0, 0);
  globalOffset.set(0, 0);
  globalEventOffset.set((int) eventX, (int) eventY);
  component.getRealView().getGlobalVisibleRect(globalRect, globalOffset);
  globalEventOffset.offset(globalOffset.x, globalOffset.y);
  return new PointF(WXViewUtils.getWebPxByWidth(globalEventOffset.x,component.getInstance().getViewPortWidth()),
                    WXViewUtils.getWebPxByWidth(globalEventOffset.y,component.getInstance().getViewPortWidth()));
}
 
Example 7
Source File: WXGesture.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Get event's location in Document's (Page) coordinate.
 * @param eventX {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @param eventY {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @return the event location in page's coordinate.
 * @see {@link #getEventLocInPageCoordinate(MotionEvent, int, int)}
 */
@NonNull
private PointF getEventLocInPageCoordinate(float eventX, float eventY) {
  locEventOffset.set(eventX, eventY);
  locLeftTop.set(0, 0);
  component.computeVisiblePointInViewCoordinate(locLeftTop);
  locEventOffset.offset(locLeftTop.x, locLeftTop.y);
  return new PointF(WXViewUtils.getWebPxByWidth(locEventOffset.x,component.getInstance().getViewPortWidth()),
                    WXViewUtils.getWebPxByWidth(locEventOffset.y,component.getInstance().getViewPortWidth()));
}
 
Example 8
Source File: WXSDKInstance.java    From weex-uikit with MIT License 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,getViewPortWidth());
  float realHeight = WXViewUtils.getWebPxByWidth(height,getViewPortWidth());

  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 9
Source File: WXGesture.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Get event location in Screen's coordinate, e.g. root(global) coordinate.
 * @param eventX {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @param eventY {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @return the eventLocation in screen's coordinate
 * @see {@link #getEventLocInScreenCoordinate(MotionEvent, int, int)}
 */
@NonNull
private PointF getEventLocInScreenCoordinate(float eventX, float eventY) {
  globalRect.set(0, 0, 0, 0);
  globalOffset.set(0, 0);
  globalEventOffset.set((int) eventX, (int) eventY);
  component.getRealView().getGlobalVisibleRect(globalRect, globalOffset);
  globalEventOffset.offset(globalOffset.x, globalOffset.y);
  return new PointF(WXViewUtils.getWebPxByWidth(globalEventOffset.x),
                    WXViewUtils.getWebPxByWidth(globalEventOffset.y));
}
 
Example 10
Source File: WXGesture.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Get event's location in Document's (Page) coordinate.
 * @param eventX {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @param eventY {@link MotionEvent#getX()} or {@link MotionEvent#getHistoricalX(int, int)}
 * @return the event location in page's coordinate.
 * @see {@link #getEventLocInPageCoordinate(MotionEvent, int, int)}
 */
@NonNull
private PointF getEventLocInPageCoordinate(float eventX, float eventY) {
  locEventOffset.set(eventX, eventY);
  locLeftTop.set(0, 0);
  component.computeVisiblePointInViewCoordinate(locLeftTop);
  locEventOffset.offset(locLeftTop.x, locLeftTop.y);
  return new PointF(WXViewUtils.getWebPxByWidth(locEventOffset.x),
                    WXViewUtils.getWebPxByWidth(locEventOffset.y));
}
 
Example 11
Source File: GetComponentRectAction.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@NonNull
private float getWebPxValue(int value,int viewport) {
  return WXViewUtils.getWebPxByWidth(value, viewport);
}