Example usage for android.content Context getTheme

List of usage examples for android.content Context getTheme

Introduction

In this page you can find the example usage for android.content Context getTheme.

Prototype

@ViewDebug.ExportedProperty(deepExport = true)
public abstract Resources.Theme getTheme();

Source Link

Document

Return the Theme object associated with this Context.

Usage

From source file:Main.java

/**
 * get action bar height//from  w w  w  . j  a v a  2s.  c o  m
 *
 * @param context
 * @return
 */
public static int getActionBarHeight(Context context) {
    int actionBarHeight = 0;
    if (context instanceof Activity && ((Activity) context).getActionBar() != null) {
        actionBarHeight = ((Activity) context).getActionBar().getHeight();
    }

    if (actionBarHeight == 0) {
        final TypedValue tv = new TypedValue();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && (context.getTheme() != null
                && context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                    context.getResources().getDisplayMetrics());
        }
    }
    return actionBarHeight;
}

From source file:com.danimahardhika.android.helpers.core.ColorHelper.java

@ColorInt
public static int getAttributeColor(Context context, @AttrRes int attr) {
    if (context == null) {
        Log.e("ColorHelper", "getAttributeColor() context is null");
        return Color.WHITE;
    }//  w  w  w  . j a  v  a2  s.  com

    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = context.getTheme();
    theme.resolveAttribute(attr, typedValue, true);
    return typedValue.data;
}

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

public static boolean getBooleanFromAttribute(Context context, int attrId) {
    if (attrId == 0) {
        return false;
    }//from www .  java2 s  . c om
    TypedArray array = context.getTheme().obtainStyledAttributes(new int[] { R.attr.isLightTheme });
    return array.getBoolean(0, false);
}

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

public static int getColorFromAttribute(Context context, int attrId) {
    if (attrId == 0) {
        return 0;
    }//  w  w  w.  ja  va  2s  . c  o  m
    TypedValue a = new TypedValue();
    context.getTheme().resolveAttribute(attrId, a, true);
    return ContextCompat.getColor(context, a.resourceId);
}

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

public static float getFloatFromAttribute(Context context, int attrId) {
    if (attrId == 0) {
        return 0;
    }//w  ww  .j a  v  a 2s .c  om
    TypedValue a = new TypedValue();
    context.getTheme().resolveAttribute(attrId, a, true);
    return a.getFloat();
}

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

public static int getResourceIdFromAttribute(Context context, int attrId) {
    if (attrId == 0) {
        return 0;
    }/*from   ww w  .  j av  a 2 s  .co  m*/
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(attrId, typedValue, true);
    return typedValue.resourceId;
}

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

public static String getStringFromAttribute(Context context, int attrId) {
    if (attrId == 0) {
        return null;
    }//from www  .ja  v a  2s  .co m
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(attrId, typedValue, true);
    CharSequence result = typedValue.string;
    return !TextUtils.isEmpty(result) ? result.toString() : null;
}

From source file:com.vinexs.tool.Utility.java

/**
 * On Lollipop, grab system colorAccent attribute
 * pre-Lollipop, grab AppCompat colorAccent attribute
 * finally, check for custom mp_colorAccent attribute
 *
 * @param context Application context//from w ww  .  jav a2s  .co  m
 * @return accent color of current theme
 */
@TargetApi(LOLLIPOP)
public static int resolveAccentColor(Context context) {
    Resources.Theme theme = context.getTheme();
    int attr = SDK_INT >= LOLLIPOP ? android.R.attr.colorAccent : R.attr.colorAccent;
    TypedArray typedArray = theme.obtainStyledAttributes(new int[] { attr, R.attr.material_pref_color_accent });

    int accentColor = typedArray.getColor(0, Color.parseColor("#009688"));
    accentColor = typedArray.getColor(1, accentColor);
    typedArray.recycle();

    return accentColor;
}

From source file:com.nextgis.maplibui.util.ControlHelper.java

public static int getColor(Context context, int attr) {
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = context.getTheme();
    theme.resolveAttribute(attr, typedValue, true);
    return typedValue.data;
}

From source file:org.kontalk.util.SystemUtils.java

public static int getThemedResource(Context context, @AttrRes int attrResId) {
    TypedValue value = new TypedValue();
    if (!context.getTheme().resolveAttribute(attrResId, value, true))
        throw new Resources.NotFoundException();
    return value.resourceId;
}