Android Open Source - Swipe-Tabs Base Transformer






From Project

Back to project page Swipe-Tabs.

License

The source code is released under:

MIT License

If you think the Android project Swipe-Tabs 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 it.bellotti.android.swipetabs.transforms;
// w w  w.ja  v a2  s.  c o  m
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * Created with IntelliJ IDEA.
 * User: Simone Bellotti
 * Date: 26/09/2014
 * Time: 10.34
 */
public abstract class BaseTransformer implements ViewPager.PageTransformer {

    /**
     * Called each {@link #transformPage(View, float)}.
     *
     * @param view
     * @param position
     */
    protected abstract void onTransform(View view, float position);

    @Override
    public void transformPage(View view, float position) {
        onPreTransform(view, position);
        onTransform(view, position);
        onPostTransform(view, position);
    }

    /**
     * If the position offset of a fragment is less than negative one or greater than one, returning true will set the
     * visibility of the fragment to {@link View#GONE}. Returning false will force the fragment to {@link View#VISIBLE}.
     *
     * @return
     */
    protected boolean hideOffscreenPages() {
        return true;
    }

    /**
     * Indicates if the default animations of the view pager should be used.
     *
     * @return
     */
    protected boolean isPagingEnabled() {
        return false;
    }

    /**
     * Called each {@link #transformPage(View, float)} before {{@link #onTransform(View, float)} is called.
     *
     * @param view
     * @param position
     */
    protected void onPreTransform(View view, float position) {
        final float width = view.getWidth();
        view.setRotationX(0);
        view.setRotationY(0);
        view.setRotation(0);
        view.setScaleX(1);
        view.setScaleY(1);
        view.setPivotX(0);
        view.setPivotY(0);
        view.setTranslationY(0);
        view.setTranslationX(isPagingEnabled() ? 0f : -width * position);
        if (hideOffscreenPages()) {
            view.setAlpha(position <= -1f || position >= 1f ? 0f : 1f);
        } else {
            view.setAlpha(1f);
        }
    }

    /**
     * Called each {@link #transformPage(View, float)} call after {@link #onTransform(View, float)} is finished.
     *
     * @param view
     * @param position
     */
    protected void onPostTransform(View view, float position) {
    }
}




Java Source Code List

it.bellotti.android.swipetabs.activities.MainActivity.java
it.bellotti.android.swipetabs.adapters.TabsPagerAdapter.java
it.bellotti.android.swipetabs.fragments.CalendarFragment.java
it.bellotti.android.swipetabs.fragments.HomeFragment.java
it.bellotti.android.swipetabs.fragments.StatisticsFragment.java
it.bellotti.android.swipetabs.transforms.AccordionTransformer.java
it.bellotti.android.swipetabs.transforms.AlphaTransformer.java
it.bellotti.android.swipetabs.transforms.BackgroundToForegroundTransformer.java
it.bellotti.android.swipetabs.transforms.BaseTransformer.java
it.bellotti.android.swipetabs.transforms.CubeInTransformer.java
it.bellotti.android.swipetabs.transforms.CubeOutTransformer.java
it.bellotti.android.swipetabs.transforms.DepthPageTransformer.java
it.bellotti.android.swipetabs.transforms.FlipHorizontalTransformer.java
it.bellotti.android.swipetabs.transforms.FlipVerticalTransformer.java
it.bellotti.android.swipetabs.transforms.ForegroundToBackgroundTransformer.java
it.bellotti.android.swipetabs.transforms.ParallaxPageTransformer.java
it.bellotti.android.swipetabs.transforms.RotateDownTransformer.java
it.bellotti.android.swipetabs.transforms.RotateUpTransformer.java
it.bellotti.android.swipetabs.transforms.RotationPageTransformer.java
it.bellotti.android.swipetabs.transforms.ScalePageTransformer.java
it.bellotti.android.swipetabs.transforms.StackTransformer.java
it.bellotti.android.swipetabs.transforms.TabletTransformer.java
it.bellotti.android.swipetabs.transforms.ZoomInPageTransformer.java
it.bellotti.android.swipetabs.transforms.ZoomOutPageTransformer.java
it.bellotti.android.swipetabs.transforms.ZoomOutSlideTransformer.java