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:android.support.v7.internal.view.menu.ActionMenuItemView.java

public ActionMenuItemView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    final Resources res = context.getResources();
    mAllowTextWithIcon = res.getBoolean(R.bool.abc_config_allowActionMenuItemTextWithIcon);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionMenuItemView, defStyle, 0);
    mMinWidth = a.getDimensionPixelSize(R.styleable.ActionMenuItemView_android_minWidth, 0);
    a.recycle();//ww  w .j  av  a 2s  .c o  m

    final float density = res.getDisplayMetrics().density;
    mMaxIconSize = (int) (MAX_ICON_SIZE * density + 0.5f);

    setOnClickListener(this);
    setOnLongClickListener(this);

    mSavedPaddingLeft = -1;
}

From source file:com.hadis.mylunbo.carrousel.CircleIndicator.java

private void handleTypedArray(Context context, AttributeSet attrs) {
    if (attrs == null) {
        return;//from  w  w  w . ja v a2  s. c om
    }

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleIndicator);
    mIndicatorWidth = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_width, -1);
    mIndicatorHeight = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_height, -1);
    mIndicatorMargin = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_margin, -1);

    mAnimatorResId = typedArray.getResourceId(R.styleable.CircleIndicator_ci_animator,
            R.animator.scale_with_alpha);
    mAnimatorReverseResId = typedArray.getResourceId(R.styleable.CircleIndicator_ci_animator_reverse, 0);
    mIndicatorBackgroundResId = typedArray.getResourceId(R.styleable.CircleIndicator_ci_drawable,
            R.drawable.white_radius);
    mIndicatorUnselectedBackgroundResId = typedArray
            .getResourceId(R.styleable.CircleIndicator_ci_drawable_unselected, mIndicatorBackgroundResId);

    int orientation = typedArray.getInt(R.styleable.CircleIndicator_ci_orientation, -1);
    setOrientation(orientation == VERTICAL ? VERTICAL : HORIZONTAL);

    int gravity = typedArray.getInt(R.styleable.CircleIndicator_ci_gravity, -1);
    setGravity(gravity >= 0 ? gravity : Gravity.CENTER);

    typedArray.recycle();
}

From source file:com.playground.notification.app.activities.AppActivity.java

/**
 * Calculate height of actionbar./*  www .j a v a 2 s . c  o m*/
 */
protected void calcAppBarHeight() {
    int[] abSzAttr;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        abSzAttr = new int[] { android.R.attr.actionBarSize };
    } else {
        abSzAttr = new int[] { R.attr.actionBarSize };
    }
    TypedArray a = obtainStyledAttributes(abSzAttr);
    mAppBarHeight = a.getDimensionPixelSize(0, -1);
}

From source file:android.support.v7.app.DrawerLayoutActivity.java

@Override
protected void onContentViewSet() {
    super.onContentViewSet();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawer = (ListView) findViewById(R.id.start_drawer);
    mContent = (TextView) findViewById(R.id.content_text);

    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // The drawer title must be set in order to announce state changes when
    // accessibility is turned on. This is typically a simple description,
    // e.g. "Navigation".
    mDrawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.drawer_title));

    mDrawer.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Shakespeare.TITLES));
    mDrawer.setOnItemClickListener(new DrawerItemClickListener());

    // Find the toolbar in our layout and set it as the support action bar on the activity.
    // This is required to have the drawer slide "over" the toolbar.
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle(R.string.drawer_title);
    setSupportActionBar(mToolbar);/*from  w w  w  .  j a  v a2s  .  c o  m*/

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(false);

    // ActionBarDrawerToggle provides convenient helpers for tying together the
    // prescribed interactions between a top-level sliding drawer and the action bar.
    // Note that, as the Javadocs of ActionBarDrawerToggle constructors say, we are
    // *not* using a constructor that gets a Toolbar since we're setting our toolbar
    // dynamically at runtime. Furthermore, as the drawer is sliding over the toolbar,
    // we are suppressing the morphing animation from hamburger to back arrow by
    // calling super.onDrawerSlide with slideOffset=0.0f. In case your app only has
    // top-level pages and doesn't need back arrow visuals at all, you can set up
    // your activity theme to have attribute named "drawerArrowStyle" that points
    // to an extension of Widget.AppCompat.DrawerArrowToggle that has its "spinBars"
    // attribute set to false.
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open,
            R.string.drawer_close) {
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            super.onDrawerSlide(drawerView, 0.0f);
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, 0.0f);
        }
    };

    mDrawerLayout.addDrawerListener(mDrawerToggle);

    // Configure the background color fill of the system status bar (on supported platform
    // versions) and the toolbar itself. We're using the same color, and android:statusBar
    // from the theme makes the status bar slightly darker.
    final int metalBlueColor = getResources().getColor(R.color.drawer_sample_metal_blue);
    mDrawerLayout.setStatusBarBackgroundColor(metalBlueColor);
    mToolbar.setBackgroundColor(metalBlueColor);

    // Register a pre-draw listener to get the initial width of the DrawerLayout so
    // that we can determine the width of the drawer based on the Material spec at
    // https://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-specs
    mDrawerLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // What is the width of the entire DrawerLayout?
            final int drawerLayoutWidth = mDrawerLayout.getWidth();

            // What is the action bar size?
            final Resources.Theme theme = mDrawerLayout.getContext().getTheme();
            final TypedArray a = theme
                    .obtainStyledAttributes(new int[] { android.support.v7.appcompat.R.attr.actionBarSize });
            final int actionBarSize = a.getDimensionPixelSize(0, 0);
            if (a != null) {
                a.recycle();
            }

            // Compute the width of the drawer and set it on the layout params.
            final int idealDrawerWidth = 5 * actionBarSize;
            final int maxDrawerWidth = Math.max(0, drawerLayoutWidth - actionBarSize);
            final int drawerWidth = Math.min(idealDrawerWidth, maxDrawerWidth);

            final DrawerLayout.LayoutParams drawerLp = (DrawerLayout.LayoutParams) mDrawer.getLayoutParams();
            drawerLp.width = drawerWidth;
            mDrawer.setLayoutParams(drawerLp);

            // Remove ourselves as the pre-draw listener since this is a one-time
            // configuration.
            mDrawerLayout.getViewTreeObserver().removeOnPreDrawListener(this);
            return true;
        }
    });
}

From source file:com.hirebuddy.util.CircleImageView.java

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

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

    mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH);
    mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color,
            getResources().getColor(R.color.yellow));
    mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY);
    mFillColor = a.getColor(R.styleable.CircleImageView_civ_fill_color, DEFAULT_FILL_COLOR);

    a.recycle();//  w  w w .  ja  va  2  s .c om

    init();
}

From source file:com.github.jorgecastilloprz.FABProgressCircle.java

private void setupInitialAttributes(AttributeSet attrs) {
    if (attrs != null) {
        TypedArray attrArray = getAttributes(attrs);
        try {//ww  w .ja  v a  2  s. c  o  m
            arcColor = attrArray.getColor(R.styleable.FABProgressCircle_arcColor,
                    getResources().getColor(R.color.fab_orange_dark));
            arcWidth = attrArray.getDimensionPixelSize(R.styleable.FABProgressCircle_arcWidth,
                    getResources().getDimensionPixelSize(R.dimen.progress_arc_stroke_width));
            completeIconDrawable = attrArray.getDrawable(R.styleable.FABProgressCircle_finalIcon);
            circleSize = attrArray.getInt(R.styleable.FABProgressCircle_circleSize, 1);
            roundedStroke = attrArray.getBoolean(R.styleable.FABProgressCircle_roundedStroke, false);
            reusable = attrArray.getBoolean(R.styleable.FABProgressCircle_reusable, false);
        } finally {
            attrArray.recycle();
        }
    }
}

From source file:com.linroid.pushapp.view.ContentLoaderView.java

private void initAttrs(Context ctx, AttributeSet attr) {
    TypedArray ta = ctx.obtainStyledAttributes(attr, R.styleable.ContentLoaderView);
    padding = ta.getDimensionPixelSize(R.styleable.ContentLoaderView_android_padding, -1);
    paddingLeft = ta.getDimensionPixelSize(R.styleable.ContentLoaderView_android_paddingLeft, -1);
    paddingRight = ta.getDimensionPixelSize(R.styleable.ContentLoaderView_android_paddingRight, -1);
    paddingTop = ta.getDimensionPixelSize(R.styleable.ContentLoaderView_android_paddingTop, -1);
    paddingBottom = ta.getDimensionPixelSize(R.styleable.ContentLoaderView_android_paddingBottom, -1);
    clipToPadding = ta.getBoolean(R.styleable.ContentLoaderView_android_clipToPadding, true);
    int errorViewId = ta.getResourceId(R.styleable.ContentLoaderView_errorView, R.layout.content_loader_error);
    int emptyViewId = ta.getResourceId(R.styleable.ContentLoaderView_emptyView, R.layout.content_loader_empty);
    int loadingViewId = ta.getResourceId(R.styleable.ContentLoaderView_loadingView,
            R.layout.content_loader_loading);
    int contentViewId = ta.getResourceId(R.styleable.ContentLoaderView_contentView,
            R.layout.content_loader_content);
    ta.recycle();/*w w w.  j  a  v a  2 s .c  om*/
    LayoutInflater inflater = LayoutInflater.from(ctx);

    errorView = inflater.inflate(errorViewId, this, false);
    emptyView = inflater.inflate(emptyViewId, this, false);
    loadingView = inflater.inflate(loadingViewId, this, false);
    contentView = inflater.inflate(contentViewId, this, false);
    addView(errorView);
    addView(emptyView);
    addView(loadingView);
    addView(contentView);
}

From source file:com.orange.ocara.ui.view.PagerSlidingTabStrip.java

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

    setWillNotDraw(false);//from w w w.  jav a  2s.  com

    DisplayMetrics dm = getResources().getDisplayMetrics();

    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.getColorStateList(1);

    a.recycle();

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

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_indicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_underlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_dividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_indicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_underlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_dividerPaddingTabStrip,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_tabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_tabBackground, tabBackgroundResId);

    a.recycle();

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

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

    tabLayoutParams = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

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

    addView(tabsContainer, new LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
}

From source file:com.facebook.FacebookButtonBase.java

private void parseContentAttributes(final Context context, final AttributeSet attrs, final int defStyleAttr,
        final int defStyleRes) {
    final int attrsResources[] = { android.R.attr.paddingLeft, android.R.attr.paddingTop,
            android.R.attr.paddingRight, android.R.attr.paddingBottom, };
    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs, attrsResources, defStyleAttr,
            defStyleRes);//from  ww w.ja  va2s. co  m
    try {
        setPadding(a.getDimensionPixelSize(0, 0), a.getDimensionPixelSize(1, 0), a.getDimensionPixelSize(2, 0),
                a.getDimensionPixelSize(3, 0));
    } finally {
        a.recycle();
    }
}

From source file:com.gj.administrator.gjerp.view.CircleIndicator.java

private void handleTypedArray(Context context, AttributeSet attrs) {
    if (attrs == null)
        return;//from   ww w  . j  a  v a2  s.  c om
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleIndicator);
    mIndicatorRadius = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_radius,
            DEFAULT_INDICATOR_RADIUS);
    mIndicatorMargin = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_margin,
            DEFAULT_INDICATOR_MARGIN);
    mIndicatorBackground = typedArray.getColor(R.styleable.CircleIndicator_ci_background,
            DEFAULT_INDICATOR_BACKGROUND);
    mIndicatorSelectedBackground = typedArray.getColor(R.styleable.CircleIndicator_ci_selected_background,
            DEFAULT_INDICATOR_SELECTED_BACKGROUND);
    int gravity = typedArray.getInt(R.styleable.CircleIndicator_ci_gravity, DEFAULT_INDICATOR_LAYOUT_GRAVITY);
    mIndicatorLayoutGravity = Gravity.values()[gravity];
    int mode = typedArray.getInt(R.styleable.CircleIndicator_ci_mode, DEFAULT_INDICATOR_MODE);
    mIndicatorMode = Mode.values()[mode];
    typedArray.recycle();
}