Android Open Source - android-slideshow-widget Random Transition Factory






From Project

Back to project page android-slideshow-widget.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions...

If you think the Android project android-slideshow-widget 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 com.marvinlabs.widget.slideshow.transition;
//from w ww. jav a  2s .co m
import android.animation.Animator;
import android.view.View;
import android.view.animation.Interpolator;

import com.marvinlabs.widget.slideshow.SlideShowView;
import com.marvinlabs.widget.slideshow.TransitionFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * A factory that will pick a random transition for the slides. This assumes that the IN animator is
 * always requested before the OUT animator.
 * <p/>
 * Created by Vincent Mimoun-Prat @ MarvinLabs on 02/06/2014.
 */
public class RandomTransitionFactory extends BaseTransitionFactory {

    private static final Random RAND = new Random();

    private final List<TransitionFactory> factories;

    private TransitionFactory currentFactory;

    static {
        RAND.setSeed(System.currentTimeMillis());
    }

    //==============================================================================================
    // GENERAL METHODS
    //==

    /**
     * Default constuctor
     */
    public RandomTransitionFactory() {
        this(DEFAULT_DURATION, DEFAULT_INTERPOLATOR);
    }

    /**
     * Constructor
     *
     * @param duration Duration for the transition in ms
     */
    public RandomTransitionFactory(long duration) {
        this(duration, DEFAULT_INTERPOLATOR);
    }

    /**
     * Constructor
     *
     * @param duration     The duration for the transition in ms
     * @param interpolator The kind of interpolator we need
     */
    public RandomTransitionFactory(long duration, Interpolator interpolator) {
        super(duration, interpolator);

        factories = new ArrayList<TransitionFactory>();
        factories.add(new FadeTransitionFactory(getDuration(), getInterpolator()));
        factories.add(new ZoomTransitionFactory(getDuration(), getInterpolator()));
        factories.add(new SlideAndZoomTransitionFactory(getDuration(), getInterpolator()));
        factories.add(new FlipTransitionFactory(getDuration(), getInterpolator()));
    }

    //==============================================================================================
    // INTERFACE IMPLEMENTATION: SlideTransitionFactory
    //==

    @Override
    public Animator getInAnimator(View target, SlideShowView parent, int fromSlide, int toSlide) {
        // Pick a factory for this round of transition
        int r = RAND.nextInt(factories.size());
        currentFactory = factories.get(r);

        return currentFactory.getInAnimator(target, parent, fromSlide, toSlide);
    }

    @Override
    public Animator getOutAnimator(View target, SlideShowView parent, int fromSlide, int toSlide) {
        // Factory has been picked when calling getInAnimator
        return currentFactory.getOutAnimator(target, parent, fromSlide, toSlide);
    }
}




Java Source Code List

com.marvinlabs.widget.slideshow.PlayList.java
com.marvinlabs.widget.slideshow.SlideShowAdapter.java
com.marvinlabs.widget.slideshow.SlideShowView.java
com.marvinlabs.widget.slideshow.TransitionFactory.java
com.marvinlabs.widget.slideshow.adapter.BitmapAdapter.java
com.marvinlabs.widget.slideshow.adapter.GenericBitmapAdapter.java
com.marvinlabs.widget.slideshow.adapter.GenericRemoteBitmapAdapter.java
com.marvinlabs.widget.slideshow.adapter.GenericResourceBitmapAdapter.java
com.marvinlabs.widget.slideshow.adapter.RemoteBitmapAdapter.java
com.marvinlabs.widget.slideshow.adapter.ResourceBitmapAdapter.java
com.marvinlabs.widget.slideshow.demo.SlideShowActivity.java
com.marvinlabs.widget.slideshow.picasso.GenericPicassoBitmapAdapter.java
com.marvinlabs.widget.slideshow.picasso.PicassoRemoteBitmapAdapter.java
com.marvinlabs.widget.slideshow.picasso.PicassoResourceBitmapAdapter.java
com.marvinlabs.widget.slideshow.playlist.RandomPlayList.java
com.marvinlabs.widget.slideshow.playlist.SequentialPlayList.java
com.marvinlabs.widget.slideshow.transition.BaseTransitionFactory.java
com.marvinlabs.widget.slideshow.transition.FadeTransitionFactory.java
com.marvinlabs.widget.slideshow.transition.FlipTransitionFactory.java
com.marvinlabs.widget.slideshow.transition.NoTransitionFactory.java
com.marvinlabs.widget.slideshow.transition.RandomTransitionFactory.java
com.marvinlabs.widget.slideshow.transition.SlideAndZoomTransitionFactory.java
com.marvinlabs.widget.slideshow.transition.ZoomTransitionFactory.java