com.taobao.weex.utils.WXResourceUtils Java Examples

The following examples show how to use com.taobao.weex.utils.WXResourceUtils. 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: AbstractEditComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Process view after created.
 *
 * @param editText
 */
protected void appleStyleAfterCreated(WXEditText editText) {
  String alignStr = (String) getDomObject().getStyles().get(Constants.Name.TEXT_ALIGN);
  int textAlign = getTextAlign(alignStr);
  if (textAlign <= 0) {
    textAlign = Gravity.START;
  }
  editText.setGravity(textAlign | getVerticalGravity());
  int colorInt = WXResourceUtils.getColor("#999999");
  if (colorInt != Integer.MIN_VALUE) {
    editText.setHintTextColor(colorInt);
  }

  editText.setTextSize(TypedValue.COMPLEX_UNIT_PX, WXStyle.getFontSize(getDomObject().getStyles(),getInstance().getViewPortWidth()));
  editText.setText(getDomObject().getAttrs().optString(Constants.Name.VALUE));
}
 
Example #2
Source File: WXParallax.java    From incubator-weex-playground with Apache License 2.0 6 votes vote down vote up
private void initBackgroundColor(Object obj) {
  if (obj == null)
    return;

  if (obj instanceof JSONObject) {
    mBackgroundColor = new BackgroundColorCreator();
    JSONObject object = (JSONObject) obj;

    JSONArray in = object.getJSONArray("in");
    mBackgroundColor.input = new int[in.size()];
    for (int i = 0; i < in.size(); i++) {
      mBackgroundColor.input[i] = in.getInteger(i);
    }

    JSONArray out = object.getJSONArray("out");
    mBackgroundColor.output = new int[out.size()];
    for (int i = 0; i < out.size(); i++) {
      String colorStr = out.getString(i);
      mBackgroundColor.output[i] = WXResourceUtils.getColor(colorStr);
    }
  }
}
 
Example #3
Source File: WXInput.java    From weex with Apache License 2.0 6 votes vote down vote up
@Override
protected void initView() {
  super.initView();
  WXEditText inputView = new WXEditText(mContext);
  mTextAlign = Gravity.LEFT;
  int colorInt = WXResourceUtils.getColor("#999999");
  if (colorInt != Integer.MIN_VALUE) {
    inputView.setHintTextColor(colorInt);
  }

  inputView.setTextSize(TypedValue.COMPLEX_UNIT_PX, WXStyle.getFontSize(mDomObj.style));
  inputView.setSingleLine();//default use single line , same to ios
  inputView.setMovementMethod(null);

  mHost = inputView;
}
 
Example #4
Source File: BaseBounceView.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param refresh should be {@link WXRefreshView}
 */
public void setHeaderView(WXComponent refresh) {
    setRefreshEnable(true);
    if (swipeLayout != null) {
        WXRefreshView refreshView = swipeLayout.getHeaderView();
        if (refreshView != null) {
            ImmutableDomObject immutableDomObject = refresh.getDomObject();
            if (immutableDomObject != null) {
                int refreshHeight = (int) immutableDomObject.getLayoutHeight();
                swipeLayout.setRefreshHeight(refreshHeight);
                String colorStr = (String) immutableDomObject.getStyles().get(Constants.Name.BACKGROUND_COLOR);
                String bgColor = WXUtils.getString(colorStr, null);
                if (bgColor != null) {
                    if (!TextUtils.isEmpty(bgColor)) {
                        int colorInt = WXResourceUtils.getColor(bgColor);
                        if (!(colorInt == Color.TRANSPARENT)) {
                            swipeLayout.setRefreshBgColor(colorInt);
                        }
                    }
                }
                refreshView.setRefreshView(refresh.getHostView());
            }
        }
    }
}
 
Example #5
Source File: BaseBounceView.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param loading should be {@link WXRefreshView}
 */
public void setFooterView(WXComponent loading) {
    setLoadmoreEnable(true);
    if (swipeLayout != null) {
        WXRefreshView refreshView = swipeLayout.getFooterView();
        if (refreshView != null) {
            ImmutableDomObject immutableDomObject = loading.getDomObject();
            if (immutableDomObject != null) {
                int loadingHeight = (int) immutableDomObject.getLayoutHeight();
                swipeLayout.setLoadingHeight(loadingHeight);
                String colorStr = (String) immutableDomObject.getStyles().get(Constants.Name.BACKGROUND_COLOR);
                String bgColor = WXUtils.getString(colorStr, null);
                if (bgColor != null) {
                    if (!TextUtils.isEmpty(bgColor)) {
                        int colorInt = WXResourceUtils.getColor(bgColor);
                        if (!(colorInt == Color.TRANSPARENT)) {
                            swipeLayout.setLoadingBgColor(colorInt);
                        }
                    }
                }
                refreshView.setRefreshView(loading.getHostView());
            }
        }
    }
}
 
Example #6
Source File: BaseBounceView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 *
 * @param loading should be {@link WXRefreshView}
 */
public void setFooterView(WXComponent loading) {
    setLoadmoreEnable(true);
    if (swipeLayout != null) {
        if (swipeLayout.getFooterView() != null) {
            swipeLayout.setLoadingHeight((int) loading.getDomObject().getLayoutHeight());

            String colorStr = (String) loading.getDomObject().getStyles().get(Constants.Name.BACKGROUND_COLOR);
            String bgColor = WXUtils.getString(colorStr, null);

            if (bgColor != null) {
                if (!TextUtils.isEmpty(bgColor)) {
                    int colorInt = WXResourceUtils.getColor(bgColor);
                    if (!(colorInt == Color.TRANSPARENT)) {
                        swipeLayout.setLoadingBgColor(colorInt);
                    }
                }
            }
            swipeLayout.getFooterView().setRefreshView(loading.getHostView());
        }
    }
}
 
Example #7
Source File: BaseBounceView.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 *
 * @param refresh should be {@link WXRefreshView}
 */
public void setHeaderView(WXComponent refresh) {
    setRefreshEnable(true);
    if (swipeLayout != null) {
        if (swipeLayout.getHeaderView() != null) {
            swipeLayout.setRefreshHeight((int) refresh.getDomObject().getLayoutHeight());

            String colorStr = (String) refresh.getDomObject().getStyles().get(Constants.Name.BACKGROUND_COLOR);
            String bgColor = WXUtils.getString(colorStr, null);

            if (bgColor != null) {
                if (!TextUtils.isEmpty(bgColor)) {
                    int colorInt = WXResourceUtils.getColor(bgColor);
                    if (!(colorInt == Color.TRANSPARENT)) {
                        swipeLayout.setRefreshBgColor(colorInt);
                    }
                }
            }
            swipeLayout.getHeaderView().setRefreshView(refresh.getHostView());
        }
    }
}
 
Example #8
Source File: WXComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
public void setBorderColor(String key, String borderColor) {
  if (!TextUtils.isEmpty(borderColor)) {
    int colorInt = WXResourceUtils.getColor(borderColor);
    if (colorInt != Integer.MIN_VALUE) {
      switch (key) {
        case Constants.Name.BORDER_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.ALL, colorInt);
          break;
        case Constants.Name.BORDER_TOP_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.TOP, colorInt);
          break;
        case Constants.Name.BORDER_RIGHT_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.RIGHT, colorInt);
          break;
        case Constants.Name.BORDER_BOTTOM_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.BOTTOM, colorInt);
          break;
        case Constants.Name.BORDER_LEFT_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.LEFT, colorInt);
          break;
      }
    }
  }
}
 
Example #9
Source File: BorderDrawableTest.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetOpacity() throws Exception {
  BorderDrawable opaque = new BorderDrawable();
  opaque.setColor(Color.GREEN);
  assertThat(opaque.getOpacity(), is(PixelFormat.OPAQUE));

  BorderDrawable transparent = new BorderDrawable();
  transparent.setColor(WXResourceUtils.getColor("#00ff0000"));
  assertThat(transparent.getOpacity(), is(PixelFormat.TRANSPARENT));

  BorderDrawable half = new BorderDrawable();
  half.setColor(WXResourceUtils.getColor("#aaff0000"));
  assertThat(half.getOpacity(), is(PixelFormat.TRANSLUCENT));

  BorderDrawable changeAlpha = new BorderDrawable();
  changeAlpha.setColor(Color.RED);
  changeAlpha.setAlpha(15);
  assertThat(changeAlpha.getOpacity(), is(PixelFormat.TRANSLUCENT));
}
 
Example #10
Source File: BorderDrawableTest.java    From weex-uikit with MIT License 6 votes vote down vote up
@Test
public void testGetOpacity() throws Exception {
  BorderDrawable opaque = new BorderDrawable();
  opaque.setColor(Color.GREEN);
  assertThat(opaque.getOpacity(), is(PixelFormat.OPAQUE));

  BorderDrawable transparent = new BorderDrawable();
  transparent.setColor(WXResourceUtils.getColor("#00ff0000"));
  assertThat(transparent.getOpacity(), is(PixelFormat.TRANSPARENT));

  BorderDrawable half = new BorderDrawable();
  half.setColor(WXResourceUtils.getColor("#aaff0000"));
  assertThat(half.getOpacity(), is(PixelFormat.TRANSLUCENT));

  BorderDrawable changeAlpha = new BorderDrawable();
  changeAlpha.setColor(Color.RED);
  changeAlpha.setAlpha(15);
  assertThat(changeAlpha.getOpacity(), is(PixelFormat.TRANSLUCENT));
}
 
Example #11
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
public void setBorderColor(String key, String borderColor) {
  if (!TextUtils.isEmpty(borderColor)) {
    int colorInt = WXResourceUtils.getColor(borderColor);
    if (colorInt != Integer.MIN_VALUE) {
      switch (key) {
        case Constants.Name.BORDER_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.ALL, colorInt);
          break;
        case Constants.Name.BORDER_TOP_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.TOP, colorInt);
          break;
        case Constants.Name.BORDER_RIGHT_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.RIGHT, colorInt);
          break;
        case Constants.Name.BORDER_BOTTOM_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.BOTTOM, colorInt);
          break;
        case Constants.Name.BORDER_LEFT_COLOR:
          getOrCreateBorder().setBorderColor(Spacing.LEFT, colorInt);
          break;
      }
    }
  }
}
 
Example #12
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 #13
Source File: AbstractEditComponent.java    From weex-uikit with MIT License 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.COLOR)
public void setColor(String color) {
  if (getHostView() != null && !TextUtils.isEmpty(color)) {
    int colorInt = WXResourceUtils.getColor(color);
    if (colorInt != Integer.MIN_VALUE) {
      getHostView().setTextColor(colorInt);
    }
  }
}
 
Example #14
Source File: WXComponent.java    From weex-uikit with MIT License 5 votes vote down vote up
public void setBackgroundColor(String color) {
  if (!TextUtils.isEmpty(color)&& mHost!=null) {
    int colorInt = WXResourceUtils.getColor(color);
    if (!(colorInt == Color.TRANSPARENT && mBackgroundDrawable == null)){
        getOrCreateBorder().setColor(colorInt);
    }
  }
}
 
Example #15
Source File: WXLoadingIndicator.java    From weex-uikit with MIT License 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.COLOR)
public void setColor(String color) {
    if (color != null && !color.equals("")) {
        int parseColor = WXResourceUtils.getColor(color, Color.RED);
        getHostView().setColorSchemeColors(parseColor);
    }
}
 
Example #16
Source File: WXTextDomObject.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Record the property according to the given style
 * @param style the give style.
 */
private void updateStyleImp(Map<String, Object> style) {
  if (style != null) {
    if (style.containsKey(WXDomPropConstant.WX_LINES)) {
      int lines = WXStyle.getLines(style);
      if (lines > 0) {
        mNumberOfLines = lines;
      }
    }
    if (style.containsKey(WXDomPropConstant.WX_FONTSIZE)) {
      mFontSize = WXStyle.getFontSize(style);
    }
    if (style.containsKey(WXDomPropConstant.WX_FONTWEIGHT)) {
      mFontWeight = WXStyle.getFontWeight(style);
    }
    if (style.containsKey(WXDomPropConstant.WX_FONTSTYLE)) {
      mFontStyle = WXStyle.getFontStyle(style);
    }
    if (style.containsKey(WXDomPropConstant.WX_COLOR)) {
      mColor = WXResourceUtils.getColor(WXStyle.getTextColor(style));
      mIsColorSet = mColor != Integer.MIN_VALUE;
    }
    if (style.containsKey(WXDomPropConstant.WX_TEXTDECORATION)) {
      mTextDecoration = WXStyle.getTextDecoration(style);
    }
    if (style.containsKey(WXDomPropConstant.WX_FONTFAMILY)) {
      mFontFamily = WXStyle.getFontFamily(style);
    }
    mAlignment = WXStyle.getTextAlignment(style);
    textOverflow = WXStyle.getTextOverflow(style);
    int lineHeight=WXStyle.getLineHeight(style);
    if(lineHeight!=UNSET)
      mLineHeight=lineHeight;
  }
}
 
Example #17
Source File: WXIndicator.java    From weex-uikit with MIT License 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.ITEM_COLOR)
public void setItemColor(String itemColor) {
  if (!TextUtils.isEmpty(itemColor)) {
    int colorInt = WXResourceUtils.getColor(itemColor);
    if (colorInt != Integer.MIN_VALUE) {
      getHostView().setPageColor(colorInt);
      getHostView().forceLayout();
      getHostView().requestLayout();
    }
  }
}
 
Example #18
Source File: WXImage.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
@WXComponentProp(name = WXDomPropConstant.WX_BACKGROUNDCOLOR)
public void setBackgroundColor(String color) {
    if (!TextUtils.isEmpty(color)) {
        int colorInt = WXResourceUtils.getColor(color);
        if (colorInt != Integer.MIN_VALUE) {
            mHost.setBackgroundColor(colorInt);
        }
    }
}
 
Example #19
Source File: WXIndicator.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = "itemColor")
public void setItemColor(String itemColor) {
  if (!TextUtils.isEmpty(itemColor)) {
    int colorInt = WXResourceUtils.getColor(itemColor);
    if (colorInt != Integer.MIN_VALUE) {
      getView().setPageColor(colorInt);
      getView().forceLayout();
      getView().requestLayout();
    }
  }
}
 
Example #20
Source File: WXIndicator.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = "itemSelectedColor")
public void setItemSelectedColor(String itemSelectedColor) {
  if (!TextUtils.isEmpty(itemSelectedColor)) {
    int colorInt = WXResourceUtils.getColor(itemSelectedColor);
    if (colorInt != Integer.MIN_VALUE) {
      getView().setFillColor(colorInt);
      getView().forceLayout();
      getView().requestLayout();
    }
  }
}
 
Example #21
Source File: WXComponent.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = WXDomPropConstant.WX_BACKGROUNDCOLOR)
public void setBackgroundColor(String color) {
  if (!TextUtils.isEmpty(color)) {
    int colorInt = WXResourceUtils.getColor(color);
    if (colorInt != Integer.MIN_VALUE) {
      getOrCreateBorder().setBackgroundColor(colorInt);
    }
  }
}
 
Example #22
Source File: WXComponent.java    From weex with Apache License 2.0 5 votes vote down vote up
private void setBorderColor(int position, String borderColor) {
  if (!TextUtils.isEmpty(borderColor)) {
    int colorInt = WXResourceUtils.getColor(borderColor);
    if (colorInt != Integer.MIN_VALUE) {
      getOrCreateBorder().setBorderColor(position, colorInt);
    }
  }
}
 
Example #23
Source File: WXInput.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = WXDomPropConstant.WX_INPUT_PLACEHOLDER_COLOR)
public void setPlaceholderColor(String color) {
  if (mHost != null && !TextUtils.isEmpty(color)) {
    int colorInt = WXResourceUtils.getColor(color);
    if (colorInt != Integer.MIN_VALUE) {
      ((WXEditText) mHost).setHintTextColor(colorInt);
    }
  }
}
 
Example #24
Source File: WXInput.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = WXDomPropConstant.WX_COLOR)
public void setColor(String color) {
  if (mHost != null && !TextUtils.isEmpty(color)) {
    int colorInt = WXResourceUtils.getColor(color);
    if (colorInt != Integer.MIN_VALUE) {
      ((WXEditText) mHost).setTextColor(colorInt);
    }
  }
}
 
Example #25
Source File: WXLoadingIndicator.java    From weex with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = WXDomPropConstant.WX_COLOR)
public void setColor(String color) {
    if (color != null && !color.equals("")) {
        int parseColor = WXResourceUtils.getColor(color, Color.RED);
        circleProgressBar.setColorSchemeColors(parseColor);
    }
}
 
Example #26
Source File: WXComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void setBackgroundColor(String color) {
  if (!TextUtils.isEmpty(color)&& mHost!=null) {
    int colorInt = WXResourceUtils.getColor(color);
    if (!(colorInt == Color.TRANSPARENT && mBackgroundDrawable == null)){
        getOrCreateBorder().setColor(colorInt);
    }
  }
}
 
Example #27
Source File: WXPickersModule.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private int getColor(Map<String, Object> options, String key, int defValue) {
    Object value = getOption(options, key, null);
    if (value == null) {
        return defValue;
    }
    return WXResourceUtils.getColor(value.toString(), defValue);
}
 
Example #28
Source File: WXTextDomObject.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Record the property according to the given style
 * @param style the give style.
 */
private void updateStyleImp(Map<String, Object> style) {
  if (style != null) {
    if (style.containsKey(Constants.Name.LINES)) {
      int lines = WXStyle.getLines(style);
      mNumberOfLines = lines > 0 ? lines : UNSET;
    }
    if (style.containsKey(Constants.Name.FONT_SIZE)) {
      mFontSize = WXStyle.getFontSize(style,getViewPortWidth());
    }
    if (style.containsKey(Constants.Name.FONT_WEIGHT)) {
      mFontWeight = WXStyle.getFontWeight(style);
    }
    if (style.containsKey(Constants.Name.FONT_STYLE)) {
      mFontStyle = WXStyle.getFontStyle(style);
    }
    if (style.containsKey(Constants.Name.COLOR)) {
      mColor = WXResourceUtils.getColor(WXStyle.getTextColor(style));
      mIsColorSet = mColor != Integer.MIN_VALUE;
    }
    if (style.containsKey(Constants.Name.TEXT_DECORATION)) {
      mTextDecoration = WXStyle.getTextDecoration(style);
    }
    if (style.containsKey(Constants.Name.FONT_FAMILY)) {
      mFontFamily = WXStyle.getFontFamily(style);
    }
    mAlignment = WXStyle.getTextAlignment(style);
    textOverflow = WXStyle.getTextOverflow(style);
    int lineHeight = WXStyle.getLineHeight(style,getViewPortWidth());
    if (lineHeight != UNSET) {
      mLineHeight = lineHeight;
    }
  }
}
 
Example #29
Source File: WXVideoView.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
  setBackgroundColor(WXResourceUtils.getColor("#ee000000"));
  mProgressBar = new ProgressBar(context);
  FrameLayout.LayoutParams pLayoutParams =
      new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
          FrameLayout.LayoutParams.WRAP_CONTENT);
  mProgressBar.setLayoutParams(pLayoutParams);
  pLayoutParams.gravity = Gravity.CENTER;
  addView(mProgressBar);

  getViewTreeObserver().addOnGlobalLayoutListener(this);
}
 
Example #30
Source File: WXIndicator.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@WXComponentProp(name = Constants.Name.ITEM_COLOR)
public void setItemColor(String itemColor) {
  if (!TextUtils.isEmpty(itemColor)) {
    int colorInt = WXResourceUtils.getColor(itemColor);
    if (colorInt != Integer.MIN_VALUE) {
      getHostView().setPageColor(colorInt);
      getHostView().forceLayout();
      getHostView().requestLayout();
    }
  }
}