Search in sources :

Example 1 with BaseFragment

use of io.github.ryanhoo.music.ui.base.BaseFragment in project StylishMusicPlayer by ryanhoo.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);
    // Main Controls' Titles
    mTitles = getResources().getStringArray(R.array.mp_main_titles);
    // Fragments
    BaseFragment[] fragments = new BaseFragment[mTitles.length];
    fragments[0] = new PlayListFragment();
    fragments[1] = new MusicPlayerFragment();
    fragments[2] = new LocalFilesFragment();
    fragments[3] = new SettingsFragment();
    // Inflate ViewPager
    MainPagerAdapter adapter = new MainPagerAdapter(getSupportFragmentManager(), mTitles, fragments);
    viewPager.setAdapter(adapter);
    viewPager.setOffscreenPageLimit(adapter.getCount() - 1);
    viewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.mp_margin_large));
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        // Empty
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        // Empty
        }

        @Override
        public void onPageSelected(int position) {
            radioButtons.get(position).setChecked(true);
        }
    });
    radioButtons.get(DEFAULT_PAGE_INDEX).setChecked(true);
}
Also used : MusicPlayerFragment(io.github.ryanhoo.music.ui.music.MusicPlayerFragment) SettingsFragment(io.github.ryanhoo.music.ui.settings.SettingsFragment) PlayListFragment(io.github.ryanhoo.music.ui.playlist.PlayListFragment) LocalFilesFragment(io.github.ryanhoo.music.ui.local.LocalFilesFragment) ViewPager(android.support.v4.view.ViewPager) BaseFragment(io.github.ryanhoo.music.ui.base.BaseFragment)

Aggregations

ViewPager (android.support.v4.view.ViewPager)1 BaseFragment (io.github.ryanhoo.music.ui.base.BaseFragment)1 LocalFilesFragment (io.github.ryanhoo.music.ui.local.LocalFilesFragment)1 MusicPlayerFragment (io.github.ryanhoo.music.ui.music.MusicPlayerFragment)1 PlayListFragment (io.github.ryanhoo.music.ui.playlist.PlayListFragment)1 SettingsFragment (io.github.ryanhoo.music.ui.settings.SettingsFragment)1