├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── wahibhaq │ │ │ │ └── locationservicelivedata │ │ │ │ ├── LocationListener.kt │ │ │ │ ├── MainApplication.kt │ │ │ │ ├── LocationServiceListener.kt │ │ │ │ ├── MainViewModel.kt │ │ │ │ ├── PermissionStatusListener.kt │ │ │ │ ├── Utils.kt │ │ │ │ ├── GpsStatusListener.kt │ │ │ │ ├── NotificationUtil.kt │ │ │ │ ├── LocationService.kt │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── wahibhaq │ │ │ └── locationservicelivedata │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── wahibhaq │ │ └── locationservicelivedata │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── LICENSE ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KI-labs/gps-permission-checks-livedata/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KI-labs/gps-permission-checks-livedata/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KI-labs/gps-permission-checks-livedata/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KI-labs/gps-permission-checks-livedata/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KI-labs/gps-permission-checks-livedata/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KI-labs/gps-permission-checks-livedata/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KI-labs/gps-permission-checks-livedata/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/KI-labs/gps-permission-checks-livedata/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/KI-labs/gps-permission-checks-livedata/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KI-labs/gps-permission-checks-livedata/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/KI-labs/gps-permission-checks-livedata/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/java/com/wahibhaq/locationservicelivedata/LocationListener.kt: -------------------------------------------------------------------------------- 1 | package com.wahibhaq.locationservicelivedata 2 | 3 | 4 | interface LocationListener { 5 | fun subscribeToLocationUpdates() 6 | 7 | fun unsubscribeFromLocationUpdates() 8 | } -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun May 27 16:48:51 CEST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/java/com/wahibhaq/locationservicelivedata/MainApplication.kt: -------------------------------------------------------------------------------- 1 | package com.wahibhaq.locationservicelivedata 2 | 3 | import android.app.Application 4 | import timber.log.Timber 5 | 6 | class MainApplication : Application() { 7 | 8 | override fun onCreate() { 9 | super.onCreate() 10 | if (BuildConfig.DEBUG) { 11 | Timber.plant(Timber.DebugTree()) 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/wahibhaq/locationservicelivedata/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.wahibhaq.locationservicelivedata 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #Android generated 3 | bin 4 | gen 5 | *.ap_ 6 | .apt_generated/ 7 | app/schemas 8 | 9 | #IntelliJ IDEA 10 | .idea 11 | *.iml 12 | *.ipr 13 | *.iws 14 | classes 15 | gen-external-apklibs 16 | 17 | #Maven 18 | target 19 | release.properties 20 | pom.xml.* 21 | 22 | #Ant 23 | build.xml 24 | ant.properties 25 | local.properties 26 | proguard.cfg 27 | 28 | #Gradle 29 | .gradle 30 | build 31 | gradle.properties 32 | 33 | #Other 34 | .DS_Store 35 | tmp 36 | *.swp 37 | *.tmp 38 | *.bak 39 | *.swp 40 | *.launch 41 | captures 42 | *.apk 43 | 44 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/wahibhaq/locationservicelivedata/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.wahibhaq.locationservicelivedata 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.wahibhaq.locationservicelivedata", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/wahibhaq/locationservicelivedata/LocationServiceListener.kt: -------------------------------------------------------------------------------- 1 | package com.wahibhaq.locationservicelivedata 2 | 3 | import android.annotation.TargetApi 4 | import android.content.Context 5 | import android.content.Intent 6 | import android.os.Build 7 | import timber.log.Timber 8 | 9 | 10 | class LocationServiceListener( 11 | private val context: Context, 12 | private val serviceIntent: Intent 13 | ) : LocationListener { 14 | 15 | @TargetApi(Build.VERSION_CODES.O) 16 | override fun subscribeToLocationUpdates() { 17 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 18 | Timber.d("Running on Android O") 19 | context.startForegroundService(serviceIntent) 20 | } else { 21 | Timber.d("Running on Android N or lower") 22 | context.startService(serviceIntent) 23 | } 24 | } 25 | 26 | override fun unsubscribeFromLocationUpdates() { 27 | context.stopService(serviceIntent) 28 | } 29 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Wahib Ul Haq 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/wahibhaq/locationservicelivedata/MainViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.wahibhaq.locationservicelivedata 2 | 3 | import android.Manifest 4 | import android.app.Application 5 | import android.app.NotificationManager 6 | import android.arch.lifecycle.AndroidViewModel 7 | import android.content.Context 8 | import android.content.Intent 9 | 10 | 11 | class MainViewModel(application: Application) : AndroidViewModel(application) { 12 | 13 | private val locationServiceListener = LocationServiceListener(application, Intent(application, 14 | LocationService::class.java)) 15 | 16 | private val notificationsUtil = NotificationsUtil(application, 17 | application.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager) 18 | 19 | val gpsStatusLiveData = GpsStatusListener(application) 20 | 21 | val locationPermissionStatusLiveData = PermissionStatusListener(application, 22 | Manifest.permission.ACCESS_FINE_LOCATION) 23 | 24 | fun startLocationTracking() = locationServiceListener.subscribeToLocationUpdates() 25 | 26 | fun stopLocationTracking() { 27 | locationServiceListener.unsubscribeFromLocationUpdates() 28 | notificationsUtil.cancelAlertNotification() 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/wahibhaq/locationservicelivedata/PermissionStatusListener.kt: -------------------------------------------------------------------------------- 1 | package com.wahibhaq.locationservicelivedata 2 | 3 | import android.arch.lifecycle.LiveData 4 | import android.content.Context 5 | import android.content.pm.PackageManager 6 | import android.support.v4.app.ActivityCompat 7 | 8 | /** 9 | * Listens to Runtime Permission Status of provided [permissionToListen] which comes under the 10 | * category of "Dangerous" and then responds with appropriate state specified in {@link PermissionStatus} 11 | */ 12 | class PermissionStatusListener(private val context: Context, 13 | private val permissionToListen: String) : LiveData() { 14 | 15 | override fun onActive() = handlePermissionCheck() 16 | 17 | private fun handlePermissionCheck() { 18 | val isPermissionGranted = ActivityCompat.checkSelfPermission(context, 19 | permissionToListen) == PackageManager.PERMISSION_GRANTED 20 | 21 | if (isPermissionGranted) 22 | postValue(PermissionStatus.Granted()) 23 | else 24 | postValue(PermissionStatus.Denied()) 25 | } 26 | } 27 | 28 | sealed class PermissionStatus { 29 | data class Granted(val message: Int = R.string.permission_status_granted) : PermissionStatus() 30 | data class Denied(val message: Int = R.string.permission_status_denied) : PermissionStatus() 31 | data class Blocked(val message: Int = R.string.permission_status_blocked) : PermissionStatus() 32 | } -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | GPS and Permission Checks 3 | Start Tracking 4 | End Tracking 5 | Settings 6 | Location Permission is Granted 7 | Location Permission is Denied 8 | Location Permission is Blocked 9 | "Location permission not granted. " + 10 | "Show a notification to alert user" 11 | "GPS is Enabled" 12 | "GPS is Disabled" 13 | In Progress… 14 | GPS Required 15 | Location Permission Required 16 | Enable GPS otherwise location tracking won\'t work 17 | Location Tracking 18 | Allow otherwise location tracking won\'t work 19 | Location Permission has been set not to ask again! Please provide it from Settings. 20 | Waiting for GPS to be enabled… 21 | Simulate Notification(s) 22 | (click to retry) 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/wahibhaq/locationservicelivedata/Utils.kt: -------------------------------------------------------------------------------- 1 | package com.wahibhaq.locationservicelivedata 2 | 3 | import android.arch.lifecycle.LiveData 4 | import android.arch.lifecycle.MediatorLiveData 5 | import android.arch.lifecycle.MutableLiveData 6 | 7 | /** 8 | * This function creates a [LiveData] of a [Pair] of the two types provided. The resulting LiveData is updated whenever either input LiveData updates and both LiveData have updated at least once before. 9 | * 10 | * If the combination of A and B is C, and A and B are updated in this pattern: `AABA`, C would be updated twice (once with the second A value and first B value, and once with the third A value and first B value). 11 | * 12 | * @param a the first LiveData 13 | * @param b the second LiveData 14 | * @author Mitchell Skaggs https://gist.github.com/magneticflux-/044c9d7a3cea431aa0e4f4f4950a2898 15 | */ 16 | fun combineLatest(a: LiveData, b: LiveData): MutableLiveData> { 17 | return MediatorLiveData>().apply { 18 | var lastA: A? = null 19 | var lastB: B? = null 20 | 21 | fun update() { 22 | val localLastA = lastA 23 | val localLastB = lastB 24 | if (localLastA != null && localLastB != null) 25 | this.value = Pair(localLastA, localLastB) 26 | } 27 | 28 | addSource(a) { 29 | lastA = it 30 | update() 31 | } 32 | addSource(b) { 33 | lastB = it 34 | update() 35 | } 36 | } 37 | } 38 | 39 | /** 40 | * This is merely an extension function for [combineLatest]. 41 | * 42 | * @see combineLatest 43 | * @author Mitchell Skaggs 44 | */ 45 | fun LiveData.combineLatestWith(b: LiveData): LiveData> = combineLatest(this, b) -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | apply plugin: 'kotlin-kapt' 8 | 9 | android { 10 | compileSdkVersion 28 11 | defaultConfig { 12 | applicationId "com.wahibhaq.locationservicelivedata" 13 | minSdkVersion 21 14 | targetSdkVersion 28 15 | versionCode 1 16 | versionName "1.0" 17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 30 | implementation "com.android.support:support-v4:$supportlib" 31 | implementation "com.android.support:appcompat-v7:$supportlib" 32 | implementation "com.android.support.constraint:constraint-layout:$constraint_layout" 33 | implementation "android.arch.lifecycle:extensions:$aac_lifecycle" 34 | kapt "android.arch.lifecycle:compiler:$aac_lifecycle" 35 | implementation "android.arch.lifecycle:runtime:$aac_lifecycle" 36 | debugImplementation "com.jakewharton.timber:timber:$timber" 37 | implementation "com.google.android.gms:play-services-location:$play_services" 38 | implementation "com.nabinbhandari.android:permissions:$permissions" 39 | 40 | testImplementation "junit:junit:$junit" 41 | androidTestImplementation "com.android.support.test:runner:$test_runner" 42 | androidTestImplementation "com.android.support.test.espresso:espresso-core:$test_espresso_core" 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/wahibhaq/locationservicelivedata/GpsStatusListener.kt: -------------------------------------------------------------------------------- 1 | package com.wahibhaq.locationservicelivedata 2 | 3 | import android.arch.lifecycle.LiveData 4 | import android.content.BroadcastReceiver 5 | import android.content.Context 6 | import android.content.Intent 7 | import android.content.IntentFilter 8 | import android.location.LocationManager 9 | import android.os.Build 10 | import android.provider.Settings 11 | import android.provider.Settings.Secure.* 12 | import timber.log.Timber 13 | 14 | /** 15 | * Listens to Gps (location service) which is highly important for tracking to work and then 16 | * responds with appropriate state specified in {@link GpsStatus} 17 | */ 18 | class GpsStatusListener(private val context: Context) : LiveData() { 19 | 20 | private val gpsSwitchStateReceiver = object : BroadcastReceiver() { 21 | override fun onReceive(context: Context, intent: Intent) = checkGpsAndReact() 22 | } 23 | 24 | override fun onInactive() = unregisterReceiver() 25 | 26 | override fun onActive() { 27 | registerReceiver() 28 | checkGpsAndReact() 29 | } 30 | 31 | private fun checkGpsAndReact() = if (isLocationEnabled()) { 32 | postValue(GpsStatus.Enabled()) 33 | } else { 34 | postValue(GpsStatus.Disabled()) 35 | } 36 | 37 | private fun isLocationEnabled() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 38 | context.getSystemService(LocationManager::class.java) 39 | .isProviderEnabled(LocationManager.GPS_PROVIDER) 40 | } else { 41 | try { 42 | getInt(context.contentResolver, LOCATION_MODE) != LOCATION_MODE_OFF 43 | } catch (e: Settings.SettingNotFoundException) { 44 | Timber.e(e) 45 | false 46 | } 47 | } 48 | 49 | /** 50 | * Broadcast receiver to listen the Location button toggle state in Android. 51 | */ 52 | private fun registerReceiver() = context.registerReceiver(gpsSwitchStateReceiver, 53 | IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION)) 54 | 55 | private fun unregisterReceiver() = context.unregisterReceiver(gpsSwitchStateReceiver) 56 | } 57 | 58 | sealed class GpsStatus { 59 | data class Enabled(val message: Int = R.string.gps_status_enabled) : GpsStatus() 60 | data class Disabled(val message: Int = R.string.gps_status_disabled) : GpsStatus() 61 | } 62 | -------------------------------------------------------------------------------- /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/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 21 | 22 | 37 | 38 |