package fr.ludovic.vimont.carouselviewpager;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.Animation;

import java.util.ArrayList;

import fr.ludovic.vimont.carouselviewpager.model.Entity;
import fr.ludovic.vimont.carouselviewpager.view.CarouselViewPager;

public class MainActivity extends AppCompatActivity {
    private CarouselViewPager carousel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        carousel = findViewById(R.id.carousel);
        ArrayList<Entity> entities = buildData();
        CarouselAdapter carouselAdapter = new CarouselAdapter(this, carousel, getSupportFragmentManager(), entities);

        carousel.setAdapter(carouselAdapter);
        carousel.addOnPageChangeListener(carouselAdapter);
        carousel.setOffscreenPageLimit(entities.size());
        carousel.setClipToPadding(false);

        carousel.setScrollDurationFactor(1.5f);
        carousel.setAlpha(0.0f);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            carousel.startAnimation(false, new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    carousel.setAlpha(1.0f);
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            });
        }
    }

    private ArrayList<Entity> buildData() {
        ArrayList<Entity> entities = new ArrayList<>();
        entities.add(new Entity(R.drawable.americano, getString(R.string.americano_title), getString(R.string.americano_description)));
        entities.add(new Entity(R.drawable.cappucino, getString(R.string.cappucino_title), getString(R.string.cappucino_description)));
        entities.add(new Entity(R.drawable.latte, getString(R.string.latte_title), getString(R.string.latte_description)));
        entities.add(new Entity(R.drawable.mocha, getString(R.string.mocha_title), getString(R.string.mocha_description)));
        entities.add(new Entity(R.drawable.ristretto, getString(R.string.ristretto_title), getString(R.string.ristretto_description)));
        entities.add(new Entity(R.drawable.short_coffee, getString(R.string.short_coffee_title), getString(R.string.short_coffee_description)));
        entities.add(new Entity(R.drawable.vienna, getString(R.string.vienna_title), getString(R.string.vienna_description)));
        return entities;
    }
}
@@ -402,16 +402,25 @@
 carousel
+ViewPager
 ;%0A%0A    @
@@ -594,16 +594,25 @@
 carousel
+ViewPager
  = findV
@@ -693,16 +693,22 @@
         
+final 
 Carousel
@@ -767,16 +767,25 @@
 carousel
+ViewPager
 , getSup
@@ -831,24 +831,33 @@
     carousel
+ViewPager
 .setAdapter(
@@ -890,16 +890,25 @@
 carousel
+ViewPager
 .addOnPa
@@ -954,24 +954,33 @@
     carousel
+ViewPager
 .setOffscree
@@ -1020,24 +1020,33 @@
     carousel
+ViewPager
 .setClipToPa
@@ -1072,24 +1072,33 @@
     carousel
+ViewPager
 .setScrollDu
@@ -1121,32 +1121,123 @@
 f);%0A        
-carousel
+// Used for the animation we hide the ViewPager until the animation start%0A        carouselViewPager
 .setAlpha(0.
@@ -1401,24 +1401,102 @@
         
-carousel
+// As soon as, we have the focus we launch the animation%0A            carouselViewPager
 .startAn
@@ -1660,24 +1660,92 @@
         
-carousel
+// And we display the widget to see it%0A                    carouselViewPager
 .setAlph

Rename + comments