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

The following examples show how to use com.taobao.weex.utils.WXViewUtils#dip2px() . 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: 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 2
Source File: WXBaseCircleIndicator.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Get attribute of xml
 */
private void getAttrs(Context context) {
  radius = WXViewUtils.dip2px(5);
  circlePadding = WXViewUtils.dip2px(5);
  pageColor = Color.parseColor("#ffffff");
  //		strokeWidth= WAViewUtils.dip2px((float)1.5);
  //		strokeColor = Color.parseColor("#FFDDDDDD");
  fillColor = Color.parseColor("#ffd545");
}
 
Example 3
Source File: SoftKeyboardDetector.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static boolean isKeyboardVisible(Activity activity) {
    Rect windowFrame = new Rect();
    View root = getActivityRoot(activity);

    if (root != null) {
        root.getWindowVisibleDisplayFrame(windowFrame);
        int heightDiff = root.getRootView().getHeight() - windowFrame.height();
        return heightDiff > WXViewUtils.dip2px(KEYBOARD_VISIBLE_THRESHOLD_DIP);
    }
    return false;
}
 
Example 4
Source File: WXBaseCircleIndicator.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Get attribute of xml
 */
private void getAttrs(Context context) {
  radius = WXViewUtils.dip2px(5);
  circlePadding = WXViewUtils.dip2px(5);
  pageColor = Color.parseColor("#ffffff");
  //		strokeWidth= WAViewUtils.dip2px((float)1.5);
  //		strokeColor = Color.parseColor("#FFDDDDDD");
  fillColor = Color.parseColor("#ffd545");
}
 
Example 5
Source File: WXBaseCircleIndicator.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Get attribute of xml
 */
private void getAttrs(Context context) {
  radius = WXViewUtils.dip2px(5);
  circlePadding = WXViewUtils.dip2px(5);
  pageColor = Color.parseColor("#ffffff");
  //		strokeWidth= WAViewUtils.dip2px((float)1.5);
  //		strokeColor = Color.parseColor("#FFDDDDDD");
  fillColor = Color.parseColor("#ffd545");
}
 
Example 6
Source File: SoftKeyboardDetector.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public static Unregister registerKeyboardEventListener(Activity activity, final OnKeyboardEventListener listener) {
    if (activity == null || listener == null) {
        WXLogUtils.e("Activity or listener is null!");
        return null;
    }

    if (activity.getWindow() != null) {
        WindowManager.LayoutParams attributes = activity.getWindow().getAttributes();
        if (attributes != null) {
            int softInputMode = attributes.softInputMode;
            if (softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING
                    || softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) {
                WXLogUtils.e("SoftKeyboard detector can't work with softInputMode is SOFT_INPUT_ADJUST_NOTHING or SOFT_INPUT_ADJUST_PAN");
                return null;
            }
        }
    }

    final View activityRoot = getActivityRoot(activity);

    if (activityRoot == null) {
        WXLogUtils.e("Activity root is null!");
        return null;
    }

    final ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {

        private final Rect visibleFrame = new Rect();
        private final int threshold = WXViewUtils.dip2px(KEYBOARD_VISIBLE_THRESHOLD_DIP);
        private boolean wasKeyboardOpened = false;

        @Override
        public void onGlobalLayout() {
            activityRoot.getWindowVisibleDisplayFrame(visibleFrame);
            int heightDiff = activityRoot.getRootView().getHeight() - visibleFrame.height();
            boolean isOpen = heightDiff > threshold;
            if (isOpen == wasKeyboardOpened) {
                return;
            }

            wasKeyboardOpened = isOpen;
            listener.onKeyboardEvent(isOpen);
        }
    };

    activityRoot.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
    return new DefaultUnRegister(activity, layoutListener);
}