Example usage for android.support.v4.graphics.drawable DrawableCompat setTintList

List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTintList

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable DrawableCompat setTintList.

Prototype

public static void setTintList(Drawable drawable, ColorStateList colorStateList) 

Source Link

Usage

From source file:org.gateshipone.malp.application.fragments.serverfragments.MyMusicTabsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_tab_pager, container, false);

    // create tabs
    TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.my_music_tab_layout);

    // Icons/*from   w  w w  .  j a v  a2 s . c  o m*/
    final ColorStateList tabColors = tabLayout.getTabTextColors();
    Resources res = getResources();
    Drawable drawable = res.getDrawable(R.drawable.ic_recent_actors_24dp, null);
    if (drawable != null) {
        Drawable icon = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(icon, tabColors);
        tabLayout.addTab(tabLayout.newTab().setIcon(icon));
    }
    drawable = res.getDrawable(R.drawable.ic_album_24dp, null);
    if (drawable != null) {
        Drawable icon = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(icon, tabColors);
        tabLayout.addTab(tabLayout.newTab().setIcon(icon));
    }

    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    mViewPager = (ViewPager) rootView.findViewById(R.id.my_music_viewpager);
    mMyMusicPagerAdapter = new MyMusicPagerAdapter(getChildFragmentManager());
    mViewPager.setAdapter(mMyMusicPagerAdapter);
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.setOnTabSelectedListener(this);

    // set start page
    Bundle args = getArguments();

    DEFAULTTAB tab = DEFAULTTAB.ALBUMS;

    if (args != null && savedInstanceState == null) {
        tab = DEFAULTTAB.values()[args.getInt(MY_MUSIC_REQUESTED_TAB)];
        switch (tab) {
        case ARTISTS:
            mViewPager.setCurrentItem(0);
            break;
        case ALBUMS:
            mViewPager.setCurrentItem(1);
            break;
        }
    }

    // try to resume the saved search string
    if (savedInstanceState != null) {
        mSearchString = savedInstanceState.getString(MYMUSICFRAGMENT_SAVED_INSTANCE_SEARCH_STRING);
    }

    setHasOptionsMenu(true);
    return rootView;
}

From source file:com.classiqo.nativeandroid_32bitz.ui.MediaItemViewHolder.java

public static Drawable getDrawableByState(Context context, int state) {
    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(context);
    }/*from   w  w w  .j  a  va2  s.  c om*/

    switch (state) {
    case STATE_PLAYABLE:
        Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play_arrow_black_36dp);
        DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);

        return pauseDrawable;
    case STATE_PLAYING:
        AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context,
                R.drawable.ic_equalizer_white_36dp);
        DrawableCompat.setTintList(animation, sColorStatePlaying);
        animation.start();

        return animation;
    case STATE_PAUSED:
        Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.ic_equalizer1_white_36dp);
        DrawableCompat.setTintList(playDrawable, sColorStatePlaying);

        return playDrawable;
    default:
        return null;
    }
}

From source file:cat.terrones.devops.radiofx.ui.MediaItemViewHolder.java

public static Drawable getDrawableByState(Context context, int state) {
    if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
        initializeColorStateLists(context);
    }/*from ww  w.  j a v a  2  s.  co m*/

    switch (state) {
    case STATE_PLAYABLE:
        Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play_arrow_black_36dp);
        DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying);
        return pauseDrawable;
    case STATE_PLAYING:
        AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context,
                R.drawable.ic_equalizer_white_36dp);
        DrawableCompat.setTintList(animation, sColorStatePlaying);
        animation.start();
        return animation;
    case STATE_PAUSED:
        Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.ic_equalizer1_white_36dp);
        DrawableCompat.setTintList(playDrawable, sColorStatePlaying);
        return playDrawable;
    default:
        return null;
    }
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeSubheaderItemView.java

@Override
public void setIconTintList(ColorStateList tintList) {
    mExpandDrawable = DrawableCompat.wrap(mExpandDrawable.getConstantState().newDrawable()).mutate();
    DrawableCompat.setTintList(mExpandDrawable, tintList);

    mCollapseDrawable = DrawableCompat.wrap(mCollapseDrawable.getConstantState().newDrawable()).mutate();
    DrawableCompat.setTintList(mCollapseDrawable, tintList);

    super.setIconTintList(tintList);
}

From source file:org.solovyev.android.widget.menu.CustomPopupMenuHelper.java

static void tintMenuItem(@Nonnull MenuItemImpl item, @Nonnull ColorStateList tintColorStateList) {
    Drawable icon = item.getIcon();/* www  . java2  s.  c om*/
    if (icon != null) {
        icon = DrawableCompat.wrap(icon);
        DrawableCompat.setTintList(icon, tintColorStateList);
        item.setIcon(icon);
    }
    if (item.hasSubMenu()) {
        final SubMenu subMenu = item.getSubMenu();
        for (int i = 0; i < subMenu.size(); i++) {
            final MenuItem subItem = subMenu.getItem(i);
            if (subItem instanceof MenuItemImpl) {
                tintMenuItem((MenuItemImpl) subItem, tintColorStateList);
            }
        }
    }
}

From source file:android.support.v7.widget.AppCompatCompoundButtonHelper.java

void applyButtonTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView);

    if (buttonDrawable != null && (mHasButtonTint || mHasButtonTintMode)) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable);
        buttonDrawable = buttonDrawable.mutate();
        if (mHasButtonTint) {
            DrawableCompat.setTintList(buttonDrawable, mButtonTintList);
        }/*  w ww .j av a 2 s  .  c o m*/
        if (mHasButtonTintMode) {
            DrawableCompat.setTintMode(buttonDrawable, mButtonTintMode);
        }
        // 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());
        }
        mView.setButtonDrawable(buttonDrawable);
    }
}

From source file:org.gateshipone.odyssey.fragments.MyMusicFragment.java

/**
 * Called to create instantiate the UI of the fragment.
 *///from w w  w .ja v a2s.  com
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_my_music, container, false);

    // create tabs
    TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.my_music_tab_layout);

    // setup icons for tabs
    final ColorStateList tabColors = tabLayout.getTabTextColors();
    Resources res = getResources();
    Drawable drawable = res.getDrawable(R.drawable.ic_recent_actors_24dp, null);
    if (drawable != null) {
        Drawable icon = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(icon, tabColors);
        tabLayout.addTab(tabLayout.newTab().setIcon(icon));
    }
    drawable = res.getDrawable(R.drawable.ic_album_24dp, null);
    if (drawable != null) {
        Drawable icon = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(icon, tabColors);
        tabLayout.addTab(tabLayout.newTab().setIcon(icon));
    }
    drawable = res.getDrawable(R.drawable.ic_my_library_music_24dp, null);
    if (drawable != null) {
        Drawable icon = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(icon, tabColors);
        tabLayout.addTab(tabLayout.newTab().setIcon(icon));
    }
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    // setup viewpager
    mMyMusicViewPager = (ViewPager) rootView.findViewById(R.id.my_music_viewpager);
    mMyMusicPagerAdapter = new MyMusicPagerAdapter(getChildFragmentManager());
    mMyMusicViewPager.setAdapter(mMyMusicPagerAdapter);
    mMyMusicViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    mMyMusicViewPager.setOffscreenPageLimit(2);
    tabLayout.addOnTabSelectedListener(this);

    // set start page
    Bundle args = getArguments();

    // only set requested tab if no state was saved
    if (args != null && savedInstanceState == null) {
        DEFAULTTAB tab = DEFAULTTAB.values()[args.getInt(MY_MUSIC_REQUESTED_TAB)];

        switch (tab) {
        case ARTISTS:
            mMyMusicViewPager.setCurrentItem(0, false);
            break;
        case ALBUMS:
            mMyMusicViewPager.setCurrentItem(1, false);
            break;
        case TRACKS:
            mMyMusicViewPager.setCurrentItem(2, false);
            break;
        }

    }

    // activate options menu in toolbar
    setHasOptionsMenu(true);

    // set up pbs connection
    mServiceConnection = new PlaybackServiceConnection(getActivity().getApplicationContext());
    mServiceConnection.openConnection();

    // try to resume the saved search string
    if (savedInstanceState != null) {
        mSearchString = savedInstanceState.getString(MYMUSICFRAGMENT_SAVED_INSTANCE_SEARCH_STRING);
    }

    return rootView;
}

From source file:com.tompee.funtablayout.FlipTabAdapter.java

private Drawable loadIconWithTint(Context context, @DrawableRes int resourceId) {
    Drawable icon = ContextCompat.getDrawable(context, resourceId);
    ColorStateList colorStateList;/* w ww.ja va2  s  .c  o m*/
    int[][] states = new int[][] { new int[] { android.R.attr.state_selected },
            new int[] { -android.R.attr.state_empty } };
    int[] colors = new int[] { mTabIndicatorColor, mDefaultIconColor };
    colorStateList = new ColorStateList(states, colors);
    icon = DrawableCompat.wrap(icon);
    DrawableCompat.setTintList(icon, colorStateList);
    return icon;
}

From source file:com.bilibili.magicasakura.utils.ThemeUtils.java

public static Drawable tintDrawable(Drawable drawable, ColorStateList cls, PorterDuff.Mode mode) {
    if (drawable == null)
        return null;
    Drawable wrapper = DrawableCompat.wrap(drawable.mutate());
    DrawableCompat.setTintList(wrapper, cls);
    DrawableCompat.setTintMode(drawable, mode);
    return wrapper;
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeBaseItemView.java

private Drawable prepareIcon(Drawable icon) {
    icon = DrawableCompat.wrap(icon.getConstantState().newDrawable()).mutate();
    icon.setBounds(0, 0, mIconSize, mIconSize);
    DrawableCompat.setTintList(icon, mIconTintList);
    return icon;/*  w w w .  jav  a 2 s  .co  m*/
}