Example usage for android.content.res TypedArray getDrawable

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

Introduction

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

Prototype

@Nullable
public Drawable getDrawable(@StyleableRes int index) 

Source Link

Document

Retrieve the Drawable for the attribute at index.

Usage

From source file:Main.java

public static Drawable getDrawable(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex) {
    Drawable val = a.getDrawable(index);
    if (val == null) {
        return a.getDrawable(fallbackIndex);
    }// w ww.j av a2 s.  c  o  m
    return val;
}

From source file:Main.java

public static Drawable getThemeUpIndicator(Object info, Activity activity) {
    final TypedArray a = activity.obtainStyledAttributes(THEME_ATTRS);
    final Drawable result = a.getDrawable(0);
    a.recycle();//from   ww  w .  j a v  a  2  s  .  com
    return result;
}

From source file:Main.java

public static Drawable resolveDrawable(Context context, int attr, Drawable fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr });
    try {/*  w w  w .j  a  v  a2  s.c  o  m*/
        Drawable d = a.getDrawable(0);
        if (d == null && fallback != null)
            d = fallback;
        return d;
    } finally {
        a.recycle();
    }
}

From source file:Main.java

private static Drawable resolveDrawable(Context context, @AttrRes int attr,
        @SuppressWarnings("SameParameterValue") Drawable fallback) {
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { attr });
    try {//  w  w w.  ja  v a2  s  . co m
        Drawable d = a.getDrawable(0);
        if (d == null && fallback != null)
            d = fallback;
        return d;
    } finally {
        a.recycle();
    }
}

From source file:Main.java

public static Drawable getActionBarBackground(Context context) {
    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true);
    TypedArray typedArray = context.obtainStyledAttributes(outValue.resourceId,
            new int[] { android.R.attr.background });
    Drawable background = typedArray.getDrawable(0);
    typedArray.recycle();/*from   w  ww  .  j ava 2 s  .  c  om*/
    return background;
}

From source file:Main.java

public static Drawable getSplitActionBarBackground(Context context) {
    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true);
    TypedArray typedArray = context.obtainStyledAttributes(outValue.resourceId,
            new int[] { android.R.attr.backgroundSplit });
    Drawable background = typedArray.getDrawable(0);
    typedArray.recycle();//ww w  . ja va2  s.  c om
    return background;
}

From source file:com.sherlock.navigationdrawer.compat.SherlockActionBarDrawerToggleCompat.java

public static Drawable getThemeUpIndicator(Activity activity) {
    final TypedArray a = activity.obtainStyledAttributes(THEME_ATTRS);
    final Drawable result = a.getDrawable(0);
    a.recycle();/*from   w  ww . j ava  2 s.  co m*/
    return result;
}

From source file:com.stfalcon.chatkit.messages.MessageInputStyle.java

static MessageInputStyle parse(Context context, AttributeSet attrs) {
    MessageInputStyle style = new MessageInputStyle(context, attrs);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MessageInput);

    style.inputButtonBackground = typedArray.getDrawable(R.styleable.MessageInput_inputButtonBackground);
    if (style.inputButtonBackground == null) {
        style.inputButtonBackground = ContextCompat.getDrawable(context, R.drawable.selector_bg_send);
    }//from   w w w  .  jav  a 2  s  . c o  m
    style.inputButtonIcon = typedArray.getDrawable(R.styleable.MessageInput_inputButtonIcon);
    if (style.inputButtonIcon == null) {
        style.inputButtonIcon = ContextCompat.getDrawable(context, R.drawable.selector_icon_send);
    }
    style.inputButtonWidth = typedArray.getDimensionPixelSize(R.styleable.MessageInput_inputButtonWidth,
            style.getDimension(R.dimen.input_button_width));
    style.inputButtonHeight = typedArray.getDimensionPixelSize(R.styleable.MessageInput_inputButtonHeight,
            style.getDimension(R.dimen.input_button_height));
    style.inputButtonMargin = typedArray.getDimensionPixelSize(R.styleable.MessageInput_inputButtonMargin,
            style.getDimension(R.dimen.input_button_margin));
    style.inputMaxLines = typedArray.getInt(R.styleable.MessageInput_inputMaxLines, DEFAULT_MAX_LINES);
    style.inputHint = typedArray.getString(R.styleable.MessageInput_inputHint);
    style.inputText = typedArray.getString(R.styleable.MessageInput_inputText);
    style.inputTextSize = typedArray.getDimensionPixelSize(R.styleable.MessageInput_inputTextSize,
            style.getDimension(R.dimen.input_text_size));
    style.inputTextColor = typedArray.getColor(R.styleable.MessageInput_inputTextColor,
            ContextCompat.getColor(context, R.color.dark_grey_two));
    style.inputHintColor = typedArray.getColor(R.styleable.MessageInput_inputHintColor,
            ContextCompat.getColor(context, R.color.warm_grey_three));
    style.inputBackground = typedArray.getDrawable(R.styleable.MessageInput_inputBackground);
    style.inputCursorDrawable = typedArray.getDrawable(R.styleable.MessageInput_inputCursorDrawable);

    typedArray.recycle();

    style.inputDefaultPaddingLeft = style.getDimension(R.dimen.input_padding_left);
    style.inputDefaultPaddingRight = style.getDimension(R.dimen.input_padding_right);
    style.inputDefaultPaddingTop = style.getDimension(R.dimen.input_padding_top);
    style.inputDefaultPaddingBottom = style.getDimension(R.dimen.input_padding_bottom);

    return style;
}

From source file:com.grarak.kerneladiutor.utils.ViewUtils.java

public static Drawable getSelectableBackground(Context context) {
    TypedArray typedArray = context.obtainStyledAttributes(new int[] { R.attr.selectableItemBackground });
    Drawable drawable = typedArray.getDrawable(0);
    typedArray.recycle();// w  w w .  j av a 2  s . co  m
    return drawable;
}

From source file:android.support.wear.widget.drawer.WearableDrawerView.java

private static Drawable getDrawable(Context context, TypedArray typedArray, @StyleableRes int index) {
    Drawable background;/*  ww w.j  av a 2s. com*/
    int backgroundResId = typedArray.getResourceId(index, 0);
    if (backgroundResId == 0) {
        background = typedArray.getDrawable(index);
    } else {
        background = context.getDrawable(backgroundResId);
    }
    return background;
}