Java Code Examples for com.libra.Utils#dp2px()

The following examples show how to use com.libra.Utils#dp2px() . 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: LineBase.java    From Virtualview-Android with MIT License 6 votes vote down vote up
@Override
protected boolean setAttribute(int key, float value) {
    boolean ret = true;
    switch (key) {
        case StringBase.STR_ID_paintWidth:
            mLineWidth = Utils.dp2px(value);
            if (mLineWidth <= 0) {
                mLineWidth = 1;
            }
            break;

        default:
            ret = false;
            break;
    }

    return ret;
}
 
Example 2
Source File: GridLayout.java    From Virtualview-Android with MIT License 6 votes vote down vote up
@Override
protected boolean setAttribute(int key, float value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_itemHeight:
                mItemHeight = Utils.dp2px(Math.round(value));
                break;
            case StringBase.STR_ID_itemHorizontalMargin:
                mItemHorizontalMargin = Utils.dp2px(value);
                break;
            case StringBase.STR_ID_itemVerticalMargin:
                mItemVerticalMargin = Utils.dp2px(value);
                break;
            default:
                ret = false;
                break;
        }
    }

    return ret;
}
 
Example 3
Source File: VirtualProgress.java    From Virtualview-Android with MIT License 6 votes vote down vote up
@Override
protected boolean setAttribute(int key, float value) {
    boolean ret = super.setAttribute(key, value);
    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_initValue:
                mInitPos = Utils.dp2px(value);
                break;

            default:
                ret = false;
        }
    }
    return ret;
}
 
Example 4
Source File: TextBase.java    From Virtualview-Android with MIT License 6 votes vote down vote up
@Override
protected boolean setAttribute(int key, float value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_textSize:
                mTextSize = Utils.dp2px(Math.round(value));
                break;

            default:
                ret = false;
        }
    }

    return ret;
}
 
Example 5
Source File: TextBase.java    From Virtualview-Android with MIT License 5 votes vote down vote up
@Override
protected boolean setAttribute(int key, int value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_textSize:
                mTextSize = Utils.dp2px(value);
                break;

            case StringBase.STR_ID_textColor:
                mTextColor = value;
                break;

            case StringBase.STR_ID_textStyle:
                mTextStyle = value;
                break;

            case StringBase.STR_ID_lines:
                mLines = value;
                break;

            case StringBase.STR_ID_ellipsize:
                mEllipsize = value;
                break;

            default:
                ret = false;
                break;
        }
    }

    return ret;
}
 
Example 6
Source File: GridLayout.java    From Virtualview-Android with MIT License 5 votes vote down vote up
@Override
protected boolean setAttribute(int key, int value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_colCount:
                mColCount = value;
                break;
            case StringBase.STR_ID_itemHeight:
                mItemHeight = Utils.dp2px(value);
                break;
            case StringBase.STR_ID_itemHorizontalMargin:
                mItemHorizontalMargin = Utils.dp2px(value);
                break;
            case StringBase.STR_ID_itemVerticalMargin:
                mItemVerticalMargin = Utils.dp2px(value);
                break;
            default:
                ret = false;
                break;
        }
    }

    return ret;
}
 
Example 7
Source File: VirtualProgress.java    From Virtualview-Android with MIT License 5 votes vote down vote up
@Override
protected boolean setAttribute(int key, int value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_type:
                mType = value;
                break;

            case StringBase.STR_ID_initValue:
                mInitPos = Utils.dp2px(value);
                break;

            case StringBase.STR_ID_color:
                mProgressColor = value;
                mPaint.setColor(mProgressColor);
                break;

            default:
                ret = false;
        }
    }

    return ret;
}
 
Example 8
Source File: NativeText.java    From Virtualview-Android with MIT License 5 votes vote down vote up
@Override
protected boolean setAttribute(int key, float value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_supportHTMLStyle:
                mSupportHtmlStyle = (value > 0) ? true : false;
                break;

            case StringBase.STR_ID_lineSpaceMultiplier:
                mLineSpaceMultipiler = value;
                break;

            case StringBase.STR_ID_lineSpaceExtra:
                mLineSpaceExtra = value;
                break;
            case StringBase.STR_ID_lineHeight:
                mLineHeight = Utils.dp2px(value);
                break;
            default:
                ret = false;
                break;
        }
    }

    return ret;
}
 
Example 9
Source File: NativeText.java    From Virtualview-Android with MIT License 5 votes vote down vote up
@Override
protected boolean setAttribute(int key, int value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_supportHTMLStyle:
                mSupportHtmlStyle = (value > 0) ? true : false;
                break;

            case StringBase.STR_ID_lineSpaceMultiplier:
                mLineSpaceMultipiler = value;
                break;

            case StringBase.STR_ID_lineSpaceExtra:
                mLineSpaceExtra = value;
                break;

            case StringBase.STR_ID_maxLines:
                mNative.setMaxLines(value);
                break;
            case StringBase.STR_ID_lineHeight:
                mLineHeight = Utils.dp2px(value);
                break;
            default:
                ret = false;
                break;
        }
    }

    return ret;
}
 
Example 10
Source File: Scroller.java    From Virtualview-Android with MIT License 5 votes vote down vote up
@Override
protected boolean setAttribute(int key, float value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_span:
                mSpan = Utils.dp2px(value);
                break;

            case StringBase.STR_ID_lineSpace:
                mLineSpace = Utils.dp2px(value);
                break;
            case StringBase.STR_ID_firstSpace:
                mFirstSpace = Utils.dp2px(value);
                break;
            case StringBase.STR_ID_lastSpace:
                mLastSpace = Utils.dp2px(value);
                break;
            default:
                ret = false;
        }
    }

    return ret;
}
 
Example 11
Source File: TextBase.java    From Virtualview-Android with MIT License 5 votes vote down vote up
public TextBase(VafContext context, ViewCache viewCache) {
    super(context, viewCache);

    mLines = -1;
    mEllipsize = -1;
    mText = "";
    mTextColor = Color.BLACK;
    mTextSize = Utils.dp2px(20);
    mDataTag = "title";
    mTextStyle = Typeface.NORMAL;
}
 
Example 12
Source File: VirtualGraph.java    From Virtualview-Android with MIT License 5 votes vote down vote up
@Override
protected boolean setAttribute(int key, float value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_paintWidth:
                mPaint.setStrokeWidth(Utils.dp2px(value));
                break;

            case StringBase.STR_ID_diameterX:
                mDiameterX = Utils.dp2px(value);
                break;

            case StringBase.STR_ID_diameterY:
                mDiameterY = Utils.dp2px(value);
                break;

            default:
                ret = false;
                break;
        }
    }

    return ret;
}
 
Example 13
Source File: LineBase.java    From Virtualview-Android with MIT License 5 votes vote down vote up
@Override
protected boolean setAttribute(int key, int value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_color:
                mLineColor = value;
                break;

            case StringBase.STR_ID_orientation:
                mIsHorizontal = (0 == value) ? false : true;
                break;

            case StringBase.STR_ID_paintWidth:
                mLineWidth = Utils.dp2px(value);
                if (mLineWidth <= 0) {
                    mLineWidth = 1;
                }
                break;

            case StringBase.STR_ID_style:
                mStyle = value;
                break;

            default:
                ret = false;
                break;
        }
    }

    return ret;
}
 
Example 14
Source File: VirtualGraph.java    From Virtualview-Android with MIT License 4 votes vote down vote up
@Override
protected boolean setAttribute(int key, int value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_paintWidth:
                mPaint.setStrokeWidth(Utils.dp2px(value));
                break;

            case StringBase.STR_ID_paintStyle:
                switch (value) {
                    case PAINT_STYLE_Stroke:
                        mPaint.setStyle(Paint.Style.STROKE);
                        break;

                    case PAINT_STYLE_Fill:
                        mPaint.setStyle(Paint.Style.FILL);
                        break;
                    default:
                        break;
                }
                break;

            case StringBase.STR_ID_color:
                mColor = value;
                break;

            case StringBase.STR_ID_diameterX:
                mDiameterX = Utils.dp2px(value);
                break;

            case StringBase.STR_ID_diameterY:
                mDiameterY = Utils.dp2px(value);
                break;

            case StringBase.STR_ID_type:
                mType = value;
                break;

            default:
                ret = false;
                break;
        }
    }

    return ret;
}
 
Example 15
Source File: Layout.java    From Virtualview-Android with MIT License 4 votes vote down vote up
public boolean setAttribute(int key, float value) {
    boolean ret = true;

    switch (key) {
        case StringBase.STR_ID_layoutWidth:
            if (value > 0) {
                mLayoutWidth = Utils.dp2px(value);
            } else {
                mLayoutWidth = (int) value;
            }
            break;
        case StringBase.STR_ID_layoutHeight:
            if (value > 0) {
                mLayoutHeight = Utils.dp2px(value);
            } else {
                mLayoutHeight = (int) value;
            }
            break;
        case StringBase.STR_ID_layoutMargin:
            mLayoutMargin = Utils.dp2px(value);
            if (!isLayoutMarginLeftSet) {
                mLayoutMarginLeft = mLayoutMargin;
            }
            if (!isLayoutMarginRightSet) {
                mLayoutMarginRight = mLayoutMargin;
            }
            if (!isLayoutMarginTopSet) {
                mLayoutMarginTop = mLayoutMargin;
            }
            if (!isLayoutMarginBottomSet) {
                mLayoutMarginBottom = mLayoutMargin;
            }
            break;
        case StringBase.STR_ID_layoutMarginLeft:
            mLayoutMarginLeft = Utils.dp2px(value);
            isLayoutMarginLeftSet = true;
            break;
        case StringBase.STR_ID_layoutMarginRight:
            mLayoutMarginRight = Utils.dp2px(value);
            isLayoutMarginRightSet = true;
            break;
        case StringBase.STR_ID_layoutMarginTop:
            mLayoutMarginTop = Utils.dp2px(value);
            isLayoutMarginTopSet = true;
            break;
        case StringBase.STR_ID_layoutMarginBottom:
            mLayoutMarginBottom = Utils.dp2px(value);
            isLayoutMarginBottomSet = true;
            break;

        default:
            ret = false;
    }

    return ret;
}
 
Example 16
Source File: Layout.java    From Virtualview-Android with MIT License 4 votes vote down vote up
public boolean setAttribute(int key, int value) {
    boolean ret = true;

    switch (key) {
        case StringBase.STR_ID_layoutWidth:
            if (value > 0) {
                mLayoutWidth = Utils.dp2px(value);
            } else {
                mLayoutWidth = value;
            }
            break;
        case StringBase.STR_ID_layoutHeight:
            if (value > 0) {
                mLayoutHeight = Utils.dp2px(value);
            } else {
                mLayoutHeight = value;
            }
            break;
        case StringBase.STR_ID_layoutMargin:
            mLayoutMargin = Utils.dp2px(value);
            if (!isLayoutMarginLeftSet) {
                mLayoutMarginLeft = mLayoutMargin;
            }
            if (!isLayoutMarginRightSet) {
                mLayoutMarginRight = mLayoutMargin;
            }
            if (!isLayoutMarginTopSet) {
                mLayoutMarginTop = mLayoutMargin;
            }
            if (!isLayoutMarginBottomSet) {
                mLayoutMarginBottom = mLayoutMargin;
            }
            break;
        case StringBase.STR_ID_layoutMarginLeft:
            mLayoutMarginLeft = Utils.dp2px(value);
            isLayoutMarginLeftSet = true;
            break;
        case StringBase.STR_ID_layoutMarginRight:
            mLayoutMarginRight = Utils.dp2px(value);
            isLayoutMarginRightSet = true;
            break;
        case StringBase.STR_ID_layoutMarginTop:
            mLayoutMarginTop = Utils.dp2px(value);
            isLayoutMarginTopSet = true;
            break;
        case StringBase.STR_ID_layoutMarginBottom:
            mLayoutMarginBottom = Utils.dp2px(value);
            isLayoutMarginBottomSet = true;
            break;

        default:
            ret = false;
    }

    return ret;
}
 
Example 17
Source File: Scroller.java    From Virtualview-Android with MIT License 4 votes vote down vote up
@Override
protected boolean setAttribute(int key, int value) {
    boolean ret = super.setAttribute(key, value);

    if (!ret) {
        ret = true;
        switch (key) {
            case StringBase.STR_ID_orientation:
                if (value == VHCommon.HORIZONTAL) {
                    mOrientation = LinearLayoutManager.HORIZONTAL;
                } else if (value == VHCommon.VERTICAL) {
                    mOrientation = LinearLayoutManager.VERTICAL;
                }
                break;

            case StringBase.STR_ID_mode:
                mMode = value;
                break;

            case StringBase.STR_ID_supportSticky:
                mSupportSticky = (value > 0) ? true : false;
                break;

            case StringBase.STR_ID_span:
                mSpan = Utils.dp2px(value);
                break;

            case StringBase.STR_ID_autoRefreshThreshold:
                mAutoRefreshThreshold = value;
                break;

            case StringBase.STR_ID_lineSpace:
                mLineSpace = Utils.dp2px(value);
                break;
            case StringBase.STR_ID_firstSpace:
                mFirstSpace = Utils.dp2px(value);
                break;
            case StringBase.STR_ID_lastSpace:
                mLastSpace = Utils.dp2px(value);
                break;
            default:
                ret = false;
                break;
        }
    }

    return ret;
}