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:com.odoo.followup.orm.widgets.BezelImageView.java

public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mContext = context;//from  w  w w.j ava 2s  . c om
    // 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);
    }

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

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

    a.recycle();
    otherInit();
}

From source file:com.simplecity.amp_library.ui.views.ScrimInsetsFrameLayout.java

private void init(Context context, AttributeSet attrs, int defStyle) {

    mContext = context;/*  www.j  a  v a 2 s. com*/

    //Don't do anything special if we're not allowed to tint the status bar
    if (!ShuttleUtils.hasKitKat()) {
        return;
    }

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrimInsetsView, defStyle, 0);
    if (a == null) {
        return;
    }
    mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsView_scrimInsetForeground);
    a.recycle();

    setWillNotDraw(true);
}

From source file:com.cqu.lightutils.widget.ScrimInsetsFrameLayout.java

public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrimInsetsFrameLayoutCompat,
            defStyleAttr, R.style.LightUtilsWidget_Design_ScrimInsetsFrameLayoutCompat);
    mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsFrameLayoutCompat_insetsForeground);
    a.recycle();//from  w ww .  j a  v a  2  s . com
    setWillNotDraw(true); // No need to draw until the insets are adjusted

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {

            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
            setWillNotDraw(mInsets.isEmpty() || mInsetForeground == null);
            ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this);
            return insets.consumeSystemWindowInsets();
        }
    });
}

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);
    }/*w w  w  .ja v  a  2  s  .  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   w  w  w  .  jav a  2 s . c  o  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.nextgis.maplibui.util.TrackView.java

private void init(Context context) {
    mContext = context;/* w  w w  .  j  av  a2  s  .com*/
    mSelectedIds = new ArrayList<>();

    int[] attrs = new int[] { R.attr.ic_action_visibility_on, R.attr.ic_action_visibility_off };
    TypedArray ta = mContext.obtainStyledAttributes(attrs);
    mVisibilityOn = ta.getDrawable(0);
    mVisibilityOff = ta.getDrawable(1);
    ta.recycle();

    setItemsCanFocus(false);
    setChoiceMode(CHOICE_MODE_MULTIPLE);

    if (context instanceof AppCompatActivity) {
        AppCompatActivity activity = (AppCompatActivity) context;
        IGISApplication application = (IGISApplication) activity.getApplication();
        mContentUriTracks = Uri
                .parse("content://" + application.getAuthority() + "/" + TrackLayer.TABLE_TRACKS);

        String[] from = new String[] { TrackLayer.FIELD_NAME, TrackLayer.FIELD_VISIBLE };
        int[] to = new int[] { R.id.tv_name, R.id.iv_visibility };
        mTrackAdapter = new TrackAdapter(context, R.layout.row_track, null, from, to,
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        setAdapter(mTrackAdapter);

        activity.getSupportLoaderManager().initLoader(TRACKS_ID, null, this);
    }

    setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CheckedTextView name = (CheckedTextView) view.findViewById(R.id.tv_name);
            name.setChecked(!name.isChecked());

            if (name.isChecked())
                mSelectedIds.add(id + "");
            else
                mSelectedIds.remove(id + "");

            if (mCheckedChangeListener != null)
                mCheckedChangeListener.onCheckedChanged();
        }
    });
}

From source file:com.popdeem.sdk.uikit.widget.PDUIBezelImageView.java

public PDUIBezelImageView(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);
    }/*w ww .j  a va2 s .  c  o 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.grarak.cardview.BaseCardView.java

public BaseCardView(Context context, AttributeSet attributeSet, int layout) {
    super(context, attributeSet);

    // Add a margin
    setMargin();/*from  w  w  w.j a  v  a  2  s .  c  om*/

    // Make a rounded card
    setRadius();

    // Set background color depending on the current theme
    setCardBackgroundColor(ContextCompat.getColor(context,
            Utils.DARKTHEME ? R.color.card_background_dark : R.color.card_background_light));

    // This will enable the touch feedback of the card
    TypedArray ta = getContext().obtainStyledAttributes(new int[] { R.attr.selectableItemBackground });
    Drawable d = ta.getDrawable(0);
    ta.recycle();
    setForeground(d);

    // null parent avoid Layout Inflation without a Parent
    ViewGroup base_parent = (ViewGroup) findViewById(R.id.base_parent);

    // Add the base view
    View view = LayoutInflater.from(getContext()).inflate(R.layout.base_cardview, base_parent, false);
    addView(view);

    headerLayout = (LinearLayout) view.findViewById(R.id.header_layout);

    setUpHeader();

    LinearLayout innerLayout = (LinearLayout) view.findViewById(R.id.inner_layout);
    customLayout = (LinearLayout) view.findViewById(R.id.custom_layout);

    // Inflate the innerlayout
    layoutView = LayoutInflater.from(getContext()).inflate(layout, null, false);

    // If sub class overwrites the default layout then don't try to get the TextView
    if (layout == DEFAULT_LAYOUT) {
        innerView = (TextView) layoutView.findViewById(R.id.inner_view);
        if (mTitle != null)
            innerView.setText(mTitle);
    } else
        setUpInnerLayout(layoutView);

    // Add innerlayout to base view
    innerLayout.addView(layoutView);
    if (Utils.isTV(getContext()))
        setFocus();
}

From source file:com.saarang.samples.apps.iosched.ui.widget.ScrimInsetsFrameLayout.java

private void init(Context context, AttributeSet attrs, int defStyle) {
    final TypedArray a = context.obtainStyledAttributes(attrs,
            com.saarang.samples.apps.iosched.R.styleable.ScrimInsetsView, defStyle, 0);
    if (a == null) {
        return;//w  ww.  j  av a  2  s  .  c o m
    }
    mInsetForeground = a
            .getDrawable(com.saarang.samples.apps.iosched.R.styleable.ScrimInsetsView_insetForeground);
    a.recycle();

    setWillNotDraw(true);
}

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 .ja v  a 2  s  .  c om*/

    // 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);
    }
}