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.landenlabs.all_UiDemo.frag.RadioBtnFrag.java

private void addTabBar(RadioGroup tabHolder, float weight, int padding) {
    final int maxTabs = 4;
    // tabHolder.removeAllViews();

    int[][] states = new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} };
    ColorStateList colorStateList = new ColorStateList(states, new int[] { 0xff00ff00, 0x80ff0000 });

    RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, weight);

    /*//from   w  w w. j a v a2s.c  o m
    ViewOutlineProvider outlineBoundary;
    if (Build.VERSION.SDK_INT >= 21) {
    outlineBoundary = new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setRect(0, 0, 200, 60); // view.getMeasuredWidth(), view.getMeasuredHeight());
        }
    };
    }
    */

    String[] pageNames = new String[] { "Home", "Map", "Hourly", "Daily" };
    int tabCnt = 0;
    for (String pageName : pageNames) {
        RadioButton button = new RadioButton(tabHolder.getContext());

        String resName = "tab_" + pageName.toLowerCase();
        int resID = getResources().getIdentifier(resName, "drawable", this.getContext().getPackageName());
        Drawable tabBtnIcon = getResources().getDrawable(resID);
        if (tabBtnIcon != null) {

            if (tabBtnIcon != null && Build.VERSION.SDK_INT >= 21) {
                tabBtnIcon.setTintMode(PorterDuff.Mode.MULTIPLY);
                tabBtnIcon.setTintList(colorStateList);
            } else {
                tabBtnIcon = DrawableCompat.wrap(tabBtnIcon);
                DrawableCompat.setTintList(tabBtnIcon.mutate(), colorStateList);
                DrawableCompat.setTintMode(tabBtnIcon.mutate(), PorterDuff.Mode.MULTIPLY);
            }

            // tabBtnIcon = tabHolder.getResources().getDrawable(android.R.drawable.btn_radio);
            if (Build.VERSION.SDK_INT >= 21) {
                // Hide standard radio button but leave ripple effect
                button.setButtonDrawable(null);
            } else {
                // Hide standard radio button
                button.setButtonDrawable(new StateListDrawable());
            }
            button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null);

            /*
            // button.setBackgroundResource(R.drawable.ripple_boarderless);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    
            button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null);
            // button.setCompoundDrawablesRelativeWithIntrinsicBounds(null, tabBtnIcon, null, null);
            // tabBtnIcon.setBounds(0, 0, 50, 100); // img.getMinimumWidth(), img.getMinimumHeight());
            // button.setCompoundDrawables(null, tabBtnIcon, null, null);
            } else {
            button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null);
            }
            */

            button.setBackgroundResource(R.drawable.ripple_boarderless);
            button.setPadding(padding, padding, padding, padding);
            button.setGravity(Gravity.CENTER);
            button.setTextColor(colorStateList);
            button.setText(pageName);

            tabHolder.addView(button, lp);

            if (++tabCnt == maxTabs)
                break;
        }
    }
}

From source file:com.quran.labs.androidquran.ui.preference.SeekBarPreference.java

private void styleSeekBar() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        final Drawable progressDrawable = mSeekBar.getProgressDrawable();
        if (progressDrawable != null) {
            if (progressDrawable instanceof LayerDrawable) {
                LayerDrawable ld = (LayerDrawable) progressDrawable;
                int layers = ld.getNumberOfLayers();
                for (int i = 0; i < layers; i++) {
                    ld.getDrawable(i).mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
                }//from w  w  w  . ja va2s.co  m
            } else {
                progressDrawable.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
            }
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            final Drawable thumb = mSeekBar.getThumb();
            if (thumb != null) {
                thumb.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
            }
        }
    }
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.ApptentiveBaseFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (toolbarLayoutId != 0) {
        toolbar = (Toolbar) getActivity().findViewById(toolbarLayoutId);
        if (getMenuResourceId() != 0 && toolbar != null) {
            Menu parentMenu = toolbar.getMenu();
            ArrayList parentMenuItems = new ArrayList();
            // Before creating fragment, host activity may already has menu items on toolbar
            for (int fragmentMenu = 0; fragmentMenu < parentMenu.size(); ++fragmentMenu) {
                parentMenuItems.add(Integer.valueOf(parentMenu.getItem(fragmentMenu).getItemId()));
            }// www . ja v a  2 s  .  c om
            // Add to toolbar menu items and menu listeners created this fragment
            toolbar.inflateMenu(getMenuResourceId());
            attachFragmentMenuListeners(toolbar.getMenu());

            //
            Menu combinedMenu = toolbar.getMenu();
            fragmentMenuItems = new ArrayList();

            int colorControlNormal = Util.getThemeColor(
                    ApptentiveInternal.getInstance().getApptentiveToolbarTheme(), R.attr.colorControlNormal);
            for (int i = 0; i < combinedMenu.size(); ++i) {
                int menuItemId = combinedMenu.getItem(i).getItemId();
                // fragmentMenuItems contains new menu items added by this fragment
                if (!parentMenuItems.contains(Integer.valueOf(menuItemId))) {
                    fragmentMenuItems.add(Integer.valueOf(menuItemId));
                    Drawable drawable = combinedMenu.getItem(i).getIcon();
                    if (drawable != null) {
                        drawable.mutate();
                        drawable.setColorFilter(colorControlNormal, PorterDuff.Mode.SRC_ATOP);
                    }
                }
            }
        }
    }

}

From source file:org.ciasaboark.tacere.view.EventListItem.java

private void drawCalendarTitle() {
    if (calendarIcon != null) {
        Drawable calendarIconDrawable = getResources().getDrawable(R.drawable.calendar_calendar);
        calendarIconDrawable.setColorFilter(iconTintColor, PorterDuff.Mode.MULTIPLY);
        calendarIcon.setImageDrawable(calendarIconDrawable);
    }/*w  w  w  . j  a  v  a  2s  .  co  m*/
    if (eventCalendarTitle != null) {
        String title;
        if (calendarTitle != null) {
            title = calendarTitle;
        } else {
            long calendarId = event.getCalendarId();
            title = databaseInterface.getCalendarNameForId(calendarId);
        }
        eventCalendarTitle.setText(title);
        eventCalendarTitle.setTextColor(textColor);
    }

    if (isFutureEvent() && calendarIcon != null) {
        try {
            Drawable d = calendarIcon.getDrawable();
            d.mutate().setColorFilter(iconTintColor, PorterDuff.Mode.MULTIPLY);
            calendarIcon.setImageDrawable(d);
        } catch (NullPointerException e) {
            Log.e(TAG, "caught null pointer exception pulling drawable from calendar icon");
        }
    }
}

From source file:com.waz.zclient.pages.main.profile.preferences.dialogs.AddPhoneNumberPreferenceDialogFragment.java

private void updateEditTextBackground(EditText editText) {
    ensureBackgroundDrawableStateWorkaround(editText);

    Drawable editTextBackground = editText.getBackground();
    if (editTextBackground == null) {
        return;/*from   www  .  j a v a2  s. c  o  m*/
    }

    if (android.support.v7.widget.DrawableUtils.canSafelyMutateDrawable(editTextBackground)) {
        editTextBackground = editTextBackground.mutate();
    }

    if (errorView != null && errorView.getVisibility() == View.VISIBLE) {
        // Set a color filter of the error color
        editTextBackground.setColorFilter(AppCompatDrawableManager
                .getPorterDuffColorFilter(errorView.getCurrentTextColor(), PorterDuff.Mode.SRC_IN));
    } else {
        // Else reset the color filter and refresh the drawable state so that the
        // normal tint is used
        clearColorFilter(editTextBackground);
        editText.refreshDrawableState();
    }
}

From source file:com.achep.acdisplay.ui.widgets.notification.NotificationActions.java

@Nullable
protected Drawable onCreateActionIcon(@NonNull Drawable icon) {
    int size = getResources().getDimensionPixelSize(R.dimen.notification_action_icon_size);
    icon = icon.mutate();
    icon.setBounds(0, 0, size, size);/*  ww  w . j  av  a 2  s . c o m*/

    // The matrix is stored in a single array, and its treated as follows:
    // [ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t ]
    // When applied to a color [r, g, b, a], the resulting color is computed as (after clamping)
    //   R' = a*R + b*G + c*B + d*A + e;
    //   G' = f*R + g*G + h*B + i*A + j;
    //   B' = k*R + l*G + m*B + n*A + o;
    //   A' = p*R + q*G + r*B + s*A + t;
    ColorFilter colorFilter = new ColorMatrixColorFilter(new float[] { 0, 0, 0, 0, 255, // Red
            0, 0, 0, 0, 255, // Green
            0, 0, 0, 0, 255, // Blue
            0, 0, 0, 1, 0 //    Alpha
    });
    icon.setColorFilter(colorFilter); // force white color
    return icon;
}

From source file:org.ciasaboark.tacere.view.EventListItem.java

private void drawLocation() {
    if (locationIcon != null) {
        Drawable calendarIconDrawable = getResources().getDrawable(R.drawable.location);
        calendarIconDrawable.setColorFilter(iconTintColor, PorterDuff.Mode.MULTIPLY);
        locationIcon.setImageDrawable(calendarIconDrawable);
    }// w  w  w .ja va  2  s . c om

    if (locationBox != null) {
        String eventLocation = event.getLocation();
        if (eventLocation.equals("")) {
            locationBox.setVisibility(View.INVISIBLE);
        } else {
            locationBox.setVisibility(View.VISIBLE);
            TextView location = (TextView) view.findViewById(R.id.event_location);
            if (location != null) {
                location.setText(eventLocation);
                location.setTextColor(textColor);
            }

            if (isFutureEvent() && locationIcon != null) {
                try {
                    Drawable d = locationIcon.getDrawable();
                    d.mutate().setColorFilter(iconTintColor, PorterDuff.Mode.MULTIPLY);
                    locationIcon.setImageDrawable(d);
                } catch (NullPointerException e) {
                    Log.e(TAG, "caught null pointer exception pulling drawable from location icon");
                }
            }
        }
    }

}

From source file:org.ciasaboark.tacere.view.EventListItem.java

private void drawDateTimeText() {
    String beginDate = event.getLocalBeginDate();
    String endDate = event.getLocalEndDate();
    String beginTime = event.getLocalBeginTime();
    String endTime = event.getLocalEndTime();
    boolean usingExtendedMinutes = false;
    int extendMinutes = event.getExtendMinutes();
    if (extendMinutes != 0) {
        usingExtendedMinutes = true;/* w  w w  .ja va2s.c o  m*/
        endDate = event.getLocalEffectiveEndDate();
        endTime = event.getLocalEffectiveEndTime();
    }

    //there are a number of different ways to display the date and time
    if (beginDate.equals(endDate)) {
        if (event.isAllDay()) {
            //field1: <begin date>
            //field2: 'All Day'
            dateTimeField1.setText(beginDate);
            dateTimeField2.setText(R.string.all_day);
        } else {
            //field1: <begin date>
            //field2: <begin time> - <end time>
            dateTimeField1.setText(beginDate);
            dateTimeField2.setText(beginTime + " - " + endTime);
        }
    } else {
        if (event.isAllDay()) {
            //field1: <begin date> - <end date>
            //field2: 'All Day'
            dateTimeField1.setText(beginDate + " - " + endDate);
            dateTimeField2.setText(R.string.all_day);
        } else {
            //field1: <begin date> <begin time>
            //field2: <end date> <end time>
            dateTimeField1.setText(beginDate + " " + beginTime);
            dateTimeField2.setText(endDate + " " + endTime);
            if (usingExtendedMinutes) {
                dateTimeField2.setTypeface(null, Typeface.BOLD);
            }
        }
    }

    dateTimeField1.setTextColor(textColor);
    dateTimeField2.setTextColor(textColor);

    if (isFutureEvent() && clockIcon != null) {
        try {
            Drawable d = clockIcon.getDrawable();
            d.mutate().setColorFilter(iconTintColor, PorterDuff.Mode.MULTIPLY);
            clockIcon.setImageDrawable(d);
        } catch (NullPointerException e) {
            Log.e(TAG, "caught null pointer exception pulling drawable from clock icon");
        }
    }
}

From source file:com.irccloud.android.activity.BaseActivity.java

public void setMenuColorFilter(final Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem menuItem = menu.getItem(i);
        Drawable d = menuItem.getIcon();
        if (d != null) {
            d.mutate();
            d.setColorFilter(ColorScheme.getInstance().navBarSubheadingColor, PorterDuff.Mode.SRC_ATOP);
        }/*from  w  w w. java 2 s . c  om*/
    }
}

From source file:com.android.contacts.activities.ContactSelectionActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search_menu, menu);

    final MenuItem searchItem = menu.findItem(R.id.menu_search);
    searchItem.setVisible(!mIsSearchMode && mIsSearchSupported);

    final Drawable searchIcon = searchItem.getIcon();
    if (searchIcon != null) {
        searchIcon.mutate().setColorFilter(ContextCompat.getColor(this, R.color.actionbar_icon_color),
                PorterDuff.Mode.SRC_ATOP);
    }/* w  w w  . j  av a2 s .  c o  m*/
    return true;
}