package com.eftimoff.androidplayer.actions;

import android.view.View;

import com.eftimoff.androidplayer.actions.arc.CurveAction;
import com.eftimoff.androidplayer.actions.property.PropertyAction;

/**
 * Collection of common actions.
 * <p/>
 * Created by georgi.eftimov on 4/16/2015.
 */
public class Actions {

    private Actions() {
    }

    public static PropertyAction x(final View view, final float x) {
        return PropertyAction.newPropertyAction(view).translationX(x).build();
    }

    public static PropertyAction y(final View view, final float y) {
        return PropertyAction.newPropertyAction(view).translationY(y).build();
    }

    public static PropertyAction scale(final View view, final float x, final float y) {
        return PropertyAction.newPropertyAction(view).scaleX(x).scaleY(y).build();
    }

    public static PropertyAction alpha(final View view, final float alpha) {
        return PropertyAction.newPropertyAction(view).alpha(alpha).build();
    }

    public static CurveAction curve(final View view, final float x, final float y, final int degree) {
        final float base = abstand(view.getX(), view.getY(), x, y);
        final float heightOfTriangle = getHeightOfTriangle(base / 2, degree);
        final float xCoordinate = getXCoordinate(x / 2, heightOfTriangle, 90 - degree / 2);
        final float yCoordinate = getYCoordinate(y / 2, heightOfTriangle, 90 - degree / 2);
        return CurveAction.newControlPointsCurveAction(view).translationX(x).translationY(y).controlPoint1X(xCoordinate).controlPoint1Y(yCoordinate).controlPoint2X(xCoordinate).controlPoint2Y(yCoordinate).build();
    }

    private static float getHeightOfTriangle(final float base, final float baseDegree) {
        return (float) ((base / 2) * Math.tan(Math.toRadians(baseDegree)));
    }

    private static float getBaseOfRightTriangle(final float side) {
        return (float) Math.sqrt(2) * side;
    }

    private static float getXCoordinate(final float x, final float distance, final float angle) {
        return (float) (x + distance * (Math.cos(Math.toRadians(angle))));
    }

    private static float getYCoordinate(final float y, final float distance, final float angle) {
        return (float) (y + distance * (Math.sin(Math.toRadians(angle))));
    }

    private static float abstand(final float point1X, final float point1Y, final float point2X, final float point2Y) {
        return (float) Math.sqrt((point1X - point2X) * (point1X - point2X) + (point1Y - point2Y) * (point1Y - point2Y));
    }
}

@@ -1201,45 +1201,10 @@
 e = 
-getHeightOfTriangle(base / 2, degree)
+50
 ;%0A  
@@ -1493,17 +1493,20 @@
 Point1X(
-x
+getX
 Coordina
@@ -1499,32 +1499,61 @@
 X(getXCoordinate
+(x, heightOfTriangle, degree)
 ).controlPoint1Y
@@ -1553,17 +1553,20 @@
 Point1Y(
-y
+getY
 Coordina
@@ -1559,32 +1559,61 @@
 Y(getYCoordinate
+(y, heightOfTriangle, degree)
 ).controlPoint2X
@@ -1613,17 +1613,20 @@
 Point2X(
-x
+getX
 Coordina
@@ -1627,16 +1627,55 @@
 ordinate
+(view.getX(), heightOfTriangle, degree)
 ).contro
@@ -1683,17 +1683,20 @@
 Point2Y(
-y
+getY
 Coordina
@@ -1697,16 +1697,55 @@
 ordinate
+(view.getY(), heightOfTriangle, degree)
 ).build(

Create ArcAction that transition the View by an arc in the screen.