Search in sources :

Example 16 with InsetDrawable

use of android.graphics.drawable.InsetDrawable in project platform_packages_apps_Settings by BlissRoms.

the class MusicViewHolderController method setupView.

@Override
public void setupView(AppViewHolder holder) {
    holder.appIcon.setImageDrawable(new InsetDrawable(mContext.getDrawable(R.drawable.ic_headset_24dp), INSET_SIZE));
    holder.appName.setText(mContext.getText(R.string.audio_files_title));
    holder.summary.setText(Formatter.formatFileSize(mContext, mMusicSize));
}
Also used : InsetDrawable(android.graphics.drawable.InsetDrawable)

Example 17 with InsetDrawable

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

the class FlatCheckBox 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_FlatCheckBox);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatCheckBox_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setFontFamily(a.getString(R.styleable.fl_FlatCheckBox_fl_fontFamily));
        attributes.setFontWeight(a.getString(R.styleable.fl_FlatCheckBox_fl_fontWeight));
        attributes.setFontExtension(a.getString(R.styleable.fl_FlatCheckBox_fl_fontExtension));
        attributes.setSize(a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_size, Attributes.DEFAULT_SIZE_PX));
        attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
        attributes.setBorderWidth(attributes.getSize() / 10);
        // getting view specific attributes
        dotMargin = a.getDimensionPixelSize(R.styleable.fl_FlatCheckBox_fl_dotMargin, dotMargin);
        a.recycle();
    }
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedEnabled = new GradientDrawable();
    uncheckedEnabled.setCornerRadius(attributes.getRadius());
    uncheckedEnabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedEnabled.setColor(Color.TRANSPARENT);
    uncheckedEnabled.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    // creating checked-enabled state drawable
    GradientDrawable checkedOutside = new GradientDrawable();
    checkedOutside.setCornerRadius(attributes.getRadius());
    checkedOutside.setSize(attributes.getSize(), attributes.getSize());
    checkedOutside.setColor(Color.TRANSPARENT);
    checkedOutside.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    PaintDrawable checkedCore = new PaintDrawable(attributes.getColor(2));
    checkedCore.setCornerRadius(attributes.getRadius());
    checkedCore.setIntrinsicHeight(attributes.getSize());
    checkedCore.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInside = new InsetDrawable(checkedCore, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedEnabledDrawable = { checkedOutside, checkedInside };
    LayerDrawable checkedEnabled = new LayerDrawable(checkedEnabledDrawable);
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedDisabled = new GradientDrawable();
    uncheckedDisabled.setCornerRadius(attributes.getRadius());
    uncheckedDisabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedDisabled.setColor(Color.TRANSPARENT);
    uncheckedDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    // creating checked-disabled state drawable
    GradientDrawable checkedOutsideDisabled = new GradientDrawable();
    checkedOutsideDisabled.setCornerRadius(attributes.getRadius());
    checkedOutsideDisabled.setSize(attributes.getSize(), attributes.getSize());
    checkedOutsideDisabled.setColor(Color.TRANSPARENT);
    checkedOutsideDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    PaintDrawable checkedCoreDisabled = new PaintDrawable(attributes.getColor(3));
    checkedCoreDisabled.setCornerRadius(attributes.getRadius());
    checkedCoreDisabled.setIntrinsicHeight(attributes.getSize());
    checkedCoreDisabled.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
    LayerDrawable checkedDisabled = new LayerDrawable(checkedDisabledDrawable);
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, uncheckedEnabled);
    states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, checkedEnabled);
    states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, uncheckedDisabled);
    states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, checkedDisabled);
    setButtonDrawable(states);
    // setting padding for avoiding text to appear on icon
    setPadding(attributes.getSize() / 4 * 5, 0, 0, 0);
    setTextColor(attributes.getColor(2));
    // check for IDE preview render
    if (!this.isInEditMode()) {
        Typeface typeface = FlatUI.getFont(getContext(), attributes);
        if (typeface != null)
            setTypeface(typeface);
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) LayerDrawable(android.graphics.drawable.LayerDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) PaintDrawable(android.graphics.drawable.PaintDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) PaintDrawable(android.graphics.drawable.PaintDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 18 with InsetDrawable

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

the class FlatRadioButton 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_FlatRadioButton);
        // getting common attributes
        int customTheme = a.getResourceId(R.styleable.fl_FlatRadioButton_fl_theme, Attributes.DEFAULT_THEME);
        attributes.setThemeSilent(customTheme, getResources());
        attributes.setFontFamily(a.getString(R.styleable.fl_FlatRadioButton_fl_fontFamily));
        attributes.setFontWeight(a.getString(R.styleable.fl_FlatRadioButton_fl_fontWeight));
        attributes.setFontExtension(a.getString(R.styleable.fl_FlatRadioButton_fl_fontExtension));
        attributes.setSize(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_size, Attributes.DEFAULT_SIZE_PX));
        attributes.setRadius(attributes.getSize() / 2);
        attributes.setBorderWidth(a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_borderWidth, Attributes.DEFAULT_BORDER_WIDTH_PX));
        // getting view specific attributes
        dotMargin = a.getDimensionPixelSize(R.styleable.fl_FlatRadioButton_fl_dotMargin, dotMargin);
        a.recycle();
    }
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedEnabled = new GradientDrawable();
    uncheckedEnabled.setCornerRadius(attributes.getRadius());
    uncheckedEnabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedEnabled.setColor(Color.TRANSPARENT);
    uncheckedEnabled.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    // creating checked-enabled state drawable
    GradientDrawable checkedOutside = new GradientDrawable();
    checkedOutside.setCornerRadius(attributes.getSize());
    checkedOutside.setSize(attributes.getSize(), attributes.getSize());
    checkedOutside.setColor(Color.TRANSPARENT);
    checkedOutside.setStroke(attributes.getBorderWidth(), attributes.getColor(2));
    PaintDrawable checkedCore = new PaintDrawable(attributes.getColor(2));
    checkedCore.setCornerRadius(attributes.getSize());
    checkedCore.setIntrinsicHeight(attributes.getSize());
    checkedCore.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInside = new InsetDrawable(checkedCore, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedEnabledDrawable = { checkedOutside, checkedInside };
    LayerDrawable checkedEnabled = new LayerDrawable(checkedEnabledDrawable);
    // creating unchecked-enabled state drawable
    GradientDrawable uncheckedDisabled = new GradientDrawable();
    uncheckedDisabled.setCornerRadius(attributes.getRadius());
    uncheckedDisabled.setSize(attributes.getSize(), attributes.getSize());
    uncheckedDisabled.setColor(Color.TRANSPARENT);
    uncheckedDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    // creating checked-disabled state drawable
    GradientDrawable checkedOutsideDisabled = new GradientDrawable();
    checkedOutsideDisabled.setCornerRadius(attributes.getRadius());
    checkedOutsideDisabled.setSize(attributes.getSize(), attributes.getSize());
    checkedOutsideDisabled.setColor(Color.TRANSPARENT);
    checkedOutsideDisabled.setStroke(attributes.getBorderWidth(), attributes.getColor(3));
    PaintDrawable checkedCoreDisabled = new PaintDrawable(attributes.getColor(3));
    checkedCoreDisabled.setCornerRadius(attributes.getRadius());
    checkedCoreDisabled.setIntrinsicHeight(attributes.getSize());
    checkedCoreDisabled.setIntrinsicWidth(attributes.getSize());
    InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin, attributes.getBorderWidth() + dotMargin);
    Drawable[] checkedDisabledDrawable = { checkedOutsideDisabled, checkedInsideDisabled };
    LayerDrawable checkedDisabled = new LayerDrawable(checkedDisabledDrawable);
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, uncheckedEnabled);
    states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, checkedEnabled);
    states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, uncheckedDisabled);
    states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, checkedDisabled);
    setButtonDrawable(states);
    // setting padding for avoiding text to be appear on icon
    setPadding(attributes.getSize() / 4 * 5, 0, 0, 0);
    setTextColor(attributes.getColor(2));
    // check for IDE preview render
    if (!this.isInEditMode()) {
        Typeface typeface = FlatUI.getFont(getContext(), attributes);
        if (typeface != null)
            setTypeface(typeface);
    }
}
Also used : Typeface(android.graphics.Typeface) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) Attributes(com.cengalabs.flatui.Attributes) LayerDrawable(android.graphics.drawable.LayerDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Drawable(android.graphics.drawable.Drawable) PaintDrawable(android.graphics.drawable.PaintDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) PaintDrawable(android.graphics.drawable.PaintDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 19 with InsetDrawable

use of android.graphics.drawable.InsetDrawable in project TextDrawable by amulyakhare.

the class DrawableProvider method getRectWithCustomSize.

public Drawable getRectWithCustomSize() {
    String leftText = "I";
    String rightText = "J";
    TextDrawable.IBuilder builder = TextDrawable.builder().beginConfig().width(toPx(29)).withBorder(toPx(2)).endConfig().rect();
    TextDrawable left = builder.build(leftText, mGenerator.getColor(leftText));
    TextDrawable right = builder.build(rightText, mGenerator.getColor(rightText));
    Drawable[] layerList = { new InsetDrawable(left, 0, 0, toPx(31), 0), new InsetDrawable(right, toPx(31), 0, 0, 0) };
    return new LayerDrawable(layerList);
}
Also used : TextDrawable(com.amulyakhare.textdrawable.TextDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) TextDrawable(com.amulyakhare.textdrawable.TextDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) InsetDrawable(android.graphics.drawable.InsetDrawable)

Example 20 with InsetDrawable

use of android.graphics.drawable.InsetDrawable in project Signal-Android by WhisperSystems.

the class LiveUpdateMessage method toSpannable.

@NonNull
private static SpannableString toSpannable(@NonNull Context context, @NonNull UpdateDescription updateDescription, @NonNull String string, @ColorInt int defaultTint, boolean adjustPosition) {
    boolean isDarkTheme = ThemeUtil.isDarkTheme(context);
    int drawableResource = updateDescription.getIconResource();
    int tint = isDarkTheme ? updateDescription.getDarkTint() : updateDescription.getLightTint();
    if (tint == 0) {
        tint = defaultTint;
    }
    if (drawableResource == 0) {
        return new SpannableString(string);
    } else {
        Drawable drawable = ContextUtil.requireDrawable(context, drawableResource);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.setColorFilter(tint, PorterDuff.Mode.SRC_ATOP);
        int insetTop = adjustPosition ? ViewUtil.dpToPx(2) : 0;
        InsetDrawable insetDrawable = new InsetDrawable(drawable, 0, insetTop, 0, 0);
        insetDrawable.setBounds(0, 0, drawable.getIntrinsicWidth(), insetDrawable.getIntrinsicHeight());
        Drawable spaceDrawable = new ColorDrawable(Color.TRANSPARENT);
        spaceDrawable.setBounds(0, 0, ViewUtil.dpToPx(8), drawable.getIntrinsicHeight());
        Spannable stringWithImage = new SpannableStringBuilder().append(SpanUtil.buildImageSpan(drawable)).append(SpanUtil.buildImageSpan(spaceDrawable)).append(string);
        return new SpannableString(SpanUtil.color(tint, stringWithImage));
    }
}
Also used : SpannableString(android.text.SpannableString) ColorDrawable(android.graphics.drawable.ColorDrawable) InsetDrawable(android.graphics.drawable.InsetDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) InsetDrawable(android.graphics.drawable.InsetDrawable) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder) NonNull(androidx.annotation.NonNull)

Aggregations

InsetDrawable (android.graphics.drawable.InsetDrawable)37 Drawable (android.graphics.drawable.Drawable)15 LayerDrawable (android.graphics.drawable.LayerDrawable)6 StateListDrawable (android.graphics.drawable.StateListDrawable)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 Resources (android.content.res.Resources)4 ColorDrawable (android.graphics.drawable.ColorDrawable)4 GradientDrawable (android.graphics.drawable.GradientDrawable)4 NonNull (androidx.annotation.NonNull)4 Context (android.content.Context)3 TypedArray (android.content.res.TypedArray)3 Bitmap (android.graphics.Bitmap)3 ShapeDrawable (android.graphics.drawable.ShapeDrawable)3 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)3 View (android.view.View)3 Attributes (com.cengalabs.flatui.Attributes)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 Typeface (android.graphics.Typeface)2