Example usage for android.graphics.drawable Drawable mutate

List of usage examples for android.graphics.drawable Drawable mutate

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable mutate.

Prototype

public @NonNull Drawable mutate() 

Source Link

Document

Make this drawable mutable.

Usage

From source file:com.bilibili.magicasakura.widgets.AppCompatForegroundHelper.java

private boolean applySupportForegroundTint() {
    Drawable foregroundDrawable = getForeground();
    if (foregroundDrawable != null && mForegroundTintInfo != null && mForegroundTintInfo.mHasTintList) {
        foregroundDrawable = DrawableCompat.wrap(foregroundDrawable);
        foregroundDrawable = foregroundDrawable.mutate();
        if (mForegroundTintInfo.mHasTintList) {
            DrawableCompat.setTintList(foregroundDrawable, mForegroundTintInfo.mTintList);
        }// w w  w. j a  v a2s.  c  om
        if (mForegroundTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(foregroundDrawable, mForegroundTintInfo.mTintMode);
        }
        if (foregroundDrawable.isStateful()) {
            foregroundDrawable.setState(mView.getDrawableState());
        }
        setForegroundDrawable(foregroundDrawable);
        return true;
    }
    return false;
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void wrapMenuItemIcon(@NonNull MenuItem item, int itemColor, int... excludeGroups) {
    if (ArrayUtils.contains(excludeGroups, item.getGroupId()))
        return;/* www .  j a  v  a2 s .c o m*/
    final Drawable icon = item.getIcon();
    if (icon == null)
        return;
    if (icon instanceof ActionIconDrawable) {
        ((ActionIconDrawable) icon).setDefaultColor(itemColor);
        item.setIcon(icon);
        return;
    }
    icon.mutate();
    final Drawable.Callback callback = icon.getCallback();
    final ActionIconDrawable newIcon = new ActionIconDrawable(icon, itemColor);
    newIcon.setCallback(callback);
    item.setIcon(newIcon);
}

From source file:com.adrguides.ReadGuideFragment.java

private Drawable getDrawableDisabled(int res) {
    Drawable resIcon = getResources().getDrawable(res);
    resIcon.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
    return resIcon;
}

From source file:com.bilibili.magicasakura.widgets.AppCompatCompoundDrawableHelper.java

private Drawable applySupportCompoundDrawableTint(int position) {
    Drawable originDrawable = ((TextView) mView).getCompoundDrawables()[position];
    Drawable compoundDrawable = originDrawable;
    TintInfo tintInfo = mCompoundDrawableTintInfos[position];
    if (compoundDrawable != null && tintInfo != null && tintInfo.mHasTintList) {
        compoundDrawable = DrawableCompat.wrap(compoundDrawable);
        compoundDrawable.mutate();
        if (tintInfo.mHasTintList) {
            DrawableCompat.setTintList(compoundDrawable, tintInfo.mTintList);
        }//from   ww  w.  ja va  2  s .c  o m
        if (tintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(compoundDrawable, tintInfo.mTintMode);
        }
        if (compoundDrawable.isStateful()) {
            compoundDrawable.setState(originDrawable.getState());
        }
        return compoundDrawable;
    }
    return originDrawable;
}

From source file:com.forrestguice.suntimeswidget.settings.ColorChooser.java

private void updateViews() {
    if (edit != null) {
        edit.setText(String.format("#%08X", color));
        edit.setVisibility((isCollapsed ? View.GONE : View.VISIBLE));
    }/*from  w w  w  . j  a v a  2 s  . c  o m*/

    if (button != null) {
        Drawable d = button.getDrawable();
        if (d != null) {
            GradientDrawable g = (GradientDrawable) d.mutate();
            g.setColor(color);
            g.invalidateSelf();
        }
    }
}

From source file:com.bilibili.magicasakura.widgets.AppCompatBackgroundHelper.java

private boolean applySupportBackgroundTint() {
    Drawable backgroundDrawable = mView.getBackground();
    if (backgroundDrawable != null && mBackgroundTintInfo != null && mBackgroundTintInfo.mHasTintList) {
        backgroundDrawable = DrawableCompat.wrap(backgroundDrawable);
        backgroundDrawable = backgroundDrawable.mutate();
        if (mBackgroundTintInfo.mHasTintList) {
            DrawableCompat.setTintList(backgroundDrawable, mBackgroundTintInfo.mTintList);
        }/*  w  w w . ja v  a2 s  . c o  m*/
        if (mBackgroundTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(backgroundDrawable, mBackgroundTintInfo.mTintMode);
        }
        if (backgroundDrawable.isStateful()) {
            backgroundDrawable.setState(mView.getDrawableState());
        }
        setBackgroundDrawable(backgroundDrawable);
        return true;
    }
    return false;
}

From source file:com.bilibili.magicasakura.widgets.AppCompatCompoundButtonHelper.java

public boolean applySupportButtonDrawableTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable((CompoundButton) mView);
    if (buttonDrawable != null && mCompoundButtonTintInfo != null && mCompoundButtonTintInfo.mHasTintList) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable);
        buttonDrawable = buttonDrawable.mutate();
        if (mCompoundButtonTintInfo.mHasTintList) {
            DrawableCompat.setTintList(buttonDrawable, mCompoundButtonTintInfo.mTintList);
        }//w ww .j  a  v  a  2  s . c o m
        if (mCompoundButtonTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(buttonDrawable, mCompoundButtonTintInfo.mTintMode);
        }
        // The drawable (or one of its children) may not have been
        // stateful before applying the tint, so let's try again.
        if (buttonDrawable.isStateful()) {
            buttonDrawable.setState(mView.getDrawableState());
        }
        setButtonDrawable(buttonDrawable);
        return true;
    }
    return false;
}

From source file:org.ciasaboark.tacere.activity.fragment.EventDetailsFragment.java

private void resetEvent() {
    boolean eventRepeats = databaseInterface.doesEventRepeat(event.getEventId());
    boolean eventSeriesRingerSet = prefs.getRingerForEventSeries(event.getEventId()) != RingerType.UNDEFINED;
    if (eventRepeats && eventSeriesRingerSet) {
        if (event.getRingerType() == RingerType.UNDEFINED) {
            //this event does not have an instance ringer set, the reset button should prompt that
            //resetting will reset the entire event series
            String message = getResources().getString(R.string.event_dialog_reset_event_series);
            //if this events calendar has a custom ringer then notify the user that this is what
            //we will drop back to, otherwize use the default ringer
            if (prefs.getRingerForCalendar(event.getCalendarId()) != RingerType.UNDEFINED) {
                message = String.format(message, new String[] { "calendar" });
            } else {
                message = String.format(message, new String[] { "default" });
            }// w ww.j av  a  2  s .c om

            Drawable icon = getResources().getDrawable(R.drawable.history);
            icon.mutate().setColorFilter(getResources().getColor(R.color.dialog_icon_tint),
                    PorterDuff.Mode.MULTIPLY);
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(getActivity(), R.style.Dialog))
                            .setTitle(R.string.event_dialog_repeating_event_conformation_title)
                            .setMessage(message).setPositiveButton(R.string.event_dialog_reset_event_series_ok,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            resetAllEvents();
                                        }
                                    })
                            .setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    //nothing to do here
                                }
                            }).setIcon(icon);
            AlertDialog dialog = builder.show();

        } else {
            //this event has instance and event series ringers set, prompt for which to reset
            long eventRepetions = databaseInterface.getEventRepetitionCount(event.getEventId());
            String message = getResources().getString(R.string.event_dialog_reset_all_instances_message);
            Drawable icon = getResources().getDrawable(R.drawable.history);
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(getActivity(), R.style.Dialog))
                            .setTitle(R.string.event_dialog_repeating_event_conformation_title)
                            .setMessage(String.format(message, event.getTitle(), eventRepetions))
                            .setPositiveButton(R.string.event_dialog_save_all_instances,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            resetAllEvents();
                                        }
                                    })
                            .setNegativeButton(R.string.event_dialog_save_instance,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            resetEventInstance();
                                        }
                                    })
                            .setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    //nothing to do here
                                }
                            }).setIcon(icon);
            AlertDialog dialog = builder.show();
        }

    } else {
        resetEventInstance();
    }
}

From source file:com.agenmate.lollipop.addedit.AddEditFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        getActivity().onBackPressed();//from  w ww . java2s .  co  m
        return true;
    case R.id.action_save:
        String title = emptyStringChecker(titleEdit.getText().toString());
        if (title == null) {
            Snackbar.make(background, "Title can't be Empty", Snackbar.LENGTH_LONG).show();
            return true;
        }
        String description = emptyStringChecker(descEdit.getText().toString());
        int priority = getPriority();

        long dueAt = getDueDate();
        if (dueAt < 0) {
            Snackbar.make(background, "Not enough time to complete task at due date", Snackbar.LENGTH_LONG)
                    .show();
            return true;
        }

        presenter.saveTask(title, description, priority, selectedColor, dueAt, hasAlarm, isCompleted);

        return true;
    case R.id.action_alarm:
        if (!hasAlarm) {
            if (getDueDate() < 0) {
                Snackbar.make(background, "Not enough time to complete task at due date", Snackbar.LENGTH_LONG)
                        .show();
                return true;
            }
        }
        boolean setWhite = selectedColor == 0 || selectedColor == 5 || selectedColor == 6;
        item.setIcon(hasAlarm ? R.drawable.ic_alarm_off : R.drawable.ic_alarm_on);
        Drawable drawable = item.getIcon();
        drawable.mutate();
        drawable.setColorFilter(setWhite ? Color.WHITE : Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        hasAlarm = !hasAlarm;
        return true;

    case R.id.action_delete:
        presenter.deleteTask();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:alexander.martinz.libs.materialpreferences.MaterialPreference.java

public boolean init(Context context, AttributeSet attrs) {
    if (mInit) {//from  w  w w.  j  a v  a 2s.  c  o  m
        return false;
    }
    mInit = true;

    if (attrs != null) {
        TypedArray typedArray = parseAttrs(context, attrs);
        recycleTypedArray(typedArray);
    }

    final int layoutResId = mPrefAsCard ? R.layout.material_prefs_card_preference
            : R.layout.material_prefs_preference;
    mView = getLayoutInflater().inflate(layoutResId, this, true);
    if (mPrefAsCard) {
        mCardView = (CardView) mView.findViewById(R.id.card_preference_root);
    }

    mIcon = (ImageView) mView.findViewById(android.R.id.icon);
    mTitle = (TextView) mView.findViewById(android.R.id.title);
    mSummary = (TextView) mView.findViewById(android.R.id.summary);
    mWidgetFrame = (LinearLayout) mView.findViewById(android.R.id.widget_frame);
    mWidgetFrameBottom = (LinearLayout) mView.findViewById(R.id.widget_frame_bottom);

    if (mResIdIcon != -1 && mIcon != null) {
        Drawable d = ContextCompat.getDrawable(context, mResIdIcon);
        if (d != null && mIconTintColor != Integer.MIN_VALUE) {
            d = d.mutate();
            d.setColorFilter(new LightingColorFilter(Color.BLACK, mIconTintColor));
        }
        mIcon.setImageDrawable(d);
        mIcon.setVisibility(View.VISIBLE);
    }
    if (mResIdTitle != -1) {
        mTitle.setText(mResIdTitle);
    }
    if (mResIdSummary != -1 && mSummary != null) {
        mSummary.setText(mResIdSummary);
        mSummary.setVisibility(View.VISIBLE);
    }

    if (mPrefAsCard && mCardBackgroundColor != Integer.MIN_VALUE) {
        setBackgroundColor(mCardBackgroundColor);
    }

    setSelectable(true);
    setOnClickListener(this);
    setOnTouchListener(this);
    setOrientation(LinearLayout.VERTICAL);

    return true;
}