35 | * Set releaseSurface to true if you want the Surface to be released when release() is
36 | * called. This is convenient, but can interfere with framework classes that expect to
37 | * manage the Surface themselves (e.g. if you release a SurfaceView's Surface, the
38 | * surfaceDestroyed() callback won't fire).
39 | */
40 | public WindowSurface(EglCore eglCore, Surface surface, boolean releaseSurface) {
41 | super(eglCore);
42 | createWindowSurface(surface);
43 | mSurface = surface;
44 | mReleaseSurface = releaseSurface;
45 | }
46 |
47 | /**
48 | * Associates an EGL surface with the SurfaceTexture.
49 | */
50 | public WindowSurface(EglCore eglCore, SurfaceTexture surfaceTexture) {
51 | super(eglCore);
52 | createWindowSurface(surfaceTexture);
53 | }
54 |
55 | /**
56 | * Releases any resources associated with the EGL surface (and, if configured to do so,
57 | * with the Surface as well).
58 | *
59 | * Does not require that the surface's EGL context be current.
60 | */
61 | public void release() {
62 | releaseEglSurface();
63 | if (mSurface != null) {
64 | if (mReleaseSurface) {
65 | mSurface.release();
66 | }
67 | mSurface = null;
68 | }
69 | }
70 |
71 | public void setSurface(Surface surface) {
72 | mSurface = surface;
73 | }
74 |
75 | /**
76 | * Recreate the EGLSurface, using the new EglBase. The caller should have already
77 | * freed the old EGLSurface with releaseEglSurface().
78 | *
79 | * This is useful when we want to update the EGLSurface associated with a Surface.
80 | * For example, if we want to share with a different EGLContext, which can only
81 | * be done by tearing down and recreating the context. (That's handled by the caller;
82 | * this just creates a new EGLSurface for the Surface we were handed earlier.)
83 | *
84 | * If the previous EGLSurface isn't fully destroyed, e.g. it's still current on a
85 | * context somewhere, the create call will fail with complaints from the Surface
86 | * about already being connected.
87 | */
88 | public void recreate(EglCore newEglCore) {
89 | if (mSurface == null) {
90 | throw new RuntimeException("not yet implemented for SurfaceTexture");
91 | }
92 | mEglCore = newEglCore; // switch to new context
93 | createWindowSurface(mSurface); // create new surface
94 | }
95 |
96 | public EGLSurface getEGLSurface(){
97 | return mEGLSurface;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/vonchenchen/mediacodecdemo/video/gles/FullFrameRect.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.vonchenchen.mediacodecdemo.video.gles;
18 |
19 |
20 | /**
21 | * This class essentially represents a viewport-sized sprite that will be rendered with
22 | * a texture, usually from an external source like the camera or video decoder.
23 | */
24 | public class FullFrameRect {
25 | private final Drawable2d mRectDrawable = new Drawable2d(Drawable2d.Prefab.FULL_RECTANGLE);
26 | private Texture2dProgram mProgram;
27 |
28 | /**
29 | * Prepares the object.
30 | *
31 | * @param program The program to use. FullFrameRect takes ownership, and will release
32 | * the program when no longer needed.
33 | */
34 | public FullFrameRect(Texture2dProgram program) {
35 | mProgram = program;
36 | }
37 |
38 | /**
39 | * Releases resources.
40 | *
41 | * This must be called with the appropriate EGL context current (i.e. the one that was
42 | * current when the constructor was called). If we're about to destroy the EGL context,
43 | * there's no value in having the caller make it current just to do this cleanup, so you
44 | * can pass a flag that will tell this function to skip any EGL-context-specific cleanup.
45 | */
46 | public void release(boolean doEglCleanup) {
47 | if (mProgram != null) {
48 | if (doEglCleanup) {
49 | mProgram.release();
50 | }
51 | mProgram = null;
52 | }
53 | }
54 |
55 | /**
56 | * Returns the program currently in use.
57 | */
58 | public Texture2dProgram getProgram() {
59 | return mProgram;
60 | }
61 |
62 | /**
63 | * Changes the program. The previous program will be released.
64 | *
65 | * The appropriate EGL context must be current.
66 | */
67 | public void changeProgram(Texture2dProgram program) {
68 | mProgram.release();
69 | mProgram = program;
70 | }
71 |
72 | /**
73 | * Creates a texture object suitable for use with drawFrame().
74 | */
75 | public int createTextureObject() {
76 | return mProgram.createTextureObject();
77 | }
78 |
79 | /**
80 | * 将视频按比例缩放到窗口中
81 | * @param vertexBuf
82 | */
83 | public void rescaleDrawRect(float[] vertexBuf){
84 | mRectDrawable.setVertexArray(vertexBuf);
85 | }
86 |
87 | /**
88 | * 渲染textureId到framebuffer
89 | * @param textureId
90 | */
91 | public void beginDrawToTexture(int textureId){
92 | mProgram.beginDrawToTexture(textureId);
93 | }
94 |
95 | /**
96 | * Draws a viewport-filling rect, texturing it with the specified texture object.
97 | */
98 | public void drawFrame(int textureId, float[] texMatrix) {
99 | // Use the identity matrix for MVP so our 2x2 FULL_RECTANGLE covers the viewport.
100 | mProgram.draw(GlUtil.IDENTITY_MATRIX, mRectDrawable.getVertexArray(), 0,
101 | mRectDrawable.getVertexCount(), mRectDrawable.getCoordsPerVertex(),
102 | mRectDrawable.getVertexStride(),
103 | texMatrix, mRectDrawable.getTexCoordArray(), textureId,
104 | mRectDrawable.getTexCoordStride());
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/vonchenchen/mediacodecdemo/video/statistics/BitrateInfoCounter.java:
--------------------------------------------------------------------------------
1 | package com.vonchenchen.mediacodecdemo.video.statistics;
2 |
3 | import com.vonchenchen.mediacodecdemo.utils.NumUtils;
4 |
5 | import java.util.LinkedList;
6 | import java.util.List;
7 |
8 | public class BitrateInfoCounter {
9 |
10 | private List mBitrateList;
11 |
12 | public BitrateInfoCounter(){
13 |
14 | mBitrateList = new LinkedList<>();
15 | }
16 |
17 | public void addData(int data){
18 |
19 | mBitrateList.add(data);
20 | }
21 |
22 | public BitrateInfo count(int target){
23 |
24 | BitrateInfo bitrateInfo = new BitrateInfo();
25 |
26 | int standCntSum = 0;
27 | int sum = 0;
28 |
29 | if(mBitrateList.size() <= 0){
30 | return bitrateInfo;
31 | }
32 |
33 | bitrateInfo.min = mBitrateList.get(0)*8;
34 | bitrateInfo.max = mBitrateList.get(0)*8;
35 |
36 | for(int i=0; i bitrateInfo.max){
41 | bitrateInfo.max = data;
42 | }else if(data < bitrateInfo.min){
43 | bitrateInfo.min = data;
44 | }
45 |
46 | sum += data;
47 | }
48 |
49 | bitrateInfo.average = sum/mBitrateList.size();
50 |
51 | for(int i=0; i
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
19 |
20 |
26 |
27 |
33 |
34 |
39 |
40 |
41 |
46 |
51 |
57 |
58 |
59 |
65 |
66 |
72 |
73 |
81 |
82 |
87 |
93 |
99 |
100 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_opengldemo.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_record1_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_record_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_splash.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
28 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_line_chart.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/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/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/out.vp8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/app/src/main/res/raw/out.vp8
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MediaCodecDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/vonchenchen/mediacodecdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.vonchenchen.mediacodecdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.2.0'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu May 23 10:06:52 CST 2019
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-4.6-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/hellocharts-library/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/hellocharts-library/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | hellocharts-library
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/hellocharts-library/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/hellocharts-library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | buildscript {
4 | repositories {
5 | mavenCentral()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0'
9 | }
10 | }
11 |
12 | dependencies {
13 | //compile fileTree(dir: 'libs', include: '*.jar')
14 | implementation 'com.android.support:support-v4:23.4.0'
15 | }
16 |
17 |
18 | android {
19 | compileSdkVersion 26
20 |
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_7
23 | targetCompatibility JavaVersion.VERSION_1_7
24 | }
25 |
26 | defaultConfig {
27 | minSdkVersion 19
28 | targetSdkVersion 26
29 | versionCode 1
30 | versionName "1.0"
31 | }
32 |
33 | sourceSets {
34 | main {
35 | manifest.srcFile 'AndroidManifest.xml'
36 | java.srcDirs = ['src']
37 | resources.srcDirs = ['src']
38 | aidl.srcDirs = ['src']
39 | renderscript.srcDirs = ['src']
40 | res.srcDirs = ['res']
41 | assets.srcDirs = ['assets']
42 | }
43 | }
44 |
45 | buildTypes {
46 | release {
47 | minifyEnabled false
48 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
49 | }
50 | }
51 |
52 | lintOptions {
53 | abortOnError false
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/hellocharts-library/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=HelloCharts Library for Android
2 | POM_ARTIFACT_ID=hellocharts-library
3 | POM_PACKAGING=aar
4 |
--------------------------------------------------------------------------------
/hellocharts-library/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/hellocharts-library/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/hellocharts-library/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | lecho.lib.hellocharts
6 | hellocharts-library
7 | HelloCharts Android
8 | 1.0
9 | jar
10 |
11 |
12 | UTF-8
13 | 4.4
14 | 19
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | com.google.android
23 | android
24 | ${android.version}
25 | provided
26 |
27 |
28 | com.android.support
29 | support-v4
30 | ${support.version}
31 |
32 |
33 |
34 |
35 | src
36 |
37 |
38 |
39 | com.jayway.maven.plugins.android.generation2
40 | android-maven-plugin
41 | true
42 |
43 |
44 |
45 |
46 |
47 |
48 | Apache License Version 2.0
49 | http://www.apache.org/licenses/LICENSE-2.0.html
50 | repo
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/hellocharts-library/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/hellocharts-library/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/hellocharts-library/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/hellocharts-library/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/hellocharts-library/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/hellocharts-library/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/ChartAnimationListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | import java.util.EventListener;
4 |
5 | /**
6 | * Listener used to listen for chart animation start and stop events. Implementations of this interface can be used for
7 | * all types of chart animations(data, viewport, PieChart rotation).
8 | */
9 | public interface ChartAnimationListener extends EventListener {
10 |
11 | public void onAnimationStarted();
12 |
13 | public void onAnimationFinished();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/ChartDataAnimator.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | public interface ChartDataAnimator {
4 |
5 | public static final long DEFAULT_ANIMATION_DURATION = 500;
6 |
7 | public void startAnimation(long duration);
8 |
9 | public void cancelAnimation();
10 |
11 | public boolean isAnimationStarted();
12 |
13 | public void setChartAnimationListener(ChartAnimationListener animationListener);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/ChartDataAnimatorV14.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | import android.animation.Animator;
4 | import android.animation.Animator.AnimatorListener;
5 | import android.animation.ValueAnimator;
6 | import android.animation.ValueAnimator.AnimatorUpdateListener;
7 | import android.annotation.SuppressLint;
8 |
9 | import lecho.lib.hellocharts.view.Chart;
10 |
11 | @SuppressLint("NewApi")
12 | public class ChartDataAnimatorV14 implements ChartDataAnimator, AnimatorListener, AnimatorUpdateListener {
13 | private final Chart chart;
14 | private ValueAnimator animator;
15 | private ChartAnimationListener animationListener = new DummyChartAnimationListener();
16 |
17 | public ChartDataAnimatorV14(Chart chart) {
18 | this.chart = chart;
19 | animator = ValueAnimator.ofFloat(0.0f, 1.0f);
20 | animator.addListener(this);
21 | animator.addUpdateListener(this);
22 | }
23 |
24 | @Override
25 | public void startAnimation(long duration) {
26 | if (duration >= 0) {
27 | animator.setDuration(duration);
28 | } else {
29 | animator.setDuration(DEFAULT_ANIMATION_DURATION);
30 | }
31 | animator.start();
32 | }
33 |
34 | @Override
35 | public void cancelAnimation() {
36 | animator.cancel();
37 | }
38 |
39 | @Override
40 | public void onAnimationUpdate(ValueAnimator animation) {
41 | chart.animationDataUpdate(animation.getAnimatedFraction());
42 | }
43 |
44 | @Override
45 | public void onAnimationCancel(Animator animation) {
46 | }
47 |
48 | @Override
49 | public void onAnimationEnd(Animator animation) {
50 | chart.animationDataFinished();
51 | animationListener.onAnimationFinished();
52 | }
53 |
54 | @Override
55 | public void onAnimationRepeat(Animator animation) {
56 | }
57 |
58 | @Override
59 | public void onAnimationStart(Animator animation) {
60 | animationListener.onAnimationStarted();
61 | }
62 |
63 | @Override
64 | public boolean isAnimationStarted() {
65 | return animator.isStarted();
66 | }
67 |
68 | @Override
69 | public void setChartAnimationListener(ChartAnimationListener animationListener) {
70 | if (null == animationListener) {
71 | this.animationListener = new DummyChartAnimationListener();
72 | } else {
73 | this.animationListener = animationListener;
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/ChartDataAnimatorV8.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | import android.os.Handler;
4 | import android.os.SystemClock;
5 | import android.view.animation.AccelerateDecelerateInterpolator;
6 | import android.view.animation.Interpolator;
7 |
8 | import lecho.lib.hellocharts.view.Chart;
9 |
10 | public class ChartDataAnimatorV8 implements ChartDataAnimator {
11 |
12 | final Chart chart;
13 | final Handler handler;
14 | final Interpolator interpolator = new AccelerateDecelerateInterpolator();
15 | long start;
16 | boolean isAnimationStarted = false;
17 | long duration;
18 | private final Runnable runnable = new Runnable() {
19 |
20 | @Override
21 | public void run() {
22 | long elapsed = SystemClock.uptimeMillis() - start;
23 | if (elapsed > duration) {
24 | isAnimationStarted = false;
25 | handler.removeCallbacks(runnable);
26 | chart.animationDataFinished();
27 | return;
28 | }
29 | float scale = Math.min(interpolator.getInterpolation((float) elapsed / duration), 1);
30 | chart.animationDataUpdate(scale);
31 | handler.postDelayed(this, 16);
32 |
33 | }
34 | };
35 | private ChartAnimationListener animationListener = new DummyChartAnimationListener();
36 |
37 | public ChartDataAnimatorV8(Chart chart) {
38 | this.chart = chart;
39 | this.handler = new Handler();
40 | }
41 |
42 | @Override
43 | public void startAnimation(long duration) {
44 | if (duration >= 0) {
45 | this.duration = duration;
46 | } else {
47 | this.duration = DEFAULT_ANIMATION_DURATION;
48 | }
49 |
50 | isAnimationStarted = true;
51 | animationListener.onAnimationStarted();
52 | start = SystemClock.uptimeMillis();
53 | handler.post(runnable);
54 | }
55 |
56 | @Override
57 | public void cancelAnimation() {
58 | isAnimationStarted = false;
59 | handler.removeCallbacks(runnable);
60 | chart.animationDataFinished();
61 | animationListener.onAnimationFinished();
62 | }
63 |
64 | @Override
65 | public boolean isAnimationStarted() {
66 | return isAnimationStarted;
67 | }
68 |
69 | @Override
70 | public void setChartAnimationListener(ChartAnimationListener animationListener) {
71 | if (null == animationListener) {
72 | this.animationListener = new DummyChartAnimationListener();
73 | } else {
74 | this.animationListener = animationListener;
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/ChartViewportAnimator.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | import lecho.lib.hellocharts.model.Viewport;
4 |
5 | public interface ChartViewportAnimator {
6 |
7 | public static final int FAST_ANIMATION_DURATION = 300;
8 |
9 | public void startAnimation(Viewport startViewport, Viewport targetViewport);
10 |
11 | public void startAnimation(Viewport startViewport, Viewport targetViewport, long duration);
12 |
13 | public void cancelAnimation();
14 |
15 | public boolean isAnimationStarted();
16 |
17 | public void setChartAnimationListener(ChartAnimationListener animationListener);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/ChartViewportAnimatorV14.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | import android.animation.Animator;
4 | import android.animation.Animator.AnimatorListener;
5 | import android.animation.ValueAnimator;
6 | import android.animation.ValueAnimator.AnimatorUpdateListener;
7 | import android.annotation.SuppressLint;
8 |
9 | import lecho.lib.hellocharts.model.Viewport;
10 | import lecho.lib.hellocharts.view.Chart;
11 |
12 | @SuppressLint("NewApi")
13 | public class ChartViewportAnimatorV14 implements ChartViewportAnimator, AnimatorListener, AnimatorUpdateListener {
14 | private final Chart chart;
15 | private ValueAnimator animator;
16 | private Viewport startViewport = new Viewport();
17 | private Viewport targetViewport = new Viewport();
18 | private Viewport newViewport = new Viewport();
19 | private ChartAnimationListener animationListener = new DummyChartAnimationListener();
20 |
21 | public ChartViewportAnimatorV14(Chart chart) {
22 | this.chart = chart;
23 | animator = ValueAnimator.ofFloat(0.0f, 1.0f);
24 | animator.addListener(this);
25 | animator.addUpdateListener(this);
26 | animator.setDuration(FAST_ANIMATION_DURATION);
27 | }
28 |
29 | @Override
30 | public void startAnimation(Viewport startViewport, Viewport targetViewport) {
31 | this.startViewport.set(startViewport);
32 | this.targetViewport.set(targetViewport);
33 | animator.setDuration(FAST_ANIMATION_DURATION);
34 | animator.start();
35 | }
36 |
37 | @Override
38 | public void startAnimation(Viewport startViewport, Viewport targetViewport, long duration) {
39 | this.startViewport.set(startViewport);
40 | this.targetViewport.set(targetViewport);
41 | animator.setDuration(duration);
42 | animator.start();
43 | }
44 |
45 | @Override
46 | public void cancelAnimation() {
47 | animator.cancel();
48 | }
49 |
50 | @Override
51 | public void onAnimationUpdate(ValueAnimator animation) {
52 | float scale = animation.getAnimatedFraction();
53 | float diffLeft = (targetViewport.left - startViewport.left) * scale;
54 | float diffTop = (targetViewport.top - startViewport.top) * scale;
55 | float diffRight = (targetViewport.right - startViewport.right) * scale;
56 | float diffBottom = (targetViewport.bottom - startViewport.bottom) * scale;
57 | newViewport.set(startViewport.left + diffLeft, startViewport.top + diffTop, startViewport.right + diffRight,
58 | startViewport.bottom + diffBottom);
59 | chart.setCurrentViewport(newViewport);
60 | }
61 |
62 | @Override
63 | public void onAnimationCancel(Animator animation) {
64 | }
65 |
66 | @Override
67 | public void onAnimationEnd(Animator animation) {
68 | chart.setCurrentViewport(targetViewport);
69 | animationListener.onAnimationFinished();
70 | }
71 |
72 | @Override
73 | public void onAnimationRepeat(Animator animation) {
74 | }
75 |
76 | @Override
77 | public void onAnimationStart(Animator animation) {
78 | animationListener.onAnimationStarted();
79 | }
80 |
81 | @Override
82 | public boolean isAnimationStarted() {
83 | return animator.isStarted();
84 | }
85 |
86 | @Override
87 | public void setChartAnimationListener(ChartAnimationListener animationListener) {
88 | if (null == animationListener) {
89 | this.animationListener = new DummyChartAnimationListener();
90 | } else {
91 | this.animationListener = animationListener;
92 | }
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/ChartViewportAnimatorV8.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | import android.os.Handler;
4 | import android.os.SystemClock;
5 | import android.view.animation.AccelerateDecelerateInterpolator;
6 | import android.view.animation.Interpolator;
7 |
8 | import lecho.lib.hellocharts.model.Viewport;
9 | import lecho.lib.hellocharts.view.Chart;
10 |
11 | public class ChartViewportAnimatorV8 implements ChartViewportAnimator {
12 |
13 | final Chart chart;
14 | final Handler handler;
15 | final Interpolator interpolator = new AccelerateDecelerateInterpolator();
16 | long start;
17 | boolean isAnimationStarted = false;
18 | private Viewport startViewport = new Viewport();
19 | private Viewport targetViewport = new Viewport();
20 | private Viewport newViewport = new Viewport();
21 | private long duration;
22 | private ChartAnimationListener animationListener = new DummyChartAnimationListener();
23 | private final Runnable runnable = new Runnable() {
24 |
25 | @Override
26 | public void run() {
27 | long elapsed = SystemClock.uptimeMillis() - start;
28 | if (elapsed > duration) {
29 | isAnimationStarted = false;
30 | handler.removeCallbacks(runnable);
31 | chart.setCurrentViewport(targetViewport);
32 | animationListener.onAnimationFinished();
33 | return;
34 | }
35 | float scale = Math.min(interpolator.getInterpolation((float) elapsed / duration), 1);
36 | float diffLeft = (targetViewport.left - startViewport.left) * scale;
37 | float diffTop = (targetViewport.top - startViewport.top) * scale;
38 | float diffRight = (targetViewport.right - startViewport.right) * scale;
39 | float diffBottom = (targetViewport.bottom - startViewport.bottom) * scale;
40 | newViewport.set(startViewport.left + diffLeft, startViewport.top + diffTop,
41 | startViewport.right + diffRight, startViewport.bottom + diffBottom);
42 | chart.setCurrentViewport(newViewport);
43 |
44 | handler.postDelayed(this, 16);
45 | }
46 | };
47 |
48 | public ChartViewportAnimatorV8(Chart chart) {
49 | this.chart = chart;
50 | this.duration = FAST_ANIMATION_DURATION;
51 | this.handler = new Handler();
52 | }
53 |
54 | @Override
55 | public void startAnimation(Viewport startViewport, Viewport targetViewport) {
56 | this.startViewport.set(startViewport);
57 | this.targetViewport.set(targetViewport);
58 | duration = FAST_ANIMATION_DURATION;
59 | isAnimationStarted = true;
60 | animationListener.onAnimationStarted();
61 | start = SystemClock.uptimeMillis();
62 | handler.post(runnable);
63 | }
64 |
65 | @Override
66 | public void startAnimation(Viewport startViewport, Viewport targetViewport, long duration) {
67 | this.startViewport.set(startViewport);
68 | this.targetViewport.set(targetViewport);
69 | this.duration = duration;
70 | isAnimationStarted = true;
71 | animationListener.onAnimationStarted();
72 | start = SystemClock.uptimeMillis();
73 | handler.post(runnable);
74 | }
75 |
76 | @Override
77 | public void cancelAnimation() {
78 | isAnimationStarted = false;
79 | handler.removeCallbacks(runnable);
80 | chart.setCurrentViewport(targetViewport);
81 | animationListener.onAnimationFinished();
82 | }
83 |
84 | @Override
85 | public boolean isAnimationStarted() {
86 | return isAnimationStarted;
87 | }
88 |
89 | @Override
90 | public void setChartAnimationListener(ChartAnimationListener animationListener) {
91 | if (null == animationListener) {
92 | this.animationListener = new DummyChartAnimationListener();
93 | } else {
94 | this.animationListener = animationListener;
95 | }
96 | }
97 |
98 |
99 | }
100 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/DummyChartAnimationListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | public class DummyChartAnimationListener implements ChartAnimationListener {
4 |
5 | @Override
6 | public void onAnimationStarted() {
7 | // do nothing
8 |
9 | }
10 |
11 | @Override
12 | public void onAnimationFinished() {
13 | // do nothing
14 |
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/PieChartRotationAnimator.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | public interface PieChartRotationAnimator {
4 |
5 | public static final int FAST_ANIMATION_DURATION = 200;
6 |
7 | public void startAnimation(float startAngle, float angleToRotate);
8 |
9 | public void cancelAnimation();
10 |
11 | public boolean isAnimationStarted();
12 |
13 | public void setChartAnimationListener(ChartAnimationListener animationListener);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/PieChartRotationAnimatorV14.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | import android.animation.Animator;
4 | import android.animation.Animator.AnimatorListener;
5 | import android.animation.ValueAnimator;
6 | import android.animation.ValueAnimator.AnimatorUpdateListener;
7 | import android.annotation.SuppressLint;
8 |
9 | import lecho.lib.hellocharts.view.PieChartView;
10 |
11 | @SuppressLint("NewApi")
12 | public class PieChartRotationAnimatorV14 implements PieChartRotationAnimator, AnimatorListener, AnimatorUpdateListener {
13 | private final PieChartView chart;
14 | private ValueAnimator animator;
15 | private float startRotation = 0;
16 | private float targetRotation = 0;
17 | private ChartAnimationListener animationListener = new DummyChartAnimationListener();
18 |
19 | public PieChartRotationAnimatorV14(PieChartView chart) {
20 | this(chart, FAST_ANIMATION_DURATION);
21 | }
22 |
23 | public PieChartRotationAnimatorV14(PieChartView chart, long duration) {
24 | this.chart = chart;
25 | animator = ValueAnimator.ofFloat(0.0f, 1.0f);
26 | animator.setDuration(duration);
27 | animator.addListener(this);
28 | animator.addUpdateListener(this);
29 | }
30 |
31 | @Override
32 | public void startAnimation(float startRotation, float targetRotation) {
33 | this.startRotation = (startRotation % 360 + 360) % 360;
34 | this.targetRotation = (targetRotation % 360 + 360) % 360;
35 | animator.start();
36 | }
37 |
38 | @Override
39 | public void cancelAnimation() {
40 | animator.cancel();
41 | }
42 |
43 | @Override
44 | public void onAnimationUpdate(ValueAnimator animation) {
45 | float scale = animation.getAnimatedFraction();
46 | float rotation = startRotation + (targetRotation - startRotation) * scale;
47 | rotation = (rotation % 360 + 360) % 360;
48 | chart.setChartRotation((int) rotation, false);
49 | }
50 |
51 | @Override
52 | public void onAnimationCancel(Animator animation) {
53 | }
54 |
55 | @Override
56 | public void onAnimationEnd(Animator animation) {
57 | chart.setChartRotation((int) targetRotation, false);
58 | animationListener.onAnimationFinished();
59 | }
60 |
61 | @Override
62 | public void onAnimationRepeat(Animator animation) {
63 | }
64 |
65 | @Override
66 | public void onAnimationStart(Animator animation) {
67 | animationListener.onAnimationStarted();
68 | }
69 |
70 | @Override
71 | public boolean isAnimationStarted() {
72 | return animator.isStarted();
73 | }
74 |
75 | @Override
76 | public void setChartAnimationListener(ChartAnimationListener animationListener) {
77 | if (null == animationListener) {
78 | this.animationListener = new DummyChartAnimationListener();
79 | } else {
80 | this.animationListener = animationListener;
81 | }
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/animation/PieChartRotationAnimatorV8.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.animation;
2 |
3 | import android.os.Handler;
4 | import android.os.SystemClock;
5 | import android.view.animation.AccelerateDecelerateInterpolator;
6 | import android.view.animation.Interpolator;
7 |
8 | import lecho.lib.hellocharts.view.PieChartView;
9 |
10 | public class PieChartRotationAnimatorV8 implements PieChartRotationAnimator {
11 |
12 | final PieChartView chart;
13 | final long duration;
14 | final Handler handler;
15 | final Interpolator interpolator = new AccelerateDecelerateInterpolator();
16 | long start;
17 | boolean isAnimationStarted = false;
18 | private float startRotation = 0;
19 | private float targetRotation = 0;
20 | private ChartAnimationListener animationListener = new DummyChartAnimationListener();
21 | private final Runnable runnable = new Runnable() {
22 |
23 | @Override
24 | public void run() {
25 | long elapsed = SystemClock.uptimeMillis() - start;
26 | if (elapsed > duration) {
27 | isAnimationStarted = false;
28 | handler.removeCallbacks(runnable);
29 | chart.setChartRotation((int) targetRotation, false);
30 | animationListener.onAnimationFinished();
31 | return;
32 | }
33 | float scale = Math.min(interpolator.getInterpolation((float) elapsed / duration), 1);
34 | float rotation = startRotation + (targetRotation - startRotation) * scale;
35 | rotation = (rotation % 360 + 360) % 360;
36 | chart.setChartRotation((int) rotation, false);
37 | handler.postDelayed(this, 16);
38 | }
39 | };
40 |
41 | public PieChartRotationAnimatorV8(PieChartView chart) {
42 | this(chart, FAST_ANIMATION_DURATION);
43 | }
44 |
45 | public PieChartRotationAnimatorV8(PieChartView chart, long duration) {
46 | this.chart = chart;
47 | this.duration = duration;
48 | this.handler = new Handler();
49 | }
50 |
51 | @Override
52 | public void startAnimation(float startRotation, float targetRotation) {
53 | this.startRotation = (startRotation % 360 + 360) % 360;
54 | this.targetRotation = (targetRotation % 360 + 360) % 360;
55 | isAnimationStarted = true;
56 | animationListener.onAnimationStarted();
57 | start = SystemClock.uptimeMillis();
58 | handler.post(runnable);
59 | }
60 |
61 | @Override
62 | public void cancelAnimation() {
63 | isAnimationStarted = false;
64 | handler.removeCallbacks(runnable);
65 | chart.setChartRotation((int) targetRotation, false);
66 | animationListener.onAnimationFinished();
67 | }
68 |
69 | @Override
70 | public boolean isAnimationStarted() {
71 | return isAnimationStarted;
72 | }
73 |
74 | @Override
75 | public void setChartAnimationListener(ChartAnimationListener animationListener) {
76 | if (null == animationListener) {
77 | this.animationListener = new DummyChartAnimationListener();
78 | } else {
79 | this.animationListener = animationListener;
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/computator/PreviewChartComputator.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.computator;
2 |
3 | import lecho.lib.hellocharts.model.Viewport;
4 |
5 | /**
6 | * Version of ChartComputator for preview charts. It always uses maxViewport as visible viewport and currentViewport as
7 | * preview area.
8 | */
9 | public class PreviewChartComputator extends ChartComputator {
10 |
11 | public float computeRawX(float valueX) {
12 | final float pixelOffset = (valueX - maxViewport.left) * (contentRectMinusAllMargins.width() / maxViewport
13 | .width());
14 | return contentRectMinusAllMargins.left + pixelOffset;
15 | }
16 |
17 | public float computeRawY(float valueY) {
18 | final float pixelOffset = (valueY - maxViewport.bottom) * (contentRectMinusAllMargins.height() / maxViewport
19 | .height());
20 | return contentRectMinusAllMargins.bottom - pixelOffset;
21 | }
22 |
23 | public Viewport getVisibleViewport() {
24 | return maxViewport;
25 | }
26 |
27 | public void setVisibleViewport(Viewport visibleViewport) {
28 | setMaxViewport(visibleViewport);
29 | }
30 |
31 | public void constrainViewport(float left, float top, float right, float bottom) {
32 | super.constrainViewport(left, top, right, bottom);
33 | viewportChangeListener.onViewportChanged(currentViewport);
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/AxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 |
4 | import lecho.lib.hellocharts.model.AxisValue;
5 |
6 | public interface AxisValueFormatter {
7 |
8 | /**
9 | * Formats AxisValue for manual(custom) axis. Result is stored in (output) formattedValue array. Method
10 | * returns number of chars of formatted value. The formatted value starts at index [formattedValue.length -
11 | * charsNumber] and ends at index [formattedValue.length-1].
12 | */
13 | public int formatValueForManualAxis(char[] formattedValue, AxisValue axisValue);
14 |
15 | /**
16 | * Used only for auto-generated axes. If you are not going to use your implementation for aut-generated axes you can
17 | * skip implementation of this method and just return 0. SFormats values with given number of digits after
18 | * decimal separator. Result is stored in given array. Method returns number of chars for formatted value. The
19 | * formatted value starts at index [formattedValue.length - charsNumber] and ends at index [formattedValue
20 | * .length-1].
21 | */
22 | public int formatValueForAutoGeneratedAxis(char[] formattedValue, float value, int autoDecimalDigits);
23 | }
24 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/BubbleChartValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 | import lecho.lib.hellocharts.model.BubbleValue;
4 |
5 | public interface BubbleChartValueFormatter {
6 |
7 | public int formatChartValue(char[] formattedValue, BubbleValue value);
8 | }
9 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/ColumnChartValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 | import lecho.lib.hellocharts.model.SubcolumnValue;
4 |
5 | public interface ColumnChartValueFormatter {
6 |
7 | public int formatChartValue(char[] formattedValue, SubcolumnValue value);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/LineChartValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 |
4 | import lecho.lib.hellocharts.model.PointValue;
5 |
6 | public interface LineChartValueFormatter {
7 |
8 | public int formatChartValue(char[] formattedValue, PointValue value);
9 | }
10 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/PieChartValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 | import lecho.lib.hellocharts.model.SliceValue;
4 |
5 | public interface PieChartValueFormatter {
6 |
7 | public int formatChartValue(char[] formattedValue, SliceValue value);
8 | }
9 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/SimpleAxisValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 | import lecho.lib.hellocharts.model.AxisValue;
4 |
5 | public class SimpleAxisValueFormatter implements AxisValueFormatter {
6 |
7 | private ValueFormatterHelper valueFormatterHelper = new ValueFormatterHelper();
8 |
9 | public SimpleAxisValueFormatter() {
10 | valueFormatterHelper.determineDecimalSeparator();
11 | }
12 |
13 | public SimpleAxisValueFormatter(int decimalDigitsNumber) {
14 | this();
15 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
16 | }
17 |
18 | @Override
19 | public int formatValueForManualAxis(char[] formattedValue, AxisValue axisValue) {
20 | final int charsNumber = valueFormatterHelper.formatFloatValueWithPrependedAndAppendedText(formattedValue,
21 | axisValue.getValue(), axisValue.getLabelAsChars());
22 | return charsNumber;
23 | }
24 |
25 | @Override
26 | public int formatValueForAutoGeneratedAxis(char[] formattedValue, float value, int autoDecimalDigits) {
27 | final int charsNumber = valueFormatterHelper.formatFloatValueWithPrependedAndAppendedText(formattedValue,
28 | value, autoDecimalDigits);
29 | return charsNumber;
30 | }
31 |
32 | public int getDecimalDigitsNumber() {
33 | return valueFormatterHelper.getDecimalDigitsNumber();
34 | }
35 |
36 | public SimpleAxisValueFormatter setDecimalDigitsNumber(int decimalDigitsNumber) {
37 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
38 | return this;
39 | }
40 |
41 | public char[] getAppendedText() {
42 | return valueFormatterHelper.getAppendedText();
43 | }
44 |
45 | public SimpleAxisValueFormatter setAppendedText(char[] appendedText) {
46 | valueFormatterHelper.setAppendedText(appendedText);
47 | return this;
48 | }
49 |
50 | public char[] getPrependedText() {
51 | return valueFormatterHelper.getPrependedText();
52 | }
53 |
54 | public SimpleAxisValueFormatter setPrependedText(char[] prependedText) {
55 | valueFormatterHelper.setPrependedText(prependedText);
56 | return this;
57 | }
58 |
59 | public char getDecimalSeparator() {
60 | return valueFormatterHelper.getDecimalSeparator();
61 | }
62 |
63 | public SimpleAxisValueFormatter setDecimalSeparator(char decimalSeparator) {
64 | valueFormatterHelper.setDecimalSeparator(decimalSeparator);
65 | return this;
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/SimpleBubbleChartValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 | import lecho.lib.hellocharts.model.BubbleValue;
4 |
5 |
6 | public class SimpleBubbleChartValueFormatter implements BubbleChartValueFormatter {
7 |
8 | private ValueFormatterHelper valueFormatterHelper = new ValueFormatterHelper();
9 |
10 | public SimpleBubbleChartValueFormatter() {
11 | valueFormatterHelper.determineDecimalSeparator();
12 | }
13 |
14 | public SimpleBubbleChartValueFormatter(int decimalDigitsNumber) {
15 | this();
16 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
17 | }
18 |
19 | @Override
20 | public int formatChartValue(char[] formattedValue, BubbleValue value) {
21 | return valueFormatterHelper.formatFloatValueWithPrependedAndAppendedText(formattedValue, value.getZ(), value
22 | .getLabelAsChars());
23 | }
24 |
25 | public int getDecimalDigitsNumber() {
26 | return valueFormatterHelper.getDecimalDigitsNumber();
27 | }
28 |
29 | public SimpleBubbleChartValueFormatter setDecimalDigitsNumber(int decimalDigitsNumber) {
30 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
31 | return this;
32 | }
33 |
34 | public char[] getAppendedText() {
35 | return valueFormatterHelper.getAppendedText();
36 | }
37 |
38 | public SimpleBubbleChartValueFormatter setAppendedText(char[] appendedText) {
39 | valueFormatterHelper.setAppendedText(appendedText);
40 | return this;
41 | }
42 |
43 | public char[] getPrependedText() {
44 | return valueFormatterHelper.getPrependedText();
45 | }
46 |
47 | public SimpleBubbleChartValueFormatter setPrependedText(char[] prependedText) {
48 | valueFormatterHelper.setPrependedText(prependedText);
49 | return this;
50 | }
51 |
52 | public char getDecimalSeparator() {
53 | return valueFormatterHelper.getDecimalSeparator();
54 | }
55 |
56 | public SimpleBubbleChartValueFormatter setDecimalSeparator(char decimalSeparator) {
57 | valueFormatterHelper.setDecimalSeparator(decimalSeparator);
58 | return this;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/SimpleColumnChartValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 | import lecho.lib.hellocharts.model.SubcolumnValue;
4 |
5 | public class SimpleColumnChartValueFormatter implements ColumnChartValueFormatter {
6 |
7 | private ValueFormatterHelper valueFormatterHelper = new ValueFormatterHelper();
8 |
9 | public SimpleColumnChartValueFormatter() {
10 | valueFormatterHelper.determineDecimalSeparator();
11 | }
12 |
13 | public SimpleColumnChartValueFormatter(int decimalDigitsNumber) {
14 | this();
15 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
16 | }
17 |
18 | @Override
19 | public int formatChartValue(char[] formattedValue, SubcolumnValue value) {
20 | return valueFormatterHelper.formatFloatValueWithPrependedAndAppendedText(formattedValue, value.getValue(),
21 | value.getLabelAsChars());
22 | }
23 |
24 | public int getDecimalDigitsNumber() {
25 | return valueFormatterHelper.getDecimalDigitsNumber();
26 | }
27 |
28 | public SimpleColumnChartValueFormatter setDecimalDigitsNumber(int decimalDigitsNumber) {
29 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
30 | return this;
31 | }
32 |
33 | public char[] getAppendedText() {
34 | return valueFormatterHelper.getAppendedText();
35 | }
36 |
37 | public SimpleColumnChartValueFormatter setAppendedText(char[] appendedText) {
38 | valueFormatterHelper.setAppendedText(appendedText);
39 | return this;
40 | }
41 |
42 | public char[] getPrependedText() {
43 | return valueFormatterHelper.getPrependedText();
44 | }
45 |
46 | public SimpleColumnChartValueFormatter setPrependedText(char[] prependedText) {
47 | valueFormatterHelper.setPrependedText(prependedText);
48 | return this;
49 | }
50 |
51 | public char getDecimalSeparator() {
52 | return valueFormatterHelper.getDecimalSeparator();
53 | }
54 |
55 | public SimpleColumnChartValueFormatter setDecimalSeparator(char decimalSeparator) {
56 | valueFormatterHelper.setDecimalSeparator(decimalSeparator);
57 | return this;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/SimpleLineChartValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 | import lecho.lib.hellocharts.model.PointValue;
4 |
5 | public class SimpleLineChartValueFormatter implements LineChartValueFormatter {
6 |
7 | private ValueFormatterHelper valueFormatterHelper = new ValueFormatterHelper();
8 |
9 | public SimpleLineChartValueFormatter() {
10 | valueFormatterHelper.determineDecimalSeparator();
11 | }
12 |
13 | public SimpleLineChartValueFormatter(int decimalDigitsNumber) {
14 | this();
15 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
16 | }
17 |
18 | @Override
19 | public int formatChartValue(char[] formattedValue, PointValue value) {
20 | return valueFormatterHelper.formatFloatValueWithPrependedAndAppendedText(formattedValue, value.getY(), value
21 | .getLabelAsChars());
22 | }
23 |
24 | public int getDecimalDigitsNumber() {
25 | return valueFormatterHelper.getDecimalDigitsNumber();
26 | }
27 |
28 | public SimpleLineChartValueFormatter setDecimalDigitsNumber(int decimalDigitsNumber) {
29 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
30 | return this;
31 | }
32 |
33 | public char[] getAppendedText() {
34 | return valueFormatterHelper.getAppendedText();
35 | }
36 |
37 | public SimpleLineChartValueFormatter setAppendedText(char[] appendedText) {
38 | valueFormatterHelper.setAppendedText(appendedText);
39 | return this;
40 | }
41 |
42 | public char[] getPrependedText() {
43 | return valueFormatterHelper.getPrependedText();
44 | }
45 |
46 | public SimpleLineChartValueFormatter setPrependedText(char[] prependedText) {
47 | valueFormatterHelper.setPrependedText(prependedText);
48 | return this;
49 | }
50 |
51 | public char getDecimalSeparator() {
52 | return valueFormatterHelper.getDecimalSeparator();
53 | }
54 |
55 | public SimpleLineChartValueFormatter setDecimalSeparator(char decimalSeparator) {
56 | valueFormatterHelper.setDecimalSeparator(decimalSeparator);
57 | return this;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/formatter/SimplePieChartValueFormatter.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.formatter;
2 |
3 | import lecho.lib.hellocharts.model.SliceValue;
4 |
5 |
6 | public class SimplePieChartValueFormatter implements PieChartValueFormatter {
7 |
8 | private ValueFormatterHelper valueFormatterHelper = new ValueFormatterHelper();
9 |
10 | public SimplePieChartValueFormatter() {
11 | valueFormatterHelper.determineDecimalSeparator();
12 | }
13 |
14 | public SimplePieChartValueFormatter(int decimalDigitsNumber) {
15 | this();
16 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
17 | }
18 |
19 | @Override
20 | public int formatChartValue(char[] formattedValue, SliceValue value) {
21 | return valueFormatterHelper.formatFloatValueWithPrependedAndAppendedText(formattedValue, value.getValue(),
22 | value.getLabelAsChars());
23 | }
24 |
25 | public int getDecimalDigitsNumber() {
26 | return valueFormatterHelper.getDecimalDigitsNumber();
27 | }
28 |
29 | public SimplePieChartValueFormatter setDecimalDigitsNumber(int decimalDigitsNumber) {
30 | valueFormatterHelper.setDecimalDigitsNumber(decimalDigitsNumber);
31 | return this;
32 | }
33 |
34 | public char[] getAppendedText() {
35 | return valueFormatterHelper.getAppendedText();
36 | }
37 |
38 | public SimplePieChartValueFormatter setAppendedText(char[] appendedText) {
39 | valueFormatterHelper.setAppendedText(appendedText);
40 | return this;
41 | }
42 |
43 | public char[] getPrependedText() {
44 | return valueFormatterHelper.getPrependedText();
45 | }
46 |
47 | public SimplePieChartValueFormatter setPrependedText(char[] prependedText) {
48 | valueFormatterHelper.setPrependedText(prependedText);
49 | return this;
50 | }
51 |
52 | public char getDecimalSeparator() {
53 | return valueFormatterHelper.getDecimalSeparator();
54 | }
55 |
56 | public SimplePieChartValueFormatter setDecimalSeparator(char decimalSeparator) {
57 | valueFormatterHelper.setDecimalSeparator(decimalSeparator);
58 | return this;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/gesture/ContainerScrollType.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.gesture;
2 |
3 | /**
4 | * Enum used to inform chart in which type of container it exists.
5 | */
6 | public enum ContainerScrollType {
7 | HORIZONTAL, VERTICAL
8 | }
9 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/gesture/PreviewChartTouchHandler.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.gesture;
2 |
3 | import android.content.Context;
4 | import android.view.GestureDetector;
5 | import android.view.MotionEvent;
6 | import android.view.ScaleGestureDetector;
7 |
8 | import lecho.lib.hellocharts.view.Chart;
9 |
10 | /**
11 | * Touch Handler for preview charts. It scroll and zoom only preview area, not all preview chart data.
12 | */
13 | public class PreviewChartTouchHandler extends ChartTouchHandler {
14 |
15 | public PreviewChartTouchHandler(Context context, Chart chart) {
16 | super(context, chart);
17 | gestureDetector = new GestureDetector(context, new PreviewChartGestureListener());
18 | scaleGestureDetector = new ScaleGestureDetector(context, new ChartScaleGestureListener());
19 |
20 | // Disable value touch and selection mode, by default not needed for preview chart.
21 | isValueTouchEnabled = false;
22 | isValueSelectionEnabled = false;
23 | }
24 |
25 | protected class ChartScaleGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
26 |
27 | @Override
28 | public boolean onScale(ScaleGestureDetector detector) {
29 | if (isZoomEnabled) {
30 | float scale = detector.getCurrentSpan() / detector.getPreviousSpan();
31 | if (Float.isInfinite(scale)) {
32 | scale = 1;
33 | }
34 | return chartZoomer.scale(computator, detector.getFocusX(), detector.getFocusY(), scale);
35 | }
36 |
37 | return false;
38 | }
39 | }
40 |
41 | protected class PreviewChartGestureListener extends ChartGestureListener {
42 |
43 | @Override
44 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
45 | return super.onScroll(e1, e2, -distanceX, -distanceY);
46 | }
47 |
48 | @Override
49 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
50 | return super.onFling(e1, e2, -velocityX, -velocityY);
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/gesture/ZoomType.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.gesture;
2 |
3 | public enum ZoomType {
4 |
5 | HORIZONTAL, VERTICAL, HORIZONTAL_AND_VERTICAL;
6 | }
7 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/gesture/ZoomerCompat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package lecho.lib.hellocharts.gesture;
18 |
19 | import android.content.Context;
20 | import android.os.SystemClock;
21 | import android.view.animation.DecelerateInterpolator;
22 | import android.view.animation.Interpolator;
23 |
24 | /**
25 | * A simple class that animates double-touch zoom gestures. Functionally similar to a {@link android.widget.Scroller}.
26 | */
27 | public class ZoomerCompat {
28 | private static final int DEFAULT_SHORT_ANIMATION_DURATION = 200;
29 | /**
30 | * The interpolator, used for making zooms animate 'naturally.'
31 | */
32 | private Interpolator mInterpolator;
33 |
34 | /**
35 | * The total animation duration for a zoom.
36 | */
37 | private long mAnimationDurationMillis;
38 |
39 | /**
40 | * Whether or not the current zoom has finished.
41 | */
42 | private boolean mFinished = true;
43 |
44 | /**
45 | * The current zoom value; computed by {@link #computeZoom()}.
46 | */
47 | private float mCurrentZoom;
48 |
49 | /**
50 | * The time the zoom started, computed using {@link android.os.SystemClock#elapsedRealtime()}.
51 | */
52 | private long mStartRTC;
53 |
54 | /**
55 | * The destination zoom factor.
56 | */
57 | private float mEndZoom;
58 |
59 | public ZoomerCompat(Context context) {
60 | mInterpolator = new DecelerateInterpolator();
61 | // TODO: use constant
62 | mAnimationDurationMillis = DEFAULT_SHORT_ANIMATION_DURATION;
63 | }
64 |
65 | /**
66 | * Forces the zoom finished state to the given value. Unlike {@link #abortAnimation()}, the current zoom value isn't
67 | * set to the ending value.
68 | *
69 | * @see android.widget.Scroller#forceFinished(boolean)
70 | */
71 | public void forceFinished(boolean finished) {
72 | mFinished = finished;
73 | }
74 |
75 | /**
76 | * Aborts the animation, setting the current zoom value to the ending value.
77 | *
78 | * @see android.widget.Scroller#abortAnimation()
79 | */
80 | public void abortAnimation() {
81 | mFinished = true;
82 | mCurrentZoom = mEndZoom;
83 | }
84 |
85 | /**
86 | * Starts a zoom from 1.0 to (1.0 + endZoom). That is, to zoom from 100% to 125%, endZoom should by 0.25f.
87 | *
88 | * @see android.widget.Scroller#startScroll(int, int, int, int)
89 | */
90 | public void startZoom(float endZoom) {
91 | mStartRTC = SystemClock.elapsedRealtime();
92 | mEndZoom = endZoom;
93 |
94 | mFinished = false;
95 | mCurrentZoom = 1f;
96 | }
97 |
98 | /**
99 | * Computes the current zoom level, returning true if the zoom is still active and false if the zoom has finished.
100 | *
101 | * @see android.widget.Scroller#computeScrollOffset()
102 | */
103 | public boolean computeZoom() {
104 | if (mFinished) {
105 | return false;
106 | }
107 |
108 | long tRTC = SystemClock.elapsedRealtime() - mStartRTC;
109 | if (tRTC >= mAnimationDurationMillis) {
110 | mFinished = true;
111 | mCurrentZoom = mEndZoom;
112 | return false;
113 | }
114 |
115 | float t = tRTC * 1f / mAnimationDurationMillis;
116 | mCurrentZoom = mEndZoom * mInterpolator.getInterpolation(t);
117 | return true;
118 | }
119 |
120 | /**
121 | * Returns the current zoom level.
122 | *
123 | * @see android.widget.Scroller#getCurrX()
124 | */
125 | public float getCurrZoom() {
126 | return mCurrentZoom;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/BubbleChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.BubbleValue;
5 |
6 | public interface BubbleChartOnValueSelectListener extends OnValueDeselectListener {
7 |
8 | public void onValueSelected(int bubbleIndex, BubbleValue value);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/ColumnChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.SubcolumnValue;
5 |
6 | public interface ColumnChartOnValueSelectListener extends OnValueDeselectListener {
7 |
8 | public void onValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/ComboLineColumnChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.PointValue;
5 | import lecho.lib.hellocharts.model.SubcolumnValue;
6 |
7 | public interface ComboLineColumnChartOnValueSelectListener extends OnValueDeselectListener {
8 |
9 | public void onColumnValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value);
10 |
11 | public void onPointValueSelected(int lineIndex, int pointIndex, PointValue value);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/DummyBubbleChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.BubbleValue;
5 |
6 | public class DummyBubbleChartOnValueSelectListener implements BubbleChartOnValueSelectListener {
7 |
8 | @Override
9 | public void onValueSelected(int bubbleIndex, BubbleValue value) {
10 |
11 | }
12 |
13 | @Override
14 | public void onValueDeselected() {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/DummyColumnChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.SubcolumnValue;
5 |
6 | public class DummyColumnChartOnValueSelectListener implements ColumnChartOnValueSelectListener {
7 |
8 | @Override
9 | public void onValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value) {
10 |
11 | }
12 |
13 | @Override
14 | public void onValueDeselected() {
15 |
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/DummyCompoLineColumnChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.PointValue;
5 | import lecho.lib.hellocharts.model.SubcolumnValue;
6 |
7 | public class DummyCompoLineColumnChartOnValueSelectListener implements ComboLineColumnChartOnValueSelectListener {
8 |
9 | @Override
10 | public void onColumnValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value) {
11 |
12 | }
13 |
14 | @Override
15 | public void onPointValueSelected(int lineIndex, int pointIndex, PointValue value) {
16 |
17 | }
18 |
19 | @Override
20 | public void onValueDeselected() {
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/DummyLineChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.PointValue;
5 |
6 | public class DummyLineChartOnValueSelectListener implements LineChartOnValueSelectListener {
7 |
8 | @Override
9 | public void onValueSelected(int lineIndex, int pointIndex, PointValue value) {
10 |
11 | }
12 |
13 | @Override
14 | public void onValueDeselected() {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/DummyPieChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.SliceValue;
5 |
6 | public class DummyPieChartOnValueSelectListener implements PieChartOnValueSelectListener {
7 |
8 | @Override
9 | public void onValueSelected(int arcIndex, SliceValue value) {
10 |
11 | }
12 |
13 | @Override
14 | public void onValueDeselected() {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/DummyVieportChangeListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 | import lecho.lib.hellocharts.model.Viewport;
4 |
5 | public class DummyVieportChangeListener implements ViewportChangeListener {
6 |
7 | @Override
8 | public void onViewportChanged(Viewport viewport) {
9 | // Do nothing
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/LineChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.PointValue;
5 |
6 | public interface LineChartOnValueSelectListener extends OnValueDeselectListener {
7 |
8 | public void onValueSelected(int lineIndex, int pointIndex, PointValue value);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/OnValueDeselectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | public interface OnValueDeselectListener {
5 |
6 | /**
7 | * Called only in chart selection mode when user touch empty space causing value deselection.
8 | * Note: this method is not called when selection mode is disabled.
9 | */
10 | public void onValueDeselected();
11 | }
12 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/PieChartOnValueSelectListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 |
4 | import lecho.lib.hellocharts.model.SliceValue;
5 |
6 | public interface PieChartOnValueSelectListener extends OnValueDeselectListener {
7 |
8 | public void onValueSelected(int arcIndex, SliceValue value);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/listener/ViewportChangeListener.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.listener;
2 |
3 | import lecho.lib.hellocharts.model.Viewport;
4 |
5 | /**
6 | * Use implementations of this listener to be notified when chart viewport changed. For now it works only for preview
7 | * charts. To make it works for other chart types you just need to uncomment last line in
8 | * {@link lecho.lib.hellocharts.computator.ChartComputator#constrainViewport(float, float, float, float)} method.
9 | */
10 | public interface ViewportChangeListener {
11 |
12 | /**
13 | * Called when current viewport of chart changed. You should not modify that viewport.
14 | */
15 | public void onViewportChanged(Viewport viewport);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/AxisValue.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | import java.util.Arrays;
4 |
5 | /**
6 | * Single axis value, use it to manually set axis labels position. You can use label attribute to display text instead
7 | * of number but value formatter implementation have to handle it.
8 | */
9 | public class AxisValue {
10 | private float value;
11 | private char[] label;
12 |
13 | public AxisValue(float value) {
14 | setValue(value);
15 | }
16 |
17 | @Deprecated
18 | public AxisValue(float value, char[] label) {
19 | this.value = value;
20 | this.label = label;
21 | }
22 |
23 | public AxisValue(AxisValue axisValue) {
24 | this.value = axisValue.value;
25 | this.label = axisValue.label;
26 | }
27 |
28 | public float getValue() {
29 | return value;
30 | }
31 |
32 | public AxisValue setValue(float value) {
33 | this.value = value;
34 | return this;
35 | }
36 |
37 | @Deprecated
38 | public char[] getLabel() {
39 | return label;
40 | }
41 |
42 | /**
43 | * Set custom label for this axis value.
44 | *
45 | * @param label
46 | */
47 | public AxisValue setLabel(String label) {
48 | this.label = label.toCharArray();
49 | return this;
50 | }
51 |
52 | public char[] getLabelAsChars() {
53 | return label;
54 | }
55 |
56 | /**
57 | * Set custom label for this axis value.
58 | *
59 | * @param label
60 | */
61 | @Deprecated
62 | public AxisValue setLabel(char[] label) {
63 | this.label = label;
64 | return this;
65 | }
66 |
67 | @Override
68 | public boolean equals(Object o) {
69 | if (this == o) return true;
70 | if (o == null || getClass() != o.getClass()) return false;
71 |
72 | AxisValue axisValue = (AxisValue) o;
73 |
74 | if (Float.compare(axisValue.value, value) != 0) return false;
75 | if (!Arrays.equals(label, axisValue.label)) return false;
76 |
77 | return true;
78 | }
79 |
80 | @Override
81 | public int hashCode() {
82 | int result = (value != +0.0f ? Float.floatToIntBits(value) : 0);
83 | result = 31 * result + (label != null ? Arrays.hashCode(label) : 0);
84 | return result;
85 | }
86 | }
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/ChartData.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | import android.graphics.Typeface;
4 |
5 | /**
6 | * Base interface for all chart data models.
7 | */
8 | public interface ChartData {
9 |
10 | /**
11 | * Updates data by scale during animation.
12 | *
13 | * @param scale value from 0 to 1.0
14 | */
15 | public void update(float scale);
16 |
17 | /**
18 | * Inform data that animation finished(data should be update with scale 1.0f).
19 | */
20 | public void finish();
21 |
22 | /**
23 | * @see #setAxisXBottom(Axis)
24 | */
25 | public Axis getAxisXBottom();
26 |
27 | /**
28 | * Set horizontal axis at the bottom of the chart. Pass null to remove that axis.
29 | *
30 | * @param axisX
31 | */
32 | public void setAxisXBottom(Axis axisX);
33 |
34 | /**
35 | * @see #setAxisYLeft(Axis)
36 | */
37 | public Axis getAxisYLeft();
38 |
39 | /**
40 | * Set vertical axis on the left of the chart. Pass null to remove that axis.
41 | *
42 | * @param axisY
43 | */
44 | public void setAxisYLeft(Axis axisY);
45 |
46 | /**
47 | * @see #setAxisXTop(Axis)
48 | */
49 | public Axis getAxisXTop();
50 |
51 | /**
52 | * Set horizontal axis at the top of the chart. Pass null to remove that axis.
53 | *
54 | * @param axisX
55 | */
56 | public void setAxisXTop(Axis axisX);
57 |
58 | /**
59 | * @see #setAxisYRight(Axis)
60 | */
61 | public Axis getAxisYRight();
62 |
63 | /**
64 | * Set vertical axis on the right of the chart. Pass null to remove that axis.
65 | *
66 | * @param axisY
67 | */
68 | public void setAxisYRight(Axis axisY);
69 |
70 | /**
71 | * Returns color used to draw value label text.
72 | */
73 | public int getValueLabelTextColor();
74 |
75 | /**
76 | * Set value label text color, by default Color.WHITE.
77 | */
78 | public void setValueLabelsTextColor(int labelsTextColor);
79 |
80 | /**
81 | * Returns text size for value label in SP units.
82 | */
83 | public int getValueLabelTextSize();
84 |
85 | /**
86 | * Set text size for value label in SP units.
87 | */
88 | public void setValueLabelTextSize(int labelsTextSize);
89 |
90 | /**
91 | * Returns Typeface for value labels.
92 | *
93 | * @return Typeface or null if Typeface is not set.
94 | */
95 | public Typeface getValueLabelTypeface();
96 |
97 | /**
98 | * Set Typeface for all values labels.
99 | *
100 | * @param typeface
101 | */
102 | public void setValueLabelTypeface(Typeface typeface);
103 |
104 | /**
105 | * @see #setValueLabelBackgroundEnabled(boolean)
106 | */
107 | public boolean isValueLabelBackgroundEnabled();
108 |
109 | /**
110 | * Set whether labels should have rectangle background. Default is true.
111 | */
112 | public void setValueLabelBackgroundEnabled(boolean isValueLabelBackgroundEnabled);
113 |
114 | /**
115 | * @see #setValueLabelBackgroundAuto(boolean)
116 | */
117 | public boolean isValueLabelBackgroundAuto();
118 |
119 | /**
120 | * Set false if you want to set custom color for all value labels. Default is true.
121 | */
122 | public void setValueLabelBackgroundAuto(boolean isValueLabelBackgrountAuto);
123 |
124 | /**
125 | * @see #setValueLabelBackgroundColor(int)
126 | */
127 | public int getValueLabelBackgroundColor();
128 |
129 | /**
130 | * Set value labels background. This value is used only if isValueLabelBackgroundAuto returns false. Default is
131 | * green.
132 | */
133 | public void setValueLabelBackgroundColor(int valueLabelBackgroundColor);
134 | }
135 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/Column.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import lecho.lib.hellocharts.formatter.ColumnChartValueFormatter;
7 | import lecho.lib.hellocharts.formatter.SimpleColumnChartValueFormatter;
8 | import lecho.lib.hellocharts.view.Chart;
9 |
10 | /**
11 | * Single column for ColumnChart. One column can be divided into multiple sub-columns(ColumnValues) especially for
12 | * stacked ColumnChart.
13 | * Note: you can set X value for columns or sub-columns, columns are by default indexed from 0 to numOfColumns-1 and
14 | * column index is used as column X value, so first column has X value 0, second clumn has X value 1 etc.
15 | * If you want to display AxisValue for given column you should initialize AxisValue with X value of that column.
16 | */
17 | public class Column {
18 | private boolean hasLabels = false;
19 | private boolean hasLabelsOnlyForSelected = false;
20 | private ColumnChartValueFormatter formatter = new SimpleColumnChartValueFormatter();
21 | // TODO: consider Collections.emptyList()
22 | private List values = new ArrayList();
23 |
24 | public Column() {
25 |
26 | }
27 |
28 | public Column(List values) {
29 | setValues(values);
30 | }
31 |
32 | public Column(Column column) {
33 | this.hasLabels = column.hasLabels;
34 | this.hasLabelsOnlyForSelected = column.hasLabelsOnlyForSelected;
35 | this.formatter = column.formatter;
36 |
37 | for (SubcolumnValue columnValue : column.values) {
38 | this.values.add(new SubcolumnValue(columnValue));
39 | }
40 | }
41 |
42 | public void update(float scale) {
43 | for (SubcolumnValue value : values) {
44 | value.update(scale);
45 | }
46 |
47 | }
48 |
49 | public void finish() {
50 | for (SubcolumnValue value : values) {
51 | value.finish();
52 | }
53 | }
54 |
55 | public List getValues() {
56 | return values;
57 | }
58 |
59 | public Column setValues(List values) {
60 | if (null == values) {
61 | this.values = new ArrayList();
62 | } else {
63 | this.values = values;
64 | }
65 | return this;
66 | }
67 |
68 | public boolean hasLabels() {
69 | return hasLabels;
70 | }
71 |
72 | public Column setHasLabels(boolean hasLabels) {
73 | this.hasLabels = hasLabels;
74 | if (hasLabels) {
75 | this.hasLabelsOnlyForSelected = false;
76 | }
77 | return this;
78 | }
79 |
80 | /**
81 | * @see #setHasLabelsOnlyForSelected(boolean)
82 | */
83 | public boolean hasLabelsOnlyForSelected() {
84 | return hasLabelsOnlyForSelected;
85 | }
86 |
87 | /**
88 | * Set true if you want to show value labels only for selected value, works best when chart has
89 | * isValueSelectionEnabled set to true {@link Chart#setValueSelectionEnabled(boolean)}.
90 | */
91 | public Column setHasLabelsOnlyForSelected(boolean hasLabelsOnlyForSelected) {
92 | this.hasLabelsOnlyForSelected = hasLabelsOnlyForSelected;
93 | if (hasLabelsOnlyForSelected) {
94 | this.hasLabels = false;
95 | }
96 | return this;
97 | }
98 |
99 | public ColumnChartValueFormatter getFormatter() {
100 | return formatter;
101 | }
102 |
103 | public Column setFormatter(ColumnChartValueFormatter formatter) {
104 | if (null != formatter) {
105 | this.formatter = formatter;
106 | }
107 | return this;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/ColumnChartData.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Data model for column chart. Note: you can set X value for columns or sub-columns, columns are by default indexed
8 | * from 0 to numOfColumns-1 and
9 | * column index is used as column X value, so first column has X value 0, second clumn has X value 1 etc.
10 | * If you want to display AxisValue for given column you should initialize AxisValue with X value of that column.
11 | */
12 | public class ColumnChartData extends AbstractChartData {
13 | public static final float DEFAULT_FILL_RATIO = 0.75f;
14 | public static final float DEFAULT_BASE_VALUE = 0.0f;
15 | private float fillRatio = DEFAULT_FILL_RATIO;
16 | private float baseValue = DEFAULT_BASE_VALUE;
17 | private List columns = new ArrayList();
18 | private boolean isStacked = false;
19 |
20 | public ColumnChartData() {
21 | }
22 |
23 | public ColumnChartData(List columns) {
24 | setColumns(columns);
25 | }
26 |
27 | /**
28 | * Copy constructor for deep copy.
29 | */
30 | public ColumnChartData(ColumnChartData data) {
31 | super(data);
32 | this.isStacked = data.isStacked;
33 | this.fillRatio = data.fillRatio;
34 |
35 | for (Column column : data.columns) {
36 | this.columns.add(new Column(column));
37 | }
38 | }
39 |
40 | public static ColumnChartData generateDummyData() {
41 | final int numColumns = 4;
42 | ColumnChartData data = new ColumnChartData();
43 | List columns = new ArrayList(numColumns);
44 | List values;
45 | Column column;
46 | for (int i = 1; i <= numColumns; ++i) {
47 | values = new ArrayList(numColumns);
48 | values.add(new SubcolumnValue(i));
49 | column = new Column(values);
50 | columns.add(column);
51 | }
52 |
53 | data.setColumns(columns);
54 | return data;
55 | }
56 |
57 | @Override
58 | public void update(float scale) {
59 | for (Column column : columns) {
60 | column.update(scale);
61 | }
62 |
63 | }
64 |
65 | @Override
66 | public void finish() {
67 | for (Column column : columns) {
68 | column.finish();
69 | }
70 | }
71 |
72 | public List getColumns() {
73 | return columns;
74 | }
75 |
76 | public ColumnChartData setColumns(List columns) {
77 | if (null == columns) {
78 | this.columns = new ArrayList();
79 | } else {
80 | this.columns = columns;
81 | }
82 | return this;
83 | }
84 |
85 | public boolean isStacked() {
86 | return isStacked;
87 | }
88 |
89 | /**
90 | * Set true if you want stacked column chart.
91 | *
92 | * @param isStacked
93 | * @return
94 | */
95 | public ColumnChartData setStacked(boolean isStacked) {
96 | this.isStacked = isStacked;
97 | return this;
98 | }
99 |
100 | public float getFillRatio() {
101 | return fillRatio;
102 | }
103 |
104 | /**
105 | * Set fill ration for columns, value from 0 to 1, 1 means that there will be almost no free space between columns,
106 | * 0 means that columns will have minimum width(2px).
107 | *
108 | * @param fillRatio
109 | * @return
110 | */
111 | public ColumnChartData setFillRatio(float fillRatio) {
112 | if (fillRatio < 0) {
113 | fillRatio = 0;
114 | }
115 | if (fillRatio > 1) {
116 | fillRatio = 1;
117 | }
118 | this.fillRatio = fillRatio;
119 | return this;
120 | }
121 |
122 | /**
123 | * @see #setBaseValue(float)
124 | */
125 | public float getBaseValue() {
126 | return baseValue;
127 | }
128 |
129 | /**
130 | * Set value below which values will be drawn as negative, by default 0.
131 | */
132 | public ColumnChartData setBaseValue(float baseValue) {
133 | this.baseValue = baseValue;
134 | return this;
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/ComboLineColumnChartData.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | /**
4 | * Data model for combo line-column chart. It uses ColumnChartData and LineChartData internally.
5 | */
6 | public class ComboLineColumnChartData extends AbstractChartData {
7 |
8 | private ColumnChartData columnChartData;
9 | private LineChartData lineChartData;
10 |
11 | public ComboLineColumnChartData() {
12 | this.columnChartData = new ColumnChartData();
13 | this.lineChartData = new LineChartData();
14 | }
15 |
16 | public ComboLineColumnChartData(ColumnChartData columnChartData, LineChartData lineChartData) {
17 | setColumnChartData(columnChartData);
18 | setLineChartData(lineChartData);
19 | }
20 |
21 | public ComboLineColumnChartData(ComboLineColumnChartData data) {
22 | super(data);
23 |
24 | setColumnChartData(new ColumnChartData(data.getColumnChartData()));
25 | setLineChartData(new LineChartData(data.getLineChartData()));
26 | }
27 |
28 | public static ComboLineColumnChartData generateDummyData() {
29 | ComboLineColumnChartData data = new ComboLineColumnChartData();
30 | data.setColumnChartData(ColumnChartData.generateDummyData());
31 | data.setLineChartData(LineChartData.generateDummyData());
32 | return data;
33 | }
34 |
35 | @Override
36 | public void update(float scale) {
37 | columnChartData.update(scale);
38 | lineChartData.update(scale);
39 | }
40 |
41 | @Override
42 | public void finish() {
43 | columnChartData.finish();
44 | lineChartData.finish();
45 | }
46 |
47 | public ColumnChartData getColumnChartData() {
48 | return columnChartData;
49 | }
50 |
51 | public void setColumnChartData(ColumnChartData columnChartData) {
52 | if (null == columnChartData) {
53 | this.columnChartData = new ColumnChartData();
54 | } else {
55 | this.columnChartData = columnChartData;
56 | }
57 | }
58 |
59 | public LineChartData getLineChartData() {
60 | return lineChartData;
61 | }
62 |
63 | public void setLineChartData(LineChartData lineChartData) {
64 | if (null == lineChartData) {
65 | this.lineChartData = new LineChartData();
66 | } else {
67 | this.lineChartData = lineChartData;
68 | }
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/LineChartData.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Data model for LineChartView.
8 | */
9 | public class LineChartData extends AbstractChartData {
10 | public static final float DEFAULT_BASE_VALUE = 0.0f;
11 |
12 | private List lines = new ArrayList();
13 | private float baseValue = DEFAULT_BASE_VALUE;
14 |
15 | public LineChartData() {
16 |
17 | }
18 |
19 | public LineChartData(List lines) {
20 | setLines(lines);
21 | }
22 |
23 | /**
24 | * Copy constructor to perform deep copy of chart data.
25 | */
26 | public LineChartData(LineChartData data) {
27 | super(data);
28 | this.baseValue = data.baseValue;
29 |
30 | for (Line line : data.lines) {
31 | this.lines.add(new Line(line));
32 | }
33 | }
34 |
35 | public static LineChartData generateDummyData() {
36 | final int numValues = 4;
37 | LineChartData data = new LineChartData();
38 | List values = new ArrayList(numValues);
39 | values.add(new PointValue(0, 2));
40 | values.add(new PointValue(1, 4));
41 | values.add(new PointValue(2, 3));
42 | values.add(new PointValue(3, 4));
43 | Line line = new Line(values);
44 | List lines = new ArrayList(1);
45 | lines.add(line);
46 | data.setLines(lines);
47 | return data;
48 | }
49 |
50 | @Override
51 | public void update(float scale) {
52 | for (Line line : lines) {
53 | line.update(scale);
54 | }
55 | }
56 |
57 | @Override
58 | public void finish() {
59 | for (Line line : lines) {
60 | line.finish();
61 | }
62 | }
63 |
64 | public List getLines() {
65 | return lines;
66 | }
67 |
68 | public LineChartData setLines(List lines) {
69 | if (null == lines) {
70 | this.lines = new ArrayList();
71 | } else {
72 | this.lines = lines;
73 | }
74 | return this;
75 | }
76 |
77 | /**
78 | * @see #setBaseValue(float)
79 | */
80 | public float getBaseValue() {
81 | return baseValue;
82 | }
83 |
84 | /**
85 | * Set value below which values will be drawn as negative, important attribute for drawing filled area charts, by
86 | * default 0.
87 | */
88 | public LineChartData setBaseValue(float baseValue) {
89 | this.baseValue = baseValue;
90 | return this;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/PointValue.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | import java.util.Arrays;
4 |
5 | import lecho.lib.hellocharts.view.Chart;
6 |
7 | /**
8 | * Single point coordinates, used for LineChartData.
9 | */
10 | public class PointValue {
11 |
12 | private float x;
13 | private float y;
14 | private float originX;
15 | private float originY;
16 | private float diffX;
17 | private float diffY;
18 | private char[] label;
19 |
20 | public PointValue() {
21 | set(0, 0);
22 | }
23 |
24 | public PointValue(float x, float y) {
25 | set(x, y);
26 | }
27 |
28 | public PointValue(PointValue pointValue) {
29 | set(pointValue.x, pointValue.y);
30 | this.label = pointValue.label;
31 | }
32 |
33 | public void update(float scale) {
34 | x = originX + diffX * scale;
35 | y = originY + diffY * scale;
36 | }
37 |
38 | public void finish() {
39 | set(originX + diffX, originY + diffY);
40 | }
41 |
42 | public PointValue set(float x, float y) {
43 | this.x = x;
44 | this.y = y;
45 | this.originX = x;
46 | this.originY = y;
47 | this.diffX = 0;
48 | this.diffY = 0;
49 | return this;
50 | }
51 |
52 | /**
53 | * Set target values that should be reached when data animation finish then call {@link Chart#startDataAnimation()}
54 | */
55 | public PointValue setTarget(float targetX, float targetY) {
56 | set(x, y);
57 | this.diffX = targetX - originX;
58 | this.diffY = targetY - originY;
59 | return this;
60 | }
61 |
62 | public float getX() {
63 | return this.x;
64 | }
65 |
66 | public float getY() {
67 | return this.y;
68 | }
69 |
70 | @Deprecated
71 | public char[] getLabel() {
72 | return label;
73 | }
74 |
75 | public PointValue setLabel(String label) {
76 | this.label = label.toCharArray();
77 | return this;
78 | }
79 |
80 | public char[] getLabelAsChars() {
81 | return label;
82 | }
83 |
84 | @Deprecated
85 | public PointValue setLabel(char[] label) {
86 | this.label = label;
87 | return this;
88 | }
89 |
90 | @Override
91 | public String toString() {
92 | return "PointValue [x=" + x + ", y=" + y + "]";
93 | }
94 |
95 | @Override
96 | public boolean equals(Object o) {
97 | if (this == o) return true;
98 | if (o == null || getClass() != o.getClass()) return false;
99 |
100 | PointValue that = (PointValue) o;
101 |
102 | if (Float.compare(that.diffX, diffX) != 0) return false;
103 | if (Float.compare(that.diffY, diffY) != 0) return false;
104 | if (Float.compare(that.originX, originX) != 0) return false;
105 | if (Float.compare(that.originY, originY) != 0) return false;
106 | if (Float.compare(that.x, x) != 0) return false;
107 | if (Float.compare(that.y, y) != 0) return false;
108 | if (!Arrays.equals(label, that.label)) return false;
109 |
110 | return true;
111 | }
112 |
113 | @Override
114 | public int hashCode() {
115 | int result = (x != +0.0f ? Float.floatToIntBits(x) : 0);
116 | result = 31 * result + (y != +0.0f ? Float.floatToIntBits(y) : 0);
117 | result = 31 * result + (originX != +0.0f ? Float.floatToIntBits(originX) : 0);
118 | result = 31 * result + (originY != +0.0f ? Float.floatToIntBits(originY) : 0);
119 | result = 31 * result + (diffX != +0.0f ? Float.floatToIntBits(diffX) : 0);
120 | result = 31 * result + (diffY != +0.0f ? Float.floatToIntBits(diffY) : 0);
121 | result = 31 * result + (label != null ? Arrays.hashCode(label) : 0);
122 | return result;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/SelectedValue.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | /**
4 | * Holds selected values indexes, i.e. for LineChartModel it will be firstIndex=lineIndex; secondIndex=valueIndex.
5 | */
6 | public class SelectedValue {
7 |
8 | /**
9 | * First index i.e for LineChart that will be line index.
10 | */
11 | private int firstIndex;
12 |
13 | /**
14 | * Second index i.e for LineChart that will be PointValue index.
15 | */
16 | private int secondIndex;
17 |
18 | /**
19 | * Used only for combo charts, in other cases should have value NONE.
20 | */
21 | private SelectedValueType type = SelectedValueType.NONE;
22 |
23 | public SelectedValue() {
24 | clear();
25 | }
26 |
27 | public SelectedValue(int firstIndex, int secondIndex, SelectedValueType type) {
28 | set(firstIndex, secondIndex, type);
29 | }
30 |
31 | public void set(int firstIndex, int secondIndex, SelectedValueType type) {
32 | this.firstIndex = firstIndex;
33 | this.secondIndex = secondIndex;
34 | if (null != type) {
35 | this.type = type;
36 | } else {
37 | this.type = SelectedValueType.NONE;
38 | }
39 | }
40 |
41 | public void set(SelectedValue selectedValue) {
42 | this.firstIndex = selectedValue.firstIndex;
43 | this.secondIndex = selectedValue.secondIndex;
44 | this.type = selectedValue.type;
45 | }
46 |
47 | public void clear() {
48 | set(Integer.MIN_VALUE, Integer.MIN_VALUE, SelectedValueType.NONE);
49 | }
50 |
51 | /**
52 | * Return true if selected value have meaningful value.
53 | */
54 | public boolean isSet() {
55 | if (firstIndex >= 0 && secondIndex >= 0) {
56 | return true;
57 | } else {
58 | return false;
59 | }
60 | }
61 |
62 | /**
63 | * First index i.e for LineChart that will be line index.
64 | */
65 | public int getFirstIndex() {
66 | return firstIndex;
67 | }
68 |
69 | public void setFirstIndex(int firstIndex) {
70 | this.firstIndex = firstIndex;
71 | }
72 |
73 | /**
74 | * Second index i.e for LineChart that will be PointValue index.
75 | */
76 | public int getSecondIndex() {
77 | return secondIndex;
78 | }
79 |
80 | public void setSecondIndex(int secondIndex) {
81 | this.secondIndex = secondIndex;
82 | }
83 |
84 | public SelectedValueType getType() {
85 | return type;
86 | }
87 |
88 | public void setType(SelectedValueType type) {
89 | this.type = type;
90 | }
91 |
92 | @Override
93 | public int hashCode() {
94 | final int prime = 31;
95 | int result = 1;
96 | result = prime * result + firstIndex;
97 | result = prime * result + secondIndex;
98 | result = prime * result + ((type == null) ? 0 : type.hashCode());
99 | return result;
100 | }
101 |
102 | @Override
103 | public boolean equals(Object obj) {
104 | if (this == obj)
105 | return true;
106 | if (obj == null)
107 | return false;
108 | if (getClass() != obj.getClass())
109 | return false;
110 | SelectedValue other = (SelectedValue) obj;
111 | if (firstIndex != other.firstIndex)
112 | return false;
113 | if (secondIndex != other.secondIndex)
114 | return false;
115 | if (type != other.type)
116 | return false;
117 | return true;
118 | }
119 |
120 | @Override
121 | public String toString() {
122 | return "SelectedValue [firstIndex=" + firstIndex + ", secondIndex=" + secondIndex + ", type=" + type + "]";
123 | }
124 |
125 | /**
126 | * Used in combo chart to determine if selected value is used for line or column selection.
127 | */
128 | public enum SelectedValueType {
129 | NONE, LINE, COLUMN
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/SubcolumnValue.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | import java.util.Arrays;
4 |
5 | import lecho.lib.hellocharts.util.ChartUtils;
6 | import lecho.lib.hellocharts.view.Chart;
7 |
8 | /**
9 | * Single sub-column value for ColumnChart.
10 | */
11 | public class SubcolumnValue {
12 |
13 | private float value;
14 | private float originValue;
15 | private float diff;
16 | private int color = ChartUtils.DEFAULT_COLOR;
17 | private int darkenColor = ChartUtils.DEFAULT_DARKEN_COLOR;
18 | private char[] label;
19 |
20 | public SubcolumnValue() {
21 | setValue(0);
22 | }
23 |
24 | public SubcolumnValue(float value) {
25 | // point and targetPoint have to be different objects
26 | setValue(value);
27 | }
28 |
29 | public SubcolumnValue(float value, int color) {
30 | // point and targetPoint have to be different objects
31 | setValue(value);
32 | setColor(color);
33 | }
34 |
35 | public SubcolumnValue(SubcolumnValue columnValue) {
36 | setValue(columnValue.value);
37 | setColor(columnValue.color);
38 | this.label = columnValue.label;
39 | }
40 |
41 | public void update(float scale) {
42 | value = originValue + diff * scale;
43 | }
44 |
45 | public void finish() {
46 | setValue(originValue + diff);
47 | }
48 |
49 | public float getValue() {
50 | return value;
51 | }
52 |
53 | public SubcolumnValue setValue(float value) {
54 | this.value = value;
55 | this.originValue = value;
56 | this.diff = 0;
57 | return this;
58 | }
59 |
60 | /**
61 | * Set target value that should be reached when data animation finish then call {@link Chart#startDataAnimation()}
62 | *
63 | * @param target
64 | * @return
65 | */
66 | public SubcolumnValue setTarget(float target) {
67 | setValue(value);
68 | this.diff = target - originValue;
69 | return this;
70 | }
71 |
72 | public int getColor() {
73 | return color;
74 | }
75 |
76 | public SubcolumnValue setColor(int color) {
77 | this.color = color;
78 | this.darkenColor = ChartUtils.darkenColor(color);
79 | return this;
80 | }
81 |
82 | public int getDarkenColor() {
83 | return darkenColor;
84 | }
85 |
86 | @Deprecated
87 | public char[] getLabel() {
88 | return label;
89 | }
90 |
91 | public SubcolumnValue setLabel(String label) {
92 | this.label = label.toCharArray();
93 | return this;
94 | }
95 |
96 | public char[] getLabelAsChars() {
97 | return label;
98 | }
99 |
100 | @Deprecated
101 | public SubcolumnValue setLabel(char[] label) {
102 | this.label = label;
103 | return this;
104 | }
105 |
106 | @Override
107 | public String toString() {
108 | return "ColumnValue [value=" + value + "]";
109 | }
110 |
111 | @Override
112 | public boolean equals(Object o) {
113 | if (this == o) return true;
114 | if (o == null || getClass() != o.getClass()) return false;
115 |
116 | SubcolumnValue that = (SubcolumnValue) o;
117 |
118 | if (color != that.color) return false;
119 | if (darkenColor != that.darkenColor) return false;
120 | if (Float.compare(that.diff, diff) != 0) return false;
121 | if (Float.compare(that.originValue, originValue) != 0) return false;
122 | if (Float.compare(that.value, value) != 0) return false;
123 | if (!Arrays.equals(label, that.label)) return false;
124 |
125 | return true;
126 | }
127 |
128 | @Override
129 | public int hashCode() {
130 | int result = (value != +0.0f ? Float.floatToIntBits(value) : 0);
131 | result = 31 * result + (originValue != +0.0f ? Float.floatToIntBits(originValue) : 0);
132 | result = 31 * result + (diff != +0.0f ? Float.floatToIntBits(diff) : 0);
133 | result = 31 * result + color;
134 | result = 31 * result + darkenColor;
135 | result = 31 * result + (label != null ? Arrays.hashCode(label) : 0);
136 | return result;
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/model/ValueShape.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.model;
2 |
3 | public enum ValueShape {
4 | CIRCLE, SQUARE, DIAMOND
5 | }
6 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/provider/BubbleChartDataProvider.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.provider;
2 |
3 | import lecho.lib.hellocharts.model.BubbleChartData;
4 |
5 | public interface BubbleChartDataProvider {
6 |
7 | public BubbleChartData getBubbleChartData();
8 |
9 | public void setBubbleChartData(BubbleChartData data);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/provider/ColumnChartDataProvider.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.provider;
2 |
3 | import lecho.lib.hellocharts.model.ColumnChartData;
4 |
5 | public interface ColumnChartDataProvider {
6 |
7 | public ColumnChartData getColumnChartData();
8 |
9 | public void setColumnChartData(ColumnChartData data);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/provider/ComboLineColumnChartDataProvider.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.provider;
2 |
3 | import lecho.lib.hellocharts.model.ComboLineColumnChartData;
4 |
5 | public interface ComboLineColumnChartDataProvider {
6 |
7 | public ComboLineColumnChartData getComboLineColumnChartData();
8 |
9 | public void setComboLineColumnChartData(ComboLineColumnChartData data);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/provider/LineChartDataProvider.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.provider;
2 |
3 | import lecho.lib.hellocharts.model.LineChartData;
4 |
5 | public interface LineChartDataProvider {
6 |
7 | public LineChartData getLineChartData();
8 |
9 | public void setLineChartData(LineChartData data);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/provider/PieChartDataProvider.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.provider;
2 |
3 | import lecho.lib.hellocharts.model.PieChartData;
4 |
5 | public interface PieChartDataProvider {
6 |
7 | public PieChartData getPieChartData();
8 |
9 | public void setPieChartData(PieChartData data);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/renderer/ChartRenderer.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.renderer;
2 |
3 | import android.graphics.Canvas;
4 |
5 | import lecho.lib.hellocharts.model.SelectedValue;
6 | import lecho.lib.hellocharts.model.Viewport;
7 |
8 | /**
9 | * Interface for all chart renderer.
10 | */
11 | public interface ChartRenderer {
12 |
13 | public void onChartSizeChanged();
14 |
15 | public void onChartDataChanged();
16 |
17 | public void onChartViewportChanged();
18 |
19 | public void resetRenderer();
20 |
21 | /**
22 | * Draw chart data.
23 | */
24 | public void draw(Canvas canvas);
25 |
26 | /**
27 | * Draw chart data that should not be clipped to contentRect area.
28 | */
29 | public void drawUnclipped(Canvas canvas);
30 |
31 | /**
32 | * Checks if given pixel coordinates corresponds to any chart value. If yes return true and set selectedValue, if
33 | * not selectedValue should be *cleared* and method should return false.
34 | */
35 | public boolean checkTouch(float touchX, float touchY);
36 |
37 | /**
38 | * Returns true if there is value selected.
39 | */
40 | public boolean isTouched();
41 |
42 | /**
43 | * Clear value selection.
44 | */
45 | public void clearTouch();
46 |
47 | public Viewport getMaximumViewport();
48 |
49 | public void setMaximumViewport(Viewport maxViewport);
50 |
51 | public Viewport getCurrentViewport();
52 |
53 | public void setCurrentViewport(Viewport viewport);
54 |
55 | public boolean isViewportCalculationEnabled();
56 |
57 | public void setViewportCalculationEnabled(boolean isEnabled);
58 |
59 | public void selectValue(SelectedValue selectedValue);
60 |
61 | public SelectedValue getSelectedValue();
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/renderer/ComboChartRenderer.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.renderer;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import lecho.lib.hellocharts.model.Viewport;
10 | import lecho.lib.hellocharts.view.Chart;
11 |
12 | public class ComboChartRenderer extends AbstractChartRenderer {
13 |
14 | protected List renderers;
15 | protected Viewport unionViewport = new Viewport();
16 |
17 | public ComboChartRenderer(Context context, Chart chart) {
18 | super(context, chart);
19 | this.renderers = new ArrayList<>();
20 | }
21 |
22 | @Override
23 | public void onChartSizeChanged() {
24 | for (ChartRenderer renderer : renderers) {
25 | renderer.onChartSizeChanged();
26 | }
27 | }
28 |
29 | @Override
30 | public void onChartDataChanged() {
31 | super.onChartDataChanged();
32 | for (ChartRenderer renderer : renderers) {
33 | renderer.onChartDataChanged();
34 | }
35 | onChartViewportChanged();
36 | }
37 |
38 | @Override
39 | public void onChartViewportChanged() {
40 | if (isViewportCalculationEnabled) {
41 | int rendererIndex = 0;
42 | for (ChartRenderer renderer : renderers) {
43 | renderer.onChartViewportChanged();
44 | if (rendererIndex == 0) {
45 | unionViewport.set(renderer.getMaximumViewport());
46 | } else {
47 | unionViewport.union(renderer.getMaximumViewport());
48 | }
49 | ++rendererIndex;
50 | }
51 | computator.setMaxViewport(unionViewport);
52 | computator.setCurrentViewport(unionViewport);
53 | }
54 |
55 |
56 | }
57 |
58 | public void draw(Canvas canvas) {
59 | for (ChartRenderer renderer : renderers) {
60 | renderer.draw(canvas);
61 | }
62 | }
63 |
64 | @Override
65 | public void drawUnclipped(Canvas canvas) {
66 | for (ChartRenderer renderer : renderers) {
67 | renderer.drawUnclipped(canvas);
68 | }
69 | }
70 |
71 | public boolean checkTouch(float touchX, float touchY) {
72 | selectedValue.clear();
73 | int rendererIndex = renderers.size() - 1;
74 | for (; rendererIndex >= 0; rendererIndex--) {
75 | ChartRenderer renderer = renderers.get(rendererIndex);
76 | if (renderer.checkTouch(touchX, touchY)) {
77 | selectedValue.set(renderer.getSelectedValue());
78 | break;
79 | }
80 | }
81 |
82 | //clear the rest of renderers if value was selected, if value was not selected this loop
83 | // will not be executed.
84 | for (rendererIndex--; rendererIndex >= 0; rendererIndex--) {
85 | ChartRenderer renderer = renderers.get(rendererIndex);
86 | renderer.clearTouch();
87 | }
88 |
89 | return isTouched();
90 | }
91 |
92 | @Override
93 | public void clearTouch() {
94 | for (ChartRenderer renderer : renderers) {
95 | renderer.clearTouch();
96 | }
97 | selectedValue.clear();
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/renderer/ComboLineColumnChartRenderer.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.renderer;
2 |
3 | import android.content.Context;
4 |
5 | import lecho.lib.hellocharts.provider.ColumnChartDataProvider;
6 | import lecho.lib.hellocharts.provider.LineChartDataProvider;
7 | import lecho.lib.hellocharts.view.Chart;
8 |
9 | public class ComboLineColumnChartRenderer extends ComboChartRenderer {
10 |
11 | private ColumnChartRenderer columnChartRenderer;
12 | private LineChartRenderer lineChartRenderer;
13 |
14 | public ComboLineColumnChartRenderer(Context context, Chart chart, ColumnChartDataProvider columnChartDataProvider,
15 | LineChartDataProvider lineChartDataProvider) {
16 | this(context, chart, new ColumnChartRenderer(context, chart, columnChartDataProvider),
17 | new LineChartRenderer(context, chart, lineChartDataProvider));
18 | }
19 |
20 | public ComboLineColumnChartRenderer(Context context, Chart chart, ColumnChartRenderer columnChartRenderer,
21 | LineChartDataProvider lineChartDataProvider) {
22 | this(context, chart, columnChartRenderer, new LineChartRenderer(context, chart, lineChartDataProvider));
23 | }
24 |
25 | public ComboLineColumnChartRenderer(Context context, Chart chart, ColumnChartDataProvider columnChartDataProvider,
26 | LineChartRenderer lineChartRenderer) {
27 | this(context, chart, new ColumnChartRenderer(context, chart, columnChartDataProvider), lineChartRenderer);
28 | }
29 |
30 | public ComboLineColumnChartRenderer(Context context, Chart chart, ColumnChartRenderer columnChartRenderer,
31 | LineChartRenderer lineChartRenderer) {
32 | super(context, chart);
33 |
34 | this.columnChartRenderer = columnChartRenderer;
35 | this.lineChartRenderer = lineChartRenderer;
36 |
37 | renderers.add(this.columnChartRenderer);
38 | renderers.add(this.lineChartRenderer);
39 | }
40 | }
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/renderer/PreviewColumnChartRenderer.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.renderer;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 |
8 | import lecho.lib.hellocharts.model.Viewport;
9 | import lecho.lib.hellocharts.provider.ColumnChartDataProvider;
10 | import lecho.lib.hellocharts.util.ChartUtils;
11 | import lecho.lib.hellocharts.view.Chart;
12 |
13 | /**
14 | * Renderer for preview chart based on ColumnChart. In addition to drawing chart data it also draw current viewport as
15 | * preview area.
16 | */
17 | public class PreviewColumnChartRenderer extends ColumnChartRenderer {
18 | private static final int DEFAULT_PREVIEW_TRANSPARENCY = 64;
19 | private static final int FULL_ALPHA = 255;
20 | private static final int DEFAULT_PREVIEW_STROKE_WIDTH_DP = 2;
21 |
22 | private Paint previewPaint = new Paint();
23 |
24 | public PreviewColumnChartRenderer(Context context, Chart chart, ColumnChartDataProvider dataProvider) {
25 | super(context, chart, dataProvider);
26 | previewPaint.setAntiAlias(true);
27 | previewPaint.setColor(Color.LTGRAY);
28 | previewPaint.setStrokeWidth(ChartUtils.dp2px(density, DEFAULT_PREVIEW_STROKE_WIDTH_DP));
29 | }
30 |
31 | @Override
32 | public void drawUnclipped(Canvas canvas) {
33 | super.drawUnclipped(canvas);
34 | final Viewport currentViewport = computator.getCurrentViewport();
35 | final float left = computator.computeRawX(currentViewport.left);
36 | final float top = computator.computeRawY(currentViewport.top);
37 | final float right = computator.computeRawX(currentViewport.right);
38 | final float bottom = computator.computeRawY(currentViewport.bottom);
39 | previewPaint.setAlpha(DEFAULT_PREVIEW_TRANSPARENCY);
40 | previewPaint.setStyle(Paint.Style.FILL);
41 | canvas.drawRect(left, top, right, bottom, previewPaint);
42 | previewPaint.setStyle(Paint.Style.STROKE);
43 | previewPaint.setAlpha(FULL_ALPHA);
44 | canvas.drawRect(left, top, right, bottom, previewPaint);
45 | }
46 |
47 | public int getPreviewColor() {
48 | return previewPaint.getColor();
49 | }
50 |
51 | public void setPreviewColor(int color) {
52 | previewPaint.setColor(color);
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/renderer/PreviewLineChartRenderer.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.renderer;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 |
8 | import lecho.lib.hellocharts.model.Viewport;
9 | import lecho.lib.hellocharts.provider.LineChartDataProvider;
10 | import lecho.lib.hellocharts.util.ChartUtils;
11 | import lecho.lib.hellocharts.view.Chart;
12 |
13 | /**
14 | * Renderer for preview chart based on LineChart. In addition to drawing chart data it also draw current viewport as
15 | * preview area.
16 | */
17 | public class PreviewLineChartRenderer extends LineChartRenderer {
18 | private static final int DEFAULT_PREVIEW_TRANSPARENCY = 64;
19 | private static final int FULL_ALPHA = 255;
20 | private static final int DEFAULT_PREVIEW_STROKE_WIDTH_DP = 2;
21 |
22 | private Paint previewPaint = new Paint();
23 |
24 | public PreviewLineChartRenderer(Context context, Chart chart, LineChartDataProvider dataProvider) {
25 | super(context, chart, dataProvider);
26 | previewPaint.setAntiAlias(true);
27 | previewPaint.setColor(Color.LTGRAY);
28 | previewPaint.setStrokeWidth(ChartUtils.dp2px(density, DEFAULT_PREVIEW_STROKE_WIDTH_DP));
29 | }
30 |
31 | @Override
32 | public void drawUnclipped(Canvas canvas) {
33 | super.drawUnclipped(canvas);
34 | final Viewport currentViewport = computator.getCurrentViewport();
35 | final float left = computator.computeRawX(currentViewport.left);
36 | final float top = computator.computeRawY(currentViewport.top);
37 | final float right = computator.computeRawX(currentViewport.right);
38 | final float bottom = computator.computeRawY(currentViewport.bottom);
39 | previewPaint.setAlpha(DEFAULT_PREVIEW_TRANSPARENCY);
40 | previewPaint.setStyle(Paint.Style.FILL);
41 | canvas.drawRect(left, top, right, bottom, previewPaint);
42 | previewPaint.setStyle(Paint.Style.STROKE);
43 | previewPaint.setAlpha(FULL_ALPHA);
44 | canvas.drawRect(left, top, right, bottom, previewPaint);
45 | }
46 |
47 | public int getPreviewColor() {
48 | return previewPaint.getColor();
49 | }
50 |
51 | public void setPreviewColor(int color) {
52 | previewPaint.setColor(color);
53 | }
54 | }
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/util/AxisAutoValues.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.util;
2 |
3 | /**
4 | * A simple class representing axis label values used only for auto generated axes.
5 | */
6 | public class AxisAutoValues {
7 | public float[] values = new float[]{};
8 | public int valuesNumber;
9 | public int decimals;
10 | }
11 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/util/ChartUtils.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.util;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.util.TypedValue;
6 |
7 | public abstract class ChartUtils {
8 |
9 | public static final int DEFAULT_COLOR = Color.parseColor("#DFDFDF");
10 | public static final int DEFAULT_DARKEN_COLOR = Color.parseColor("#DDDDDD");
11 | public static final int COLOR_BLUE = Color.parseColor("#33B5E5");
12 | public static final int COLOR_VIOLET = Color.parseColor("#AA66CC");
13 | public static final int COLOR_GREEN = Color.parseColor("#99CC00");
14 | public static final int COLOR_ORANGE = Color.parseColor("#FFBB33");
15 | public static final int COLOR_RED = Color.parseColor("#FF4444");
16 | public static final int[] COLORS = new int[]{COLOR_BLUE, COLOR_VIOLET, COLOR_GREEN, COLOR_ORANGE, COLOR_RED};
17 | private static final float DARKEN_SATURATION = 1.1f;
18 | private static final float DARKEN_INTENSITY = 0.9f;
19 | private static int COLOR_INDEX = 0;
20 |
21 | public static final int pickColor() {
22 | return COLORS[(int) Math.round(Math.random() * (COLORS.length - 1))];
23 | }
24 |
25 | public static final int nextColor() {
26 | if (COLOR_INDEX >= COLORS.length) {
27 | COLOR_INDEX = 0;
28 | }
29 | return COLORS[COLOR_INDEX++];
30 | }
31 |
32 | public static int dp2px(float density, int dp) {
33 | if (dp == 0) {
34 | return 0;
35 | }
36 | return (int) (dp * density + 0.5f);
37 |
38 | }
39 |
40 | public static int px2dp(float density, int px) {
41 | return (int) Math.ceil(px / density);
42 | }
43 |
44 | public static int sp2px(float scaledDensity, int sp) {
45 | if (sp == 0) {
46 | return 0;
47 | }
48 | return (int) (sp * scaledDensity + 0.5f);
49 | }
50 |
51 | public static int px2sp(float scaledDensity, int px) {
52 | return (int) Math.ceil(px / scaledDensity);
53 | }
54 |
55 | public static int mm2px(Context context, int mm) {
56 | return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, mm, context.getResources()
57 | .getDisplayMetrics()) + 0.5f);
58 | }
59 |
60 | public static int darkenColor(int color) {
61 | float[] hsv = new float[3];
62 | int alpha = Color.alpha(color);
63 | Color.colorToHSV(color, hsv);
64 | hsv[1] = Math.min(hsv[1] * DARKEN_SATURATION, 1.0f);
65 | hsv[2] = hsv[2] * DARKEN_INTENSITY;
66 | int tempColor = Color.HSVToColor(hsv);
67 | return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/view/BubbleChartView.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.view;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewCompat;
5 | import android.util.AttributeSet;
6 | import android.util.Log;
7 |
8 | import lecho.lib.hellocharts.BuildConfig;
9 | import lecho.lib.hellocharts.listener.BubbleChartOnValueSelectListener;
10 | import lecho.lib.hellocharts.listener.DummyBubbleChartOnValueSelectListener;
11 | import lecho.lib.hellocharts.model.BubbleChartData;
12 | import lecho.lib.hellocharts.model.BubbleValue;
13 | import lecho.lib.hellocharts.model.ChartData;
14 | import lecho.lib.hellocharts.model.SelectedValue;
15 | import lecho.lib.hellocharts.provider.BubbleChartDataProvider;
16 | import lecho.lib.hellocharts.renderer.BubbleChartRenderer;
17 |
18 | /**
19 | * BubbleChart, supports circle bubbles and square bubbles.
20 | *
21 | * @author lecho
22 | */
23 | public class BubbleChartView extends AbstractChartView implements BubbleChartDataProvider {
24 | private static final String TAG = "BubbleChartView";
25 | protected BubbleChartData data;
26 | protected BubbleChartOnValueSelectListener onValueTouchListener = new DummyBubbleChartOnValueSelectListener();
27 |
28 | protected BubbleChartRenderer bubbleChartRenderer;
29 |
30 | public BubbleChartView(Context context) {
31 | this(context, null, 0);
32 | }
33 |
34 | public BubbleChartView(Context context, AttributeSet attrs) {
35 | this(context, attrs, 0);
36 | }
37 |
38 | public BubbleChartView(Context context, AttributeSet attrs, int defStyle) {
39 | super(context, attrs, defStyle);
40 | bubbleChartRenderer = new BubbleChartRenderer(context, this, this);
41 | setChartRenderer(bubbleChartRenderer);
42 | setBubbleChartData(BubbleChartData.generateDummyData());
43 | }
44 |
45 | @Override
46 | public BubbleChartData getBubbleChartData() {
47 | return data;
48 | }
49 |
50 | @Override
51 | public void setBubbleChartData(BubbleChartData data) {
52 | if (BuildConfig.DEBUG) {
53 | Log.d(TAG, "Setting data for BubbleChartView");
54 | }
55 |
56 | if (null == data) {
57 | this.data = BubbleChartData.generateDummyData();
58 | } else {
59 | this.data = data;
60 | }
61 |
62 | super.onChartDataChange();
63 | }
64 |
65 | @Override
66 | public ChartData getChartData() {
67 | return data;
68 | }
69 |
70 | @Override
71 | public void callTouchListener() {
72 | SelectedValue selectedValue = chartRenderer.getSelectedValue();
73 |
74 | if (selectedValue.isSet()) {
75 | BubbleValue value = data.getValues().get(selectedValue.getFirstIndex());
76 | onValueTouchListener.onValueSelected(selectedValue.getFirstIndex(), value);
77 | } else {
78 | onValueTouchListener.onValueDeselected();
79 | }
80 | }
81 |
82 | public BubbleChartOnValueSelectListener getOnValueTouchListener() {
83 | return onValueTouchListener;
84 | }
85 |
86 | public void setOnValueTouchListener(BubbleChartOnValueSelectListener touchListener) {
87 | if (null != touchListener) {
88 | this.onValueTouchListener = touchListener;
89 | }
90 | }
91 |
92 | /**
93 | * Removes empty spaces, top-bottom for portrait orientation and left-right for landscape. This method has to be
94 | * called after view View#onSizeChanged() method is called and chart data is set. This method may be inaccurate.
95 | *
96 | * @see BubbleChartRenderer#removeMargins()
97 | */
98 | public void removeMargins() {
99 | bubbleChartRenderer.removeMargins();
100 | ViewCompat.postInvalidateOnAnimation(this);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/view/ColumnChartView.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.util.Log;
6 |
7 | import lecho.lib.hellocharts.BuildConfig;
8 | import lecho.lib.hellocharts.listener.ColumnChartOnValueSelectListener;
9 | import lecho.lib.hellocharts.listener.DummyColumnChartOnValueSelectListener;
10 | import lecho.lib.hellocharts.model.ColumnChartData;
11 | import lecho.lib.hellocharts.model.SelectedValue;
12 | import lecho.lib.hellocharts.model.SubcolumnValue;
13 | import lecho.lib.hellocharts.provider.ColumnChartDataProvider;
14 | import lecho.lib.hellocharts.renderer.ColumnChartRenderer;
15 |
16 | /**
17 | * ColumnChart/BarChart, supports subcolumns, stacked collumns and negative values.
18 | *
19 | * @author Leszek Wach
20 | */
21 | public class ColumnChartView extends AbstractChartView implements ColumnChartDataProvider {
22 | private static final String TAG = "ColumnChartView";
23 | private ColumnChartData data;
24 | private ColumnChartOnValueSelectListener onValueTouchListener = new DummyColumnChartOnValueSelectListener();
25 |
26 | public ColumnChartView(Context context) {
27 | this(context, null, 0);
28 | }
29 |
30 | public ColumnChartView(Context context, AttributeSet attrs) {
31 | this(context, attrs, 0);
32 | }
33 |
34 | public ColumnChartView(Context context, AttributeSet attrs, int defStyle) {
35 | super(context, attrs, defStyle);
36 | setChartRenderer(new ColumnChartRenderer(context, this, this));
37 | setColumnChartData(ColumnChartData.generateDummyData());
38 | }
39 |
40 | @Override
41 | public ColumnChartData getColumnChartData() {
42 | return data;
43 | }
44 |
45 | @Override
46 | public void setColumnChartData(ColumnChartData data) {
47 | if (BuildConfig.DEBUG) {
48 | Log.d(TAG, "Setting data for ColumnChartView");
49 | }
50 |
51 | if (null == data) {
52 | this.data = ColumnChartData.generateDummyData();
53 | } else {
54 | this.data = data;
55 | }
56 |
57 | super.onChartDataChange();
58 |
59 | }
60 |
61 | @Override
62 | public ColumnChartData getChartData() {
63 | return data;
64 | }
65 |
66 | @Override
67 | public void callTouchListener() {
68 | SelectedValue selectedValue = chartRenderer.getSelectedValue();
69 |
70 | if (selectedValue.isSet()) {
71 | SubcolumnValue value = data.getColumns().get(selectedValue.getFirstIndex()).getValues()
72 | .get(selectedValue.getSecondIndex());
73 | onValueTouchListener.onValueSelected(selectedValue.getFirstIndex(), selectedValue.getSecondIndex(), value);
74 | } else {
75 | onValueTouchListener.onValueDeselected();
76 | }
77 | }
78 |
79 | public ColumnChartOnValueSelectListener getOnValueTouchListener() {
80 | return onValueTouchListener;
81 | }
82 |
83 | public void setOnValueTouchListener(ColumnChartOnValueSelectListener touchListener) {
84 | if (null != touchListener) {
85 | this.onValueTouchListener = touchListener;
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/view/LineChartView.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.util.Log;
6 |
7 | import lecho.lib.hellocharts.BuildConfig;
8 | import lecho.lib.hellocharts.listener.DummyLineChartOnValueSelectListener;
9 | import lecho.lib.hellocharts.listener.LineChartOnValueSelectListener;
10 | import lecho.lib.hellocharts.model.ChartData;
11 | import lecho.lib.hellocharts.model.LineChartData;
12 | import lecho.lib.hellocharts.model.PointValue;
13 | import lecho.lib.hellocharts.model.SelectedValue;
14 | import lecho.lib.hellocharts.provider.LineChartDataProvider;
15 | import lecho.lib.hellocharts.renderer.LineChartRenderer;
16 |
17 | /**
18 | * LineChart, supports cubic lines, filled lines, circle and square points. Point radius and stroke width can be
19 | * adjusted using LineChartData attributes.
20 | *
21 | * @author Leszek Wach
22 | */
23 | public class LineChartView extends AbstractChartView implements LineChartDataProvider {
24 | private static final String TAG = "LineChartView";
25 | protected LineChartData data;
26 | protected LineChartOnValueSelectListener onValueTouchListener = new DummyLineChartOnValueSelectListener();
27 |
28 | public LineChartView(Context context) {
29 | this(context, null, 0);
30 | }
31 |
32 | public LineChartView(Context context, AttributeSet attrs) {
33 | this(context, attrs, 0);
34 | }
35 |
36 | public LineChartView(Context context, AttributeSet attrs, int defStyle) {
37 | super(context, attrs, defStyle);
38 | setChartRenderer(new LineChartRenderer(context, this, this));
39 | setLineChartData(LineChartData.generateDummyData());
40 | }
41 |
42 | @Override
43 | public LineChartData getLineChartData() {
44 | return data;
45 | }
46 |
47 | @Override
48 | public void setLineChartData(LineChartData data) {
49 | if (BuildConfig.DEBUG) {
50 | Log.d(TAG, "Setting data for LineChartView");
51 | }
52 |
53 | if (null == data) {
54 | this.data = LineChartData.generateDummyData();
55 | } else {
56 | this.data = data;
57 | }
58 |
59 | super.onChartDataChange();
60 | }
61 |
62 | @Override
63 | public ChartData getChartData() {
64 | return data;
65 | }
66 |
67 | @Override
68 | public void callTouchListener() {
69 | SelectedValue selectedValue = chartRenderer.getSelectedValue();
70 |
71 | if (selectedValue.isSet()) {
72 | PointValue point = data.getLines().get(selectedValue.getFirstIndex()).getValues()
73 | .get(selectedValue.getSecondIndex());
74 | onValueTouchListener.onValueSelected(selectedValue.getFirstIndex(), selectedValue.getSecondIndex(), point);
75 | } else {
76 | onValueTouchListener.onValueDeselected();
77 | }
78 | }
79 |
80 | public LineChartOnValueSelectListener getOnValueTouchListener() {
81 | return onValueTouchListener;
82 | }
83 |
84 | public void setOnValueTouchListener(LineChartOnValueSelectListener touchListener) {
85 | if (null != touchListener) {
86 | this.onValueTouchListener = touchListener;
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/view/PreviewColumnChartView.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.view;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewCompat;
5 | import android.util.AttributeSet;
6 | import android.util.Log;
7 |
8 | import lecho.lib.hellocharts.BuildConfig;
9 | import lecho.lib.hellocharts.computator.PreviewChartComputator;
10 | import lecho.lib.hellocharts.gesture.PreviewChartTouchHandler;
11 | import lecho.lib.hellocharts.model.ColumnChartData;
12 | import lecho.lib.hellocharts.renderer.PreviewColumnChartRenderer;
13 |
14 | /**
15 | * Preview chart that can be used as overview for other ColumnChart. When you change Viewport of this chart, visible
16 | * area of other chart will change. For that you need also to use
17 | * {@link Chart#setViewportChangeListener(lecho.lib.hellocharts.listener.ViewportChangeListener)}
18 | *
19 | * @author Leszek Wach
20 | */
21 | public class PreviewColumnChartView extends ColumnChartView {
22 | private static final String TAG = "ColumnChartView";
23 |
24 | protected PreviewColumnChartRenderer previewChartRenderer;
25 |
26 | public PreviewColumnChartView(Context context) {
27 | this(context, null, 0);
28 | }
29 |
30 | public PreviewColumnChartView(Context context, AttributeSet attrs) {
31 | this(context, attrs, 0);
32 | }
33 |
34 | public PreviewColumnChartView(Context context, AttributeSet attrs, int defStyle) {
35 | super(context, attrs, defStyle);
36 | chartComputator = new PreviewChartComputator();
37 | previewChartRenderer = new PreviewColumnChartRenderer(context, this, this);
38 | touchHandler = new PreviewChartTouchHandler(context, this);
39 | setChartRenderer(previewChartRenderer);
40 | setColumnChartData(ColumnChartData.generateDummyData());
41 | }
42 |
43 | public int getPreviewColor() {
44 | return previewChartRenderer.getPreviewColor();
45 | }
46 |
47 | public void setPreviewColor(int color) {
48 | if (BuildConfig.DEBUG) {
49 | Log.d(TAG, "Changing preview area color");
50 | }
51 |
52 | previewChartRenderer.setPreviewColor(color);
53 | ViewCompat.postInvalidateOnAnimation(this);
54 | }
55 |
56 | @Override
57 | public boolean canScrollHorizontally(int direction) {
58 | final int offset = computeHorizontalScrollOffset();
59 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
60 | if (range == 0) return false;
61 | if (direction < 0) {
62 | return offset > 0;
63 | } else {
64 | return offset < range - 1;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/view/PreviewLineChartView.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.view;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewCompat;
5 | import android.util.AttributeSet;
6 | import android.util.Log;
7 |
8 | import lecho.lib.hellocharts.BuildConfig;
9 | import lecho.lib.hellocharts.computator.PreviewChartComputator;
10 | import lecho.lib.hellocharts.gesture.PreviewChartTouchHandler;
11 | import lecho.lib.hellocharts.model.LineChartData;
12 | import lecho.lib.hellocharts.renderer.PreviewLineChartRenderer;
13 |
14 | /**
15 | * Preview chart that can be used as overview for other LineChart. When you change Viewport of this chart, visible area
16 | * of other chart will change. For that you need also to use
17 | * {@link Chart#setViewportChangeListener(lecho.lib.hellocharts.listener.ViewportChangeListener)}
18 | *
19 | * @author Leszek Wach
20 | */
21 | public class PreviewLineChartView extends LineChartView {
22 | private static final String TAG = "PreviewLineChartView";
23 |
24 | protected PreviewLineChartRenderer previewChartRenderer;
25 |
26 | public PreviewLineChartView(Context context) {
27 | this(context, null, 0);
28 | }
29 |
30 | public PreviewLineChartView(Context context, AttributeSet attrs) {
31 | this(context, attrs, 0);
32 | }
33 |
34 | public PreviewLineChartView(Context context, AttributeSet attrs, int defStyle) {
35 | super(context, attrs, defStyle);
36 | chartComputator = new PreviewChartComputator();
37 | previewChartRenderer = new PreviewLineChartRenderer(context, this, this);
38 | touchHandler = new PreviewChartTouchHandler(context, this);
39 | setChartRenderer(previewChartRenderer);
40 | setLineChartData(LineChartData.generateDummyData());
41 | }
42 |
43 | public int getPreviewColor() {
44 | return previewChartRenderer.getPreviewColor();
45 | }
46 |
47 | public void setPreviewColor(int color) {
48 | if (BuildConfig.DEBUG) {
49 | Log.d(TAG, "Changing preview area color");
50 | }
51 |
52 | previewChartRenderer.setPreviewColor(color);
53 | ViewCompat.postInvalidateOnAnimation(this);
54 | }
55 |
56 | @Override
57 | public boolean canScrollHorizontally(int direction) {
58 | final int offset = computeHorizontalScrollOffset();
59 | final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
60 | if (range == 0) return false;
61 | if (direction < 0) {
62 | return offset > 0;
63 | } else {
64 | return offset < range - 1;
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/view/hack/HackyDrawerLayout.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.view.hack;
2 |
3 | import android.content.Context;
4 | import android.support.v4.widget.DrawerLayout;
5 | import android.util.AttributeSet;
6 | import android.view.MotionEvent;
7 |
8 | /**
9 | * Hacky fix for issue with DrawerLayout https://github.com/chrisbanes/PhotoView/issues/72
10 | */
11 | public class HackyDrawerLayout extends DrawerLayout {
12 |
13 | public HackyDrawerLayout(Context context) {
14 | super(context);
15 | }
16 |
17 | public HackyDrawerLayout(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | }
20 |
21 | public HackyDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
22 | super(context, attrs, defStyle);
23 | }
24 |
25 | @Override
26 | public boolean onInterceptTouchEvent(MotionEvent ev) {
27 | try {
28 | return super.onInterceptTouchEvent(ev);
29 | } catch (Exception e) {
30 | e.printStackTrace();
31 | return false;
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/hellocharts-library/src/lecho/lib/hellocharts/view/hack/HackyViewPager.java:
--------------------------------------------------------------------------------
1 | package lecho.lib.hellocharts.view.hack;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewPager;
5 | import android.util.AttributeSet;
6 | import android.view.MotionEvent;
7 |
8 | /**
9 | * ScaleGestureDetector seems to mess up the touch events, which means that ViewGroups which make use of
10 | * onInterceptTouchEvent throw a lot of IllegalArgumentException: pointerIndex out of range.There's not much I can do
11 | * in my code for now, but we can mask the result by just catching the problem and ignoring
12 | * it.
13 | *
14 | * @author Chris Banes
15 | */
16 | public class HackyViewPager extends ViewPager {
17 |
18 | public HackyViewPager(Context context) {
19 | super(context);
20 | }
21 |
22 | public HackyViewPager(final Context context, final AttributeSet attrs) {
23 | super(context, attrs);
24 | }
25 |
26 | @Override
27 | public boolean onInterceptTouchEvent(MotionEvent ev) {
28 | try {
29 | return super.onInterceptTouchEvent(ev);
30 | } catch (Exception e) {
31 | e.printStackTrace();
32 | return false;
33 | }
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/out.vp8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vonchenchen/AndroidMediacodecDemo/c602c5b22cd32f7c5cb580129e499dd21312da22/out.vp8
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':hellocharts-library'
2 |
--------------------------------------------------------------------------------