├── app
├── .gitignore
├── .settings
│ └── org.eclipse.buildship.core.prefs
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── xml
│ │ │ │ └── file_paths.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── myapplication
│ │ │ │ ├── DataPoint.java
│ │ │ │ ├── Emoji.java
│ │ │ │ ├── EmojiView.java
│ │ │ │ ├── SessionLog.java
│ │ │ │ ├── Session.java
│ │ │ │ ├── Vector3.java
│ │ │ │ ├── BumpMonitorService.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── myapplication
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── myapplication
│ │ └── ExampleInstrumentedTest.java
├── .classpath
├── .project
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .settings
└── org.eclipse.buildship.core.prefs
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
├── misc.xml
├── runConfigurations.xml
├── gradle.xml
└── codeStyles
│ └── Project.xml
├── .gitignore
├── .project
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | connection.project.dir=
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/app/.settings/org.eclipse.buildship.core.prefs:
--------------------------------------------------------------------------------
1 | connection.project.dir=..
2 | eclipse.preferences.version=1
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nitro/bump/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 | Main2Activity
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/file_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Apr 08 10:34:05 BST 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.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | @android:color/black
4 | @android:color/black
5 | #FF5252
6 | #4CAF50
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | bump
4 | Project bump created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.buildship.core.gradleprojectbuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.buildship.core.gradleprojectnature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/DataPoint.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | public class DataPoint {
4 | long time = 0;
5 | double latitude = 0;
6 | double longitude = 0;
7 | float accelerometer_x = 0.0f;
8 | float accelerometer_y = 0.0f;
9 | float accelerometer_z = 0.0f;
10 |
11 | public String toCSV() {
12 | return String.format("%d,%f,%f,%f,%f,%f\n", time, latitude, longitude, accelerometer_x, accelerometer_y, accelerometer_z);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | app
4 | Project app created by Buildship.
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.buildship.core.gradleprojectbuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.buildship.core.gradleprojectnature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/Emoji.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | public class Emoji {
4 |
5 | public String body = "";
6 | public String leftArm = "";
7 | public String rightArm = "";
8 |
9 | public Emoji(float motion) {
10 |
11 | System.out.println(motion);
12 |
13 | if (motion <= 0.2) body = "(•‿•)";
14 | else body = "(゚Д゚)";
15 |
16 | if (motion <= 0.2) {
17 | leftArm = " ";
18 | rightArm = " ";
19 | }
20 | else {
21 | leftArm = "ヽ";
22 | rightArm = "ノ";
23 | }
24 | }
25 |
26 | public String toString() {
27 | return leftArm + body + rightArm;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/EmojiView.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.TextView;
6 |
7 | public class EmojiView extends android.support.v7.widget.AppCompatTextView {
8 |
9 | public EmojiView(Context context, AttributeSet attrs, int defStyle) {
10 | super(context, attrs, defStyle);
11 | init(attrs);
12 | }
13 |
14 | public EmojiView(Context context, AttributeSet attrs) {
15 | super(context, attrs);
16 | init(attrs);
17 |
18 | }
19 |
20 | public EmojiView(Context context) {
21 | super(context);
22 | init(null);
23 | }
24 |
25 | private void init(AttributeSet attrs) {
26 | // Do your staff
27 | }
28 |
29 | public void setFeelings() {
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/myapplication/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.myapplication", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/SessionLog.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import android.content.Context;
4 | import java.io.File;
5 | import java.io.FileOutputStream;
6 | import java.io.FileWriter;
7 | import java.io.IOException;
8 | import java.io.OutputStreamWriter;
9 | import java.util.Vector;
10 |
11 | public class SessionLog {
12 |
13 | private Context context;
14 | private String buffer;
15 |
16 | public SessionLog(Context context) {
17 | this.context = context;
18 | reset();
19 | }
20 |
21 | public void write(DataPoint dataPoint) {
22 |
23 | buffer += dataPoint.toCSV();
24 |
25 | if(buffer.length() > 1024) {
26 | flush();
27 | }
28 | }
29 |
30 | public void reset() {
31 | buffer = "";
32 | context.getFileStreamPath("session.txt").delete();
33 | }
34 |
35 | public void flush() {
36 | try {
37 | OutputStreamWriter writer = new OutputStreamWriter(context.openFileOutput("session.txt", Context.MODE_APPEND));
38 | writer.write(buffer);
39 | buffer = "";
40 | writer.close();
41 | }
42 | catch (IOException e) {
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.example.myapplication"
7 | minSdkVersion 15
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | implementation 'com.android.support:design:28.0.0'
26 | implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
27 | implementation 'io.reactivex.rxjava2:rxjava:2.x.x'
28 | testImplementation 'junit:junit:4.12'
29 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
30 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
31 | implementation 'com.robinhood.spark:spark:1.2.0'
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
17 |
18 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
36 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/Session.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import android.content.Context;
4 |
5 | import java.util.UUID;
6 |
7 | public class Session {
8 |
9 | public enum State {
10 | NONE,
11 | STARTED,
12 | STOPPED
13 | }
14 |
15 | private State state;
16 | private String sessionId;
17 | private SessionLog sessionLog;
18 |
19 | private DataPoint lastDataPoint;
20 |
21 | public Session(Context context) {
22 | sessionLog = new SessionLog(context);
23 | state = State.NONE;
24 | lastDataPoint = new DataPoint();
25 | }
26 |
27 | public void startSession() {
28 | state = State.STARTED;
29 | sessionId = UUID.randomUUID().toString();
30 | sessionLog.reset();
31 | }
32 |
33 | public void stopSession() {
34 | state = State.STOPPED;
35 | sessionLog.flush();
36 | }
37 |
38 | public State getState() {
39 | return state;
40 | }
41 |
42 | public DataPoint getLastDataPoint() {
43 | return lastDataPoint;
44 | }
45 |
46 | public void onAccelerometerEvent(long time, float x, float y, float z) {
47 | if(getState() != State.STARTED) {
48 | return;
49 | }
50 |
51 | lastDataPoint.time = time;
52 | lastDataPoint.accelerometer_x = x;
53 | lastDataPoint.accelerometer_y = y;
54 | lastDataPoint.accelerometer_z = z;
55 |
56 | sessionLog.write(lastDataPoint);
57 | }
58 |
59 | public void onGeoEvent(long time, double latitude, double longitude) {
60 | if(getState() != State.STARTED) {
61 | return;
62 | }
63 |
64 | lastDataPoint.time = time;
65 | lastDataPoint.latitude = latitude;
66 | lastDataPoint.longitude = longitude;
67 |
68 | sessionLog.write(lastDataPoint);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CycleWorks
2 |
3 | Cycleworks is a service for crowd souring data on cycling journeys. Two observations inspired it's creation
4 | * Many policy documents (such as the recent [busconnects project](https://www.busconnects.ie/initiatives/core-bus-corridor-project/)) rely on very simple sample cycling data e.g. a count of cyclist entering the city bounded by the canals on a small number of days
5 | * Most cyclists in Dublin have a smartphone in their pocket
6 |
7 | Cycleworks aims to use the second observation to replace the first with a much richer and more complete data source on cycling journeys.
8 | The hope is that by providing this richer source of data it will be easier to motivate changes to cycling infrastructure and cycyling policy in the city.
9 |
10 | Some interesting data points we expect may be possible to capture via a smartphone app:
11 | * number of journeys
12 | * heatmap of journeys
13 | * heatmap of poor road condition
14 | * heatmap of hard braking events
15 |
16 | # Challenges
17 | One of the key challenges will be protecting individuals privacy so people are open to sharing their cycling journey info.
18 | Some privacy topics already identified:
19 | * Data is alway aggregated
20 | * It is not possible to query an individuals data
21 | * Data points are associated with a machine generated unique (per journey) id only
22 | * no personal data is assocaited with this id e.g. no name, phone number or email address
23 | * No data is shared on the first or last 100m of any journey
24 | * in order to ensure starting point and destination are never shared
25 |
26 |
27 | # Help
28 | So far we have only built a very simple prototype. This is not our full time job and we are not android developers so we could do with some help:
29 | * How to we collect data while smartphone in pocket or bag
30 | * How to we identitfy start and end of cycling journeys
31 | * How to we make the data available
32 | * How to port from android to iphone
33 | * ...
34 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/Vector3.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | /*
4 | * Copyright (C) 2010 The Android Open Source Project
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | /**
20 | * Simple 3D vector class. Handles basic vector math for 3D vectors.
21 | */
22 | public final class Vector3 {
23 | public float x;
24 | public float y;
25 | public float z;
26 |
27 | public static final Vector3 ZERO = new Vector3(0, 0, 0);
28 |
29 | public Vector3() {
30 | }
31 |
32 | public Vector3(float value[]) {
33 | set(value[0], value[1], value[2]);
34 | }
35 |
36 | public Vector3(float xValue, float yValue, float zValue) {
37 | set(xValue, yValue, zValue);
38 | }
39 |
40 | public Vector3(Vector3 other) {
41 | set(other);
42 | }
43 |
44 | public final void add(Vector3 other) {
45 | x += other.x;
46 | y += other.y;
47 | z += other.z;
48 | }
49 |
50 | public final void add(float otherX, float otherY, float otherZ) {
51 | x += otherX;
52 | y += otherY;
53 | z += otherZ;
54 | }
55 |
56 | public final void subtract(Vector3 other) {
57 | x -= other.x;
58 | y -= other.y;
59 | z -= other.z;
60 | }
61 |
62 | public final void multiply(float magnitude) {
63 | x *= magnitude;
64 | y *= magnitude;
65 | z *= magnitude;
66 | }
67 |
68 | public final void multiply(Vector3 other) {
69 | x *= other.x;
70 | y *= other.y;
71 | z *= other.z;
72 | }
73 |
74 | public final void divide(float magnitude) {
75 | if (magnitude != 0.0f) {
76 | x /= magnitude;
77 | y /= magnitude;
78 | z /= magnitude;
79 | }
80 | }
81 |
82 | public final void set(Vector3 other) {
83 | x = other.x;
84 | y = other.y;
85 | z = other.z;
86 | }
87 |
88 | public final void set(float xValue, float yValue, float zValue) {
89 | x = xValue;
90 | y = yValue;
91 | z = zValue;
92 | }
93 |
94 | public final float dot(Vector3 other) {
95 | return (x * other.x) + (y * other.y) + (z * other.z);
96 | }
97 |
98 | public final float length() {
99 | return (float) Math.sqrt(length2());
100 | }
101 |
102 | public final float length2() {
103 | return (x * x) + (y * y) + (z * z);
104 | }
105 |
106 | public final float distance2(Vector3 other) {
107 | float dx = x - other.x;
108 | float dy = y - other.y;
109 | float dz = z - other.z;
110 | return (dx * dx) + (dy * dy) + (dz * dz);
111 | }
112 |
113 | public final float normalize() {
114 | final float magnitude = length();
115 |
116 | // TODO: I'm choosing safety over speed here.
117 | if (magnitude != 0.0f) {
118 | x /= magnitude;
119 | y /= magnitude;
120 | z /= magnitude;
121 | }
122 |
123 | return magnitude;
124 | }
125 |
126 | public final void zero() {
127 | set(0.0f, 0.0f, 0.0f);
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
22 |
23 |
32 |
33 |
44 |
45 |
56 |
57 |
58 |
66 |
67 |
76 |
77 |
78 |
79 |
80 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/BumpMonitorService.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import android.Manifest;
4 | import android.app.Service;
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.hardware.Sensor;
8 | import android.hardware.SensorEvent;
9 | import android.hardware.SensorEventListener;
10 | import android.hardware.SensorManager;
11 | import android.location.Location;
12 | import android.location.LocationListener;
13 | import android.location.LocationManager;
14 | import android.os.Bundle;
15 | import android.os.IBinder;
16 | import android.support.v4.app.ActivityCompat;
17 | import android.util.Log;
18 |
19 | import io.reactivex.Observable;
20 | import io.reactivex.subjects.PublishSubject;
21 |
22 |
23 | public class BumpMonitorService extends Service implements SensorEventListener, LocationListener {
24 | private static final String TAG = "CycleCrowd";
25 | private SensorManager sensorManager;
26 | private Sensor senAccelerometer;
27 | private LocationManager locationManager;
28 | private Session session;
29 | private static PublishSubject publisher = PublishSubject.create();
30 |
31 | public BumpMonitorService() {
32 | }
33 |
34 | @Override
35 | public int onStartCommand(Intent intent, int flags, int startId) {
36 | Log.d(TAG, "starting BumpMonitorService");
37 |
38 | session = new Session(this);
39 | session.startSession();
40 |
41 | sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
42 | senAccelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
43 | sensorManager.registerListener(this, senAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
44 |
45 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
46 | locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
47 | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this);
48 | onLocationChanged(locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
49 | }
50 |
51 | publish();
52 |
53 | return START_STICKY;
54 | }
55 |
56 | @Override
57 | public IBinder onBind(Intent intent) {
58 | Log.d(TAG, "onBind");
59 | return null;
60 | }
61 |
62 | @Override
63 | public void onSensorChanged(SensorEvent event) {
64 | if (event != null && event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
65 | session.onAccelerometerEvent(System.currentTimeMillis(), event.values[0], event.values[1], event.values[2]);
66 | publish();
67 | }
68 | }
69 |
70 | @Override
71 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
72 |
73 | }
74 |
75 | @Override
76 | public void onLocationChanged(Location location) {
77 | if(location != null) {
78 | session.onGeoEvent(location.getTime(), location.getLatitude(), location.getLongitude());
79 | publish();
80 | }
81 | }
82 |
83 | @Override
84 | public void onStatusChanged(String provider, int status, Bundle extras) {
85 |
86 | }
87 |
88 | @Override
89 | public void onProviderEnabled(String provider) {
90 |
91 | }
92 |
93 | @Override
94 | public void onProviderDisabled(String provider) {
95 |
96 | }
97 |
98 | @Override
99 | public void onTaskRemoved(Intent rootIntent) {
100 | Log.d(TAG,"task removed");
101 | super.onTaskRemoved(rootIntent);
102 | publish();
103 | }
104 |
105 | @Override
106 | public void onDestroy() {
107 | Log.d(TAG,"onDestroy");
108 | super.onDestroy();
109 | session.stopSession();
110 | sensorManager.unregisterListener(this);
111 | locationManager.removeUpdates(this);
112 | publish();
113 | }
114 |
115 | public static Observable getObservable(){
116 | return publisher;
117 | }
118 |
119 | private void publish() {
120 |
121 | Vector3 v = new Vector3(session.getLastDataPoint().accelerometer_x, session.getLastDataPoint().accelerometer_y, session.getLastDataPoint().accelerometer_z);
122 | float f = Math.abs(new Vector3(0, 0, 0).distance2(v));
123 | f = f < 50 ? 0 : Math.min(f, 1000.0f);
124 |
125 | publisher.onNext(new MainActivity.ViewModel(session.getState(), f));
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.myapplication;
2 |
3 | import android.Manifest;
4 | import android.animation.Animator;
5 | import android.animation.ValueAnimator;
6 | import android.app.AlarmManager;
7 | import android.app.PendingIntent;
8 | import android.content.Context;
9 | import android.content.Intent;
10 | import android.content.res.ColorStateList;
11 | import android.graphics.Path;
12 | import android.graphics.PathMeasure;
13 | import android.graphics.RectF;
14 | import android.net.Uri;
15 | import android.os.Handler;
16 | import android.support.design.widget.FloatingActionButton;
17 | import android.support.v4.app.ActivityCompat;
18 | import android.support.v4.content.FileProvider;
19 | import android.support.v7.app.AppCompatActivity;
20 | import android.os.Bundle;
21 | import android.view.View;
22 | import android.view.animation.Animation;
23 | import android.widget.Button;
24 | import android.widget.TextView;
25 |
26 | import com.robinhood.spark.SparkAdapter;
27 | import com.robinhood.spark.SparkView;
28 | import com.robinhood.spark.animation.LineSparkAnimator;
29 | import com.robinhood.spark.animation.MorphSparkAnimator;
30 | import com.robinhood.spark.animation.SparkAnimator;
31 |
32 | import java.util.Vector;
33 |
34 | import io.reactivex.Observable;
35 | import io.reactivex.Observer;
36 | import io.reactivex.disposables.Disposable;
37 |
38 | public class MainActivity extends AppCompatActivity {
39 | public static class ViewModel
40 | {
41 | Session.State state = Session.State.NONE;
42 | float bumpScore = 0;
43 |
44 | public ViewModel() {
45 | }
46 |
47 | public ViewModel(Session.State state, float bumpScore) {
48 | this.state = state;
49 | this.bumpScore = bumpScore;
50 | }
51 | }
52 |
53 | private static class SparklineAdapter extends SparkAdapter {
54 | private final int size = 32;
55 | private float data[] = new float[size];
56 | private int idx = 0;
57 |
58 | public SparklineAdapter() {
59 | for(int i = 0; i < size; i++) {
60 | data[i] = 0;
61 | }
62 | }
63 |
64 | public void addData(float f) {
65 | data[idx++ % size] = f;
66 | }
67 |
68 | @Override
69 | public int getCount() {
70 | return size;
71 | }
72 |
73 | @Override
74 | public Object getItem(int index) {
75 | //data[0] = 1000;
76 | return data[Math.abs(index - idx + 1) % size];
77 | }
78 |
79 | @Override
80 | public float getY(int index) {
81 | // data[0] = 1000;
82 | return data[Math.abs(index - idx + 1) % size];
83 | }
84 |
85 | @Override
86 | public RectF getDataBounds() {
87 | final int count = getCount();
88 | final boolean hasBaseLine = hasBaseLine();
89 |
90 | float minY = hasBaseLine ? getBaseLine() : Float.MAX_VALUE;
91 | float maxY = hasBaseLine ? minY : -Float.MAX_VALUE;
92 | float minX = Float.MAX_VALUE;
93 | float maxX = -Float.MAX_VALUE;
94 | for (int i = 0; i < count; i++) {
95 | final float x = getX(i);
96 | minX = Math.min(minX, x);
97 | maxX = Math.max(maxX, x);
98 | minY = 0;
99 | maxY = 1000;
100 | }
101 |
102 | // set values on the return object
103 | return new RectF(minX, minY, maxX, maxY);
104 | }
105 | }
106 |
107 | public class LineSparkAnimatorCustom implements SparkAnimator {
108 |
109 | @Override
110 | public Animator getAnimation(final SparkView sparkView) {
111 | ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
112 | return animator;
113 | }
114 |
115 | }
116 |
117 | private TextView bump_score_txt;
118 | private TextView start_button_txt;
119 | private FloatingActionButton start_button;
120 | private Button share_button;
121 | private SparkView sparkView;
122 | private PendingIntent scheduledIntent;
123 | private AlarmManager scheduler;
124 | private Intent myService;
125 | private ViewModel viewModel;
126 | private SparklineAdapter sparklineAdapter;
127 | private Handler handler;
128 |
129 | Runnable drawLoop = new Runnable() {
130 | @Override
131 | public void run() {
132 | try {
133 | redraw();
134 | } finally {
135 | handler.postDelayed(drawLoop, 20);
136 | }
137 | }
138 | };
139 |
140 | @Override
141 | protected void onCreate(Bundle savedInstanceState) {
142 | super.onCreate(savedInstanceState);
143 | setContentView(R.layout.activity_main);
144 |
145 | viewModel = new ViewModel();
146 |
147 | bump_score_txt = findViewById(R.id.bump_score_txt);
148 | start_button = findViewById(R.id.start_button);
149 | start_button_txt = findViewById(R.id.start_button_txt);
150 | share_button = findViewById(R.id.share_button);
151 | sparkView = findViewById(R.id.sparkview);
152 |
153 | sparklineAdapter = new SparklineAdapter();
154 | sparkView.setSparkAnimator(new LineSparkAnimatorCustom());
155 | sparkView.setAdapter(sparklineAdapter);
156 | handler = new Handler();
157 | drawLoop.run();
158 |
159 | createObservable();
160 |
161 | start_button.setOnClickListener(new View.OnClickListener() {
162 | public void onClick(View v) {
163 | onStartButtonClick();
164 | }
165 | });
166 |
167 | share_button.setOnClickListener(new View.OnClickListener() {
168 | public void onClick(View v) {
169 | onShareButtonClick();
170 | }
171 | });
172 |
173 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
174 | }
175 |
176 | protected void onPause() {
177 | super.onPause();
178 | handler.removeCallbacks(drawLoop);
179 | }
180 |
181 | protected void onResume() {
182 | super.onResume();
183 | drawLoop.run();
184 | }
185 |
186 | private void stopMonitorService() {
187 | stopService(new Intent(this, BumpMonitorService.class));
188 | /*
189 | scheduler = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
190 | if(scheduledIntent != null) {
191 | scheduler.cancel(scheduledIntent);
192 | }
193 |
194 | if(myService != null) {
195 | stopService(myService);
196 | }
197 |
198 | myService = new Intent(this, BumpMonitorService.class);
199 | stopService(myService);
200 | */
201 | }
202 |
203 | private void startMonitorService() {
204 | startService(new Intent(this, BumpMonitorService.class));
205 | /*
206 | scheduler = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
207 | if(scheduledIntent != null) {
208 | scheduler.cancel(scheduledIntent);
209 | }
210 |
211 | if(myService != null) {
212 | stopService(myService);
213 | }
214 |
215 | myService = new Intent(this, BumpMonitorService.class);
216 | stopService(myService);
217 |
218 | scheduledIntent = PendingIntent.getService(this,0, myService, PendingIntent.FLAG_UPDATE_CURRENT);
219 | scheduler.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 , scheduledIntent);
220 | */
221 | }
222 |
223 | private void onStartButtonClick() {
224 | switch (viewModel.state) {
225 | case STARTED:
226 | stopMonitorService();
227 | break;
228 | case STOPPED:
229 | case NONE:
230 | startMonitorService();
231 | break;
232 | }
233 | }
234 |
235 | private void onShareButtonClick() {
236 | Uri uri = FileProvider.getUriForFile(this, "com.example.myapplication", this.getFileStreamPath("session.txt"));
237 | Intent sharingIntent = new Intent(Intent.ACTION_SEND);
238 | sharingIntent.setType("text/plain");
239 | sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
240 | startActivity(Intent.createChooser(sharingIntent, "Share using"));
241 | }
242 |
243 | private int xx = 0;
244 |
245 | private void createObservable(){
246 | Observable observable = BumpMonitorService.getObservable();
247 | observable.subscribe(new Observer() {
248 | @Override
249 | public void onSubscribe(Disposable d) {
250 | }
251 |
252 | @Override
253 | public void onNext(ViewModel model) {
254 | viewModel = model;
255 | }
256 |
257 | @Override
258 | public void onError(Throwable e) {
259 | }
260 |
261 | @Override
262 | public void onComplete() {
263 | }
264 | });
265 | }
266 |
267 |
268 | private void redraw() {
269 | sparklineAdapter.addData(viewModel.bumpScore);
270 | sparklineAdapter.notifyDataSetChanged();
271 | bump_score_txt.setText(""+(int)viewModel.bumpScore);
272 |
273 | switch (viewModel.state) {
274 | case STARTED:
275 | start_button.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorAccent)));
276 | share_button.setVisibility(View.INVISIBLE);
277 | start_button_txt.setText("■");
278 | break;
279 | case STOPPED:
280 | start_button.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.blue)));
281 | share_button.setVisibility(View.VISIBLE);
282 | start_button_txt.setText("⬤");
283 | break;
284 | case NONE:
285 | start_button.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.blue)));
286 | share_button.setVisibility(View.INVISIBLE);
287 | start_button_txt.setText("⬤");
288 | break;
289 | }
290 | }
291 | }
292 |
--------------------------------------------------------------------------------