/
MainActivity.java
96 lines (79 loc) · 3.17 KB
/
MainActivity.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
86
87
88
89
90
91
92
93
94
95
96
package it.sephiroth.android.library.demo_viewrevealanimator;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import it.sephiroth.android.library.viewrevealanimator.ViewRevealAnimator;
public class MainActivity extends ActionBarActivity
implements View.OnClickListener, ViewRevealAnimator.OnViewAnimationListener, ViewRevealAnimator.OnViewChangedListener {
private static final String TAG = "MainActivity";
ViewRevealAnimator mViewAnimator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mViewAnimator = (ViewRevealAnimator) findViewById(R.id.animator);
findViewById(R.id.next).setOnClickListener(this);
findViewById(R.id.next2).setOnClickListener(this);
findViewById(R.id.previous).setOnClickListener(this);
mViewAnimator.setOnTouchListener(
new View.OnTouchListener() {
@Override
public boolean onTouch(final View v, final MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
mViewAnimator.showNext(new Point((int)event.getX(), (int)event.getY()));
return true;
}
return false;
}
});
mViewAnimator.setOnViewAnimationListener(this);
mViewAnimator.setOnViewChangedListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(final View v) {
final int id = v.getId();
switch (id) {
case R.id.next:
mViewAnimator.showNext(null);
break;
case R.id.previous:
mViewAnimator.showPrevious(null);
break;
case R.id.next2:
int current = mViewAnimator.getDisplayedChild() + 2;
current = current % mViewAnimator.getChildCount();
mViewAnimator.setDisplayedChild(current, null);
break;
}
}
@Override
public void onViewAnimationStarted(final int previousIndex, final int currentIndex) {
Log.d(TAG, "onViewAnimationStarted(" + previousIndex + ":" + currentIndex + ")");
}
@Override
public void onViewAnimationCompleted(final int previousIndex, final int currentIndex) {
Log.d(TAG, "onViewAnimationCompleted(" + previousIndex + ":" + currentIndex + ")");
}
@Override
public void onViewChanged(final int previousIndex, final int currentIndex) {
Log.d(TAG, "onViewChanged(" + previousIndex + ":" + currentIndex + ")");
}
}