Search in sources :

Example 1 with FirstrunPagerAdapter

use of org.mozilla.focus.firstrun.FirstrunPagerAdapter in project Rocket by mozilla-tw.

the class FirstrunFragment method findPagerAdapter.

private PagerAdapter findPagerAdapter(Context context, View.OnClickListener onClickListener) {
    final PagerAdapter pagerAdapter;
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    boolean shown = sharedPreferences.getBoolean(PREF_KEY_BOOLEAN_FIRSTRUN_SHOWN, false);
    int firstrunUpgradeVersion = sharedPreferences.getInt(PREF_KEY_INT_FIRSTRUN_UPGRADE_VERSION, 0);
    if (!shown) {
        pagerAdapter = new FirstrunPagerAdapter(context, onClickListener);
    } else if (FIRSTRUN_UPGRADE_VERSION > firstrunUpgradeVersion) {
        pagerAdapter = new FirstrunUpgradePagerAdapter(context, onClickListener);
    } else {
        pagerAdapter = null;
    }
    return pagerAdapter;
}
Also used : FirstrunUpgradePagerAdapter(org.mozilla.focus.firstrun.FirstrunUpgradePagerAdapter) SharedPreferences(android.content.SharedPreferences) FirstrunPagerAdapter(org.mozilla.focus.firstrun.FirstrunPagerAdapter) PagerAdapter(android.support.v4.view.PagerAdapter) FirstrunUpgradePagerAdapter(org.mozilla.focus.firstrun.FirstrunUpgradePagerAdapter) FirstrunPagerAdapter(org.mozilla.focus.firstrun.FirstrunPagerAdapter)

Example 2 with FirstrunPagerAdapter

use of org.mozilla.focus.firstrun.FirstrunPagerAdapter in project focus-android by mozilla-mobile.

the class FirstrunFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_firstrun, container, false);
    view.findViewById(R.id.skip).setOnClickListener(this);
    background = view.findViewById(R.id.background);
    final FirstrunPagerAdapter adapter = new FirstrunPagerAdapter(container.getContext(), this);
    viewPager = (ViewPager) view.findViewById(R.id.pager);
    viewPager.setFocusable(true);
    viewPager.setPageTransformer(true, new ViewPager.PageTransformer() {

        @Override
        public void transformPage(View page, float position) {
            page.setAlpha(1 - (0.5f * Math.abs(position)));
        }
    });
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            TelemetryWrapper.showFirstRunPageEvent(position);
        }

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

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    viewPager.setClipToPadding(false);
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            final TransitionDrawable drawable = (TransitionDrawable) background.getBackground();
            if (position == adapter.getCount() - 1) {
                drawable.startTransition(200);
            } else {
                drawable.resetTransition();
            }
        }

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

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    final TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager, true);
    return view;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) FirstrunPagerAdapter(org.mozilla.focus.firstrun.FirstrunPagerAdapter) TabLayout(android.support.design.widget.TabLayout) View(android.view.View) ViewPager(android.support.v4.view.ViewPager)

Aggregations

FirstrunPagerAdapter (org.mozilla.focus.firstrun.FirstrunPagerAdapter)2 SharedPreferences (android.content.SharedPreferences)1 TransitionDrawable (android.graphics.drawable.TransitionDrawable)1 TabLayout (android.support.design.widget.TabLayout)1 PagerAdapter (android.support.v4.view.PagerAdapter)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 FirstrunUpgradePagerAdapter (org.mozilla.focus.firstrun.FirstrunUpgradePagerAdapter)1