Search in sources :

Example 36 with Drawable

use of android.graphics.drawable.Drawable in project Carbon by ZieIony.

the class Button method updateBackgroundTint.

private void updateBackgroundTint() {
    Drawable background = getBackground();
    if (background instanceof RippleDrawable)
        background = ((RippleDrawable) background).getBackground();
    if (background == null)
        return;
    if (backgroundTint != null && backgroundTintMode != null) {
        int color = backgroundTint.getColorForState(getDrawableState(), backgroundTint.getDefaultColor());
        background.setColorFilter(new PorterDuffColorFilter(color, backgroundTintMode));
    } else {
        background.setColorFilter(null);
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) RippleDrawable(carbon.drawable.ripple.RippleDrawable) ColorStateListDrawable(carbon.drawable.ColorStateListDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) RippleDrawable(carbon.drawable.ripple.RippleDrawable)

Example 37 with Drawable

use of android.graphics.drawable.Drawable in project Carbon by ZieIony.

the class CheckedTextView method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    final Drawable buttonDrawable = drawable;
    if (buttonDrawable != null) {
        final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
        final int drawableHeight = buttonDrawable.getIntrinsicHeight();
        final int drawableWidth = buttonDrawable.getIntrinsicWidth();
        final int top;
        switch(verticalGravity) {
            case Gravity.BOTTOM:
                top = getHeight() - drawableHeight;
                break;
            case Gravity.CENTER_VERTICAL:
                top = (getHeight() - drawableHeight) / 2;
                break;
            default:
                top = 0;
        }
        final int bottom = top + drawableHeight;
        final int left = isLayoutRtl() ? getPaddingLeft() : getWidth() - drawableWidth - getPaddingRight();
        final int right = isLayoutRtl() ? drawableWidth + getPaddingLeft() : getWidth() - getPaddingRight();
        buttonDrawable.setBounds(left, top, right, bottom);
        final Drawable background = getBackground();
        if (background != null && background instanceof RippleDrawable) {
        //TODO: hotspotBounds
        // ((RippleDrawable)background).setHotspotBounds(left, top, right, bottom);
        }
    }
    super.onDraw(canvas);
    if (buttonDrawable != null) {
        final int scrollX = getScrollX();
        final int scrollY = getScrollY();
        if (scrollX == 0 && scrollY == 0) {
            buttonDrawable.draw(canvas);
        } else {
            canvas.translate(scrollX, scrollY);
            buttonDrawable.draw(canvas);
            canvas.translate(-scrollX, -scrollY);
        }
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) RippleDrawable(carbon.drawable.ripple.RippleDrawable) CheckableDrawable(carbon.drawable.CheckableDrawable) RippleDrawable(carbon.drawable.ripple.RippleDrawable)

Example 38 with Drawable

use of android.graphics.drawable.Drawable in project Carbon by ZieIony.

the class ExpandableRecyclerView method initRecycler.

private void initRecycler(AttributeSet attrs, int defStyleAttr) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RecyclerView, defStyleAttr, R.style.carbon_RecyclerView);
    for (int i = 0; i < a.getIndexCount(); i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.RecyclerView_carbon_overScroll) {
            setOverScrollMode(a.getInt(attr, ViewCompat.OVER_SCROLL_ALWAYS));
        } else if (attr == R.styleable.RecyclerView_carbon_headerTint) {
            setHeaderTint(a.getColor(attr, 0));
        } else if (attr == R.styleable.RecyclerView_carbon_headerMinHeight) {
            setHeaderMinHeight((int) a.getDimension(attr, 0.0f));
        } else if (attr == R.styleable.RecyclerView_carbon_headerParallax) {
            setHeaderParallax(a.getFloat(attr, 0.0f));
        } else if (attr == R.styleable.RecyclerView_android_divider) {
            Drawable drawable = a.getDrawable(attr);
            float height = a.getDimension(R.styleable.RecyclerView_android_dividerHeight, 0);
            if (drawable != null && height > 0)
                setDivider(drawable, (int) height);
        }
    }
    Carbon.initTint(this, a, tintIds);
    a.recycle();
    setClipToPadding(false);
    setItemAnimator(new DefaultItemAnimator());
    setWillNotDraw(false);
}
Also used : TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) RippleDrawable(carbon.drawable.ripple.RippleDrawable) Paint(android.graphics.Paint) DefaultItemAnimator(carbon.internal.DefaultItemAnimator)

Example 39 with Drawable

use of android.graphics.drawable.Drawable in project Carbon by ZieIony.

the class AvatarTextListItemActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listcomponent);
    Samples.initToolbar(this, getString(R.string.avatarTextListItemActivity_title));
    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
    RowListAdapter adapter = new RowListAdapter<>(DefaultAvatarTextItem.class, AvatarTextRow.FACTORY);
    adapter.addFactory(DividerItem.class, DividerRow.FACTORY);
    recycler.setAdapter(adapter);
    Drawable avatar = getResources().getDrawable(R.drawable.iceland);
    adapter.setItems(Arrays.asList(new DefaultAvatarTextItem(avatar, "text"), new DefaultAvatarTextItem(avatar, "text"), new DividerItem(), new DefaultAvatarTextItem(avatar, "text"), new DefaultAvatarTextItem(avatar, "text")));
}
Also used : Drawable(android.graphics.drawable.Drawable) DefaultAvatarTextItem(carbon.component.DefaultAvatarTextItem) RowListAdapter(carbon.recycler.RowListAdapter) RecyclerView(carbon.widget.RecyclerView) DividerItem(carbon.component.DividerItem)

Example 40 with Drawable

use of android.graphics.drawable.Drawable in project Carbon by ZieIony.

the class ImageTextSubtextDateListItemActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listcomponent);
    Samples.initToolbar(this, getString(R.string.imageTextSubtextDateListItemActivity_title));
    RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
    recycler.setLayoutManager(new LinearLayoutManager(this));
    RowListAdapter adapter = new RowListAdapter<>(DefaultImageTextSubtextDateItem.class, ImageTextSubtextDateRow::new);
    adapter.addFactory(DefaultHeaderItem.class, PaddedHeaderRow.FACTORY);
    recycler.setAdapter(adapter);
    Drawable drawable = getResources().getDrawable(R.drawable.watermelon);
    String date = format.format(new Date().getTime());
    adapter.setItems(Arrays.asList(new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultHeaderItem("Header"), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date), new DefaultImageTextSubtextDateItem(drawable, "text", "subtext", date)));
}
Also used : DefaultHeaderItem(carbon.component.DefaultHeaderItem) ImageTextSubtextDateRow(carbon.component.ImageTextSubtextDateRow) Drawable(android.graphics.drawable.Drawable) RowListAdapter(carbon.recycler.RowListAdapter) RecyclerView(carbon.widget.RecyclerView) DefaultImageTextSubtextDateItem(carbon.component.DefaultImageTextSubtextDateItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Date(java.util.Date)

Aggregations

Drawable (android.graphics.drawable.Drawable)4516 BitmapDrawable (android.graphics.drawable.BitmapDrawable)795 View (android.view.View)579 Bitmap (android.graphics.Bitmap)476 ColorDrawable (android.graphics.drawable.ColorDrawable)473 ImageView (android.widget.ImageView)471 TextView (android.widget.TextView)439 Paint (android.graphics.Paint)322 LayerDrawable (android.graphics.drawable.LayerDrawable)314 Test (org.junit.Test)276 Context (android.content.Context)267 Resources (android.content.res.Resources)252 Rect (android.graphics.Rect)243 PackageManager (android.content.pm.PackageManager)233 StateListDrawable (android.graphics.drawable.StateListDrawable)212 TypedArray (android.content.res.TypedArray)205 Intent (android.content.Intent)155 ViewGroup (android.view.ViewGroup)148 AnimationDrawable (android.graphics.drawable.AnimationDrawable)147 ArrayList (java.util.ArrayList)139