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:Main.java

public static int getDimensionPixelSize(Activity activity, int attr, int defaultValue) {
    int[] attrs = new int[] { attr };
    TypedArray ta = activity.obtainStyledAttributes(attrs);
    int value = ta.getDimensionPixelSize(0, defaultValue);
    ta.recycle();//from  w  w  w. jav  a 2s  .  c o m
    return value;
}

From source file:Main.java

public static int getPixelDimension(Context context, int attr) {
    TypedArray ta = context.obtainStyledAttributes(new int[] { attr });
    int dimension = ta.getDimensionPixelSize(0, 0);
    ta.recycle();//from  w w w .  j a v  a2 s  . c o m

    return dimension;
}

From source file:Main.java

private static int resolveDimension(Context context, @AttrRes int attr, int fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr });
    try {/*from   ww  w  .j a  v  a2  s .c o  m*/
        return a.getDimensionPixelSize(0, fallback);
    } finally {
        a.recycle();
    }
}

From source file:com.marstemp.app.activities.MarsTempActivity.java

/**
 * Calculate height of actionbar./* w  w w  .  j a v  a2s . c om*/
 *
 * @return Height of system defined actionbar.
 */
public static int calcActionBarHeight(Context conte) {
    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 = conte.obtainStyledAttributes(abSzAttr);
    return a.getDimensionPixelSize(0, -1);
}

From source file:com.bilibili.magicasakura.utils.ThemeUtils.java

public static int getThemeAttrDimensionPixelSize(Context context, @AttrRes int attr) {
    TEMP_ARRAY[0] = attr;//www .  j a  v a  2 s.com
    TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY);
    try {
        return a.getDimensionPixelSize(0, 0);
    } finally {
        a.recycle();
    }
}

From source file:com.aaa.activity.main.BaseFragment.java

protected int getActionBarSize() {
    Activity activity = getActivity();/* w w w .j a va2  s  .c o m*/
    if (activity == null) {
        return 0;
    }
    TypedValue typedValue = new TypedValue();
    int[] textSizeAttr = new int[] { R.attr.actionBarSize };
    int indexOfAttrTextSize = 0;
    TypedArray a = activity.obtainStyledAttributes(typedValue.data, textSizeAttr);
    int actionBarSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1);
    a.recycle();
    return actionBarSize;
}

From source file:com.cnpaypal.ObservableScrollView.BaseActivity.java

protected int getActionBarSize() {
    TypedValue typedValue = new TypedValue();
    int[] textSizeAttr = new int[] { R.attr.actionBarSize };
    int indexOfAttrTextSize = 0;
    TypedArray a = obtainStyledAttributes(typedValue.data, textSizeAttr);
    int actionBarSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1);
    a.recycle();/*from  w  w  w .ja va  2s  .co m*/
    return actionBarSize;
}

From source file:com.gosuncn.core.ui.widget.ToolbarExtend.java

public ToolbarExtend(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ToolbarExtend);
    drawableSize = a.getDimensionPixelSize(R.styleable.ToolbarExtend_drawableSize, DEFAULT_SIZE);
    titleGravity = a.getInt(R.styleable.ToolbarExtend_titleGravity, DEFAULT_GRAVITY);

    a.recycle();// w  w w .j  av  a2  s.c  o  m

    resizeDrawable();
    changeTitleGravity();
}

From source file:android.support.design.internal.SnackbarContentLayout.java

public SnackbarContentLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackbarLayout);
    mMaxWidth = a.getDimensionPixelSize(R.styleable.SnackbarLayout_android_maxWidth, -1);
    mMaxInlineActionWidth = a.getDimensionPixelSize(R.styleable.SnackbarLayout_maxActionInlineWidth, -1);
    a.recycle();//www .  j  a v a 2 s  .  c  o m
}

From source file:com.ameron32.apps.tapnotes._trial.ui.MultiViewPager.java

private void init(Context context, AttributeSet attrs) {
    setClipChildren(false);//from www .j  a va 2  s.com
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MultiViewPager);
    setMaxWidth(ta.getDimensionPixelSize(R.styleable.MultiViewPager_android_maxWidth, -1));
    setMaxHeight(ta.getDimensionPixelSize(R.styleable.MultiViewPager_android_maxHeight, -1));
    setMatchChildWidth(ta.getResourceId(R.styleable.MultiViewPager_matchChildWidth, 0));
    ta.recycle();
}