├── .github ├── scripts │ └── gradlew_recursive.sh └── workflows │ ├── build.yaml │ └── copy-branch.yml ├── .gitignore ├── ActivityRecognition ├── .gitignore ├── .google │ └── packaging.yaml ├── README.md ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── gms │ │ │ └── location │ │ │ └── sample │ │ │ └── activityrecognition │ │ │ ├── ActivityRecognitionApp.kt │ │ │ ├── BootReceiver.kt │ │ │ ├── DetectedActivityReceiver.kt │ │ │ ├── MainActivity.kt │ │ │ ├── MainViewModel.kt │ │ │ ├── PermissionUtils.kt │ │ │ ├── data │ │ │ ├── ActivityTransitionManager.kt │ │ │ ├── AppPreferences.kt │ │ │ ├── PlayServicesAvailabilityChecker.kt │ │ │ └── db │ │ │ │ ├── ActivityTransitionDao.kt │ │ │ │ ├── ActivityTransitionRecord.kt │ │ │ │ ├── AppDatabase.kt │ │ │ │ └── TimestampConverter.kt │ │ │ └── ui │ │ │ ├── ActivityRecognitionPermissionState.kt │ │ │ ├── ActivityRecognitionScreen.kt │ │ │ ├── InitializingScreen.kt │ │ │ ├── ServiceUnavailableScreen.kt │ │ │ └── theme │ │ │ ├── Color.kt │ │ │ ├── Shape.kt │ │ │ ├── Theme.kt │ │ │ └── Type.kt │ │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── AwarenessApisSampleKotlin ├── .gitignore ├── .google │ └── packaging.yaml ├── README.md ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── android │ │ │ └── example │ │ │ └── awarenessapissamplekotlin │ │ │ └── MainActivity.kt │ │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── CONTRIBUTING.md ├── ForegroundLocationUpdates ├── .gitignore ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── gms │ │ │ └── location │ │ │ └── sample │ │ │ └── foregroundlocation │ │ │ ├── ForegroundLocationApp.kt │ │ │ ├── ForegroundLocationService.kt │ │ │ ├── MainActivity.kt │ │ │ ├── MainViewModel.kt │ │ │ ├── data │ │ │ ├── LocationPreferences.kt │ │ │ ├── LocationRepository.kt │ │ │ └── PlayServicesAvailablityChecker.kt │ │ │ └── ui │ │ │ ├── InitializingScreen.kt │ │ │ ├── LocationPermissionState.kt │ │ │ ├── LocationUpdatesScreen.kt │ │ │ ├── ServiceUnvailableScreen.kt │ │ │ └── theme │ │ │ ├── Color.kt │ │ │ └── Theme.kt │ │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ ├── ic_location.xml │ │ └── ic_stop.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── Geofencing ├── .gitignore ├── .google │ └── packaging.yaml ├── README.md ├── app │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── gms │ │ │ └── location │ │ │ └── sample │ │ │ └── geofencing │ │ │ ├── Constants.java │ │ │ ├── GeofenceBroadcastReceiver.java │ │ │ ├── GeofenceErrorMessages.java │ │ │ ├── GeofenceTransitionsJobIntentService.java │ │ │ └── MainActivity.java │ │ └── res │ │ ├── drawable-hdpi │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ │ ├── layout │ │ └── main_activity.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── LICENSE ├── LocationAddress ├── .gitignore ├── README.md ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── gms │ │ │ └── location │ │ │ └── sample │ │ │ └── locationaddress │ │ │ ├── LocationAddressApp.kt │ │ │ ├── MainActivity.kt │ │ │ ├── MainViewModel.kt │ │ │ ├── data │ │ │ ├── GeocodingApi.kt │ │ │ ├── LocationApi.kt │ │ │ └── PlayServicesAvailabilityChecker.kt │ │ │ └── ui │ │ │ ├── DiscreteSlider.kt │ │ │ ├── GeocoderScreen.kt │ │ │ ├── InitializingScreen.kt │ │ │ ├── LocationPermissionState.kt │ │ │ ├── ServiceUnavailableScreen.kt │ │ │ └── theme │ │ │ ├── Color.kt │ │ │ ├── Shape.kt │ │ │ ├── Theme.kt │ │ │ └── Type.kt │ │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots │ └── results_ui.png └── settings.gradle ├── LocationUpdatesBackgroundKotlin ├── .gitignore ├── .google │ └── packaging.yaml ├── README.md ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── google │ │ │ └── android │ │ │ └── gms │ │ │ └── location │ │ │ └── sample │ │ │ └── locationupdatesbackgroundkotlin │ │ │ └── ExampleInstrumentedTest.kt │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── google │ │ │ │ └── android │ │ │ │ └── gms │ │ │ │ └── location │ │ │ │ └── sample │ │ │ │ └── locationupdatesbackgroundkotlin │ │ │ │ ├── LocationUpdatesBroadcastReceiver.kt │ │ │ │ ├── Utils.kt │ │ │ │ ├── data │ │ │ │ ├── LocationRepository.kt │ │ │ │ ├── MyLocationManager.kt │ │ │ │ └── db │ │ │ │ │ ├── MyLocationDao.kt │ │ │ │ │ ├── MyLocationDatabase.kt │ │ │ │ │ ├── MyLocationEntity.kt │ │ │ │ │ └── MyLocationTypeConverters.kt │ │ │ │ ├── ui │ │ │ │ ├── LocationUpdateFragment.kt │ │ │ │ ├── MainActivity.kt │ │ │ │ └── PermissionRequestFragment.kt │ │ │ │ └── viewmodels │ │ │ │ └── LocationUpdateViewModel.kt │ │ └── res │ │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ ├── ic_launcher_background.xml │ │ │ ├── ic_location_on_24px.xml │ │ │ └── ic_my_location_24px.xml │ │ │ ├── layout │ │ │ ├── activity_main.xml │ │ │ ├── fragment_location_update.xml │ │ │ └── fragment_permission_request.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── google │ │ └── android │ │ └── gms │ │ └── location │ │ └── sample │ │ └── locationupdatesbackgroundkotlin │ │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── README.md └── SleepSampleKotlin ├── .gitignore ├── .google └── packaging.yaml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── android │ │ └── example │ │ └── sleepsamplekotlin │ │ ├── MainActivity.kt │ │ ├── MainApplication.kt │ │ ├── MainViewModel.kt │ │ ├── data │ │ ├── SleepRepository.kt │ │ ├── datastore │ │ │ └── SleepSubscriptionStatus.kt │ │ └── db │ │ │ ├── SleepClassifyEventDao.kt │ │ │ ├── SleepClassifyEventEntity.kt │ │ │ ├── SleepDatabase.kt │ │ │ ├── SleepSegmentEventDao.kt │ │ │ └── SleepSegmentEventEntity.kt │ │ └── receiver │ │ ├── BootReceiver.kt │ │ └── SleepReceiver.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── values-night │ └── themes.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── themes.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/scripts/gradlew_recursive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (C) 2020 The Android Open Source Project 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -xe 18 | 19 | # Default Gradle settings are not optimal for Android builds, override them 20 | # here to make the most out of the GitHub Actions build servers 21 | GRADLE_OPTS="$GRADLE_OPTS -Xms4g -Xmx4g" 22 | GRADLE_OPTS="$GRADLE_OPTS -XX:+HeapDumpOnOutOfMemoryError" 23 | GRADLE_OPTS="$GRADLE_OPTS -Dorg.gradle.daemon=false" 24 | GRADLE_OPTS="$GRADLE_OPTS -Dorg.gradle.workers.max=2" 25 | GRADLE_OPTS="$GRADLE_OPTS -Dkotlin.incremental=false" 26 | GRADLE_OPTS="$GRADLE_OPTS -Dkotlin.compiler.execution.strategy=in-process" 27 | GRADLE_OPTS="$GRADLE_OPTS -Dfile.encoding=UTF-8" 28 | export GRADLE_OPTS 29 | 30 | # Crawl all gradlew files which indicate an Android project 31 | # You may edit this if your repo has a different project structure 32 | for GRADLEW in `find . -name "gradlew"` ; do 33 | SAMPLE=$(dirname "${GRADLEW}") 34 | # Tell Gradle that this is a CI environment and disable parallel compilation 35 | bash "$GRADLEW" -p "$SAMPLE" -Pci --no-parallel --stacktrace $@ 36 | done 37 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Build 16 | 17 | on: 18 | push: 19 | branches: 20 | - main 21 | pull_request: 22 | 23 | concurrency: 24 | group: build-${{ github.ref }} 25 | cancel-in-progress: true 26 | 27 | jobs: 28 | build: 29 | runs-on: ubuntu-latest 30 | timeout-minutes: 60 31 | steps: 32 | - name: Checkout 33 | uses: actions/checkout@v3 34 | 35 | - name: Set up JDK 11 36 | uses: actions/setup-java@v3 37 | with: 38 | distribution: 'zulu' 39 | java-version: 11 40 | 41 | - name: Build project 42 | run: .github/scripts/gradlew_recursive.sh lint test build 43 | -------------------------------------------------------------------------------- /.github/workflows/copy-branch.yml: -------------------------------------------------------------------------------- 1 | # Duplicates default main branch to the old master branch 2 | 3 | name: Duplicates main to old master branch 4 | 5 | # Controls when the action will run. Triggers the workflow on push or pull request 6 | # events but only for the main branch 7 | on: 8 | push: 9 | branches: [ main ] 10 | 11 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 12 | jobs: 13 | # This workflow contains a single job called "copy-branch" 14 | copy-branch: 15 | # The type of runner that the job will run on 16 | runs-on: ubuntu-latest 17 | 18 | # Steps represent a sequence of tasks that will be executed as part of the job 19 | steps: 20 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it, 21 | # but specifies master branch (old default). 22 | - uses: actions/checkout@v2 23 | with: 24 | fetch-depth: 0 25 | ref: master 26 | 27 | - run: | 28 | git config user.name github-actions 29 | git config user.email github-actions@github.com 30 | git merge origin/main 31 | git push 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Ignore gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | proguard-project.txt 25 | 26 | # Eclipse files 27 | .project 28 | .classpath 29 | .settings/ 30 | 31 | # Android Studio/IDEA 32 | *.iml 33 | .idea 34 | 35 | # Mac specific ignore 36 | .DS_Store -------------------------------------------------------------------------------- /ActivityRecognition/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | -------------------------------------------------------------------------------- /ActivityRecognition/.google/packaging.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # This file is used by Google as part of our samples packaging process. 16 | # End users may safely ignore this file. It has no relevance to other systems. 17 | --- 18 | status: PUBLISHED 19 | technologies: [Android] 20 | categories: [Location] 21 | languages: [Java] 22 | solutions: [Mobile] 23 | github: android/location-samples 24 | level: BEGINNER 25 | license: apache2 26 | -------------------------------------------------------------------------------- /ActivityRecognition/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /ActivityRecognition/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 -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/DetectedActivityReceiver.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition 18 | 19 | import android.content.BroadcastReceiver 20 | import android.content.Context 21 | import android.content.Intent 22 | import com.google.android.gms.location.ActivityTransitionResult 23 | import com.google.android.gms.location.sample.activityrecognition.data.db.ActivityTransitionDao 24 | import com.google.android.gms.location.sample.activityrecognition.data.db.asRecord 25 | import dagger.hilt.android.AndroidEntryPoint 26 | import kotlinx.coroutines.MainScope 27 | import kotlinx.coroutines.launch 28 | import javax.inject.Inject 29 | 30 | @AndroidEntryPoint 31 | class DetectedActivityReceiver : BroadcastReceiver() { 32 | 33 | @Inject lateinit var dao: ActivityTransitionDao 34 | 35 | private val coroutineScope = MainScope() 36 | 37 | override fun onReceive(context: Context, intent: Intent) { 38 | val result = ActivityTransitionResult.extractResult(intent) ?: return 39 | 40 | if (result.transitionEvents.isNotEmpty()) { 41 | coroutineScope.launch { 42 | dao.insert( 43 | result.transitionEvents.map { it.asRecord() } 44 | ) 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/PermissionUtils.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition 18 | 19 | import android.app.Activity 20 | import android.content.Context 21 | import android.content.pm.PackageManager 22 | import android.os.Build 23 | import androidx.core.app.ActivityCompat 24 | import androidx.core.content.ContextCompat 25 | 26 | fun Context.hasPermission(permission: String): Boolean = 27 | ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED 28 | 29 | fun Activity.shouldShowRationaleFor(permission: String): Boolean = 30 | ActivityCompat.shouldShowRequestPermissionRationale(this, permission) 31 | 32 | /** 33 | * Activity recognition requires a different permission starting from Android 10 (API level 29). 34 | */ 35 | val ActivityRecognitionPermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { 36 | android.Manifest.permission.ACTIVITY_RECOGNITION 37 | } else { 38 | "com.google.android.gms.permission.ACTIVITY_RECOGNITION" 39 | } 40 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/data/AppPreferences.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition.data 18 | 19 | import androidx.datastore.core.DataStore 20 | import androidx.datastore.preferences.core.Preferences 21 | import androidx.datastore.preferences.core.booleanPreferencesKey 22 | import androidx.datastore.preferences.core.edit 23 | import kotlinx.coroutines.flow.map 24 | import javax.inject.Inject 25 | 26 | class AppPreferences @Inject constructor( 27 | private val dataStore: DataStore 28 | ) { 29 | val isActivityTransitionUpdatesTurnedOn = dataStore.data.map { 30 | it[ACTIVITY_TRANSITION_UPDATES_TURNED_ON] ?: false 31 | } 32 | 33 | suspend fun setActivityTransitionUpdatesTurnedOn(isOn: Boolean) { 34 | dataStore.edit { 35 | it[ACTIVITY_TRANSITION_UPDATES_TURNED_ON] = isOn 36 | } 37 | } 38 | 39 | private companion object { 40 | val ACTIVITY_TRANSITION_UPDATES_TURNED_ON = 41 | booleanPreferencesKey("activity_transition_updates_on") 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/data/PlayServicesAvailabilityChecker.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition.data 18 | 19 | import android.content.Context 20 | import com.google.android.gms.common.ConnectionResult 21 | import com.google.android.gms.common.GoogleApiAvailability 22 | import dagger.hilt.android.qualifiers.ApplicationContext 23 | import kotlinx.coroutines.Dispatchers 24 | import kotlinx.coroutines.withContext 25 | import javax.inject.Inject 26 | 27 | /** 28 | * Utility class which checks for the avialability of Google Play Services on this device. 29 | */ 30 | class PlayServicesAvailabilityChecker @Inject constructor( 31 | @ApplicationContext private val context: Context, 32 | private val googleApiAvailability: GoogleApiAvailability 33 | ) { 34 | suspend fun isGooglePlayServicesAvailable(): Boolean = withContext(Dispatchers.Default) { 35 | when (googleApiAvailability.isGooglePlayServicesAvailable(context)) { 36 | ConnectionResult.SUCCESS -> true 37 | else -> false 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/data/db/ActivityTransitionDao.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition.data.db 18 | 19 | import androidx.room.Dao 20 | import androidx.room.Insert 21 | import androidx.room.Query 22 | import kotlinx.coroutines.flow.Flow 23 | 24 | /** 25 | * Data Access Object for managing [ActivityTransitionRecord]s in the database. 26 | */ 27 | @Dao 28 | interface ActivityTransitionDao { 29 | 30 | @Insert 31 | suspend fun insert(records: List) 32 | 33 | @Query("DELETE FROM ActivityTransitionRecord") 34 | suspend fun deleteAll() 35 | 36 | @Query("SELECT * FROM ActivityTransitionRecord ORDER BY timestamp DESC LIMIT 20") 37 | fun getMostRecent(): Flow> 38 | } 39 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/data/db/AppDatabase.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition.data.db 18 | 19 | import androidx.room.Database 20 | import androidx.room.RoomDatabase 21 | 22 | /** 23 | * Room database for the app. 24 | */ 25 | @Database( 26 | entities = [ActivityTransitionRecord::class], 27 | version = 1, 28 | exportSchema = false 29 | ) 30 | abstract class AppDatabase : RoomDatabase() { 31 | 32 | abstract fun getActivityTransitionRecordDao(): ActivityTransitionDao 33 | } 34 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/data/db/TimestampConverter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition.data.db 18 | 19 | import androidx.room.TypeConverter 20 | import java.time.Instant 21 | 22 | /** 23 | * [TypeConverter] functions so that Room can process [Instant]s. 24 | */ 25 | class TimestampConverter { 26 | @TypeConverter 27 | fun fromTimestamp(value: Long?): Instant? { 28 | return value?.let { Instant.ofEpochMilli(it) } 29 | } 30 | 31 | @TypeConverter 32 | fun toTimestamp(date: Instant?): Long? { 33 | return date?.toEpochMilli() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition.ui.theme 18 | 19 | import androidx.compose.ui.graphics.Color 20 | 21 | val Purple200 = Color(0xFFBB86FC) 22 | val Purple500 = Color(0xFF6200EE) 23 | val Purple700 = Color(0xFF3700B3) 24 | val Teal200 = Color(0xFF03DAC5) 25 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/ui/theme/Shape.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition.ui.theme 18 | 19 | import androidx.compose.foundation.shape.RoundedCornerShape 20 | import androidx.compose.material.Shapes 21 | import androidx.compose.ui.unit.dp 22 | 23 | val Shapes = Shapes( 24 | small = RoundedCornerShape(4.dp), 25 | medium = RoundedCornerShape(4.dp), 26 | large = RoundedCornerShape(0.dp) 27 | ) 28 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/ui/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition.ui.theme 18 | 19 | import androidx.compose.foundation.isSystemInDarkTheme 20 | import androidx.compose.material.MaterialTheme 21 | import androidx.compose.material.darkColors 22 | import androidx.compose.material.lightColors 23 | import androidx.compose.runtime.Composable 24 | 25 | private val DarkColorPalette = darkColors( 26 | primary = Purple200, 27 | primaryVariant = Purple700, 28 | secondary = Teal200 29 | ) 30 | 31 | private val LightColorPalette = lightColors( 32 | primary = Purple500, 33 | primaryVariant = Purple700, 34 | secondary = Teal200 35 | 36 | /* Other default colors to override 37 | background = Color.White, 38 | surface = Color.White, 39 | onPrimary = Color.White, 40 | onSecondary = Color.Black, 41 | onBackground = Color.Black, 42 | onSurface = Color.Black, 43 | */ 44 | ) 45 | 46 | @Composable 47 | fun ActivityRecognitionTheme( 48 | darkTheme: Boolean = isSystemInDarkTheme(), 49 | content: @Composable() () -> Unit 50 | ) { 51 | val colors = if (darkTheme) { 52 | DarkColorPalette 53 | } else { 54 | LightColorPalette 55 | } 56 | 57 | MaterialTheme( 58 | colors = colors, 59 | typography = Typography, 60 | shapes = Shapes, 61 | content = content 62 | ) 63 | } 64 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google, Inc 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.activityrecognition.ui.theme 18 | 19 | import androidx.compose.material.Typography 20 | import androidx.compose.ui.text.TextStyle 21 | import androidx.compose.ui.text.font.FontFamily 22 | import androidx.compose.ui.text.font.FontWeight 23 | import androidx.compose.ui.unit.sp 24 | 25 | // Set of Material typography styles to start with 26 | val Typography = Typography( 27 | body1 = TextStyle( 28 | fontFamily = FontFamily.Default, 29 | fontWeight = FontWeight.Normal, 30 | fontSize = 16.sp 31 | ) 32 | /* Other default text styles to override 33 | button = TextStyle( 34 | fontFamily = FontFamily.Default, 35 | fontWeight = FontWeight.W500, 36 | fontSize = 14.sp 37 | ), 38 | caption = TextStyle( 39 | fontFamily = FontFamily.Default, 40 | fontWeight = FontWeight.Normal, 41 | fontSize = 12.sp 42 | ) 43 | */ 44 | ) 45 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ActivityRecognition/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 32 | 33 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #FFBB86FC 20 | #FF6200EE 21 | #FF3700B3 22 | #FF03DAC5 23 | #FF018786 24 | #FF000000 25 | #FFFFFFFF 26 | 27 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | Activity Recognition 19 | Initializing 20 | Google Play Services are unavailable on this device. 21 | Start activity recognition 22 | Stop activity recognition 23 | Tap Start to begin activity recognition 24 | Please allow permission for activity recognition 25 | Permission needed 26 | This app requires permission to access activity recognition. Please accept. 27 | Waiting for events... 28 | Error while requesting activity transition updates. 29 | 30 | -------------------------------------------------------------------------------- /ActivityRecognition/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 32 | 33 | 37 | 38 | 32 | 33 | -------------------------------------------------------------------------------- /AwarenessApisSampleKotlin/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | #FFBB86FC 19 | #FF6200EE 20 | #FF3700B3 21 | #FF03DAC5 22 | #FF018786 23 | #FF000000 24 | #FFFFFFFF 25 | 26 | -------------------------------------------------------------------------------- /AwarenessApisSampleKotlin/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | AwarenessApisSampleKotlin 19 | Click on the button for a snapshot! 20 | Get Snapshot 21 | 22 | Settings 23 | Sample requires activity transition permissions to function. 24 | No 25 | Yes 26 | Permission Approved! 27 | 28 | -------------------------------------------------------------------------------- /AwarenessApisSampleKotlin/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 32 | 33 | -------------------------------------------------------------------------------- /AwarenessApisSampleKotlin/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 17 | buildscript { 18 | ext.kotlin_version = "1.4.21" 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | dependencies { 24 | classpath "com.android.tools.build:gradle:4.1.2" 25 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 26 | 27 | // NOTE: Do not place your application dependencies here; they belong 28 | // in the individual module build.gradle files 29 | } 30 | } 31 | 32 | allprojects { 33 | repositories { 34 | google() 35 | jcenter() 36 | } 37 | } 38 | 39 | task clean(type: Delete) { 40 | delete rootProject.buildDir 41 | } 42 | -------------------------------------------------------------------------------- /AwarenessApisSampleKotlin/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 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /AwarenessApisSampleKotlin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/AwarenessApisSampleKotlin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /AwarenessApisSampleKotlin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jan 30 14:05:32 PST 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-all.zip 7 | -------------------------------------------------------------------------------- /AwarenessApisSampleKotlin/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | include ':app' 17 | rootProject.name = "AwarenessApisSampleKotlin" 18 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | We'd love to accept your sample apps and patches! Before we can take them, we 5 | have to jump a couple of legal hurdles. 6 | 7 | Please fill out either the individual or corporate Contributor License Agreement 8 | (CLA). 9 | * If you are an individual writing original source code and you're sure you 10 | own the intellectual property, then you'll need to sign an [individual CLA] 11 | (https://cla.developers.google.com/clas). 12 | * If you work for a company that wants to allow you to contribute your work, 13 | then you'll need to sign a [corporate CLA] 14 | (https://developers.google.com/open-source/cla/corporate). 15 | 16 | Follow either of the two links above to access the appropriate CLA and 17 | instructions for how to sign and return it. Once we receive it, we'll be able to 18 | accept your pull requests. 19 | 20 | ## Contributing A Patch 21 | 1. Submit an issue describing your proposed change to the repo in question. 22 | 1. The repo owner will respond to your issue promptly. 23 | 1. If your proposed change is accepted, and you haven't already done so, sign a 24 | Contributor License Agreement (see details above). 25 | 1. Fork the desired repo, develop and test your code changes. 26 | 1. Ensure that your code adheres to the existing style in the sample to which 27 | you are contributing. Refer to the 28 | [Google Cloud Platform Samples Style Guide] 29 | (https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the 30 | recommended coding standards for this organization. 31 | 1. Ensure that your code has an appropriate set of unit tests which all pass. 32 | 1. Submit a pull request. 33 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /ForegroundLocationUpdates/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 -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/java/com/google/android/gms/location/sample/foregroundlocation/ForegroundLocationApp.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.foregroundlocation 18 | 19 | import android.app.Application 20 | import androidx.datastore.core.DataStore 21 | import androidx.datastore.preferences.core.PreferenceDataStoreFactory 22 | import androidx.datastore.preferences.core.Preferences 23 | import androidx.datastore.preferences.preferencesDataStoreFile 24 | import com.google.android.gms.common.GoogleApiAvailability 25 | import com.google.android.gms.location.LocationServices 26 | import dagger.Module 27 | import dagger.Provides 28 | import dagger.hilt.InstallIn 29 | import dagger.hilt.android.HiltAndroidApp 30 | import dagger.hilt.components.SingletonComponent 31 | import javax.inject.Singleton 32 | 33 | @HiltAndroidApp 34 | class ForegroundLocationApp : Application() 35 | 36 | @Module 37 | @InstallIn(SingletonComponent::class) 38 | object AppModule { 39 | 40 | @Provides 41 | @Singleton 42 | fun provideGoogleApiAvailability() = GoogleApiAvailability.getInstance() 43 | 44 | @Provides 45 | @Singleton 46 | fun provideFusedLocationProviderClient( 47 | application: Application 48 | ) = LocationServices.getFusedLocationProviderClient(application) 49 | 50 | @Provides 51 | @Singleton 52 | fun provideDataStore(application: Application): DataStore { 53 | return PreferenceDataStoreFactory.create { 54 | application.preferencesDataStoreFile("prefs") 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/java/com/google/android/gms/location/sample/foregroundlocation/data/LocationPreferences.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.foregroundlocation.data 18 | 19 | import androidx.datastore.core.DataStore 20 | import androidx.datastore.preferences.core.Preferences 21 | import androidx.datastore.preferences.core.booleanPreferencesKey 22 | import androidx.datastore.preferences.core.edit 23 | import kotlinx.coroutines.Dispatchers 24 | import kotlinx.coroutines.flow.map 25 | import kotlinx.coroutines.withContext 26 | import javax.inject.Inject 27 | 28 | /** 29 | * Data store which holds preferences for the app. 30 | */ 31 | class LocationPreferences @Inject constructor( 32 | private val dataStore: DataStore 33 | ) { 34 | val isLocationTurnedOn = dataStore.data.map { 35 | it[locationOnKey] ?: false 36 | } 37 | 38 | suspend fun setLocationTurnedOn(isStarted: Boolean) = withContext(Dispatchers.IO) { 39 | dataStore.edit { 40 | it[locationOnKey] = isStarted 41 | } 42 | } 43 | 44 | private companion object { 45 | val locationOnKey = booleanPreferencesKey("is_location_on") 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/java/com/google/android/gms/location/sample/foregroundlocation/data/PlayServicesAvailablityChecker.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.foregroundlocation.data 18 | 19 | import android.content.Context 20 | import com.google.android.gms.common.ConnectionResult 21 | import com.google.android.gms.common.GoogleApiAvailability 22 | import dagger.hilt.android.qualifiers.ApplicationContext 23 | import kotlinx.coroutines.Dispatchers 24 | import kotlinx.coroutines.withContext 25 | import javax.inject.Inject 26 | 27 | class PlayServicesAvailabilityChecker @Inject constructor( 28 | @ApplicationContext private val context: Context, 29 | private val googleApiAvailability: GoogleApiAvailability 30 | ) { 31 | suspend fun isGooglePlayServicesAvailable(): Boolean = withContext(Dispatchers.Default) { 32 | when (googleApiAvailability.isGooglePlayServicesAvailable(context)) { 33 | ConnectionResult.SUCCESS -> true 34 | else -> false 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/java/com/google/android/gms/location/sample/foregroundlocation/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.foregroundlocation.ui.theme 18 | 19 | import androidx.compose.ui.graphics.Color 20 | 21 | val Purple200 = Color(0xFFBB86FC) 22 | val Purple500 = Color(0xFF6200EE) 23 | val Teal200 = Color(0xFF03DAC5) 24 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/java/com/google/android/gms/location/sample/foregroundlocation/ui/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.foregroundlocation.ui.theme 18 | 19 | import androidx.compose.foundation.isSystemInDarkTheme 20 | import androidx.compose.material.MaterialTheme 21 | import androidx.compose.material.darkColors 22 | import androidx.compose.material.lightColors 23 | import androidx.compose.runtime.Composable 24 | 25 | private val DarkColorPalette = darkColors( 26 | primary = Purple200, 27 | secondary = Teal200 28 | ) 29 | 30 | private val LightColorPalette = lightColors( 31 | primary = Purple500, 32 | secondary = Teal200 33 | ) 34 | 35 | @Composable 36 | fun ForegroundLocationTheme( 37 | darkTheme: Boolean = isSystemInDarkTheme(), 38 | content: @Composable() () -> Unit 39 | ) { 40 | val colors = if (darkTheme) { 41 | DarkColorPalette 42 | } else { 43 | LightColorPalette 44 | } 45 | 46 | MaterialTheme( 47 | colors = colors, 48 | content = content 49 | ) 50 | } 51 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/drawable/ic_location.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 22 | 25 | 26 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/drawable/ic_stop.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 22 | 25 | 26 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/ForegroundLocationUpdates/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 33 | 34 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #FFBB86FC 20 | #FF6200EE 21 | #FF3700B3 22 | #FF03DAC5 23 | #FF018786 24 | #FF000000 25 | #FFFFFFFF 26 | 27 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | Foreground Location 20 | Initializing 21 | Google Play Services are unavailable on this device. 22 | Start 23 | Stop 24 | Tap Start to receive location updates 25 | 26 | Please allow permission to access location 27 | Permission needed 28 | This app requires permission to access your location. Please accept. 29 | 30 | Waiting for location… 31 | Lat: %1$f\nLng: %2$f 32 | Location updates 33 | Location updates 34 | 35 | -------------------------------------------------------------------------------- /ForegroundLocationUpdates/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 33 | 34 | 38 | 39 | 4 | 5 | -------------------------------------------------------------------------------- /Geofencing/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | google() 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.4.1' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | google() 19 | mavenCentral() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Geofencing/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Settings specified in this file will override any Gradle settings 5 | # configured through the IDE. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | android.useAndroidX=true 20 | -------------------------------------------------------------------------------- /Geofencing/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/Geofencing/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Geofencing/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-rc-2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /Geofencing/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /LocationAddress/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | -------------------------------------------------------------------------------- /LocationAddress/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /LocationAddress/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 -------------------------------------------------------------------------------- /LocationAddress/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 27 | 28 | 29 | 30 | 38 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/java/com/google/android/gms/location/sample/locationaddress/LocationAddressApp.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.locationaddress 18 | 19 | import android.app.Application 20 | import android.location.Geocoder 21 | import com.google.android.gms.common.GoogleApiAvailability 22 | import com.google.android.gms.location.LocationServices 23 | import dagger.Module 24 | import dagger.Provides 25 | import dagger.hilt.InstallIn 26 | import dagger.hilt.android.HiltAndroidApp 27 | import dagger.hilt.components.SingletonComponent 28 | import javax.inject.Singleton 29 | 30 | @HiltAndroidApp 31 | class LocationAddressApp : Application() 32 | 33 | @Module 34 | @InstallIn(SingletonComponent::class) 35 | object AppModule { 36 | 37 | @Provides 38 | @Singleton 39 | fun provideGoogleApiAvailability() = GoogleApiAvailability.getInstance() 40 | 41 | @Provides 42 | @Singleton 43 | fun provideLocationProviderClient(application: Application) = 44 | LocationServices.getFusedLocationProviderClient(application) 45 | 46 | @Provides 47 | @Singleton 48 | fun provideGeocoder(application: Application) = Geocoder(application) 49 | } 50 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/java/com/google/android/gms/location/sample/locationaddress/data/GeocodingApi.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.locationaddress.data 18 | 19 | import android.location.Geocoder 20 | import android.location.Location 21 | import android.util.Log 22 | import kotlinx.coroutines.Dispatchers 23 | import kotlinx.coroutines.withContext 24 | import java.io.IOException 25 | import javax.inject.Inject 26 | 27 | data class FormattedAddress(val display: String) 28 | 29 | /** Provides an API to search for addresses from a [Location]. */ 30 | class GeocodingApi @Inject constructor( 31 | private val geocoder: Geocoder 32 | ) { 33 | // Geocoder specifically says that this call can use network and that it must not be called 34 | // from the main thread, so move it to the IO dispatcher. 35 | suspend fun getFromLocation( 36 | location: Location, 37 | maxResults: Int = 1 38 | ): List = withContext(Dispatchers.IO) { 39 | try { 40 | val addresses = geocoder.getFromLocation( 41 | location.latitude, 42 | location.longitude, 43 | maxResults 44 | ) ?: emptyList() 45 | addresses.map { address -> 46 | FormattedAddress( 47 | (0..address.maxAddressLineIndex) 48 | .joinToString("\n") { address.getAddressLine(it) } 49 | ) 50 | } 51 | } catch (e: IOException) { 52 | Log.w("GeocodingApi", "Error trying to get address from location.", e) 53 | emptyList() 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/java/com/google/android/gms/location/sample/locationaddress/data/LocationApi.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.locationaddress.data 18 | 19 | import android.location.Location 20 | import android.util.Log 21 | import com.google.android.gms.location.FusedLocationProviderClient 22 | import com.google.android.gms.location.LocationRequest 23 | import com.google.android.gms.tasks.CancellationTokenSource 24 | import kotlinx.coroutines.tasks.await 25 | import javax.inject.Inject 26 | 27 | class LocationApi @Inject constructor( 28 | private val locationProvider: FusedLocationProviderClient 29 | ) { 30 | 31 | suspend fun getCurrentLocation(): Location? { 32 | val cancellationTokenSource = CancellationTokenSource() 33 | return try { 34 | locationProvider.getCurrentLocation( 35 | LocationRequest.PRIORITY_HIGH_ACCURACY, 36 | cancellationTokenSource.token 37 | ).await(cancellationTokenSource) 38 | } catch (e: SecurityException) { 39 | Log.w("LocationApi", "Couldn't get location, did you request location permissions?", e) 40 | null 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/java/com/google/android/gms/location/sample/locationaddress/data/PlayServicesAvailabilityChecker.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.locationaddress.data 18 | 19 | import android.content.Context 20 | import com.google.android.gms.common.ConnectionResult 21 | import com.google.android.gms.common.GoogleApiAvailability 22 | import dagger.hilt.android.qualifiers.ApplicationContext 23 | import kotlinx.coroutines.Dispatchers 24 | import kotlinx.coroutines.withContext 25 | import javax.inject.Inject 26 | 27 | class PlayServicesAvailabilityChecker @Inject constructor( 28 | @ApplicationContext private val context: Context, 29 | private val googleApiAvailability: GoogleApiAvailability 30 | ) { 31 | suspend fun isGooglePlayServicesAvailable(): Boolean = withContext(Dispatchers.Default) { 32 | when (googleApiAvailability.isGooglePlayServicesAvailable(context)) { 33 | ConnectionResult.SUCCESS -> true 34 | else -> false 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/java/com/google/android/gms/location/sample/locationaddress/ui/DiscreteSlider.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.locationaddress.ui 18 | 19 | import androidx.compose.foundation.interaction.MutableInteractionSource 20 | import androidx.compose.material.Slider 21 | import androidx.compose.material.SliderColors 22 | import androidx.compose.material.SliderDefaults 23 | import androidx.compose.runtime.Composable 24 | import androidx.compose.runtime.remember 25 | import androidx.compose.ui.Modifier 26 | import kotlin.math.roundToInt 27 | 28 | /** 29 | * Compose [Slider] works with floating point values. This version works with integers and hides the 30 | * details of using floats underneath. 31 | */ 32 | @Composable 33 | fun DiscreteSlider( 34 | value: Int, 35 | valueRange: ClosedRange, 36 | onValueChange: (Int) -> Unit, 37 | modifier: Modifier = Modifier, 38 | enabled: Boolean = true, 39 | onValueChangeFinished: (() -> Unit)? = null, 40 | interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, 41 | colors: SliderColors = SliderDefaults.colors() 42 | ) = Slider( 43 | value = value.toFloat(), 44 | onValueChange = { onValueChange(it.roundToInt()) }, 45 | modifier = modifier, 46 | enabled = enabled, 47 | valueRange = valueRange.start.toFloat()..valueRange.endInclusive.toFloat(), 48 | steps = valueRange.endInclusive - valueRange.start - 1, 49 | onValueChangeFinished = onValueChangeFinished, 50 | interactionSource = interactionSource, 51 | colors = colors 52 | ) 53 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/java/com/google/android/gms/location/sample/locationaddress/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.locationaddress.ui.theme 18 | 19 | import androidx.compose.ui.graphics.Color 20 | 21 | val Purple200 = Color(0xFFBB86FC) 22 | val Purple500 = Color(0xFF6200EE) 23 | val Purple700 = Color(0xFF3700B3) 24 | val Teal200 = Color(0xFF03DAC5) 25 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/java/com/google/android/gms/location/sample/locationaddress/ui/theme/Shape.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.locationaddress.ui.theme 18 | 19 | import androidx.compose.foundation.shape.RoundedCornerShape 20 | import androidx.compose.material.Shapes 21 | import androidx.compose.ui.unit.dp 22 | 23 | val Shapes = Shapes( 24 | small = RoundedCornerShape(4.dp), 25 | medium = RoundedCornerShape(4.dp), 26 | large = RoundedCornerShape(0.dp) 27 | ) 28 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/java/com/google/android/gms/location/sample/locationaddress/ui/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.locationaddress.ui.theme 18 | 19 | import androidx.compose.foundation.isSystemInDarkTheme 20 | import androidx.compose.material.MaterialTheme 21 | import androidx.compose.material.darkColors 22 | import androidx.compose.material.lightColors 23 | import androidx.compose.runtime.Composable 24 | 25 | private val DarkColorPalette = darkColors( 26 | primary = Purple200, 27 | primaryVariant = Purple700, 28 | secondary = Teal200 29 | ) 30 | 31 | private val LightColorPalette = lightColors( 32 | primary = Purple500, 33 | primaryVariant = Purple700, 34 | secondary = Teal200 35 | 36 | /* Other default colors to override 37 | background = Color.White, 38 | surface = Color.White, 39 | onPrimary = Color.White, 40 | onSecondary = Color.Black, 41 | onBackground = Color.Black, 42 | onSurface = Color.Black, 43 | */ 44 | ) 45 | 46 | @Composable 47 | fun LocationAddressTheme( 48 | darkTheme: Boolean = isSystemInDarkTheme(), 49 | content: @Composable() () -> Unit 50 | ) { 51 | val colors = if (darkTheme) { 52 | DarkColorPalette 53 | } else { 54 | LightColorPalette 55 | } 56 | 57 | MaterialTheme( 58 | colors = colors, 59 | typography = Typography, 60 | shapes = Shapes, 61 | content = content 62 | ) 63 | } 64 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/java/com/google/android/gms/location/sample/locationaddress/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.android.gms.location.sample.locationaddress.ui.theme 18 | 19 | import androidx.compose.material.Typography 20 | import androidx.compose.ui.text.TextStyle 21 | import androidx.compose.ui.text.font.FontFamily 22 | import androidx.compose.ui.text.font.FontWeight 23 | import androidx.compose.ui.unit.sp 24 | 25 | // Set of Material typography styles to start with 26 | val Typography = Typography( 27 | body1 = TextStyle( 28 | fontFamily = FontFamily.Default, 29 | fontWeight = FontWeight.Normal, 30 | fontSize = 16.sp 31 | ) 32 | /* Other default text styles to override 33 | button = TextStyle( 34 | fontFamily = FontFamily.Default, 35 | fontWeight = FontWeight.W500, 36 | fontSize = 14.sp 37 | ), 38 | caption = TextStyle( 39 | fontFamily = FontFamily.Default, 40 | fontWeight = FontWeight.Normal, 41 | fontSize = 12.sp 42 | ) 43 | */ 44 | ) 45 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationAddress/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 33 | 34 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #FFBB86FC 20 | #FF6200EE 21 | #FF3700B3 22 | #FF03DAC5 23 | #FF018786 24 | #FF000000 25 | #FFFFFFFF 26 | 27 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | Location Address 20 | 21 | Initializing… 22 | Google Play Services are unavailable on this device. 23 | This sample requires access to precise location in order to retrieve an address. 24 | 25 | Find address 26 | Fetching address… 27 | Results: %d 28 | Max results: %d 29 | 30 | -------------------------------------------------------------------------------- /LocationAddress/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 33 | 34 | 38 | 39 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LocationUpdatesBackgroundKotlin/app/src/test/java/com/google/android/gms/location/sample/locationupdatesbackgroundkotlin/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.google.android.gms.location.sample.locationupdatesbackgroundkotlin 17 | 18 | import org.junit.Test 19 | 20 | import org.junit.Assert.* 21 | 22 | /** 23 | * Example local unit test, which will execute on the development machine (host). 24 | * 25 | * See [testing documentation](http://d.android.com/tools/testing). 26 | */ 27 | class ExampleUnitTest { 28 | @Test 29 | fun addition_isCorrect() { 30 | assertEquals(4, 2 + 2) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LocationUpdatesBackgroundKotlin/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 18 | 19 | buildscript { 20 | ext.kotlin_version = '1.6.0' 21 | repositories { 22 | google() 23 | mavenCentral() 24 | 25 | } 26 | dependencies { 27 | classpath 'com.android.tools.build:gradle:7.2.2' 28 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 29 | // NOTE: Do not place your application dependencies here; they belong 30 | // in the individual module build.gradle files 31 | } 32 | } 33 | 34 | allprojects { 35 | repositories { 36 | google() 37 | mavenCentral() 38 | } 39 | } 40 | 41 | task clean(type: Delete) { 42 | delete rootProject.buildDir 43 | } 44 | -------------------------------------------------------------------------------- /LocationUpdatesBackgroundKotlin/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /LocationUpdatesBackgroundKotlin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/LocationUpdatesBackgroundKotlin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /LocationUpdatesBackgroundKotlin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Feb 16 14:37:02 PST 2023 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /LocationUpdatesBackgroundKotlin/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name='LocationUpdatesBackgroundKotlin' 3 | -------------------------------------------------------------------------------- /SleepSampleKotlin/.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Mac files 6 | .DS_Store 7 | 8 | # files for the dex VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # generated files 15 | bin/ 16 | gen/ 17 | 18 | # Ignore gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | proguard-project.txt 28 | 29 | # Eclipse files 30 | .project 31 | .classpath 32 | .settings/ 33 | 34 | # Android Studio/IDEA 35 | *.iml 36 | .idea 37 | -------------------------------------------------------------------------------- /SleepSampleKotlin/.google/packaging.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # GOOGLE SAMPLE PACKAGING DATA 16 | # 17 | # This file is used by Google as part of our samples packaging process. 18 | # End users may safely ignore this file. It has no relevance to other systems. 19 | --- 20 | status: PUBLISHED 21 | technologies: [Android] 22 | categories: [Location,Context] 23 | languages: [Kotlin] 24 | solutions: [Mobile] 25 | github: android/location-samples 26 | level: INTERMEDIATE 27 | apiRefs: 28 | - gms:com.google.android.gms.location.SleepSegmentEvent 29 | - gms:com.google.android.gms.location.SleepClassifyEvent 30 | - gms:com.google.android.gms.location.SleepSegmentRequest 31 | - gms:com.google.android.gms.location.ActivityRecognition 32 | license: apache2 33 | -------------------------------------------------------------------------------- /SleepSampleKotlin/README.md: -------------------------------------------------------------------------------- 1 | Subscribe and Recognize to the User's Sleep Activity 2 | ==================================================== 3 | 4 | Demonstrates use of the [Sleep API][1] to recognize a user's sleep activity. 5 | 6 | Introduction 7 | ============ 8 | 9 | Demonstrates use of the [Sleep API][1] to recognize a user's current sleep activity. 10 | 11 | Users can request activity updates by pressing the "Subscribe to Sleep Data" button, 12 | and stop receiving updates using the "Unsubscribe to Sleep Data" button. 13 | 14 | Note: This sample targets the preferred minimum API level of 29. 15 | 16 | [1]: https://developers.google.com/location-context/sleep 17 | 18 | Prerequisites 19 | -------------- 20 | 21 | - Android API Level >v29 22 | - Android Build Tools >v21 23 | - Google (Support) Repository 24 | 25 | Getting Started 26 | --------------- 27 | 28 | This sample uses the Gradle build system. To build this project, use the "gradlew build" command or 29 | use "Import Project" in Android Studio. 30 | 31 | Support 32 | ------- 33 | 34 | - Stack Overflow: http://stackoverflow.com/questions/tagged/google-play-services 35 | 36 | If you've found an error in this sample, please file an issue: 37 | https://github.com/android/location-samples/issues 38 | 39 | Patches are encouraged, and may be submitted according to the instructions in 40 | CONTRIBUTING.md. 41 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /SleepSampleKotlin/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Add project specific ProGuard rules here. 16 | # You can control the set of applied configuration files using the 17 | # proguardFiles setting in build.gradle. 18 | # 19 | # For more details, see 20 | # http://developer.android.com/guide/developing/tools/proguard.html 21 | 22 | # If your project uses WebView with JS, uncomment the following 23 | # and specify the fully qualified class name to the JavaScript interface 24 | # class: 25 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 26 | # public *; 27 | #} 28 | 29 | # Uncomment this to preserve the line number information for 30 | # debugging stack traces. 31 | #-keepattributes SourceFile,LineNumberTable 32 | 33 | # If you keep the line number information, uncomment this to 34 | # hide the original source file name. 35 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/java/com/android/example/sleepsamplekotlin/MainApplication.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.android.example.sleepsamplekotlin 17 | 18 | import android.app.Application 19 | import androidx.datastore.preferences.createDataStore 20 | import com.android.example.sleepsamplekotlin.data.SleepRepository 21 | import com.android.example.sleepsamplekotlin.data.datastore.SLEEP_PREFERENCES_NAME 22 | import com.android.example.sleepsamplekotlin.data.datastore.SleepSubscriptionStatus 23 | import com.android.example.sleepsamplekotlin.data.db.SleepDatabase 24 | 25 | /** 26 | * Sets up repository for all sleep data. 27 | */ 28 | class MainApplication : Application() { 29 | // Both database and repository use lazy so they aren't created when the app starts, but only 30 | // when repository is first needed. 31 | private val database by lazy { 32 | SleepDatabase.getDatabase(applicationContext) 33 | } 34 | 35 | val repository by lazy { 36 | SleepRepository( 37 | sleepSubscriptionStatus = SleepSubscriptionStatus( 38 | applicationContext.createDataStore(name = SLEEP_PREFERENCES_NAME)), 39 | sleepSegmentEventDao = database.sleepSegmentEventDao(), 40 | sleepClassifyEventDao = database.sleepClassifyEventDao() 41 | ) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/java/com/android/example/sleepsamplekotlin/data/datastore/SleepSubscriptionStatus.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.android.example.sleepsamplekotlin.data.datastore 17 | 18 | import androidx.datastore.core.DataStore 19 | import androidx.datastore.preferences.core.Preferences 20 | import androidx.datastore.preferences.core.booleanPreferencesKey 21 | import androidx.datastore.preferences.core.edit 22 | import kotlinx.coroutines.flow.Flow 23 | import kotlinx.coroutines.flow.map 24 | 25 | const val SLEEP_PREFERENCES_NAME = "sleep_preferences" 26 | 27 | /** 28 | * Saves the sleep data subscription status into a [DataStore]. 29 | * Used to check if the app is still listening to changes in sleep data when the app is brought 30 | * back into the foreground. 31 | */ 32 | class SleepSubscriptionStatus(private val dataStore: DataStore) { 33 | 34 | private object PreferencesKeys { 35 | val SUBSCRIBED_TO_SLEEP_DATA = booleanPreferencesKey("subscribed_to_sleep_data") 36 | } 37 | // Observed Flow will notify the observer when the the sleep subscription status has changed. 38 | val subscribedToSleepDataFlow: Flow = dataStore.data.map { preferences -> 39 | // Get the subscription value, defaults to false if not set: 40 | preferences[PreferencesKeys.SUBSCRIBED_TO_SLEEP_DATA] ?: false 41 | } 42 | 43 | // Updates subscription status. 44 | suspend fun updateSubscribedToSleepData(subscribedToSleepData: Boolean) { 45 | dataStore.edit { preferences -> 46 | preferences[PreferencesKeys.SUBSCRIBED_TO_SLEEP_DATA] = subscribedToSleepData 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/java/com/android/example/sleepsamplekotlin/data/db/SleepClassifyEventDao.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.android.example.sleepsamplekotlin.data.db 17 | 18 | import androidx.room.Dao 19 | import androidx.room.Delete 20 | import androidx.room.Insert 21 | import androidx.room.OnConflictStrategy 22 | import androidx.room.Query 23 | import kotlinx.coroutines.flow.Flow 24 | 25 | /** 26 | * Defines [SleepClassifyEventEntity] database operations. 27 | */ 28 | @Dao 29 | interface SleepClassifyEventDao { 30 | @Query("SELECT * FROM sleep_classify_events_table ORDER BY time_stamp_seconds DESC") 31 | fun getAll(): Flow> 32 | 33 | @Insert(onConflict = OnConflictStrategy.REPLACE) 34 | suspend fun insert(sleepClassifyEventEntity: SleepClassifyEventEntity) 35 | 36 | @Insert(onConflict = OnConflictStrategy.REPLACE) 37 | suspend fun insertAll(sleepClassifyEventEntities: List) 38 | 39 | @Delete 40 | suspend fun delete(sleepClassifyEventEntity: SleepClassifyEventEntity) 41 | 42 | @Query("DELETE FROM sleep_classify_events_table") 43 | suspend fun deleteAll() 44 | } 45 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/java/com/android/example/sleepsamplekotlin/data/db/SleepClassifyEventEntity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.android.example.sleepsamplekotlin.data.db 17 | 18 | import androidx.room.ColumnInfo 19 | import androidx.room.Entity 20 | import androidx.room.PrimaryKey 21 | import com.google.android.gms.location.SleepClassifyEvent 22 | 23 | /** 24 | * Entity class (table version of the class) for [SleepClassifyEvent] which represents a sleep 25 | * classification event including the classification timestamp, the sleep confidence, and the 26 | * supporting data such as device motion and ambient light level. Classification events are 27 | * reported regularly. 28 | */ 29 | @Entity(tableName = "sleep_classify_events_table") 30 | data class SleepClassifyEventEntity( 31 | @PrimaryKey 32 | @ColumnInfo(name = "time_stamp_seconds") 33 | val timestampSeconds: Int, 34 | 35 | @ColumnInfo(name = "confidence") 36 | val confidence: Int, 37 | 38 | @ColumnInfo(name = "motion") 39 | val motion: Int, 40 | 41 | @ColumnInfo(name = "light") 42 | val light: Int 43 | ) { 44 | companion object { 45 | fun from(sleepClassifyEvent: SleepClassifyEvent): SleepClassifyEventEntity { 46 | return SleepClassifyEventEntity( 47 | timestampSeconds = (sleepClassifyEvent.timestampMillis / 1000).toInt(), 48 | confidence = sleepClassifyEvent.confidence, 49 | motion = sleepClassifyEvent.motion, 50 | light = sleepClassifyEvent.light 51 | ) 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/java/com/android/example/sleepsamplekotlin/data/db/SleepDatabase.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.android.example.sleepsamplekotlin.data.db 17 | 18 | import android.content.Context 19 | import androidx.room.Database 20 | import androidx.room.Room 21 | import androidx.room.RoomDatabase 22 | 23 | private const val DATABASE_NAME = "sleep_segments_database" 24 | 25 | /** 26 | * Stores all sleep segment data. 27 | */ 28 | @Database( 29 | entities = [SleepSegmentEventEntity::class, SleepClassifyEventEntity::class], 30 | version = 3, 31 | exportSchema = false 32 | ) 33 | abstract class SleepDatabase : RoomDatabase() { 34 | 35 | abstract fun sleepSegmentEventDao(): SleepSegmentEventDao 36 | abstract fun sleepClassifyEventDao(): SleepClassifyEventDao 37 | 38 | companion object { 39 | // For Singleton instantiation 40 | @Volatile 41 | private var INSTANCE: SleepDatabase? = null 42 | 43 | fun getDatabase(context: Context): SleepDatabase { 44 | return INSTANCE ?: synchronized(this) { 45 | val instance = Room.databaseBuilder( 46 | context, 47 | SleepDatabase::class.java, 48 | DATABASE_NAME 49 | ) 50 | // Wipes and rebuilds instead of migrating if no Migration object. 51 | // Migration is not part of this sample. 52 | .fallbackToDestructiveMigration() 53 | .build() 54 | INSTANCE = instance 55 | // return instance 56 | instance 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/java/com/android/example/sleepsamplekotlin/data/db/SleepSegmentEventDao.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.android.example.sleepsamplekotlin.data.db 17 | 18 | import androidx.room.Dao 19 | import androidx.room.Delete 20 | import androidx.room.Insert 21 | import androidx.room.OnConflictStrategy 22 | import androidx.room.Query 23 | import kotlinx.coroutines.flow.Flow 24 | 25 | /** 26 | * Defines [SleepSegmentEventEntity] database operations. 27 | */ 28 | @Dao 29 | interface SleepSegmentEventDao { 30 | @Query("SELECT * FROM sleep_segment_events_table ORDER BY start_time_millis DESC") 31 | fun getAll(): Flow> 32 | 33 | @Insert(onConflict = OnConflictStrategy.REPLACE) 34 | suspend fun insert(sleepSegmentEventEntity: SleepSegmentEventEntity) 35 | 36 | @Insert(onConflict = OnConflictStrategy.REPLACE) 37 | suspend fun insertAll(sleepSegmentEventEntities: List) 38 | 39 | @Delete 40 | suspend fun delete(sleepSegmentEventEntity: SleepSegmentEventEntity) 41 | 42 | @Query("DELETE FROM sleep_segment_events_table") 43 | suspend fun deleteAll() 44 | } 45 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/java/com/android/example/sleepsamplekotlin/data/db/SleepSegmentEventEntity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.android.example.sleepsamplekotlin.data.db 17 | 18 | import androidx.room.ColumnInfo 19 | import androidx.room.Entity 20 | import androidx.room.PrimaryKey 21 | import com.google.android.gms.location.SleepSegmentEvent 22 | 23 | /** 24 | * Data class for Sleep Segment Events which represents the time the user slept at night. 25 | */ 26 | @Entity(tableName = "sleep_segment_events_table") 27 | data class SleepSegmentEventEntity( 28 | @PrimaryKey 29 | @ColumnInfo(name = "start_time_millis") 30 | val startTimeMillis: Long, 31 | 32 | @ColumnInfo(name = "end_time_millis") 33 | val endTimeMillis: Long, 34 | 35 | @ColumnInfo(name = "status") 36 | val status: Int 37 | ) { 38 | companion object { 39 | fun from(sleepSegmentEvent: SleepSegmentEvent): SleepSegmentEventEntity { 40 | return SleepSegmentEventEntity( 41 | startTimeMillis = sleepSegmentEvent.startTimeMillis, 42 | endTimeMillis = sleepSegmentEvent.endTimeMillis, 43 | status = sleepSegmentEvent.status 44 | ) 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 32 | 33 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | #FFBB86FC 19 | #FF6200EE 20 | #FF3700B3 21 | #FF03DAC5 22 | #FF018786 23 | #FF000000 24 | #FFFFFFFF 25 | 26 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | SleepSampleKotlin 19 | Click on the button below to subscribe to Sleep Transitions! 20 | Subscribe to Sleep Data 21 | Unsubscribe to Sleep Data 22 | 23 | Settings 24 | Sample requires Activity Recognition permissions to function. 25 | No 26 | Yes 27 | Permission Approved! 28 | 29 | 30 | Currently subscribed to sleep data:\nSleepClassifyEvents should occur regularly.\n(Last update: %1$s):\n\n 31 | Currently NOT subscribed to sleep data:\n(Information below was saved from previous sessions to the database):\n\n 32 | === Sleep Segment Events ===\n%1$s\n\n=== Sleep Classify Events ===\n%2$s 33 | 34 | -------------------------------------------------------------------------------- /SleepSampleKotlin/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 32 | 33 | -------------------------------------------------------------------------------- /SleepSampleKotlin/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 17 | buildscript { 18 | ext.kotlin_version = "1.4.21" 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | dependencies { 24 | classpath "com.android.tools.build:gradle:4.1.2" 25 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 26 | 27 | // NOTE: Do not place your application dependencies here; they belong 28 | // in the individual module build.gradle files 29 | } 30 | } 31 | 32 | allprojects { 33 | repositories { 34 | google() 35 | jcenter() 36 | } 37 | } 38 | 39 | task clean(type: Delete) { 40 | delete rootProject.buildDir 41 | } -------------------------------------------------------------------------------- /SleepSampleKotlin/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Project-wide Gradle settings. 16 | # IDE (e.g. Android Studio) users: 17 | # Gradle settings configured through the IDE *will override* 18 | # any settings specified in this file. 19 | # For more details on how to configure your build environment visit 20 | # http://www.gradle.org/docs/current/userguide/build_environment.html 21 | # Specifies the JVM arguments used for the daemon process. 22 | # The setting is particularly useful for tweaking memory settings. 23 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 24 | # When configured, Gradle will run in incubating parallel mode. 25 | # This option should only be used with decoupled projects. More details, visit 26 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 27 | # org.gradle.parallel=true 28 | # AndroidX package structure to make it clearer which packages are bundled with the 29 | # Android operating system, and which are packaged with your app"s APK 30 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 31 | android.useAndroidX=true 32 | # Automatically convert third-party libraries to use AndroidX 33 | android.enableJetifier=true 34 | # Kotlin code style for this project: "official" or "obsolete": 35 | kotlin.code.style=official -------------------------------------------------------------------------------- /SleepSampleKotlin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/android/location-samples/8110fbc1234e502bbd63ac6b46443743ae248466/SleepSampleKotlin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /SleepSampleKotlin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2021 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | #Sun Jan 17 15:22:15 PST 2021 16 | distributionBase=GRADLE_USER_HOME 17 | distributionPath=wrapper/dists 18 | zipStoreBase=GRADLE_USER_HOME 19 | zipStorePath=wrapper/dists 20 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip 21 | -------------------------------------------------------------------------------- /SleepSampleKotlin/settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | include ':app' 17 | rootProject.name = "SleepSampleKotlin" --------------------------------------------------------------------------------