Search in sources :

Example 6 with InsetDrawable

use of android.graphics.drawable.InsetDrawable in project material-components-android by material-components.

the class FloatingActionButtonLollipop method onPaddingUpdated.

@Override
void onPaddingUpdated(Rect padding) {
    if (mShadowViewDelegate.isCompatPaddingEnabled()) {
        mInsetDrawable = new InsetDrawable(mRippleDrawable, padding.left, padding.top, padding.right, padding.bottom);
        mShadowViewDelegate.setBackgroundDrawable(mInsetDrawable);
    } else {
        mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
    }
}
Also used : InsetDrawable(android.graphics.drawable.InsetDrawable)

Example 7 with InsetDrawable

use of android.graphics.drawable.InsetDrawable in project Shuttle by timusus.

the class SettingsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (mPrefResId == R.xml.settings_headers) {
        if (getListView() != null && getListView().getDivider() != null) {
            Drawable drawable = getListView().getDivider();
            InsetDrawable divider = new InsetDrawable(drawable, ResourceUtils.toPixels(72), 0, 0, 0);
            getListView().setDivider(divider);
        }
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) InsetDrawable(android.graphics.drawable.InsetDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable)

Example 8 with InsetDrawable

use of android.graphics.drawable.InsetDrawable in project FlatUI by eluleci.

the class FlatToggleButton method init.

private void init(AttributeSet attrs) {
    if (attributes == null)
        attributes = new Attributes(this, getResources());
    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatToggleButton);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatToggleButton_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatToggleButton_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
        space = a.getDimensionPixelSize(R.styleable.fl_FlatToggleButton_fl_space, space);
        padding = space / 10;
        a.recycle();
    }
    // creating unchecked-enabled state drawable
    ShapeDrawable uncheckedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    uncheckedEnabledFrontCore.getPaint().setColor(attributes.getColor(2));
    InsetDrawable uncheckedEnabledFront = new InsetDrawable(uncheckedEnabledFrontCore, padding);
    ShapeDrawable uncheckedEnabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    uncheckedEnabledBack.getPaint().setColor(Color.parseColor("#f2f2f2"));
    uncheckedEnabledBack.setIntrinsicWidth(space / 2 * 5);
    uncheckedEnabledBack.setIntrinsicHeight(space);
    uncheckedEnabledBack.setPadding(0, 0, space / 2 * 5, 0);
    Drawable[] d1 = { uncheckedEnabledBack, uncheckedEnabledFront };
    LayerDrawable uncheckedEnabled = new LayerDrawable(d1);
    // creating checked-enabled state drawable
    ShapeDrawable checkedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    checkedEnabledFrontCore.getPaint().setColor(attributes.getColor(2));
    InsetDrawable checkedEnabledFront = new InsetDrawable(checkedEnabledFrontCore, padding);
    ShapeDrawable checkedEnabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    checkedEnabledBack.getPaint().setColor(attributes.getColor(3));
    checkedEnabledBack.setPadding(space / 2 * 5, 0, 0, 0);
    Drawable[] d2 = { checkedEnabledBack, checkedEnabledFront };
    LayerDrawable checkedEnabled = new LayerDrawable(d2);
    // creating unchecked-disabled state drawable
    ShapeDrawable uncheckedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    uncheckedDisabledFrontCore.getPaint().setColor(Color.parseColor("#d2d2d2"));
    InsetDrawable uncheckedDisabledFront = new InsetDrawable(uncheckedDisabledFrontCore, padding);
    ShapeDrawable uncheckedDisabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    uncheckedDisabledBack.getPaint().setColor(Color.parseColor("#f2f2f2"));
    uncheckedDisabledBack.setPadding(0, 0, space / 2 * 5, 0);
    Drawable[] d3 = { uncheckedDisabledBack, uncheckedDisabledFront };
    LayerDrawable uncheckedDisabled = new LayerDrawable(d3);
    // creating checked-disabled state drawable
    ShapeDrawable checkedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    checkedDisabledFrontCore.getPaint().setColor(attributes.getColor(3));
    InsetDrawable checkedDisabledFront = new InsetDrawable(checkedDisabledFrontCore, padding);
    ShapeDrawable checkedDisabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
    checkedDisabledBack.getPaint().setColor(Color.parseColor("#f2f2f2"));
    checkedDisabledBack.setPadding(space / 2 * 5, 0, 0, 0);
    Drawable[] d4 = { checkedDisabledBack, checkedDisabledFront };
    LayerDrawable checkedDisabled = new LayerDrawable(d4);
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, new InsetDrawable(uncheckedEnabled, padding * 2));
    states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, new InsetDrawable(checkedEnabled, padding * 2));
    states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, new InsetDrawable(uncheckedDisabled, padding * 2));
    states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, new InsetDrawable(checkedDisabled, padding * 2));
    setBackgroundDrawable(states);
    setText("");
    setTextOff("");
    setTextOn("");
    setTextSize(0);
}
Also used : RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) LayerDrawable(android.graphics.drawable.LayerDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable)

Example 9 with InsetDrawable

use of android.graphics.drawable.InsetDrawable in project PocketHub by pockethub.

the class AvatarLoader method bind.

/**
     * Sets the logo on the {@link ActionBar} to the user's avatar.
     *
     * @param actionBar     An ActionBar object on which you're placing the user's avatar.
     * @param userReference An AtomicReference that points to the desired user.
     * @return this helper
     */
public void bind(final ActionBar actionBar, final AtomicReference<User> userReference) {
    if (userReference == null) {
        return;
    }
    final User user = userReference.get();
    if (user == null) {
        return;
    }
    String avatarUrl = user.avatarUrl();
    if (TextUtils.isEmpty(avatarUrl)) {
        return;
    }
    // Remove the URL params as they are not needed and break cache
    if (avatarUrl.contains("?") && !avatarUrl.contains("gravatar")) {
        avatarUrl = avatarUrl.substring(0, avatarUrl.indexOf("?"));
    }
    final String url = avatarUrl;
    new FetchAvatarTask(context) {

        @Override
        public BitmapDrawable call() throws Exception {
            Bitmap image = Bitmap.createScaledBitmap(p.load(url).get(), avatarSize, avatarSize, false);
            return new BitmapDrawable(context.getResources(), ImageUtils.roundCorners(image, cornerRadius));
        }

        @Override
        protected void onSuccess(BitmapDrawable image) throws Exception {
            // compute inset in pixels
            int insetPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, context.getResources().getDisplayMetrics());
            actionBar.setLogo(new InsetDrawable(image, 0, 0, insetPx, 0));
        }
    }.execute();
}
Also used : Bitmap(android.graphics.Bitmap) User(com.meisolsson.githubsdk.model.User) InsetDrawable(android.graphics.drawable.InsetDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException)

Example 10 with InsetDrawable

use of android.graphics.drawable.InsetDrawable in project uitableview4android by DayS.

the class UITableCellView method setBackgroundColor.

public void setBackgroundColor(int[] colorDefault, int[] colorPressed) {
    // Assign the right backgroundDrawable according to the cell's position in the group
    Drawable backgroundDrawable;
    if (indexPath.getRowsCount() == 1) {
        backgroundDrawable = new UITableCellDrawable(10.0f, 10.0f, colorDefault, colorPressed, borderColor);
    } else {
        if (indexPath.isFirstCellOfGroup()) {
            backgroundDrawable = new UITableCellDrawable(10.0f, 0, colorDefault, colorPressed, borderColor);
        } else if (indexPath.isLastCellOfGroup()) {
            backgroundDrawable = new UITableCellDrawable(0, 10.0f, colorDefault, colorPressed, borderColor);
        } else {
            backgroundDrawable = new UITableCellDrawable(0, 0, colorDefault, colorPressed, borderColor);
        }
    }
    // Add extra space if this cell is the last one
    int bottomInset = 0;
    if (indexPath.isLastCell()) {
        bottomInset = INSET;
    }
    setBackgroundDrawable(new InsetDrawable(backgroundDrawable, INSET, 0, INSET, bottomInset));
}
Also used : UITableCellDrawable(fr.days.android.uitableview.drawable.UITableCellDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) UITableCellDrawable(fr.days.android.uitableview.drawable.UITableCellDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable)

Aggregations

InsetDrawable (android.graphics.drawable.InsetDrawable)12 Drawable (android.graphics.drawable.Drawable)6 LayerDrawable (android.graphics.drawable.LayerDrawable)4 StateListDrawable (android.graphics.drawable.StateListDrawable)4 TypedArray (android.content.res.TypedArray)3 ShapeDrawable (android.graphics.drawable.ShapeDrawable)3 Attributes (com.cengalabs.flatui.Attributes)3 Typeface (android.graphics.Typeface)2 GradientDrawable (android.graphics.drawable.GradientDrawable)2 PaintDrawable (android.graphics.drawable.PaintDrawable)2 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)2 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Bitmap (android.graphics.Bitmap)1 Rect (android.graphics.Rect)1 AnimationDrawable (android.graphics.drawable.AnimationDrawable)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 DrawableContainer (android.graphics.drawable.DrawableContainer)1 OvalShape (android.graphics.drawable.shapes.OvalShape)1 DrawableWrapper (android.support.v4.graphics.drawable.DrawableWrapper)1