├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-playstore.png
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── app_icon.png
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── values
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── strings.xml
│ │ │ ├── xml
│ │ │ │ └── network_security_config.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── layout
│ │ │ │ ├── activity_login.xml
│ │ │ │ ├── activity_register.xml
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── batt
│ │ │ │ └── data
│ │ │ │ ├── receiver
│ │ │ │ └── RestartReceiver.java
│ │ │ │ ├── service
│ │ │ │ ├── ActivityIntentService.java
│ │ │ │ └── BackgroundService.java
│ │ │ │ ├── RegisterActivity.java
│ │ │ │ ├── LoginActivity.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── batt
│ │ │ └── data
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── batt
│ │ └── data
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
├── google-services.json
└── build.gradle
├── settings.gradle
├── .idea
├── .gitignore
├── compiler.xml
├── misc.xml
└── jarRepositories.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name = "BattData"
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/ic_launcher-playstore.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/app_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/drawable/app_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Battery-Activity-Collection-App
2 | We are collecting various attributes from different APIs such as Android BatteryManager, Activity recognition, and location
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SnowStar0423/Battery-Activity-Collection-App/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Apr 18 08:47:55 MSK 2021
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-6.5-bin.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/network_security_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/test/java/com/batt/data/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.batt.data;
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 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 | #3F51B5
11 | #303F9F
12 | #FF4081
13 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/main/java/com/batt/data/receiver/RestartReceiver.java:
--------------------------------------------------------------------------------
1 | package com.batt.data.receiver;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | import com.batt.data.LoginActivity;
8 |
9 | public class RestartReceiver extends BroadcastReceiver {
10 |
11 | @Override
12 | public void onReceive(Context context, Intent intent) {
13 | if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
14 | Intent i = new Intent(context, LoginActivity.class);
15 | i.setAction(Intent.ACTION_MAIN);
16 | i.addCategory(Intent.CATEGORY_LAUNCHER);
17 | i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
18 | context.startActivity(i);
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/batt/data/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.batt.data;
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 | assertEquals("com.batt.data", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.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 |
--------------------------------------------------------------------------------
/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=-Xmx2048m -Dfile.encoding=UTF-8
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
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "392280278358",
4 | "project_id": "battdata-cd04a",
5 | "storage_bucket": "battdata-cd04a.appspot.com"
6 | },
7 | "client": [
8 | {
9 | "client_info": {
10 | "mobilesdk_app_id": "1:392280278358:android:7e6e00908c18d9db2502f7",
11 | "android_client_info": {
12 | "package_name": "com.batt.data"
13 | }
14 | },
15 | "oauth_client": [
16 | {
17 | "client_id": "392280278358-0kc55agi19sdl2qlg8dg7bo9594i2rmv.apps.googleusercontent.com",
18 | "client_type": 3
19 | }
20 | ],
21 | "api_key": [
22 | {
23 | "current_key": "AIzaSyCNYuR577l1FdmxBL44_SVO6ZhDNbaCl7A"
24 | }
25 | ],
26 | "services": {
27 | "appinvite_service": {
28 | "other_platform_oauth_client": [
29 | {
30 | "client_id": "392280278358-0kc55agi19sdl2qlg8dg7bo9594i2rmv.apps.googleusercontent.com",
31 | "client_type": 3
32 | }
33 | ]
34 | }
35 | }
36 | }
37 | ],
38 | "configuration_version": "1"
39 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea/workspace.xml
42 | .idea/tasks.xml
43 | .idea/gradle.xml
44 | .idea/assetWizardSettings.xml
45 | .idea/dictionaries
46 | .idea/libraries
47 | # Android Studio 3 in .gitignore file.
48 | .idea/caches
49 | .idea/modules.xml
50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
51 | .idea/navEditor.xml
52 |
53 | # Keystore files
54 | # Uncomment the following lines if you do not want to check your keystore files in.
55 | #*.jks
56 | #*.keystore
57 |
58 | # External native build folder generated in Android Studio 2.2 and later
59 | .externalNativeBuild
60 | .cxx/
61 |
62 | # Google Services (e.g. APIs or Firebase)
63 | # google-services.json
64 |
65 | # Freeline
66 | freeline.py
67 | freeline/
68 | freeline_project_description.json
69 |
70 | # fastlane
71 | fastlane/report.xml
72 | fastlane/Preview.html
73 | fastlane/screenshots
74 | fastlane/test_output
75 | fastlane/readme.md
76 |
77 | # Version control
78 | vcs.xml
79 |
80 | # lint
81 | lint/intermediates/
82 | lint/generated/
83 | lint/outputs/
84 | lint/tmp/
85 | # lint/reports/
86 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdkVersion 30
7 | buildToolsVersion "30.0.3"
8 |
9 | defaultConfig {
10 | applicationId "com.batt.data"
11 | minSdkVersion 21
12 | targetSdkVersion 30
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | }
30 |
31 | dependencies {
32 |
33 | implementation 'androidx.appcompat:appcompat:1.2.0'
34 | implementation 'com.google.android.material:material:1.3.0'
35 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
36 | testImplementation 'junit:junit:4.13.2'
37 | androidTestImplementation 'androidx.test.ext:junit:1.1.2'
38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
39 |
40 | implementation 'com.google.android.gms:play-services-location:18.0.0'
41 | implementation 'com.google.code.gson:gson:2.8.6'
42 | implementation 'org.apache.poi:poi:3.17'
43 | implementation "com.google.firebase:firebase-auth:20.0.4"
44 | implementation 'com.google.firebase:firebase-core:18.0.3'
45 | implementation platform('com.google.firebase:firebase-bom:27.1.0')
46 | implementation 'com.google.firebase:firebase-analytics'
47 | implementation 'com.google.firebase:firebase-storage:19.2.2'
48 | implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
49 | }
50 |
51 | apply plugin: 'com.google.gms.google-services'
--------------------------------------------------------------------------------
/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/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | BattData
3 | Time Since Boot:
4 | Battery Technology:
5 | Battery Temperature:
6 | Battery Voltage:
7 | Battery Health:
8 | Battery Scale:
9 | Battery Level:
10 | Power Plug:
11 | Battery Status:
12 |
13 | Charging
14 | Not Charging
15 | AC Power
16 | USB Plugged
17 | Cold
18 | Dead
19 | Good
20 | Overheat
21 | Over Voltage
22 | Not Plugged
23 | Unknown Health
24 | Unspecified failure
25 | Wireless Charging
26 | Stop
27 | Start
28 | Longitude:
29 |
30 | Track Activity
31 | %1$d%%
32 | On a bicycle
33 | On foot
34 | Running
35 | Still
36 | Tilting
37 | Unknown activity
38 | In a vehicle
39 | Walking
40 | Excel Export
41 |
42 | Enter your email
43 | Enter your password
44 | Login
45 | Email
46 | Password too short, enter minimum 6 characters!
47 | Authentication failed, check your email and password or sign up
48 | Don\'t you have an account yet?
49 | Register
50 | Already registered
51 | Login Me!
52 | Sign Up
53 | Enter your username
54 | Log In
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
33 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
44 |
45 |
48 |
51 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
25 |
26 |
34 |
35 |
42 |
43 |
51 |
59 |
65 |
70 |
78 |
79 |
80 |
81 |
82 |
83 |
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/batt/data/service/ActivityIntentService.java:
--------------------------------------------------------------------------------
1 | package com.batt.data.service;
2 |
3 | import android.app.IntentService;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.res.Resources;
7 | import android.preference.PreferenceManager;
8 | import android.util.Log;
9 |
10 | import com.batt.data.MainActivity;
11 | import com.batt.data.R;
12 | import com.google.android.gms.location.ActivityRecognitionResult;
13 | import com.google.android.gms.location.DetectedActivity;
14 | import com.google.gson.Gson;
15 | import com.google.gson.reflect.TypeToken;
16 |
17 | import java.lang.reflect.Type;
18 | import java.util.ArrayList;
19 |
20 | public class ActivityIntentService extends IntentService {
21 | private Context mContext;
22 | protected static final String TAG = "Activity Recognition";
23 | //Call the super IntentService constructor with the name for the worker thread//
24 | public ActivityIntentService() {
25 | super(TAG);
26 | }
27 | @Override
28 | public void onCreate() {
29 | super.onCreate();
30 | }
31 |
32 | @Override
33 | protected void onHandleIntent(Intent intent) {
34 | //Check whether the Intent contains activity recognition data//
35 | if (ActivityRecognitionResult.hasResult(intent)) {
36 |
37 | //If data is available, then extract the ActivityRecognitionResult from the Intent//
38 | ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
39 |
40 | //Get an array of DetectedActivity objects//
41 | ArrayList detectedActivities = (ArrayList) result.getProbableActivities();
42 | PreferenceManager.getDefaultSharedPreferences(this)
43 | .edit()
44 | .putString(MainActivity.DETECTED_ACTIVITY,
45 | detectedActivitiesToJson(detectedActivities))
46 | .apply();
47 | Log.e("Detected Activity: ", result.getProbableActivities().toString());
48 |
49 | }
50 | }
51 |
52 | static String getActivityString(Context context, int detectedActivityType) {
53 | Resources resources = context.getResources();
54 | switch(detectedActivityType) {
55 | case DetectedActivity.ON_BICYCLE:
56 | return resources.getString(R.string.bicycle);
57 | case DetectedActivity.ON_FOOT:
58 | return resources.getString(R.string.foot);
59 | case DetectedActivity.RUNNING:
60 | return resources.getString(R.string.running);
61 | case DetectedActivity.STILL:
62 | return resources.getString(R.string.still);
63 | case DetectedActivity.TILTING:
64 | return resources.getString(R.string.tilting);
65 | case DetectedActivity.WALKING:
66 | return resources.getString(R.string.walking);
67 | case DetectedActivity.IN_VEHICLE:
68 | return resources.getString(R.string.vehicle);
69 | default:
70 | return resources.getString(R.string.unknown_activity);
71 | }
72 | }
73 | public static int[] POSSIBLE_ACTIVITIES = {
74 | DetectedActivity.IN_VEHICLE,
75 | DetectedActivity.ON_BICYCLE,
76 | DetectedActivity.ON_FOOT,
77 | DetectedActivity.RUNNING,
78 | DetectedActivity.STILL,
79 | DetectedActivity.TILTING,
80 | DetectedActivity.UNKNOWN,
81 | DetectedActivity.WALKING
82 | };
83 | static String detectedActivitiesToJson(ArrayList detectedActivitiesList) {
84 | Type type = new TypeToken>() {}.getType();
85 | return new Gson().toJson(detectedActivitiesList, type);
86 | }
87 | public static ArrayList detectedActivitiesFromJson(String jsonArray) {
88 | Type listType = new TypeToken>(){}.getType();
89 | ArrayList detectedActivities = new Gson().fromJson(jsonArray, listType);
90 | if (detectedActivities == null) {
91 | detectedActivities = new ArrayList<>();
92 | }
93 | return detectedActivities;
94 | }
95 |
96 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
25 |
35 |
36 |
43 |
44 |
52 |
53 |
61 |
69 |
75 |
80 |
81 |
90 |
91 |
92 |
93 |
103 |
--------------------------------------------------------------------------------
/app/src/main/java/com/batt/data/RegisterActivity.java:
--------------------------------------------------------------------------------
1 | package com.batt.data;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.text.TextUtils;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.EditText;
10 | import android.widget.ProgressBar;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import androidx.annotation.NonNull;
15 | import androidx.appcompat.app.AppCompatActivity;
16 |
17 | import com.google.android.gms.tasks.OnCompleteListener;
18 | import com.google.android.gms.tasks.Task;
19 | import com.google.firebase.auth.AuthResult;
20 | import com.google.firebase.auth.FirebaseAuth;
21 |
22 | public class RegisterActivity extends AppCompatActivity {
23 | EditText inputUsername, inputEmail, inputPassword;
24 | TextView login;
25 | Button register_btn;
26 | ProgressBar progressBar;
27 | private String username, email, password;
28 | private FirebaseAuth auth;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_register);
34 |
35 | auth = FirebaseAuth.getInstance();
36 |
37 | inputUsername = findViewById(R.id.username);
38 | inputEmail = findViewById(R.id.email);
39 | inputPassword = findViewById(R.id.password);
40 | login = findViewById(R.id.login);
41 | progressBar = findViewById(R.id.progressBar);
42 | register_btn = findViewById(R.id.register_btn);
43 |
44 | register_btn.setOnClickListener(new View.OnClickListener() {
45 | @Override
46 | public void onClick(View v) {
47 | username = inputUsername.getText().toString().trim();
48 | email = inputEmail.getText().toString().trim();
49 | password = inputPassword.getText().toString().trim();
50 |
51 | if (TextUtils.isEmpty(username)) {
52 | Toast.makeText(getApplicationContext(), "Enter username", Toast.LENGTH_SHORT).show();
53 | return;
54 | }
55 |
56 | if (TextUtils.isEmpty(email)) {
57 | Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
58 | return;
59 | }
60 |
61 | if (TextUtils.isEmpty(password)) {
62 | Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
63 | return;
64 | }
65 |
66 | if (password.length() < 6) {
67 | Toast.makeText(getApplicationContext(), "Password too short, enter minimum 6 characters!", Toast.LENGTH_SHORT).show();
68 | return;
69 | }
70 |
71 | progressBar.setVisibility(View.VISIBLE);
72 | //create user
73 | auth.createUserWithEmailAndPassword(email, password)
74 | .addOnCompleteListener(RegisterActivity.this, new OnCompleteListener() {
75 | @Override
76 | public void onComplete(@NonNull Task task) {
77 | Toast.makeText(RegisterActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
78 | progressBar.setVisibility(View.GONE);
79 | // If sign in fails, display a message to the user. If sign in succeeds
80 | // the auth state listener will be notified and logic to handle the
81 | // signed in user can be handled in the listener.
82 | if (!task.isSuccessful()) {
83 | Log.e("error: ", String.valueOf(task.getException()));
84 | Toast.makeText(RegisterActivity.this, "Authentication failed." + task.getException(),
85 | Toast.LENGTH_SHORT).show();
86 | } else {
87 | startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
88 | finish();
89 | }
90 | }
91 | }
92 | );
93 | }
94 | });
95 |
96 | login.setOnClickListener(new View.OnClickListener() {
97 | @Override
98 | public void onClick(View v) {
99 | startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
100 | }
101 | });
102 |
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/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/batt/data/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.batt.data;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.content.pm.PackageManager;
7 | import android.os.Build;
8 | import android.os.Bundle;
9 | import android.provider.Settings;
10 | import android.text.TextUtils;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.EditText;
14 | import android.widget.ProgressBar;
15 | import android.widget.TextView;
16 | import android.widget.Toast;
17 |
18 | import androidx.annotation.NonNull;
19 | import androidx.annotation.RequiresApi;
20 | import androidx.appcompat.app.AppCompatActivity;
21 | import androidx.core.content.ContextCompat;
22 |
23 | import com.google.android.gms.tasks.OnCompleteListener;
24 | import com.google.android.gms.tasks.Task;
25 | import com.google.firebase.auth.AuthResult;
26 | import com.google.firebase.auth.FirebaseAuth;
27 |
28 |
29 | public class LoginActivity extends AppCompatActivity {
30 | EditText inputEmail, inputPassword;
31 | TextView register;
32 | Button login_btn;
33 | ProgressBar progressBar;
34 | private FirebaseAuth auth;
35 | SharedPreferences prefs;
36 | private SharedPreferences.Editor editor;
37 | String userID;
38 |
39 | @RequiresApi(api = Build.VERSION_CODES.M)
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.activity_login);
44 | if (!Settings.canDrawOverlays(getApplicationContext())) {
45 | startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION));
46 | Toast.makeText(this, "app is been restarting now", Toast.LENGTH_SHORT).show();
47 | }
48 |
49 | prefs = getSharedPreferences("info", MODE_PRIVATE);
50 | editor = prefs.edit();
51 | requestPermission();
52 |
53 | auth = FirebaseAuth.getInstance();
54 | authUser();
55 |
56 | inputEmail = findViewById(R.id.email);
57 | inputPassword = findViewById(R.id.password);
58 | login_btn = findViewById(R.id.login_btn);
59 | progressBar = findViewById(R.id.progressBar);
60 | register = findViewById(R.id.register);
61 |
62 | login_btn.setOnClickListener(new View.OnClickListener() {
63 | @Override
64 | public void onClick(View v) {
65 | String email = inputEmail.getText().toString();
66 | final String password = inputPassword.getText().toString();
67 |
68 | if (TextUtils.isEmpty(email)) {
69 | Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
70 | return;
71 | }
72 |
73 | if (TextUtils.isEmpty(password)) {
74 | Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
75 | return;
76 | }
77 |
78 | progressBar.setVisibility(View.VISIBLE);
79 |
80 | auth.signInWithEmailAndPassword(email, password)
81 | .addOnCompleteListener(LoginActivity.this, new OnCompleteListener() {
82 | @Override
83 | public void onComplete(@NonNull Task task) {
84 | progressBar.setVisibility(View.GONE);
85 | if (!task.isSuccessful()) {
86 | // there was an error
87 | if (password.length() < 6) {
88 | inputPassword.setError(getString(R.string.minimum_password));
89 | } else {
90 | Toast.makeText(LoginActivity.this, getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
91 | }
92 | } else {
93 | editor.putString("userID", auth.getCurrentUser().getUid() ).apply();
94 | Intent intent = new Intent(getApplicationContext(), MainActivity.class);
95 | startActivity(intent);
96 | finish();
97 | }
98 | }
99 | });
100 | }
101 | });
102 |
103 | register.setOnClickListener(new View.OnClickListener() {
104 | @Override
105 | public void onClick(View v) {
106 | Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
107 | startActivity(intent);
108 | finish();
109 | }
110 | });
111 | }
112 |
113 | private void authUser() {
114 | userID = prefs.getString("userID", null);
115 | if (userID != null) {
116 | startActivity(new Intent(LoginActivity.this, MainActivity.class));
117 | finish();
118 | }
119 | }
120 |
121 | private void requestPermission(){
122 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
123 | if ((ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) &&
124 | (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACTIVITY_RECOGNITION) != PackageManager.PERMISSION_GRANTED) &&
125 | (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) &&
126 | (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) &&
127 | (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.RECEIVE_BOOT_COMPLETED) != PackageManager.PERMISSION_GRANTED) ) {
128 | requestPermissions(new String[]{
129 | Manifest.permission.ACCESS_FINE_LOCATION,
130 | Manifest.permission.ACTIVITY_RECOGNITION,
131 | Manifest.permission.READ_EXTERNAL_STORAGE,
132 | Manifest.permission.WRITE_EXTERNAL_STORAGE,
133 | Manifest.permission.RECEIVE_BOOT_COMPLETED,
134 | }, 0);
135 | }
136 | }
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
29 |
32 |
33 |
39 |
40 |
45 |
46 |
47 |
50 |
51 |
57 |
58 |
63 |
64 |
65 |
68 |
69 |
75 |
76 |
81 |
82 |
83 |
86 |
87 |
93 |
94 |
99 |
100 |
101 |
104 |
105 |
111 |
112 |
117 |
118 |
119 |
122 |
123 |
129 |
130 |
135 |
136 |
137 |
140 |
141 |
147 |
148 |
153 |
154 |
155 |
156 |
157 |
167 |
168 |
174 |
175 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
--------------------------------------------------------------------------------
/app/src/main/java/com/batt/data/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.batt.data;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.annotation.RequiresApi;
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import androidx.core.app.ActivityCompat;
7 | import androidx.core.content.ContextCompat;
8 |
9 | import android.Manifest;
10 | import android.annotation.SuppressLint;
11 | import android.app.Activity;
12 | import android.app.AlarmManager;
13 | import android.app.PendingIntent;
14 | import android.content.BroadcastReceiver;
15 | import android.content.Context;
16 | import android.content.Intent;
17 | import android.content.IntentFilter;
18 | import android.content.SharedPreferences;
19 | import android.content.pm.PackageManager;
20 | import android.location.Location;
21 | import android.location.LocationListener;
22 | import android.location.LocationManager;
23 | import android.net.Uri;
24 | import android.os.BatteryManager;
25 | import android.os.Build;
26 | import android.os.Bundle;
27 | import android.os.Environment;
28 | import android.os.SystemClock;
29 | import android.preference.PreferenceManager;
30 | import android.util.Log;
31 | import android.view.View;
32 | import android.widget.Button;
33 | import android.widget.TextView;
34 | import android.widget.Toast;
35 |
36 | import com.batt.data.service.ActivityIntentService;
37 | import com.batt.data.service.BackgroundService;
38 | import com.google.android.gms.location.ActivityRecognitionClient;
39 | import com.google.android.gms.location.DetectedActivity;
40 | import com.google.android.gms.tasks.OnFailureListener;
41 | import com.google.android.gms.tasks.OnSuccessListener;
42 | import com.google.android.gms.tasks.Task;
43 | import com.google.firebase.auth.FirebaseAuth;
44 | import com.google.firebase.storage.FirebaseStorage;
45 | import com.google.firebase.storage.OnProgressListener;
46 | import com.google.firebase.storage.StorageReference;
47 | import com.google.firebase.storage.UploadTask;
48 |
49 | import org.apache.poi.hssf.usermodel.HSSFCellStyle;
50 | import org.apache.poi.hssf.usermodel.HSSFWorkbook;
51 | import org.apache.poi.hssf.util.HSSFColor;
52 | import org.apache.poi.ss.usermodel.Cell;
53 | import org.apache.poi.ss.usermodel.CellStyle;
54 | import org.apache.poi.ss.usermodel.FillPatternType;
55 | import org.apache.poi.ss.usermodel.HorizontalAlignment;
56 | import org.apache.poi.ss.usermodel.Row;
57 | import org.apache.poi.ss.usermodel.Sheet;
58 | import org.apache.poi.ss.usermodel.Workbook;
59 |
60 | import java.io.File;
61 | import java.io.FileOutputStream;
62 | import java.io.IOException;
63 | import java.util.ArrayList;
64 | import java.util.HashMap;
65 | import java.util.UUID;
66 |
67 | import static android.os.Environment.DIRECTORY_DOWNLOADS;
68 |
69 | public class MainActivity extends AppCompatActivity implements LocationListener, SharedPreferences.OnSharedPreferenceChangeListener {
70 |
71 | TextView showBatteryStatus, showPowerPlug, showBatterLevel, showBatteryScale, showBatteryHealth, showBatteryVoltage, showBatteryTemperature;
72 | Button start_btn, stop_btn;
73 | protected LocationManager locationManager;
74 | protected Context context;
75 | public String latitude, longitude;
76 | private Context mContext;
77 | public static final String DETECTED_ACTIVITY = ".DETECTED_ACTIVITY";
78 | private StorageReference storageReference;
79 | private ActivityRecognitionClient mActivityRecognitionClient;
80 |
81 |
82 | @RequiresApi(api = Build.VERSION_CODES.Q)
83 | @Override
84 | protected void onCreate(Bundle savedInstanceState) {
85 | super.onCreate(savedInstanceState);
86 | setContentView(R.layout.activity_main);
87 |
88 | mContext = this;
89 | // get the Firebase storage reference
90 | storageReference = FirebaseStorage.getInstance().getReference();
91 | mActivityRecognitionClient = new ActivityRecognitionClient(this);
92 |
93 | showBatteryStatus = findViewById(R.id.showBatteryStatus);
94 | showPowerPlug = findViewById(R.id.showPowerPlug);
95 | showBatterLevel = findViewById(R.id.showBatterLevel);
96 | showBatteryScale = findViewById(R.id.showBatteryScale);
97 | showBatteryHealth = findViewById(R.id.showBatteryHealth);
98 | showBatteryVoltage = findViewById(R.id.showBatteryVoltage);
99 | showBatteryTemperature = findViewById(R.id.showBatteryTemperature);
100 | start_btn = findViewById(R.id.start_btn);
101 | stop_btn = findViewById(R.id.stop_btn);
102 |
103 | // startAlert();
104 |
105 | Intent intent = new Intent(this, BackgroundService.class);
106 | startService(intent);
107 |
108 | locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
109 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
110 | // TODO: Consider calling
111 | // ActivityCompat#requestPermissions
112 | // here to request the missing permissions, and then overriding
113 | // public void onRequestPermissionsResult(int requestCode, String[] permissions,
114 | // int[] grantResults)
115 | // to handle the case where the user grants the permission. See the documentation
116 | // for ActivityCompat#requestPermissions for more details.
117 | return;
118 | }
119 | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
120 |
121 | Intent i = new Intent(getApplicationContext(), ActivityIntentService.class);
122 | startService(i);
123 |
124 | ArrayList detectedActivities = ActivityIntentService.detectedActivitiesFromJson(
125 | PreferenceManager.getDefaultSharedPreferences(this).getString(
126 | DETECTED_ACTIVITY, ""));
127 |
128 |
129 | }
130 |
131 | @Override
132 | public void onLocationChanged(@NonNull Location location) {
133 | longitude = String.valueOf(location.getLongitude());
134 | }
135 |
136 | public void requestUpdatesHandler(View view) {
137 | Log.e("dd", "click");
138 | //Set the activity detection interval. I’m using 3 seconds//
139 | Task task = mActivityRecognitionClient.requestActivityUpdates(
140 | 3000,
141 | getActivityDetectionPendingIntent());
142 | task.addOnSuccessListener(new OnSuccessListener() {
143 | @Override
144 | public void onSuccess(Void result) {
145 | updateDetectedActivitiesList();
146 | }
147 | });
148 | }
149 | private PendingIntent getActivityDetectionPendingIntent() {
150 | //Send the activity data to our DetectedActivitiesIntentService class//
151 | Intent intent = new Intent(this, ActivityIntentService.class);
152 | return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
153 |
154 | }
155 |
156 | protected void updateDetectedActivitiesList() {
157 | ArrayList detectedActivities = ActivityIntentService.detectedActivitiesFromJson(
158 | PreferenceManager.getDefaultSharedPreferences(mContext)
159 | .getString(DETECTED_ACTIVITY, ""));
160 |
161 | HashMap detectedActivitiesMap = new HashMap<>();
162 | for (DetectedActivity activity : detectedActivities) {
163 | detectedActivitiesMap.put(activity.getType(), activity.getConfidence());
164 | }
165 |
166 | ArrayList temporaryList = new ArrayList<>();
167 | for (int i = 0; i < ActivityIntentService.POSSIBLE_ACTIVITIES.length; i++) {
168 | int confidence = detectedActivitiesMap.containsKey(ActivityIntentService.POSSIBLE_ACTIVITIES[i]) ?
169 | detectedActivitiesMap.get(ActivityIntentService.POSSIBLE_ACTIVITIES[i]) : 0;
170 |
171 | //Add the object to a temporaryList//
172 | temporaryList.add(new
173 | DetectedActivity(ActivityIntentService.POSSIBLE_ACTIVITIES[i],
174 | confidence));
175 | }
176 | }
177 |
178 | @Override
179 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
180 | if (key.equals(DETECTED_ACTIVITY)) {
181 | updateDetectedActivitiesList();
182 | }
183 | }
184 |
185 | public void startAlert(){
186 | Intent intent = new Intent(this, LoginActivity.class);
187 | int mPendingIntentId = 123456;
188 | PendingIntent pendingIntent = PendingIntent.getActivity(this.getApplicationContext(), mPendingIntentId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
189 | AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
190 | alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 10000, pendingIntent);
191 | System.exit(0);
192 | Toast.makeText(this, "Alarm set in 60 seconds",Toast.LENGTH_LONG).show();
193 | }
194 |
195 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/app/src/main/java/com/batt/data/service/BackgroundService.java:
--------------------------------------------------------------------------------
1 | package com.batt.data.service;
2 |
3 | import android.Manifest;
4 | import android.annotation.SuppressLint;
5 | import android.app.PendingIntent;
6 | import android.app.Service;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.IntentFilter;
10 | import android.content.SharedPreferences;
11 | import android.content.pm.PackageManager;
12 | import android.location.Location;
13 | import android.location.LocationListener;
14 | import android.location.LocationManager;
15 | import android.net.Uri;
16 | import android.os.BatteryManager;
17 | import android.os.Build;
18 | import android.os.Environment;
19 | import android.os.Handler;
20 | import android.os.IBinder;
21 | import android.preference.PreferenceManager;
22 | import android.util.Log;
23 | import android.widget.Toast;
24 |
25 | import androidx.annotation.NonNull;
26 | import androidx.annotation.RequiresApi;
27 | import androidx.core.app.ActivityCompat;
28 |
29 | import com.google.android.gms.location.ActivityRecognitionClient;
30 | import com.google.android.gms.location.DetectedActivity;
31 | import com.google.android.gms.tasks.OnFailureListener;
32 | import com.google.android.gms.tasks.OnSuccessListener;
33 | import com.google.android.gms.tasks.Task;
34 | import com.google.firebase.storage.FirebaseStorage;
35 | import com.google.firebase.storage.OnProgressListener;
36 | import com.google.firebase.storage.StorageReference;
37 | import com.google.firebase.storage.UploadTask;
38 |
39 | import org.apache.poi.hssf.usermodel.HSSFWorkbook;
40 | import org.apache.poi.ss.usermodel.Cell;
41 | import org.apache.poi.ss.usermodel.Row;
42 | import org.apache.poi.ss.usermodel.Sheet;
43 | import org.apache.poi.ss.usermodel.Workbook;
44 |
45 | import java.io.File;
46 | import java.io.FileInputStream;
47 | import java.io.FileNotFoundException;
48 | import java.io.FileOutputStream;
49 | import java.io.IOException;
50 | import java.time.LocalDateTime;
51 | import java.time.format.DateTimeFormatter;
52 | import java.util.ArrayList;
53 | import java.util.HashMap;
54 | import java.util.UUID;
55 |
56 | import static android.os.Environment.DIRECTORY_DOWNLOADS;
57 | import static com.batt.data.MainActivity.DETECTED_ACTIVITY;
58 |
59 | public class BackgroundService extends Service implements LocationListener {
60 |
61 | public Context context = this;
62 | public Handler handler = null;
63 | public static Runnable runnable = null;
64 | private static String TAG = "Background Service -> ";
65 | private StorageReference storageReference;
66 | String latitude, longitude, altitude;
67 | int ACTION_CHARGING, ACTION_DISCHARGING, BATTERY_HEALTH_COLD, BATTERY_HEALTH_DEAD, BATTERY_HEALTH_GOOD, BATTERY_HEALTH_OVERHEAT, BATTERY_HEALTH_OVER_VOLTAGE,
68 | BATTERY_HEALTH_UNKNOWN, BATTERY_HEALTH_UNSPECIFIED_FAILURE, BATTERY_PLUGGED_AC, BATTERY_PLUGGED_USB, BATTERY_PLUGGED_WIRELESS, BATTERY_PROPERTY_CAPACITY,
69 | BATTERY_PROPERTY_CHARGE_COUNTER, BATTERY_PROPERTY_STATUS, BATTERY_STATUS_CHARGING, BATTERY_STATUS_DISCHARGING,
70 | BATTERY_STATUS_FULL, BATTERY_STATUS_NOT_CHARGING, BATTERY_STATUS_UNKNOWN, EXTRA_LEVEL, EXTRA_SCALE, EXTRA_VOLTAGE, EXTRA_PLUGGED, EXTRA_STATUS, EXTRA_HEALTH,
71 | EXTRA_BATTERY_LOW, EXTRA_ICON_SMALL,
72 | intProperty, IN_VEHICLE, ON_BICYCLE, ON_FOOT, RUNNING, STILL, TILTING, UNKNOWN, WALKING;
73 | long chargingTime, longProperty;
74 | float BATTERY_PROPERTY_CURRENT_NOW, EXTRA_TEMPERATURE;
75 | boolean _isCharging;
76 | protected LocationManager locationManager;
77 | SharedPreferences prefs;
78 | private SharedPreferences.Editor editor;
79 | private String userID, currentDate;
80 | private ActivityRecognitionClient mActivityRecognitionClient;
81 | ArrayList temporaryList = new ArrayList<>();
82 |
83 | @Override
84 | public IBinder onBind(Intent intent) {
85 | return null;
86 | }
87 |
88 |
89 | @SuppressLint("CommitPrefEdits")
90 | @Override
91 | public void onCreate() {
92 |
93 | prefs = getSharedPreferences("info", MODE_PRIVATE);
94 | editor = prefs.edit();
95 | userID = prefs.getString("userID", "tb1BrFsDa6bq3zomteJejOxmBJg2");
96 | storageReference = FirebaseStorage.getInstance().getReference();
97 | mActivityRecognitionClient = new ActivityRecognitionClient(this);
98 | /* GPS Location Initialize*/
99 | locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
100 | if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
101 | // TODO: Consider calling
102 | // ActivityCompat#requestPermissions
103 | // here to request the missing permissions, and then overriding
104 | // public void onRequestPermissionsResult(int requestCode, String[] permissions,
105 | // int[] grantResults)
106 | // to handle the case where the user grants the permission. See the documentation
107 | // for ActivityCompat#requestPermissions for more details.
108 | return;
109 | }
110 | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
111 |
112 |
113 |
114 |
115 | handler = new Handler();
116 | runnable = new Runnable() {
117 | @RequiresApi(api = Build.VERSION_CODES.O)
118 | public void run() {
119 | // Toast.makeText(context, "Service is still running", Toast.LENGTH_LONG).show();
120 |
121 | UpdatesHandler();
122 | new Handler().postDelayed(new Runnable() {
123 | @RequiresApi(api = Build.VERSION_CODES.P)
124 | @Override
125 | public void run() {
126 | IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
127 | Intent batteryInfo = context.registerReceiver(null, intentFilter);
128 |
129 |
130 |
131 | ACTION_CHARGING = batteryInfo.getIntExtra(BatteryManager.ACTION_CHARGING, 0);
132 | ACTION_DISCHARGING = batteryInfo.getIntExtra(BatteryManager.ACTION_DISCHARGING, 0);
133 | BATTERY_HEALTH_COLD = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_HEALTH_COLD), 0);
134 | BATTERY_HEALTH_DEAD = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_HEALTH_DEAD), 0);
135 | BATTERY_HEALTH_GOOD = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_HEALTH_GOOD), 0);
136 | BATTERY_HEALTH_OVERHEAT = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_HEALTH_OVERHEAT), 0);
137 | BATTERY_HEALTH_OVER_VOLTAGE = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE), 0);
138 | BATTERY_HEALTH_UNKNOWN = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_HEALTH_UNKNOWN), 0);
139 | BATTERY_HEALTH_UNSPECIFIED_FAILURE = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE), 0);
140 | BATTERY_PLUGGED_AC = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_PLUGGED_AC), 0);
141 | BATTERY_PLUGGED_USB = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_PLUGGED_USB), 0);
142 | BATTERY_PLUGGED_WIRELESS = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_PLUGGED_WIRELESS), 0);
143 | BATTERY_PROPERTY_CAPACITY = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_PROPERTY_CAPACITY), 0);
144 | BATTERY_PROPERTY_CHARGE_COUNTER = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER), 0);
145 | BATTERY_PROPERTY_CURRENT_NOW = (float)batteryInfo.getIntExtra(String.valueOf(BatteryManager. BATTERY_PROPERTY_CURRENT_NOW), 0);
146 | BATTERY_PROPERTY_STATUS = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_PROPERTY_STATUS), 0);
147 | BATTERY_STATUS_CHARGING = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_STATUS_CHARGING), 0);
148 | BATTERY_STATUS_DISCHARGING = batteryInfo.getIntExtra(String.valueOf(BatteryManager. BATTERY_STATUS_DISCHARGING), 0);
149 | BATTERY_STATUS_FULL = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_STATUS_FULL), 0);
150 | BATTERY_STATUS_NOT_CHARGING = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_STATUS_NOT_CHARGING), 0);
151 | BATTERY_STATUS_UNKNOWN = batteryInfo.getIntExtra(String.valueOf(BatteryManager.BATTERY_STATUS_UNKNOWN), 0);
152 | boolean battery_low = batteryInfo.getBooleanExtra(BatteryManager.EXTRA_BATTERY_LOW, false);
153 | if (!battery_low) {
154 | EXTRA_BATTERY_LOW = 0;
155 | } else {
156 | EXTRA_BATTERY_LOW = 1;
157 | }
158 | EXTRA_HEALTH = batteryInfo.getIntExtra(BatteryManager.EXTRA_HEALTH, 0);
159 | if (EXTRA_HEALTH == BatteryManager.BATTERY_HEALTH_COLD) {
160 | BATTERY_HEALTH_COLD = 1;
161 | } else if (EXTRA_HEALTH == BatteryManager.BATTERY_HEALTH_GOOD) {
162 | BATTERY_HEALTH_GOOD = 1;
163 | } else if (EXTRA_HEALTH == BatteryManager.BATTERY_HEALTH_DEAD) {
164 | BATTERY_HEALTH_DEAD = 1;
165 | } else if (EXTRA_HEALTH == BatteryManager.BATTERY_HEALTH_OVERHEAT) {
166 | BATTERY_HEALTH_OVERHEAT = 1;
167 | } else if (EXTRA_HEALTH == BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE) {
168 | BATTERY_HEALTH_OVER_VOLTAGE = 1;
169 | } else if (EXTRA_HEALTH == BatteryManager.BATTERY_HEALTH_UNKNOWN) {
170 | BATTERY_HEALTH_UNKNOWN = 1;
171 | } else {
172 | BATTERY_HEALTH_UNSPECIFIED_FAILURE = 1;
173 | }
174 | EXTRA_ICON_SMALL = batteryInfo.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, 0);
175 | EXTRA_LEVEL = batteryInfo.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
176 | EXTRA_PLUGGED = batteryInfo.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
177 | if (EXTRA_PLUGGED == BatteryManager.BATTERY_PLUGGED_AC) {
178 | BATTERY_PLUGGED_AC = 1;
179 | } else if (EXTRA_PLUGGED == BatteryManager.BATTERY_PLUGGED_USB) {
180 | BATTERY_PLUGGED_USB = 1;
181 | } else {
182 | BATTERY_PLUGGED_WIRELESS = 1;
183 | }
184 | EXTRA_SCALE = batteryInfo.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
185 | EXTRA_STATUS = batteryInfo.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
186 | if (EXTRA_STATUS == BatteryManager.BATTERY_STATUS_CHARGING) {
187 | BATTERY_STATUS_CHARGING = 1;
188 | } else if (EXTRA_STATUS == BatteryManager.BATTERY_STATUS_DISCHARGING) {
189 | BATTERY_STATUS_DISCHARGING = 1;
190 | } else if (EXTRA_STATUS == BatteryManager.BATTERY_STATUS_FULL) {
191 | BATTERY_STATUS_FULL = 1;
192 | } else if (EXTRA_STATUS == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
193 | BATTERY_STATUS_NOT_CHARGING = 1;
194 | } else {
195 | BATTERY_STATUS_UNKNOWN = 1;
196 | }
197 | EXTRA_TEMPERATURE = (float)((batteryInfo.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0))/10);
198 | EXTRA_VOLTAGE = batteryInfo.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);
199 |
200 | if (EXTRA_STATUS == BatteryManager.BATTERY_STATUS_CHARGING || EXTRA_STATUS == BatteryManager.BATTERY_STATUS_FULL) {
201 | ACTION_CHARGING = 1;
202 | } else {
203 | ACTION_DISCHARGING = 1;
204 | }
205 |
206 |
207 |
208 | Log.e("CURRENT_NOW", String.valueOf(BATTERY_PROPERTY_CURRENT_NOW));
209 | Log.e("EXTRA_TEMPERATURE", String.valueOf(EXTRA_TEMPERATURE));
210 |
211 | DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm");
212 | LocalDateTime now = LocalDateTime.now();
213 | currentDate = dtf.format(now);
214 |
215 | if (userID != null) {
216 | try {
217 | saveExcelFile();
218 | } catch (FileNotFoundException e) {
219 | e.printStackTrace();
220 | } catch (IOException e) {
221 | e.printStackTrace();
222 | }
223 | }
224 | }
225 | }, 10000);
226 |
227 | //43200000
228 | handler.postDelayed(runnable, 1200000);
229 | }
230 | };
231 | handler.postDelayed(runnable, 15000);
232 | }
233 |
234 | @Override
235 | public void onDestroy() {
236 | /* IF YOU WANT THIS SERVICE KILLED WITH THE APP THEN UNCOMMENT THE FOLLOWING LINE */
237 | Log.e("Service: ", "Stopped");
238 | // handler.removeCallbacks(runnable);
239 | // Toast.makeText(this, "Service stopped", Toast.LENGTH_SHORT).show();
240 | // stopSelf();
241 | // super.onDestroy();
242 | }
243 |
244 | @Override
245 | public void onStart(Intent intent, int startid) {
246 | Toast.makeText(this, "Service started by user.", Toast.LENGTH_SHORT).show();
247 | }
248 |
249 |
250 | public void saveExcelFile() throws IOException {
251 | String path;
252 | File dir;
253 | if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
254 | Log.e("Failed", "Storage not available or read only");
255 | return;
256 | }
257 | boolean success = false;
258 |
259 |
260 | path = Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS).getAbsolutePath()+"/";
261 | dir = new File(path);
262 | if (!dir.exists()) {
263 | dir.mkdirs();
264 | }
265 | File file = new File(path, "myExcel.csv");
266 | FileInputStream inputStream = null;
267 |
268 | //New Workbook
269 | Workbook wb = new HSSFWorkbook();
270 | Sheet sheet1 = null;
271 | Cell c = null;
272 |
273 | // Generate column headings
274 | Row row = null;
275 | int k = prefs.getInt("rowNumber", 0);
276 | if (k == 0 || !file.exists()) {
277 | sheet1 = wb.createSheet("myData");
278 | row = sheet1.createRow(0);
279 |
280 | for(int j = 0; j < info_lists.length; j++){
281 | c = row.createCell(j);
282 | c.setCellValue(info_lists[j]);
283 | sheet1.setColumnWidth(j, (15 * 300));
284 | }
285 | row = sheet1.createRow(k+1);
286 | c = row.createCell(0);
287 | c.setCellValue(currentDate);
288 | c = row.createCell(1);
289 | c.setCellValue(ACTION_CHARGING);
290 | c = row.createCell(2);
291 | c.setCellValue(ACTION_DISCHARGING);
292 | c = row.createCell(3);
293 | c.setCellValue(BATTERY_HEALTH_COLD);
294 | c = row.createCell(4);
295 | c.setCellValue(BATTERY_HEALTH_DEAD);
296 | c = row.createCell(5);
297 | c.setCellValue(BATTERY_HEALTH_GOOD);
298 | c = row.createCell(6);
299 | c.setCellValue(BATTERY_HEALTH_OVERHEAT);
300 | c = row.createCell(7);
301 | c.setCellValue(BATTERY_HEALTH_OVER_VOLTAGE);
302 | c = row.createCell(8);
303 | c.setCellValue(BATTERY_HEALTH_UNKNOWN);
304 | c = row.createCell(9);
305 | c.setCellValue(BATTERY_HEALTH_UNSPECIFIED_FAILURE);
306 | c = row.createCell(10);
307 | c.setCellValue(BATTERY_PLUGGED_AC);
308 | c = row.createCell(11);
309 | c.setCellValue(BATTERY_PLUGGED_USB);
310 | c = row.createCell(12);
311 | c.setCellValue(BATTERY_PLUGGED_WIRELESS);
312 | c = row.createCell(13);
313 | c.setCellValue(BATTERY_PROPERTY_CAPACITY);
314 | c = row.createCell(14);
315 | c.setCellValue(BATTERY_PROPERTY_CHARGE_COUNTER);
316 | c = row.createCell(15);
317 | c.setCellValue(BATTERY_PROPERTY_CURRENT_NOW);
318 | c = row.createCell(16);
319 | c.setCellValue(BATTERY_PROPERTY_STATUS);
320 | c = row.createCell(17);
321 | c.setCellValue(BATTERY_STATUS_CHARGING);
322 | c = row.createCell(18);
323 | c.setCellValue(BATTERY_STATUS_DISCHARGING);
324 | c = row.createCell(19);
325 | c.setCellValue(BATTERY_STATUS_FULL);
326 | c = row.createCell(20);
327 | c.setCellValue(BATTERY_STATUS_NOT_CHARGING);
328 | c = row.createCell(21);
329 | c.setCellValue(BATTERY_STATUS_UNKNOWN);
330 | c = row.createCell(22);
331 | c.setCellValue(EXTRA_BATTERY_LOW);
332 | c = row.createCell(23);
333 | c.setCellValue(EXTRA_HEALTH);
334 | c = row.createCell(24);
335 | c.setCellValue(EXTRA_ICON_SMALL);
336 | c = row.createCell(25);
337 | c.setCellValue(EXTRA_LEVEL);
338 | c = row.createCell(26);
339 | c.setCellValue(EXTRA_PLUGGED);
340 | c = row.createCell(27);
341 | c.setCellValue(EXTRA_SCALE);
342 | c = row.createCell(28);
343 | c.setCellValue(EXTRA_STATUS);
344 | c = row.createCell(29);
345 | c.setCellValue(EXTRA_TEMPERATURE);
346 | c = row.createCell(30);
347 | c.setCellValue(EXTRA_VOLTAGE);
348 | c = row.createCell(31);
349 | c.setCellValue(temporaryList.get(0).getConfidence());
350 | c = row.createCell(32);
351 | c.setCellValue(temporaryList.get(1).getConfidence());
352 | c = row.createCell(33);
353 | c.setCellValue(temporaryList.get(2).getConfidence());
354 | c = row.createCell(34);
355 | c.setCellValue(temporaryList.get(3).getConfidence());
356 | c = row.createCell(35);
357 | c.setCellValue(temporaryList.get(4).getConfidence());
358 | c = row.createCell(36);
359 | c.setCellValue(temporaryList.get(5).getConfidence());
360 | c = row.createCell(37);
361 | c.setCellValue(temporaryList.get(6).getConfidence());
362 | c = row.createCell(38);
363 | c.setCellValue(temporaryList.get(7).getConfidence());
364 | c = row.createCell(39);
365 | c.setCellValue(latitude);
366 | c = row.createCell(40);
367 | c.setCellValue(longitude);
368 | c = row.createCell(41);
369 | c.setCellValue(altitude);
370 |
371 | } else {
372 | inputStream = new FileInputStream(file);
373 | wb = new HSSFWorkbook(inputStream);
374 | sheet1 = wb.getSheet("myData");
375 | row = sheet1.createRow(k+1);
376 | c = row.createCell(0);
377 | c.setCellValue(currentDate);
378 | c = row.createCell(1);
379 | c.setCellValue(ACTION_CHARGING);
380 | c = row.createCell(2);
381 | c.setCellValue(ACTION_DISCHARGING);
382 | c = row.createCell(3);
383 | c.setCellValue(BATTERY_HEALTH_COLD);
384 | c = row.createCell(4);
385 | c.setCellValue(BATTERY_HEALTH_DEAD);
386 | c = row.createCell(5);
387 | c.setCellValue(BATTERY_HEALTH_GOOD);
388 | c = row.createCell(6);
389 | c.setCellValue(BATTERY_HEALTH_OVERHEAT);
390 | c = row.createCell(7);
391 | c.setCellValue(BATTERY_HEALTH_OVER_VOLTAGE);
392 | c = row.createCell(8);
393 | c.setCellValue(BATTERY_HEALTH_UNKNOWN);
394 | c = row.createCell(9);
395 | c.setCellValue(BATTERY_HEALTH_UNSPECIFIED_FAILURE);
396 | c = row.createCell(10);
397 | c.setCellValue(BATTERY_PLUGGED_AC);
398 | c = row.createCell(11);
399 | c.setCellValue(BATTERY_PLUGGED_USB);
400 | c = row.createCell(12);
401 | c.setCellValue(BATTERY_PLUGGED_WIRELESS);
402 | c = row.createCell(13);
403 | c.setCellValue(BATTERY_PROPERTY_CAPACITY);
404 | c = row.createCell(14);
405 | c.setCellValue(BATTERY_PROPERTY_CHARGE_COUNTER);
406 | c = row.createCell(15);
407 | c.setCellValue(BATTERY_PROPERTY_CURRENT_NOW);
408 | c = row.createCell(16);
409 | c.setCellValue(BATTERY_PROPERTY_STATUS);
410 | c = row.createCell(17);
411 | c.setCellValue(BATTERY_STATUS_CHARGING);
412 | c = row.createCell(18);
413 | c.setCellValue(BATTERY_STATUS_DISCHARGING);
414 | c = row.createCell(19);
415 | c.setCellValue(BATTERY_STATUS_FULL);
416 | c = row.createCell(20);
417 | c.setCellValue(BATTERY_STATUS_NOT_CHARGING);
418 | c = row.createCell(21);
419 | c.setCellValue(BATTERY_STATUS_UNKNOWN);
420 | c = row.createCell(22);
421 | c.setCellValue(EXTRA_BATTERY_LOW);
422 | c = row.createCell(23);
423 | c.setCellValue(EXTRA_HEALTH);
424 | c = row.createCell(24);
425 | c.setCellValue(EXTRA_ICON_SMALL);
426 | c = row.createCell(25);
427 | c.setCellValue(EXTRA_LEVEL);
428 | c = row.createCell(26);
429 | c.setCellValue(EXTRA_PLUGGED);
430 | c = row.createCell(27);
431 | c.setCellValue(EXTRA_SCALE);
432 | c = row.createCell(28);
433 | c.setCellValue(EXTRA_STATUS);
434 | c = row.createCell(29);
435 | c.setCellValue(EXTRA_TEMPERATURE);
436 | c = row.createCell(30);
437 | c.setCellValue(EXTRA_VOLTAGE);
438 | c = row.createCell(31);
439 | c.setCellValue(temporaryList.get(0).getConfidence());
440 | c = row.createCell(32);
441 | c.setCellValue(temporaryList.get(1).getConfidence());
442 | c = row.createCell(33);
443 | c.setCellValue(temporaryList.get(2).getConfidence());
444 | c = row.createCell(34);
445 | c.setCellValue(temporaryList.get(3).getConfidence());
446 | c = row.createCell(35);
447 | c.setCellValue(temporaryList.get(4).getConfidence());
448 | c = row.createCell(36);
449 | c.setCellValue(temporaryList.get(5).getConfidence());
450 | c = row.createCell(37);
451 | c.setCellValue(temporaryList.get(6).getConfidence());
452 | c = row.createCell(38);
453 | c.setCellValue(temporaryList.get(7).getConfidence());
454 | c = row.createCell(39);
455 | c.setCellValue(latitude);
456 | c = row.createCell(40);
457 | c.setCellValue(longitude);
458 | c = row.createCell(41);
459 | c.setCellValue(altitude);
460 |
461 |
462 | inputStream.close();
463 | }
464 | editor.putInt("rowNumber", k + 1 ).apply();
465 |
466 | FileOutputStream outputStream = null;
467 |
468 | try {
469 | outputStream = new FileOutputStream(file);
470 | wb.write(outputStream);
471 | wb.close();
472 | outputStream.close();
473 | Log.w("FileUtils", "Writing file" + file + ":" + UUID.randomUUID().toString());
474 | StorageReference ref = storageReference.child("excel/" + userID + "/myExcel.csv");
475 | // adding listeners on upload
476 | // or failure of image
477 | ref.putFile(Uri.fromFile(file))
478 | .addOnSuccessListener(
479 | new OnSuccessListener() {
480 |
481 | @Override
482 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
483 | {
484 | Log.e("File Upload", "done");
485 | Toast.makeText(getApplicationContext(), "The data has been successfully uploaded to storage", Toast.LENGTH_SHORT).show();
486 | }
487 | })
488 |
489 | .addOnFailureListener(new OnFailureListener() {
490 | @Override
491 | public void onFailure(@NonNull Exception e)
492 | {
493 | Toast.makeText(getApplicationContext(), "Failed " + e.getMessage(), Toast.LENGTH_SHORT).show();
494 | }
495 | })
496 | .addOnProgressListener(
497 | new OnProgressListener() {
498 |
499 | // Progress Listener for loading
500 | // percentage on the dialog box
501 | @Override
502 | public void onProgress(
503 | UploadTask.TaskSnapshot taskSnapshot)
504 | {
505 | double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount());
506 | // progressDialog.setMessage("Uploaded " + (int)progress + "%");
507 | }
508 | });
509 | success = true;
510 | } catch (IOException e) {
511 | Log.w("FileUtils", "Error writing " + file, e);
512 | } catch (Exception e) {
513 | Log.w("FileUtils", "Failed to save file", e);
514 | } finally {
515 | try {
516 | if (null != outputStream)
517 | Log.e("file created", "success");
518 | // ou.close();
519 | } catch (Exception ex) {
520 | }
521 | }
522 | return;
523 | }
524 |
525 | public static boolean isExternalStorageReadOnly() {
526 | String extStorageState = Environment.getExternalStorageState();
527 | if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(extStorageState)) {
528 | return true;
529 | }
530 | return false;
531 | }
532 |
533 | public static boolean isExternalStorageAvailable() {
534 | String extStorageState = Environment.getExternalStorageState();
535 | if (Environment.MEDIA_MOUNTED.equals(extStorageState)) {
536 | return true;
537 | }
538 | return false;
539 | }
540 |
541 | @Override
542 | public void onLocationChanged(@NonNull Location location) {
543 | latitude = String.valueOf(location.getLatitude());
544 | longitude = String.valueOf(location.getLongitude());
545 | altitude = String.valueOf(location.getAltitude());
546 | }
547 |
548 | public void UpdatesHandler() {
549 | //Set the activity detection interval. I’m using 3 seconds//
550 | Task task = mActivityRecognitionClient.requestActivityUpdates(
551 | 3000,
552 | getActivityDetectionPendingIntent());
553 | task.addOnSuccessListener(new OnSuccessListener() {
554 | @Override
555 | public void onSuccess(Void result) {
556 | updateDetectedActivitiesList();
557 | }
558 | });
559 | }
560 | private PendingIntent getActivityDetectionPendingIntent() {
561 | //Send the activity data to our DetectedActivitiesIntentService class//
562 | Intent intent = new Intent(this, ActivityIntentService.class);
563 | return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
564 |
565 | }
566 |
567 | protected void updateDetectedActivitiesList() {
568 | temporaryList.clear();
569 | ArrayList detectedActivities = ActivityIntentService.detectedActivitiesFromJson(
570 | PreferenceManager.getDefaultSharedPreferences(context)
571 | .getString(DETECTED_ACTIVITY, "")
572 | );
573 |
574 | HashMap detectedActivitiesMap = new HashMap<>();
575 | for (DetectedActivity activity : detectedActivities) {
576 | detectedActivitiesMap.put(activity.getType(), activity.getConfidence());
577 | }
578 |
579 |
580 | for (int i = 0; i < ActivityIntentService.POSSIBLE_ACTIVITIES.length; i++) {
581 | int confidence = detectedActivitiesMap.containsKey(ActivityIntentService.POSSIBLE_ACTIVITIES[i]) ?
582 | detectedActivitiesMap.get(ActivityIntentService.POSSIBLE_ACTIVITIES[i]) : 0;
583 |
584 | //Add the object to a temporaryList//
585 | temporaryList.add(new
586 | DetectedActivity(ActivityIntentService.POSSIBLE_ACTIVITIES[i],
587 | confidence));
588 | }
589 | Log.e("ddddddddddd ", (String.valueOf(temporaryList)));
590 | }
591 |
592 | public static String[] info_lists = {
593 | "Date",
594 | "ACTION_CHARGING",
595 | "ACTION_DISCHARGING",
596 | "BATTERY_HEALTH_COLD",
597 | "BATTERY_HEALTH_DEAD",
598 | "BATTERY_HEALTH_GOOD",
599 | "BATTERY_HEALTH_OVERHEAT",
600 | "BATTERY_HEALTH_OVER_VOLTAGE",
601 | "BATTERY_HEALTH_UNKNOWN",
602 | "BATTERY_HEALTH_UNSPECIFIED",
603 | "BATTERY_PLUGGED_AC",
604 | "BATTERY_PLUGGED_USB",
605 | "BATTERY_PLUGGED_WIRELESS",
606 | "BATTERY_PROPERTY_CAPACITY",
607 | "BATTERY_PROPERTY_CHARGE_COUNTER",
608 | "BATTERY_PROPERTY_CURRENT_NOW",
609 | "BATTERY_PROPERTY_STATUS",
610 | "BATTERY_STATUS_CHARGING",
611 | "BATTERY_STATUS_DISCHARGING",
612 | "BATTERY_STATUS_FULL",
613 | "BATTERY_STATUS_NOT_CHARGING",
614 | "BATTERY_STATUS_UNKNOWN",
615 | "EXTRA_BATTERY_LOW",
616 | "EXTRA_HEALTH",
617 | "EXTRA_ICON_SMALL",
618 | "EXTRA_LEVEL",
619 | "EXTRA_PLUGGED",
620 | "EXTRA_SCALE",
621 | "EXTRA_STATUS",
622 | "EXTRA_TEMPERATURE",
623 | "EXTRA_VOLTAGE",
624 | "IN_VEHICLE",
625 | "ON_BICYCLE",
626 | "ON_FOOT",
627 | "RUNNING",
628 | "STILL",
629 | "TILTING",
630 | "UNKNOWN",
631 | "WALKING",
632 | "Longitude",
633 | "Latitude",
634 | "Altitude"
635 | };
636 |
637 | public static String[] POSSIBLE_ACTIVITIES = {
638 | "STILL",
639 | "ON_FOOT",
640 | "WALKING",
641 | "RUNNING",
642 | "IN_VEHICLE",
643 | "ON_BICYCLE",
644 | "TILTING",
645 | "UNKNOWN"
646 | };
647 | }
--------------------------------------------------------------------------------