package com.github.florent37.expectanim.core.scale;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.Gravity;
import android.view.View;

import com.github.florent37.expectanim.ViewCalculator;
import com.github.florent37.expectanim.core.AnimExpectation;

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

/**
 * Created by florentchampigny on 17/02/2017.
 */

public class ExpectAnimScaleManager {

    private final List<AnimExpectation> animExpectations;
    private final View viewToMove;
    private final ViewCalculator viewCalculator;

    private Float scaleX = null;
    private Float scaleY = null;

    private Float pivotX = null;
    private Float pivotY = null;

    public ExpectAnimScaleManager(List<AnimExpectation> animExpectations, View viewToMove, ViewCalculator viewCalculator) {
        this.animExpectations = animExpectations;
        this.viewToMove = viewToMove;
        this.viewCalculator = viewCalculator;
    }

    public void calculate() {

        for (AnimExpectation animExpectation : animExpectations) {
            if (animExpectation instanceof ScaleAnimExpectation) {
                final ScaleAnimExpectation expectation = (ScaleAnimExpectation) animExpectation;

                expectation.setViewCalculator(viewCalculator);

                final Float scaleX = expectation.getCalculatedValueScaleX(viewToMove);
                if (scaleX != null) {
                    this.scaleX = scaleX;
                }

                final Float scaleY = expectation.getCalculatedValueScaleY(viewToMove);
                if (scaleY != null) {
                    this.scaleY = scaleY;
                }

                final Integer gravityHorizontal = expectation.getGravityHorizontal();
                if (gravityHorizontal != null) {
                    switch (gravityHorizontal){
                        case Gravity.LEFT : pivotX = (float)viewToMove.getLeft(); break;
                        case Gravity.RIGHT : pivotX = (float)viewToMove.getRight(); break;
                        case Gravity.CENTER_HORIZONTAL:
                        case Gravity.CENTER : pivotX = viewToMove.getLeft() + viewToMove.getWidth()/2f; break;
                    }
                }

                final Integer gravityVertical = expectation.getGravityVertical();
                if (gravityVertical != null) {
                    switch (gravityVertical){
                        case Gravity.TOP : pivotY = (float)viewToMove.getTop(); break;
                        case Gravity.BOTTOM : pivotY = (float)viewToMove.getBottom(); break;
                        case Gravity.CENTER_VERTICAL:
                        case Gravity.CENTER : pivotY = viewToMove.getTop() + viewToMove.getHeight()/2f; break;
                    }
                }

            }
        }
    }

    public Float getScaleX() {
        return scaleX;
    }

    public Float getScaleY() {
        return scaleY;
    }

    public List<Animator> getAnimators() {
        final List<Animator> animations = new ArrayList<>();

        if(viewToMove != null){
            if (pivotX != null) {
                viewToMove.setPivotX(pivotX);
            }
            if (pivotY != null) {
                viewToMove.setPivotY(pivotY);
            }
        }

        if (scaleX != null) {
            animations.add(ObjectAnimator.ofFloat(viewToMove, View.SCALE_X, scaleX));
        }

        if (scaleY != null) {
            animations.add(ObjectAnimator.ofFloat(viewToMove, View.SCALE_Y, scaleY));
        }

        return animations;
    }
}

@@ -1906,18 +1906,89 @@
 ity.LEFT
- 
 :
+%0A                        case Gravity.START:%0A                           
  pivotX 
@@ -2013,24 +2013,52 @@
 e.getLeft();
+%0A                           
  break;%0A    
@@ -2095,18 +2095,87 @@
 ty.RIGHT
- 
 :
+%0A                        case Gravity.END:%0A                           
  pivotX 
@@ -2205,16 +2205,44 @@
 Right();
+%0A                           
  break;%0A

Add Gravity.START and Gravity.END to ExpectAnimScaleManager's switch statement