Example usage for android.content Context obtainStyledAttributes

List of usage examples for android.content Context obtainStyledAttributes

Introduction

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

Prototype

public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs,
        @AttrRes int defStyleAttr, @StyleRes int defStyleRes) 

Source Link

Document

Retrieve styled attribute information in this Context's theme.

Usage

From source file:com.astuetz.viewpager.extensions.FixedTabsView.java

public FixedTabsView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    this.mContext = context;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0);

    mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor);

    mDividerMarginTop = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginTop,
            mDividerMarginTop);/*  w  ww . ja va 2s.  c o m*/
    mDividerMarginBottom = a.getDimensionPixelSize(R.styleable.ViewPagerExtensions_dividerMarginBottom,
            mDividerMarginBottom);

    mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable);

    a.recycle();

    this.setOrientation(LinearLayout.HORIZONTAL);
}

From source file:com.astuetz.viewpager.extensions.IndicatorLineView.java

public IndicatorLineView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0);

    mLineColor = a.getColor(R.styleable.ViewPagerExtensions_lineColor, mLineColor);

    mFadeOutTime = a.getInt(R.styleable.ViewPagerExtensions_fadeOutDelay, mFadeOutTime);

    mFadingDuration = a.getInt(R.styleable.ViewPagerExtensions_fadeOutDuration, mFadingDuration);

    a.recycle();/* ww  w . ja v a2 s .  com*/
}

From source file:com.astuetz.viewpager.extensions.ProgressLineView.java

public ProgressLineView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerExtensions, defStyle, 0);

    mLineColor = a.getColor(R.styleable.ViewPagerExtensions_lineColor, mLineColor);

    mFadeOutTime = a.getInt(R.styleable.ViewPagerExtensions_fadeOutDelay, mFadeOutTime);

    mFadingDuration = a.getInt(R.styleable.ViewPagerExtensions_fadeOutDuration, mFadingDuration);

    a.recycle();//from w  ww  .java2  s  . co m
}

From source file:cl.monsoon.s1next.widget.BezelImageView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    // attribute initialization
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView,
            defStyleAttr, defStyleRes);//from  w  ww.  java2  s.com

    mMaskDrawable = typedArray.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }

    mBorderDrawable = typedArray.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    typedArray.recycle();

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // always want a cache allocated
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static Drawable getActionBarBackground(final Context context, final int themeRes,
        final int accentColor) {
    if (!isDarkTheme(themeRes)) {
        final ColorDrawable d = new ActionBarColorDrawable(accentColor);
        return applyActionBarDrawable(context, d, isTransparentBackground(themeRes));
    }/*  w  ww.  j a  v a  2s.  c  o  m*/
    final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.background },
            android.R.attr.actionBarStyle, themeRes);
    final Drawable d = a.getDrawable(0);
    a.recycle();
    return applyActionBarDrawable(context, d, isTransparentBackground(themeRes));
}

From source file:app.geochat.ui.widgets.BezelImageView.java

public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }/*from  w w w  . j a  v a 2s . co  m*/

    mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}

From source file:com.aprz.easy_iosched.ui.widget.BezelImageView.java

public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization.
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }//from   www . j a v  a  2s. com

    mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);

    a.recycle();

    // Other initialization.
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}

From source file:android.support.v7.preference.SwitchPreferenceCompat.java

/**
 * Construct a new SwitchPreference with the given style options.
 *
 * @param context The Context that will style this preference
 * @param attrs Style attributes that differ from the default
 * @param defStyleAttr An attribute in the current theme that contains a
 *        reference to a style resource that supplies default values for
 *        the view. Can be 0 to not look for defaults.
 * @param defStyleRes A resource identifier of a style resource that
 *        supplies default values for the view, used only if
 *        defStyleAttr is 0 or can not be found in the theme. Can be 0
 *        to not look for defaults./*from w  w w . j  av a  2s  . c  om*/
 */
public SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwitchPreferenceCompat, defStyleAttr,
            defStyleRes);

    setSummaryOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_summaryOn,
            R.styleable.SwitchPreferenceCompat_android_summaryOn));

    setSummaryOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_summaryOff,
            R.styleable.SwitchPreferenceCompat_android_summaryOff));

    setSwitchTextOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_switchTextOn,
            R.styleable.SwitchPreferenceCompat_android_switchTextOn));

    setSwitchTextOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_switchTextOff,
            R.styleable.SwitchPreferenceCompat_android_switchTextOff));

    setDisableDependentsState(
            TypedArrayUtils.getBoolean(a, R.styleable.SwitchPreferenceCompat_disableDependentsState,
                    R.styleable.SwitchPreferenceCompat_android_disableDependentsState, false));

    a.recycle();
}

From source file:android.support.v14.preference.SwitchPreference.java

/**
 * Construct a new SwitchPreference with the given style options.
 *
 * @param context The Context that will style this preference
 * @param attrs Style attributes that differ from the default
 * @param defStyleAttr An attribute in the current theme that contains a
 *        reference to a style resource that supplies default values for
 *        the view. Can be 0 to not look for defaults.
 * @param defStyleRes A resource identifier of a style resource that
 *        supplies default values for the view, used only if
 *        defStyleAttr is 0 or can not be found in the theme. Can be 0
 *        to not look for defaults.//www.  j  a  v  a2 s .co m
 */
public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwitchPreference, defStyleAttr,
            defStyleRes);

    setSummaryOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_summaryOn,
            R.styleable.SwitchPreference_android_summaryOn));

    setSummaryOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_summaryOff,
            R.styleable.SwitchPreference_android_summaryOff));

    setSwitchTextOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_switchTextOn,
            R.styleable.SwitchPreference_android_switchTextOn));

    setSwitchTextOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_switchTextOff,
            R.styleable.SwitchPreference_android_switchTextOff));

    setDisableDependentsState(TypedArrayUtils.getBoolean(a, R.styleable.SwitchPreference_disableDependentsState,
            R.styleable.SwitchPreference_android_disableDependentsState, false));

    a.recycle();
}

From source file:com.abewy.android.apps.klyph.messenger.widget.BezelImageView.java

public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

    setMaskDrawable(a.getDrawable(R.styleable.BezelImageView_maskDrawable));

    setBorderDrawable(a.getDrawable(R.styleable.BezelImageView_borderDrawable));

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);

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

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}