/
SampleActivity.java
85 lines (72 loc) · 2.85 KB
/
SampleActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package net.grobas.movingimageview.sample;
import android.animation.Animator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import net.grobas.view.MovingImageView;
public class SampleActivity extends AppCompatActivity {
MovingImageView image;
boolean toggleState = true;
boolean toggleCustomMovement = true;
int[] imageList = {R.drawable.anotherworld, R.drawable.futurecity, R.drawable.spacecargo, R.drawable.city};
int pos = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
image = (MovingImageView) findViewById(R.id.image);
image.getMovingAnimator().addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
Log.i("Sample MovingImageView", "Start");
}
@Override
public void onAnimationEnd(Animator animation) {
Log.i("Sample MovingImageView", "End");
}
@Override
public void onAnimationCancel(Animator animation) {
Log.i("Sample MovingImageView", "Cancel");
}
@Override
public void onAnimationRepeat(Animator animation) {
Log.i("Sample MovingImageView", "Repeat");
}
});
}
public void clickImage(View v) {
if (toggleState) {
image.getMovingAnimator().pause();
Toast.makeText(this, "Pause", Toast.LENGTH_SHORT).show();
} else {
image.getMovingAnimator().resume();
Toast.makeText(this, "Resume", Toast.LENGTH_SHORT).show();
}
toggleState = !toggleState;
}
public void clickTitle(View v) {
pos = (pos + 1) >= imageList.length ? 0 : pos + 1;
image.setImageResource(imageList[pos]);
toggleCustomMovement = true;
Toast.makeText(this, "Next picture", Toast.LENGTH_SHORT).show();
}
public void clickText(View v) {
if(toggleCustomMovement) {
image.getMovingAnimator().addCustomMovement().addDiagonalMoveToDownRight().addHorizontalMoveToLeft().addDiagonalMoveToUpRight()
.addVerticalMoveToDown().addHorizontalMoveToLeft().addVerticalMoveToUp().start();
Toast.makeText(this, "Custom movement", Toast.LENGTH_SHORT).show();
} else {
image.getMovingAnimator().clearCustomMovement();
Toast.makeText(this, "Default movement", Toast.LENGTH_SHORT).show();
}
toggleCustomMovement = !toggleCustomMovement;
}
@Override
protected void onStop() {
super.onStop();
if(image != null)
image.getMovingAnimator().cancel();
}
}