├── ic_launcher-web.png
├── res
├── drawable-hdpi
│ ├── bg.png
│ ├── p1.jpg
│ ├── p2.jpg
│ ├── p3.jpg
│ ├── p4.jpg
│ ├── charming.jpg
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── values-sw600dp
│ └── dimens.xml
├── values
│ ├── dimens.xml
│ ├── strings.xml
│ ├── styles.xml
│ └── attrs.xml
├── values-sw720dp-land
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
├── layout
│ ├── activity_next.xml
│ └── activity_main.xml
└── menu
│ └── main.xml
├── libs
└── android-support-v4.jar
├── README.md
├── gen
└── com
│ └── dk
│ └── animation
│ ├── BuildConfig.java
│ └── R.java
├── .settings
└── org.eclipse.jdt.core.prefs
├── .gitignore
├── src
└── com
│ └── dk
│ └── animation
│ ├── folding
│ ├── Util.java
│ ├── OnFoldListener.java
│ ├── FoldingLayout.java
│ └── BaseFoldingLayout.java
│ ├── BaseEffect.java
│ ├── demo
│ ├── NextActivity.java
│ └── MainActivity.java
│ ├── ActivityAnimationTool.java
│ ├── WaterEffect.java
│ ├── FoldingEffect.java
│ ├── water
│ ├── DrawWaterWave.java
│ └── DrawWaterWaveWithSina.java
│ ├── SkewEffect.java
│ ├── CloseEffect.java
│ ├── TwisterEffect.java
│ ├── SplitEffect.java
│ └── BlurEffect.java
├── .classpath
├── project.properties
├── proguard-project.txt
├── .project
└── AndroidManifest.xml
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/ic_launcher-web.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-hdpi/bg.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/p1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-hdpi/p1.jpg
--------------------------------------------------------------------------------
/res/drawable-hdpi/p2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-hdpi/p2.jpg
--------------------------------------------------------------------------------
/res/drawable-hdpi/p3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-hdpi/p3.jpg
--------------------------------------------------------------------------------
/res/drawable-hdpi/p4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-hdpi/p4.jpg
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/res/drawable-hdpi/charming.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-hdpi/charming.jpg
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dkmeteor/ActivityAnimationLib/HEAD/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Demo
2 | 
3 |
4 | 
--------------------------------------------------------------------------------
/gen/com/dk/animation/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.dk.animation;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
Must be an integer value, such as "100".
13 |
This may also be a reference to a resource (in the form
14 | "@[package:]type:name") or
15 | theme attribute (in the form
16 | "?[package:][type:]name")
17 | containing a value of this type.
18 | */
19 | public static final int foldNumber=0x7f010000;
20 | }
21 | public static final class dimen {
22 | /** Default screen margins, per the Android Design guidelines.
23 |
24 | Customize dimensions originally defined in res/values/dimens.xml (such as
25 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
26 |
27 | */
28 | public static final int activity_horizontal_margin=0x7f040000;
29 | public static final int activity_vertical_margin=0x7f040001;
30 | }
31 | public static final class drawable {
32 | public static final int bg=0x7f020000;
33 | public static final int charming=0x7f020001;
34 | public static final int ic_launcher=0x7f020002;
35 | public static final int p1=0x7f020003;
36 | public static final int p2=0x7f020004;
37 | public static final int p3=0x7f020005;
38 | public static final int p4=0x7f020006;
39 | }
40 | public static final class id {
41 | public static final int action_blur=0x7f080001;
42 | public static final int action_close=0x7f080002;
43 | public static final int action_folding=0x7f080004;
44 | public static final int action_skew=0x7f080005;
45 | public static final int action_split=0x7f080003;
46 | public static final int action_water=0x7f080006;
47 | public static final int iv=0x7f080000;
48 | }
49 | public static final class layout {
50 | public static final int activity_main=0x7f030000;
51 | public static final int activity_next=0x7f030001;
52 | }
53 | public static final class menu {
54 | public static final int main=0x7f070000;
55 | }
56 | public static final class string {
57 | public static final int action_settings=0x7f050001;
58 | public static final int app_name=0x7f050000;
59 | public static final int effect_blur=0x7f050003;
60 | public static final int effect_close=0x7f050005;
61 | public static final int effect_folding=0x7f050007;
62 | public static final int effect_skew=0x7f050008;
63 | public static final int effect_split=0x7f050004;
64 | public static final int effect_twister=0x7f050006;
65 | public static final int effect_water=0x7f050009;
66 | public static final int hello_world=0x7f050002;
67 | }
68 | public static final class style {
69 | /**
70 | Base application theme, dependent on API level. This theme is replaced
71 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
72 |
73 |
74 | Theme customizations available in newer API levels can go in
75 | res/values-vXX/styles.xml, while customizations related to
76 | backward-compatibility can go here.
77 |
78 |
79 | Base application theme for API 11+. This theme completely replaces
80 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
81 |
82 | API 11 theme customizations can go here.
83 |
84 | Base application theme for API 14+. This theme completely replaces
85 | AppBaseTheme from BOTH res/values/styles.xml and
86 | res/values-v11/styles.xml on API 14+ devices.
87 |
88 | API 14 theme customizations can go here.
89 | */
90 | public static final int AppBaseTheme=0x7f060000;
91 | /** Application theme.
92 | */
93 | public static final int AppTheme=0x7f060001;
94 | }
95 | public static final class styleable {
96 | /** Attributes that can be used with a FoldingMenu.
97 |
Includes the following attributes:
98 || Attribute | Description |
|---|---|
{@link #FoldingMenu_foldNumber com.dk.animation:foldNumber} |
This symbol is the offset where the {@link com.dk.animation.R.attr#foldNumber} 111 | attribute's value can be found in the {@link #FoldingMenu} array. 112 | 113 | 114 |
Must be an integer value, such as "100".
115 |
This may also be a reference to a resource (in the form
116 | "@[package:]type:name") or
117 | theme attribute (in the form
118 | "?[package:][type:]name")
119 | containing a value of this type.
120 | @attr name com.dk.animation:foldNumber
121 | */
122 | public static final int FoldingMenu_foldNumber = 0;
123 | };
124 | }
125 |
--------------------------------------------------------------------------------
/src/com/dk/animation/CloseEffect.java:
--------------------------------------------------------------------------------
1 | package com.dk.animation;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Paint;
9 | import android.graphics.PixelFormat;
10 | import android.os.Handler;
11 | import android.os.Message;
12 | import android.view.Gravity;
13 | import android.view.View;
14 | import android.view.WindowManager;
15 | import android.widget.ImageView;
16 |
17 | public class CloseEffect extends BaseEffect {
18 | public Bitmap mBitmap = null;
19 | private ImageView mTopImage;
20 | private int top;
21 | private float t = 0;
22 |
23 | public void prepareAnimation(final Activity destActivity) {
24 | mTopImage = createImageView(destActivity, mBitmap);
25 | }
26 |
27 | public void prepare(Activity currActivity) {
28 | // Get the content of the activity and put in a bitmap
29 | View root = currActivity.getWindow().getDecorView().findViewById(android.R.id.content);
30 | root.setDrawingCacheEnabled(true);
31 | mBitmap = root.getDrawingCache();
32 | top = root.getTop();
33 |
34 | }
35 |
36 | public void cancel() {
37 |
38 | }
39 |
40 | public void clean(Activity activity) {
41 |
42 | if (mTopImage != null) {
43 | mTopImage.setLayerType(View.LAYER_TYPE_NONE, null);
44 | try {
45 | activity.getWindowManager().removeViewImmediate(mTopImage);
46 | } catch (Exception ignored) {
47 | }
48 | }
49 |
50 | mBitmap = null;
51 | }
52 |
53 | private ImageView createImageView(Activity destActivity, Bitmap bmp) {
54 | MyImageView imageView = new MyImageView(destActivity);
55 | imageView.setImageBitmap(bmp);
56 |
57 | WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
58 | windowParams.gravity = Gravity.TOP;
59 | windowParams.x = 0;
60 | windowParams.y = top;
61 | windowParams.height = bmp.getHeight();
62 | windowParams.width = bmp.getWidth();
63 | windowParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
64 | windowParams.format = PixelFormat.TRANSLUCENT;
65 | windowParams.windowAnimations = 0;
66 | destActivity.getWindowManager().addView(imageView, windowParams);
67 |
68 | return imageView;
69 | }
70 |
71 |
72 | public void animate(final Activity destActivity, final int duration) {
73 |
74 | //make sure it is run in main thread
75 | new Handler().post(new Runnable() {
76 |
77 | @Override
78 | public void run() {
79 | //callback UI thread
80 | final Handler callBack = new Handler() {
81 |
82 | @Override
83 | public void handleMessage(Message msg) {
84 | switch (msg.what) {
85 | case 101:
86 | mTopImage.invalidate();
87 | break;
88 | case 102:
89 | clean(destActivity);
90 | break;
91 | }
92 | }
93 | };
94 |
95 | Thread animationThread = new Thread(new Runnable() {
96 |
97 | @Override
98 | public void run() {
99 | while (t < 1) {
100 | t += 0.08;
101 | callBack.sendEmptyMessage(101);
102 |
103 | try {
104 | Thread.sleep(20);
105 | } catch (InterruptedException e) {
106 | e.printStackTrace();
107 | }
108 | }
109 |
110 | callBack.sendEmptyMessage(102);
111 | }
112 | });
113 |
114 | animationThread.start();
115 |
116 | }
117 | });
118 | }
119 |
120 | private class MyImageView extends ImageView {
121 | private Matrix mMatrix;
122 | private Paint mPaint = new Paint();
123 |
124 | public MyImageView(Context context) {
125 | super(context);
126 | }
127 |
128 | @Override
129 | protected void onDraw(Canvas canvas) {
130 | if (mMatrix != null)
131 | mMatrix.reset();
132 | mMatrix = CloseEffect.this.getMatrix(canvas.getMatrix(), t, getWidth(), getHeight());
133 | canvas.drawBitmap(mBitmap, mMatrix, mPaint);
134 |
135 | }
136 |
137 | }
138 |
139 | /**
140 | * t should be 0~1;
141 | *
142 | * @param t
143 | * @param w
144 | * @param h
145 | * @return
146 | */
147 | private Matrix getMatrix(Matrix matrix, float t, int w, int h) {
148 | float[] src = new float[8];
149 | float[] dst = new float[8];
150 |
151 | src[0] = 0;
152 | src[1] = 0;
153 | src[2] = w;
154 | src[3] = 0;
155 | src[4] = 0;
156 | src[5] = h;
157 | src[6] = w;
158 | src[7] = h;
159 |
160 | dst[0] = 0;
161 | dst[1] = 0.5f * h * t;
162 | dst[2] = w;
163 | dst[3] = 0.5f * h * t;
164 | dst[4] = 0;
165 | dst[5] = h - 0.5f * h * t;
166 | dst[6] = w;
167 | dst[7] = h - 0.5f * h * t;
168 |
169 | matrix.setPolyToPoly(src, 0, dst, 0, 4);
170 | return matrix;
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/src/com/dk/animation/TwisterEffect.java:
--------------------------------------------------------------------------------
1 | package com.dk.animation;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Camera;
7 | import android.graphics.Canvas;
8 | import android.graphics.Matrix;
9 | import android.graphics.Paint;
10 | import android.graphics.PixelFormat;
11 | import android.os.Handler;
12 | import android.os.Message;
13 | import android.view.Gravity;
14 | import android.view.View;
15 | import android.view.WindowManager;
16 | import android.widget.ImageView;
17 |
18 | public class TwisterEffect extends BaseEffect{
19 | public Bitmap mBitmap = null;
20 | private ImageView mTopImage;
21 | private int top;
22 | private float t = 0;
23 |
24 | public void prepareAnimation(final Activity destActivity) {
25 | mTopImage = createImageView(destActivity, mBitmap);
26 | }
27 |
28 | public void prepare(Activity currActivity) {
29 | // Get the content of the activity and put in a bitmap
30 | View root = currActivity.getWindow().getDecorView().findViewById(android.R.id.content);
31 | root.setDrawingCacheEnabled(true);
32 | mBitmap = root.getDrawingCache();
33 | top = root.getTop();
34 |
35 | }
36 |
37 | public void cancel() {
38 | }
39 |
40 | public void clean(Activity activity) {
41 |
42 | if (mTopImage != null) {
43 | mTopImage.setLayerType(View.LAYER_TYPE_NONE, null);
44 | try {
45 | activity.getWindowManager().removeViewImmediate(mTopImage);
46 | } catch (Exception ignored) {
47 | }
48 | }
49 |
50 | mBitmap = null;
51 | }
52 |
53 | private ImageView createImageView(Activity destActivity, Bitmap bmp) {
54 | MyImageView imageView = new MyImageView(destActivity);
55 | imageView.setImageBitmap(bmp);
56 |
57 | WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
58 | windowParams.gravity = Gravity.TOP;
59 | windowParams.x = 0;
60 | windowParams.y = top;
61 | windowParams.height = bmp.getHeight();
62 | windowParams.width = bmp.getWidth();
63 | windowParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
64 | windowParams.format = PixelFormat.TRANSLUCENT;
65 | windowParams.windowAnimations = 0;
66 | destActivity.getWindowManager().addView(imageView, windowParams);
67 |
68 | return imageView;
69 | }
70 |
71 | public void animate(final Activity destActivity, final int duration) {
72 |
73 | new Handler().post(new Runnable() {
74 |
75 | @Override
76 | public void run() {
77 |
78 | final Handler callBack = new Handler() {
79 |
80 | @Override
81 | public void handleMessage(Message msg) {
82 | switch (msg.what) {
83 | case 101:
84 | mTopImage.invalidate();
85 | break;
86 | case 102:
87 | clean(destActivity);
88 | break;
89 | }
90 | }
91 | };
92 |
93 | Thread animationThread = new Thread(new Runnable() {
94 |
95 | @Override
96 | public void run() {
97 | while (t < 1) {
98 | t += 0.08;
99 | callBack.sendEmptyMessage(101);
100 |
101 | try {
102 | Thread.sleep(20);
103 | } catch (InterruptedException e) {
104 | e.printStackTrace();
105 | }
106 | }
107 |
108 | callBack.sendEmptyMessage(102);
109 | }
110 | });
111 |
112 | animationThread.start();
113 |
114 | }
115 | });
116 | }
117 |
118 | private class MyImageView extends ImageView {
119 | private Matrix mMatrix;
120 | private Camera mCamera = new Camera();
121 |
122 | public MyImageView(Context context) {
123 | super(context);
124 | }
125 |
126 | @Override
127 | protected void onDraw(Canvas canvas) {
128 | if (mMatrix != null)
129 | mMatrix.reset();
130 | mMatrix = TwisterEffect.this.getMatrix(canvas.getMatrix(), t, getWidth(), getHeight());
131 |
132 | canvas.drawBitmap(mBitmap, mMatrix, new Paint());
133 | }
134 | }
135 |
136 | /**
137 | * t should be 0~1;
138 | *
139 | * @param t
140 | * @param w
141 | * @param h
142 | * @return
143 | */
144 | private Matrix getMatrix(Matrix matrix, float t, int w, int h) {
145 | float[] src = new float[8];
146 | float[] dst = new float[8];
147 |
148 | src[0] = 0;
149 | src[1] = 0;
150 | src[2] = w;
151 | src[3] = 0;
152 | src[4] = 0;
153 | src[5] = h;
154 | src[6] = w;
155 | src[7] = h;
156 |
157 | dst[0] = 0;
158 | dst[1] = 0.5f * h * t;
159 | dst[2] = w;
160 | dst[3] = 0.5f * h * t;
161 | dst[4] = 0;
162 | dst[5] = h - 0.5f * h * t;
163 | dst[6] = w;
164 | dst[7] = h - 0.5f * h * t;
165 |
166 | matrix.setPolyToPoly(src, 0, dst, 0, 4);
167 |
168 | for (int i = 0; i < 8; i++) {
169 | System.out.print(" " + dst[i]);
170 | }
171 | System.out.println();
172 | return matrix;
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/src/com/dk/animation/water/DrawWaterWaveWithSina.java:
--------------------------------------------------------------------------------
1 | package com.dk.animation.water;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Bitmap;
5 | import android.graphics.Paint;
6 | import android.widget.ImageView;
7 |
8 | public class DrawWaterWaveWithSina extends ImageView implements Runnable {
9 | boolean isRunning = false;
10 |
11 | private final static double TWO_PI = Math.PI * 2;
12 | private int width;
13 |
14 | private int height;
15 |
16 | private int[] mBitmap2;
17 |
18 | private int[] mBitmap1;
19 |
20 | private float wavelength = 36;
21 | private float amplitude = 10;
22 | private float phase = 0;
23 | private int radius = 5;
24 |
25 | private int radius2 = 0;
26 | private int icentreX;
27 | private int icentreY;
28 |
29 | private int alpha = 255;
30 | private Paint mPaint;
31 | private boolean flag = true;
32 | private Activity mActivity;
33 |
34 | private int SCALE = 3;
35 |
36 | public DrawWaterWaveWithSina(Activity context, Bitmap bmp) {
37 | super(context);
38 | mPaint = new Paint();
39 | Bitmap image = bmp;
40 | width = image.getWidth() / SCALE;
41 | height = image.getHeight() / SCALE;
42 | mActivity = context;
43 | mBitmap2 = new int[width * height];
44 | mBitmap1 = new int[width * height];
45 |
46 | Bitmap scaledBitmap = Bitmap.createScaledBitmap(image, width, height, false);
47 |
48 | scaledBitmap.getPixels(mBitmap1, 0, width, 0, 0, width, height);
49 | for (int i = 0; i < width * height; i++) {
50 | mBitmap2[i] = mBitmap1[i];
51 | }
52 | setImageBitmap(Bitmap.createBitmap(mBitmap2, 0, width, width, height, Bitmap.Config.ARGB_8888));
53 |
54 | }
55 |
56 | // protected void onDraw(Canvas canvas) {
57 | // canvas.drawBitmap(mBitmap2, 0, width, 0, 0, width, height, true, mPaint);
58 | // super.onDraw(canvas);
59 | // }
60 |
61 | // @Override
62 | // public boolean onTouchEvent(MotionEvent event) {
63 | //
64 | // if (event.getAction() == MotionEvent.ACTION_DOWN && !isRunning) {
65 | // start((int)event.getX(), (int)event.getY());
66 | // }
67 | //
68 | // return super.onTouchEvent(event);
69 | // }
70 |
71 | private boolean transformInverse(int x, int y, int[] out) {
72 | int dx = x - icentreX;
73 | int dy = y - icentreY;
74 | int distance2 = dx * dx + dy * dy;
75 |
76 | if (distance2 > radius2) {
77 | out[0] = x;
78 | out[1] = y;
79 | out[2] = 0;
80 | return false;
81 | } else {
82 | float distance = (float)Math.sqrt(distance2);
83 | float amount = amplitude * (float)Math.sin(distance / wavelength * TWO_PI - phase / TWO_PI);
84 | // float amount = amplitude * (float)Math.sin(distance / WT - PW);
85 | amount *= (radius - distance) / radius;
86 | // if (distance != 0)
87 | // amount *= wavelength / distance;
88 | out[0] = (int)(x + dx * amount);
89 | out[1] = (int)(y + dy * amount);
90 | out[2] = (int)distance;
91 | return true;
92 | }
93 | }
94 |
95 | private void createNextBitmap() {
96 | int[] temp = new int[3];
97 | for (int i = 0; i < width; i++)
98 | for (int j = 0; j < height; j++) {
99 | if (transformInverse(i, j, temp)) {
100 | if (temp[0] >= width || temp[1] >= height || temp[0] < 0 || temp[1] < 0) {
101 | mBitmap2[j * width + i] = 0x00000000;
102 | } else {
103 | // mBitmap2[j * width + i] = (mBitmap1[temp[1] * width + temp[0]] & 0x00ffffff)
104 | // + (int)((1 - temp[2] / (float)radius) * alpha) << 24;
105 | mBitmap2[j * width + i] = (mBitmap1[temp[1] * width + temp[0]] & 0x00ffffff)
106 | + (alpha << 24);
107 | }
108 | } else {
109 | if (temp[0] >= width || temp[1] >= height || temp[0] < 0 || temp[1] < 0) {
110 | mBitmap2[j * width + i] = 0x00000000;
111 | } else {
112 | mBitmap2[j * width + i] = mBitmap1[temp[1] * width + temp[0]];
113 | }
114 | }
115 |
116 | }
117 | }
118 |
119 | @Override
120 | public void run() {
121 | isRunning = true;
122 | while (flag) {
123 | try {
124 | Thread.sleep(30);
125 | } catch (Exception e) {
126 | }
127 | // filter.radius2++;
128 | phase += 5;
129 | radius += 5;
130 | amplitude /= 1.12;
131 | if (amplitude < 0.01) {
132 | stop();
133 | return;
134 | }
135 | if (alpha > 0) {
136 | alpha -= 5;
137 | } else {
138 | alpha = 0;
139 | }
140 | radius2 = radius * radius;
141 |
142 | long start = System.currentTimeMillis();
143 | createNextBitmap();
144 | post(new Runnable() {
145 |
146 | @Override
147 | public void run() {
148 | setImageBitmap(Bitmap.createBitmap(mBitmap2, 0, width, width, height, Bitmap.Config.ARGB_8888));
149 |
150 | }
151 | });
152 |
153 | System.out.println("duration:" + (System.currentTimeMillis() - start));
154 | postInvalidate();
155 |
156 | }
157 | }
158 |
159 | private void stop() {
160 | flag = false;
161 | if (this.getParent() != null) {
162 | this.post(new Runnable() {
163 |
164 | @Override
165 | public void run() {
166 | mActivity.getWindowManager().removeView(DrawWaterWaveWithSina.this);
167 | }
168 | });
169 | }
170 |
171 | }
172 |
173 | public void start(int x, int y) {
174 | icentreX = x / SCALE;
175 | icentreY = y / SCALE;
176 |
177 | Thread t = new Thread(this);
178 | t.start();
179 | }
180 |
181 | }
182 |
--------------------------------------------------------------------------------
/src/com/dk/animation/SplitEffect.java:
--------------------------------------------------------------------------------
1 | package com.dk.animation;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.app.Activity;
7 | import android.content.Context;
8 | import android.graphics.Bitmap;
9 | import android.graphics.Canvas;
10 | import android.graphics.Paint;
11 | import android.graphics.PixelFormat;
12 | import android.graphics.Rect;
13 | import android.graphics.drawable.BitmapDrawable;
14 | import android.graphics.drawable.Drawable;
15 | import android.os.Handler;
16 | import android.view.Gravity;
17 | import android.view.View;
18 | import android.view.WindowManager;
19 | import android.view.animation.DecelerateInterpolator;
20 | import android.view.animation.Interpolator;
21 | import android.widget.ImageView;
22 |
23 | public class SplitEffect extends BaseEffect {
24 |
25 | public Bitmap mBitmap = null;
26 | private int[] mLoc1;
27 | private int[] mLoc2;
28 | private ImageView mTopImage;
29 | private ImageView mBottomImage;
30 | private AnimatorSet mSetAnim;
31 |
32 | public void prepareAnimation(final Activity destActivity) {
33 | mTopImage = createImageView(destActivity, mBitmap, mLoc1);
34 | mBottomImage = createImageView(destActivity, mBitmap, mLoc2);
35 | }
36 |
37 | public void prepare(Activity currActivity) {
38 | int splitYCoord = -1;
39 | // Get the content of the activity and put in a bitmap
40 | View root = currActivity.getWindow().getDecorView().findViewById(android.R.id.content);
41 | root.setDrawingCacheEnabled(true);
42 | mBitmap = root.getDrawingCache();
43 |
44 | // If the split Y coordinate is -1 - We'll split the activity equally
45 | splitYCoord = (splitYCoord != -1 ? splitYCoord : mBitmap.getHeight() / 2);
46 |
47 | if (splitYCoord > mBitmap.getHeight())
48 | throw new IllegalArgumentException("Split Y coordinate [" + splitYCoord + "] exceeds the activity's height ["
49 | + mBitmap.getHeight() + "]");
50 |
51 | // Set the location to put the 2 bitmaps on the destination activity
52 | mLoc1 = new int[] { 0, splitYCoord, root.getTop() };
53 | mLoc2 = new int[] { splitYCoord, mBitmap.getHeight(), root.getTop() };
54 | }
55 |
56 | public void cancel() {
57 | if (mSetAnim != null)
58 | mSetAnim.cancel();
59 | }
60 |
61 | public void clean(Activity activity) {
62 | if (mTopImage != null) {
63 | mTopImage.setLayerType(View.LAYER_TYPE_NONE, null);
64 | try {
65 | // If we use the regular removeView() we'll get a small UI glitch
66 | activity.getWindowManager().removeViewImmediate(mBottomImage);
67 | } catch (Exception ignored) {
68 | }
69 | }
70 | if (mBottomImage != null) {
71 | mBottomImage.setLayerType(View.LAYER_TYPE_NONE, null);
72 | try {
73 | activity.getWindowManager().removeViewImmediate(mTopImage);
74 | } catch (Exception ignored) {
75 | }
76 | }
77 |
78 | mBitmap = null;
79 | }
80 |
81 | private ImageView createImageView(Activity destActivity, Bitmap bmp, int loc[]) {
82 | MyImageView imageView = new MyImageView(destActivity);
83 | imageView.setImageBitmap(bmp);
84 | imageView.setImageOffsets(bmp.getWidth(), loc[0], loc[1]);
85 |
86 | WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
87 | windowParams.gravity = Gravity.TOP;
88 | windowParams.x = 0;
89 | windowParams.y = loc[2] + loc[0];
90 | windowParams.height = loc[1] - loc[0];
91 | windowParams.width = bmp.getWidth();
92 | windowParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
93 | windowParams.format = PixelFormat.TRANSLUCENT;
94 | windowParams.windowAnimations = 0;
95 | destActivity.getWindowManager().addView(imageView, windowParams);
96 |
97 | return imageView;
98 | }
99 |
100 | private class MyImageView extends ImageView {
101 | private Rect mSrcRect;
102 | private Rect mDstRect;
103 | private Paint mPaint;
104 |
105 | public MyImageView(Context context) {
106 | super(context);
107 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
108 | }
109 |
110 | public void setImageOffsets(int width, int startY, int endY) {
111 | mSrcRect = new Rect(0, startY, width, endY);
112 | mDstRect = new Rect(0, 0, width, endY - startY);
113 | }
114 |
115 | @Override
116 | protected void onDraw(Canvas canvas) {
117 | Bitmap bm = null;
118 | Drawable drawable = getDrawable();
119 | if (null != drawable && drawable instanceof BitmapDrawable) {
120 | bm = ((BitmapDrawable)drawable).getBitmap();
121 | }
122 |
123 | if (null == bm) {
124 | super.onDraw(canvas);
125 | } else {
126 | canvas.drawBitmap(bm, mSrcRect, mDstRect, mPaint);
127 | }
128 | }
129 | }
130 |
131 | public void animate(final Activity destActivity, final int duration) {
132 | final Interpolator interpolator = new DecelerateInterpolator();
133 | destActivity.getWindow().setFlags(
134 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
135 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
136 |
137 |
138 | new Handler().post(new Runnable() {
139 |
140 | @Override
141 | public void run() {
142 | mSetAnim = new AnimatorSet();
143 | mTopImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
144 | mBottomImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
145 | mSetAnim.addListener(new Animator.AnimatorListener() {
146 | @Override
147 | public void onAnimationStart(Animator animation) {
148 | }
149 |
150 | @Override
151 | public void onAnimationEnd(Animator animation) {
152 | clean(destActivity);
153 | }
154 |
155 | @Override
156 | public void onAnimationCancel(Animator animation) {
157 | clean(destActivity);
158 | }
159 |
160 | @Override
161 | public void onAnimationRepeat(Animator animation) {
162 |
163 | }
164 | });
165 |
166 | Animator anim1 = ObjectAnimator.ofFloat(mTopImage, "translationY", mTopImage.getHeight() * -1);
167 | Animator anim2 = ObjectAnimator.ofFloat(mBottomImage, "translationY", mBottomImage.getHeight());
168 |
169 | if (interpolator != null) {
170 | anim1.setInterpolator(interpolator);
171 | anim2.setInterpolator(interpolator);
172 | }
173 |
174 | mSetAnim.setDuration(duration);
175 | mSetAnim.playTogether(anim1, anim2);
176 | mSetAnim.start();
177 |
178 | }
179 | });
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/src/com/dk/animation/folding/FoldingLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Priboi Tiberiu
3 | * Copyright (C) 2013 The Android Open Source Project
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.dk.animation.folding;
19 |
20 |
21 | import android.content.Context;
22 | import android.util.AttributeSet;
23 | import android.view.GestureDetector;
24 | import android.view.MotionEvent;
25 | import android.view.View;
26 | import android.view.ViewConfiguration;
27 |
28 | /**
29 | * The folding layout where the number of folds, the anchor point and the
30 | * orientation of the fold can be specified. Each of these parameters can be
31 | * modified individually and updates and resets the fold to a default (unfolded)
32 | * state. The fold factor varies between 0 (completely unfolded flat image) to
33 | * 1.0 (completely folded, non-visible image).
34 | *
35 | * This layout throws an exception if there is more than one child added to the
36 | * view. For more complicated view hierarchy's inside the folding layout, the
37 | * views should all be nested inside 1 parent layout.
38 | *
39 | * This layout folds the contents of its child in real time. By applying matrix
40 | * transformations when drawing to canvas, the contents of the child may change
41 | * as the fold takes place. It is important to note that there are jagged edges
42 | * about the perimeter of the layout as a result of applying transformations to
43 | * a rectangle. This can be avoided by having the child of this layout wrap its
44 | * content inside a 1 pixel transparent border. This will cause an anti-aliasing
45 | * like effect and smoothen out the edges.
46 | *
47 | */
48 | public class FoldingLayout extends BaseFoldingLayout {
49 |
50 | private final String FOLDING_VIEW_EXCEPTION_MESSAGE = "Folding Layout can only 1 child at "
51 | + "most";
52 |
53 | private GestureDetector mScrollGestureDetector;
54 |
55 | FoldingLayout that = null;
56 |
57 | private int mTranslation = 0;
58 | private int mParentPositionY = -1;
59 | private int mTouchSlop = -1;
60 | private boolean mDidNotStartScroll = true;
61 |
62 | public FoldingLayout(Context context) {
63 | super(context);
64 | init(context, null);
65 | that = this;
66 | }
67 |
68 | public FoldingLayout(Context context, AttributeSet attrs) {
69 | super(context, attrs);
70 | init(context, attrs);
71 | that = this;
72 | }
73 |
74 | public FoldingLayout(Context context, AttributeSet attrs, int defStyle) {
75 | super(context, attrs, defStyle);
76 | init(context, attrs);
77 | that = this;
78 | }
79 |
80 | public void init(Context context, AttributeSet attrs) {
81 | mScrollGestureDetector = new GestureDetector(context,
82 | new ScrollGestureDetector());
83 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
84 | setAnchorFactor(0);
85 | super.init(context, attrs);
86 | }
87 |
88 | @Override
89 | protected boolean addViewInLayout(View child, int index,
90 | LayoutParams params, boolean preventRequestLayout) {
91 | throwCustomException(getChildCount());
92 | boolean returnValue = super.addViewInLayout(child, index, params,
93 | preventRequestLayout);
94 | return returnValue;
95 | }
96 |
97 | /**
98 | * The custom exception to be thrown so as to limit the number of views in
99 | * this layout to at most one.
100 | */
101 | private class NumberOfFoldingLayoutChildrenException extends
102 | RuntimeException {
103 | /**
104 | *
105 | */
106 | private static final long serialVersionUID = 1L;
107 |
108 | public NumberOfFoldingLayoutChildrenException(String message) {
109 | super(message);
110 | }
111 | }
112 |
113 | /**
114 | * Throws an exception if the number of views added to this layout exceeds
115 | * one.
116 | */
117 | private void throwCustomException(int numOfChildViews) {
118 | if (numOfChildViews == 1) {
119 | throw new NumberOfFoldingLayoutChildrenException(
120 | FOLDING_VIEW_EXCEPTION_MESSAGE);
121 | }
122 | }
123 |
124 | /** This class uses user touch events to fold and unfold the folding view. */
125 | private class ScrollGestureDetector extends
126 | GestureDetector.SimpleOnGestureListener {
127 | @Override
128 | public boolean onDown(MotionEvent e) {
129 | mDidNotStartScroll = true;
130 | return true;
131 | }
132 |
133 | /**
134 | * All the logic here is used to determine by what factor the paper view
135 | * should be folded in response to the user's touch events. The logic
136 | * here uses vertical scrolling to fold a vertically oriented view and
137 | * horizontal scrolling to fold a horizontally oriented fold. Depending
138 | * on where the anchor point of the fold is, movements towards or away
139 | * from the anchor point will either fold or unfold the paper
140 | * respectively.
141 | *
142 | * The translation logic here also accounts for the touch slop when a
143 | * new user touch begins, but before a scroll event is first invoked.
144 | */
145 | @Override
146 | public boolean onScroll(MotionEvent e1, MotionEvent e2,
147 | float distanceX, float distanceY) {
148 | int touchSlop = 0;
149 | float factor;
150 | if (mOrientation == Orientation.VERTICAL) {
151 | factor = Math.abs((float) (mTranslation)
152 | / (float) (that.getHeight()));
153 |
154 | if (e2.getY() - mParentPositionY <= that.getHeight()
155 | && e2.getY() - mParentPositionY >= 0) {
156 | if ((e2.getY() - mParentPositionY) > that.getHeight()
157 | * getAnchorFactor()) {
158 | mTranslation -= (int) distanceY;
159 | touchSlop = distanceY < 0 ? -mTouchSlop : mTouchSlop;
160 | } else {
161 | mTranslation += (int) distanceY;
162 | touchSlop = distanceY < 0 ? mTouchSlop : -mTouchSlop;
163 | }
164 | mTranslation = mDidNotStartScroll ? mTranslation
165 | + touchSlop : mTranslation;
166 |
167 | if (mTranslation < -that.getHeight()) {
168 | mTranslation = -that.getHeight();
169 | }
170 | }
171 | } else {
172 | factor = Math.abs(((float) mTranslation)
173 | / ((float) that.getWidth()));
174 |
175 | if (e2.getRawX() > that.getWidth() * getAnchorFactor()) {
176 | mTranslation -= (int) distanceX;
177 | touchSlop = distanceX < 0 ? -mTouchSlop : mTouchSlop;
178 | } else {
179 | mTranslation += (int) distanceX;
180 | touchSlop = distanceX < 0 ? mTouchSlop : -mTouchSlop;
181 | }
182 | mTranslation = mDidNotStartScroll ? mTranslation + touchSlop
183 | : mTranslation;
184 |
185 | if (mTranslation < -that.getWidth()) {
186 | mTranslation = -that.getWidth();
187 | }
188 | }
189 |
190 | mDidNotStartScroll = false;
191 |
192 | if (mTranslation > 0) {
193 | mTranslation = 0;
194 | }
195 |
196 | that.setFoldFactor(factor);
197 |
198 | return true;
199 | }
200 | }
201 |
202 | @Override
203 | public boolean onTouchEvent(MotionEvent me) {
204 | return mScrollGestureDetector.onTouchEvent(me);
205 | }
206 |
207 | }
--------------------------------------------------------------------------------
/src/com/dk/animation/BlurEffect.java:
--------------------------------------------------------------------------------
1 | package com.dk.animation;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Camera;
8 | import android.graphics.Canvas;
9 | import android.graphics.Matrix;
10 | import android.graphics.Paint;
11 | import android.graphics.PixelFormat;
12 | import android.os.Build.VERSION;
13 | import android.os.Handler;
14 | import android.os.Message;
15 | import android.renderscript.Allocation;
16 | import android.renderscript.Element;
17 | import android.renderscript.RenderScript;
18 | import android.renderscript.ScriptIntrinsicBlur;
19 | import android.view.Gravity;
20 | import android.view.View;
21 | import android.view.WindowManager;
22 | import android.widget.ImageView;
23 | import android.widget.ImageView.ScaleType;
24 |
25 | public class BlurEffect extends BaseEffect {
26 |
27 | private Bitmap mBitmap = null;
28 | private Bitmap mScaledBitmap = null;
29 | private ImageView mTopImage;
30 | private int top;
31 |
32 | public void prepareAnimation(final Activity destActivity) {
33 | mTopImage = createImageView(destActivity, mBitmap);
34 | }
35 |
36 | public void prepare(Activity currActivity) {
37 | View root = currActivity.getWindow().getDecorView().findViewById(android.R.id.content);
38 | top = root.getTop();
39 | root.setDrawingCacheEnabled(true);
40 | mBitmap = root.getDrawingCache();
41 | scaleBitmap(mBitmap);
42 | }
43 |
44 | private void scaleBitmap(Bitmap bmp) {
45 | mScaledBitmap = Bitmap.createScaledBitmap(bmp, bmp.getWidth() / 8, bmp.getWidth() / 8, true);
46 |
47 | }
48 |
49 | public void cancel() {
50 | }
51 |
52 | public void clean(Activity activity) {
53 | if (mTopImage != null) {
54 | mTopImage.setLayerType(View.LAYER_TYPE_NONE, null);
55 | try {
56 | // If we use the regular removeView() we'll get a small UI glitch
57 | activity.getWindowManager().removeViewImmediate(mTopImage);
58 | } catch (Exception ignored) {
59 | }
60 | }
61 | mBitmap = null;
62 | }
63 |
64 | private ImageView createImageView(Activity destActivity, Bitmap bmp) {
65 | ImageView imageView = new ImageView(destActivity);
66 | imageView.setImageBitmap(bmp);
67 | imageView.setScaleType(ScaleType.FIT_XY);
68 | WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
69 | windowParams.gravity = Gravity.TOP;
70 | windowParams.x = 0;
71 | windowParams.y = top;
72 | windowParams.height = bmp.getHeight();
73 | windowParams.width = bmp.getWidth();
74 | windowParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
75 | windowParams.format = PixelFormat.TRANSLUCENT;
76 | windowParams.windowAnimations = 0;
77 | destActivity.getWindowManager().addView(imageView, windowParams);
78 |
79 | return imageView;
80 | }
81 |
82 | public void animate(final Activity destActivity, final int duration) {
83 |
84 | new Handler().post(new Runnable() {
85 | private int alpha = 255;
86 |
87 | @Override
88 | public void run() {
89 |
90 | final Handler callBack = new Handler() {
91 |
92 | @Override
93 | public void handleMessage(Message msg) {
94 | switch (msg.what) {
95 | case 101:
96 | mTopImage.setAlpha(alpha);
97 | mTopImage.setImageBitmap(mScaledBitmap);
98 | System.out.println("refresh:" + alpha);
99 | break;
100 | case 102:
101 | clean(destActivity);
102 | break;
103 | }
104 | }
105 | };
106 |
107 | Thread animationThread = new Thread(new Runnable() {
108 |
109 | @Override
110 | public void run() {
111 | while (alpha > 0) {
112 | if (alpha > 180) {
113 | alpha -= 8;
114 | } else {
115 | alpha -= 25;
116 | }
117 | if (alpha > 0) {
118 | mScaledBitmap = apply(destActivity, mScaledBitmap, 3);
119 |
120 | }
121 |
122 | callBack.sendEmptyMessage(101);
123 |
124 | try {
125 | Thread.sleep(50);
126 | } catch (InterruptedException e) {
127 | e.printStackTrace();
128 | }
129 | }
130 |
131 | callBack.sendEmptyMessage(102);
132 | }
133 | });
134 |
135 | animationThread.start();
136 |
137 | }
138 | });
139 | }
140 |
141 | // blur effect
142 | private static int DEFAULT_BLUR_RADIUS = 7;
143 |
144 | public static Bitmap apply(Context context, Bitmap sentBitmap) {
145 | return apply(context, sentBitmap, DEFAULT_BLUR_RADIUS);
146 | }
147 |
148 | @SuppressLint("NewApi")
149 | public static Bitmap apply(Context context, Bitmap sentBitmap, int radius) {
150 | if (VERSION.SDK_INT > 16) {
151 | Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
152 |
153 | final RenderScript rs = RenderScript.create(context);
154 | final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
155 | Allocation.USAGE_SCRIPT);
156 | final Allocation output = Allocation.createTyped(rs, input.getType());
157 | final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
158 | script.setRadius(radius);
159 | script.setInput(input);
160 | script.forEach(output);
161 | output.copyTo(bitmap);
162 | return bitmap;
163 | }
164 |
165 | // Stack Blur v1.0 from
166 | // http://www.quasimondo.com/StackBlurForCanvas/StackBlurDemo.html
167 | //
168 | // Java Author: Mario Klingemann