Search in sources :

Example 1 with Dagger2MetricsFragment

use of com.frogermcs.androiddevmetrics.internal.ui.fragment.Dagger2MetricsFragment in project AndroidDevMetrics by frogermcs.

the class MetricsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.adm_activity_metrics);
    btnActivities = (Button) findViewById(R.id.btnActivities);
    btnDagger2 = (Button) findViewById(R.id.btnDagger2);
    vpMetrics = (ViewPager) findViewById(R.id.vpMetrics);
    activitiesMetricsFragment = new ActivitiesMetricsFragment();
    dagger2MetricsFragment = new Dagger2MetricsFragment();
    FragmentPagerAdapter fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return activitiesMetricsFragment;
            } else if (position == 1) {
                return dagger2MetricsFragment;
            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;
        }
    };
    vpMetrics.setAdapter(fragmentPagerAdapter);
    vpMetrics.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

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

        @Override
        public void onPageSelected(int position) {
            if (position == 0) {
                activitiesPageSelected();
            } else if (position == 1) {
                daggerPageSelected();
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    btnActivities.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            vpMetrics.setCurrentItem(0);
        }
    });
    btnDagger2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            vpMetrics.setCurrentItem(1);
        }
    });
    activitiesPageSelected();
}
Also used : Dagger2MetricsFragment(com.frogermcs.androiddevmetrics.internal.ui.fragment.Dagger2MetricsFragment) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ActivitiesMetricsFragment(com.frogermcs.androiddevmetrics.internal.ui.fragment.ActivitiesMetricsFragment) ViewPager(android.support.v4.view.ViewPager) View(android.view.View)

Aggregations

FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ActivitiesMetricsFragment (com.frogermcs.androiddevmetrics.internal.ui.fragment.ActivitiesMetricsFragment)1 Dagger2MetricsFragment (com.frogermcs.androiddevmetrics.internal.ui.fragment.Dagger2MetricsFragment)1