TimeView.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:DroneControl 作者:
public TimeView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs, R.styleable.TimeView, 0, 0);
    try {
        TypedValue textSizeValue = new TypedValue();
        if (a.getValue(R.styleable.TimeView_textSize, textSizeValue)) {
            if (textSizeValue.type == TypedValue.TYPE_DIMENSION) {
                mTextSize = a.getDimensionPixelSize(R.styleable.TimeView_textSize,
                        ViewGroup.LayoutParams.MATCH_PARENT);
                setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
            }
        }

        mTimeType = TimeType.values()[a.getInt(R.styleable.TimeView_timeType, 0)];
        mTemplate = a.getString(R.styleable.TimeView_template);
        mFontPath = a.getString(R.styleable.TimeView_fontPath);

        if (getTimeStateCount() > 1) {
            if (getBackground() instanceof LevelListDrawable) {
                // Do nothing.
            } else {
                final int textArrayId = a.getResourceId(R.styleable.TimeView_textArray, 0);
                if (textArrayId != 0) {
                    mTimeTextResArray = loadTextResArray(
                            getResources().getIntArray(textArrayId));
                } else {
                    mTimeTextResArray = getDefaultTimeTextResArray();
                }
                if (mTimeTextResArray != null && mTimeTextResArray.length > 0) {
                    // This gives the view a default size.
                    setText(mTimeTextResArray[0]);
                }
            }
        }

    } finally {
        a.recycle();
    }

    if (mFontPath != null) {
        try {
            setTypeface(sFontCache.getFont(context, mFontPath));
        } catch (RuntimeException ex) {
            if (isInEditMode()) {
                System.out.println("Custom fonts are not visible in the layout editor.");
            }
        }
    }

    mFontPaint = new TextPaint(getPaint());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号