-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b302b2d
commit c3dd5c1
Showing
78 changed files
with
2,998 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.javinator9889.handwashingreminder" | ||
minSdkVersion 14 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
debug { | ||
ext.enableCrashliytics = false | ||
applicationIdSuffix ".debug" | ||
debuggable true | ||
} | ||
release { | ||
minifyEnabled true | ||
shrinkResources true | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
dexOptions { | ||
preDexLibraries true | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
implementation 'androidx.core:core-ktx:1.2.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
|
||
// https://github.com/Javinator9889/LocaleManager | ||
implementation 'com.github.javinator9889:localemanager:1.1X' | ||
// https://material.io/develop/android/docs/getting-started/ | ||
implementation 'com.google.android.material:material:1.1.0' | ||
// https://developers.google.com/android/guides/setup | ||
implementation 'com.google.android.gms:play-services-location:17.0.0' | ||
// https://developer.android.com/jetpack/androidx/releases/annotation | ||
implementation 'androidx.annotation:annotation:1.1.0' | ||
// https://github.com/AppIntro/AppIntro | ||
implementation 'com.github.AppIntro:AppIntro:5.1.0' | ||
// https://github.com/andkulikov/Transitions-Everywhere | ||
implementation "com.andkulikov:transitionseverywhere:2.1.0" | ||
// https://developer.android.com/jetpack/androidx/releases/cardview | ||
implementation "androidx.cardview:cardview:1.0.0" | ||
// https://developer.android.com/jetpack/androidx/releases/recyclerview | ||
implementation "androidx.recyclerview:recyclerview:1.1.0" | ||
// https://developer.android.com/studio/build/multidex | ||
implementation 'androidx.multidex:multidex:2.0.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/javinator9889/handwashingreminder/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.javinator9889.handwashingreminder | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = | ||
InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals( | ||
"com.javinator9889.handwashingreminder", | ||
appContext.packageName | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.javinator9889.handwashingreminder"> | ||
|
||
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" /> | ||
<!-- Required for 29+. --> | ||
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" /> | ||
|
||
<application | ||
android:name=".application.HandwashingApplication" | ||
android:allowBackup="true" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
|
||
<activity android:name=".views.activities.intro.IntroActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".views.activities.MainActivity" /> | ||
<activity android:name=".views.activities.config.TimeConfigActivity" /> | ||
|
||
<meta-data | ||
android:name="preloaded_fonts" | ||
android:resource="@array/preloaded_fonts" /> | ||
</application> | ||
|
||
</manifest> |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions
78
...src/main/java/com/javinator9889/handwashingreminder/application/HandwashingApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright © 2020 - present | Handwashing reminder by Javinator9889 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
* | ||
* Created by Javinator9889 on 15/03/20 - Handwashing reminder. | ||
*/ | ||
package com.javinator9889.handwashingreminder.application | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import androidx.multidex.MultiDex | ||
import javinator9889.localemanager.application.BaseApplication | ||
import javinator9889.localemanager.utils.languagesupport.LanguagesSupport.Language | ||
|
||
|
||
class HandwashingApplication : BaseApplication() { | ||
private lateinit var sharedPreferences: SharedPreferences | ||
|
||
companion object { | ||
private lateinit var instance: HandwashingApplication | ||
|
||
fun getInstance(): HandwashingApplication { | ||
return this.instance | ||
} | ||
} | ||
|
||
override fun attachBaseContext(base: Context?) { | ||
super.attachBaseContext(base) | ||
MultiDex.install(this) | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
override fun onCreate() { | ||
super.onCreate() | ||
instance = this | ||
sharedPreferences = getCustomSharedPreferences(this)!! | ||
} | ||
|
||
/** | ||
* Obtains the initialized shared preferences. | ||
*/ | ||
fun getSharedPreferences(): SharedPreferences { | ||
return sharedPreferences | ||
} | ||
|
||
/** | ||
* Updates the application language | ||
* @param language a valid language code. | ||
* @see Language | ||
*/ | ||
fun setNewLocale(@Language language: String) { | ||
localeManager.setNewLocale(this, language) | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
override fun getCustomSharedPreferences(base: Context): SharedPreferences? { | ||
return base.getSharedPreferences( | ||
"handwasingreminder.prefs", | ||
Context.MODE_PRIVATE | ||
) | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
app/src/main/java/com/javinator9889/handwashingreminder/gms/activity/ActivityHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright © 2020 - present | Handwashing reminder by Javinator9889 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see https://www.gnu.org/licenses/. | ||
* | ||
* Created by Javinator9889 on 15/03/20 - Handwashing reminder. | ||
*/ | ||
package com.javinator9889.handwashingreminder.gms.activity | ||
|
||
import android.app.PendingIntent | ||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.util.Log | ||
import com.google.android.gms.location.* | ||
import com.google.android.gms.tasks.Task | ||
import com.javinator9889.handwashingreminder.R | ||
import com.javinator9889.handwashingreminder.notifications.NotificationsHandler | ||
import com.javinator9889.handwashingreminder.utils.ACTIVITY_CHANNEL_ID | ||
|
||
class ActivityHandler(private val context: Context) : BroadcastReceiver() { | ||
private val requestCode = 51824210 | ||
private val tag = "ActivityHandler" | ||
private val transitions: MutableList<ActivityTransition> = mutableListOf() | ||
private var task: Task<Void> | ||
private val pendingIntent: PendingIntent | ||
private var activityRegistered = false | ||
|
||
init { | ||
val activitiesSet = setOf( | ||
DetectedActivity.IN_VEHICLE, | ||
DetectedActivity.ON_BICYCLE, | ||
DetectedActivity.RUNNING, | ||
DetectedActivity.WALKING | ||
) | ||
addTransitions(activitiesSet, transitions) | ||
|
||
val intent = Intent(context, this::class.java) | ||
pendingIntent = PendingIntent.getBroadcast( | ||
context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT | ||
) | ||
val request = ActivityTransitionRequest(transitions) | ||
task = ActivityRecognition.getClient(context) | ||
.requestActivityTransitionUpdates(request, pendingIntent) | ||
task.addOnSuccessListener { activityRegistered = true } | ||
task.addOnFailureListener { activityRegistered = false } | ||
} | ||
|
||
private fun addTransitions( | ||
activitiesSet: Set<Int>, | ||
transitions: MutableList<ActivityTransition>, | ||
activityTransition: Int = ActivityTransition.ACTIVITY_TRANSITION_EXIT | ||
) { | ||
for (activity in activitiesSet) { | ||
transitions += ActivityTransition.Builder() | ||
.setActivityType(activity) | ||
.setActivityTransition(activityTransition) | ||
.build() | ||
} | ||
} | ||
|
||
fun disableActivityTracker() { | ||
task = ActivityRecognition.getClient(context) | ||
.removeActivityTransitionUpdates(pendingIntent) | ||
task.addOnSuccessListener { pendingIntent.cancel() } | ||
task.addOnFailureListener { e: Exception -> Log.e(tag, e.message, e) } | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
override fun onReceive(context: Context?, intent: Intent?) { | ||
if (ActivityTransitionResult.hasResult(intent)) { | ||
val result = ActivityTransitionResult.extractResult(intent)!! | ||
for (event in result.transitionEvents) { | ||
if (event.transitionType != | ||
ActivityTransition.ACTIVITY_TRANSITION_EXIT || | ||
event.activityType == DetectedActivity.UNKNOWN | ||
) | ||
continue | ||
val notificationHandler = NotificationsHandler( | ||
this.context, | ||
ACTIVITY_CHANNEL_ID, | ||
this.context.getString( | ||
R.string | ||
.activity_notification_channel_name | ||
), | ||
this.context.getString( | ||
R.string | ||
.activity_notification_channel_desc | ||
) | ||
) | ||
notificationHandler.createNotification( | ||
R.drawable.ic_handwashing_icon, | ||
R.drawable.handwashing_app_logo, | ||
R.string.test_notification, | ||
R.string.test_content | ||
) | ||
break | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.