Example usage for android.content.res TypedArray getDimensionPixelSize

List of usage examples for android.content.res TypedArray getDimensionPixelSize

Introduction

In this page you can find the example usage for android.content.res TypedArray getDimensionPixelSize.

Prototype

public int getDimensionPixelSize(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieve a dimensional unit attribute at index for use as a size in raw pixels.

Usage

From source file:com.marshalchen.ultimaterecyclerview.ui.timelineview.TimelineView.java

private void init(AttributeSet attrs) {
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.timeline_style);
    mMarker = typedArray.getDrawable(R.styleable.timeline_style_tls_marker);
    mStartLine = typedArray.getDrawable(R.styleable.timeline_style_tls_line);
    mEndLine = typedArray.getDrawable(R.styleable.timeline_style_tls_line);
    mMarkerSize = typedArray.getDimensionPixelSize(R.styleable.timeline_style_tls_marker_size, 25);
    mLineSize = typedArray.getDimensionPixelSize(R.styleable.timeline_style_tls_line_size, 2);
    typedArray.recycle();// ww w.jav  a2s  .c  o  m

    if (mMarker == null) {
        mMarker = ContextCompat.getDrawable(mContext, R.drawable.timelinedefaultmarker);
    }
}

From source file:com.cheikh.lazywaimai.widget.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/* w w w .  jav a2 s.  c o m*/

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout);

    if (a.hasValue(R.styleable.SlidingTabLayout_indicatorHeight)) {
        mTabStrip.setSelectedIndicatorHeight(
                a.getDimensionPixelSize(R.styleable.SlidingTabLayout_indicatorHeight, 0));
    }

    if (a.hasValue(R.styleable.SlidingTabLayout_selectedColor)) {
        mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.SlidingTabLayout_selectedColor, 0));
    }

    mTabViewTextAppearance = a.getResourceId(R.styleable.SlidingTabLayout_android_textAppearance, 0);

    mTitleOffset = a.getDimensionPixelSize(R.styleable.SlidingTabLayout_contentInsetStart, mTitleOffset);

    mTabStrip.setPadding(mTitleOffset, 0, 0, 0);

    a.recycle();
}

From source file:com.peoit.twopointcf.ui.view.SlidingTabLayout.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/*w  w  w. j a va2  s  .c o m*/

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout);

    if (a.hasValue(R.styleable.SlidingTabLayout_indicatorHeight)) {
        mTabStrip.setSelectedIndicatorHeight(
                a.getDimensionPixelSize(R.styleable.SlidingTabLayout_indicatorHeight, 0));
    }

    if (a.hasValue(R.styleable.SlidingTabLayout_selectedColor)) {
        mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.SlidingTabLayout_selectedColor, 0));
    }

    mTabViewTextAppearance = a.getResourceId(R.styleable.SlidingTabLayout_android_textAppearance, 0);

    mTitleOffset = a.getDimensionPixelSize(R.styleable.SlidingTabLayout_contentInsetStart, mTitleOffset);

    mTabStrip.setPadding(mTitleOffset, 0, 0, 0);

    a.recycle();
}

From source file:com.github.johnpersano.supertoasts.demo.views.TabStrip.java

public TabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);/*w w  w  . j  a v  a2 s.co  m*/
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
    indicatorPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, indicatorPadding, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);

    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.TabStrip);

    indicatorColor = a.getColor(R.styleable.TabStrip_TabStripIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.TabStrip_TabStripUnderlineColor, underlineColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripIndicatorHeight, indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripUnderlineHeight, underlineHeight);
    tabPadding = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.TabStrip_TabStripTabBackground, tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.TabStrip_TabStripShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripScrollOffset, scrollOffset);
    tabSwitch = a.getBoolean(R.styleable.TabStrip_TabStripTabSwitch, tabSwitch);
    tabTextColor = a.getColor(R.styleable.TabStrip_TabStripActivateTextColor, tabTextColor);
    tabDeactivateTextColor = a.getColor(R.styleable.TabStrip_TabStripDeactivateTextColor,
            tabDeactivateTextColor);
    indicatorPadding = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripIndicatorPadding, indicatorPadding);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:bigshots.people_helping_people.scroll_iew_lib.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);// w  ww .  j  a  va2 s  .  com
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    indicatorColor = getResources().getColor(R.color.current_charity_color);
    underlineColor = indicatorColor;
    dividerColor = 0xffffffff;
    tabBackgroundResId = 0x00000000;

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:android.support.v7.widget.ActionBarContainer.java

public ActionBarContainer(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Set a transparent background so that we project appropriately.
    final Drawable bg = Build.VERSION.SDK_INT >= 21 ? new ActionBarBackgroundDrawableV21(this)
            : new ActionBarBackgroundDrawable(this);
    ViewCompat.setBackground(this, bg);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar);
    mBackground = a.getDrawable(R.styleable.ActionBar_background);
    mStackedBackground = a.getDrawable(R.styleable.ActionBar_backgroundStacked);
    mHeight = a.getDimensionPixelSize(R.styleable.ActionBar_height, -1);

    if (getId() == R.id.split_action_bar) {
        mIsSplit = true;//from   ww w.jav a2  s.  c  o  m
        mSplitBackground = a.getDrawable(R.styleable.ActionBar_backgroundSplit);
    }
    a.recycle();

    setWillNotDraw(mIsSplit ? mSplitBackground == null : mBackground == null && mStackedBackground == null);
}

From source file:com.irccloud.android.DrawerArrowDrawable.java

/**
 * @param context used to get the configuration for the drawable from
 *//*from  w  w  w.  ja v a2s.  c  o  m*/
public DrawerArrowDrawable(Activity context) {
    final TypedArray typedArray = context.getTheme().obtainStyledAttributes(null, R.styleable.DrawerArrowToggle,
            R.attr.drawerArrowStyle, R.style.Base_Widget_AppCompat_DrawerArrowToggle);
    mContext = context;
    mPaint.setAntiAlias(true);
    mPaint.setColor(typedArray.getColor(R.styleable.DrawerArrowToggle_color, 0));
    mSize = typedArray.getDimensionPixelSize(R.styleable.DrawerArrowToggle_drawableSize, 0);
    mBarSize = typedArray.getDimension(R.styleable.DrawerArrowToggle_barSize, 0);
    mTopBottomArrowSize = typedArray.getDimension(R.styleable.DrawerArrowToggle_topBottomBarArrowSize, 0);
    mBarThickness = typedArray.getDimension(R.styleable.DrawerArrowToggle_thickness, 0);
    mBarGap = typedArray.getDimension(R.styleable.DrawerArrowToggle_gapBetweenBars, 0);
    mSpin = typedArray.getBoolean(R.styleable.DrawerArrowToggle_spinBars, true);
    mMiddleArrowSize = typedArray.getDimension(R.styleable.DrawerArrowToggle_middleBarArrowSize, 0);
    typedArray.recycle();

    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.SQUARE);
    mPaint.setStrokeWidth(mBarThickness);
}

From source file:com.baoyz.bigbang.BigBangLayout.java

private void readAttribute(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.BigBangLayout);
        mItemSpace = typedArray.getDimensionPixelSize(R.styleable.BigBangLayout_itemSpace,
                getResources().getDimensionPixelSize(R.dimen.big_bang_default_item_space));
        mLineSpace = typedArray.getDimensionPixelSize(R.styleable.BigBangLayout_lineSpace,
                getResources().getDimensionPixelSize(R.dimen.big_bang_default_line_space));
        typedArray.recycle();/*from  w  ww .  ja v a  2s .c  o  m*/
        mActionBarBottomHeight = mLineSpace;
        mActionBarTopHeight = getResources().getDimensionPixelSize(R.dimen.big_bang_action_bar_height);
    }

    // TODO 
    mActionBar = new BigBangActionBar(getContext());
    mActionBar.setVisibility(View.GONE);
    mActionBar.setActionListener(this);

    addView(mActionBar, 0);

    setClipChildren(false);

    mScaledTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
}

From source file:com.nxt.njitong.page.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);//from ww  w.  ja va 2s. c om
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);

    int dividerWidth = 1;
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:android.support.design.widget.NavigationDrawerView.java

public NavigationDrawerView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    // Custom attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NavigationDrawerView, defStyleAttr,
            R.style.Widget_Design_NavigationDrawerView);

    //noinspection deprecation
    setBackgroundDrawable(a.getDrawable(R.styleable.NavigationDrawerView_android_background));
    ViewCompat.setElevation(this,
            a.getDimensionPixelSize(R.styleable.NavigationDrawerView_android_elevation, 0));
    ViewCompat.setFitsSystemWindows(this,
            a.getBoolean(R.styleable.NavigationDrawerView_android_fitsSystemWindows, false));
    mMaxWidth = a.getDimensionPixelSize(R.styleable.NavigationDrawerView_android_maxWidth, 0);
    a.recycle();/*from   www  .  java 2s .c  om*/

    // Set up the menu
    mMenu = new MenuBuilder(context);
    mMenu.setCallback(new MenuBuilder.Callback() {
        @Override
        public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
            return mListener != null && mListener.onNavigationItemSelected(item);
        }

        @Override
        public void onMenuModeChange(MenuBuilder menu) {

        }
    });
    mPresenter = new NavigationMenuPresenter();
    mPresenter.setId(PRESENTER_NAVIGATION_DRAWER_VIEW);
    mPresenter.initForMenu(context, mMenu);
    mMenu.addMenuPresenter(mPresenter);
    addView((View) mPresenter.getMenuView(this));
}