package com.mobify.astro.utilities;

import android.app.Activity;
import android.util.TypedValue;

import com.mobify.astro.R;

/**
 * Created by karl on 2016-02-29.
 */
public class HeaderUtilities {

    // Returns the height of the action bar for the theme of the given activity (with a fallback)
    // in the format of dips (density-independent-pixels)
    public static int getActionBarHeight(Activity activity) {
        // Try to get the action bar's height from the theme's resources.
        TypedValue actionBarSizeTypedValue = new TypedValue();
        if (activity.getTheme().resolveAttribute(
                android.R.attr.actionBarSize, actionBarSizeTypedValue, true))
        {
            return TypedValue.complexToDimensionPixelSize(
                    actionBarSizeTypedValue.data, activity.getResources().getDisplayMetrics()
            );
        }

        // Fallback to hardcoded, reasonable dips.
        return (int) activity.getResources().getDimension(R.dimen.header_bar_fallback_height);
    }
}
