Example usage for android.content.res TypedArray getDimension

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

Introduction

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

Prototype

public float getDimension(@StyleableRes int index, float defValue) 

Source Link

Document

Retrieve a dimensional unit attribute at index.

Usage

From source file:me.henrytao.mdcore.core.MdCompat.java

public static int getActionBarSize(Context context) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    int size = (int) a.getDimension(0, 0);
    a.recycle();/*  ww  w . ja  v  a  2  s  .  c om*/
    return size;
}

From source file:Main.java

public static int getDisplayHeight(Activity activity) {
    int height = 0;
    if (activity != null && activity.getWindowManager() != null
            && activity.getWindowManager().getDefaultDisplay() != null) {
        Point point = new Point();
        activity.getWindowManager().getDefaultDisplay().getSize(point);
        height = point.y;/*from   ww w .  j  av a  2 s  . com*/
    }

    Log.e(TAG, "isSupportSmartBar:" + isSupportSmartBar);

    if (isSupportSmartBar) {
        int smartBarHeight = getSmartBarHeight(activity);
        Log.e(TAG, "smartBarHeight:" + smartBarHeight);
        height -= smartBarHeight;
    }

    if (activity != null && activity.getActionBar() != null) {
        int actionbar = activity.getActionBar().getHeight();
        if (actionbar == 0) {
            TypedArray actionbarSizeTypedArray = activity
                    .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
            actionbar = (int) actionbarSizeTypedArray.getDimension(0, 0);
        }
        Log.d(TAG, "actionbar:" + actionbar);
        height -= actionbar;
    }

    int status = getStatusBarHeight(activity);
    Log.d(TAG, "status:" + status);

    height -= status;

    Log.d(TAG, "height:" + height);
    return height;
}

From source file:com.example.mediastock.util.Utilities.java

/**
 * Method used for the floating action button behaviour.
 *///from  w w  w . j a va 2  s  .  c  o m
public static int getToolbarHeight(Context context) {
    final TypedArray styledAttributes = context.getTheme()
            .obtainStyledAttributes(new int[] { R.attr.actionBarSize });
    int toolbarHeight = (int) styledAttributes.getDimension(0, 0);
    styledAttributes.recycle();

    return toolbarHeight;
}

From source file:com.cardvlaue.sys.util.ScreenUtil.java

public static int getDisplayHeight(AppCompatActivity activity) {
    int height = 0;
    if (activity != null && activity.getWindowManager() != null
            && activity.getWindowManager().getDefaultDisplay() != null) {
        Point point = new Point();
        activity.getWindowManager().getDefaultDisplay().getSize(point);
        height = point.y;/* w w w.ja  va2  s. c o  m*/
    }

    Log.e(TAG, "isSupportSmartBar:" + isSupportSmartBar);

    if (isSupportSmartBar) {
        int smartBarHeight = getSmartBarHeight(activity);
        Log.e(TAG, "smartBarHeight:" + smartBarHeight);
        height -= smartBarHeight;
    }

    if (activity.getSupportActionBar() != null) {
        int actionbar = activity.getSupportActionBar().getHeight();
        if (actionbar == 0) {
            TypedArray actionbarSizeTypedArray = activity
                    .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
            actionbar = (int) actionbarSizeTypedArray.getDimension(0, 0);
        }
        Log.d(TAG, "actionbar:" + actionbar);
        height -= actionbar;
    }

    int status = getStatusBarHeight(activity);
    Log.d(TAG, "status:" + status);

    height -= status;

    Log.d(TAG, "height:" + height);
    return height;
}

From source file:io.github.hidroh.materialistic.AppUtils.java

public static float getDimension(Context context, @StyleRes int styleResId, @AttrRes int attr) {
    TypedArray a = context.getTheme().obtainStyledAttributes(styleResId, new int[] { attr });
    float size = a.getDimension(0, 0);
    a.recycle();/*from   w ww  .j  a v  a  2 s  .co m*/
    return size;
}

From source file:com.amaze.carbonfilemanager.fragments.ZipViewer.java

public static int getToolbarHeight(Context context) {
    final TypedArray styledAttributes = context.getTheme()
            .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
    int toolbarHeight = (int) styledAttributes.getDimension(0, 0);
    styledAttributes.recycle();//w ww. j a  va2  s.  c om

    return toolbarHeight;
}

From source file:de.mrapp.android.util.ThemeUtil.java

/**
 * Obtains the dimension, which corresponds to a specific resource id, from a specific theme. If
 * the given resource id is invalid, a {@link NotFoundException} will be thrown.
 *
 * @param context//w  w w.jav a  2  s  .c om
 *         The context, which should be used, as an instance of the class {@link Context}. The
 *         context may not be null
 * @param themeResourceId
 *         The resource id of the theme, the attribute should be obtained from, as an {@link
 *         Integer} value or -1, if the attribute should be obtained from the given context's
 *         theme
 * @param resourceId
 *         The resource id of the attribute, which should be obtained, as an {@link Integer}
 *         value. The resource id must corresponds to a valid theme attribute
 * @return The dimension, which has been obtained, as a {@link Float} value
 */
public static float getDimension(@NonNull final Context context, @StyleRes final int themeResourceId,
        @AttrRes final int resourceId) {
    TypedArray typedArray = null;

    try {
        typedArray = obtainStyledAttributes(context, themeResourceId, resourceId);
        float dimension = typedArray.getDimension(0, -1);

        if (dimension == -1) {
            throw new NotFoundException("Resource ID #0x" + Integer.toHexString(resourceId) + " is not valid");
        }

        return dimension;
    } finally {
        if (typedArray != null) {
            typedArray.recycle();
        }
    }
}

From source file:com.google.samples.apps.iosched.util.UIUtils.java

/**
 * Calculates the Action Bar height in pixels.
 *//*from w w w.  j a v a 2 s .c o m*/
public static int calculateActionBarSize(Context context) {
    if (context == null) {
        return 0;
    }

    Resources.Theme curTheme = context.getTheme();
    if (curTheme == null) {
        return 0;
    }

    TypedArray att = curTheme.obtainStyledAttributes(RES_IDS_ACTION_BAR_SIZE);
    if (att == null) {
        return 0;
    }

    float size = att.getDimension(0, 0);
    att.recycle();
    return (int) size;
}

From source file:de.vanita5.twittnuker.view.TwidereToolbar.java

public TwidereToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final TypedArray a = context.obtainStyledAttributes(attrs, new int[] { R.attr.elevation }, defStyleAttr, 0);
    ViewCompat.setElevation(this, a.getDimension(0, 0));
}

From source file:org.getlantern.firetweet.view.FiretweetToolbar.java

public FiretweetToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(getThemedContext(context, attrs, defStyleAttr), attrs, defStyleAttr);
    final TypedArray a = getContext().obtainStyledAttributes(attrs, new int[] { R.attr.elevation },
            defStyleAttr, 0);/*w w w.ja  v a  2  s . co m*/
    ViewCompat.setElevation(this, a.getDimension(0, 0));
    a.recycle();
}