├── .gitattributes ├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tobias │ │ └── schrittzaehlerfacharbeit │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── tobias │ │ │ └── schrittzaehlerfacharbeit │ │ │ ├── AccelerationData.java │ │ │ ├── MainActivity.java │ │ │ ├── StepDetector.java │ │ │ ├── StepListener.java │ │ │ ├── StepType.java │ │ │ └── ui │ │ │ ├── beschleunigungssensor │ │ │ ├── BeschleunigungsSensorFragment.java │ │ │ └── BeschleunigungsSensorViewModel.java │ │ │ └── schrittzaehler │ │ │ ├── SchrittzaehlerFragment.java │ │ │ └── SchrittzaehlerViewModel.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_directions_walk_black_24dp.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_show_chart_black_24dp.xml │ │ └── relatives_koordinatensystem.png │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── beschleunigungs_sensor_fragment.xml │ │ └── schrittzaehler_fragment.xml │ │ ├── menu │ │ └── bottom_nav_menu.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.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 │ │ ├── navigation │ │ └── mobile_navigation.xml │ │ ├── values-en-rUS │ │ └── strings.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── tobias │ └── schrittzaehlerfacharbeit │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pedometer_mockup.png └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | *.aab 5 | 6 | # Files for the ART/Dalvik VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | out/ 16 | 17 | # Gradle files 18 | .gradle/ 19 | build/ 20 | 21 | # Local configuration file (sdk path, etc) 22 | local.properties 23 | 24 | # Proguard folder generated by Eclipse 25 | proguard/ 26 | 27 | # Log Files 28 | *.log 29 | 30 | # Android Studio Navigation editor temp files 31 | .navigation/ 32 | 33 | # Android Studio captures folder 34 | captures/ 35 | 36 | # IntelliJ 37 | *.iml 38 | .idea/workspace.xml 39 | .idea/tasks.xml 40 | .idea/gradle.xml 41 | .idea/assetWizardSettings.xml 42 | .idea/dictionaries 43 | .idea/libraries 44 | .idea/caches 45 | 46 | # Keystore files 47 | # Uncomment the following lines if you do not want to check your keystore files in. 48 | #*.jks 49 | #*.keystore 50 | 51 | # External native build folder generated in Android Studio 2.2 and later 52 | .externalNativeBuild 53 | 54 | # Google Services (e.g. APIs or Firebase) 55 | google-services.json 56 | 57 | # Freeline 58 | freeline.py 59 | freeline/ 60 | freeline_project_description.json 61 | 62 | # fastlane 63 | fastlane/report.xml 64 | fastlane/Preview.html 65 | fastlane/screenshots 66 | fastlane/test_output 67 | fastlane/readme.md 68 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android step counter (with Accelerometer) 2 | Native Android app that counts the user's steps with the accelerometer. 3 | 4 | Just to demonstrate this way of step counting. The main parts of this simple algorithm can be found in the class [StepDetector.java](app/src/main/java/com/tobias/schrittzaehlerfacharbeit/StepDetector.java). 5 | Most of the comments are in German. 6 | 7 | ![UI Images](pedometer_mockup.png) 8 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.1" 6 | defaultConfig { 7 | applicationId "com.tobias.schrittzaehlerfacharbeit" 8 | minSdkVersion 21 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'androidx.appcompat:appcompat:1.1.0' 25 | implementation 'com.google.android.material:material:1.1.0' 26 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 27 | implementation 'androidx.navigation:navigation-fragment:2.2.1' 28 | implementation 'androidx.navigation:navigation-ui:2.2.1' 29 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' 30 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 34 | 35 | // Grafik - Library: 36 | implementation 'com.jjoe64:graphview:4.2.2' 37 | } 38 | -------------------------------------------------------------------------------- /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/androidTest/java/com/tobias/schrittzaehlerfacharbeit/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | 25 | assertEquals("com.tobias.schrittzaehlerfacharbeit", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/tobias/schrittzaehlerfacharbeit/AccelerationData.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit; 2 | 3 | /** 4 | * 5 | */ 6 | public class AccelerationData { 7 | 8 | private double value; // Länge des Vektors (errechnet aus x, y und z) 9 | private float x; 10 | private float y; 11 | private float z; 12 | private long time; 13 | 14 | public double getValue() { 15 | return value; 16 | } 17 | 18 | public void setValue(double value) { 19 | this.value = value; 20 | } 21 | 22 | public float getX() { 23 | return x; 24 | } 25 | 26 | public void setX(float x) { 27 | this.x = x; 28 | } 29 | 30 | public float getY() { 31 | return y; 32 | } 33 | 34 | public void setY(float y) { 35 | this.y = y; 36 | } 37 | 38 | public float getZ() { 39 | return z; 40 | } 41 | 42 | public void setZ(float z) { 43 | this.z = z; 44 | } 45 | 46 | public long getTime() { 47 | return time; 48 | } 49 | 50 | public void setTime(long time) { 51 | this.time = time; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/tobias/schrittzaehlerfacharbeit/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.google.android.material.bottomnavigation.BottomNavigationView; 6 | 7 | import androidx.appcompat.app.AppCompatActivity; 8 | import androidx.navigation.NavController; 9 | import androidx.navigation.Navigation; 10 | import androidx.navigation.ui.AppBarConfiguration; 11 | import androidx.navigation.ui.NavigationUI; 12 | 13 | /** 14 | * Die Klasse MeinActivity ist die einzige Activity (= "Seite") der App 15 | * und dient als Grundlage. Die onCreate Methode in ihr wird beim Start der Applikation 16 | * aufgerufen. 17 | */ 18 | public class MainActivity extends AppCompatActivity { 19 | 20 | private static final String TAG = "MainActivity"; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_main); 26 | BottomNavigationView navView = findViewById(R.id.nav_view); 27 | // Passing each menu ID as a set of Ids because each 28 | // menu should be considered as top level destinations. 29 | AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder( 30 | R.id.navigation_schrittzaehler, R.id.navigation_beschleunigungssensor) 31 | .build(); 32 | NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); 33 | NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); 34 | NavigationUI.setupWithNavController(navView, navController); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/tobias/schrittzaehlerfacharbeit/StepDetector.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit; 2 | 3 | import android.os.SystemClock; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.Comparator; 8 | 9 | /** 10 | * Die Klasse StepDetector dient der Ermittlung von Schritten 11 | * aus Datensätzen des Beschleunigungssensors. Über das StepListener-Interface 12 | * werden die erkannten Schritte "zurückgegeben". 13 | */ 14 | public class StepDetector { 15 | 16 | private static final int WALKINGTHRESHOLD = 17; 17 | private static final int JOGGINGTHRESHOLD = 24; 18 | private static final int RUNNINGTHRESHOLD = 30; 19 | 20 | private StepListener stepListener; 21 | 22 | private ArrayList newAccelerationDataList; 23 | private ArrayList calculatedList; 24 | 25 | /** 26 | * Konstruktor der Klasse. 27 | * Es werden zwei leere ArrayListen erstellt, 28 | * welche in den anderen Methoden benötigt werden. 29 | */ 30 | public StepDetector(){ 31 | newAccelerationDataList = new ArrayList<>(); 32 | calculatedList = new ArrayList<>(); 33 | } 34 | 35 | 36 | /** 37 | * Die Methode registerStepListener registriert das mitgegebene Interface 38 | * als Attribut in der Klasse. Über dieses werden später erkannte Schritte mitgeteilt. 39 | * @param pStepListener Das Interface, welches erkannte Schritte mitgeteilt bekommt. 40 | */ 41 | public void registerStepListener(StepListener pStepListener){ 42 | stepListener = pStepListener; 43 | } 44 | 45 | /** 46 | * Die Methode addAccelerationData nimmt neue Messwerte des Beschleunigungssensors entgegen. 47 | * Wenn 25 Datensätze vorhanden sind, werden sie verarbeitet und es werden erneut 25 Datensätze gesammelt. 48 | * @param pNewAccelerationData 49 | */ 50 | public void addAccelerationData(AccelerationData pNewAccelerationData){ 51 | newAccelerationDataList.add(pNewAccelerationData); 52 | 53 | if(newAccelerationDataList.size() >= 25){ 54 | handleAccelerationData(); 55 | } 56 | } 57 | 58 | /** 59 | * Die Methode handleAccelerationData erkennt Schritte in Beschleunigungsdaten. 60 | * Dazu werden auch die vier Methoden calculateValueAndTime, findHighPoints, removeNearHighPoints, und examineStepTypeAndSendResponse 61 | * genutzt. Für jeden Datensatz wird außerdem die Vektorlänge (= Geschwindigkeit zu bestimmten Zeitpunkt) berechnet und 62 | * das time Attribut des Datensatzes wird von Nanosekunden seit Gerätestartzeit in Unixzeit (Millisekunden) geändert. 63 | * Nach Abarbeitung aller Daten werden die erkannten Schritte über das Interface ausgegeben und 64 | * die ArrayListen wieder geleert, damit sie erneut verwendet werden können. 65 | */ 66 | private void handleAccelerationData(){ 67 | 68 | for (int i = 0; i < newAccelerationDataList.size(); i++) { 69 | AccelerationData accelerationData = newAccelerationDataList.get(i); 70 | accelerationData = calculateValueAndTime(accelerationData); 71 | calculatedList.add(accelerationData); 72 | } 73 | 74 | ArrayList highPointList = findHighPoints(); 75 | highPointList = removeNearHighPoints(highPointList); 76 | examineStepTypeAndSendResponse(highPointList); 77 | 78 | calculatedList.clear(); 79 | newAccelerationDataList.clear(); 80 | } 81 | 82 | /** 83 | * Die Methode calculateValueAndTime berechnet für pAccelerationData die Vektorlänge und den Unix-Timestamp. 84 | * Die entsprechenden Werte werden in pAccelerationData geändert. Anschließend wird pAccelerationData returnt. 85 | * @param pAccelerationData Objekt, von welchem die Vektorlänge und der Unix-Timestamp berechnet werden. 86 | * @return AccelerationData: Das Objekt, mit geänderten Werten. 87 | */ 88 | private AccelerationData calculateValueAndTime(AccelerationData pAccelerationData){ 89 | 90 | float x = pAccelerationData.getX(); 91 | float y = pAccelerationData.getY(); 92 | float z = pAccelerationData.getZ(); 93 | 94 | double vectorLength = Math.sqrt(x * x + y * y + z * z); 95 | pAccelerationData.setValue(vectorLength); 96 | 97 | long time = pAccelerationData.getTime(); 98 | long timeOffsetToUnix = System.currentTimeMillis() - SystemClock.elapsedRealtime(); 99 | long unixTimestamp = (time / 1000000L) + timeOffsetToUnix; 100 | pAccelerationData.setTime(unixTimestamp); 101 | 102 | return pAccelerationData; 103 | } 104 | 105 | /** 106 | * Die Methode findHighPoints findet die Beschleunigungsdatensätze aus rawAccelerationData 107 | * heraus, deren Gesamtbeschleunigung höher als der Wert von WALKINGTHRESHOLD (17) ist. Diese werden 108 | * einer weiteren ArrayList hinzugefügt, welche returnt wird. 109 | * @return ArrayList: Eine Liste, mit den höchsten Hochpunkten. 110 | */ 111 | private ArrayList findHighPoints(){ 112 | ArrayList highPointList = new ArrayList<>(); 113 | ArrayList aboveWalkingThresholdList = new ArrayList<>(); 114 | boolean wasAboveThreshold = true; 115 | for (int i = 0; i < calculatedList.size(); i++) { 116 | 117 | AccelerationData calculatedDataSet = calculatedList.get(i); 118 | if(calculatedDataSet.getValue() > WALKINGTHRESHOLD){ 119 | aboveWalkingThresholdList.add(calculatedDataSet); 120 | wasAboveThreshold = true; 121 | } else { 122 | // erst, wenn es einen Wert unter WALKINGTHRESHOLD gibt 123 | if(wasAboveThreshold && aboveWalkingThresholdList.size() > 0){ 124 | Collections.sort(aboveWalkingThresholdList, new AccelerationDataSorter()); 125 | highPointList.add(aboveWalkingThresholdList.get(aboveWalkingThresholdList.size() - 1)); 126 | aboveWalkingThresholdList.clear(); 127 | } 128 | wasAboveThreshold = false; 129 | } 130 | } 131 | return highPointList; 132 | } 133 | 134 | 135 | /** 136 | * Die Methode removeNearHighPoints geht die ArrayList pAccelerationData mit den höchsten Hochpunkten 137 | * durch und überprüft, ob innerhalb von 400 Millisekunden ein weiterer "höchster Gipfel" vorhanden ist. 138 | * Falls dies der Fall ist, wird der kleinere von beiden aus der Liste entfernt. 139 | * @param pAccelerationDataList Die Liste mit den Hochpunkten als ArrayList 140 | * @return Eine ArrayList, mit den entfernten Hochpunkten innerhalb von 400 Millisekunden 141 | */ 142 | private ArrayList removeNearHighPoints(ArrayList pAccelerationDataList){ 143 | ArrayList wrongHighPointIndexes = new ArrayList<>(); 144 | for (int i = 0; i < pAccelerationDataList.size() - 1; i++) { 145 | if((pAccelerationDataList.get(i + 1).getTime() - pAccelerationDataList.get(i).getTime()) < 400){ 146 | if(pAccelerationDataList.get(i + 1).getValue() < pAccelerationDataList.get(i).getValue()){ 147 | wrongHighPointIndexes.add(i + 1); 148 | } else { 149 | wrongHighPointIndexes.add(i); 150 | } 151 | } 152 | } 153 | for (int i = wrongHighPointIndexes.size() - 1; i >= 0; i--) { 154 | System.out.println(i); 155 | pAccelerationDataList.remove(i); 156 | } 157 | return pAccelerationDataList; 158 | } 159 | 160 | /** 161 | * 162 | * Die Methode examineStepTypeAndSendResponse überprüft die Gesamtbeschleunigung der höchsten Gipfel aus 163 | * pAccelerationData und sendet über das registrierte Interface stepListener alle erkannten Schritte. 164 | * Wenn die Gesamtbeschleunigung größer als RUNNINGPEAK ist, wird der Schritttyp RUNNING ausgegeben, 165 | * wenn die Gesamtbeschleunigung größer als JOGGINGPEAK ist, wird der Schritttyp JOGGING ausgegeben, 166 | * andernfalls der Schritttype WALKING. 167 | * @param pAccelerationDataList Eine ArrayList, mit den höchsten Hochpunkten 168 | */ 169 | private void examineStepTypeAndSendResponse(ArrayList pAccelerationDataList){ 170 | for (int i = 0; i < pAccelerationDataList.size(); i++) { 171 | AccelerationData highPoint = pAccelerationDataList.get(i); 172 | if(highPoint.getValue() > RUNNINGTHRESHOLD){ 173 | stepListener.step(highPoint, StepType.RUNNING); 174 | } else if(highPoint.getValue() > JOGGINGTHRESHOLD){ 175 | stepListener.step(highPoint, StepType.JOGGING); 176 | } else { 177 | stepListener.step(highPoint, StepType.WALKING); 178 | } 179 | } 180 | } 181 | 182 | /** 183 | * Die Klasse DataSorter ist eine Comparator-Klasse für Arraylisten mit AccelerationData. 184 | * Es wird nach der Größe des Gesamtbeschleunigungswertes aufwärts sortiert. 185 | */ 186 | public class AccelerationDataSorter implements Comparator { 187 | /** 188 | * Die Methode compare vergleicht zwei Datensätze von AccelerationData anhand der 189 | * Gesamtbeschleunigung "value". Wenn die Beschleunigung des ersten Datensatzes größer ist, 190 | * wird 1 returnt. Wenn die Beschleunigung des zweiten Datensatzes größer ist, wird -1 returnt. 191 | * Ansonsten (wenn die Beschlunigung gleich ist) wird 0 returnt. 192 | * @param data1 AccelerationData: Das erste Vergleichsobjekt 193 | * @param data2 AccelerationData: Das zweite Vergleichsobjekt 194 | * @return int 0, 1 oder -1; je nachdem, welche Beschleunigung größer ist. 195 | */ 196 | @Override 197 | public int compare(AccelerationData data1, AccelerationData data2) { 198 | int returnValue = 0; 199 | if(data1.getValue() < data2.getValue()){ 200 | returnValue = -1; 201 | } else if(data1.getValue() > data2.getValue()){ 202 | returnValue = 1; 203 | } 204 | return returnValue; 205 | } 206 | } 207 | 208 | } 209 | 210 | 211 | -------------------------------------------------------------------------------- /app/src/main/java/com/tobias/schrittzaehlerfacharbeit/StepListener.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit; 2 | 3 | /** 4 | * Das interface StepListener dient dazu, erkannte Schritte von der StepDetector Klasse 5 | * zurück zur Activity bzw. der Klasse, in der das Interface implementiert wird, zurück zu "senden". 6 | * Dazu muss die Klasse, in der das Interface implementiert ist, im StepDetector registriert werden. 7 | */ 8 | public interface StepListener { 9 | 10 | /** 11 | * Die Methode step soll erkannte Schritte übergeben. 12 | * @param accelerationData AccelerationData: Ein Datensatz des Beschleunigungssensors, welcher für einen Schritt steht. 13 | * @param stepType Enum StepType: Eine der drei Schritttypen aus dem Enum StepType. 14 | */ 15 | void step(AccelerationData accelerationData, StepType stepType); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/tobias/schrittzaehlerfacharbeit/StepType.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit; 2 | 3 | /** 4 | * Das Enum StepType enthält die möglichen Schritttypen. 5 | */ 6 | public enum StepType { 7 | WALKING, 8 | JOGGING, 9 | RUNNING 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/tobias/schrittzaehlerfacharbeit/ui/beschleunigungssensor/BeschleunigungsSensorFragment.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit.ui.beschleunigungssensor; 2 | 3 | import androidx.lifecycle.ViewModelProviders; 4 | 5 | import android.content.Context; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.hardware.Sensor; 9 | import android.hardware.SensorEvent; 10 | import android.hardware.SensorEventListener; 11 | import android.hardware.SensorManager; 12 | import android.os.Bundle; 13 | 14 | import androidx.annotation.NonNull; 15 | import androidx.annotation.Nullable; 16 | import androidx.fragment.app.Fragment; 17 | 18 | import android.util.Log; 19 | import android.view.LayoutInflater; 20 | import android.view.View; 21 | import android.view.ViewGroup; 22 | import android.widget.TextView; 23 | 24 | import com.jjoe64.graphview.GraphView; 25 | import com.jjoe64.graphview.LegendRenderer; 26 | import com.jjoe64.graphview.helper.StaticLabelsFormatter; 27 | import com.jjoe64.graphview.series.DataPoint; 28 | import com.jjoe64.graphview.series.LineGraphSeries; 29 | import com.tobias.schrittzaehlerfacharbeit.R; 30 | 31 | public class BeschleunigungsSensorFragment extends Fragment implements SensorEventListener { 32 | 33 | private static final String TAG = "AccelSensorFragment"; 34 | 35 | // Live-Data Bereich: 36 | private TextView textview_accel_live_data_x, textview_accel_live_data_y, textview_accel_live_data_z, 37 | textview_accel_live_data_accuracy, textview_accel_live_data_delay; 38 | 39 | // Details Bereich: 40 | private TextView textview_accel_details_name, textview_accel_details_manufacturer, 41 | textview_accel_details_version, textview_accel_details_energy, 42 | textview_accel_details_resolution, textview_accel_details_max_range; 43 | 44 | private SensorManager sensorManager; 45 | private Sensor accelerationSensor; 46 | private boolean accelerationSensorRegistered; 47 | private int sensorDelay = SensorManager.SENSOR_DELAY_NORMAL; 48 | 49 | private GraphView accelerationGraph; 50 | private LineGraphSeries graphSeriesX; 51 | private LineGraphSeries graphSeriesY; 52 | private LineGraphSeries graphSeriesZ; 53 | 54 | 55 | private BeschleunigungsSensorViewModel mViewModel; 56 | 57 | public static BeschleunigungsSensorFragment newInstance() { 58 | return new BeschleunigungsSensorFragment(); 59 | } 60 | 61 | @Override 62 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 63 | @Nullable Bundle savedInstanceState) { 64 | View view = inflater.inflate(R.layout.beschleunigungs_sensor_fragment, container, false); 65 | 66 | textview_accel_live_data_x = view.findViewById(R.id.textview_accel_live_data_x); 67 | textview_accel_live_data_y = view.findViewById(R.id.textview_accel_live_data_y); 68 | textview_accel_live_data_z = view.findViewById(R.id.textview_accel_live_data_z); 69 | textview_accel_live_data_accuracy = view.findViewById(R.id.textview_accel_live_data_accuracy); 70 | 71 | textview_accel_live_data_delay = view.findViewById(R.id.textview_accel_live_data_delay); 72 | textview_accel_live_data_delay.setOnClickListener(new View.OnClickListener() { 73 | @Override 74 | public void onClick(View view) { 75 | changeDelay(); 76 | } 77 | }); 78 | 79 | textview_accel_details_name = view.findViewById(R.id.textview_accel_details_name); 80 | textview_accel_details_manufacturer = view.findViewById(R.id.textview_accel_details_manufacturer); 81 | textview_accel_details_version = view.findViewById(R.id.textview_accel_details_version); 82 | textview_accel_details_energy = view.findViewById(R.id.textview_accel_details_energy); 83 | textview_accel_details_resolution = view.findViewById(R.id.textview_accel_details_resolution); 84 | textview_accel_details_max_range = view.findViewById(R.id.textview_accel_details_max_range); 85 | 86 | accelerationGraph = (GraphView) view.findViewById(R.id.acceleration_graph); 87 | graphSeriesX = new LineGraphSeries<>(new DataPoint[]{}); 88 | graphSeriesX.setTitle("x"); 89 | graphSeriesX.setColor(getResources().getColor(R.color.green)); 90 | graphSeriesY = new LineGraphSeries<>(new DataPoint[]{}); 91 | graphSeriesY.setTitle("y"); 92 | graphSeriesY.setColor(getResources().getColor(R.color.blue)); 93 | graphSeriesZ = new LineGraphSeries<>(new DataPoint[]{}); 94 | graphSeriesZ.setTitle("z"); 95 | graphSeriesZ.setColor(getResources().getColor(R.color.red)); 96 | 97 | return view; 98 | } 99 | 100 | @Override 101 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 102 | super.onActivityCreated(savedInstanceState); 103 | mViewModel = ViewModelProviders.of(this).get(BeschleunigungsSensorViewModel.class); 104 | 105 | 106 | // eine Instanz des SensorManagers 107 | sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); 108 | // der Beschleunigungssensor wird über den SensorManager instanziert 109 | if(sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) { 110 | accelerationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); 111 | } 112 | this.updateAccelDetails(); 113 | } 114 | 115 | @Override 116 | public void onStart() { 117 | registerListener(); 118 | initGraphView(); 119 | super.onStart(); 120 | } 121 | 122 | @Override 123 | public void onStop() { 124 | unregisterListener(); 125 | resetGraphView(); 126 | super.onStop(); 127 | } 128 | 129 | //------------------------------------------------------------------ 130 | // Sensor (Live Data) - Bereich 131 | //------------------------------------------------------------------ 132 | 133 | private void registerListener(){ 134 | sensorManager.registerListener(this, accelerationSensor, sensorDelay); 135 | this.updateDelayText(); 136 | accelerationSensorRegistered = true; 137 | } 138 | 139 | private void unregisterListener(){ 140 | sensorManager.unregisterListener(this); 141 | accelerationSensorRegistered = false; 142 | } 143 | 144 | @Override 145 | public void onAccuracyChanged(Sensor sensor, int accuracy) { 146 | // wenn sich die Genauigkeit des Beschleunigungssensors ändert 147 | if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) { 148 | this.updateAccuracy(accuracy); 149 | } 150 | } 151 | 152 | @Override 153 | public void onSensorChanged(SensorEvent event) { 154 | // nur wenn der Beschleunigungssensor neue Werte liefert 155 | if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { 156 | this.updateAccelerationData(event.timestamp, event.values[0], event.values[1], event.values[2]); 157 | } 158 | } 159 | 160 | private void updateAccelerationData(long timestamp, float x, float y, float z){ 161 | //String message = "Neue Messwerte (" + timestamp + "): " + x + " , " + y + " , " + z; 162 | //Log.d(TAG, message); 163 | 164 | String x_value = x + " " + getResources().getString(R.string.accel_unit); 165 | String y_value = y + " " + getResources().getString(R.string.accel_unit); 166 | String z_value = z + " " + getResources().getString(R.string.accel_unit); 167 | 168 | textview_accel_live_data_x.setText(x_value); 169 | textview_accel_live_data_y.setText(y_value); 170 | textview_accel_live_data_z.setText(z_value); 171 | 172 | graphSeriesX.appendData(new DataPoint(timestamp, x), true, Integer.MAX_VALUE); 173 | graphSeriesY.appendData(new DataPoint(timestamp, y), true, Integer.MAX_VALUE); 174 | graphSeriesZ.appendData(new DataPoint(timestamp, z), true, Integer.MAX_VALUE); 175 | 176 | 177 | } 178 | 179 | private void changeDelay(){ 180 | switch (sensorDelay){ 181 | case 0: 182 | sensorDelay = SensorManager.SENSOR_DELAY_GAME; 183 | break; 184 | case 1: 185 | sensorDelay = SensorManager.SENSOR_DELAY_UI; 186 | break; 187 | case 2: 188 | sensorDelay = SensorManager.SENSOR_DELAY_NORMAL; 189 | break; 190 | case 3: 191 | sensorDelay = SensorManager.SENSOR_DELAY_FASTEST; 192 | break; 193 | default: 194 | sensorDelay = SensorManager.SENSOR_DELAY_NORMAL; 195 | break; 196 | } 197 | unregisterListener(); 198 | registerListener(); 199 | } 200 | 201 | private void updateDelayText(){ 202 | String delayMsg = ""; 203 | switch (sensorDelay){ 204 | case 0: 205 | delayMsg += "FASTEST (0 ms)"; 206 | break; 207 | case 1: 208 | delayMsg += "GAME (20 ms)"; 209 | break; 210 | case 2: 211 | delayMsg += "UI (67 ms)"; 212 | break; 213 | case 3: 214 | delayMsg += "NORMAL (200 ms)"; 215 | break; 216 | default: 217 | delayMsg += "CUSTOM (" + sensorDelay + ")"; 218 | break; 219 | } 220 | textview_accel_live_data_delay.setText(delayMsg); 221 | } 222 | 223 | private void updateAccuracy(int accuracy){ 224 | Log.d(TAG, "Beschleunigungssensor neue Genauigkeit: " + accuracy); 225 | textview_accel_live_data_accuracy.setText(String.valueOf(accuracy)); 226 | } 227 | 228 | //------------------------------------------------------------------ 229 | // Graph - Bereich 230 | //------------------------------------------------------------------ 231 | 232 | private void initGraphView(){ 233 | accelerationGraph.getViewport().setScrollable(false); 234 | accelerationGraph.getViewport().setXAxisBoundsManual(true); 235 | accelerationGraph.getViewport().setMinX(0); 236 | accelerationGraph.getViewport().setMaxX(Integer.MAX_VALUE); 237 | accelerationGraph.getLegendRenderer().setVisible(true); 238 | accelerationGraph.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.TOP); 239 | accelerationGraph.getLegendRenderer().setTextColor(getResources().getColor(R.color.colorWhite)); 240 | accelerationGraph.getLegendRenderer().setTextSize(32); 241 | 242 | accelerationGraph.getViewport().setYAxisBoundsManual(true); 243 | accelerationGraph.getViewport().setMinY(-accelerationSensor.getMaximumRange()); 244 | accelerationGraph.getViewport().setMaxY(accelerationSensor.getMaximumRange()); 245 | 246 | accelerationGraph.addSeries(graphSeriesX); 247 | accelerationGraph.addSeries(graphSeriesY); 248 | accelerationGraph.addSeries(graphSeriesZ); 249 | 250 | accelerationGraph.getGridLabelRenderer().setHorizontalLabelsVisible(false); 251 | } 252 | 253 | private void resetGraphView(){ 254 | graphSeriesX.resetData(new DataPoint[]{}); 255 | graphSeriesY.resetData(new DataPoint[]{}); 256 | graphSeriesZ.resetData(new DataPoint[]{}); 257 | accelerationGraph.removeAllSeries(); 258 | } 259 | 260 | //------------------------------------------------------------------ 261 | // Details - Bereich 262 | //------------------------------------------------------------------ 263 | 264 | private void updateAccelDetails(){ 265 | textview_accel_details_name.setText(accelerationSensor.getName()); 266 | textview_accel_details_manufacturer.setText(accelerationSensor.getVendor()); 267 | textview_accel_details_version.setText(String.valueOf(accelerationSensor.getVersion())); 268 | String energy = String.valueOf(accelerationSensor.getPower()) + " " + getResources().getString(R.string.milliampere_unit); 269 | textview_accel_details_energy.setText(energy); 270 | String resolution = String.valueOf(accelerationSensor.getResolution()) + " " + getResources().getString(R.string.accel_unit); 271 | textview_accel_details_resolution.setText(resolution); 272 | String max_range = String.valueOf(accelerationSensor.getMaximumRange()) + " " + getResources().getString(R.string.accel_unit); 273 | textview_accel_details_max_range.setText(max_range); 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /app/src/main/java/com/tobias/schrittzaehlerfacharbeit/ui/beschleunigungssensor/BeschleunigungsSensorViewModel.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit.ui.beschleunigungssensor; 2 | 3 | import androidx.lifecycle.ViewModel; 4 | 5 | public class BeschleunigungsSensorViewModel extends ViewModel { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/tobias/schrittzaehlerfacharbeit/ui/schrittzaehler/SchrittzaehlerFragment.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit.ui.schrittzaehler; 2 | 3 | import androidx.cardview.widget.CardView; 4 | 5 | import android.hardware.Sensor; 6 | import android.hardware.SensorEvent; 7 | import android.hardware.SensorEventListener; 8 | import android.hardware.SensorManager; 9 | import android.os.Bundle; 10 | 11 | import androidx.annotation.NonNull; 12 | import androidx.annotation.Nullable; 13 | import androidx.fragment.app.Fragment; 14 | import androidx.lifecycle.ViewModelProvider; 15 | 16 | import android.util.Log; 17 | import android.view.LayoutInflater; 18 | import android.view.View; 19 | import android.view.ViewGroup; 20 | import android.widget.TextView; 21 | 22 | import com.tobias.schrittzaehlerfacharbeit.AccelerationData; 23 | import com.tobias.schrittzaehlerfacharbeit.R; 24 | import com.tobias.schrittzaehlerfacharbeit.StepDetector; 25 | import com.tobias.schrittzaehlerfacharbeit.StepListener; 26 | import com.tobias.schrittzaehlerfacharbeit.StepType; 27 | 28 | import java.util.ArrayList; 29 | import java.util.Locale; 30 | 31 | import static android.content.Context.SENSOR_SERVICE; 32 | 33 | /** 34 | * Das SchrittzaehlerFragment, in dem der Schrittzähler mit der UI verknüpft wird 35 | */ 36 | public class SchrittzaehlerFragment extends Fragment implements SensorEventListener, StepListener { 37 | 38 | private static final String TAG = "PedometerFragment"; 39 | 40 | private CardView cardViewToggleStepCounting; 41 | private TextView textView_amount_steps, textView_type_of_step, 42 | textView_pedometer_is_running, textView_pedometer_toggle_text; 43 | 44 | // Ergebnisse - Textviews 45 | private TextView textview_results_total_steps, textview_results_walking_steps, textview_results_jogging_steps, textview_results_running_steps, 46 | textview_results_total_distance, textview_results_average_speed, textview_results_average_frequency, textview_results_burned_calories, textview_results_total_moving_time; 47 | 48 | // ViewModel - speichert alle relevanten Daten hier. --> Gehen nicht verloren wenn 49 | // das Fragment neu erstellt wird (Orientierung ändert sich; App im Hintergrund etc.) 50 | private SchrittzaehlerViewModel mViewModel; 51 | 52 | /** 53 | * Returnt eine neue Instanz des SchrittzaehlerFragment's. 54 | * @return neue Instanz 55 | */ 56 | public static SchrittzaehlerFragment newInstance() { 57 | return new SchrittzaehlerFragment(); 58 | } 59 | 60 | /** 61 | * Wird bei Erstellung der Ansicht / GUI aufgerufen. 62 | * Returnt die Ansicht 63 | * @param inflater 64 | * @param container 65 | * @param savedInstanceState 66 | * @return View - neu generiertes GUI 67 | */ 68 | @Override 69 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, 70 | @Nullable Bundle savedInstanceState) { 71 | View view = inflater.inflate(R.layout.schrittzaehler_fragment, container, false); 72 | 73 | cardViewToggleStepCounting = view.findViewById(R.id.btn_pedometer_toggle_tracking); 74 | cardViewToggleStepCounting.setOnClickListener(new View.OnClickListener() { 75 | @Override 76 | public void onClick(View view) { 77 | if(mViewModel.isCountingSteps()) stopCounting(); 78 | else startCounting(); 79 | } 80 | }); 81 | textView_pedometer_toggle_text = view.findViewById(R.id.textview_pedometer_toggle_text); 82 | 83 | textView_amount_steps = view.findViewById(R.id.textview_amount_steps); 84 | textView_type_of_step = view.findViewById(R.id.textview_pedometer_type_of_step); 85 | textView_pedometer_is_running = view.findViewById(R.id.textview_pedometer_isRunning); 86 | 87 | textview_results_total_steps = view.findViewById(R.id.textview_results_total_steps); 88 | textview_results_walking_steps = view.findViewById(R.id.textview_results_walking_steps); 89 | textview_results_jogging_steps = view.findViewById(R.id.textview_results_jogging_steps); 90 | textview_results_running_steps = view.findViewById(R.id.textview_results_running_steps); 91 | textview_results_total_distance = view.findViewById(R.id.textview_results_total_distance); 92 | textview_results_average_speed = view.findViewById(R.id.textview_results_average_speed); 93 | textview_results_average_frequency = view.findViewById(R.id.textview_results_average_frequency); 94 | textview_results_burned_calories = view.findViewById(R.id.textview_results_burned_calories); 95 | textview_results_total_moving_time = view.findViewById(R.id.textview_results_total_moving_time); 96 | 97 | if(mViewModel.getSensorManager() == null) { 98 | mViewModel.setSensorManager((SensorManager) getActivity().getSystemService(SENSOR_SERVICE)); 99 | } 100 | if(mViewModel.getAccelerationSensor() == null){ 101 | if(mViewModel.getSensorManager().getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null) { 102 | mViewModel.setAccelerationSensor(mViewModel.getSensorManager().getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); 103 | } 104 | } 105 | if(mViewModel.getStepDetector() == null){ 106 | mViewModel.setStepDetector(new StepDetector()); 107 | } 108 | mViewModel.getStepDetector().registerStepListener(this); 109 | 110 | if(mViewModel.getAccelerationDataArrayList() == null){ 111 | mViewModel.setAccelerationDataArrayList(new ArrayList()); 112 | } 113 | 114 | if(mViewModel.isCountingSteps()){ 115 | textView_pedometer_toggle_text.setText(getResources().getText(R.string.disable_pedometer)); 116 | textView_pedometer_is_running.setText(getResources().getText(R.string.pedometer_running)); 117 | textView_pedometer_is_running.setTextColor(getResources().getColor(R.color.green)); 118 | textView_amount_steps.setText(String.valueOf(mViewModel.getAmountOfSteps())); 119 | mViewModel.getSensorManager().registerListener(this, mViewModel.getAccelerationSensor(), SensorManager.SENSOR_DELAY_NORMAL); 120 | } 121 | return view; 122 | } 123 | 124 | /** 125 | * Wird bei Erstellung des Fragments aufgerufen. Initialisiert das ViewModel. 126 | * @param savedInstanceState 127 | */ 128 | @Override 129 | public void onCreate(@Nullable Bundle savedInstanceState) { 130 | mViewModel = new ViewModelProvider(this).get(SchrittzaehlerViewModel.class); 131 | super.onCreate(savedInstanceState); 132 | } 133 | 134 | /** 135 | * Wird aufgerufen, bevor das Fragment zerstört wird. 136 | */ 137 | @Override 138 | public void onDetach() { 139 | mViewModel.getSensorManager().unregisterListener(this); 140 | super.onDetach(); 141 | } 142 | 143 | /** 144 | * Wird aufgerufen, wenn sich Messwerte eines Sensors ändern. 145 | * Da nur der Beschleunigungssensor registriert wird, kommen Werte nur von diesem. 146 | * @param sensorEvent SensorEvent mit allen neuen Messwerten, Zeitstempel und Urpsrung 147 | */ 148 | @Override 149 | public void onSensorChanged(SensorEvent sensorEvent) { 150 | AccelerationData newAccelerationData = new AccelerationData(); 151 | newAccelerationData.setX(sensorEvent.values[0]); 152 | newAccelerationData.setY(sensorEvent.values[1]); 153 | newAccelerationData.setZ(sensorEvent.values[2]); 154 | newAccelerationData.setTime(sensorEvent.timestamp); 155 | 156 | mViewModel.getAccelerationDataArrayList().add(newAccelerationData); 157 | mViewModel.getStepDetector().addAccelerationData(newAccelerationData); 158 | 159 | // Vorherige Version (jetzt in StepDetector gehandhabt): 160 | /* 161 | // bei 200 Millisekunden Delay ca. 5 Sekunden 162 | if(mViewModel.getAccelerationDataArrayList().size() >= 25){ 163 | sendDataArray(); 164 | }*/ 165 | } 166 | 167 | /* 168 | private void sendDataArray(){ 169 | mViewModel.getStepDetector().handleData(mViewModel.getAccelerationDataArrayList()); 170 | mViewModel.getAccelerationDataArrayList().clear(); 171 | }*/ 172 | 173 | /** 174 | * Wird aufgerufen, wenn sich die Genauigkeit des registrierten Sensors ändert. 175 | * @param sensor Sensor, von dem sich die Genauigkeit geändert hat. 176 | * @param i neue Genauigkeit 177 | */ 178 | @Override 179 | public void onAccuracyChanged(Sensor sensor, int i) { 180 | 181 | } 182 | 183 | /** 184 | * Wird aufgerufen, wenn im StepDetector ein Schritt erkannt wurde. Speichert Schritt im ViewModel. 185 | * @param accelerationData AccelerationData: Ein Datensatz des Beschleunigungssensors, welcher für einen Schritt steht. 186 | * @param stepType Enum StepType: Eine der drei Schritttypen aus dem Enum StepType. 187 | */ 188 | @Override 189 | public void step(AccelerationData accelerationData, StepType stepType) { 190 | // Step event coming back from StepDetector 191 | mViewModel.setAmountOfSteps(mViewModel.getAmountOfSteps() + 1); 192 | textView_amount_steps.setText(String.valueOf(mViewModel.getAmountOfSteps())); 193 | if(stepType == StepType.WALKING) { 194 | mViewModel.setWalkingSteps(mViewModel.getWalkingSteps() + 1); 195 | textView_type_of_step.setText(getResources().getText(R.string.walking)); 196 | } 197 | else if(stepType == StepType.JOGGING) { 198 | mViewModel.setJoggingSteps(mViewModel.getJoggingSteps() + 1); 199 | textView_type_of_step.setText(getResources().getText(R.string.jogging)); 200 | } 201 | else { 202 | mViewModel.setRunningSteps(mViewModel.getRunningSteps() + 1); 203 | textView_type_of_step.setText(getResources().getText(R.string.running)); 204 | } 205 | } 206 | 207 | /** 208 | * Berechnet Ergebnisse der letzten Messung. Nur Schätzungen. 209 | * Werden in der GUI angezeigt. 210 | */ 211 | private void calculateResults(){ 212 | int totalSteps = mViewModel.getAmountOfSteps(); 213 | textview_results_total_steps.setText(String.valueOf(totalSteps)); 214 | 215 | int walkingSteps = mViewModel.getWalkingSteps(); 216 | int joggingSteps = mViewModel.getJoggingSteps(); 217 | int runningSteps = mViewModel.getRunningSteps(); 218 | 219 | textview_results_walking_steps.setText(String.valueOf(walkingSteps)); 220 | textview_results_jogging_steps.setText(String.valueOf(joggingSteps)); 221 | textview_results_running_steps.setText(String.valueOf(runningSteps)); 222 | 223 | float totalDistance = walkingSteps * 0.5f + joggingSteps * 1.0f + runningSteps * 1.5f; 224 | String distance = totalDistance + " m"; 225 | textview_results_total_distance.setText(distance); 226 | 227 | float totalDuration = walkingSteps * 1.0f + joggingSteps * 0.75f + runningSteps * 0.5f; 228 | float hours = totalDuration / 3600; 229 | float minutes = (totalDuration % 3600) / 60; 230 | float seconds = totalDuration % 60; 231 | String duration = String.format(Locale.GERMANY,"%.0f", hours) + "h " + 232 | String.format(Locale.GERMANY, "%.0f", minutes) + "min " + 233 | String.format(Locale.GERMANY, "%.0f", seconds) + "s"; 234 | textview_results_total_moving_time.setText(duration); 235 | 236 | // Average speed: 237 | String averageSpeed = String.format(Locale.GERMANY, "%.2f", totalDistance / totalDuration) + " m/s"; 238 | textview_results_average_speed.setText(averageSpeed); 239 | 240 | // Average step frequency 241 | String averageStepFrequency = String.format(Locale.GERMANY, "%.0f", totalSteps / minutes) + " Schritte/min"; 242 | textview_results_average_frequency.setText(averageStepFrequency); 243 | 244 | // Calories 245 | float totalCaloriesBurned = walkingSteps + 0.05f + joggingSteps * 0.1f + runningSteps * 0.2f; 246 | String totalCalories = String.format(Locale.GERMANY, "%.0f", totalCaloriesBurned) + " Kalorien"; 247 | textview_results_burned_calories.setText(totalCalories); 248 | } 249 | 250 | /** 251 | * Setzt einige Daten zurück. 252 | */ 253 | private void resetUI(){ 254 | mViewModel.setAmountOfSteps(0); 255 | mViewModel.setWalkingSteps(0); 256 | mViewModel.setJoggingSteps(0); 257 | mViewModel.setRunningSteps(0); 258 | textView_amount_steps.setText(String.valueOf(mViewModel.getWalkingSteps())); 259 | } 260 | 261 | /** 262 | * Startet Schrittsensor. (Fragment wird im SensorManager registriert) 263 | */ 264 | private void startCounting(){ 265 | if(!mViewModel.isCountingSteps()){ 266 | try { 267 | resetUI(); 268 | mViewModel.getSensorManager().registerListener(this, mViewModel.getAccelerationSensor(), SensorManager.SENSOR_DELAY_NORMAL); 269 | mViewModel.setCountingSteps(true); 270 | textView_pedometer_toggle_text.setText(getResources().getText(R.string.disable_pedometer)); 271 | textView_pedometer_is_running.setText(getResources().getText(R.string.pedometer_running)); 272 | textView_pedometer_is_running.setTextColor(getResources().getColor(R.color.green)); 273 | } catch (Exception e){ 274 | Log.e(TAG, e.getMessage()); 275 | } 276 | } 277 | } 278 | 279 | /** 280 | * Stoppt Schrittsensor. (Fragment wird im SensorManager unregistriert) 281 | */ 282 | private void stopCounting(){ 283 | if(mViewModel.isCountingSteps()){ 284 | try { 285 | // Letzten verbliebenen Daten werden ebenfalls verarbeitet 286 | //sendDataArray(); 287 | 288 | mViewModel.getSensorManager().unregisterListener(this); 289 | mViewModel.setCountingSteps(false); 290 | calculateResults(); 291 | textView_pedometer_toggle_text.setText(getResources().getText(R.string.acitvate_pedometer)); 292 | textView_pedometer_is_running.setText(getResources().getText(R.string.pedometer_not_running)); 293 | textView_pedometer_is_running.setTextColor(getResources().getColor(R.color.red)); 294 | } catch (Exception e){ 295 | Log.d(TAG, e.getMessage()); 296 | } 297 | } 298 | } 299 | 300 | } 301 | -------------------------------------------------------------------------------- /app/src/main/java/com/tobias/schrittzaehlerfacharbeit/ui/schrittzaehler/SchrittzaehlerViewModel.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit.ui.schrittzaehler; 2 | 3 | import android.hardware.Sensor; 4 | import android.hardware.SensorManager; 5 | 6 | import androidx.lifecycle.ViewModel; 7 | 8 | import com.tobias.schrittzaehlerfacharbeit.AccelerationData; 9 | import com.tobias.schrittzaehlerfacharbeit.StepDetector; 10 | 11 | import java.util.ArrayList; 12 | 13 | public class SchrittzaehlerViewModel extends ViewModel { 14 | 15 | private boolean isCountingSteps; 16 | private SensorManager sensorManager; 17 | private Sensor accelerationSensor; 18 | 19 | private StepDetector stepDetector; 20 | private ArrayList accelerationDataArrayList = new ArrayList<>(); 21 | 22 | private int amountOfSteps; 23 | private int walkingSteps, joggingSteps, runningSteps; 24 | 25 | 26 | public boolean isCountingSteps() { 27 | return isCountingSteps; 28 | } 29 | 30 | public void setCountingSteps(boolean countingSteps) { 31 | isCountingSteps = countingSteps; 32 | } 33 | 34 | public SensorManager getSensorManager() { 35 | return sensorManager; 36 | } 37 | 38 | public void setSensorManager(SensorManager sensorManager) { 39 | this.sensorManager = sensorManager; 40 | } 41 | 42 | public Sensor getAccelerationSensor() { 43 | return accelerationSensor; 44 | } 45 | 46 | public void setAccelerationSensor(Sensor accelerationSensor) { 47 | this.accelerationSensor = accelerationSensor; 48 | } 49 | 50 | public StepDetector getStepDetector() { 51 | return stepDetector; 52 | } 53 | 54 | public void setStepDetector(StepDetector stepDetector) { 55 | this.stepDetector = stepDetector; 56 | } 57 | 58 | public ArrayList getAccelerationDataArrayList() { 59 | return accelerationDataArrayList; 60 | } 61 | 62 | public void setAccelerationDataArrayList(ArrayList accelerationDataArrayList) { 63 | this.accelerationDataArrayList = accelerationDataArrayList; 64 | } 65 | 66 | public int getAmountOfSteps() { 67 | return amountOfSteps; 68 | } 69 | 70 | public void setAmountOfSteps(int amountOfSteps) { 71 | this.amountOfSteps = amountOfSteps; 72 | } 73 | 74 | public int getWalkingSteps() { 75 | return walkingSteps; 76 | } 77 | 78 | public void setWalkingSteps(int walkingSteps) { 79 | this.walkingSteps = walkingSteps; 80 | } 81 | 82 | public int getJoggingSteps() { 83 | return joggingSteps; 84 | } 85 | 86 | public void setJoggingSteps(int joggingSteps) { 87 | this.joggingSteps = joggingSteps; 88 | } 89 | 90 | public int getRunningSteps() { 91 | return runningSteps; 92 | } 93 | 94 | public void setRunningSteps(int runningSteps) { 95 | this.runningSteps = runningSteps; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_directions_walk_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /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/res/drawable/ic_show_chart_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/relatives_koordinatensystem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/drawable/relatives_koordinatensystem.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | 20 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/beschleunigungs_sensor_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 18 | 19 | 28 | 33 | 34 | 39 | 40 | 45 | 46 | 51 | 56 | 57 | 62 | 63 | 68 | 69 | 74 | 75 | 76 | 82 | 83 | 90 | 91 | 98 | 99 | 106 | 107 | 108 | 115 | 119 | 120 | 121 | 125 | 131 | 140 | 141 | 145 | 151 | 163 | 164 | 165 | 166 | 167 | 168 | 177 | 182 | 183 | 188 | 189 | 194 | 195 | 200 | 201 | 202 | 203 | 204 | 205 | 214 | 219 | 220 | 225 | 226 | 231 | 232 | 238 | 239 | 244 | 250 | 259 | 260 | 265 | 271 | 280 | 281 | 286 | 292 | 301 | 302 | 307 | 313 | 322 | 323 | 328 | 334 | 343 | 344 | 348 | 354 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 376 | 379 | 380 | 381 | 382 | 383 | -------------------------------------------------------------------------------- /app/src/main/res/layout/schrittzaehler_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 17 | 18 | 27 | 32 | 33 | 38 | 39 | 44 | 45 | 51 | 52 | 57 | 58 | 68 | 69 | 70 | 74 | 80 | 89 | 90 | 91 | 96 | 97 | 104 | 105 | 106 | 107 | 108 | 109 | 122 | 130 | 131 | 132 | 133 | 142 | 147 | 148 | 152 | 157 | 163 | 164 | 165 | 166 | 171 | 172 | 177 | 178 | 183 | 184 | 194 | 195 | 196 | 200 | 206 | 207 | 211 | 217 | 226 | 227 | 231 | 237 | 246 | 247 | 251 | 257 | 266 | 267 | 272 | 278 | 287 | 288 | 292 | 298 | 307 | 308 | 312 | 318 | 327 | 328 | 332 | 338 | 347 | 348 | 352 | 358 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 380 | 381 | 384 | 385 | 386 | 387 | -------------------------------------------------------------------------------- /app/src/main/res/menu/bottom_nav_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /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/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/navigation/mobile_navigation.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/values-en-rUS/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | SchrittzaehlerFacharbeit 4 | Term Paper by Tobias Schnürpel 5 | Pedometer 6 | Accelerometer 7 | Pedometer 8 | Amount of Steps: 9 | Pedometer running 10 | Pedometer stopped 11 | Type of step: 12 | Duration of step: 13 | Activate Pedometer 14 | Disable Pedometer 15 | Results 16 | of the last measurement (estimated) 17 | Total steps: 18 | from that… 19 | Walking: 20 | Jogging / Fast walking: 21 | Running: 22 | Total distance: 23 | Average speed: 24 | Average frequency: 25 | Burned calories: 26 | Moving time: 27 | Walking 28 | Jogging 29 | Running 30 | Live data 31 | Graph 32 | Details 33 | Name: 34 | Manufacturer: 35 | Version 36 | Energy: 37 | Resolution: 38 | max. range: 39 | min. range: 40 | Accuracy: 41 | Delay: 42 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | #eeeeee 8 | #e0e0e0 9 | 10 | #2196f3 11 | #f44336 12 | #4caf50 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Facharbeit von Tobias Schnürpel 3 | 4 | SchrittzaehlerFacharbeit 5 | Schrittzähler 6 | Beschleunigungssensor 7 | 8 | Schrittzähler 9 | Schrittanzahl: 10 | Schrittzähler läuft 11 | Schrittzähler gestoppt 12 | Schrittart: 13 | Schrittdauer: 14 | 15 | Schrittzähler starten 16 | Schrittzähler stoppen 17 | 18 | Ergebnisse 19 | der letzten Messung (geschätzt) 20 | Schritte gesamt: 21 | davon… 22 | Gehen: 23 | Joggen / schnelles Gehen: 24 | Rennen: 25 | Gesamtdistanz: 26 | Durchschnittsgeschwindigkeit: 27 | Schrittfrequenz: 28 | Verbrannte Kalorien: 29 | Bewegungszeit: 30 | 31 | Gehen 32 | Joggen 33 | Rennen 34 | 35 | Live-Messwerte 36 | Graph 37 | m/s² 38 | mA 39 | Details 40 | 41 | Name: 42 | Hersteller: 43 | Version: 44 | Energie: 45 | Auflösung: 46 | max. Bereich: 47 | min. Bereich: 48 | Genauigkeit: 49 | Delay: 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/tobias/schrittzaehlerfacharbeit/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.tobias.schrittzaehlerfacharbeit; 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 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | jcenter() 7 | 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.6.0' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /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 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | 21 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 25 12:00:52 CET 2020 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-5.6.4-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pedometer_mockup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tobo9000/Android-Step-Counter/fbdd0ca05e7fa8054bcf0630c9ff7e8b006bd455/pedometer_mockup.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name='SchrittzaehlerFacharbeit' 3 | --------------------------------------------------------------------------------