├── .gitignore
├── README.md
├── README_CN.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wingjay
│ │ └── wjmagiccurvedemo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── wingjay
│ │ │ └── wjmagiccurvedemo
│ │ │ ├── CJJArtLineActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── WJMagicCurveActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_cjj_art_line.xml
│ │ ├── activity_main.xml
│ │ └── activity_wj_magic_curve.xml
│ │ ├── menu
│ │ ├── cjj_menu.xml
│ │ └── wingjay_menu.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── wingjay
│ └── wjmagiccurvedemo
│ └── ExampleUnitTest.java
├── build.gradle
├── demo.apk
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── lib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wingjay
│ │ └── wjmagiccurveview
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── wingjay
│ │ │ └── wjmagiccurveview
│ │ │ ├── CJJArtLineView.java
│ │ │ └── WJMagicCurveView.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── wingjay
│ └── wjmagiccurveview
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Custom
2 | _site
3 |
4 | # Ant
5 | MANIFEST.MF
6 | ./*.jar
7 | build.num
8 | build
9 |
10 | # ADT
11 | .classpath
12 | .project
13 | .settings
14 | local.properties
15 | bin
16 | gen
17 | _layouts
18 | proguard.cfg
19 |
20 | # OSX
21 | .DS_Store
22 |
23 | # Github
24 | gh-pages
25 |
26 | # Gradle
27 | .gradle
28 | build
29 |
30 | # IDEA
31 | *.iml
32 | *.ipr
33 | *.iws
34 | out
35 | .idea
36 |
37 | # Maven
38 | target
39 | release.properties
40 | pom.xml.*
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WJMagicCurveView
2 | By setting several parameters simply, You'll get a fancy Magic Curve immediately.
3 |
4 | [中文介绍,来自Android-CJJ同学](https://github.com/wingjay/WJMagicCurveView/blob/master/README_CN.md)
5 |
6 | # Let's see what it is
7 |
8 |
9 |
10 |
11 |
12 | Order |
13 | Demo |
14 |
15 |
16 |
17 |
18 | 1 |
19 |  |
20 |
21 |
22 | 2 |
23 |  |
24 |
25 |
26 | 3 |
27 |  |
28 |
29 |
30 | 4 |
31 |  |
32 |
33 |
34 | 5 |
35 |  |
36 |
37 |
38 |
39 |
40 | # How it works
41 | By setting `eight parameters` (Of course you don't have to set every because they all have default value), `WJMagicCurveView` will draw a beautiful curve based on a math function.
42 |
43 | First, we'll create two points and make them `rotate` in specified `speed` and specified `radius` revolving a same center;
44 | Second, whenever they reach a point during rotating, we'll draw a `line connecting these two points`;
45 | Thirds, continue rotate and draw lines, Bingo! You're creating a new beautiful curve!
46 |
47 | # How to create your own curve
48 | We provide eight base parameters for normal users and more for developers from code level. Here are explaintion for these parameters:
49 |
50 | 1. `radiusAX`、`radiusAY`: A point is the outer rotating point, these two are the radius of A;
51 | 2. `radiusBX`、`radiusBY`: B point is the inner rotating point;
52 | 3. `speedOuterPoint`、`speedInnerPoint`: the rotating speed for A & B;
53 | 4. `loopTotalCount`: the loop count for these two rotating points;
54 | 5. `durationSeconds`: the durationg speed for rotating.
55 |
56 | # Playable apk
57 | [Download it from here](https://github.com/wingjay/WJMagicCurveView/raw/master/demo.apk) and make a try!
58 |
59 | # How to use it
60 | ```java
61 | WJMagicCurveView wjMagicCurveView = (WJMagicCurveView) findViewById(R.id.wj_magic_curve_view);
62 | // set parameters. of course it's not necessary to set all these parameters because they all have default value
63 | wjMagicCurveView.setRadius(radiusAX, radiusAY, radiusBX, radiusBY)
64 | .setDurationSec(durationSeconds)
65 | .setLoopTotalCount(loopTotalCount)
66 | .setSpeed(speedOuterPoint, speedInnerPoint)
67 | .startDraw();
68 | ```
69 | ```java
70 | // stop Draw
71 | wjMagicCurveView.stopDraw();
72 | ```
73 | ```java
74 | // destory and recycle bitmap
75 | wjMagicCurveView.destory();
76 | ```
77 | ```java
78 | // Customize your own curve here
79 | I create a enum called WJMagicCurveViewParameters,
80 | You can create your own WJMagicCurveViewParameters with eight parameters,
81 | for empty fields, use -1 as default value.
82 | ```
83 |
84 | # Related resource
85 | [有趣的曲线在Android上的实现](http://wingjay.com/2016/01/25/%E6%9C%89%E8%B6%A3%E7%9A%84%E6%9B%B2%E7%BA%BF%E5%9C%A8Android%E4%B8%8A%E7%9A%84%E5%AE%9E%E7%8E%B0/)
86 |
87 | [Processing: 简单法则的魅力](http://mp.weixin.qq.com/s?__biz=MzA4NTc5MDU5OQ==&mid=411441608&idx=1&sn=5e846a882f58a7ba1b5312bdbeaafccf&scene=23&srcid=0120GiYhMXjmNDoN9MFQj7f5#rd)
88 |
89 | ###Reach me - wingjay
90 | 
91 |
92 | You can get information about me and reach me in my github page: https://github.com/wingjay
93 |
94 | Blog: http://wingjay.com
95 |
96 | Weibo: http://weibo.com/u/1625892654
97 |
98 | Feel free to give me advices by
99 |
100 | Thanks!
101 |
--------------------------------------------------------------------------------
/README_CN.md:
--------------------------------------------------------------------------------
1 | # 中文版介绍来自[android-cjj](https://github.com/android-cjj)同学
2 |
3 | 最近看了群里一个小伙伴[wingjay](https://github.com/wingjay)的博文[《有趣的曲线在Android上的实现》](https://wingjay.com/2016/01/25/%E6%9C%89%E8%B6%A3%E7%9A%84%E6%9B%B2%E7%BA%BF%E5%9C%A8Android%E4%B8%8A%E7%9A%84%E5%AE%9E%E7%8E%B0/),文中又看到了一篇[《简单法则的魅力》](http://mp.weixin.qq.com/s?__biz=MzA4NTc5MDU5OQ==&mid=411441608&idx=1&sn=5e846a882f58a7ba1b5312bdbeaafccf&scene=23&srcid=0120GiYhMXjmNDoN9MFQj7f5#rd),然后得到了这样一段代码:
4 | ```
5 | float aX,aY,bX,bY,angleA,angleB,speedA,speedB,aXR,aYR,bXR,bYR;
6 | color c;
7 | void setup(){
8 | size(700,700);
9 | background(0);
10 | speedA = 0.025;
11 | speedB = 0.006;
12 | aXR = 320;
13 | aYR = 320;
14 | bXR = 320;
15 | bYR = 80;
16 | }
17 |
18 | void draw(){
19 | translate(width/2,height/2);
20 | angleA += speedA;
21 | angleB += speedB;
22 | aX = cos(angleA) * aXR;
23 | aY = sin(angleA) * aYR;
24 | bX = cos(angleB) * bXR;
25 | bY = sin(angleB) * bYR;
26 | c = color(255,50);
27 | stroke(c);
28 | line(aX, aY, bX, bY);
29 | }
30 | void mousePressed(){
31 | saveFrame(frameCount + " speedA-" + speedA + " speedB-" + speedB + " aXR-"+aXR + " aYR-"+aYR + " bXR-"+bXR + " bYR-"+bYR +".png");
32 | }
33 | ```
34 | 一开始我也不信,因为我看了下代码,绘制只有这句` line(aX, aY, bX, bY);`,然后自己敲了一下,按自己的想法去自定义ArtLine了。
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 | 上面的所有图形都是由同一段代码实现的,只有寥寥几行代码。其中的核心变量有 6 个。换句话说,只需修改 6 个参数就能衍生以上图形。
69 | 参数分别是:
70 | * 点 A 的运动速率
71 | * 点 A 在 x 轴的运动范围
72 | * 点 A 在 y 轴的运动范围
73 | * 点 B 的运动速率
74 | * 点 B 在 x 轴的运动范围
75 | * 点 B 在 y 轴的运动范围
76 |
77 | 我就开启了个动画,不断的绘画view自身,核心代码如下:
78 |
79 | ```java
80 | protected void onDraw(Canvas canvas) {
81 | super.onDraw(canvas);
82 | angleA += speedA;
83 | angleB += speedB;
84 | aX = (float) (Math.cos(angleA) * aXR);
85 | aY = (float) (Math.sin(angleA) * aYR);
86 | bX = (float) (Math.cos(angleB) * bXR);
87 | bY = (float) (Math.sin(angleB) * bYR);
88 |
89 | listPos.add(aX);
90 | listPos.add(aY);
91 | listPos.add(bX);
92 | listPos.add(bY);
93 |
94 | canvas.translate(centerX, centerY);
95 | canvas.drawColor(Color.BLACK);
96 | canvas.save();
97 | for (int i = 0; i < listPos.size(); i++) {
98 | if (i % 4 == 0) {
99 | canvas.drawLine(listPos.get(i), listPos.get(i + 1), listPos.get(i + 2), listPos.get(i + 3), paint);
100 | }
101 | }
102 | canvas.restore();
103 | }
104 | ```
105 |
106 | 好像挺简单的,就测试的时候麻烦点!源码已上传github ,你可以在这里找到[wingjay](https://github.com/wingjay)!
107 |
108 | 这里打打个广告!最近发起了个 android sdk 源码解析——旨在帮助初学者更好的学习Android !高手请不要略过,仓库上还有很多Class没被认领分析,有兴趣的可以一起愉快搞基哦!虽然很多人说我瞎折腾,但是,还是有些人喜欢的!
109 | 另外,关于群里一言不合就开车事件
110 |
111 | 
112 |
113 | 我们已经深深反省,决定深夜开车!
114 |
115 |
116 | #### 关于android-cjj
117 | 如果你喜欢这个东东的话,可以关注[cjj github](https://github.com/android-cjj) ,也可以关注微博[Android_cJJ](http://weibo.com/chenjijun2011/).
118 |
119 |
120 | #### 项目作者 - wingjay
121 | 
122 |
123 | 如果你对我的开源项目感兴趣,可以关注我: https://github.com/wingjay
124 |
125 | 博客: https://wingjay.com
126 |
127 | 微博: http://weibo.com/u/1625892654
128 |
129 | 随时可以通过这个邮箱找到我
130 |
131 | 谢谢!
132 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.wingjay.wjmagiccurvedemo"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.3.0'
26 | compile project(path: ':lib')
27 | }
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Jay/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/wingjay/wjmagiccurvedemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.wingjay.wjmagiccurvedemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wingjay/wjmagiccurvedemo/CJJArtLineActivity.java:
--------------------------------------------------------------------------------
1 | package com.wingjay.wjmagiccurvedemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 |
8 | import com.wingjay.wjmagiccurveview.CJJArtLineView;
9 |
10 | /**
11 | * Created by wingjay on 4/22/16.
12 | * You can choose in top-right menu for different existing curve.
13 | */
14 | public class CJJArtLineActivity extends AppCompatActivity {
15 | private CJJArtLineView mArtLine;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_cjj_art_line);
21 | mArtLine = (CJJArtLineView) findViewById(R.id.art);
22 | line1();
23 | // line2();
24 | // line3();
25 | // line4();
26 | // line5();
27 | // line6();
28 | }
29 |
30 | @Override
31 | public boolean onCreateOptionsMenu(Menu menu) {
32 | getMenuInflater().inflate(R.menu.cjj_menu, menu);
33 | return true;
34 | }
35 |
36 | @Override
37 | public boolean onOptionsItemSelected(MenuItem item) {
38 | if (mArtLine != null) {
39 | mArtLine.destory();
40 | }
41 | switch (item.getItemId()) {
42 | case R.id.art_line_1:
43 | line1();
44 | break;
45 | case R.id.art_line_2:
46 | line2();
47 | break;
48 | case R.id.art_line_3:
49 | line3();
50 | break;
51 | case R.id.art_line_4:
52 | line4();
53 | break;
54 | case R.id.art_line_5:
55 | line5();
56 | break;
57 | case R.id.art_line_6:
58 | default:
59 | line6();
60 | }
61 |
62 | return super.onOptionsItemSelected(item);
63 | }
64 |
65 | public void line1(){
66 | mArtLine.setColor("#90ff00ff");
67 | mArtLine.setTime(40*1000);
68 | mArtLine.setSpeedA((float) 0.76);
69 | mArtLine.setAngleB((float)0.03);
70 | mArtLine.setaXR(200);
71 | mArtLine.setaYR(200);
72 | mArtLine.setbXR(300);
73 | mArtLine.setbYR(300);
74 | }
75 |
76 | public void line2(){
77 | mArtLine.setColor("#904CAF50");
78 | mArtLine.setTime(20*1000);
79 | mArtLine.setSpeedA((float)0.12);
80 | mArtLine.setAngleB((float)0.25);
81 | mArtLine.setaXR(300);
82 | mArtLine.setaYR(120);
83 | mArtLine.setbXR(120);
84 | mArtLine.setbYR(220);
85 | }
86 |
87 | public void line3(){
88 | mArtLine.setColor("#90fff700");
89 | mArtLine.setTime(10*1000);
90 | mArtLine.setSpeedA((float) 0.26);
91 | mArtLine.setAngleB((float)0.005);
92 | mArtLine.setaXR(320);
93 | mArtLine.setaYR(20);
94 | mArtLine.setbXR(20);
95 | mArtLine.setbYR(320);
96 | }
97 |
98 | public void line4(){
99 | mArtLine.setColor("#902196F3");
100 | mArtLine.setTime(40*1000);
101 | mArtLine.setSpeedA((float) 0.16);
102 | mArtLine.setAngleB((float)0.005);
103 | mArtLine.setaXR(300);
104 | mArtLine.setaYR(300);
105 | mArtLine.setbXR(300);
106 | mArtLine.setbYR(60);
107 | }
108 |
109 | public void line5(){
110 | mArtLine.setColor("#90ff00ff");
111 | mArtLine.setTime(30*1000);
112 | mArtLine.setSpeedA((float) 0.06);
113 | mArtLine.setAngleB((float)0.003);
114 | mArtLine.setaXR(120);
115 | mArtLine.setaYR(20);
116 | mArtLine.setbXR(30);
117 | mArtLine.setbYR(320);
118 | }
119 |
120 |
121 | public void line6(){
122 | mArtLine.setColor("#90ff00ff");
123 | mArtLine.setTime(30*1000);
124 | mArtLine.setSpeedA((float) 0.06);
125 | mArtLine.setAngleB((float)0.003);
126 | mArtLine.setaXR(320);
127 | mArtLine.setaYR(200);
128 | mArtLine.setbXR(200);
129 | mArtLine.setbYR(320);
130 | }
131 |
132 | }
133 |
134 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wingjay/wjmagiccurvedemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wingjay.wjmagiccurvedemo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | public class MainActivity extends AppCompatActivity {
11 |
12 | @Override
13 | protected void onCreate(@Nullable Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 |
17 | Button wjMagicCurveView = (Button) findViewById(R.id.wj_magic_curve_view);
18 | Button cjjArtLineView = (Button) findViewById(R.id.cjj_art_line_view);
19 |
20 | if (wjMagicCurveView != null) {
21 | wjMagicCurveView.setOnClickListener(new View.OnClickListener() {
22 | @Override
23 | public void onClick(View v) {
24 | startActivity(new Intent(MainActivity.this, WJMagicCurveActivity.class));
25 | }
26 | });
27 | }
28 |
29 | if (cjjArtLineView != null) {
30 | cjjArtLineView.setOnClickListener(new View.OnClickListener() {
31 | @Override
32 | public void onClick(View v) {
33 | startActivity(new Intent(MainActivity.this, CJJArtLineActivity.class));
34 | }
35 | });
36 | }
37 |
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/wingjay/wjmagiccurvedemo/WJMagicCurveActivity.java:
--------------------------------------------------------------------------------
1 | package com.wingjay.wjmagiccurvedemo;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.annotation.NonNull;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.text.Html;
9 | import android.text.TextUtils;
10 | import android.view.Menu;
11 | import android.view.MenuInflater;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 | import android.widget.Button;
15 | import android.widget.EditText;
16 | import android.widget.TextView;
17 |
18 | import com.wingjay.wjmagiccurveview.WJMagicCurveView;
19 |
20 | /**
21 | * Created by wingjay on 4/22/16.
22 | * You can choose in top-right menu for different existing curve.
23 | */
24 | public class WJMagicCurveActivity extends AppCompatActivity {
25 | private EditText radiusAX;
26 | private EditText radiusAY;
27 | private EditText radiusBX;
28 | private EditText radiusBY;
29 | private EditText loopTotalCount;
30 | private EditText durationSeconds;
31 | private EditText speedOuterPoint;
32 | private EditText speedInnerPoint;
33 | private Button startTransformBtn;
34 |
35 | private WJMagicCurveView wjMagicCurveView;
36 | private TextView aboutAuthor;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_wj_magic_curve);
42 |
43 | radiusAX = (EditText) findViewById(R.id.radius_ax);
44 | radiusAY = (EditText) findViewById(R.id.radius_ay);
45 | radiusBX = (EditText) findViewById(R.id.radius_bx);
46 | radiusBY = (EditText) findViewById(R.id.radius_by);
47 | loopTotalCount = (EditText) findViewById(R.id.loopTotalCount);
48 | durationSeconds = (EditText) findViewById(R.id.durationSeconds);
49 | speedOuterPoint = (EditText) findViewById(R.id.speedOuterPoint);
50 | speedInnerPoint = (EditText) findViewById(R.id.speedInnerPoint);
51 | startTransformBtn = (Button) findViewById(R.id.start_transform_btn);
52 | wjMagicCurveView = (WJMagicCurveView) findViewById(R.id.wj_magic_curve_view);
53 | aboutAuthor = (TextView) findViewById(R.id.about_author);
54 |
55 | startTransformBtn.setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View v) {
58 | if (wjMagicCurveView.isDrawing()) {
59 | wjMagicCurveView.stopDraw();
60 | startTransformBtn.setText("Start Transform (开始)");
61 | } else {
62 | startTransform();
63 | startTransformBtn.setText("Stop Transform (停止)");
64 | }
65 | }
66 | });
67 |
68 | setupIntroduction();
69 | }
70 |
71 | private void startTransform() {
72 | wjMagicCurveView.setRadius(getIntValueFromEdittext(radiusAX), getIntValueFromEdittext(radiusAY),
73 | getIntValueFromEdittext(radiusBX), getIntValueFromEdittext(radiusBY))
74 | .setDurationSec(getIntValueFromEdittext(durationSeconds))
75 | .setLoopTotalCount(getIntValueFromEdittext(loopTotalCount))
76 | .setSpeed(getIntValueFromEdittext(speedOuterPoint), getIntValueFromEdittext(speedInnerPoint))
77 | .startDraw();
78 | }
79 |
80 | @Override
81 | public boolean onCreateOptionsMenu(Menu menu) {
82 | MenuInflater menuInflater = new MenuInflater(WJMagicCurveActivity.this);
83 | menuInflater.inflate(R.menu.wingjay_menu, menu);
84 | return true;
85 | }
86 |
87 | @Override
88 | public boolean onOptionsItemSelected(MenuItem item) {
89 | wjMagicCurveView.stopDraw();
90 | startTransformBtn.setText("Start Transform (开始)");
91 | WJMagicCurveView.WJMagicCurveViewParameters parameters;
92 | switch (item.getItemId()) {
93 | case R.id.diamond:
94 | parameters = WJMagicCurveView.WJMagicCurveViewParameters.DIAMOND;
95 | break;
96 | case R.id.ring:
97 | parameters = WJMagicCurveView.WJMagicCurveViewParameters.RING;
98 | break;
99 | case R.id.pyramid:
100 | parameters = WJMagicCurveView.WJMagicCurveViewParameters.PYRAMID;
101 | break;
102 | case R.id.shell:
103 | parameters = WJMagicCurveView.WJMagicCurveViewParameters.SHELL;
104 | break;
105 | case R.id.flower:
106 | parameters = WJMagicCurveView.WJMagicCurveViewParameters.FLOWER;
107 | break;
108 | case R.id.leaf:
109 | parameters = WJMagicCurveView.WJMagicCurveViewParameters.LEAF;
110 | break;
111 | case R.id.airship:
112 | parameters = WJMagicCurveView.WJMagicCurveViewParameters.AIRSHIP;
113 | break;
114 | case R.id.default_key:
115 | default:
116 | parameters = WJMagicCurveView.WJMagicCurveViewParameters.DEFAULT;
117 | }
118 | wjMagicCurveView.setParameters(parameters);
119 | displayWjMagicCurveParameters(parameters);
120 |
121 | return super.onOptionsItemSelected(item);
122 | }
123 |
124 | private void displayWjMagicCurveParameters(WJMagicCurveView.WJMagicCurveViewParameters parameters) {
125 | radiusAX.setText(parameters.radiusAX > 0 ? String.valueOf((int) parameters.radiusAX) : null);
126 | radiusAY.setText(parameters.radiusAY > 0 ? String.valueOf((int) parameters.radiusAY) : null);
127 | radiusBX.setText(parameters.radiusBX > 0 ? String.valueOf((int) parameters.radiusBX) : null);
128 | radiusBY.setText(parameters.radiusBY > 0 ? String.valueOf((int) parameters.radiusBY) : null);
129 | speedOuterPoint.setText(parameters.speedOuterPoint > 0 ? String.valueOf(parameters.speedOuterPoint) : null);
130 | speedInnerPoint.setText(parameters.speedInnerPoint > 0 ? String.valueOf(parameters.speedInnerPoint) : null);
131 | loopTotalCount.setText(parameters.loopTotalCount > 0 ? String.valueOf(parameters.loopTotalCount) : null);
132 | durationSeconds.setText(parameters.durationSec > 0 ? String.valueOf(parameters.durationSec) : null);
133 | }
134 |
135 | private int getIntValueFromEdittext(@NonNull EditText editText) {
136 | String content = editText.getText().toString();
137 | if (!TextUtils.isEmpty(content)) {
138 | return Integer.parseInt(content);
139 | }
140 | return -1;
141 | }
142 |
143 | @Override
144 | protected void onStop() {
145 | super.onStop();
146 | wjMagicCurveView.stopDraw();
147 | }
148 |
149 | @Override
150 | protected void onDestroy() {
151 | super.onDestroy();
152 | wjMagicCurveView.destory();
153 | }
154 |
155 | private void setupIntroduction() {
156 | String aboutAuthorString = "Find me here: wingjay (https://github.com/wingjay)";
157 | aboutAuthor.setText(Html.fromHtml(aboutAuthorString));
158 | aboutAuthor.setOnClickListener(new View.OnClickListener() {
159 | @Override
160 | public void onClick(View v) {
161 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/wingjay"));
162 | startActivity(browserIntent);
163 | }
164 | });
165 | }
166 |
167 | }
168 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_cjj_art_line.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_wj_magic_curve.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
24 |
25 |
31 |
32 |
36 |
37 |
45 |
46 |
54 |
55 |
56 |
57 |
61 |
62 |
70 |
71 |
79 |
80 |
81 |
82 |
86 |
87 |
95 |
96 |
104 |
105 |
106 |
107 |
111 |
112 |
120 |
121 |
129 |
130 |
131 |
132 |
139 |
140 |
144 |
145 |
146 |
147 |
148 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/cjj_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/wingjay_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wingjay/WJMagicCurveView/b0b7022d64604f7f549842083eb0dda2f2bf7574/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wingjay/WJMagicCurveView/b0b7022d64604f7f549842083eb0dda2f2bf7574/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wingjay/WJMagicCurveView/b0b7022d64604f7f549842083eb0dda2f2bf7574/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wingjay/WJMagicCurveView/b0b7022d64604f7f549842083eb0dda2f2bf7574/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wingjay/WJMagicCurveView/b0b7022d64604f7f549842083eb0dda2f2bf7574/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WJMagicCurveDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/wingjay/wjmagiccurvedemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wingjay.wjmagiccurvedemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.0.0'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/demo.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wingjay/WJMagicCurveView/b0b7022d64604f7f549842083eb0dda2f2bf7574/demo.apk
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wingjay/WJMagicCurveView/b0b7022d64604f7f549842083eb0dda2f2bf7574/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | // Remember update version when library updates
6 | version = "1.0.0"
7 |
8 | android {
9 | resourcePrefix "wingjay_"
10 |
11 | compileSdkVersion 23
12 | buildToolsVersion "23.0.3"
13 |
14 | defaultConfig {
15 | minSdkVersion 15
16 | targetSdkVersion 23
17 | versionCode 1
18 | versionName "1.0"
19 | }
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | compile fileTree(dir: 'libs', include: ['*.jar'])
30 | testCompile 'junit:junit:4.12'
31 | compile 'com.android.support:appcompat-v7:23.3.0'
32 | }
33 | def siteUrl = 'https://github.com/wingjay/WJMagicCurveView' // 项目的主页
34 | def gitUrl = 'https://github.com/wingjay/WJMagicCurveView.git' // Git仓库的url
35 | group = "com.wingjay" // Maven Group ID for the artifact,一般填你唯一的包名
36 | install {
37 | repositories.mavenInstaller {
38 | // This generates POM.xml with proper parameters
39 | pom {
40 | project {
41 | packaging 'aar'
42 | // Add your description here
43 | name 'By simply setting several parameters, You\'ll get a fancy magic curve immediately.' //项目描述
44 | url siteUrl
45 | // Set your license
46 | licenses {
47 | license {
48 | name 'The Apache Software License, Version 2.0'
49 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
50 | }
51 | }
52 | developers {
53 | developer {
54 | id 'wingjay' //填写开发者基本信息
55 | name 'wingjay'
56 | email 'yinjiesh@126.com'
57 | }
58 | }
59 | scm {
60 | connection gitUrl
61 | developerConnection gitUrl
62 | url siteUrl
63 | }
64 | }
65 | }
66 | }
67 | }
68 | task sourcesJar(type: Jar) {
69 | from android.sourceSets.main.java.srcDirs
70 | classifier = 'sources'
71 | }
72 | task javadoc(type: Javadoc) {
73 | source = android.sourceSets.main.java.srcDirs
74 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
75 | }
76 | task javadocJar(type: Jar, dependsOn: javadoc) {
77 | classifier = 'javadoc'
78 | from javadoc.destinationDir
79 | }
80 | artifacts {
81 | archives javadocJar
82 | archives sourcesJar
83 | }
84 | Properties properties = new Properties()
85 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
86 | bintray {
87 | user = properties.getProperty("bintray.user")
88 | key = properties.getProperty("bintray.apikey")
89 | configurations = ['archives']
90 | pkg {
91 | repo = "maven" //发布到Bintray的那个仓库里,默认账户有四个库,我们这里上传到maven库
92 | name = "WJMagicCurveView" //发布到Bintray上的项目名字
93 | websiteUrl = siteUrl
94 | vcsUrl = gitUrl
95 | licenses = ["Apache-2.0"]
96 | publish = true
97 | }
98 | }
--------------------------------------------------------------------------------
/lib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Jay/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/lib/src/androidTest/java/com/wingjay/wjmagiccurveview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.wingjay.wjmagiccurveview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/wingjay/wjmagiccurveview/CJJArtLineView.java:
--------------------------------------------------------------------------------
1 | package com.wingjay.wjmagiccurveview;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 | import android.view.animation.LinearInterpolator;
11 |
12 | import java.util.ArrayList;
13 |
14 | /**
15 | * Created by android-cjj on 4/22/16.
16 | * GitHub: https://github.com/android-cjj
17 | * Mail: 929178101@qq.com
18 | * Weibo: http://weibo.com/chenjijun2011
19 | */
20 | public class CJJArtLineView extends View {
21 |
22 | private Paint paint;
23 | private ArrayList listPos = new ArrayList<>();
24 | private int centerX, centerY;
25 | private float aX, aY, bX, bY, angleA, angleB, speedA, speedB, aXR, aYR, bXR, bYR;
26 | private long time;
27 | private String color;
28 |
29 | public CJJArtLineView(Context context) {
30 | super(context);
31 | init();
32 | }
33 |
34 | public CJJArtLineView(Context context, AttributeSet attrs) {
35 | super(context, attrs);
36 | init();
37 | }
38 |
39 | public String getColor() {
40 | return color;
41 | }
42 |
43 | public void setColor(String color) {
44 | this.color = color;
45 | paint.setColor(Color.parseColor(color));
46 | }
47 |
48 |
49 | public float getaX() {
50 | return aX;
51 | }
52 |
53 | public void setaX(float aX) {
54 | this.aX = aX;
55 | }
56 |
57 | public float getaY() {
58 | return aY;
59 | }
60 |
61 | public void setaY(float aY) {
62 | this.aY = aY;
63 | }
64 |
65 | public float getbX() {
66 | return bX;
67 | }
68 |
69 | public void setbX(float bX) {
70 | this.bX = bX;
71 | }
72 |
73 | public float getbY() {
74 | return bY;
75 | }
76 |
77 | public void setbY(float bY) {
78 | this.bY = bY;
79 | }
80 |
81 | public float getAngleA() {
82 | return angleA;
83 | }
84 |
85 | public void setAngleA(float angleA) {
86 | this.angleA = angleA;
87 | }
88 |
89 | public float getAngleB() {
90 | return angleB;
91 | }
92 |
93 | public void setAngleB(float angleB) {
94 | this.angleB = angleB;
95 | }
96 |
97 | public float getSpeedA() {
98 | return speedA;
99 | }
100 |
101 | public void setSpeedA(float speedA) {
102 | this.speedA = speedA;
103 | }
104 |
105 | public float getSpeedB() {
106 | return speedB;
107 | }
108 |
109 | public void setSpeedB(float speedB) {
110 | this.speedB = speedB;
111 | }
112 |
113 | public float getaXR() {
114 | return aXR;
115 | }
116 |
117 | public void setaXR(float aXR) {
118 | this.aXR = aXR;
119 | }
120 |
121 | public float getaYR() {
122 | return aYR;
123 | }
124 |
125 | public void setaYR(float aYR) {
126 | this.aYR = aYR;
127 | }
128 |
129 | public float getbXR() {
130 | return bXR;
131 | }
132 |
133 | public void setbXR(float bXR) {
134 | this.bXR = bXR;
135 | }
136 |
137 | public float getbYR() {
138 | return bYR;
139 | }
140 |
141 | public void setbYR(float bYR) {
142 | this.bYR = bYR;
143 | }
144 |
145 | public long getTime() {
146 | return time;
147 | }
148 |
149 | public void setTime(long time) {
150 | this.time = time;
151 | }
152 |
153 | private void init() {
154 | paint = new Paint(Paint.ANTI_ALIAS_FLAG);
155 | paint.setColor(Color.parseColor("#90ff7000"));
156 | paint.setStrokeWidth(1);
157 |
158 |
159 | speedA = (float) 0.015;
160 | speedB = (float) 0.26;
161 | aXR = 10;
162 | aYR = 100;
163 | bXR = 200;
164 | bYR = 40;
165 | time = 40*1000;
166 |
167 | startAnim(time);
168 | }
169 |
170 | @Override
171 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
172 | super.onSizeChanged(w, h, oldw, oldh);
173 | centerX = w / 2;
174 | centerY = h / 2;
175 | }
176 |
177 | @Override
178 | protected void onDraw(Canvas canvas) {
179 | super.onDraw(canvas);
180 |
181 | angleA += speedA;
182 | angleB += speedB;
183 |
184 | aX = (float) (Math.cos(angleA) * aXR);
185 | aY = (float) (Math.sin(angleA) * aYR);
186 | bX = (float) (Math.cos(angleB) * bXR);
187 | bY = (float) (Math.sin(angleB) * bYR);
188 |
189 | listPos.add(aX);
190 | listPos.add(aY);
191 | listPos.add(bX);
192 | listPos.add(bY);
193 |
194 | canvas.translate(centerX, centerY);
195 | canvas.drawColor(Color.BLACK);
196 | canvas.save();
197 | for (int i = 0; i < listPos.size(); i++) {
198 | if (i % 4 == 0) {
199 | canvas.drawLine(listPos.get(i), listPos.get(i + 1), listPos.get(i + 2), listPos.get(i + 3), paint);
200 | }
201 | }
202 | canvas.restore();
203 | }
204 |
205 | public void startAnim(long time) {
206 | ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
207 | animator.setDuration(time);
208 | animator.setInterpolator(new LinearInterpolator());
209 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
210 | @Override
211 | public void onAnimationUpdate(ValueAnimator animation) {
212 | invalidate();
213 | }
214 | });
215 | animator.setStartDelay(500);
216 | animator.start();
217 | }
218 |
219 | public void destory() {
220 | listPos.clear();
221 | invalidate();
222 | }
223 |
224 | }
225 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/wingjay/wjmagiccurveview/WJMagicCurveView.java:
--------------------------------------------------------------------------------
1 | package com.wingjay.wjmagiccurveview;
2 |
3 | import android.animation.TypeEvaluator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.view.animation.LinearInterpolator;
14 |
15 | /**
16 | * Created by wingjay on 4/22/16.
17 | * GitHub: https://github.com/wingjay
18 | * Blog: https://wingjay.com
19 | * Weibo: http://weibo.com/1625892654
20 | * Mail: yinjiesh@126.com
21 | */
22 | public class WJMagicCurveView extends View {
23 |
24 | private final float RADIUS_AX_DEFAULT = 300, RADIUS_AY_DEFAULT = 10;
25 | private final float RADIUS_BX_DEFAULT = 10, RADIUS_BY_DEFAULT = 300;
26 |
27 | private final float SPEED_OUTER_POINT_DEFAULT = 0.032f, SPEED_INNER_POINT_DEFAULT = 0.005f;
28 |
29 | private final int DURATION_SEC_DEFAULT = 50;
30 | private final int LOOP_TOTAL_COUNT_DEFAULT = 30;
31 |
32 | private float radiusAX = RADIUS_AX_DEFAULT, radiusAY = RADIUS_AY_DEFAULT;
33 | private float radiusBX = RADIUS_BX_DEFAULT, radiusBY = RADIUS_BY_DEFAULT;
34 |
35 | private float speedOuterPoint = SPEED_OUTER_POINT_DEFAULT, speedInnerPoint = SPEED_INNER_POINT_DEFAULT;
36 |
37 | private int DEFAULT_WIDTH = 700, DEFAULT_HEIGHT = 700;
38 | private int width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT;
39 |
40 | private Paint linePaint;
41 |
42 | float angleA = 0f, angleB = 0f;
43 | float aX, aY, bX, bY;
44 |
45 | private int backgroundColor = Color.BLACK;
46 | private int lineColor = Color.WHITE;
47 | private Paint.Style paintStyle = Paint.Style.FILL;
48 | private int lineAlpha = 130;
49 | private Bitmap bitmap;
50 | private Canvas c;
51 |
52 | private ValueAnimator valueAnimator;
53 | private boolean isDrawing = false;
54 |
55 | private int durationSec = DURATION_SEC_DEFAULT;
56 | private int loopTotalCount = LOOP_TOTAL_COUNT_DEFAULT;
57 |
58 | public WJMagicCurveView(Context context) {
59 | this(context, null);
60 | }
61 |
62 | public WJMagicCurveView(Context context, AttributeSet attrs) {
63 | this(context, attrs, 0);
64 | }
65 |
66 | public WJMagicCurveView(Context context, AttributeSet attrs, int defStyleAttr) {
67 | super(context, attrs, defStyleAttr);
68 | init();
69 | }
70 |
71 | private void init() {
72 | setBackgroundColor(backgroundColor);
73 | setupPaint();
74 | bitmap = Bitmap.createBitmap(DEFAULT_WIDTH, DEFAULT_HEIGHT, Bitmap.Config.ARGB_8888);
75 | }
76 |
77 | @Override
78 | public void setBackgroundColor(int color) {
79 | super.setBackgroundColor(color);
80 | }
81 |
82 | private void setupPaint() {
83 | linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
84 | linePaint.setColor(lineColor);
85 | linePaint.setStyle(paintStyle);
86 | linePaint.setStrokeWidth(1);
87 | linePaint.setAlpha(lineAlpha);
88 | }
89 |
90 | @Override
91 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
92 | if (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY) {
93 | width = DEFAULT_WIDTH;
94 | } else {
95 | width = MeasureSpec.getSize(widthMeasureSpec);
96 | }
97 | if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) {
98 | height = DEFAULT_HEIGHT;
99 | } else {
100 | height = MeasureSpec.getSize(heightMeasureSpec);
101 | }
102 | setMeasuredDimension(width, height);
103 | }
104 |
105 | private void setupSize() {
106 | bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
107 | c = null;
108 | }
109 |
110 | @Override
111 | protected void onDraw(Canvas canvas) {
112 | super.onDraw(canvas);
113 | if (c == null) {
114 | c = new Canvas(bitmap);
115 | c.translate(width / 2, height / 2);
116 | } else {
117 | aX = (float) Math.cos(angleA) * radiusAX;
118 | aY = (float) Math.sin(angleA) * radiusAY;
119 | bX = (float) Math.cos(angleB) * radiusBX;
120 | bY = (float) Math.sin(angleB) * radiusBY;
121 | c.drawLine(aX, aY, bX, bY, linePaint);
122 | }
123 | canvas.drawBitmap(bitmap, 0, 0, linePaint);
124 | }
125 |
126 | /**
127 | * Radius for two circles
128 | */
129 | public WJMagicCurveView setRadius(float radiusAX, float radiusAY, float radiusBX, float radiusBY) {
130 | setDefaultRadius();
131 | if (radiusAX > 0) {
132 | this.radiusAX = radiusAX;
133 | }
134 | if (radiusAY > 0) {
135 | this.radiusAY = radiusAY;
136 | }
137 | if (radiusBX > 0) {
138 | this.radiusBX = radiusBX;
139 | }
140 | if (radiusBY > 0) {
141 | this.radiusBY = radiusBY;
142 | }
143 | return this;
144 | }
145 |
146 | private void setDefaultRadius() {
147 | this.radiusAX = RADIUS_AX_DEFAULT;
148 | this.radiusAY = RADIUS_AY_DEFAULT;
149 | this.radiusBX = RADIUS_BX_DEFAULT;
150 | this.radiusBY = RADIUS_BY_DEFAULT;
151 | }
152 |
153 | /**
154 | * set the duration time for animation.
155 | */
156 | public WJMagicCurveView setDurationSec(int durationSec) {
157 | if (durationSec > 0) {
158 | this.durationSec = durationSec;
159 | } else {
160 | this.durationSec = DURATION_SEC_DEFAULT;
161 | }
162 | return this;
163 | }
164 |
165 | /**
166 | * set loop count.
167 | */
168 | public WJMagicCurveView setLoopTotalCount(int loopTotalCount) {
169 | if (loopTotalCount > 0) {
170 | this.loopTotalCount = loopTotalCount;
171 | } else {
172 | this.loopTotalCount = LOOP_TOTAL_COUNT_DEFAULT;
173 | }
174 | return this;
175 | }
176 |
177 | /**
178 | * set speed for two circles.
179 | */
180 | public WJMagicCurveView setSpeed(int speedOuterPoint, int speedInnerPoint) {
181 | if (speedOuterPoint > 0) {
182 | this.speedOuterPoint = (float)speedOuterPoint / 1000.f;
183 | } else {
184 | this.speedOuterPoint = SPEED_OUTER_POINT_DEFAULT;
185 | }
186 | if (speedInnerPoint > 0) {
187 | this.speedInnerPoint = (float)speedInnerPoint / 1000.f;
188 | } else {
189 | this.speedInnerPoint = SPEED_INNER_POINT_DEFAULT;
190 | }
191 | return this;
192 | }
193 |
194 | public void startDraw() {
195 | if (bitmap != null && !bitmap.isRecycled()) {
196 | bitmap.recycle();
197 | invalidate();
198 | }
199 | setupSize();
200 | Log.i("curve", "radiusAX " + radiusAX + ", radiusAY " + radiusAY
201 | + ", radiusBX " + radiusBX + ", radiusBY " + radiusBY
202 | + ", speedOuterPoint " + speedOuterPoint + ", speedInner " + speedInnerPoint
203 | + ", loopTotalCount " + loopTotalCount + ", duration " + durationSec);
204 | angleA = 0;
205 | angleB = 0;
206 | float endAngleA = loopTotalCount * (float) Math.PI;
207 | valueAnimator = ValueAnimator.ofFloat(0, endAngleA).setDuration(durationSec * 1000);
208 | valueAnimator.setEvaluator(new MyTypeEvaluator());
209 | valueAnimator.setInterpolator(new LinearInterpolator());
210 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
211 | @Override
212 | public void onAnimationUpdate(ValueAnimator animation) {
213 | angleA = (float) animation.getAnimatedValue();
214 | angleB = (angleA / speedOuterPoint) * speedInnerPoint;
215 | invalidate();
216 | }
217 | });
218 | valueAnimator.start();
219 | isDrawing = true;
220 | }
221 |
222 | public void stopDraw() {
223 | if (valueAnimator != null && valueAnimator.isRunning()) {
224 | valueAnimator.cancel();
225 | isDrawing = false;
226 | }
227 | }
228 |
229 | public void destory() {
230 | if (bitmap != null && !bitmap.isRecycled()) {
231 | bitmap.recycle();
232 | }
233 | }
234 |
235 | public boolean isDrawing() {
236 | return isDrawing;
237 | }
238 |
239 | /**
240 | * set paint color
241 | */
242 | public void setPaintColor(int lineColor) {
243 | this.lineColor = lineColor;
244 | setupPaint();
245 | invalidate();
246 | }
247 |
248 | /**
249 | * set paint style.
250 | */
251 | private void setPaintStyle(Paint.Style style) {
252 | this.paintStyle = style;
253 | setupPaint();
254 | invalidate();
255 | }
256 |
257 |
258 | /**
259 | * set paint alpha
260 | */
261 | public void setPaintAlpha(int lineAlpha) {
262 | this.lineAlpha = lineAlpha;
263 | setupPaint();
264 | invalidate();
265 | }
266 |
267 | /**
268 | * set all eight parameters at once.
269 | */
270 | public void setAllEightParameters(float radiusAX, float radiusAY, float radiusBX, float radiusBY,
271 | int durationSec, int loopTotalCount, int speedOuterPoint, int speedInnerPoint) {
272 | this.setRadius(radiusAX, radiusAY, radiusBX, radiusBY)
273 | .setDurationSec(durationSec).setLoopTotalCount(loopTotalCount)
274 | .setSpeed(speedOuterPoint, speedInnerPoint);
275 | }
276 |
277 | /**
278 | * set a WJMagicCurveViewParameters.
279 | */
280 | public void setParameters(WJMagicCurveViewParameters wjMagicCurveViewParameters) {
281 | this.setAllEightParameters(wjMagicCurveViewParameters.radiusAX, wjMagicCurveViewParameters.radiusAY,
282 | wjMagicCurveViewParameters.radiusBX, wjMagicCurveViewParameters.radiusBY,
283 | wjMagicCurveViewParameters.durationSec, wjMagicCurveViewParameters.loopTotalCount,
284 | wjMagicCurveViewParameters.speedOuterPoint, wjMagicCurveViewParameters.speedInnerPoint);
285 | }
286 |
287 | /**
288 | * You can create your own parameters as below.
289 | */
290 | public enum WJMagicCurveViewParameters {
291 | DEFAULT(-1, -1, -1, -1, -1, -1, -1, -1),
292 | DIAMOND(300, 1, 300, 150, 100, -1, 60, 28),
293 | RING(200, 200, 300, 300, 150, -1, 60, -1),
294 | PYRAMID(1, 300, 300, 1, 50, -1, -1, -1),
295 | SHELL(1, 300, 350, 300, 10, 1, -1, -1),
296 | FLOWER(320, 320, 280, 280, -1, -1, -1, -1),
297 | LEAF(1, 300, 300, 300, 1, 10000, -1, -1),
298 | AIRSHIP(300, 20, 150, 150, 50, -1, -1, -1);
299 |
300 | public float radiusAX;
301 | public float radiusAY;
302 | public float radiusBX;
303 | public float radiusBY;
304 | public int speedOuterPoint;
305 | public int speedInnerPoint;
306 | public int loopTotalCount;
307 | public int durationSec;
308 |
309 | /**
310 | * if param is -1, then it means use the default value.
311 | * @param radiusAX X radius for A point
312 | * @param radiusAY Y radius for A point
313 | * @param radiusBX X radius for B point
314 | * @param radiusBY Y radius for B point
315 | * @param speedOuterPoint speed for A(outer) point
316 | * @param speedInnerPoint speed for B(inner) point
317 | * @param loopTotalCount whole loop count
318 | * @param durationSec the duration time
319 | */
320 | WJMagicCurveViewParameters(float radiusAX, float radiusAY, float radiusBX, float radiusBY,
321 | int speedOuterPoint, int speedInnerPoint,
322 | int loopTotalCount, int durationSec) {
323 | this.radiusAX = radiusAX;
324 | this.radiusAY = radiusAY;
325 | this.radiusBX = radiusBX;
326 | this.radiusBY = radiusBY;
327 | this.durationSec = durationSec;
328 | this.loopTotalCount = loopTotalCount;
329 | this.speedOuterPoint = speedOuterPoint;
330 | this.speedInnerPoint = speedInnerPoint;
331 | }
332 | }
333 |
334 | /**
335 | * No special usage, just for fun. You can edit your TypeEvaluator.
336 | */
337 | class MyTypeEvaluator implements TypeEvaluator {
338 | @Override
339 | public Float evaluate(float fraction, Float startValue, Float endValue) {
340 | float currentValue = (endValue - startValue) * fraction;
341 | int count = (int) (currentValue / speedOuterPoint);
342 | return (float) count * speedOuterPoint;
343 | }
344 | }
345 |
346 | }
347 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WJMagicCurveView
3 |
4 |
--------------------------------------------------------------------------------
/lib/src/test/java/com/wingjay/wjmagiccurveview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wingjay.wjmagiccurveview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':lib'
2 |
--------------------------------------------------------------------------------