├── .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 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
OrderDemo
1
2
3
4
5
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 | ![](http://tp3.sinaimg.cn/1625892654/180/5739331233/1) 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 | ![](http://ww1.sinaimg.cn/mw690/7ef01fcagw1f35hl220wyg20at0a5h5e.gif) 38 | 39 | 紫之花 40 | 41 | 42 | ![](http://ww1.sinaimg.cn/mw690/7ef01fcagw1f35hl30ev0g20at0a5n96.gif) 43 | 44 | 青之草 45 | 46 | 47 | ![](http://ww3.sinaimg.cn/mw690/7ef01fcagw1f35hl3ol83g20at0a5111.gif) 48 | 49 | 黄之星 50 | 51 | 52 | ![](http://ww4.sinaimg.cn/mw690/7ef01fcagw1f35hl53hrrg20at0a54h3.gif) 53 | 54 | 蓝之海 55 | 56 | 57 | ![](http://ww3.sinaimg.cn/mw690/7ef01fcagw1f35hl5o6hfg20at0a5ahb.gif) 58 | 59 | 粉之晶 60 | 61 | 62 | ![](http://ww3.sinaimg.cn/mw690/7ef01fcagw1f35hkpli4kg20at0a5qkc.gif) 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 | ![](http://ww3.sinaimg.cn/mw690/7ef01fcagw1f35jzd8fjwj20jf0ccgmm.jpg) 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 | ![](http://tp3.sinaimg.cn/1625892654/180/5739331233/1) 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 |