├── app
├── .gitignore
├── libs
│ └── rocket-v0.0.2.aar
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ └── frag_cylinder.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ └── com
│ │ │ └── yhd
│ │ │ └── cylinder
│ │ │ └── app
│ │ │ ├── SampleApplication.java
│ │ │ ├── activity
│ │ │ └── MainActivity.java
│ │ │ └── frag
│ │ │ └── Frag_cylinder.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── cylinder
├── consumer-rules.pro
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── yhd
│ │ └── cylinder
│ │ └── CylinderView.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── image
└── cylinder.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── markdown-navigator
│ └── profiles_settings.xml
├── vcs.xml
├── runConfigurations.xml
├── gradle.xml
├── codeStyles
│ └── Project.xml
└── misc.xml
├── gradle.properties
├── .gitignore
├── config.gradle
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/cylinder/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/cylinder/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':cylinder'
2 |
--------------------------------------------------------------------------------
/image/cylinder.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/image/cylinder.gif
--------------------------------------------------------------------------------
/app/libs/rocket-v0.0.2.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/libs/rocket-v0.0.2.aar
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HDCylinder
3 |
4 |
--------------------------------------------------------------------------------
/cylinder/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | hdwave
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/cylinder/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yinhaide/HDCylinder/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 | #ffffff
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yhd/cylinder/app/SampleApplication.java:
--------------------------------------------------------------------------------
1 | package com.yhd.cylinder.app;
2 |
3 | import com.de.rocket.app.RoApplication;
4 |
5 | /**
6 | * 进程
7 | */
8 | public class SampleApplication extends RoApplication {
9 |
10 | @Override
11 | public void onCreate() {
12 | super.onCreate();
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/cylinder/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Log files
19 | *.log
20 |
21 | #ButterKnife
22 | .apt_generated/
23 | .factorypath
24 |
25 | # for android-studio
26 | # Gradle files
27 | out/
28 | outputs/
29 | build/
30 | .gradle/
31 | gradlew
32 | gradlew.bat
33 |
34 | # IDEA
35 | *.iml
36 | .idea/
37 | .idea/.name
38 | .idea/encodings.xml
39 | .idea/inspectionProfiles/Project_Default.xml
40 | .idea/inspectionProfiles/profiles_settings.xml
41 | .idea/scopes/scope_settings.xml
42 |
43 | .DS_Store
44 | /build
45 | /captures
46 | .externalNativeBuild
47 |
48 | // add by haide.yin
49 | .idea/gradle.xml
50 | .idea/kotlinc.xml
51 | .idea/misc.xml
52 | .idea/runConfigurations.xml
53 | .idea/vcs.xml
54 |
--------------------------------------------------------------------------------
/config.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 |
3 | // 统一基本版本信息
4 | android = [
5 | buildToolsVersion: "28.0.3",
6 | compileSdkVersion: 28,
7 | minSdkVersion : 19,
8 | targetSdkVersion : 28,//22 可以绕过6.0动态获取权限
9 | versionCode : 1,
10 | versionName : "0.0.1",
11 | multiDexEnabled : true
12 | ]
13 |
14 | // 统一基础依赖
15 | dependencies = [
16 | v4 : 'com.android.support:support-v4:28.0.0',
17 | v7 : 'com.android.support:appcompat-v7:28.0.0',
18 | desigin : 'com.android.support:design:28.0.0',
19 | recyclerview : 'com.android.support:recyclerview-v7:28.0.0',
20 | fastjson : 'com.alibaba:fastjson:1.2.58',
21 | multidex : 'com.android.support:multidex:1.0.1',
22 | rocket : 'rocket-v0.0.2'
23 | ]
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/cylinder/src/main/res/values/attrs.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 |
--------------------------------------------------------------------------------
/cylinder/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.yinhaide'
4 |
5 | // 导入统一配置项
6 | def info = rootProject.ext.android
7 | def library = rootProject.ext.dependencies
8 |
9 | android {
10 | compileSdkVersion info.compileSdkVersion
11 | defaultConfig {
12 | minSdkVersion info.minSdkVersion
13 | targetSdkVersion info.targetSdkVersion
14 | versionCode info.versionCode
15 | versionName info.versionName
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 | consumerProguardFiles 'consumer-rules.pro'
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility = 1.8
28 | targetCompatibility = 1.8
29 | }
30 |
31 | }
32 |
33 | dependencies {
34 | /* ******* 统一基础包 ******** */
35 | api fileTree(dir: 'libs', include: ['*.jar'])
36 | api library.v4
37 | api library.v7
38 | api library.multidex
39 | api library.recyclerview
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/frag_cylinder.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
20 |
21 |
29 |
30 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yhd/cylinder/app/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.yhd.cylinder.app.activity;
2 |
3 | import android.graphics.Color;
4 |
5 | import com.de.rocket.Rocket;
6 | import com.de.rocket.bean.ActivityParamBean;
7 | import com.de.rocket.bean.RecordBean;
8 | import com.de.rocket.bean.StatusBarBean;
9 | import com.de.rocket.ue.activity.RoActivity;
10 | import com.yhd.cylinder.app.R;
11 | import com.yhd.cylinder.app.frag.Frag_cylinder;
12 |
13 | public class MainActivity extends RoActivity {
14 |
15 | private Class[] roFragments = {
16 | Frag_cylinder.class
17 | };
18 |
19 | @Override
20 | public ActivityParamBean initProperty() {
21 | ActivityParamBean activityParamBean = new ActivityParamBean();
22 | activityParamBean.setLayoutId(R.layout.activity_main);//Activity布局
23 | activityParamBean.setFragmentContainId(R.id.fl_fragment_contaner);//Fragment容器
24 | activityParamBean.setSaveInstanceState(true);//页面重载是否要恢复之前的页面
25 | activityParamBean.setToastCustom(true);//用自定义的吐司风格
26 | activityParamBean.setRoFragments(roFragments);//需要注册Fragment列表
27 | activityParamBean.setShowViewBall(true);//是否显示悬浮球
28 | activityParamBean.setRecordBean(new RecordBean(true,true,true,7));//日志策略
29 | activityParamBean.setEnableCrashWindow(true);//是否隐藏框架自定义的崩溃的窗口
30 | activityParamBean.setStatusBar(new StatusBarBean(true, Color.argb(0, 0, 0, 0)));//状态栏
31 | return activityParamBean;
32 | }
33 |
34 | @Override
35 | public void initViewFinish() {
36 | //恢复状态栏,因为启动Activity的Theme里面清楚了状态栏,需要恢复
37 | //- true
38 | Rocket.clearWindowFullscreen(this);
39 | }
40 |
41 | @Override
42 | public void onNexts(Object object) {
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yhd/cylinder/app/frag/Frag_cylinder.java:
--------------------------------------------------------------------------------
1 | package com.yhd.cylinder.app.frag;
2 |
3 | import android.view.View;
4 |
5 | import com.de.rocket.ue.frag.RoFragment;
6 | import com.de.rocket.ue.injector.BindView;
7 | import com.de.rocket.ue.injector.Event;
8 | import com.yhd.cylinder.CylinderView;
9 | import com.yhd.cylinder.app.R;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * 圆柱状图
16 | * Created by haide.yin(haide.yin@tcl.com) on 2019/6/6 16:12.
17 | */
18 | public class Frag_cylinder extends RoFragment {
19 |
20 |
21 | @BindView(R.id.bcv)
22 | private CylinderView cylinderView;
23 |
24 | @Override
25 | public int onInflateLayout() {
26 | return R.layout.frag_cylinder;
27 | }
28 |
29 | @Override
30 | public void initViewFinish(View inflateView) {
31 |
32 | }
33 |
34 | @Override
35 | public void onNexts(Object object) {
36 |
37 | }
38 |
39 | @Event(R.id.bt_update)
40 | private void update(View view) {
41 | /**
42 | * 柱形高度分布情况,是一个String[]类表,规则如下
43 | * float[0]:前面柱形高度百分比(0-1f)
44 | * float[1]:后面柱形高度百分比(0-1f)
45 | */
46 | List heightArray = new ArrayList<>();
47 | //x坐标轴的文字描述列表
48 | List xAxisArray = new ArrayList<>();
49 | //点击选中之后显示的文字.需要换行的用'/'分开
50 | List tipsArray = new ArrayList<>();
51 | //设置默认值
52 |
53 | heightArray.add(new float[]{0.02f, 0.5f});
54 | heightArray.add(new float[]{0.05f, 0.8f});
55 | heightArray.add(new float[]{0.08f, 0.9f});
56 | heightArray.add(new float[]{0.1f, 1f});
57 | heightArray.add(new float[]{0.3f, 0.5f});
58 | heightArray.add(new float[]{0.4f, 0.7f});
59 |
60 | xAxisArray.add("1");
61 | xAxisArray.add("2");
62 | xAxisArray.add("3");
63 | xAxisArray.add("4");
64 | xAxisArray.add("5");
65 | xAxisArray.add("6");
66 |
67 | tipsArray.add("Deephhhhdd 20 min/Light 18 min");
68 | tipsArray.add("Deep 10 min/Light 15 min");
69 | tipsArray.add("Deep 30 min/Light 28 min");
70 | tipsArray.add("Deep 40 min/Light 16 min");
71 | tipsArray.add("Deep/Light");
72 | tipsArray.add("Deep 50 min/Light 18 min");
73 |
74 | cylinderView.setdataSource(heightArray, xAxisArray, tipsArray);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | // 导入统一配置项
4 | def info = rootProject.ext.android
5 | def library = rootProject.ext.dependencies
6 |
7 | android {
8 | compileSdkVersion info.compileSdkVersion
9 | defaultConfig {
10 | applicationId "com.yhd.wave.app"
11 | minSdkVersion info.minSdkVersion
12 | targetSdkVersion info.targetSdkVersion
13 | versionCode info.versionCode
14 | versionName info.versionName
15 | multiDexEnabled info.multiDexEnabled
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | /*签名发布*/
20 | signingConfigs {
21 | release {
22 | storeFile file("../hdcylinder.jks")
23 | storePassword "hdcylinder"
24 | keyAlias "hdcylinder"
25 | keyPassword "hdcylinder"
26 | }
27 | }
28 |
29 | /*混淆*/
30 | buildTypes {
31 | release {
32 | minifyEnabled false
33 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34 | }
35 | }
36 |
37 | // 代码风格支持Java1.8
38 | compileOptions {
39 | sourceCompatibility JavaVersion.VERSION_1_8
40 | targetCompatibility JavaVersion.VERSION_1_8
41 | }
42 |
43 | // 指定jniLibs库路径为libs
44 | sourceSets {
45 | main {
46 | jniLibs.srcDir 'libs'
47 | }
48 | }
49 |
50 | // 动态修改apk的名字
51 | applicationVariants.all { variant ->
52 | variant.outputs.all { output ->
53 | def versionName = variant.versionName
54 | def versionCode = variant.versionCode
55 | def buildType = variant.buildType.name
56 | def time = new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+08:00"))
57 | if (variant.buildType.name == 'debug') {
58 | outputFileName = "cylinder_${versionName}_c${versionCode}_${buildType}.apk"
59 | } else {
60 | outputFileName = "cylinder_${versionName}_${time}_${buildType}.apk"
61 | }
62 | }
63 | }
64 | }
65 |
66 | repositories {
67 | flatDir {
68 | dirs 'libs'
69 | }
70 | }
71 |
72 | dependencies {
73 | /* ******* 统一基础包 ******** */
74 | api fileTree(dir: 'libs', include: ['*.jar'])
75 | api library.v4
76 | api library.v7
77 | api library.multidex
78 | api library.recyclerview
79 | /* ******* 工程依赖 ******** */
80 | //api 'com.github.yinhaide:DHCylinder:0.0.1'
81 | api project(':cylinder')
82 | // 架构包,单Activity多Fragment框架(https://github.com/yinhaide/HDRocket)
83 | api(name: library.rocket, ext: 'aar')
84 | //api 'com.github.yinhaide:HDRocket:0.0.4'
85 | }
86 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | xmlns:android
11 |
12 | ^$
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | xmlns:.*
22 |
23 | ^$
24 |
25 |
26 | BY_NAME
27 |
28 |
29 |
30 |
31 |
32 |
33 | .*:id
34 |
35 | http://schemas.android.com/apk/res/android
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | .*:name
45 |
46 | http://schemas.android.com/apk/res/android
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | name
56 |
57 | ^$
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | style
67 |
68 | ^$
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | .*
78 |
79 | ^$
80 |
81 |
82 | BY_NAME
83 |
84 |
85 |
86 |
87 |
88 |
89 | .*
90 |
91 | http://schemas.android.com/apk/res/android
92 |
93 |
94 | ANDROID_ATTRIBUTE_ORDER
95 |
96 |
97 |
98 |
99 |
100 |
101 | .*
102 |
103 | .*
104 |
105 |
106 | BY_NAME
107 |
108 |
109 |
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/yinhaide/Rocket-master/wiki)
2 | [](https://github.com/yinhaide/Rocket-master/wiki)
3 | [](https://www.apache.org/licenses/LICENSE-2.0)
4 |
5 | # HDCylinder
6 | 一个非常轻量级别的圆角双重叠圆柱,支持渐动画以及各种自定义属性
7 |
8 |
9 |
10 | ## 特性
11 | + **支持动画过度**
12 |
13 | + **圆滑的圆角显示**
14 |
15 | + **支持选中变大、变色、气泡提示**
16 |
17 | + **支持各种自定义属性**
18 |
19 | ## 如何快速集成
20 |
21 | ### 导入方式
22 | 在工程级别的**build.gradle**添加
23 | ```
24 | allprojects {
25 | repositories {
26 | ...
27 | maven { url 'https://jitpack.io' }
28 | }
29 | }
30 | ```
31 | 在应用级别的**build.gradle**添加
32 | ```
33 | api 'com.github.yinhaide:HDCylinder:0.0.1'
34 | ```
35 |
36 | ## 可设置属性
37 | ```
38 | //颜色属性
39 | private int behindColor = Color.parseColor("#8AFFA239");//背后柱形的颜色
40 | private int behindSelectColor = Color.parseColor("#FFFFA239");//背后柱形的颜色
41 | private int frontColor = Color.parseColor("#8A398EFF");//前面柱形的颜色
42 | private int frontSelectColor = Color.parseColor("#FF398EFF");//前面柱形的颜色
43 | //柱形属性
44 | private float barWidthRatio = 0.05f;//正常柱形宽度百分比
45 | private float selectBarWidthRatio = 0.07f;//选中的柱形宽度百分比
46 | private float distanceRatio = 0.05f;//柱形间距宽度百分比
47 | private float marginTextRatio = 0.03f;//柱形距离横坐标点娿距离百分比
48 | //画板四周边距
49 | private float marginLeftRatio = 0.05f;//画板左边距百分比
50 | private float marginRightRatio = 0.05f;//画板右边距百分比
51 | private float marginTopRatio = 0.05f;//画板上边距百分比
52 | private float marginBottomRatio = 0.05f;//画板下边距百分比
53 | //文字属性
54 | private float textRatio = 0.05f;//文字的大小百分比
55 | //气泡的属性
56 | private float bubbleHeightRatio = 0.2f;//泡泡的高度百分比
57 | private float bubbleWidthRatio = 0.2f;//泡泡的长度百分比
58 | private float triangleRatio = 0.02f;//尖部三角形边长百分比
59 | //动画
60 | private int animationTime = 1000;//动画持续时间
61 | ```
62 |
63 | ## 范例
64 | > 注意点:如果要设置渐变色的画注意其实颜色与结束颜色要保持一致
65 | ```
66 | [XML]
67 |
77 |
78 | [JAVA]
79 | /**
80 | * 柱形高度分布情况,是一个String[]类表,规则如下
81 | * float[0]:前面柱形高度百分比(0-1f)
82 | * float[1]:后面柱形高度百分比(0-1f)
83 | */
84 | List heightArray = new ArrayList<>();
85 | //x坐标轴的文字描述列表
86 | List xAxisArray = new ArrayList<>();
87 | //点击选中之后显示的文字.需要换行的用'/'分开
88 | List tipsArray = new ArrayList<>();
89 | //设置默认值
90 |
91 | heightArray.add(new float[]{0.02f, 0.5f});
92 | heightArray.add(new float[]{0.05f, 0.8f});
93 | heightArray.add(new float[]{0.08f, 0.9f});
94 | heightArray.add(new float[]{0.1f, 1f});
95 | heightArray.add(new float[]{0.3f, 0.5f});
96 | heightArray.add(new float[]{0.4f, 0.7f});
97 |
98 | xAxisArray.add("1");
99 | xAxisArray.add("2");
100 | xAxisArray.add("3");
101 | xAxisArray.add("4");
102 | xAxisArray.add("5");
103 | xAxisArray.add("6");
104 |
105 | tipsArray.add("Deephhhhdd 20 min/Light 18 min");
106 | tipsArray.add("Deep 10 min/Light 15 min");
107 | tipsArray.add("Deep 30 min/Light 28 min");
108 | tipsArray.add("Deep 40 min/Light 16 min");
109 | tipsArray.add("Deep/Light");
110 | tipsArray.add("Deep 50 min/Light 18 min");
111 |
112 | cylinderView.setdataSource(heightArray, xAxisArray, tipsArray);
113 | ```
114 |
115 | ## 分享设计思路
116 | > 绘制圆柱的难点在于当高度在一个宽度半径范围之内,直接调用drawRoundRect是不会得到预期值的,需要分别处理
117 | + 第一步:圆柱高度小于半径高度绘制扇形
118 | + 第二步:圆柱高度大于一个半径下两个半径绘制半圆加长方形
119 | + 第三部:圆柱高度大于直径绘制圆柱形
120 |
121 | ## 这个项目会持续更新中...
122 | > 都看到这里了,如果觉得写的可以或者对你有帮助的话,顺手给个星星点下Star~
123 |
124 | 这个控件内部采用一个Fragment框架,如果有兴趣的话可以去了解一下
125 | + [https://github.com/yinhaide/HDRocket](https://github.com/yinhaide/HDRocket)
126 | ## 关于我
127 | + **Email:** [123302687@qq.com](123302687@qq.com)
128 | + **Github:** [https://github.com/yinhaide](https://github.com/yinhaide)
129 | + **简书:** [https://www.jianshu.com/u/33c3dd2ceaa3](https://www.jianshu.com/u/33c3dd2ceaa3)
130 | + **CSDN:** [https://blog.csdn.net/yinhaide](https://blog.csdn.net/yinhaide)
131 |
132 | ## LICENSE
133 | ````
134 | Copyright 2019 haide.yin(123302687@qq.com)
135 |
136 | Licensed under the Apache License, Version 2.0 (the "License");
137 | you may not use this file except in compliance with the License.
138 | You may obtain a copy of the License at
139 |
140 | http://www.apache.org/licenses/LICENSE-2.0
141 |
142 | Unless required by applicable law or agreed to in writing, software
143 | distributed under the License is distributed on an "AS IS" BASIS,
144 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
145 | See the License for the specific language governing permissions and
146 | limitations under the License.
147 | ````
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/.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 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/cylinder/src/main/java/com/yhd/cylinder/CylinderView.java:
--------------------------------------------------------------------------------
1 | package com.yhd.cylinder;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.annotation.SuppressLint;
6 | import android.content.Context;
7 | import android.content.res.TypedArray;
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.graphics.Typeface;
14 | import android.os.Build;
15 | import android.text.TextUtils;
16 | import android.util.AttributeSet;
17 | import android.util.Log;
18 | import android.view.MotionEvent;
19 | import android.view.View;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | /**
25 | * 圆角柱形,可选中,而且要居中显示
26 | * Created by haide.yin(haide.yin@tcl.com) on 2019/7/25 13:34.
27 | */
28 | public class CylinderView extends View {
29 |
30 | private static final String TAG = CylinderView.class.getSimpleName();
31 |
32 | /* ********************* 外部设置的属性 *********************** */
33 | //颜色属性
34 | private int behindColor = Color.parseColor("#8AFFA239");//背后柱形的颜色
35 | private int behindSelectColor = Color.parseColor("#FFFFA239");//背后柱形的颜色
36 | private int frontColor = Color.parseColor("#8A398EFF");//前面柱形的颜色
37 | private int frontSelectColor = Color.parseColor("#FF398EFF");//前面柱形的颜色
38 | //柱形属性
39 | private float barWidthRatio = 0.05f;//正常柱形宽度百分比
40 | private float selectBarWidthRatio = 0.07f;//选中的柱形宽度百分比
41 | private float distanceRatio = 0.05f;//柱形间距宽度百分比
42 | private float marginTextRatio = 0.03f;//柱形距离横坐标点娿距离百分比
43 | //画板四周边距
44 | private float marginLeftRatio = 0.05f;//画板左边距百分比
45 | private float marginRightRatio = 0.05f;//画板右边距百分比
46 | private float marginTopRatio = 0.05f;//画板上边距百分比
47 | private float marginBottomRatio = 0.05f;//画板下边距百分比
48 | //文字属性
49 | private float textRatio = 0.05f;//文字的大小百分比
50 | //气泡的属性
51 | private float bubbleHeightRatio = 0.2f;//泡泡的高度百分比
52 | private float bubbleWidthRatio = 0.2f;//泡泡的长度百分比
53 | private float triangleRatio = 0.02f;//尖部三角形边长百分比
54 | //动画
55 | private int animationTime = 1000;//动画持续时间
56 |
57 | /**
58 | * 柱形高度分布情况,是一个String[]类表,规则如下
59 | * float[0]:前面柱形高度百分比(0-1f)
60 | * float[1]:后面柱形高度百分比(0-1f)
61 | */
62 | private List heightArray = new ArrayList<>();
63 | //x坐标轴的文字描述列表
64 | private List xAxisArray = new ArrayList<>();
65 | //点击选中之后显示的文字.需要换行的用'/'分开
66 | private List tipsArray = new ArrayList<>();
67 |
68 | /* ********************* 内部使用的属性 *********************** */
69 | private int textGrayColor = Color.parseColor("#61000000");//文字灰色
70 | private int bubbleColor = Color.parseColor("#8A000000");//文字灰色
71 | private Paint barPaint;//画柱形的画笔
72 | private Paint textPaint;//画文字画笔
73 | private List barRectList = new ArrayList<>();//柱形区域列表
74 | private int selectIndex = -1;//当前选中的柱形
75 | //动画监听
76 | private ChartAnimator chartAnimator = new ChartAnimator(animation -> postInvalidate());
77 |
78 | public CylinderView(Context context) {
79 | this(context, null);
80 | }
81 |
82 | public CylinderView(Context context, AttributeSet attrs) {
83 | this(context, attrs, 0);
84 | }
85 |
86 | public CylinderView(Context context, AttributeSet attrs, int defStyleAttr) {
87 | super(context, attrs, defStyleAttr);
88 | init(attrs);
89 | }
90 |
91 | @Override
92 | protected void onDetachedFromWindow() {
93 | super.onDetachedFromWindow();
94 | //View被窗体移除的时候释放动画资源
95 | chartAnimator.release();
96 | }
97 |
98 | @Override
99 | public void onWindowFocusChanged(boolean hasFoucus) {
100 | super.onWindowFocusChanged(hasFoucus);
101 | //View焦点变化
102 | }
103 |
104 | @Override
105 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
106 | super.onSizeChanged(w, h, oldw, oldh);
107 | chartAnimator.start(animationTime);
108 | }
109 |
110 | @SuppressLint("DrawAllocation")
111 | @Override
112 | protected void onDraw(Canvas canvas) {
113 | if (getWidth() > 0 && getHeight() > 0) {
114 | //清空列表
115 | barRectList.clear();
116 | //柱形的区域宽度
117 | float canvasWidth = (1f - marginLeftRatio - marginRightRatio) * getWidth();
118 | //柱形区域的高度
119 | float canvasHeight = (1f - marginTopRatio - marginBottomRatio - marginTextRatio - textRatio) * getHeight();
120 | //开始画柱形
121 | if (heightArray != null && heightArray.size() > 0) {
122 | float totalWidth = (heightArray.size() * barWidthRatio + (heightArray.size() -1) * distanceRatio) * getWidth();
123 | //如果超过则平分区域
124 | if(totalWidth > canvasWidth){
125 | barWidthRatio = (1f - marginLeftRatio - marginRightRatio) / (heightArray.size() * 2 -1);
126 | distanceRatio = barWidthRatio;
127 | selectBarWidthRatio = barWidthRatio * 1.3f;
128 | }
129 | //画笔的起点
130 | float chartTempStart = (getWidth() - (heightArray.size() * barWidthRatio * getWidth() + (heightArray.size() - 1) * distanceRatio * getWidth())) / 2;
131 | //开始画柱形与文字
132 | for (int i = 0; i < heightArray.size(); i++) {
133 | float[] selectValue = heightArray.get(i);
134 | if (selectValue.length >= 2) {
135 | //后面的柱形先画,乘上动画比例
136 | float phaseY = chartAnimator.getPhaseY();
137 | float behindBarHeight = selectValue[1] * canvasHeight * phaseY;
138 | //画背景柱状图矩形
139 | RectF behindRectF = new RectF();
140 | behindRectF.top = canvasHeight - behindBarHeight + marginTopRatio * getHeight();
141 | behindRectF.bottom = canvasHeight + marginTopRatio * getHeight();
142 | if (i == selectIndex) {
143 | barPaint.setColor(behindSelectColor);
144 | behindRectF.left = chartTempStart;
145 | behindRectF.right = chartTempStart + (selectBarWidthRatio) * getWidth();
146 | chartTempStart = chartTempStart + (selectBarWidthRatio + distanceRatio) * getWidth();
147 | } else {
148 | barPaint.setColor(behindColor);
149 | behindRectF.left = chartTempStart;
150 | behindRectF.right = chartTempStart + (barWidthRatio) * getWidth();
151 | chartTempStart = chartTempStart + (barWidthRatio + distanceRatio) * getWidth();
152 | }
153 | barRectList.add(behindRectF);
154 | drawSmoothBar(canvas, behindRectF, behindBarHeight, barPaint);
155 | //绘制前面的柱形,乘上动画比例
156 | float frontBarHeight = selectValue[0] * canvasHeight * phaseY;
157 | RectF frontRectF = new RectF();
158 | frontRectF.top = canvasHeight - frontBarHeight + marginTopRatio * getHeight();
159 | frontRectF.left = behindRectF.left;
160 | frontRectF.right = behindRectF.right;
161 | frontRectF.bottom = behindRectF.bottom;
162 | if (i == selectIndex) {
163 | barPaint.setColor(frontSelectColor);
164 | } else {
165 | barPaint.setColor(frontColor);
166 | }
167 | drawSmoothBar(canvas, frontRectF, frontBarHeight, barPaint);
168 | //开始画横坐标
169 | textPaint.setTextSize(textRatio * getHeight());
170 | if (i == selectIndex) {
171 | textPaint.setColor(Color.BLACK);
172 | textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
173 | } else {
174 | textPaint.setColor(textGrayColor);
175 | textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL));
176 | }
177 | canvas.drawText(xAxisArray.get(i), frontRectF.centerX(), (1 - marginBottomRatio) * getHeight(), textPaint);
178 | //画泡泡
179 | if (i == selectIndex) {
180 | //气泡显示内容
181 | String tipString = tipsArray.get(i);
182 | //绘制气泡
183 | textPaint.setColor(bubbleColor);
184 | textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL));
185 | float bubuleWidth = getBubbleWidth(textPaint, tipString, bubbleWidthRatio * getWidth());
186 | float bubbleHeight = getBubbleHeight(textPaint, tipString, bubbleHeightRatio * getHeight());
187 | float bubleTop;
188 | if (behindRectF.top - bubbleHeight - bubbleHeight / 2 <= marginTopRatio * getHeight()) {
189 | bubleTop = marginTopRatio * getHeight();
190 | } else {
191 | bubleTop = behindRectF.top - bubbleHeight - bubbleHeight / 2;
192 | }
193 | RectF rectBuble = new RectF(behindRectF.centerX() - bubuleWidth / 2, bubleTop, behindRectF.centerX() + bubuleWidth / 2, bubleTop + bubbleHeight);
194 | canvas.drawPath(drawBubble(rectBuble, triangleRatio * getWidth()), textPaint);
195 | Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
196 | //找出中心位置
197 | float bottomLineY = rectBuble.centerY() - (fontMetrics.bottom - fontMetrics.top) / 2 - fontMetrics.top;
198 | textPaint.setColor(Color.WHITE);
199 |
200 | float textSize = textRatio * getHeight();
201 | if (tipString.contains("/")) {
202 | String[] tipsString = tipString.split("/");
203 | String firstString = tipsString[0];
204 | String secondString = tipsString[1];
205 | canvas.drawText(firstString, rectBuble.centerX(), bottomLineY - textSize * 0.6f, textPaint);
206 | canvas.drawText(secondString, rectBuble.centerX(), bottomLineY + textSize * 0.6f, textPaint);
207 | } else {
208 | canvas.drawText(tipString, rectBuble.centerX(), bottomLineY, textPaint);
209 | }
210 | }
211 | }
212 | }
213 | }
214 | }
215 | }
216 |
217 | @SuppressLint("ClickableViewAccessibility")
218 | @Override
219 | public boolean onTouchEvent(MotionEvent event) {
220 | int action = event.getAction();
221 | switch (action) {
222 | case MotionEvent.ACTION_DOWN:
223 | int x = (int) event.getX();
224 | int y = (int) event.getY();
225 | for (RectF rectF : barRectList) {//选中
226 | if (rectF.contains(x, y)) {
227 | selectIndex = barRectList.indexOf(rectF);
228 | invalidate();
229 | break;
230 | }
231 | }
232 | break;
233 | }
234 | return true;
235 | }
236 |
237 | /**
238 | * 初始化
239 | */
240 | private void init(AttributeSet attrs) {
241 | //初始化属性
242 | if (attrs != null) {
243 | //初始化布局属性
244 | TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.CylinderView, 0, 0);
245 | barWidthRatio = typedArray.getFloat(R.styleable.CylinderView_cy_barWidthRatio, barWidthRatio);
246 | selectBarWidthRatio = typedArray.getFloat(R.styleable.CylinderView_cy_selectBarWidthRatio, selectBarWidthRatio);
247 | distanceRatio = typedArray.getFloat(R.styleable.CylinderView_cy_sepRatio, distanceRatio);
248 | marginTextRatio = typedArray.getFloat(R.styleable.CylinderView_cy_marginTextRatio, marginTextRatio);
249 | marginLeftRatio = typedArray.getFloat(R.styleable.CylinderView_cy_marginLeftRatio, marginLeftRatio);
250 | marginRightRatio = typedArray.getFloat(R.styleable.CylinderView_cy_marginRightRatio, marginRightRatio);
251 | marginTopRatio = typedArray.getFloat(R.styleable.CylinderView_cy_marginTopRatio, marginTopRatio);
252 | marginBottomRatio = typedArray.getFloat(R.styleable.CylinderView_cy_marginBottomRatio, marginBottomRatio);
253 | textRatio = typedArray.getFloat(R.styleable.CylinderView_cy_textRatio, textRatio);
254 | triangleRatio = typedArray.getFloat(R.styleable.CylinderView_cy_triangleRatio, triangleRatio);
255 | animationTime = typedArray.getInteger(R.styleable.CylinderView_cy_animationTime, animationTime);
256 | }
257 | //初始化画笔
258 | barPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
259 | barPaint.setAntiAlias(true); // 抗锯齿
260 | barPaint.setDither(true); // 防抖动
261 | barPaint.setStyle(Paint.Style.FILL);
262 | //文字画笔
263 | textPaint = new Paint();
264 | textPaint.setTextAlign(Paint.Align.CENTER);
265 | textPaint.setDither(true); // 防抖动
266 | textPaint.setAntiAlias(true);// 抗锯齿
267 | textPaint.setStrokeWidth(1);//画笔宽度
268 |
269 | //设置默认值
270 | heightArray.add(new float[]{0.02f, 0.5f});
271 | heightArray.add(new float[]{0.05f, 0.8f});
272 | heightArray.add(new float[]{0.08f, 0.9f});
273 | heightArray.add(new float[]{0.1f, 1f});
274 | heightArray.add(new float[]{0.3f, 0.5f});
275 | heightArray.add(new float[]{0.4f, 0.7f});
276 |
277 | xAxisArray.add("1");
278 | xAxisArray.add("2");
279 | xAxisArray.add("3");
280 | xAxisArray.add("4");
281 | xAxisArray.add("5");
282 | xAxisArray.add("6");
283 |
284 | tipsArray.add("Deephhh 20 min/Light 18 min");
285 | tipsArray.add("Deep min/Light min");
286 | tipsArray.add("Deep in/Light in");
287 | tipsArray.add("Deep n/Light n");
288 | tipsArray.add("Deep / Light");
289 | tipsArray.add("Deep/Light");
290 | }
291 |
292 | /**
293 | * 读取气泡的宽度
294 | */
295 | private float getBubbleWidth(Paint paint, String valueString, float defaultValue) {
296 | if (!TextUtils.isEmpty(valueString)) {
297 | //加字符串00是因为多测量一个多出两边的间距
298 | float sepSize = paint.measureText("00");
299 | if (valueString.contains("/")) {
300 | String[] tipsString = valueString.split("/");
301 | String firstString = tipsString[0];
302 | String secondString = tipsString[1];
303 | float firstWidth = paint.measureText(firstString);
304 | float secondWidth = paint.measureText(secondString);
305 | return Math.max(firstWidth, secondWidth) + sepSize;
306 | } else {
307 | return paint.measureText(valueString) + sepSize;
308 | }
309 | }
310 | return defaultValue;
311 | }
312 |
313 | /**
314 | * 读取气泡的宽度
315 | */
316 | private float getBubbleHeight(Paint paint, String valueString, float defaultValue) {
317 | if (!TextUtils.isEmpty(valueString)) {
318 | float sepSize = paint.measureText("00");
319 | if (valueString.contains("/")) {
320 | //多出的0.2表示两行文字的间距
321 | return paint.getTextSize() * 2.2f + sepSize;
322 | } else {
323 | return paint.getTextSize() + sepSize;
324 | }
325 | }
326 | return defaultValue;
327 | }
328 |
329 | /**
330 | * 绘制圆滑的柱形
331 | */
332 | private void drawSmoothBar(Canvas canvas, RectF barRectf, float barHeight, Paint paint) {
333 | //半径
334 | float radius = (barRectf.right - barRectf.left) / 2;
335 | //定义一个正方形
336 | RectF squareRectF = new RectF();
337 | squareRectF.left = barRectf.left;
338 | squareRectF.right = barRectf.right;
339 | squareRectF.bottom = barRectf.bottom;
340 | squareRectF.top = barRectf.bottom - radius * 2 - 1;//剪掉一个像素,不然出现一条色条
341 | //半数值直角边
342 | float cosHeight = radius - barHeight;
343 | //算出竖直边与斜边夹角
344 | int anger = (int) (180 * Math.acos(cosHeight / radius) / Math.PI);
345 | if (barHeight <= radius) {//小于半径高度绘制扇形
346 | canvas.drawArc(squareRectF, 90 - anger, anger * 2, false, paint);//绘制圆弧,不含圆心
347 | } else if (barHeight > radius && barHeight <= radius * 2) {//大一一个半径下两个半径绘制半圆加长方形
348 | //画一个半圆
349 | canvas.drawArc(squareRectF, 0, 180, false, paint);//绘制圆弧,不含圆心
350 | //定义一个长方形
351 | RectF longRectF = new RectF();
352 | longRectF.left = barRectf.left;
353 | longRectF.right = barRectf.right;
354 | longRectF.bottom = barRectf.bottom - radius;
355 | longRectF.top = barRectf.top;
356 | canvas.drawRect(longRectF, barPaint);//画长方形
357 | } else {//大于直径绘制柱形
358 | canvas.drawRoundRect(barRectf, (barRectf.right - barRectf.left) / 2, (barRectf.right - barRectf.left) / 2, paint);
359 | }
360 | }
361 |
362 | /**
363 | * 绘制气泡提示框
364 | *
365 | * @param myRect 形状
366 | * @return 路径
367 | */
368 | private Path drawBubble(RectF myRect, float triangleWidth) {
369 | int radius = 10;
370 | final Path path = new Path();
371 | final float left = myRect.left;
372 | final float top = myRect.top;
373 | final float right = myRect.right;
374 | final float bottom = myRect.bottom;
375 | final float centerX = myRect.centerX();
376 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
377 | path.addRoundRect(left, top, right, bottom, radius, radius, Path.Direction.CCW);
378 | } else {
379 | // TODO: 2019/8/1 API 21 以下绘制圆角
380 | //定位到左上角
381 | path.moveTo(left, top);
382 | //到右上角
383 | path.lineTo(right, top);
384 | //右边
385 | path.lineTo(right, bottom);
386 | path.lineTo(left, bottom);
387 | path.lineTo(left, top);
388 | }
389 | Path traAnglePath = new Path();
390 | traAnglePath.moveTo(centerX + triangleWidth, bottom);
391 | traAnglePath.lineTo(centerX, myRect.bottom + triangleWidth);
392 | traAnglePath.lineTo(centerX - triangleWidth, bottom);
393 | path.addPath(traAnglePath);
394 | traAnglePath.close();
395 | path.close();
396 | return path;
397 | }
398 |
399 | /**
400 | * 设置数据源
401 | *
402 | * @param heightArray 高度比
403 | * @param xAxisArray 坐标值
404 | * @param tipsArray 单击提示
405 | */
406 | public void setdataSource(List heightArray, List xAxisArray, List tipsArray) {
407 | if (heightArray != null && xAxisArray != null && tipsArray != null
408 | && heightArray.size() == xAxisArray.size()
409 | && xAxisArray.size() == tipsArray.size()) {
410 | selectIndex = -1;
411 | this.heightArray = heightArray;
412 | this.xAxisArray = xAxisArray;
413 | this.tipsArray = tipsArray;
414 | chartAnimator.start(animationTime);
415 | } else {
416 | Log.e(TAG, "invalid data");
417 | }
418 | }
419 |
420 | /**
421 | * 清空画布
422 | */
423 | public void clearView() {
424 | barPaint.setShader(null);
425 | textPaint.setShader(null);
426 | }
427 |
428 | /**
429 | * 圆柱绘制持续的动画类
430 | */
431 | private class ChartAnimator {
432 |
433 | private float mPhaseY = 1f; //默认动画值0f-1f
434 | private ValueAnimator.AnimatorUpdateListener mListener;//监听
435 | private ObjectAnimator objectAnimator;
436 |
437 | private ChartAnimator(ValueAnimator.AnimatorUpdateListener listener) {
438 | mListener = listener;
439 | }
440 |
441 | private float getPhaseY() {
442 | return mPhaseY;
443 | }
444 |
445 | private void setPhaseY(float phase) {
446 | mPhaseY = phase;
447 | }
448 |
449 | /**
450 | * Y轴动画
451 | *
452 | * @param durationMillis 持续时间
453 | */
454 | private void start(int durationMillis) {
455 | release();
456 | objectAnimator = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
457 | objectAnimator.setDuration(durationMillis);
458 | objectAnimator.addUpdateListener(mListener);
459 | objectAnimator.start();
460 | }
461 |
462 | /**
463 | * 释放动画
464 | */
465 | private void release() {
466 | if (objectAnimator != null) {
467 | objectAnimator.end();
468 | objectAnimator.cancel();
469 | objectAnimator = null;
470 | }
471 | }
472 | }
473 | }
474 |
--------------------------------------------------------------------------------