Android Open Source - Paginize View Pager Page






From Project

Back to project page Paginize.

License

The source code is released under:

Copyright (c) 2014 neevek <i at neevek.net> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal ...

If you think the Android project Paginize listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.neevek.android.lib.paginize;
/*from  w w  w .  j av  a  2 s . c  o  m*/
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import net.neevek.android.lib.paginize.annotation.ViewPagerResId;
import net.neevek.android.lib.paginize.exception.InjectFailedException;

/**
 * A Page that is used to hold a ViewPager
 *
 * Created by neevek on 6/15/14.
 */
public abstract class ViewPagerPage extends Page {
    private ViewPager mViewPager;

    public ViewPagerPage(PageActivity pageActivity) {
        super(pageActivity);

        Class clazz = getClass();

        ViewPagerResId resIdAnnotation = null;

        try {
            do {
                if (clazz.isAnnotationPresent(ViewPagerResId.class)) {
                    resIdAnnotation = (ViewPagerResId)clazz.getAnnotation(ViewPagerResId.class);
                    break;
                }
            } while ((clazz = clazz.getSuperclass()) != ViewPagerPage.class);

        } catch (Exception e) {
            e.printStackTrace();
            throw new InjectFailedException(e);
        }

        if (resIdAnnotation == null) {
            throw new IllegalStateException("Must specify a ViewPager resource Id for "+ clazz.getSimpleName() +" with the @ViewPagerResId annotation.");
        }

        View view = getView().findViewById(resIdAnnotation.value());
        if (view == null) {
            throw new IllegalStateException("Can not find the View with the specified resource ID: " + resIdAnnotation.value());
        }
        if (!(view instanceof ViewPager)) {
            throw new IllegalStateException("The specified View with @ViewPagerResId is not of type ViewPager.");
        }

        mViewPager = (ViewPager)view;
    }

    protected ViewPager getViewPager() {
        return mViewPager;
    }

    private PagePagerAdapter getPagePagerAdapter() {
        PagerAdapter adapter = mViewPager.getAdapter();
        if (adapter instanceof PagePagerAdapter) {
            return (PagePagerAdapter)adapter;
        }
        return null;
    }

    public void onAttach() {
        // do nothing here, onAttach is called on the ViewWrapper when
        // it is added to ViewPager
    }

    public void onDetach() {
        // do nothing here, onAttach is called on the ViewWrapper when
        // it is removed from ViewPager
    }

    public boolean onBackPressed() {
        PagePagerAdapter adapter = getPagePagerAdapter();
        if (adapter != null && adapter.getCount() > 0) {
            return adapter.getItem(mViewPager.getCurrentItem()).onBackPressed();
        }

        return false;
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        PagePagerAdapter adapter = getPagePagerAdapter();
        if (adapter != null && adapter.getCount() > 0) {
            adapter.getItem(mViewPager.getCurrentItem()).onActivityResult(requestCode, resultCode, data);
        }
    }

    public void onPause() {
        PagePagerAdapter adapter = getPagePagerAdapter();
        if (adapter != null && adapter.getCount() > 0) {
            adapter.getItem(mViewPager.getCurrentItem()).onPause();
        }
    }

    public void onResume() {
        PagePagerAdapter adapter = getPagePagerAdapter();
        if (adapter != null && adapter.getCount() > 0) {
            adapter.getItem(mViewPager.getCurrentItem()).onResume();
        }
    }

    public void onShown(Object arg) {
        PagePagerAdapter adapter = getPagePagerAdapter();
        if (adapter != null && adapter.getCount() > 0) {
            adapter.getItem(mViewPager.getCurrentItem()).onShown(arg);
        }
    }

    public void onHidden() {
        PagePagerAdapter adapter = getPagePagerAdapter();
        if (adapter != null && adapter.getCount() > 0) {
            adapter.getItem(mViewPager.getCurrentItem()).onHidden();
        }
    }

    public void onCovered() {
        PagePagerAdapter adapter = getPagePagerAdapter();
        if (adapter != null && adapter.getCount() > 0) {
            adapter.getItem(mViewPager.getCurrentItem()).onCovered();
        }
    }

    public void onUncovered(Object arg) {
        PagePagerAdapter adapter = getPagePagerAdapter();
        if (adapter != null && adapter.getCount() > 0) {
            adapter.getItem(mViewPager.getCurrentItem()).onUncovered(arg);
        }
    }
}




Java Source Code List

net.neevek.android.demo.paginize.activities.MainActivity.java
net.neevek.android.demo.paginize.pages.general.FrameInnerPage.java
net.neevek.android.demo.paginize.pages.general.FramePage.java
net.neevek.android.demo.paginize.pages.main.MainPage.java
net.neevek.android.demo.paginize.pages.main.TabPage1.java
net.neevek.android.demo.paginize.pages.main.TabPage2.java
net.neevek.android.demo.paginize.pages.other.AlertPage.java
net.neevek.android.demo.paginize.pages.other.ListItemPage.java
net.neevek.android.demo.paginize.pages.other.ListPage.java
net.neevek.android.demo.paginize.pages.other.TestPage.java
net.neevek.android.demo.paginize.pages.viewpager.MyViewPagerPage.java
net.neevek.android.demo.paginize.pages.viewpager.ViewPageSubPage1.java
net.neevek.android.demo.paginize.pages.viewpager.ViewPageSubPage2.java
net.neevek.android.lib.paginize.InnerPageContainer.java
net.neevek.android.lib.paginize.InnerPageManager.java
net.neevek.android.lib.paginize.InnerPage.java
net.neevek.android.lib.paginize.PageActivity.java
net.neevek.android.lib.paginize.PageDataCallback.java
net.neevek.android.lib.paginize.PageManager.java
net.neevek.android.lib.paginize.PagePagerAdapter.java
net.neevek.android.lib.paginize.Page.java
net.neevek.android.lib.paginize.ViewPagerInnerPage.java
net.neevek.android.lib.paginize.ViewPagerPage.java
net.neevek.android.lib.paginize.ViewWrapper.java
net.neevek.android.lib.paginize.anim.PageAnimator.java
net.neevek.android.lib.paginize.anim.SlidePageAnimator.java
net.neevek.android.lib.paginize.anim.ZoomPageAnimator.java
net.neevek.android.lib.paginize.annotation.DecoratePageConstructor.java
net.neevek.android.lib.paginize.annotation.InheritPageLayout.java
net.neevek.android.lib.paginize.annotation.InjectPageAnimator.java
net.neevek.android.lib.paginize.annotation.InjectView.java
net.neevek.android.lib.paginize.annotation.InnerPageContainerLayoutResId.java
net.neevek.android.lib.paginize.annotation.PageLayout.java
net.neevek.android.lib.paginize.annotation.SetListeners.java
net.neevek.android.lib.paginize.annotation.ViewPagerResId.java
net.neevek.android.lib.paginize.exception.InjectFailedException.java
net.neevek.android.lib.paginize.exception.NotImplementedInterfaceException.java
net.neevek.android.lib.paginize.util.AnnotationUtils.java
net.neevek.android.lib.paginize.util.ViewFinder.java