Skip to content

Commit 0b6db45

Browse files
JAVATECHIGJAVATECHIG
authored andcommitted
Added ViewFlipper example
1 parent 0a0e6f5 commit 0b6db45

File tree

18 files changed

+327
-0
lines changed

18 files changed

+327
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.javatechig.viewflipper"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<application
8+
android:icon="@drawable/ic_launcher"
9+
android:label="@string/app_name" >
10+
<activity
11+
android:name="com.javatechig.viewflipper.ViewFlipperSampleActivity"
12+
android:label="@string/app_name" >
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>

ViewFlipperExample/project.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system use,
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
10+
# Project target.
11+
target=android-14
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android" >
3+
4+
<translate
5+
android:duration="500"
6+
android:fromXDelta="100%p"
7+
android:toXDelta="0" />
8+
9+
<alpha
10+
android:duration="500"
11+
android:fromAlpha="0.1"
12+
android:toAlpha="1.0" />
13+
14+
</set>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android" >
3+
4+
<translate
5+
android:duration="500"
6+
android:fromXDelta="0"
7+
android:toXDelta="-100%p" />
8+
9+
<alpha
10+
android:duration="500"
11+
android:fromAlpha="1.0"
12+
android:toAlpha="0.1" />
13+
14+
</set>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android" >
3+
4+
<translate
5+
android:duration="500"
6+
android:fromXDelta="-100%p"
7+
android:toXDelta="0" />
8+
9+
<alpha
10+
android:duration="500"
11+
android:fromAlpha="0.1"
12+
android:toAlpha="1.0" />
13+
14+
</set>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<set xmlns:android="http://schemas.android.com/apk/res/android" >
3+
4+
<translate
5+
android:duration="500"
6+
android:fromXDelta="0"
7+
android:toXDelta="100%p" />
8+
9+
<alpha
10+
android:duration="500"
11+
android:fromAlpha="1.0"
12+
android:toAlpha="0.1" />
13+
14+
</set>
Loading
Loading
Loading
Loading
565 KB
Loading
1.05 MB
Loading
716 Bytes
Loading
677 Bytes
Loading
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:orientation="vertical" >
6+
7+
<ViewFlipper
8+
android:id="@+id/view_flipper"
9+
android:layout_width="fill_parent"
10+
android:layout_height="fill_parent" >
11+
12+
<RelativeLayout
13+
android:layout_width="fill_parent"
14+
android:layout_height="fill_parent" >
15+
16+
<ImageView
17+
android:layout_width="fill_parent"
18+
android:layout_height="fill_parent"
19+
android:layout_gravity="center"
20+
android:adjustViewBounds="true"
21+
android:scaleType="centerCrop"
22+
android:src="@drawable/lightning" />
23+
24+
<TextView
25+
style="@style/ImageTitle"
26+
android:text="@string/lightning" />
27+
</RelativeLayout>
28+
29+
<RelativeLayout
30+
android:layout_width="fill_parent"
31+
android:layout_height="fill_parent" >
32+
33+
<ImageView
34+
android:layout_width="fill_parent"
35+
android:layout_height="fill_parent"
36+
android:layout_gravity="center"
37+
android:adjustViewBounds="true"
38+
android:scaleType="centerCrop"
39+
android:src="@drawable/color_baloons" />
40+
41+
<TextView
42+
style="@style/ImageTitle"
43+
android:text="@string/color_baloons" />
44+
</RelativeLayout>
45+
46+
<RelativeLayout
47+
android:layout_width="fill_parent"
48+
android:layout_height="fill_parent" >
49+
50+
<ImageView
51+
android:layout_width="fill_parent"
52+
android:layout_height="fill_parent"
53+
android:layout_gravity="center"
54+
android:adjustViewBounds="true"
55+
android:scaleType="centerCrop"
56+
android:src="@drawable/natural_wall" />
57+
58+
<TextView
59+
style="@style/ImageTitle"
60+
android:text="@string/natural_wall" />
61+
</RelativeLayout>
62+
</ViewFlipper>
63+
64+
<LinearLayout
65+
style="@style/ButtonContainer"
66+
android:orientation="horizontal" >
67+
68+
<Button
69+
android:id="@+id/play"
70+
android:layout_width="wrap_content"
71+
android:layout_height="wrap_content"
72+
android:layout_marginRight="10dp"
73+
android:background="@android:drawable/ic_media_play" />
74+
75+
<Button
76+
android:id="@+id/stop"
77+
android:layout_width="wrap_content"
78+
android:layout_height="wrap_content"
79+
android:background="@android:drawable/ic_media_pause" />
80+
</LinearLayout>
81+
82+
<ImageView
83+
android:id="@+id/swipe_left"
84+
android:layout_width="wrap_content"
85+
android:layout_height="wrap_content"
86+
android:layout_alignParentLeft="true"
87+
android:layout_centerVertical="true"
88+
android:src="@drawable/swipe_left" />
89+
90+
<ImageView
91+
android:id="@+id/swipe_right"
92+
android:layout_width="wrap_content"
93+
android:layout_height="wrap_content"
94+
android:layout_alignParentRight="true"
95+
android:layout_centerVertical="true"
96+
android:src="@drawable/swipe_right" />
97+
98+
</RelativeLayout>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="app_name">ViewFlipper Example</string>
4+
<string name="lightning">Natural Lightning</string>
5+
<string name="color_baloons">Color Baloons</string>
6+
<string name="natural_wall">Natural Wall</string>
7+
</resources>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<style name="ImageTitle">
4+
<item name="android:layout_width">fill_parent</item>
5+
<item name="android:layout_height">50dp</item>
6+
<item name="android:layout_alignParentBottom">true</item>
7+
<item name="android:background">#99000000</item>
8+
<item name="android:gravity">center</item>
9+
<item name="android:maxLines">2</item>
10+
<item name="android:textColor">#fff</item>
11+
<item name="android:textStyle">bold</item>
12+
<item name="android:textSize">18dp</item>
13+
<item name="android:typeface">sans</item>
14+
</style>
15+
16+
<style name="ButtonContainer">
17+
<item name="android:layout_width">fill_parent</item>
18+
<item name="android:layout_height">50dp</item>
19+
<item name="android:layout_alignParentTop">true</item>
20+
<item name="android:background">#99000000</item>
21+
<item name="android:gravity">center</item>
22+
</style>
23+
24+
</resources>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.javatechig.viewflipper;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.os.Bundle;
6+
import android.view.GestureDetector;
7+
import android.view.GestureDetector.SimpleOnGestureListener;
8+
import android.view.MotionEvent;
9+
import android.view.View;
10+
import android.view.View.OnClickListener;
11+
import android.view.View.OnTouchListener;
12+
import android.view.animation.Animation;
13+
import android.view.animation.Animation.AnimationListener;
14+
import android.view.animation.AnimationUtils;
15+
import android.widget.Button;
16+
import android.widget.ViewFlipper;
17+
18+
public class ViewFlipperSampleActivity extends Activity {
19+
20+
private static final int SWIPE_MIN_DISTANCE = 120;
21+
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
22+
private ViewFlipper mViewFlipper;
23+
private AnimationListener mAnimationListener;
24+
private Context mContext;
25+
26+
27+
@SuppressWarnings("deprecation")
28+
private final GestureDetector detector = new GestureDetector(new SwipeGestureDetector());
29+
30+
@Override
31+
public void onCreate(Bundle savedInstanceState) {
32+
super.onCreate(savedInstanceState);
33+
setContentView(R.layout.main);
34+
mContext = this;
35+
mViewFlipper = (ViewFlipper) this.findViewById(R.id.view_flipper);
36+
mViewFlipper.setOnTouchListener(new OnTouchListener() {
37+
@Override
38+
public boolean onTouch(final View view, final MotionEvent event) {
39+
detector.onTouchEvent(event);
40+
return true;
41+
}
42+
});
43+
44+
45+
findViewById(R.id.play).setOnClickListener(new OnClickListener() {
46+
@Override
47+
public void onClick(View view) {
48+
//sets auto flipping
49+
mViewFlipper.setAutoStart(true);
50+
mViewFlipper.setFlipInterval(4000);
51+
mViewFlipper.startFlipping();
52+
}
53+
});
54+
55+
findViewById(R.id.stop).setOnClickListener(new OnClickListener() {
56+
@Override
57+
public void onClick(View view) {
58+
//stop auto flipping
59+
mViewFlipper.stopFlipping();
60+
}
61+
});
62+
63+
64+
//animation listener
65+
mAnimationListener = new Animation.AnimationListener() {
66+
public void onAnimationStart(Animation animation) {
67+
//animation started event
68+
}
69+
70+
public void onAnimationRepeat(Animation animation) {
71+
}
72+
73+
public void onAnimationEnd(Animation animation) {
74+
//TODO animation stopped event
75+
}
76+
};
77+
}
78+
79+
80+
class SwipeGestureDetector extends SimpleOnGestureListener {
81+
@Override
82+
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
83+
try {
84+
// right to left swipe
85+
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
86+
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.left_in));
87+
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext, R.anim.left_out));
88+
// controlling animation
89+
mViewFlipper.getInAnimation().setAnimationListener(mAnimationListener);
90+
mViewFlipper.showNext();
91+
return true;
92+
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
93+
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.right_in));
94+
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext,R.anim.right_out));
95+
// controlling animation
96+
mViewFlipper.getInAnimation().setAnimationListener(mAnimationListener);
97+
mViewFlipper.showPrevious();
98+
return true;
99+
}
100+
101+
} catch (Exception e) {
102+
e.printStackTrace();
103+
}
104+
105+
return false;
106+
}
107+
}
108+
}
109+
110+

0 commit comments

Comments
 (0)