Java Code Examples for android.content.res.TypedArray.getInt()

The following are Jave code examples for showing how to use getInt() of the android.content.res.TypedArray class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Hitalk   File: FloatingActionButton.java   View Source Code Vote up 6 votes
private void initAttributes(Context context, AttributeSet attributeSet) {
    TypedArray attr = getTypedArray(context, attributeSet, R.styleable.FloatingActionButton);
    if (attr != null) {
        try {
            mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal,
                    getColor(R.color.material_blue_500));
            mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed,
                    darkenColor(mColorNormal));
            mColorRipple = attr.getColor(R.styleable.FloatingActionButton_fab_colorRipple,
                    lightenColor(mColorNormal));
            mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled,
                    mColorDisabled);
            mShadow = attr.getBoolean(R.styleable.FloatingActionButton_fab_shadow, true);
            mType = attr.getInt(R.styleable.FloatingActionButton_fab_type, TYPE_NORMAL);
        } finally {
            attr.recycle();
        }
    }
}
 
Example 2
Project: RobotIGS   File: CameraBridgeViewBase.java   View Source Code Vote up 6 votes
public CameraBridgeViewBase(Context context, AttributeSet attrs) {
    super(context, attrs);

    int count = attrs.getAttributeCount();
    Log.d(TAG, "Attr count: " + Integer.valueOf(count));

    TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
    if (styledAttrs.getBoolean(R.styleable.CameraBridgeViewBase_show_fps, false))
        enableFpsMeter();

    mCameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);

    getHolder().addCallback(this);
    mMaxWidth = MAX_UNSPECIFIED;
    mMaxHeight = MAX_UNSPECIFIED;
    styledAttrs.recycle();
}
 
Example 3
Project: MOAAP   File: CameraGLSurfaceView.java   View Source Code Vote up 6 votes
public CameraGLSurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
    int cameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);
    styledAttrs.recycle();

    if(android.os.Build.VERSION.SDK_INT >= 21)
        mRenderer = new Camera2Renderer(this);
    else
        mRenderer = new CameraRenderer(this);

    setCameraIndex(cameraIndex);

    setEGLContextClientVersion(2);
    setRenderer(mRenderer);
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
 
Example 4
Project: TinyPlanetMaker   File: CameraBridgeViewBase.java   View Source Code Vote up 6 votes
public CameraBridgeViewBase(Context context, AttributeSet attrs) {
    super(context, attrs);

    int count = attrs.getAttributeCount();
    Log.d(TAG, "Attr count: " + Integer.valueOf(count));

    TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
    if (styledAttrs.getBoolean(R.styleable.CameraBridgeViewBase_show_fps, false))
        enableFpsMeter();

    mCameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);

    getHolder().addCallback(this);
    mMaxWidth = MAX_UNSPECIFIED;
    mMaxHeight = MAX_UNSPECIFIED;
    styledAttrs.recycle();
}
 
Example 5
Project: GitHub   File: DialogUtils.java   View Source Code Vote up 6 votes
public static GravityEnum resolveGravityEnum(Context context,
                                             @AttrRes int attr,
                                             GravityEnum defaultGravity) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr});
    try {
        switch (a.getInt(0, gravityEnumToAttrInt(defaultGravity))) {
            case 1:
                return GravityEnum.CENTER;
            case 2:
                return GravityEnum.END;
            default:
                return GravityEnum.START;
        }
    } finally {
        a.recycle();
    }
}
 
Example 6
Project: boohee_v5.6   File: ForegroundLinearLayout.java   View Source Code Vote up 6 votes
public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    this.mSelfBounds = new Rect();
    this.mOverlayBounds = new Rect();
    this.mForegroundGravity = Opcodes.INVOKE_STATIC_RANGE;
    this.mForegroundInPadding = true;
    this.mForegroundBoundsChanged = false;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLinearLayout, defStyle, 0);
    this.mForegroundGravity = a.getInt(R.styleable.ForegroundLinearLayout_android_foregroundGravity, this.mForegroundGravity);
    Drawable d = a.getDrawable(R.styleable.ForegroundLinearLayout_android_foreground);
    if (d != null) {
        setForeground(d);
    }
    this.mForegroundInPadding = a.getBoolean(R.styleable.ForegroundLinearLayout_foregroundInsidePadding, true);
    a.recycle();
}
 
Example 7
Project: AndroidSimpleViews   File: SimpleViewPager.java   View Source Code Vote up 5 votes
private void init(AttributeSet attrs, int defStyle) {
    // Load attributes
    try {
        final TypedArray a = getContext().obtainStyledAttributes(
                attrs, R.styleable.SimpleViewPager, defStyle, 0);

        mDotColor = a.getColor(R.styleable.SimpleViewPager_dotColor, Color.BLACK);
        mDotColorActive = a.getColor(R.styleable.SimpleViewPager_dotColorActive, Color.WHITE);
        mSwipeAnimationDuration = a.getInt(R.styleable.SimpleViewPager_swipeAnimationDuration, 300);
        mSwipeSensitivity = a.getInt(R.styleable.SimpleViewPager_swipeSensitivity, 300);
        mPageDotsAlignment = PageDotsAlignment.values()[(a.getInt(R.styleable.SimpleViewPager_pageDotsAlignment, 1))];
        mPageDotsMargin = (int) a.getDimension(R.styleable.SimpleViewPager_pageDotsMargin, 100);
        mDotRadius = (int) a.getDimension(R.styleable.SimpleViewPager_pageDotsRadius, 20);
        mActivePageDotsRadius = (int) a.getDimension(R.styleable.SimpleViewPager_activePageDotsRadius, mDotRadius);
        mDotsSeparate = (int) a.getDimension(R.styleable.SimpleViewPager_dotsSeperate, 10);
        mShowPageDots = a.getBoolean(R.styleable.SimpleViewPager_showPageDots, true);
        a.recycle();

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    setOnTouchListener(_OnTouchListener);
    mPagerView = new View(getContext());
    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    layoutParams.addRule(ALIGN_PARENT_BOTTOM);
    mPagerView.setLayoutParams(layoutParams);
    addView(mPagerView);
    mPagerView.bringToFront();

}
 
Example 8
Project: CornerTipView   File: CornerTipView.java   View Source Code Vote up 5 votes
private void initViews(Context context, AttributeSet attrs) {
    tipCornerPosition = TIP_POSITION_TOP_LEFT;//默认左上角
    startDisH = dp2px(context, 20);//20dp
    textVPadding = dp2px(context, 2);//3dp
    tipTextSize = sp2px(context, 11);//11sp
    tipTextColor = Color.WHITE;//默认字体白色
    tipBackgroundColor = Color.TRANSPARENT;//默认透明背景

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CornerTipView);
    tipCornerPosition = typedArray.getInt(R.styleable.CornerTipView_tip_corner_position, tipCornerPosition);
    realStartDisH = typedArray.getDimensionPixelSize(R.styleable.CornerTipView_tip_start_dis_x, (int) startDisH);
    textVPadding = typedArray.getDimensionPixelSize(R.styleable.CornerTipView_tip_text_v_padding, textVPadding);
    tipTextSize = typedArray.getDimensionPixelSize(R.styleable.CornerTipView_tip_text_size, tipTextSize);//默认12sp
    tipTextColor = typedArray.getColor(R.styleable.CornerTipView_tip_text_color, tipTextColor);
    tipBackgroundColor = typedArray.getColor(R.styleable.CornerTipView_tip_background, tipBackgroundColor);
    tipContent = typedArray.getString(R.styleable.CornerTipView_tip_text);
    typedArray.recycle();

    path = new Path();
    backPaint = new Paint();
    backPaint.setAntiAlias(true);
    backPaint.setColor(tipBackgroundColor);

    textPaint = new TextPaint();
    textPaint.setColor(tipTextColor);
    textPaint.setTextSize(tipTextSize);
    textPaint.setTextAlign(Paint.Align.CENTER);
}
 
Example 9
Project: ShapedNavigationView   File: ShapedViewSettings.java   View Source Code Vote up 5 votes
public ShapedViewSettings(Context context, AttributeSet attrs) {
    TypedArray styledAttributes = context.obtainStyledAttributes(attrs, R.styleable.ShapedDrawer, 0, 0);
    final int shape = styledAttributes.getInt(R.styleable.ShapedDrawer_drawerShape, NORMAL);
    switch (shape) {
        case 0:
            shapeType = ARC_CONCAVE;
            break;
        case 1:
            shapeType = ARC_CONVEX;
            break;
        case 2:
            shapeType = ROUNDED_RECT;
            break;
        case 3:
            shapeType = WAVES;
            break;
        case 4:
            shapeType = BOTTOM_ROUND;
            break;
        case 5:
            shapeType = FULL_ROUND;
            break;
        case 6:
            shapeType = WAVES_INDEFINITE;
            break;
        default:
            shapeType = NORMAL;
    }

    int[] attrsArray = new int[]{
            android.R.attr.background,
            android.R.attr.layout_gravity,
    };

    TypedArray androidAttrs = context.obtainStyledAttributes(attrs, attrsArray);
    backgroundDrawable = androidAttrs.getDrawable(0);

    androidAttrs.recycle();
    styledAttributes.recycle();
}
 
Example 10
Project: GitHub   File: FloatingActionButton.java   View Source Code Vote up 5 votes
protected void initAttributes(Context context, AttributeSet attributeSet) {
    TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatActionButton, 0, 0);
    if (attr != null) {
        try {
            mColorNormal = attr.getColor(R.styleable.FloatActionButton_urv_fab_colorNormal, getColor(android.R.color.holo_blue_dark));
            mColorPressed = attr.getColor(R.styleable.FloatActionButton_urv_fab_colorPressed, getColor(android.R.color.holo_blue_light));
            mSize = attr.getInt(R.styleable.FloatActionButton_urv_fab_size, SIZE_NORMAL);
            mIcon = attr.getResourceId(R.styleable.FloatActionButton_icon, 0);
            load_extended_attributes(attr);
        } finally {
            attr.recycle();
        }
    }
}
 
Example 11
Project: RLibrary   File: SlidingTabLayout.java   View Source Code Vote up 5 votes
private void obtainAttributes(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout);

    mIndicatorStyle = ta.getInt(R.styleable.SlidingTabLayout_tl_indicator_style, STYLE_NORMAL);
    mIndicatorColor = ta.getColor(R.styleable.SlidingTabLayout_tl_indicator_color, Color.parseColor(mIndicatorStyle == STYLE_BLOCK ? "#4B6A87" : "#ffffff"));
    mIndicatorHeight = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_height,
            dp2px(mIndicatorStyle == STYLE_TRIANGLE ? 4 : (mIndicatorStyle == STYLE_BLOCK ? -1 : 2)));
    mIndicatorWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_width, dp2px(mIndicatorStyle == STYLE_TRIANGLE ? 10 : -1));
    mIndicatorCornerRadius = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_corner_radius, dp2px(mIndicatorStyle == STYLE_BLOCK ? -1 : 0));
    mIndicatorMarginLeft = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_left, dp2px(0));
    mIndicatorMarginTop = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_top, dp2px(mIndicatorStyle == STYLE_BLOCK ? 7 : 0));
    mIndicatorMarginRight = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_right, dp2px(0));
    mIndicatorMarginBottom = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_bottom, dp2px(mIndicatorStyle == STYLE_BLOCK ? 7 : 0));
    mIndicatorGravity = ta.getInt(R.styleable.SlidingTabLayout_tl_indicator_gravity, Gravity.BOTTOM);
    mIndicatorWidthEqualTitle = ta.getBoolean(R.styleable.SlidingTabLayout_tl_indicator_width_equal_title, false);

    mUnderlineColor = ta.getColor(R.styleable.SlidingTabLayout_tl_underline_color, Color.parseColor("#ffffff"));
    mUnderlineHeight = ta.getDimension(R.styleable.SlidingTabLayout_tl_underline_height, dp2px(0));
    mUnderlineGravity = ta.getInt(R.styleable.SlidingTabLayout_tl_underline_gravity, Gravity.BOTTOM);

    mDividerColor = ta.getColor(R.styleable.SlidingTabLayout_tl_divider_color, Color.parseColor("#ffffff"));
    mDividerWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_divider_width, dp2px(0));
    mDividerPadding = ta.getDimension(R.styleable.SlidingTabLayout_tl_divider_padding, dp2px(12));

    mTextsize = ta.getDimension(R.styleable.SlidingTabLayout_tl_textsize, sp2px(14));
    mTextSelectColor = ta.getColor(R.styleable.SlidingTabLayout_tl_textSelectColor, Color.parseColor("#ffffff"));
    mTextUnselectColor = ta.getColor(R.styleable.SlidingTabLayout_tl_textUnselectColor, Color.parseColor("#AAffffff"));
    mTextBold = ta.getInt(R.styleable.SlidingTabLayout_tl_textBold, TEXT_BOLD_NONE);
    mTextAllCaps = ta.getBoolean(R.styleable.SlidingTabLayout_tl_textAllCaps, false);

    mTabSpaceEqual = ta.getBoolean(R.styleable.SlidingTabLayout_tl_tab_space_equal, false);
    mTabWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_width, dp2px(-1));
    mTabPadding = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(20));

    ta.recycle();
}
 
Example 12
Project: JBase   File: LabelView.java   View Source Code Vote up 5 votes
private void obtainAttributes(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LabelView);
    mTextContent = ta.getString(R.styleable.LabelView_lv_text);
    mTextColor = ta.getColor(R.styleable.LabelView_lv_text_color, Color.parseColor("#ffffff"));
    mTextSize = ta.getDimension(R.styleable.LabelView_lv_text_size, sp2px(11));
    mTextBold = ta.getBoolean(R.styleable.LabelView_lv_text_bold, true);
    mTextAllCaps = ta.getBoolean(R.styleable.LabelView_lv_text_all_caps, true);
    mFillTriangle = ta.getBoolean(R.styleable.LabelView_lv_fill_triangle, false);
    mBackgroundColor = ta.getColor(R.styleable.LabelView_lv_background_color, Color.parseColor("#FF4081"));
    mMinSize = ta.getDimension(R.styleable.LabelView_lv_min_size, mFillTriangle ? dp2px(35) : dp2px(50));
    mPadding = ta.getDimension(R.styleable.LabelView_lv_padding, dp2px(3.5f));
    mGravity = ta.getInt(R.styleable.LabelView_lv_gravity, Gravity.TOP | Gravity.LEFT);
    ta.recycle();
}
 
Example 13
Project: FlycoTablayout   File: SlidingTabLayout.java   View Source Code Vote up 5 votes
private void obtainAttributes(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout);

    mIndicatorStyle = ta.getInt(R.styleable.SlidingTabLayout_tl_indicator_style, STYLE_NORMAL);
    mIndicatorColor = ta.getColor(R.styleable.SlidingTabLayout_tl_indicator_color, Color.parseColor(mIndicatorStyle == STYLE_BLOCK ? "#4B6A87" : "#ffffff"));
    mIndicatorHeight = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_height,
            dp2px(mIndicatorStyle == STYLE_TRIANGLE ? 4 : (mIndicatorStyle == STYLE_BLOCK ? -1 : 2)));
    mIndicatorWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_width, dp2px(mIndicatorStyle == STYLE_TRIANGLE ? 10 : -1));
    mIndicatorCornerRadius = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_corner_radius, dp2px(mIndicatorStyle == STYLE_BLOCK ? -1 : 0));
    mIndicatorMarginLeft = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_left, dp2px(0));
    mIndicatorMarginTop = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_top, dp2px(mIndicatorStyle == STYLE_BLOCK ? 7 : 0));
    mIndicatorMarginRight = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_right, dp2px(0));
    mIndicatorMarginBottom = ta.getDimension(R.styleable.SlidingTabLayout_tl_indicator_margin_bottom, dp2px(mIndicatorStyle == STYLE_BLOCK ? 7 : 0));
    mIndicatorGravity = ta.getInt(R.styleable.SlidingTabLayout_tl_indicator_gravity, Gravity.BOTTOM);
    mIndicatorWidthEqualTitle = ta.getBoolean(R.styleable.SlidingTabLayout_tl_indicator_width_equal_title, false);

    mUnderlineColor = ta.getColor(R.styleable.SlidingTabLayout_tl_underline_color, Color.parseColor("#ffffff"));
    mUnderlineHeight = ta.getDimension(R.styleable.SlidingTabLayout_tl_underline_height, dp2px(0));
    mUnderlineGravity = ta.getInt(R.styleable.SlidingTabLayout_tl_underline_gravity, Gravity.BOTTOM);

    mDividerColor = ta.getColor(R.styleable.SlidingTabLayout_tl_divider_color, Color.parseColor("#ffffff"));
    mDividerWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_divider_width, dp2px(0));
    mDividerPadding = ta.getDimension(R.styleable.SlidingTabLayout_tl_divider_padding, dp2px(12));

    mTextsize = ta.getDimension(R.styleable.SlidingTabLayout_tl_textsize, sp2px(14));
    mTextSelectColor = ta.getColor(R.styleable.SlidingTabLayout_tl_textSelectColor, Color.parseColor("#ffffff"));
    mTextUnselectColor = ta.getColor(R.styleable.SlidingTabLayout_tl_textUnselectColor, Color.parseColor("#AAffffff"));
    mTextBold = ta.getInt(R.styleable.SlidingTabLayout_tl_textBold, TEXT_BOLD_NONE);
    mTextAllCaps = ta.getBoolean(R.styleable.SlidingTabLayout_tl_textAllCaps, false);

    mTabSpaceEqual = ta.getBoolean(R.styleable.SlidingTabLayout_tl_tab_space_equal, false);
    mTabWidth = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_width, dp2px(-1));
    mTabPadding = ta.getDimension(R.styleable.SlidingTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(20));

    ta.recycle();
}
 
Example 14
Project: SelectName   File: DragScrollDetailsLayout.java   View Source Code Vote up 5 votes
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public DragScrollDetailsLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DragScrollDetailsLayout, defStyleAttr, 0);
    mPercent = a.getFloat(R.styleable.DragScrollDetailsLayout_percent, DEFAULT_PERCENT);
    mDuration = a.getInt(R.styleable.DragScrollDetailsLayout_duration, DEFAULT_DURATION);
    mDefaultPanel = a.getInt(R.styleable.DragScrollDetailsLayout_default_panel, 0);
    a.recycle();
    mScroller = new Scroller(getContext(), new DecelerateInterpolator());
    mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
    mMaxFlingVelocity = ViewConfiguration.get(getContext()).getScaledMaximumFlingVelocity();
    mMiniFlingVelocity = ViewConfiguration.get(getContext()).getScaledMinimumFlingVelocity();
    setOrientation(VERTICAL);
}
 
Example 15
Project: simple-keyboard   File: KeyboardBuilder.java   View Source Code Vote up 4 votes
private void parseKeyboardAttributes(final XmlPullParser parser) {
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyboardAttr = mContext.obtainStyledAttributes(
            attr, R.styleable.Keyboard, R.attr.keyboardStyle, R.style.Keyboard);
    final TypedArray keyAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
    try {
        final KeyboardParams params = mParams;
        final int height = params.mId.mHeight;
        final int width = params.mId.mWidth;
        params.mOccupiedHeight = height;
        params.mOccupiedWidth = width;
        params.mTopPadding = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_keyboardTopPadding, height, height, 0);
        params.mBottomPadding = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_keyboardBottomPadding, height, height, 0);
        params.mLeftPadding = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_keyboardLeftPadding, width, width, 0);
        params.mRightPadding = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_keyboardRightPadding, width, width, 0);

        final int baseWidth =
                params.mOccupiedWidth - params.mLeftPadding - params.mRightPadding;
        params.mBaseWidth = baseWidth;
        params.mDefaultKeyWidth = (int)keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth,
                baseWidth, baseWidth, baseWidth / DEFAULT_KEYBOARD_COLUMNS);
        params.mHorizontalGap = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_horizontalGap, baseWidth, baseWidth, 0);
        // TODO: Fix keyboard geometry calculation clearer. Historically vertical gap between
        // rows are determined based on the entire keyboard height including top and bottom
        // paddings.
        params.mVerticalGap = (int)keyboardAttr.getFraction(
                R.styleable.Keyboard_verticalGap, height, height, 0);
        final int baseHeight = params.mOccupiedHeight - params.mTopPadding
                - params.mBottomPadding + params.mVerticalGap;
        params.mBaseHeight = baseHeight;
        params.mDefaultRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
                R.styleable.Keyboard_rowHeight, baseHeight, baseHeight / DEFAULT_KEYBOARD_ROWS);

        params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);

        params.mMoreKeysTemplate = keyboardAttr.getResourceId(
                R.styleable.Keyboard_moreKeysTemplate, 0);
        params.mMaxMoreKeysKeyboardColumn = keyAttr.getInt(
                R.styleable.Keyboard_Key_maxMoreKeysColumn, 5);

        params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0);
        params.mIconsSet.loadIcons(keyboardAttr);
        params.mTextsSet.setLocale(params.mId.getLocale(), mContext);
    } finally {
        keyAttr.recycle();
        keyboardAttr.recycle();
    }
}
 
Example 16
Project: CustomAndroidOneSheeld   File: MultiDirectionSlidingDrawer.java   View Source Code Vote up 4 votes
/**
 * Creates a new SlidingDrawer from a specified set of attributes defined in
 * XML.
 *
 * @param context  The application's environment.
 * @param attrs    The attributes defined in XML.
 * @param defStyle The style to apply to this widget.
 */
public MultiDirectionSlidingDrawer(Context context, AttributeSet attrs,
                                   int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.MultiDirectionSlidingDrawer, defStyle, 0);

    int orientation = a.getInt(
            R.styleable.MultiDirectionSlidingDrawer_direction,
            ORIENTATION_BTT);
    mVertical = (orientation == ORIENTATION_BTT || orientation == ORIENTATION_TTB);
    mBottomOffset = (int) a.getDimension(
            R.styleable.MultiDirectionSlidingDrawer_bottomOffset, 0.0f);
    mTopOffset = (int) a.getDimension(
            R.styleable.MultiDirectionSlidingDrawer_topOffset, 0.0f);
    mAllowSingleTap = a.getBoolean(
            R.styleable.MultiDirectionSlidingDrawer_allowSingleTap, true);
    mAnimateOnClick = a.getBoolean(
            R.styleable.MultiDirectionSlidingDrawer_animateOnClick, true);
    mInvert = (orientation == ORIENTATION_TTB || orientation == ORIENTATION_LTR);

    int handleId = a.getResourceId(
            R.styleable.MultiDirectionSlidingDrawer_handle, 0);
    if (handleId == 0) {
        throw new IllegalArgumentException(
                "The handle attribute is required and must refer "
                        + "to a valid child.");
    }

    int contentId = a.getResourceId(
            R.styleable.MultiDirectionSlidingDrawer_content, 0);
    if (contentId == 0) {
        throw new IllegalArgumentException(
                "The content attribute is required and must refer "
                        + "to a valid child.");
    }

    if (handleId == contentId) {
        throw new IllegalArgumentException(
                "The content and handle attributes must refer "
                        + "to different children.");
    }
    mHandleId = handleId;
    mContentId = contentId;

    final float density = getResources().getDisplayMetrics().density;
    mTapThreshold = (int) (TAP_THRESHOLD * density + 0.5f);
    mMaximumTapVelocity = (int) (MAXIMUM_TAP_VELOCITY * density + 0.5f);
    mMaximumMinorVelocity = (int) (MAXIMUM_MINOR_VELOCITY * density + 0.5f);
    mMaximumMajorVelocity = (int) (MAXIMUM_MAJOR_VELOCITY * density + 0.5f);
    mMaximumAcceleration = (int) (MAXIMUM_ACCELERATION * density + 0.5f);
    mVelocityUnits = (int) (VELOCITY_UNITS * density + 0.5f);

    if (mInvert) {
        mMaximumAcceleration = -mMaximumAcceleration;
        mMaximumMajorVelocity = -mMaximumMajorVelocity;
        mMaximumMinorVelocity = -mMaximumMinorVelocity;
    }

    a.recycle();
    setAlwaysDrawnWithCacheEnabled(false);
}
 
Example 17
Project: XinFramework   File: CommonTitleBar.java   View Source Code Vote up 4 votes
private void loadAttributes(Context context, AttributeSet attrs) {
    PADDING_5 = ScreenUtils.dp2PxInt(5);
    PADDING_12 = ScreenUtils.dp2PxInt(12);
    PADDING_15 = ScreenUtils.dp2PxInt(15);

    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CommonTitleBar);

    if (SysUtils.hasKitKat()) {
        // notice 未引入沉浸式标题栏之前,隐藏标题栏撑起布局
        fillStatusBar = array.getBoolean(R.styleable.CommonTitleBar_fillStatusBar, true);
    }
    titleBarColor = array.getColor(R.styleable.CommonTitleBar_titleBarColor, ContextCompat.getColor(context, R.color.ffffff_white_1000));
    titleBarHeight = (int) array.getDimension(R.styleable.CommonTitleBar_titleBarHeight, ScreenUtils.dp2PxInt(44));
    statusBarColor = array.getColor(R.styleable.CommonTitleBar_statusBarColor, ContextCompat.getColor(context, R.color.ffffff_white_1000));

    showBottomLine = array.getBoolean(R.styleable.CommonTitleBar_showBottomLine, true);
    bottomLineColor = array.getColor(R.styleable.CommonTitleBar_bottomLineColor, ContextCompat.getColor(context, R.color.dddddd_grey_350));
    bottomElevation = array.getDimension(R.styleable.CommonTitleBar_bottomElevation, ScreenUtils.dp2PxInt(5));

    leftType = array.getInt(R.styleable.CommonTitleBar_leftType, TYPE_LEFT_NONE);
    if (leftType == TYPE_LEFT_TEXTVIEW) {
        leftText = array.getString(R.styleable.CommonTitleBar_leftText);
        leftTextColor = array.getColor(R.styleable.CommonTitleBar_leftTextColor, ContextCompat.getColor(context, R.color.comm_titlebar_text_selector));
        leftTextSize = array.getDimension(R.styleable.CommonTitleBar_leftTextSize, ScreenUtils.sp2px(context, 16));
        leftDrawable = array.getResourceId(R.styleable.CommonTitleBar_leftDrawable, 0);
        leftDrawablePadding = array.getDimension(R.styleable.CommonTitleBar_leftDrawablePadding, 5);
    } else if (leftType == TYPE_LEFT_IMAGEBUTTON) {
        leftImageResource = array.getResourceId(R.styleable.CommonTitleBar_leftImageResource, R.drawable.comm_titlebar_reback_selector);
    } else if (leftType == TYPE_LEFT_CUSTOM_VIEW) {
        leftCustomViewRes = array.getResourceId(R.styleable.CommonTitleBar_leftCustomView, 0);
    }

    rightType = array.getInt(R.styleable.CommonTitleBar_rightType, TYPE_RIGHT_NONE);
    if (rightType == TYPE_RIGHT_TEXTVIEW) {
        rightText = array.getString(R.styleable.CommonTitleBar_rightText);
        rightTextColor = array.getColor(R.styleable.CommonTitleBar_rightTextColor, ContextCompat.getColor(context, R.color.comm_titlebar_text_selector));
        rightTextSize = array.getDimension(R.styleable.CommonTitleBar_rightTextSize, ScreenUtils.sp2px(context, 16));
    } else if (rightType == TYPE_RIGHT_IMAGEBUTTON) {
        rightImageResource = array.getResourceId(R.styleable.CommonTitleBar_rightImageResource, 0);
    } else if (rightType == TYPE_RIGHT_CUSTOM_VIEW) {
        rightCustomViewRes = array.getResourceId(R.styleable.CommonTitleBar_rightCustomView, 0);
    }

    centerType = array.getInt(R.styleable.CommonTitleBar_centerType, TYPE_CENTER_NONE);
    if (centerType == TYPE_CENTER_TEXTVIEW) {
        centerText = array.getString(R.styleable.CommonTitleBar_centerText);
        centerTextColor = array.getColor(R.styleable.CommonTitleBar_centerTextColor, ContextCompat.getColor(context, R.color.common_title_bar_center_text_color));
        centerTextSize = array.getDimension(R.styleable.CommonTitleBar_centerTextSize, ScreenUtils.sp2px(context, 18f));
        centerSubText = array.getString(R.styleable.CommonTitleBar_centerSubText);
        centerSubTextColor = array.getColor(R.styleable.CommonTitleBar_centerSubTextColor, ContextCompat.getColor(context, R.color._757575_grey_600));
        centerSubTextSize = array.getDimension(R.styleable.CommonTitleBar_centerSubTextSize, ScreenUtils.sp2px(context, 12));
    } else if (centerType == TYPE_CENTER_SEARCHVIEW) {
        centerSearchEdiable = array.getBoolean(R.styleable.CommonTitleBar_centerSearchEdiable, true);
        centerSearchBgResource = array.getResourceId(R.styleable.CommonTitleBar_centerSearchBg, R.drawable.comm_titlebar_search_gray_shape);
        centerSearchRightType = array.getInt(R.styleable.CommonTitleBar_centerSearchRightType, TYPE_CENTER_SEARCH_RIGHT_VOICE);
    } else if (centerType == TYPE_CENTER_CUSTOM_VIEW) {
        centerCustomViewRes = array.getResourceId(R.styleable.CommonTitleBar_centerCustomView, 0);
    }

    array.recycle();
}
 
Example 18
Project: GitHub   File: ProgressPieView.java   View Source Code Vote up 4 votes
private void init(Context context, AttributeSet attrs) {
    mDisplayMetrics = context.getResources().getDisplayMetrics();

    mStrokeWidth = mStrokeWidth * mDisplayMetrics.density;
    mTextSize = mTextSize * mDisplayMetrics.scaledDensity;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProgressPieView);
    final Resources res = getResources();

    mMax = a.getInteger(R.styleable.ProgressPieView_ppvMax, mMax);
    mProgress = a.getInteger(R.styleable.ProgressPieView_ppvProgress, mProgress);
    mStartAngle = a.getInt(R.styleable.ProgressPieView_ppvStartAngle, mStartAngle);
    mInverted = a.getBoolean(R.styleable.ProgressPieView_ppvInverted, mInverted);
    mCounterclockwise = a.getBoolean(R.styleable.ProgressPieView_ppvCounterclockwise, mCounterclockwise);
    mStrokeWidth = a.getDimension(R.styleable.ProgressPieView_ppvStrokeWidth, mStrokeWidth);
    mTypeface = a.getString(R.styleable.ProgressPieView_ppvTypeface);
    mTextSize = a.getDimension(R.styleable.ProgressPieView_android_textSize, mTextSize);
    mText = a.getString(R.styleable.ProgressPieView_android_text);

    mShowStroke = a.getBoolean(R.styleable.ProgressPieView_ppvShowStroke, mShowStroke);
    mShowText = a.getBoolean(R.styleable.ProgressPieView_ppvShowText, mShowText);
    mImage = a.getDrawable(R.styleable.ProgressPieView_ppvImage);

    int backgroundColor = Color.parseColor("#00000000");
    backgroundColor = a.getColor(R.styleable.ProgressPieView_ppvBackgroundColor, backgroundColor);
    int progressColor = Color.parseColor("#33b5e5");
    progressColor = a.getColor(R.styleable.ProgressPieView_ppvProgressColor, progressColor);
    int strokeColor = Color.parseColor("#33b5e5");
    strokeColor = a.getColor(R.styleable.ProgressPieView_ppvStrokeColor, strokeColor);
    int textColor = Color.parseColor("#333333");
    textColor = a.getColor(R.styleable.ProgressPieView_android_textColor, textColor);

    mProgressFillType = a.getInteger(R.styleable.ProgressPieView_ppvProgressFillType, mProgressFillType);

    a.recycle();

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setColor(backgroundColor);
    mBackgroundPaint.setStyle(Paint.Style.FILL);

    mProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mProgressPaint.setColor(progressColor);
    mProgressPaint.setStyle(Paint.Style.FILL);

    mStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mStrokePaint.setColor(strokeColor);
    mStrokePaint.setStyle(Paint.Style.STROKE);
    mStrokePaint.setStrokeWidth(mStrokeWidth);

    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(textColor);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setTextAlign(Paint.Align.CENTER);

    mInnerRectF = new RectF();
    mImageRect = new Rect();
}
 
Example 19
Project: baselibrary-master   File: NumberPickerView.java   View Source Code Vote up 4 votes
private void initAttr(Context context, AttributeSet attrs){
    if (attrs == null) {
        return;
    }
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerView);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        if(attr == R.styleable.NumberPickerView_npv_ShowCount){
            mShowCount = a.getInt(attr, DEFAULT_SHOW_COUNT);
        }else if(attr == R.styleable.NumberPickerView_npv_DividerColor){
            mDividerColor = a.getColor(attr, DEFAULT_DIVIDER_COLOR);
        }else if(attr == R.styleable.NumberPickerView_npv_DividerHeight){
            mDividerHeight = a.getDimensionPixelSize(attr, DEFAULT_DIVIDER_HEIGHT);
        }else if(attr == R.styleable.NumberPickerView_npv_DividerMarginLeft){
            mDividerMarginL = a.getDimensionPixelSize(attr, DEFAULT_DIVIDER_MARGIN_HORIZONTAL);
        }else if(attr == R.styleable.NumberPickerView_npv_DividerMarginRight){
            mDividerMarginR = a.getDimensionPixelSize(attr, DEFAULT_DIVIDER_MARGIN_HORIZONTAL);
        }else if(attr == R.styleable.NumberPickerView_npv_TextArray){
            mDisplayedValues = convertCharSequenceArrayToStringArray(a.getTextArray(attr));
        }else if(attr == R.styleable.NumberPickerView_npv_TextColorNormal){
            mTextColorNormal = a.getColor(attr, DEFAULT_TEXT_COLOR_NORMAL);
        }else if(attr == R.styleable.NumberPickerView_npv_TextColorSelected){
            mTextColorSelected = a.getColor(attr, DEFAULT_TEXT_COLOR_SELECTED);
        }else if(attr == R.styleable.NumberPickerView_npv_TextColorHint){
            mTextColorHint = a.getColor(attr, DEFAULT_TEXT_COLOR_SELECTED);
        }else if(attr == R.styleable.NumberPickerView_npv_TextSizeNormal){
            mTextSizeNormal = a.getDimensionPixelSize(attr, sp2px(context, DEFAULT_TEXT_SIZE_NORMAL_SP));
        }else if(attr == R.styleable.NumberPickerView_npv_TextSizeSelected){
            mTextSizeSelected = a.getDimensionPixelSize(attr, sp2px(context, DEFAULT_TEXT_SIZE_SELECTED_SP));
        }else if(attr == R.styleable.NumberPickerView_npv_TextSizeHint){
            mTextSizeHint = a.getDimensionPixelSize(attr, sp2px(context, DEFAULT_TEXT_SIZE_HINT_SP));
        }else if(attr == R.styleable.NumberPickerView_npv_MinValue){
            mMinShowIndex = a.getInteger(attr, 0);
        }else if(attr == R.styleable.NumberPickerView_npv_MaxValue){
            mMaxShowIndex = a.getInteger(attr, 0);
        }else if(attr == R.styleable.NumberPickerView_npv_WrapSelectorWheel){
            mWrapSelectorWheel = a.getBoolean(attr, DEFAULT_WRAP_SELECTOR_WHEEL);
        }else if(attr == R.styleable.NumberPickerView_npv_ShowDivider){
            mShowDivider = a.getBoolean(attr, DEFAULT_SHOW_DIVIDER);
        }else if(attr == R.styleable.NumberPickerView_npv_HintText){
            mHintText = a.getString(attr);
        }else if(attr == R.styleable.NumberPickerView_npv_AlternativeHint){
            mAlterHint = a.getString(attr);
        }else if(attr == R.styleable.NumberPickerView_npv_EmptyItemHint){
            mEmptyItemHint = a.getString(attr);
        }else if(attr == R.styleable.NumberPickerView_npv_MarginStartOfHint){
            mMarginStartOfHint = a.getDimensionPixelSize(attr, dp2px(context, DEFAULT_MARGIN_START_OF_HINT_DP));
        }else if(attr == R.styleable.NumberPickerView_npv_MarginEndOfHint){
            mMarginEndOfHint = a.getDimensionPixelSize(attr, dp2px(context, DEFAULT_MARGIN_END_OF_HINT_DP));
        }else if(attr == R.styleable.NumberPickerView_npv_ItemPaddingVertical){
            mItemPaddingVertical = a.getDimensionPixelSize(attr, dp2px(context, DEFAULT_ITEM_PADDING_DP_V));
        }else if(attr == R.styleable.NumberPickerView_npv_ItemPaddingHorizontal){
            mItemPaddingHorizontal = a.getDimensionPixelSize(attr, dp2px(context, DEFAULT_ITEM_PADDING_DP_H));
        }else if(attr == R.styleable.NumberPickerView_npv_AlternativeTextArrayWithMeasureHint){
            mAlterTextArrayWithMeasureHint = a.getTextArray(attr);
        }else if(attr == R.styleable.NumberPickerView_npv_AlternativeTextArrayWithoutMeasureHint){
            mAlterTextArrayWithoutMeasureHint = a.getTextArray(attr);
        }else if(attr == R.styleable.NumberPickerView_npv_RespondChangeOnDetached){
            mRespondChangeOnDetach = a.getBoolean(attr, DEFAULT_RESPOND_CHANGE_ON_DETACH);
        }else if(attr == R.styleable.NumberPickerView_npv_RespondChangeInMainThread){
            mRespondChangeInMainThread = a.getBoolean(attr, DEFAULT_RESPOND_CHANGE_IN_MAIN_THREAD);
        }else if (attr == R.styleable.NumberPickerView_npv_TextEllipsize) {
            mTextEllipsize = a.getString(attr);
        }
    }
    a.recycle();
}
 
Example 20
Project: ChatExchange-old   File: FloatingActionButton.java   View Source Code Vote up 4 votes
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
        TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0);
        mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, 0xFFDA4336);
        mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, 0xFFE75043);
        mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, 0xFFAAAAAA);
        mColorRipple = attr.getColor(R.styleable.FloatingActionButton_fab_colorRipple, 0x99FFFFFF);
        mShowShadow = attr.getBoolean(R.styleable.FloatingActionButton_fab_showShadow, true);
        mShadowColor = attr.getColor(R.styleable.FloatingActionButton_fab_shadowColor, 0x66000000);
        mShadowRadius = attr.getDimensionPixelSize(R.styleable.FloatingActionButton_fab_shadowRadius, mShadowRadius);
        mShadowXOffset = attr.getDimensionPixelSize(R.styleable.FloatingActionButton_fab_shadowXOffset, mShadowXOffset);
        mShadowYOffset = attr.getDimensionPixelSize(R.styleable.FloatingActionButton_fab_shadowYOffset, mShadowYOffset);
        mFabSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL);
        mLabelText = attr.getString(R.styleable.FloatingActionButton_fab_label);
        mShouldProgressIndeterminate = attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_indeterminate, false);
        mProgressColor = attr.getColor(R.styleable.FloatingActionButton_fab_progress_color, 0xFF009688);
        mProgressBackgroundColor = attr.getColor(R.styleable.FloatingActionButton_fab_progress_backgroundColor, 0x4D000000);
        mProgressMax = attr.getInt(R.styleable.FloatingActionButton_fab_progress_max, mProgressMax);
        mShowProgressBackground = attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_showBackground, true);

        if (attr.hasValue(R.styleable.FloatingActionButton_fab_progress)) {
            mProgress = attr.getInt(R.styleable.FloatingActionButton_fab_progress, 0);
            mShouldSetProgress = true;
        }

        if (attr.hasValue(R.styleable.FloatingActionButton_fab_elevationCompat)) {
            float elevation = attr.getDimensionPixelOffset(R.styleable.FloatingActionButton_fab_elevationCompat, 0);
            if (isInEditMode()) {
                setElevation(elevation);
            } else {
                setElevationCompat(elevation);
            }
        }

        initShowAnimation(attr);
        initHideAnimation(attr);
        attr.recycle();

        if (isInEditMode()) {
            if (mShouldProgressIndeterminate) {
                setIndeterminate(true);
            } else if (mShouldSetProgress) {
                saveButtonOriginalPosition();
                setProgress(mProgress, false);
            }
        }

//        updateBackground();
        setClickable(true);
    }