Android Open Source - Swipe-Tabs Rotation Page 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;
/*from   ww  w. ja  v a  2 s  .c  o  m*/
import android.annotation.TargetApi;
import android.os.Build;
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * This page transformer will create the effect that each page is an edge of a regular polygon
 * that is rotated to show each page. Can only be used on devices with Honeycomb or higher api
 *
 * Example usage:
 *
 *
 <pre>
 * if(BUILD.VERSION.SDK_INT >= BUILD.VERSION_CODES.HONEYCOMB){
 *  mPager.setPageTransformer(true, new RotationPageTransformer(DEGREES_BETWEEN_CARDS));
 *  mPager.setOffscreenPageLimit(mPagerAdapter.getCount());
 *  mPager.setPageMargin(-2 * paddingOnPages);
 *  mPager.setClipChildren(false);
 * }
 </pre>
 *
 * @author Steven Kideckel
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class RotationPageTransformer implements ViewPager.PageTransformer{
    private float minAlpha;
    private int degrees = 165;
    private float distanceToCentreFactor;

    public RotationPageTransformer() {
        this(165, 0.7f);
    }

    /**
     * Creates a RotationPageTransformer
     * @param degrees the inner angle between two edges in the "polygon" that the pages are on.
     * Note: this will only work with obtuse angles
     * on the outside of the shape
     */
    public RotationPageTransformer(int degrees){
        this(degrees, 0.7f);
    }
    /**
     * Creates a RotationPageTransformer
     * @param degrees the inner angle between two edges in the "polygon" that the pages are on.
     * Note: this will only work with obtuse angles
     * @param minAlpha the least faded out that the side
     */
    public RotationPageTransformer(int degrees, float minAlpha){
        this.degrees = degrees;
        distanceToCentreFactor = (float) Math.tan(Math.toRadians(degrees / 2))/2;
        this.minAlpha = minAlpha;
    }
    public void transformPage(View view, float position){
        int pageWidth = view.getWidth();
        int pageHeight = view.getHeight();
        view.setPivotX((float) pageWidth / 2);
        view.setPivotY((float) (pageHeight + pageWidth * distanceToCentreFactor));
        if(position < -1){ //[-infinity,1)
//off to the left by a lot
            view.setRotation(0);
            view.setAlpha(0);
            view.setTranslationX(0);
        }else if(position <= 1){ //[-1,1]
            view.setTranslationX((-position) * pageWidth);
            view.setRotation(position * (180 - degrees));
// Fade the page relative to its distance from the center
            view.setAlpha(Math.max(minAlpha, 1 - Math.abs(position)/3));
        }else{ //(1, +infinity]
//off to the right by a lot
            view.setRotation(0);
            view.setAlpha(0);
            view.setTranslationX(0);
        }
    }
}




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