Search in sources :

Example 1 with WXStyle

use of com.taobao.weex.dom.WXStyle in project WeexErosFramework by bmfe.

the class BMPop method getAnimationHeight.

private void getAnimationHeight() {
    WXDomObject wxDomObject = (WXDomObject) getDomObject();
    if (wxDomObject == null)
        return;
    WXStyle wxStyle = wxDomObject.getStyles();
    Object object = wxStyle.get("height");
    if (object == null)
        return;
    mHeight = Integer.valueOf(object.toString());
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) WXDomObject(com.taobao.weex.dom.WXDomObject) WXDomObject(com.taobao.weex.dom.WXDomObject)

Example 2 with WXStyle

use of com.taobao.weex.dom.WXStyle in project WeexErosFramework by bmfe.

the class BMRich method update.

private void update() {
    WXStyle styles = getDomObject().getStyles();
    if (styles == null) {
        styles = new WXStyle();
    }
    // 如果此时style为empty不会触发更新 我们在这里加入一个占位符保证style不为empty
    if (styles.isEmpty()) {
        styles.put("placeholder", "bm");
    }
    updateStyle(styles);
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle)

Example 3 with WXStyle

use of com.taobao.weex.dom.WXStyle in project WeexErosFramework by bmfe.

the class BMWXText method updateFontSize.

private void updateFontSize() {
    if (mChangeFontSize == null) {
        return;
    }
    WXStyle styles = null;
    WXAttr attrs = null;
    if (getDomObject() != null) {
        styles = getDomObject().getStyles();
        attrs = getDomObject().getAttrs();
        if ((styles != null && "iconfont".equals(styles.get("fontFamily"))) || (attrs != null && attrs.get("changeFont") != null && !Boolean.valueOf((String) attrs.get("changeFont")))) {
            return;
        }
    }
    float scale = 0;
    // 获取fontScale字段
    if (attrs != null && attrs.get("fontScale") != null) {
        float fontScale = Float.valueOf((String) attrs.get("fontScale"));
        mCurrentScale = fontScale / mCurrentScale;
    }
    if (mChangeFontSize.equals(mCurrentFontSize) && mCurrentScale == 1) {
        return;
    }
    // 获取scale字段 在标准字体下不产生变化
    if (attrs != null && attrs.get("scale") != null && !(scale > 0)) {
        scale = Float.valueOf((String) attrs.get("scale"));
        float change = getFixedEnlarge(mChangeFontSize, scale);
        float current = getFixedEnlarge(mCurrentFontSize, scale);
        scale = change / current;
    }
    // 根据全局字体配置设置字体大小
    if (!(scale > 0)) {
        float current = getEnlarge(mCurrentFontSize);
        float change = getEnlarge(mChangeFontSize);
        scale = change / current * mCurrentScale;
    }
    if (getDomObject() != null && getDomObject().getStyles() != null) {
        WXStyle wxStyle = getDomObject().getStyles();
        Object object = wxStyle.get("fontSize");
        if (object instanceof Integer) {
            int fontSize = (int) object;
            int changeFontSize = (int) (fontSize * (scale));
            wxStyle.put("fontSize", changeFontSize);
        }
        // 设置lineHeight
        Object lineHeight = wxStyle.get("lineHeight");
        if (lineHeight instanceof Integer) {
            int target = (int) lineHeight;
            wxStyle.put("lineHeight", (int) (target * scale));
        }
        updateStyle(wxStyle);
    }
    mCurrentFontSize = mChangeFontSize;
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) WXDomObject(com.taobao.weex.dom.WXDomObject) WXAttr(com.taobao.weex.dom.WXAttr)

Example 4 with WXStyle

use of com.taobao.weex.dom.WXStyle in project incubator-weex by apache.

the class WXComponent method updateBoxShadow.

protected void updateBoxShadow() {
    if (!BoxShadowUtil.isBoxShadowEnabled()) {
        WXLogUtils.w("BoxShadow", "box-shadow disabled");
        return;
    }
    if (getDomObject() != null && getDomObject().getStyles() != null) {
        Object boxShadow = getDomObject().getStyles().get(Constants.Name.BOX_SHADOW);
        Object shadowQuality = getDomObject().getAttrs().get(Constants.Name.SHADOW_QUALITY);
        if (boxShadow == null) {
            return;
        }
        View target = mHost;
        if (this instanceof WXVContainer) {
            target = ((WXVContainer) this).getBoxShadowHost(false);
        }
        if (target == null) {
            return;
        }
        float quality = WXUtils.getFloat(shadowQuality, 0.5f);
        int viewPort = getInstance().getInstanceViewPortWidth();
        String token = new StringBuilder(boxShadow.toString()).append(" / [").append(target.getMeasuredWidth()).append(",").append(target.getMeasuredHeight()).append("] / ").append(quality).toString();
        if (mLastBoxShadowId != null && mLastBoxShadowId.equals(token)) {
            WXLogUtils.d("BoxShadow", "box-shadow style was not modified. " + token);
            return;
        }
        float[] radii = new float[] { 0, 0, 0, 0, 0, 0, 0, 0 };
        WXStyle style = getDomObject().getStyles();
        if (style != null) {
            float tl = WXUtils.getFloat(style.get(Constants.Name.BORDER_TOP_LEFT_RADIUS), 0f);
            radii[0] = tl;
            radii[1] = tl;
            float tr = WXUtils.getFloat(style.get(Constants.Name.BORDER_TOP_RIGHT_RADIUS), 0f);
            radii[2] = tr;
            radii[3] = tr;
            float br = WXUtils.getFloat(style.get(Constants.Name.BORDER_BOTTOM_RIGHT_RADIUS), 0f);
            radii[4] = br;
            radii[5] = br;
            float bl = WXUtils.getFloat(style.get(Constants.Name.BORDER_BOTTOM_LEFT_RADIUS), 0f);
            radii[6] = bl;
            radii[7] = bl;
            if (style.containsKey(Constants.Name.BORDER_RADIUS)) {
                float radius = WXUtils.getFloat(style.get(Constants.Name.BORDER_RADIUS), 0f);
                for (int i = 0; i < radii.length; i++) {
                    radii[i] = radius;
                }
            }
        }
        BoxShadowUtil.setBoxShadow(target, boxShadow.toString(), radii, viewPort, quality);
        mLastBoxShadowId = token;
    } else {
        WXLogUtils.w("Can not resolve styles");
    }
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) IWXObject(com.taobao.weex.common.IWXObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) View(android.view.View) Point(android.graphics.Point)

Example 5 with WXStyle

use of com.taobao.weex.dom.WXStyle in project incubator-weex by apache.

the class WXComponent method setPseudoClassStatus.

/**
 * @param clzName like ':active' or ':active:enabled'
 * @param status
 */
protected void setPseudoClassStatus(String clzName, boolean status) {
    WXStyle styles = getDomObject().getStyles();
    Map<String, Map<String, Object>> pesudoStyles = styles.getPesudoStyles();
    if (pesudoStyles == null || pesudoStyles.size() == 0) {
        return;
    }
    Map<String, Object> resultStyles = mPesudoStatus.updateStatusAndGetUpdateStyles(clzName, status, pesudoStyles, styles.getPesudoResetStyles());
    if (resultStyles != null && isRippleEnabled()) {
        resultStyles.remove(Constants.Name.BACKGROUND_COLOR);
        if (resultStyles.isEmpty()) {
            WXLogUtils.d("PseudoClass", "skip empty pseudo styles");
            return;
        }
    }
    updateStyleByPesudo(resultStyles);
}
Also used : WXStyle(com.taobao.weex.dom.WXStyle) WXDomObject(com.taobao.weex.dom.WXDomObject) JSONObject(com.alibaba.fastjson.JSONObject) IWXObject(com.taobao.weex.common.IWXObject) ImmutableDomObject(com.taobao.weex.dom.ImmutableDomObject) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

WXStyle (com.taobao.weex.dom.WXStyle)13 WXDomObject (com.taobao.weex.dom.WXDomObject)9 JSONObject (com.alibaba.fastjson.JSONObject)6 WXAttr (com.taobao.weex.dom.WXAttr)5 ImmutableDomObject (com.taobao.weex.dom.ImmutableDomObject)4 IWXObject (com.taobao.weex.common.IWXObject)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Point (android.graphics.Point)1 ArrayMap (android.support.v4.util.ArrayMap)1 View (android.view.View)1 WXEvent (com.taobao.weex.dom.WXEvent)1 Spacing (com.taobao.weex.dom.flex.Spacing)1 ArrayStack (com.taobao.weex.el.parse.ArrayStack)1 WXImage (com.taobao.weex.ui.component.WXImage)1