Java Code Examples for android.content.res.TypedArray#getDimensionPixelSize()

The following examples show how to use android.content.res.TypedArray#getDimensionPixelSize() . 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: CountDownView.java    From CountDownView with MIT License 6 votes vote down vote up
private void init(@Nullable AttributeSet attrs) {
    textPaint.setColor(Color.BLACK);

    int textSize;
    int startDuration;
    int textAppearanceRef;
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.CountDownView);
    startDuration = ta.getInt(R.styleable.CountDownView_startDuration, 0);
    textSize = ta.getDimensionPixelSize(R.styleable.CountDownView_android_textSize, (int) dpToPx(12, getResources()));
    textAppearanceRef = ta.getResourceId(R.styleable.CountDownView_android_textAppearance, 0);
    ta.recycle();

    textPaint.setTextSize(textSize);
    if (textAppearanceRef != 0) {
        textAppearanceSpan = new TextAppearanceSpan(getContext(), textAppearanceRef);
        textPaint.setTextSize(textAppearanceSpan.getTextSize());
    }
    setStartDuration(startDuration);
}
 
Example 2
Source File: BaseAction.java    From FlowHelper with Apache License 2.0 6 votes vote down vote up
public void configAttrs(TypedArray ta) {
    mTabWidth = ta.getDimensionPixelSize(R.styleable.TabFlowLayout_tab_width, -1);
    mTabHeight = ta.getDimensionPixelSize(R.styleable.TabFlowLayout_tab_height, -1);
    int color = ta.getColor(R.styleable.TabFlowLayout_tab_color, Color.RED);
    mPaint.setColor(color);
    mType = ta.getInteger(R.styleable.TabFlowLayout_tab_type, -1);
    mMarginLeft = ta.getDimensionPixelSize(R.styleable.TabFlowLayout_tab_margin_l, 0);
    mMarginTop = ta.getDimensionPixelSize(R.styleable.TabFlowLayout_tab_margin_t, 0);
    mMarginRight = ta.getDimensionPixelSize(R.styleable.TabFlowLayout_tab_margin_r, 0);
    mMarginBottom = ta.getDimensionPixelSize(R.styleable.TabFlowLayout_tab_margin_b, 0);
    mAnimTime = ta.getInteger(R.styleable.TabFlowLayout_tab_click_animTime, 300);
    mIsAutoScale = ta.getBoolean(R.styleable.TabFlowLayout_tab_item_autoScale, false);
    mScaleFactor = ta.getFloat(R.styleable.TabFlowLayout_tab_scale_factor, 1);
    mTabOrientation = ta.getInteger(R.styleable.TabFlowLayout_tab_orientation,FlowConstants.HORIZONTATAL);
    mActionOrientation = ta.getInteger(R.styleable.TabFlowLayout_tab_action_orientaion,-1);
}
 
Example 3
Source File: AutofitRecyclerView.java    From Bangumi-Android with MIT License 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    if (attrs != null) {
        int[] attrsArray = {
                android.R.attr.columnWidth
        };
        TypedArray array = context.obtainStyledAttributes(
                attrs, attrsArray);
        columnWidth = array.getDimensionPixelSize(0, -1);
        array.recycle();
    }

    manager = new GridLayoutManager(getContext(), 1);
    setLayoutManager(manager);
}
 
Example 4
Source File: LineBreakLayout.java    From LineBreakLayout with MIT License 5 votes vote down vote up
public LineBreakLayout(Context context, AttributeSet attrs, int defStyleAttr) {
	super(context, attrs, defStyleAttr);
	TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LineBreakLayout);
	LEFT_RIGHT_SPACE = ta.getDimensionPixelSize(R.styleable.LineBreakLayout_leftAndRightSpace, 10);
	ROW_SPACE = ta.getDimensionPixelSize(R.styleable.LineBreakLayout_rowSpace, 10);
	ta.recycle(); //回收
	// ROW_SPACE=20   LEFT_RIGHT_SPACE=40
	Log.v(TAG, "ROW_SPACE="+ROW_SPACE+"   LEFT_RIGHT_SPACE="+LEFT_RIGHT_SPACE);
}
 
Example 5
Source File: ColorfulCircleView.java    From GankLock with GNU General Public License v3.0 5 votes vote down vote up
public ColorfulCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ColorfulCircleView,
        defStyleAttr, 0);
    mText = a.getString(R.styleable.ColorfulCircleView_ccv_text);
    mTextColor = a.getColor(R.styleable.ColorfulCircleView_ccv_text_color, Color.WHITE);
    mTextSize = a.getDimensionPixelSize(R.styleable.ColorfulCircleView_ccv_text_size,
        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTextSize,
            getResources().getDisplayMetrics()));
    mCircleColor = a.getColor(R.styleable.ColorfulCircleView_ccv_background_color, Color.BLUE);
    mIcon = BitmapFactory.decodeResource(getResources(),
        a.getResourceId(R.styleable.ColorfulCircleView_ccv_icon, 0));
    mPadding = a.getDimensionPixelSize(R.styleable.ColorfulCircleView_ccv_padding,
        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mPadding,
            getResources().getDisplayMetrics()));
    mAutoCapital = a.getBoolean(R.styleable.ColorfulCircleView_ccv_auto_capital, true);
    mRandomBg = a.getBoolean(R.styleable.ColorfulCircleView_ccv_random_color_bg, true);
    a.recycle();

    mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCirclePaint.setColor(mCircleColor);
    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(mTextColor);
    mTextPaint.setTextSize(mTextSize);
    mIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mFontMetrics = mTextPaint.getFontMetrics();
    if (mRandomBg) {
        mColors = new int[] { R.color.green, R.color.red, R.color.orange,
            R.color.md_blue_grey_300, R.color.md_amber_300, R.color.md_lime_A700,
            R.color.md_teal_A700, R.color.md_light_blue_A700 };
        mCirclePaint.setColor(mColors[new Random().nextInt(5)]);
    }
}
 
Example 6
Source File: DefaultHeaderTransformer.java    From AndroidPullMenu with Apache License 2.0 5 votes vote down vote up
protected int getActionBarSize(Context context) {
    int[] attrs = {android.R.attr.actionBarSize};
    TypedArray values = context.getTheme().obtainStyledAttributes(attrs);
    try {
        return values.getDimensionPixelSize(0, 0);
    } finally {
        values.recycle();
    }
}
 
Example 7
Source File: SelectorInjection.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
public SelectorInjection(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SelectorInjection);

    isSmart = a.getBoolean(R.styleable.SelectorInjection_isSmart, true);

    normal = a.getDrawable(R.styleable.SelectorInjection_normalDrawable);
    pressed = a.getDrawable(R.styleable.SelectorInjection_pressedDrawable);
    checked = a.getDrawable(R.styleable.SelectorInjection_checkedDrawable);

    normalColor = getColor(a, R.styleable.SelectorInjection_normalColor);
    pressedColor = getColor(a, R.styleable.SelectorInjection_pressedColor);
    checkedColor = getColor(a, R.styleable.SelectorInjection_checkedColor);

    normalStrokeColor = getColor(a, R.styleable.SelectorInjection_normalStrokeColor);
    normalStrokeWidth = a.getDimensionPixelSize(R.styleable.SelectorInjection_normalStrokeWidth, DEFAULT_STROKE_WIDTH);

    pressedStrokeColor = getColor(a, R.styleable.SelectorInjection_pressedStrokeColor);
    pressedStrokeWidth = a.getDimensionPixelOffset(R.styleable.SelectorInjection_pressedStrokeWidth, DEFAULT_STROKE_WIDTH);

    checkedStrokeColor = getColor(a, R.styleable.SelectorInjection_checkedStrokeColor);
    checkedStrokeWidth = a.getDimensionPixelSize(R.styleable.SelectorInjection_checkedStrokeWidth, DEFAULT_STROKE_WIDTH);

    isSrc = a.getBoolean(R.styleable.SelectorInjection_isSrc, false);

    showRipple = a.getBoolean(R.styleable.SelectorInjection_showRipple, true);
    a.recycle();
}
 
Example 8
Source File: SwipeBackLayout.java    From imsdk-android with MIT License 5 votes vote down vote up
public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeBackLayout, defStyle,
            R.style.SwipeBackLayout);

    int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1);
    if (edgeSize > 0)
        setEdgeSize(edgeSize);
    int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)];
    setEdgeTrackingEnabled(mode);

    int shadowLeft = a.getResourceId(R.styleable.SwipeBackLayout_shadow_left,
            R.drawable.atom_ui_shadow_left);
    int shadowRight = a.getResourceId(R.styleable.SwipeBackLayout_shadow_right,
            R.drawable.atom_ui_shadow_right);
    int shadowBottom = a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom,
            R.drawable.atom_ui_shadow_bottom);
    setShadow(shadowLeft, EDGE_LEFT);
    setShadow(shadowRight, EDGE_RIGHT);
    setShadow(shadowBottom, EDGE_BOTTOM);
    a.recycle();
    final float density = getResources().getDisplayMetrics().density;
    final float minVel = MIN_FLING_VELOCITY * density;
    mDragHelper.setMinVelocity(minVel);
    mDragHelper.setMaxVelocity(minVel * 2f);
}
 
Example 9
Source File: AttrUtil.java    From KlyphMessenger with MIT License 5 votes vote down vote up
public static int getPixelDimension(Context context, int attr)
{
	TypedArray ta = context.obtainStyledAttributes(new int[] { attr });
	int dimension = ta.getDimensionPixelSize(0, 0);
	ta.recycle();
	
	return dimension;
}
 
Example 10
Source File: OpacityBar.java    From BlunoAccessoryShieldDemo with GNU General Public License v3.0 5 votes vote down vote up
private void init(AttributeSet attrs, int defStyle) {
	final TypedArray a = getContext().obtainStyledAttributes(attrs,
			R.styleable.ColorBars, defStyle, 0);
	final Resources b = getContext().getResources();

	mBarThickness = a.getDimensionPixelSize(
			R.styleable.ColorBars_bar_thickness,
			b.getDimensionPixelSize(R.dimen.bar_thickness));
	mBarLength = a.getDimensionPixelSize(R.styleable.ColorBars_bar_length,
			b.getDimensionPixelSize(R.dimen.bar_length));
	mPreferredBarLength = mBarLength;
	mBarPointerRadius = a.getDimensionPixelSize(
			R.styleable.ColorBars_bar_pointer_radius,
			b.getDimensionPixelSize(R.dimen.bar_pointer_radius));
	mBarPointerHaloRadius = a.getDimensionPixelSize(
			R.styleable.ColorBars_bar_pointer_halo_radius,
			b.getDimensionPixelSize(R.dimen.bar_pointer_halo_radius));

	a.recycle();

	mBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mBarPaint.setShader(shader);

	mBarPointerPosition = mBarLength + mBarPointerHaloRadius;

	mBarPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mBarPointerHaloPaint.setColor(Color.BLACK);
	mBarPointerHaloPaint.setAlpha(0x50);

	mBarPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mBarPointerPaint.setColor(0xff81ff00);

	mPosToOpacFactor = 0xFF / ((float) mBarLength);
	mOpacToPosFactor = ((float) mBarLength) / 0xFF;
}
 
Example 11
Source File: BadgedFourThreeImageView.java    From Protein with Apache License 2.0 5 votes vote down vote up
public BadgedFourThreeImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    badge = new GifBadge(context);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BadgedFourThreeImageView, 0, 0);
    badgeGravity = a.getInt(R.styleable.BadgedFourThreeImageView_badgeGravity, Gravity.END | Gravity
            .BOTTOM);
    badgePadding = a.getDimensionPixelSize(R.styleable.BadgedFourThreeImageView_badgePadding, 0);
    a.recycle();

}
 
Example 12
Source File: EmojiTextView.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public EmojiTextView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EmojiTextView, 0, 0);
  scaleEmojis = a.getBoolean(R.styleable.EmojiTextView_scaleEmojis, false);
  maxLength   = a.getInteger(R.styleable.EmojiTextView_emoji_maxLength, -1);
  forceCustom = a.getBoolean(R.styleable.EmojiTextView_emoji_forceCustom, false);
  a.recycle();

  a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.textSize});
  originalFontSize = a.getDimensionPixelSize(0, 0);
  a.recycle();
}
 
Example 13
Source File: ShapeImageView.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs){
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ShapeImageView);
    mFormat = typedArray.getInt(R.styleable.ShapeImageView_format, 1);
    mRadius = typedArray.getDimensionPixelSize(R.styleable.ShapeImageView_radius, 0);
    mCorners = typedArray.getDimensionPixelSize(R.styleable.ShapeImageView_corners, 0);
    typedArray.recycle();
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
}
 
Example 14
Source File: IcsLinearLayout.java    From Klyph with MIT License 5 votes vote down vote up
public IcsLinearLayout(Context context, int themeAttr) {
    super(context);

    TypedArray a = context.obtainStyledAttributes(null, LL, themeAttr, 0);
    setDividerDrawable(a.getDrawable(IcsLinearLayout.LL_DIVIDER));
    mDividerPadding = a.getDimensionPixelSize(LL_DIVIDER_PADDING, 0);
    mShowDividers = a.getInteger(LL_SHOW_DIVIDER, SHOW_DIVIDER_NONE);
    a.recycle();
}
 
Example 15
Source File: NetworkStateView.java    From NetworkStateView with Apache License 2.0 5 votes vote down vote up
public NetworkStateView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NetworkStateView, defStyleAttr, R.style.NetworkStateView_Style);

    mLoadingViewId = typedArray.getResourceId(R.styleable.NetworkStateView_loadingView, R.layout.view_loading);

    mErrorViewId = typedArray.getResourceId(R.styleable.NetworkStateView_errorView, R.layout.view_network_error);
    mErrorImageId = typedArray.getResourceId(R.styleable.NetworkStateView_nsvErrorImage, NO_ID);
    mErrorText = typedArray.getString(R.styleable.NetworkStateView_nsvErrorText);

    mNoNetworkViewId = typedArray.getResourceId(R.styleable.NetworkStateView_noNetworkView, R.layout.view_no_network);
    mNoNetworkImageId = typedArray.getResourceId(R.styleable.NetworkStateView_nsvNoNetworkImage, NO_ID);
    mNoNetworkText = typedArray.getString(R.styleable.NetworkStateView_nsvNoNetworkText);

    mEmptyViewId = typedArray.getResourceId(R.styleable.NetworkStateView_emptyView, R.layout.view_empty);
    mEmptyImageId = typedArray.getResourceId(R.styleable.NetworkStateView_nsvEmptyImage, NO_ID);
    mEmptyText = typedArray.getString(R.styleable.NetworkStateView_nsvEmptyText);

    mRefreshViewId = typedArray.getResourceId(R.styleable.NetworkStateView_nsvRefreshImage, NO_ID);

    mTextColor = typedArray.getColor(R.styleable.NetworkStateView_nsvTextColor, 0x8a000000);
    mTextSize = typedArray.getDimensionPixelSize(R.styleable.NetworkStateView_nsvTextSize, UIUtils.dp2px(14));

    typedArray.recycle();

    mInflater = LayoutInflater.from(context);
    params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    setBackgroundColor(UIUtils.getColor(R.color.white));
}
 
Example 16
Source File: FlowLayout.java    From screenstandby with GNU General Public License v2.0 5 votes vote down vote up
private void readStyleParameters(Context context, AttributeSet attributeSet) {
    TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.FlowLayout);
    try {
        horizontalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_horizontalSpacing, 0);
        verticalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_verticalSpacing, 0);
        orientation = a.getInteger(R.styleable.FlowLayout_orientation, HORIZONTAL);
        debugDraw = a.getBoolean(R.styleable.FlowLayout_debugDraw, false);
    } finally {
        a.recycle();
    }
}
 
Example 17
Source File: GpCollapsingToolbar.java    From GpCollapsingToolbar with Apache License 2.0 4 votes vote down vote up
@SuppressLint("PrivateResource")
public GpCollapsingToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    ThemeUtils.checkAppCompatTheme(context);

    mCollapsingTextHelper = new CollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.GpCollapsingToolbarLayout, defStyleAttr,
            R.style.Widget_Design_CollapsingToolbar);

    mCollapsingTextHelper.setExpandedTextGravity(
            a.getInt(R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleGravity,
            GravityCompat.START | Gravity.BOTTOM));

    mCollapsingTextHelper.setCollapsedTextGravity(
            a.getInt(R.styleable.GpCollapsingToolbarLayout_gp_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom =
            a.getDimensionPixelSize(R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleMarginStart)) {
        mExpandedMarginStart = a.getDimensionPixelSize(
                R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(
                R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleMarginEnd, 0);
    }
    if (a.hasValue(R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(
                R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleMarginTop, 0);
    }
    if (a.hasValue(R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a.getDimensionPixelSize(
                R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.GpCollapsingToolbarLayout_gp_titleEnabled, true);
    mGooglePlayBehaviour = a.getBoolean(R.styleable.GpCollapsingToolbarLayout_gp_marketStyledBehaviour, false);
    setTitle(a.getText(R.styleable.GpCollapsingToolbarLayout_gp_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.GpCollapsingToolbarLayout_gp_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.GpCollapsingToolbarLayout_gp_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.GpCollapsingToolbarLayout_gp_collapsedTitleTextAppearance, 0));
    }

    mScrimVisibleHeightTrigger = a.getDimensionPixelSize(
            R.styleable.GpCollapsingToolbarLayout_gp_scrimVisibleHeightTrigger, 0);

    mScrimAnimationDuration = a.getInt(
            R.styleable.GpCollapsingToolbarLayout_gp_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    setContentScrim(a.getDrawable(R.styleable.GpCollapsingToolbarLayout_gp_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.GpCollapsingToolbarLayout_gp_statusBarScrim));

    mToolbarId = a.getResourceId(R.styleable.GpCollapsingToolbarLayout_gp_toolbarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    return setWindowInsets(insets);
                }
            });
}
 
Example 18
Source File: DkDropDownMenu.java    From DoraemonKit with Apache License 2.0 4 votes vote down vote up
public DkDropDownMenu(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    setOrientation(VERTICAL);

    //为DkDropDownMenu添加自定义属性
    int menuBackgroundColor = 0xffffffff;
    int underlineColor = 0xffcccccc;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DkDropDownMenu);
    underlineColor = a.getColor(R.styleable.DkDropDownMenu_dk_ddunderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.DkDropDownMenu_dk_dddividerColor, dividerColor);
    textSelectedColor = a.getColor(R.styleable.DkDropDownMenu_dk_ddtextSelectedColor,
            textSelectedColor);
    textUnselectedColor = a.getColor(R.styleable.DkDropDownMenu_dk_ddtextUnselectedColor,
            textUnselectedColor);
    menuBackgroundColor = a.getColor(R.styleable.DkDropDownMenu_dk_ddmenuBackgroundColor,
            menuBackgroundColor);
    maskColor = a.getColor(R.styleable.DkDropDownMenu_dk_ddmaskColor, maskColor);
    menuTextSize = a.getDimensionPixelSize(R.styleable.DkDropDownMenu_dk_ddmenuTextSize,
            menuTextSize);
    dividerHeight = a.getDimensionPixelSize(R.styleable.DkDropDownMenu_dk_dddividerHeight, ViewGroup.LayoutParams.MATCH_PARENT);
    menuSelectedIcon = a.getResourceId(R.styleable.DkDropDownMenu_dk_ddmenuSelectedIcon,
            menuSelectedIcon);
    menuUnselectedIcon = a.getResourceId(R.styleable.DkDropDownMenu_dk_ddmenuUnselectedIcon,
            menuUnselectedIcon);
    iconOrientation = a.getInt(R.styleable.DkDropDownMenu_dk_ddmenuIconOrientation, iconOrientation);
    a.recycle();
    //初始化位置参数
    mOrientation = new Orientation(getContext());
    mOrientation.init(iconOrientation, menuSelectedIcon, menuUnselectedIcon);

    //初始化tabMenuView并添加到tabMenuView
    tabMenuView = new LinearLayout(context);
    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup
            .LayoutParams.WRAP_CONTENT);
    tabMenuView.setOrientation(HORIZONTAL);
    tabMenuView.setBackgroundColor(menuBackgroundColor);
    tabMenuView.setLayoutParams(params);
    addView(tabMenuView, 0);

    //为tabMenuView添加下划线
    View underLine = new View(getContext());
    underLine.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            dpTpPx(1.0f)));
    underLine.setBackgroundColor(underlineColor);
    addView(underLine, 1);

    //初始化containerView并将其添加到DkDropDownMenu
    containerView = new FrameLayout(context);
    containerView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams
            .MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
    addView(containerView, 2);


}
 
Example 19
Source File: AnimatedPullToRefreshLayout.java    From AnimatedPullToRefresh-master with Apache License 2.0 4 votes vote down vote up
public AnimatedPullToRefreshLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    setWillNotDraw(false);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedPullToRefreshLayout);
    if (a != null) {
        String headerText = a.getString(R.styleable.AnimatedPullToRefreshLayout_headerText);
        int headerTextSize = a.getDimensionPixelSize(R.styleable.AnimatedPullToRefreshLayout_headerTextSize, (int) getResources().getDimension(R.dimen.headerTextSize));
        int headerTextColor = a.getColor(R.styleable.AnimatedPullToRefreshLayout_headerTextColor, getColor(android.R.color.darker_gray));
        int headerBackgroundColor = a.getColor(R.styleable.AnimatedPullToRefreshLayout_headerBackgroundColor, getColor(android.R.color.transparent));
        HeaderAnimSpeed headerAnimSpeed = HeaderAnimSpeed.fromId(a.getInt(R.styleable.AnimatedPullToRefreshLayout_animationSpeed, HeaderAnimSpeed.FAST.getSpeed()));
        HeaderTextAnim headerTextAnim = HeaderTextAnim.fromId(a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerTextAnimation, HeaderTextAnim.ROTATE_CW.getAnimType()));
        HeaderLoopAnim headerLoopAnim = HeaderLoopAnim.fromId(a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerLoopAnimation, HeaderLoopAnim.ZOOM.getAnimType()));
        int headerTextAnimIteration = a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerTextAnimIteration, HeaderTextAnim.ROTATE_CW.getAnimType());
        int headerLoopAnimIteration = a.getInt(R.styleable.AnimatedPullToRefreshLayout_headerLoopAnimIteration, HeaderLoopAnim.ZOOM.getAnimType());
        boolean isColorAnimEnabled = a.getBoolean(R.styleable.AnimatedPullToRefreshLayout_headerTextColorAnimationEnabled, true);
        Typeface mTitleTypeface = null;
        //Font
        if (a.hasValue(R.styleable.AnimatedPullToRefreshLayout_headerTextFontFamily)) {
            int fontId = a.getResourceId(R.styleable.AnimatedPullToRefreshLayout_headerTextFontFamily, -1);
            if (fontId != -1)
                mTitleTypeface = ResourcesCompat.getFont(context, fontId);
        }

        a.recycle();

        if (isInEditMode())
            return;

        // adding header layout : important
        headerView = new CharacterAnimatorHeaderView(getContext());
        headerView.setHeaderText(headerText);
        headerView.setHeaderTextSize(headerTextSize);
        headerView.setHeaderTextColor(headerTextColor);
        headerView.setHeaderBackgroundColor(headerBackgroundColor);
        headerView.setHeaderTextAnim(headerTextAnim);
        headerView.setHeaderLoopAnim(headerLoopAnim);
        headerView.setHeaderTextAnimIteration(headerTextAnimIteration);
        headerView.setHeaderLoopAnimIteration(headerLoopAnimIteration);
        headerView.setColorAnimEnable(isColorAnimEnabled);
        headerView.setAnimationSpeed(headerAnimSpeed);
        headerView.setHeaderTextTypeface(mTitleTypeface);

        setHeaderView(headerView);
    }

}
 
Example 20
Source File: AccentSwitch.java    From holoaccent with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a new Switch with a default style determined by the given theme
 * attribute, overriding specific style attributes as requested.
 * 
 * @param context
 *            The Context that will determine this widget's theming.
 * @param attrs
 *            Specification of attributes that should deviate from the
 *            default styling.
 * @param defStyle
 *            An attribute ID within the active theme containing a reference
 *            to the default style for this widget. e.g.
 *            android.R.attr.switchStyle.
 */
public AccentSwitch(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);

	mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
	Resources res = getResources();
	mTextPaint.density = res.getDisplayMetrics().density;

	// mTextPaint.setCompatibilityScaling(res.getCompatibilityInfo().applicationScale);

	TypedArray a = context.obtainStyledAttributes(attrs,
			R.styleable.AccentSwitch, defStyle, 0);

	mThumbDrawable = a.getDrawable(R.styleable.AccentSwitch_android_thumb);
	if (mThumbDrawable == null)
		mThumbDrawable = getDefaultThumbDrawable();
	
	mTrackDrawable = a.getDrawable(R.styleable.AccentSwitch_android_track);
	if (mTrackDrawable == null)
		mTrackDrawable = getDefaultTrackDrawable();
	
	mTextOn = a.getText(R.styleable.AccentSwitch_android_textOn);
	if (mTextOn == null)
		mTextOn = getDefaultOnString();
	
	mTextOff = a.getText(R.styleable.AccentSwitch_android_textOff);
	if (mTextOff == null)
		mTextOff = getDefaultOffString();
	
	DisplayMetrics metrics = getResources().getDisplayMetrics();
	
	mThumbTextPadding = a.getDimensionPixelSize(
			R.styleable.AccentSwitch_android_thumbTextPadding, 
			(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, metrics));
	mSwitchMinWidth = a.getDimensionPixelSize(
			R.styleable.AccentSwitch_android_switchMinWidth, 
			(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 96, metrics));
	mSwitchPadding = a.getDimensionPixelSize(
			R.styleable.AccentSwitch_android_switchPadding, 
			(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, metrics));

	int appearance = a.getResourceId(
			R.styleable.AccentSwitch_android_switchTextAppearance, R.style.TextAppearance_HoloAccent_Switch);
	if (appearance != 0) {
		setSwitchTextAppearance(context, appearance);
	}
	a.recycle();

	ViewConfiguration config = ViewConfiguration.get(context);
	mTouchSlop = config.getScaledTouchSlop();
	mMinFlingVelocity = config.getScaledMinimumFlingVelocity();

	// Refresh display with current params
	refreshDrawableState();
	setChecked(isChecked());

	// to work this switch has to have an OnClickListener
	this.setOnClickListener(new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			// do nothing
		}
	});
}