├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── braceletdemo
│ │ └── com
│ │ └── braceletdemo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── braceletdemo
│ │ │ ├── activity
│ │ │ └── MainActivity.java
│ │ │ ├── util
│ │ │ └── DensityUtil.java
│ │ │ └── view
│ │ │ ├── EffectPulseView.java
│ │ │ ├── EffectSleepView.java
│ │ │ ├── GesturePulseView.java
│ │ │ └── GestureSleepView.java
│ └── res
│ │ ├── drawable-hdpi
│ │ ├── background.png
│ │ ├── ic_launcher.png
│ │ ├── pulse.png
│ │ ├── sleep.png
│ │ └── view_bg.png
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── view_effect_pulse.xml
│ │ ├── view_effect_sleep.xml
│ │ ├── view_gesture_pulse.xml
│ │ └── view_gesture_sleep.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
│ └── braceletdemo
│ └── com
│ └── braceletdemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── uploads
├── screenshot1.jpg
└── screenshot2.gif
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | BraceletDemo
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
22 |
23 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ChartDemo
2 | 基于 `Canvas` 绘制的图表 Demo
3 |
4 | ---
5 |
6 | 使用 `Canvas` 绘制的图表,在跟随手势的两个图表中,为了增加流畅度,使用了离屏缓存。
7 |
8 |
9 | ##截图
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.braceletdemo"
9 | minSdkVersion 21
10 | targetSdkVersion 24
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:24.0.0'
26 | }
27 |
--------------------------------------------------------------------------------
/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/gaopengfei/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/braceletdemo/com/braceletdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package braceletdemo.com.braceletdemo;
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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/braceletdemo/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.braceletdemo.activity;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.TextView;
6 |
7 | import com.braceletdemo.R;
8 | import com.braceletdemo.view.GesturePulseView;
9 | import com.braceletdemo.view.GesturePulseView.OnPulseFrequencyTouchListener;
10 | import com.braceletdemo.view.GestureSleepView;
11 | import com.braceletdemo.view.GestureSleepView.OnSleepQualityTouchListener;
12 |
13 | public class MainActivity extends Activity {
14 |
15 | /** 睡眠图表 */
16 | private GestureSleepView mSleepView;
17 | /** 睡眠质量数值 */
18 | private TextView mSleepQualityTV;
19 |
20 | /** 脉搏图表 */
21 | private GesturePulseView mPulseView;
22 | /** 脉搏数值 */
23 | private TextView mPulseTV;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 | /** 实现睡眠质量的回调 */
30 | mSleepView = (GestureSleepView) findViewById(R.id.gesturesleepview);
31 | mSleepQualityTV = (TextView) findViewById(R.id.gesture_sleepquality);
32 | mSleepView.SetOnSleepQualityTouchListener(new OnSleepQualityTouchListener() {
33 | @Override
34 | public void OnSleepQualityTouch(int data) {
35 | mSleepQualityTV.setText("质量:\t" + data);
36 | }
37 | });
38 |
39 | /** 实现脉搏的回调 */
40 | mPulseView = (GesturePulseView) findViewById(R.id.gesturepulseview);
41 | mPulseTV = (TextView) findViewById(R.id.gesture_normal_value);
42 | mPulseView.SetOnPulseFrequencyTouchListener(new OnPulseFrequencyTouchListener() {
43 | @Override
44 | public void OnSleepQualityTouch(int data) {
45 | mPulseTV.setText("数值:\t" + data);
46 | }
47 | });
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/braceletdemo/util/DensityUtil.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.braceletdemo.util;
5 |
6 | import android.content.Context;
7 |
8 | /**
9 | * 单位转化工具类,dp,px,sp之间转化
10 | */
11 | public class DensityUtil {
12 |
13 | /** 这里需要改成float返回,绘图的时候更精确 */
14 | public static float dip2px(Context paramContext, float paramFloat) {
15 | float f = paramContext.getResources().getDisplayMetrics().density;
16 | return paramFloat * f;
17 | }
18 |
19 | public static int px2dip(Context paramContext, float paramFloat) {
20 | float f = paramContext.getResources().getDisplayMetrics().density;
21 | return (int) (paramFloat / f + 0.5F);
22 | }
23 |
24 | public static int sp2px(Context paramContext, float paramFloat) {
25 | float f = paramContext.getResources().getDisplayMetrics().scaledDensity;
26 | return (int) (paramFloat * f + 0.5F);
27 | }
28 |
29 | public static int px2sp(Context paramContext, float paramFloat) {
30 | float f = paramContext.getResources().getDisplayMetrics().scaledDensity;
31 | return (int) (paramFloat / f + 0.5F);
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/braceletdemo/view/EffectPulseView.java:
--------------------------------------------------------------------------------
1 | package com.braceletdemo.view;
2 |
3 | import java.util.Random;
4 |
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.graphics.Path;
12 | import android.graphics.RectF;
13 | import android.util.AttributeSet;
14 | import android.view.MotionEvent;
15 | import android.view.View;
16 |
17 | import com.braceletdemo.R;
18 | import com.braceletdemo.util.DensityUtil;
19 |
20 | /**
21 | * @author gaopengfei
22 | */
23 | public class EffectPulseView extends View {
24 |
25 | /**
26 | * 画文字与画脉搏指数的画笔
27 | * 这里健康指数为了显示成带折线下有阴影效果的样式,使用倒画的方式
28 | * 默认为显示全的阴影,通过健康指数的不同在阴影从上往下画透明梯形来做成折线下的阴影效果
29 | */
30 | private Paint mTxtPaint, mPulsePaint, mDashLinePaint;
31 | /** 当前view的宽高尺寸(像素) */
32 | private int mViewWidth, mViewHeight;
33 | /** 每小时所占宽度 */
34 | private float mUnitWidth;
35 | /** 每2小时所占宽度(左右两边预留10像素间距) */
36 | private float mUnitTimeWidth;
37 | /** 下方时间轴的预设高度 */
38 | private int mTimelineHeight = 30;
39 | /** 每个小时的脉搏指数,24条线是25个点 */
40 | private int[] mData = new int[25];
41 | /** 盐分,让数据*盐分来实现数据正常显示在屏幕上,具体盐分大小需要具体适配调整 */
42 | private float mSalt;
43 |
44 | /** onTouch down时的坐标 */
45 | private float mStartX = 0;
46 |
47 | public EffectPulseView(Context context, AttributeSet attrs) {
48 | super(context, attrs);
49 |
50 | // 初始化文字画笔,宽度2,打开抗锯齿,画白色
51 | mTxtPaint = new Paint();
52 | mTxtPaint.setStrokeWidth(2);
53 | mTxtPaint.setAntiAlias(true);
54 | mTxtPaint.setColor(Color.WHITE);
55 |
56 | // 初始化背景色画笔,打开抗锯齿,画背景色#5F8CCF
57 | // 这个#5F8CCF值是Android手机跑起来之后从显示出来的颜色抓取的
58 | // 如果改了背景色与每个组件的框框的话,这个值需要重新从运行效果中抓取
59 | mPulsePaint = new Paint();
60 | mPulsePaint.setAntiAlias(true);
61 | mPulsePaint.setColor(Color.parseColor("#5F8CCF"));
62 |
63 | // 初始化虚线,不过因为是两种颜色的虚线,所以具体的时候再赋值颜色
64 | mDashLinePaint = new Paint();
65 | mDashLinePaint.setAntiAlias(true);
66 | mDashLinePaint.setStrokeWidth(2);
67 |
68 | // 初始化盐分
69 | mSalt = DensityUtil.dip2px(getContext(), 75.0f / 200.0f);
70 | }
71 |
72 | {
73 | updata();
74 | }
75 |
76 | private void updata() {
77 | Random r = new Random();
78 | for (int i = 0; i < mData.length; i++) {
79 | mData[i] = r.nextInt(200);
80 | }
81 | invalidate();
82 | }
83 |
84 | @Override
85 | public void onWindowFocusChanged(boolean hasWindowFocus) {
86 | super.onWindowFocusChanged(hasWindowFocus);
87 | System.out.println("onWindowFocusChanged");
88 | if (hasWindowFocus) {
89 | this.mViewWidth = getWidth();
90 | this.mViewHeight = getHeight();
91 | this.mUnitTimeWidth = (mViewWidth - 20) / 12;
92 | this.mUnitWidth = mViewWidth / 24.0f;
93 | }
94 | }
95 |
96 | @Override
97 | protected void onDraw(Canvas canvas) {
98 | drawTimeline(canvas);
99 | drawBackground(canvas);
100 | drawLine(canvas);
101 | drawDashLine(canvas);
102 | }
103 |
104 | /** 画折线,为了实现阴影效果其实画的是上方的透明梯形 */
105 | private void drawLine(Canvas canvas) {
106 |
107 | // 首先先画遮盖住阴影部分的梯形
108 | Path path = new Path();
109 | for (int i = 0; i < mData.length - 1; i++) {
110 | path.moveTo(i * mUnitWidth, 0);
111 | path.lineTo(i * mUnitWidth, mViewHeight - mTimelineHeight - mData[i] * mSalt);
112 | path.lineTo(i * mUnitWidth + mUnitWidth, mViewHeight - mTimelineHeight - mData[i + 1] * mSalt);
113 | path.lineTo(i * mUnitWidth + mUnitWidth, 0);
114 | canvas.drawPath(path, mPulsePaint);
115 | }
116 |
117 | // 因为24条折线是25个点,所以先手动画出第一个点,再for循环
118 | canvas.drawCircle(0, mViewHeight - mTimelineHeight - mData[0] * mSalt, 5, mTxtPaint);
119 | for (int i = 0; i < mData.length - 1; i++) {
120 | // 画折线
121 | canvas.drawLine(i * mUnitWidth, mViewHeight - mTimelineHeight - mData[i] * mSalt, i * mUnitWidth + mUnitWidth,
122 | mViewHeight - mTimelineHeight - mData[i + 1] * mSalt, mTxtPaint);
123 | // 画点
124 | canvas.drawCircle(i * mUnitWidth + mUnitWidth, mViewHeight - mTimelineHeight - mData[i + 1] * mSalt, 5, mTxtPaint);
125 | }
126 | }
127 |
128 | /** 画时间轴 */
129 | private void drawTimeline(Canvas canvas) {
130 | canvas.drawLine(0, mViewHeight - mTimelineHeight, mViewWidth, mViewHeight - mTimelineHeight, mTxtPaint);
131 | mTxtPaint.setTextSize(22);
132 | for (int i = 0; i <= 12; i++) {
133 | String time;
134 | if (i < 5) {
135 | time = "0" + i * 2;
136 | } else if (i < 12) {
137 | time = " " + i * 2;
138 | } else {
139 | time = "00";
140 | }
141 | canvas.drawText(time, i * mUnitTimeWidth, mViewHeight - 5, mTxtPaint);
142 | }
143 | }
144 |
145 | /** 画阴影背景底色 */
146 | private void drawBackground(Canvas canvas) {
147 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);
148 | RectF rect = new RectF();
149 | rect.top = 0;
150 | rect.bottom = mViewHeight - mTimelineHeight;
151 | rect.left = 0;
152 | rect.right = mViewWidth;
153 | canvas.drawBitmap(bitmap, null, rect, mTxtPaint);
154 | }
155 |
156 | /** 画虚线标尺,因为高版本好像已经不持支PathEffect了,所以画虚线就是for循环出来的 */
157 | private void drawDashLine(Canvas canvas) {
158 | // 在值160与60的两个高度画两条虚线(需要注意的是,当前的取值范围为0~200)
159 | int highValue = 160;
160 | int deepValue = 60;
161 | mDashLinePaint.setColor(Color.parseColor("#A7DF8C"));
162 | for (int i = 0; i < mViewWidth; i += 10) {
163 | canvas.drawLine(i, mViewHeight - mTimelineHeight - highValue * mSalt, i + 5, mViewHeight - mTimelineHeight - highValue * mSalt, mDashLinePaint);
164 | }
165 |
166 | mDashLinePaint.setColor(Color.parseColor("#6AA9DA"));
167 | for (int i = 0; i < mViewWidth; i += 10) {
168 | canvas.drawLine(i, mViewHeight - mTimelineHeight - deepValue * mSalt, i + 5, mViewHeight - mTimelineHeight - deepValue * mSalt, mDashLinePaint);
169 | }
170 | }
171 |
172 | @Override
173 | public boolean onTouchEvent(MotionEvent event) {
174 | switch (event.getAction()) {
175 | case MotionEvent.ACTION_DOWN:
176 | mStartX = event.getX();
177 | break;
178 | case MotionEvent.ACTION_UP:
179 | if (event.getX() > mStartX + 100) {// 向右滑动
180 | updata();
181 | } else if (event.getX() < mStartX - 100) {// 向左滑动
182 | updata();
183 | }
184 | }
185 | return true;
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/app/src/main/java/com/braceletdemo/view/EffectSleepView.java:
--------------------------------------------------------------------------------
1 | package com.braceletdemo.view;
2 |
3 | import java.util.Random;
4 |
5 | import com.braceletdemo.util.DensityUtil;
6 |
7 | import android.content.Context;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.util.AttributeSet;
12 | import android.view.MotionEvent;
13 | import android.view.View;
14 |
15 | /**
16 | * @author gaopengfei
17 | */
18 | public class EffectSleepView extends View {
19 |
20 | /** 画文字、画睡眠质量、画Touch时竖线的画笔 */
21 | private Paint mTxtPaint, mSleepQualityPaint, mTouchEffectPaint;
22 | /** 当前view的宽高尺寸(像素) */
23 | private int mViewWidth, mViewHeight;
24 | /** 每分钟所占宽度 */
25 | private float mUnitWidth;
26 | /** 每小时所占宽度(左右两边预留10像素间距) */
27 | private float mUnitTimeWidth;
28 | /** 下方时间轴的预设高度 */
29 | private int mTimelineHeight = 30;
30 | /** 总的分钟数(默认12个小时) */
31 | private int mUnitCount = 60 * 12;
32 | /** 起始时间,小时为单位,外后推延12个小时 */
33 | private int mStartTime = 21;
34 | /** 每分钟的睡眠质量数据 */
35 | private int mData[];
36 |
37 | /** onTouch down时的坐标 */
38 | float mStartX = 0;
39 |
40 | public EffectSleepView(Context context, AttributeSet attrs) {
41 | super(context, attrs);
42 |
43 | // 初始化文字画笔,宽度2,打开抗锯齿,画白色
44 | mTxtPaint = new Paint();
45 | mTxtPaint.setStrokeWidth(2);
46 | mTxtPaint.setAntiAlias(true);
47 | mTxtPaint.setColor(Color.WHITE);
48 |
49 | // 初始化睡眠质量画笔,开启抗锯齿,画#80E1C2
50 | mSleepQualityPaint = new Paint();
51 | mSleepQualityPaint.setAntiAlias(true);
52 | mSleepQualityPaint.setColor(Color.parseColor("#80E1C2"));
53 |
54 | // 初始化onTouch时竖线的画笔
55 | mTouchEffectPaint = new Paint();
56 | mTouchEffectPaint.setAntiAlias(true);
57 | mTouchEffectPaint.setColor(Color.parseColor("#FF9000"));
58 | mTouchEffectPaint.setStrokeWidth(2.0f);
59 | }
60 |
61 | {
62 | mData = new int[mUnitCount];
63 | updata();
64 | }
65 |
66 | private void updata() {
67 | Random r = new Random();
68 | for (int i = 0; i < mData.length; i++) {
69 | mData[i] = r.nextInt(200);
70 | }
71 | invalidate();
72 | }
73 |
74 | @Override
75 | public void onWindowFocusChanged(boolean hasWindowFocus) {
76 | super.onWindowFocusChanged(hasWindowFocus);
77 | if (hasWindowFocus) {
78 | this.mViewWidth = getWidth();
79 | this.mViewHeight = getHeight();
80 | this.mUnitTimeWidth = mViewWidth / 13.0f;
81 | this.mUnitWidth = this.mViewWidth / (float) mData.length;
82 | }
83 | }
84 |
85 | @Override
86 | protected void onDraw(Canvas canvas) {
87 | drawTimeline(canvas);
88 | drawSleepQuality(canvas);
89 | }
90 |
91 | /** 字体大小22,时间12个小时 */
92 | private void drawTimeline(Canvas canvas) {
93 | canvas.drawLine(0, mViewHeight - mTimelineHeight, mViewWidth, mViewHeight - mTimelineHeight, mTxtPaint);
94 | mTxtPaint.setTextSize(22);
95 | for (int i = 0; i < 13; i++) {
96 | String time;
97 | if (mStartTime % 24 < 10) {
98 | time = "0" + mStartTime++ % 24;
99 | } else {
100 | time = " " + mStartTime++ % 24;
101 | }
102 | canvas.drawText(time, i * mUnitTimeWidth, mViewHeight - 5, mTxtPaint);
103 | }
104 | mStartTime--;// 上面的time加多了一个减回去
105 | }
106 |
107 | /** 绘制睡眠质量 */
108 | private void drawSleepQuality(Canvas canvas) {
109 | /**
110 | * 加盐,防止数据绘制时溢出,具体盐分要看具体数据取值范围与屏幕大小
111 | */
112 | float salt = DensityUtil.dip2px(getContext(), 75.0f / 200.0f);
113 | for (int i = 0; i < mData.length; i++) {
114 | canvas.drawRect(i * mUnitWidth, mViewHeight - mTimelineHeight - mData[i] * salt, i * mUnitWidth + mUnitWidth, mViewHeight - mTimelineHeight,
115 | mSleepQualityPaint);
116 | }
117 | }
118 |
119 | /** 这个onTouchEvent是手势切换数据的效果 */
120 | @Override
121 | public boolean onTouchEvent(MotionEvent event) {
122 | switch (event.getAction()) {
123 | case MotionEvent.ACTION_DOWN:
124 | mStartX = event.getX();
125 | break;
126 | case MotionEvent.ACTION_UP:
127 | if (event.getX() > mStartX + 100) {// 向右滑动
128 | updata();
129 | } else if (event.getX() < mStartX - 100) {// 向左滑动
130 | updata();
131 | }
132 | break;
133 | }
134 | return true;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/app/src/main/java/com/braceletdemo/view/GesturePulseView.java:
--------------------------------------------------------------------------------
1 | package com.braceletdemo.view;
2 |
3 | import java.util.Random;
4 |
5 | import com.braceletdemo.R;
6 | import com.braceletdemo.util.DensityUtil;
7 |
8 | import android.content.Context;
9 | import android.graphics.Bitmap;
10 | import android.graphics.BitmapFactory;
11 | import android.graphics.Canvas;
12 | import android.graphics.Color;
13 | import android.graphics.Paint;
14 | import android.graphics.Path;
15 | import android.graphics.RectF;
16 | import android.graphics.Bitmap.Config;
17 | import android.util.AttributeSet;
18 | import android.view.MotionEvent;
19 | import android.view.View;
20 |
21 | /**
22 | * @author gaopengfei
23 | */
24 | public class GesturePulseView extends View {
25 |
26 | /**
27 | * 画文字与画脉搏指数的画笔
28 | * 这里健康指数为了显示成带折线下有阴影效果的样式,使用倒画的方式
29 | * 默认为显示全的阴影,通过健康指数的不同在阴影从上往下画透明梯形来做成折线下的阴影效果
30 | */
31 | private Paint mTxtPaint, mPulsePaint, mTouchEffectPaint, mDashLinePaint;
32 | /** 当前view的宽高尺寸(像素) */
33 | private int mViewWidth, mViewHeight;
34 | /** 每小时所占宽度 */
35 | private float mUnitWidth;
36 | /** 每2小时所占宽度(左右两边预留10像素间距) */
37 | private float mUnitTimeWidth;
38 | /** 下方时间轴的预设高度 */
39 | private int mTimelineHeight = 30;
40 | /** 每个小时的脉搏指数,24条线是25个点 */
41 | private int[] mData = new int[25];
42 | /** 盐分,让数据*盐分来实现数据正常显示在屏幕上,具体盐分大小需要具体适配调整 */
43 | private float mSalt;
44 |
45 | /** onTouch时的回调 */
46 | private OnPulseFrequencyTouchListener mPulseFrequencyTouchListener;
47 | /** onTouch down时的坐标 */
48 | private float mStartX = -5;
49 |
50 | /** 缓冲 */
51 | private Canvas mCacheCanvas;
52 | private Bitmap mCacheBitmap;
53 |
54 | public GesturePulseView(Context context, AttributeSet attrs) {
55 | super(context, attrs);
56 |
57 | // 初始化文字画笔,宽度2,打开抗锯齿,画白色
58 | mTxtPaint = new Paint();
59 | mTxtPaint.setStrokeWidth(2);
60 | mTxtPaint.setAntiAlias(true);
61 | mTxtPaint.setColor(Color.WHITE);
62 |
63 | // 初始化背景色画笔,打开抗锯齿,画背景色#5F8CCF
64 | // 这个#5F8CCF值是Android手机跑起来之后从显示出来的颜色抓取的
65 | // 如果改了背景色与每个组件的框框的话,这个值需要重新从运行效果中抓取
66 | mPulsePaint = new Paint();
67 | mPulsePaint.setAntiAlias(true);
68 | mPulsePaint.setColor(Color.parseColor("#5F8CCF"));
69 |
70 | // 初始化onTouch时竖线的画笔
71 | mTouchEffectPaint = new Paint();
72 | mTouchEffectPaint.setAntiAlias(true);
73 | mTouchEffectPaint.setColor(Color.parseColor("#FF9000"));
74 | mTouchEffectPaint.setStrokeWidth(2.0f);
75 |
76 | // 初始化虚线,不过因为是两种颜色的虚线,所以具体的时候再赋值颜色
77 | mDashLinePaint = new Paint();
78 | mDashLinePaint.setAntiAlias(true);
79 | mDashLinePaint.setStrokeWidth(2);
80 |
81 | // 初始化盐分
82 | mSalt = DensityUtil.dip2px(getContext(), 75.0f / 200.0f);
83 |
84 | mCacheCanvas = new Canvas();
85 | }
86 |
87 | {
88 | updata();
89 | }
90 |
91 | private void updata() {
92 | Random r = new Random();
93 | for (int i = 0; i < mData.length; i++) {
94 | mData[i] = r.nextInt(200);
95 | }
96 | }
97 |
98 | @Override
99 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
100 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
101 | this.mViewWidth = MeasureSpec.getSize(widthMeasureSpec);
102 | this.mViewHeight = MeasureSpec.getSize(heightMeasureSpec);
103 | this.mUnitTimeWidth = (mViewWidth - 20) / 12;
104 | this.mUnitWidth = mViewWidth / 24.0f;
105 | }
106 |
107 | @Override
108 | public void onWindowFocusChanged(boolean hasWindowFocus) {
109 | super.onWindowFocusChanged(hasWindowFocus);
110 | if (hasWindowFocus) {
111 | this.mViewWidth = getWidth();
112 | this.mViewHeight = getHeight();
113 | this.mUnitTimeWidth = (mViewWidth - 20) / 12;
114 | this.mUnitWidth = mViewWidth / 24.0f;
115 | }
116 | }
117 |
118 | @Override
119 | protected void onDraw(Canvas canvas) {
120 | if (mCacheBitmap == null) {// 没缓冲过,增加一份缓冲,以后直接画缓冲中的bitmap再加上touch效果就行了
121 | mCacheBitmap = Bitmap.createBitmap(mViewWidth, mViewHeight, Config.ARGB_8888);
122 | mCacheCanvas.setBitmap(mCacheBitmap);
123 | drawTimeline(mCacheCanvas);
124 | drawBackground(mCacheCanvas);
125 | drawLine(mCacheCanvas);
126 | drawDashLine(mCacheCanvas);
127 | }
128 | canvas.drawBitmap(mCacheBitmap, 0, 0, mTxtPaint);
129 | drawTouchEffect(canvas);
130 | }
131 |
132 | /** 画touch效果 */
133 | private void drawTouchEffect(Canvas canvas) {
134 | float x = mStartX;
135 | for (int i = 0; i < 25; i++) {
136 | if (mUnitWidth * i - 5 < mStartX && mUnitWidth * i + 5 > mStartX) {// 吸附效果
137 | x = mUnitWidth * i;
138 | canvas.drawCircle(x, mViewHeight - mTimelineHeight - mData[i] * mSalt, 5, mTouchEffectPaint);
139 | if (mPulseFrequencyTouchListener != null) {
140 | mPulseFrequencyTouchListener.OnSleepQualityTouch(mData[i]);
141 | }
142 | break;
143 | }
144 | }
145 | canvas.drawLine(x, 0, x, mViewHeight - mTimelineHeight, mTouchEffectPaint);
146 | }
147 |
148 | /** 画折线,为了实现阴影效果其实画的是上方的透明梯形 */
149 | private void drawLine(Canvas canvas) {
150 |
151 | // 首先先画遮盖住阴影部分的梯形
152 | Path path = new Path();
153 | for (int i = 0; i < mData.length - 1; i++) {
154 | path.moveTo(i * mUnitWidth, 0);
155 | path.lineTo(i * mUnitWidth, mViewHeight - mTimelineHeight - mData[i] * mSalt);
156 | path.lineTo(i * mUnitWidth + mUnitWidth, mViewHeight - mTimelineHeight - mData[i + 1] * mSalt);
157 | path.lineTo(i * mUnitWidth + mUnitWidth, 0);
158 | canvas.drawPath(path, mPulsePaint);
159 | }
160 |
161 | // 因为24条折线是25个点,所以先手动画出第一个点,再for循环
162 | canvas.drawCircle(0, mViewHeight - mTimelineHeight - mData[0] * mSalt, 5, mTxtPaint);
163 | for (int i = 0; i < mData.length - 1; i++) {
164 | // 画折线
165 | canvas.drawLine(i * mUnitWidth, mViewHeight - mTimelineHeight - mData[i] * mSalt, i * mUnitWidth + mUnitWidth,
166 | mViewHeight - mTimelineHeight - mData[i + 1] * mSalt, mTxtPaint);
167 | // 画点
168 | canvas.drawCircle(i * mUnitWidth + mUnitWidth, mViewHeight - mTimelineHeight - mData[i + 1] * mSalt, 5, mTxtPaint);
169 | }
170 | }
171 |
172 | /** 画时间轴 */
173 | private void drawTimeline(Canvas canvas) {
174 | canvas.drawLine(0, mViewHeight - mTimelineHeight, mViewWidth, mViewHeight - mTimelineHeight, mTxtPaint);
175 | mTxtPaint.setTextSize(22);
176 | for (int i = 0; i <= 12; i++) {
177 | String time;
178 | if (i < 5) {
179 | time = "0" + i * 2;
180 | } else if (i < 12) {
181 | time = " " + i * 2;
182 | } else {
183 | time = "00";
184 | }
185 | canvas.drawText(time, i * mUnitTimeWidth, mViewHeight - 5, mTxtPaint);
186 | }
187 | }
188 |
189 | /** 画阴影背景底色 */
190 | private void drawBackground(Canvas canvas) {
191 | Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);
192 | RectF rect = new RectF();
193 | rect.top = 0;
194 | rect.bottom = mViewHeight - mTimelineHeight;
195 | rect.left = 0;
196 | rect.right = mViewWidth;
197 | canvas.drawBitmap(bitmap, null, rect, mTxtPaint);
198 | }
199 |
200 | /** 画虚线标尺,因为高版本好像已经不持支PathEffect了,所以画虚线就是for循环出来的 */
201 | private void drawDashLine(Canvas canvas) {
202 | // 在值160与60的两个高度画两条虚线(需要注意的是,当前的取值范围为0~200)
203 | int highValue = 160;
204 | int deepValue = 60;
205 | mDashLinePaint.setColor(Color.parseColor("#A7DF8C"));
206 | for (int i = 0; i < mViewWidth; i += 10) {
207 | canvas.drawLine(i, mViewHeight - mTimelineHeight - highValue * mSalt, i + 5, mViewHeight - mTimelineHeight - highValue * mSalt, mDashLinePaint);
208 | }
209 |
210 | mDashLinePaint.setColor(Color.parseColor("#6AA9DA"));
211 | for (int i = 0; i < mViewWidth; i += 10) {
212 | canvas.drawLine(i, mViewHeight - mTimelineHeight - deepValue * mSalt, i + 5, mViewHeight - mTimelineHeight - deepValue * mSalt, mDashLinePaint);
213 | }
214 | }
215 |
216 | @Override
217 | public boolean onTouchEvent(MotionEvent event) {
218 | this.mStartX = event.getX();
219 | invalidate();
220 | return true;
221 | }
222 |
223 | public interface OnPulseFrequencyTouchListener {
224 | public void OnSleepQualityTouch(int data);
225 | }
226 |
227 | /** touch时回调方法 */
228 | public void SetOnPulseFrequencyTouchListener(OnPulseFrequencyTouchListener listener) {
229 | this.mPulseFrequencyTouchListener = listener;
230 | }
231 | }
232 |
--------------------------------------------------------------------------------
/app/src/main/java/com/braceletdemo/view/GestureSleepView.java:
--------------------------------------------------------------------------------
1 | package com.braceletdemo.view;
2 |
3 | import java.util.Random;
4 |
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.graphics.Bitmap.Config;
11 | import android.util.AttributeSet;
12 | import android.view.MotionEvent;
13 | import android.view.View;
14 |
15 | import com.braceletdemo.util.DensityUtil;
16 |
17 | /**
18 | * @author gaopengfei
19 | */
20 | public class GestureSleepView extends View {
21 |
22 | /** 画文字、画睡眠质量、画Touch时竖线的画笔 */
23 | private Paint mTxtPaint, mSleepQualityPaint, mTouchEffectPaint;
24 | /** 当前view的宽高尺寸(像素) */
25 | private int mViewWidth, mViewHeight;
26 | /** 每分钟所占宽度 */
27 | private float mUnitWidth;
28 | /** 每小时所占宽度(左右两边预留10像素间距) */
29 | private float mUnitTimeWidth;
30 | /** 下方时间轴的预设高度 */
31 | private int mTimelineHeight = 30;
32 | /** 总的分钟数(默认12个小时) */
33 | private int mUnitCount = 60 * 12;
34 | /** 起始时间,小时为单位,外后推延12个小时 */
35 | private int mStartTime = 21;
36 | /** 每分钟的睡眠质量数据 */
37 | private int mData[];
38 | /** 加盐,防止数据绘制时溢出,具体盐分要看具体数据 */
39 | float mSalt;
40 |
41 | /** 睡眠质量touch时的回调 */
42 | private OnSleepQualityTouchListener mSleepQualityTouchListener;
43 | /** touch的X轴坐标 */
44 | private float mTouchX = -5;
45 |
46 | /** 缓冲 */
47 | private Canvas mCacheCanvas;
48 | private Bitmap mCacheBitmap;
49 |
50 | public GestureSleepView(Context context, AttributeSet attrs) {
51 | super(context, attrs);
52 |
53 | // 初始化文字画笔,宽度2,打开抗锯齿,画白色
54 | mTxtPaint = new Paint();
55 | mTxtPaint.setStrokeWidth(2);
56 | mTxtPaint.setAntiAlias(true);
57 | mTxtPaint.setColor(Color.WHITE);
58 |
59 | // 初始化睡眠质量画笔,开启抗锯齿,画#80E1C2
60 | mSleepQualityPaint = new Paint();
61 | mSleepQualityPaint.setAntiAlias(true);
62 | mSleepQualityPaint.setColor(Color.parseColor("#80E1C2"));
63 |
64 | // 初始化onTouch时竖线的画笔
65 | mTouchEffectPaint = new Paint();
66 | mTouchEffectPaint.setAntiAlias(true);
67 | mTouchEffectPaint.setColor(Color.parseColor("#FF9000"));
68 | mTouchEffectPaint.setStrokeWidth(2.0f);
69 |
70 | mSalt = DensityUtil.dip2px(getContext(), 75.0f / 200.0f);
71 |
72 | mCacheCanvas = new Canvas();
73 | }
74 |
75 | {
76 | mData = new int[mUnitCount];
77 | updata();
78 | }
79 |
80 | private void updata() {
81 | // 模拟数据,到时候这里替换成网络请求就可以了
82 | Random r = new Random();
83 | for (int i = 0; i < mData.length; i++) {
84 | mData[i] = r.nextInt(200);
85 | }
86 | }
87 |
88 | @Override
89 | public void onWindowFocusChanged(boolean hasWindowFocus) {
90 | super.onWindowFocusChanged(hasWindowFocus);
91 | if (hasWindowFocus) {
92 | this.mViewWidth = getWidth();
93 | this.mViewHeight = getHeight();
94 | this.mUnitTimeWidth = mViewWidth / 13.0f;
95 | this.mUnitWidth = this.mViewWidth / (float) mData.length;
96 | }
97 | }
98 |
99 | @Override
100 | protected void onDraw(Canvas canvas) {
101 | if (mCacheBitmap == null) {// 没缓冲过,增加一份缓冲,以后直接画缓冲中的bitmap再加上touch效果就行了
102 | mCacheBitmap = Bitmap.createBitmap(mViewWidth, mViewHeight, Config.ARGB_8888);
103 | mCacheCanvas.setBitmap(mCacheBitmap);
104 | drawTimeline(mCacheCanvas);
105 | drawSleepQuality(mCacheCanvas);
106 | }
107 | canvas.drawBitmap(mCacheBitmap, 0, 0, mTxtPaint);
108 | drawTouchEffect(canvas);
109 | }
110 |
111 | /** 字体大小22,时间12个小时 */
112 | private void drawTimeline(Canvas canvas) {
113 | canvas.drawLine(0, mViewHeight - mTimelineHeight, mViewWidth, mViewHeight - mTimelineHeight, mTxtPaint);
114 | mTxtPaint.setTextSize(22);
115 | for (int i = 0; i < 13; i++) {
116 | String time;
117 | if (mStartTime % 24 < 10) {
118 | time = "0" + mStartTime++ % 24;
119 | } else {
120 | time = " " + mStartTime++ % 24;
121 | }
122 | canvas.drawText(time, 10 + i * mUnitTimeWidth, mViewHeight - 5, mTxtPaint);
123 | }
124 | mStartTime = 21;// 还原时间
125 | }
126 |
127 | /** 绘制睡眠质量 */
128 | private void drawSleepQuality(Canvas canvas) {
129 |
130 | for (int i = 0; i < mData.length; i++) {
131 | canvas.drawRect(i * mUnitWidth, mViewHeight - mTimelineHeight - mData[i] * mSalt, i * mUnitWidth + mUnitWidth, mViewHeight - mTimelineHeight,
132 | mSleepQualityPaint);
133 | }
134 | }
135 |
136 | /** 绘制touch竖线与下方小球 */
137 | private void drawTouchEffect(Canvas canvas) {
138 | canvas.drawLine(mTouchX, 0, mTouchX, mViewHeight - mTimelineHeight, mTouchEffectPaint);
139 | canvas.drawCircle(mTouchX, mViewHeight - mTimelineHeight, 5, mTouchEffectPaint);
140 | // 找到touch坐标对应的数据回调显示
141 | if (mSleepQualityTouchListener != null) {
142 | int position = (int) (mTouchX / mUnitWidth);// 对应的数据坐标
143 | if (position >= 0 && position < mData.length) {
144 | int data = mData[position];
145 | mSleepQualityTouchListener.OnSleepQualityTouch(data);
146 | }
147 | }
148 | }
149 |
150 | /** 这个onTouchEvent是显示竖线右上角显示对应数据的效果 */
151 | @Override
152 | public boolean onTouchEvent(MotionEvent event) {
153 | this.mTouchX = event.getX();
154 | System.out.println("touch" + mTouchX);
155 | invalidate();
156 | return true;
157 | }
158 |
159 | public interface OnSleepQualityTouchListener {
160 | public void OnSleepQualityTouch(int data);
161 | }
162 |
163 | /** touch时回调方法 */
164 | public void SetOnSleepQualityTouchListener(OnSleepQualityTouchListener listener) {
165 | this.mSleepQualityTouchListener = listener;
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/app/src/main/res/drawable-hdpi/background.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/pulse.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/app/src/main/res/drawable-hdpi/pulse.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/sleep.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/app/src/main/res/drawable-hdpi/sleep.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/view_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/app/src/main/res/drawable-hdpi/view_bg.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_effect_pulse.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
17 |
18 |
29 |
30 |
39 |
40 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_effect_sleep.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
17 |
18 |
26 |
27 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_gesture_pulse.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
17 |
18 |
29 |
30 |
39 |
40 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_gesture_sleep.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
17 |
18 |
27 |
28 |
36 |
37 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/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 | BraceletDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/test/java/braceletdemo/com/braceletdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package braceletdemo.com.braceletdemo;
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.1.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/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/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/uploads/screenshot1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/uploads/screenshot1.jpg
--------------------------------------------------------------------------------
/uploads/screenshot2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/feeeei/ChartDemo/f6ec662cbb44fa7db3652c285f533fb98aaa6df1/uploads/screenshot2.gif
--------------------------------------------------------------------------------