Skip to content

Commit

Permalink
Change the creation of the Player.
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Eftimov committed Apr 28, 2015
1 parent 3792eea commit 838f1e5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
## android-player
Animations when entering actvity or fragment made easy.</br>
Animations when entering Actvity or Fragment made easy.</br>
Backward compatibility API 12.

#### You have created beautiful UI , but it is boring

![svg](https://github.com/geftimov/android-player/blob/master/art/playerPhoto.png)

#### Run the player and you will can create beautiful transitions for your views.
#### Run the player and you will can create beautiful transitions for your views when entering Activity / Fragment.

```java
Player.with(toolbar).
Player.init().
animate(headerAction).
then().
animate(fabAction).
Expand Down
27 changes: 20 additions & 7 deletions androidplayer/src/main/java/com/eftimoff/androidplayer/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@
public class Player {

private List<List<BaseAction>> list;
private View view;
private PlayerStartListener playerStartListener;
private PlayerEndListener playerEndListener;
final Handler handler = new Handler();

private Player(final View view) {
private Player() {
list = new ArrayList<List<BaseAction>>();
list.add(new ArrayList<BaseAction>());
this.view = view;
}

public static Player with(final View view) {
return new Player(view);
public static Player init() {
return new Player();
}

public Player animate(final BaseAction action) {
Expand All @@ -49,17 +47,32 @@ public Player then() {
}

public void play() {
view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
final View firstView = getFirstView();
if (firstView == null) {
return;
}
firstView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
view.getViewTreeObserver().removeOnPreDrawListener(this);
firstView.getViewTreeObserver().removeOnPreDrawListener(this);
initAll();
animateAll();
return true;
}
});
}

private View getFirstView() {
final List<BaseAction> baseActions = list.get(0);
if (baseActions != null) {
final BaseAction baseAction = baseActions.get(0);
if (baseAction != null) {
return baseAction.getView();
}
}
return null;
}

private void initAll() {
for (final List<BaseAction> baseActions : list) {
for (final BaseAction baseAction : baseActions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ 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) {
private static CurveAction curve(final View view, final float x, final float y) {
final float base = abstand(view.getX(), view.getY(), x, y);
final float heightOfTriangle = getHeightOfTriangle(base, 165);
float x1 = -x;
Expand Down
8 changes: 4 additions & 4 deletions sample/src/main/java/com/eftimoff/empty/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void animateSampleOne(View toolbar, View activityMainMobileNumberLayout,
final PropertyAction fabAction = PropertyAction.newPropertyAction(activityMainPinkFab).scaleX(0).scaleY(0).duration(750).interpolator(new AccelerateDecelerateInterpolator()).build();
final PropertyAction headerAction = PropertyAction.newPropertyAction(activityMainheaderLayout).interpolator(new DecelerateInterpolator()).translationY(-200).duration(550).alpha(0.4f).build();
final PropertyAction bottomAction = PropertyAction.newPropertyAction(activityMainMobileNumberLayout).translationY(500).duration(750).alpha(0f).build();
Player.with(toolbar).
Player.init().
animate(headerAction).
then().
animate(fabAction).
Expand All @@ -65,7 +65,7 @@ private void animateSampleTwo(View toolbar, View activityMainMobileNumberLayout,
final PropertyAction headerAction = PropertyAction.newPropertyAction(activityMainheaderLayout).interpolator(new DecelerateInterpolator()).duration(550).alpha(0.0f).build();
final PropertyAction bottomAction = PropertyAction.newPropertyAction(activityMainMobileNumberLayout).duration(2500).alpha(0f).build();
final CurveAction curveAction = CurveAction.newControlPointsCurveAction(activityMainMobileNumberLayout).translationX(-500).translationY(100).controlPoint1X(-500).controlPoint1Y(255.5f).controlPoint2X(0).controlPoint2Y(255.5f).duration(2500).build();
Player.with(activityMainheaderLayout).
Player.init().
animate(headerAction).
then().
animate(fabAction).
Expand All @@ -80,7 +80,7 @@ private void animateSampleThree(View activityMainProfileName, View activityMainM
final PropertyAction headerPropertyAction = PropertyAction.newPropertyAction(activityMainProfileName).interpolator(new DecelerateInterpolator()).translationY(-200).duration(3750).delay(1233).alpha(0.4f).build();
final PropertyAction viewSecondAction = PropertyAction.newPropertyAction(activityMainPinkFab).translationY(200).duration(750).alpha(0f).build();
final PropertyAction bottomPropertyAction = PropertyAction.newPropertyAction(activityMainMobileNumberLayout).rotation(-180).scaleX(0.1f).scaleY(0.1f).translationX(-200).duration(750).build();
Player.with(activityMainMessageIcon).
Player.init().
setPlayerStartListener(playerStartListener).
setPlayerEndListener(playerEndListener).
animate(propertyAction).
Expand All @@ -99,7 +99,7 @@ private void animateSampleFour(View toolbar, View activityMainMessageIcon, View
final PropertyAction activityMainMobileNumberAction = PropertyAction.newPropertyAction(activityMainMobileNumber).scaleX(0).scaleY(0).duration(550).alpha(0f).build();
final PropertyAction activityMainMobileAction = PropertyAction.newPropertyAction(activityMainMobile).translationY(300).duration(750).alpha(0f).build();
final PropertyAction activityMainMessageIconAction = PropertyAction.newPropertyAction(activityMainMessageIcon).scaleX(0).scaleY(0).duration(350).alpha(0f).build();
Player.with(toolbar).
Player.init().
animate(headerAction).
then().
animate(fabAction).
Expand Down

0 comments on commit 838f1e5

Please sign in to comment.