Example usage for android.content.res Resources getDrawable

List of usage examples for android.content.res Resources getDrawable

Introduction

In this page you can find the example usage for android.content.res Resources getDrawable.

Prototype

public Drawable getDrawable(@DrawableRes int id, @Nullable Theme theme) throws NotFoundException 

Source Link

Document

Return a drawable object associated with a particular resource ID and styled for the specified theme.

Usage

From source file:Main.java

/**
 * @see android.content.res.Resources#getDrawable(int id).
 *//*from  ww w  . j  a v a  2s . c  o m*/
@SuppressWarnings("deprecation")
public static Drawable getDrawable(Resources res, int id) throws NotFoundException {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return res.getDrawable(id, null);
    } else {
        return res.getDrawable(id);
    }
}

From source file:Main.java

public static Drawable getDrawableByWidthAndHeight(Resources res, int drawId, int width, int height) {
    Drawable draw = null;//ww w.  ja va2s . co  m
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        draw = res.getDrawable(drawId, null);
    } else {
        draw = res.getDrawable(drawId);
    }
    draw.setBounds(0, 0, width, height);
    return draw;
}

From source file:org.gateshipone.malp.application.fragments.serverfragments.ServerPropertiesFragment.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);

    mViewPager = (ViewPager) rootView.findViewById(R.id.my_music_viewpager);
    mTabAdapter = new ServerPropertiesTabAdapter(getChildFragmentManager());
    mViewPager.setAdapter(mTabAdapter);//from   w  w  w.  j  a v  a  2s  . co m
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.setOnTabSelectedListener(this);

    // Icons
    final ColorStateList tabColors = tabLayout.getTabTextColors();
    Resources res = getResources();
    Drawable drawable = res.getDrawable(R.drawable.ic_statistics_black_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_hearing_black_24dp, null);
    if (drawable != null) {
        Drawable icon = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(icon, tabColors);
        tabLayout.addTab(tabLayout.newTab().setIcon(icon));
    }

    mViewPager.setCurrentItem(0);

    return rootView;
}

From source file:com.github.mkjensen.dml.live.SetupFragment.java

@NonNull
@Override//  ww  w . j a  v  a 2s.c o  m
public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
    Resources resources = getResources();
    String title = resources.getString(R.string.app_name);
    String description = resources.getString(R.string.live_setup_description);
    Drawable icon = resources.getDrawable(R.mipmap.ic_launcher, null);
    return new GuidanceStylist.Guidance(title, description, BREADCRUMB, icon);
}

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 a 2s. com
    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:org.gateshipone.odyssey.fragments.MyMusicFragment.java

/**
 * Called to create instantiate the UI of the fragment.
 *//*from  w  ww  .ja  va 2  s .  c o  m*/
@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;
}