├── .gitignore
├── app
├── src
│ └── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ ├── drawable
│ │ │ ├── android_map.png
│ │ │ └── android_treasure.png
│ │ ├── font
│ │ │ └── della_respira.ttf
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── drawable-xxxhdpi
│ │ │ └── map_small.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_round.png
│ │ │ └── ic_launcher_foreground.png
│ │ ├── values
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ └── layout
│ │ │ └── activity_hunt_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── android
│ │ └── treasureHunt
│ │ ├── GeofenceViewModel.kt
│ │ ├── GeofenceUtils.kt
│ │ ├── GeofenceBroadcastReceiver.kt
│ │ ├── NotificationUtils.kt
│ │ └── HuntMainActivity.kt
├── .gitignore
├── proguard-rules.pro
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle
├── .github
└── ISSUE_TEMPLATE
│ └── advanced-android-in-kotlin-issue.md
├── README.md
├── CONTRIBUTING.md
├── gradle.properties
├── gradlew.bat
├── gradlew
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | *.iml
3 | local.properties
4 | build
5 | .gradle
6 | # Eclipse project files
7 | .project
8 | .settings/
9 | .classpath
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/android_map.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/drawable/android_map.png
--------------------------------------------------------------------------------
/app/src/main/res/font/della_respira.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/font/della_respira.ttf
--------------------------------------------------------------------------------
/app/src/main/res/drawable/android_treasure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/drawable/android_treasure.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/map_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/drawable-xxxhdpi/map_small.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/advanced-android-kotlin-geo-fences/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 17 11:45:33 PDT 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/.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
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 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 | * 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 | include ':app'
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #FFFFFF
20 |
21 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/advanced-android-in-kotlin-issue.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Advanced Android in Kotlin issue
3 | about: Report problems with Advanced Android in Kotlin codelab.
4 | title: " Advanced Android in Kotlin: Geofences 4.2 [Step #][description]"
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the problem**
11 | A clear and concise description of what the problem is.
12 |
13 | **In which lesson and step of the codelab can this issue be found?**
14 | Lesson number + step number. (e.g., Lesson 4.2, Step 1.3)
15 |
16 | **How to reproduce?**
17 | What are the exact steps to reproduce the problem?
18 |
19 | **Versions**
20 | 1. What version of Android Studio are you using?
21 | 2. What API level are you targeting?
22 |
23 | **Additional information**
24 | Add any other context about the problem here.
25 |
26 | **codelab:** advanced-android-kotlin
27 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #008577
20 | #00574B
21 | #D81B60
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | 16dp
20 | 8dp
21 | 16dp
22 | 24sp
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Geofencing - Final code
2 | =======================
3 |
4 | Solution code for Advanced Android with Kotlin Codelab
5 |
6 | Introduction
7 | ------------
8 | A geofence is a virtual perimeter defined by GPS or RFID around a real world area.
9 | Geofences can be created with a radius around a point location.
10 |
11 | Geofencing has a lot of applications including:
12 |
13 | - Reminder apps, such as reminding you to pick up a prescription when you get to a certain destination like your pharmacy.
14 | - Child location services, where a parent can be notified if a child leaves an area designated by a geofence.
15 | - Attendance, where an employer can know when their employees arrive by the time they enter a geofence.
16 | - A treasure hunt app that uses geofences to mark the place where the treasure is hidden. When you enter that place, you will be notified that you have won! - This is what you will be making in this codelab!
17 |
18 | Pre-requisites
19 | --------------
20 | - The latest version of Android Studio.
21 | - A minimum of SDK API 29 on your device or emulator. (This should still work on lower API levels but may look differenti.)
22 |
23 | Getting Started
24 | ---------------
25 | 1. Download and run the app.
26 | 2. If you are running API 29 or higher, grant the "Always allow" permission; otherwisa, grant "Allow" for location permissions.
27 |
28 | Note: If you are running this app on an emulator, you will need to use another app to pull location data from.
29 | This is because geofencing relies on device sensors to detect the location of the device, which the emulator cannot access.
30 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to become a contributor and submit your own code
2 |
3 | ## Contributor License Agreements
4 |
5 | We'd love to accept your sample apps and patches! Before we can take them, we
6 | have to jump a couple of legal hurdles.
7 |
8 | Please fill out either the individual or corporate Contributor License Agreement
9 | (CLA).
10 |
11 | * If you are an individual writing original source code and you're sure you
12 | own the intellectual property, then you'll need to sign an [individual CLA]
13 | (https://developers.google.com/open-source/cla/individual).
14 | * If you work for a company that wants to allow you to contribute your work,
15 | then you'll need to sign a [corporate CLA]
16 | (https://developers.google.com/open-source/cla/corporate).
17 |
18 | Follow either of the two links above to access the appropriate CLA and
19 | instructions for how to sign and return it. Once we receive it, we'll be able to
20 | accept your pull requests.
21 |
22 | ## Contributing A Patch
23 |
24 | 1. Submit an issue describing your proposed change to the repo in question.
25 | 1. The repo owner will respond to your issue promptly.
26 | 1. If your proposed change is accepted, and you haven't already done so, sign a
27 | Contributor License Agreement (see details above).
28 | 1. Fork the desired repo, develop and test your code changes.
29 | 1. Ensure that your code adheres to the existing style in the sample to which
30 | you are contributing. Refer to the
31 | [Google Cloud Platform Samples Style Guide]
32 | (https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the
33 | recommended coding standards for this organization.
34 | 1. Ensure that your code has an appropriate set of unit tests which all pass.
35 | 1. Submit a pull request.
36 |
37 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2019 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 | # 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 | # Project-wide Gradle settings.
18 | # IDE (e.g. Android Studio) users:
19 | # Gradle settings configured through the IDE *will override*
20 | # any settings specified in this file.
21 | # For more details on how to configure your build environment visit
22 | # http://www.gradle.org/docs/current/userguide/build_environment.html
23 | # Specifies the JVM arguments used for the daemon process.
24 | # The setting is particularly useful for tweaking memory settings.
25 | org.gradle.jvmargs=-Xmx1536m
26 | # When configured, Gradle will run in incubating parallel mode.
27 | # This option should only be used with decoupled projects. More details, visit
28 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
29 | # org.gradle.parallel=true
30 | # AndroidX package structure to make it clearer which packages are bundled with the
31 | # Android operating system, and which are packaged with your app's APK
32 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
33 | android.useAndroidX=true
34 | # Automatically convert third-party libraries to use AndroidX
35 | android.enableJetifier=true
36 | # Kotlin code style for this project: "official" or "obsolete":
37 | kotlin.code.style=official
38 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
23 |
24 |
27 |
28 |
29 |
36 |
37 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 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 | * 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 | apply plugin: 'com.android.application'
18 |
19 | apply plugin: 'kotlin-android'
20 |
21 | apply plugin: 'kotlin-android-extensions'
22 |
23 | android {
24 | compileSdkVersion 29
25 | defaultConfig {
26 | applicationId "com.example.android.treasureHunt"
27 | minSdkVersion 19
28 | targetSdkVersion 29
29 | versionCode 1
30 | versionName "1.0"
31 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
32 | }
33 | buildTypes {
34 | release {
35 | minifyEnabled false
36 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
37 | }
38 | }
39 |
40 | dataBinding {
41 | enabled true
42 | }
43 | }
44 |
45 | dependencies {
46 | implementation fileTree(dir: 'libs', include: ['*.jar'])
47 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
48 | implementation 'androidx.appcompat:appcompat:1.1.0'
49 | implementation 'androidx.core:core-ktx:1.1.0'
50 | implementation 'com.google.android.gms:play-services-maps:17.0.0'
51 | implementation 'com.google.android.gms:play-services-location:17.0.0'
52 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
53 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
54 | testImplementation 'junit:junit:4.12'
55 | androidTestImplementation 'androidx.test:runner:1.2.0'
56 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
57 | implementation 'com.google.android.material:material:1.0.0'
58 | implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
59 | implementation 'androidx.lifecycle:lifecycle-viewmodel-savedstate:1.0.0-beta01'
60 | }
61 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/treasureHunt/GeofenceViewModel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 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 | * 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 | package com.example.android.treasureHunt
18 |
19 | import androidx.lifecycle.LiveData
20 | import androidx.lifecycle.SavedStateHandle
21 | import androidx.lifecycle.Transformations
22 | import androidx.lifecycle.ViewModel
23 |
24 | /*
25 | * This class contains the state of the game. The two important pieces of state are the index
26 | * of the geofence, which is the geofence that the game thinks is active, and the state of the
27 | * hint being shown. If the hint matches the geofence, then the Activity won't update the geofence
28 | * as it cycles through various activity states.
29 | *
30 | * These states are stored in SavedState, which matches the Android lifecycle. Destroying the
31 | * associated Activity with the back action will delete all state and reset the game, while
32 | * the Home action will cause the state to be saved, even if the game is terminated by Android in
33 | * the background.
34 | */
35 | class GeofenceViewModel(state: SavedStateHandle) : ViewModel() {
36 | private val _geofenceIndex = state.getLiveData(GEOFENCE_INDEX_KEY, -1)
37 | private val _hintIndex = state.getLiveData(HINT_INDEX_KEY, 0)
38 | val geofenceIndex: LiveData
39 | get() = _geofenceIndex
40 |
41 | val geofenceHintResourceId = Transformations.map(geofenceIndex) {
42 | val index = geofenceIndex?.value ?: -1
43 | when {
44 | index < 0 -> R.string.not_started_hint
45 | index < GeofencingConstants.NUM_LANDMARKS -> GeofencingConstants.LANDMARK_DATA[geofenceIndex.value!!].hint
46 | else -> R.string.geofence_over
47 | }
48 | }
49 |
50 | val geofenceImageResourceId = Transformations.map(geofenceIndex) {
51 | val index = geofenceIndex.value ?: -1
52 | when {
53 | index < GeofencingConstants.NUM_LANDMARKS -> R.drawable.android_map
54 | else -> R.drawable.android_treasure
55 | }
56 | }
57 |
58 | fun updateHint(currentIndex: Int) {
59 | _hintIndex.value = currentIndex+1
60 | }
61 |
62 | fun geofenceActivated() {
63 | _geofenceIndex.value = _hintIndex.value
64 | }
65 |
66 | fun geofenceIsActive() =_geofenceIndex.value == _hintIndex.value
67 | fun nextGeofenceIndex() = _hintIndex.value ?: 0
68 | }
69 |
70 | private const val HINT_INDEX_KEY = "hintIndex"
71 | private const val GEOFENCE_INDEX_KEY = "geofenceIndex"
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/treasureHunt/GeofenceUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 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 | * 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 | package com.example.android.treasureHunt
18 |
19 | import android.content.Context
20 | import com.google.android.gms.location.GeofenceStatusCodes
21 | import com.google.android.gms.maps.model.LatLng
22 | import java.util.concurrent.TimeUnit
23 |
24 | /**
25 | * Returns the error string for a geofencing error code.
26 | */
27 | fun errorMessage(context: Context, errorCode: Int): String {
28 | val resources = context.resources
29 | return when (errorCode) {
30 | GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE -> resources.getString(
31 | R.string.geofence_not_available
32 | )
33 | GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES -> resources.getString(
34 | R.string.geofence_too_many_geofences
35 | )
36 | GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS -> resources.getString(
37 | R.string.geofence_too_many_pending_intents
38 | )
39 | else -> resources.getString(R.string.unknown_geofence_error)
40 | }
41 | }
42 |
43 | /**
44 | * Stores latitude and longitude information along with a hint to help user find the location.
45 | */
46 | data class LandmarkDataObject(val id: String, val hint: Int, val name: Int, val latLong: LatLng)
47 |
48 | internal object GeofencingConstants {
49 |
50 | /**
51 | * Used to set an expiration time for a geofence. After this amount of time, Location services
52 | * stops tracking the geofence. For this sample, geofences expire after one hour.
53 | */
54 | val GEOFENCE_EXPIRATION_IN_MILLISECONDS: Long = TimeUnit.HOURS.toMillis(1)
55 |
56 | val LANDMARK_DATA = arrayOf(
57 | LandmarkDataObject(
58 | "golden_gate_bridge",
59 | R.string.golden_gate_bridge_hint,
60 | R.string.golden_gate_bridge_location,
61 | LatLng(37.819927, -122.478256)),
62 |
63 | LandmarkDataObject(
64 | "ferry_building",
65 | R.string.ferry_building_hint,
66 | R.string.ferry_building_location,
67 | LatLng(37.795490, -122.394276)),
68 |
69 | LandmarkDataObject(
70 | "pier_39",
71 | R.string.pier_39_hint,
72 | R.string.pier_39_location,
73 | LatLng(37.808674, -122.409821)),
74 |
75 | LandmarkDataObject(
76 | "union_square",
77 | R.string.union_square_hint,
78 | R.string.union_square_location,
79 | LatLng(37.788151, -122.407570))
80 | )
81 |
82 | val NUM_LANDMARKS = LANDMARK_DATA.size
83 | const val GEOFENCE_RADIUS_IN_METERS = 100f
84 | const val EXTRA_GEOFENCE_INDEX = "GEOFENCE_INDEX"
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_hunt_main.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
21 |
22 |
23 |
26 |
27 |
28 |
37 |
38 |
55 |
56 |
62 |
63 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/treasureHunt/GeofenceBroadcastReceiver.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 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 | * 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 | package com.example.android.treasureHunt
18 |
19 | import android.app.NotificationManager
20 | import android.content.BroadcastReceiver
21 | import android.content.Context
22 | import android.content.Intent
23 | import android.util.Log
24 | import androidx.core.content.ContextCompat
25 | import com.example.android.treasureHunt.HuntMainActivity.Companion.ACTION_GEOFENCE_EVENT
26 | import com.google.android.gms.location.Geofence
27 | import com.google.android.gms.location.GeofencingEvent
28 |
29 | /*
30 | * Triggered by the Geofence. Since we only have one active Geofence at once, we pull the request
31 | * ID from the first Geofence, and locate it within the registered landmark data in our
32 | * GeofencingConstants within GeofenceUtils, which is a linear string search. If we had very large
33 | * numbers of Geofence possibilities, it might make sense to use a different data structure. We
34 | * then pass the Geofence index into the notification, which allows us to have a custom "found"
35 | * message associated with each Geofence.
36 | */
37 | class GeofenceBroadcastReceiver : BroadcastReceiver() {
38 |
39 | override fun onReceive(context: Context, intent: Intent) {
40 | if (intent.action == ACTION_GEOFENCE_EVENT) {
41 | val geofencingEvent = GeofencingEvent.fromIntent(intent)
42 |
43 | if (geofencingEvent.hasError()) {
44 | val errorMessage = errorMessage(context, geofencingEvent.errorCode)
45 | Log.e(TAG, errorMessage)
46 | return
47 | }
48 |
49 | if (geofencingEvent.geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
50 | Log.v(TAG, context.getString(R.string.geofence_entered))
51 |
52 | val fenceId = when {
53 | geofencingEvent.triggeringGeofences.isNotEmpty() ->
54 | geofencingEvent.triggeringGeofences[0].requestId
55 | else -> {
56 | Log.e(TAG, "No Geofence Trigger Found! Abort mission!")
57 | return
58 | }
59 | }
60 | // Check geofence against the constants listed in GeofenceUtil.kt to see if the
61 | // user has entered any of the locations we track for geofences.
62 | val foundIndex = GeofencingConstants.LANDMARK_DATA.indexOfFirst {
63 | it.id == fenceId
64 | }
65 |
66 | // Unknown Geofences aren't helpful to us
67 | if ( -1 == foundIndex ) {
68 | Log.e(TAG, "Unknown Geofence: Abort Mission")
69 | return
70 | }
71 |
72 | val notificationManager = ContextCompat.getSystemService(
73 | context,
74 | NotificationManager::class.java
75 | ) as NotificationManager
76 |
77 | notificationManager.sendGeofenceEnteredNotification(
78 | context, foundIndex
79 | )
80 | }
81 | }
82 | }
83 | }
84 |
85 | private const val TAG = "GeofenceReceiver"
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/treasureHunt/NotificationUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 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 | * 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 | package com.example.android.treasureHunt
18 |
19 | import android.app.NotificationChannel
20 | import android.app.NotificationManager
21 | import android.app.PendingIntent
22 | import android.content.Context
23 | import android.content.Intent
24 | import android.graphics.BitmapFactory
25 | import android.graphics.Color
26 | import android.os.Build
27 | import androidx.core.app.NotificationCompat
28 |
29 | /*
30 | * We need to create a NotificationChannel associated with our CHANNEL_ID before sending a
31 | * notification.
32 | */
33 | fun createChannel(context: Context) {
34 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
35 | val notificationChannel = NotificationChannel(
36 | CHANNEL_ID,
37 | context.getString(R.string.channel_name),
38 |
39 | NotificationManager.IMPORTANCE_HIGH
40 | )
41 | .apply {
42 | setShowBadge(false)
43 | }
44 |
45 | notificationChannel.enableLights(true)
46 | notificationChannel.lightColor = Color.RED
47 | notificationChannel.enableVibration(true)
48 | notificationChannel.description = context.getString(R.string.notification_channel_description)
49 |
50 | val notificationManager = context.getSystemService(NotificationManager::class.java)
51 | notificationManager.createNotificationChannel(notificationChannel)
52 | }
53 | }
54 |
55 | /*
56 | * A Kotlin extension function for AndroidX's NotificationCompat that sends our Geofence
57 | * entered notification. It sends a custom notification based on the name string associated
58 | * with the LANDMARK_DATA from GeofencingConstatns in the GeofenceUtils file.
59 | */
60 | fun NotificationManager.sendGeofenceEnteredNotification(context: Context, foundIndex: Int) {
61 | val contentIntent = Intent(context, HuntMainActivity::class.java)
62 | contentIntent.putExtra(GeofencingConstants.EXTRA_GEOFENCE_INDEX, foundIndex)
63 | val contentPendingIntent = PendingIntent.getActivity(
64 | context,
65 | NOTIFICATION_ID,
66 | contentIntent,
67 | PendingIntent.FLAG_UPDATE_CURRENT
68 | )
69 | val mapImage = BitmapFactory.decodeResource(
70 | context.resources,
71 | R.drawable.map_small
72 | )
73 | val bigPicStyle = NotificationCompat.BigPictureStyle()
74 | .bigPicture(mapImage)
75 | .bigLargeIcon(null)
76 |
77 | // We use the name resource ID from the LANDMARK_DATA along with content_text to create
78 | // a custom message when a Geofence triggers.
79 | val builder = NotificationCompat.Builder(context, CHANNEL_ID)
80 | .setContentTitle(context.getString(R.string.app_name))
81 | .setContentText(context.getString(R.string.content_text,
82 | context.getString(GeofencingConstants.LANDMARK_DATA[foundIndex].name)))
83 | .setPriority(NotificationCompat.PRIORITY_HIGH)
84 | .setContentIntent(contentPendingIntent)
85 | .setSmallIcon(R.drawable.map_small)
86 | .setStyle(bigPicStyle)
87 | .setLargeIcon(mapImage)
88 |
89 | notify(NOTIFICATION_ID, builder.build())
90 | }
91 |
92 | private const val NOTIFICATION_ID = 33
93 | private const val CHANNEL_ID = "GeofenceChannel"
94 |
95 |
96 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | Treasure Hunt
19 | Treasure Hunt
20 |
21 |
22 | Location permission needed for core functionality of the game.
24 |
25 |
26 |
27 | You need to grant location permission in order to play this game.
28 |
29 | Settings
30 | Please turn on device location in Settings and try again.
32 |
33 |
34 |
35 | Clue Geofence added.
36 | Geofences removed.
37 | Geofence entered.
38 | You have found the treasure! Congratulations!
39 |
40 |
41 |
42 | Go to a bridge with a name that does not match the color that it is!
43 | Go to a market with an amazing assortment of delicious foods. It is a San Francisco classic!
44 | Go to a pier popular for tourist attractions, carnival games, fresh fish, and delicious sourdough bread!
45 | Go to a square named after Civil War rallies held there, but now known for its amazing shopping!
46 |
47 |
48 | at the Golden Gate bridge
49 | in the Ferry Building
50 | at Pier 39
51 | in Union Square
52 |
53 |
54 | Geofence service is not available now
55 | Your app has registered too many geofences
56 |
57 | You have provided too many PendingIntents to the addGeofences() call
58 |
59 |
60 | Unknown error: the Geofence service is not available now
61 |
62 | Location services must be enabled for this game.
63 |
64 | Geofences not removed.
65 | Problem in adding geofences.
66 | Insufficient permissions.
67 | There was an error in finding your treasure
68 |
69 |
70 | GeofenceStatus
71 | You found a clue %1$s.
72 | Geofence status notification
73 |
74 |
75 | An Android robot with a map
76 |
77 |
78 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/treasureHunt/HuntMainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2019 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 | * 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 | package com.example.android.treasureHunt
18 |
19 | import android.app.PendingIntent
20 | import android.content.Intent
21 | import android.content.pm.PackageManager
22 | import android.Manifest
23 | import android.annotation.TargetApi
24 | import android.content.IntentSender
25 | import android.net.Uri
26 | import android.os.Bundle
27 | import android.provider.Settings
28 | import android.util.Log
29 | import android.widget.Toast
30 | import androidx.appcompat.app.AppCompatActivity
31 | import androidx.core.app.ActivityCompat
32 | import androidx.databinding.DataBindingUtil
33 | import androidx.lifecycle.SavedStateViewModelFactory
34 | import androidx.lifecycle.ViewModelProviders
35 | import com.example.android.treasureHunt.databinding.ActivityHuntMainBinding
36 | import com.google.android.gms.common.api.ResolvableApiException
37 | import com.google.android.gms.location.Geofence
38 | import com.google.android.gms.location.GeofencingClient
39 | import com.google.android.gms.location.GeofencingRequest
40 | import com.google.android.gms.location.LocationRequest
41 | import com.google.android.gms.location.LocationServices
42 | import com.google.android.gms.location.LocationSettingsRequest
43 | import com.google.android.material.snackbar.Snackbar
44 |
45 | /**
46 | * The Treasure Hunt app is a single-player game based on geofences.
47 | *
48 | * This app demonstrates how to create and remove geofences using the GeofencingApi. Uses an
49 | * BroadcastReceiver to monitor geofence transitions and creates notification and finishes the game
50 | * when the user enters the final geofence (destination).
51 | *
52 | * This app requires a device's Location settings to be turned on. It also requires
53 | * the ACCESS_FINE_LOCATION permission and user consent. For geofences to work
54 | * in Android Q, app also needs the ACCESS_BACKGROUND_LOCATION permission and user consent.
55 | */
56 |
57 | class HuntMainActivity : AppCompatActivity() {
58 |
59 | private lateinit var binding: ActivityHuntMainBinding
60 | private lateinit var geofencingClient: GeofencingClient
61 | private lateinit var viewModel: GeofenceViewModel
62 |
63 | private val runningQOrLater =
64 | android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q
65 |
66 | // A PendingIntent for the Broadcast Receiver that handles geofence transitions.
67 | private val geofencePendingIntent: PendingIntent by lazy {
68 | val intent = Intent(this, GeofenceBroadcastReceiver::class.java)
69 | intent.action = ACTION_GEOFENCE_EVENT
70 | // Use FLAG_UPDATE_CURRENT so that you get the same pending intent back when calling
71 | // addGeofences() and removeGeofences().
72 | PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
73 | }
74 |
75 | override fun onCreate(savedInstanceState: Bundle?) {
76 | super.onCreate(savedInstanceState)
77 | binding = DataBindingUtil.setContentView(this, R.layout.activity_hunt_main)
78 | viewModel = ViewModelProviders.of(this, SavedStateViewModelFactory(this.application,
79 | this)).get(GeofenceViewModel::class.java)
80 | binding.viewmodel = viewModel
81 | binding.lifecycleOwner = this
82 | geofencingClient = LocationServices.getGeofencingClient(this)
83 |
84 | // Create channel for notifications
85 | createChannel(this )
86 | }
87 |
88 | override fun onStart() {
89 | super.onStart()
90 | checkPermissionsAndStartGeofencing()
91 | }
92 |
93 | /*
94 | * When we get the result from asking the user to turn on device location, we call
95 | * checkDeviceLocationSettingsAndStartGeofence again to make sure it's actually on, but
96 | * we don't resolve the check to keep the user from seeing an endless loop.
97 | */
98 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
99 | super.onActivityResult(requestCode, resultCode, data)
100 | if (requestCode == REQUEST_TURN_DEVICE_LOCATION_ON) {
101 | // We don't rely on the result code, but just check the location setting again
102 | checkDeviceLocationSettingsAndStartGeofence(false)
103 | }
104 | }
105 |
106 | /*
107 | * When the user clicks on the notification, this method will be called, letting us know that
108 | * the geofence has been triggered, and it's time to move to the next one in the treasure
109 | * hunt.
110 | */
111 | override fun onNewIntent(intent: Intent?) {
112 | super.onNewIntent(intent)
113 | val extras = intent?.extras
114 | if(extras != null){
115 | if(extras.containsKey(GeofencingConstants.EXTRA_GEOFENCE_INDEX)){
116 | viewModel.updateHint(extras.getInt(GeofencingConstants.EXTRA_GEOFENCE_INDEX))
117 | checkPermissionsAndStartGeofencing()
118 | }
119 | }
120 | }
121 |
122 | /*
123 | * In all cases, we need to have the location permission. On Android 10+ (Q) we need to have
124 | * the background permission as well.
125 | */
126 | override fun onRequestPermissionsResult(
127 | requestCode: Int,
128 | permissions: Array,
129 | grantResults: IntArray
130 | ) {
131 | Log.d(TAG, "onRequestPermissionResult")
132 |
133 | if (
134 | grantResults.isEmpty() ||
135 | grantResults[LOCATION_PERMISSION_INDEX] == PackageManager.PERMISSION_DENIED ||
136 | (requestCode == REQUEST_FOREGROUND_AND_BACKGROUND_PERMISSION_RESULT_CODE &&
137 | grantResults[BACKGROUND_LOCATION_PERMISSION_INDEX] ==
138 | PackageManager.PERMISSION_DENIED))
139 | {
140 | // Permission denied.
141 | Snackbar.make(
142 | binding.activityMapsMain,
143 | R.string.permission_denied_explanation, Snackbar.LENGTH_INDEFINITE
144 | )
145 | .setAction(R.string.settings) {
146 | // Displays App settings screen.
147 | startActivity(Intent().apply {
148 | action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
149 | data = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null)
150 | flags = Intent.FLAG_ACTIVITY_NEW_TASK
151 | })
152 | }.show()
153 | } else {
154 | checkDeviceLocationSettingsAndStartGeofence()
155 | }
156 | }
157 |
158 | /**
159 | * This will also destroy any saved state in the associated ViewModel, so we remove the
160 | * geofences here.
161 | */
162 | override fun onDestroy() {
163 | super.onDestroy()
164 | removeGeofences()
165 | }
166 |
167 | /**
168 | * Starts the permission check and Geofence process only if the Geofence associated with the
169 | * current hint isn't yet active.
170 | */
171 | private fun checkPermissionsAndStartGeofencing() {
172 | if (viewModel.geofenceIsActive()) return
173 | if (foregroundAndBackgroundLocationPermissionApproved()) {
174 | checkDeviceLocationSettingsAndStartGeofence()
175 | } else {
176 | requestForegroundAndBackgroundLocationPermissions()
177 | }
178 | }
179 |
180 | /*
181 | * Uses the Location Client to check the current state of location settings, and gives the user
182 | * the opportunity to turn on location services within our app.
183 | */
184 | private fun checkDeviceLocationSettingsAndStartGeofence(resolve:Boolean = true) {
185 | val locationRequest = LocationRequest.create().apply {
186 | priority = LocationRequest.PRIORITY_LOW_POWER
187 | }
188 | val builder = LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
189 |
190 | val settingsClient = LocationServices.getSettingsClient(this)
191 | val locationSettingsResponseTask =
192 | settingsClient.checkLocationSettings(builder.build())
193 |
194 | locationSettingsResponseTask.addOnFailureListener { exception ->
195 | if (exception is ResolvableApiException && resolve){
196 | // Location settings are not satisfied, but this can be fixed
197 | // by showing the user a dialog.
198 | try {
199 | // Show the dialog by calling startResolutionForResult(),
200 | // and check the result in onActivityResult().
201 | exception.startResolutionForResult(this@HuntMainActivity,
202 | REQUEST_TURN_DEVICE_LOCATION_ON)
203 | } catch (sendEx: IntentSender.SendIntentException) {
204 | Log.d(TAG, "Error geting location settings resolution: " + sendEx.message)
205 | }
206 | } else {
207 | Snackbar.make(
208 | binding.activityMapsMain,
209 | R.string.location_required_error, Snackbar.LENGTH_INDEFINITE
210 | ).setAction(android.R.string.ok) {
211 | checkDeviceLocationSettingsAndStartGeofence()
212 | }.show()
213 | }
214 | }
215 | locationSettingsResponseTask.addOnCompleteListener {
216 | if ( it.isSuccessful ) {
217 | addGeofenceForClue()
218 | }
219 | }
220 | }
221 |
222 | /*
223 | * Determines whether the app has the appropriate permissions across Android 10+ and all other
224 | * Android versions.
225 | */
226 | @TargetApi(29)
227 | private fun foregroundAndBackgroundLocationPermissionApproved(): Boolean {
228 | val foregroundLocationApproved = (
229 | PackageManager.PERMISSION_GRANTED ==
230 | ActivityCompat.checkSelfPermission(this,
231 | Manifest.permission.ACCESS_FINE_LOCATION))
232 | val backgroundPermissionApproved =
233 | if (runningQOrLater) {
234 | PackageManager.PERMISSION_GRANTED ==
235 | ActivityCompat.checkSelfPermission(
236 | this, Manifest.permission.ACCESS_BACKGROUND_LOCATION
237 | )
238 | } else {
239 | true
240 | }
241 | return foregroundLocationApproved && backgroundPermissionApproved
242 | }
243 |
244 | /*
245 | * Requests ACCESS_FINE_LOCATION and (on Android 10+ (Q) ACCESS_BACKGROUND_LOCATION.
246 | */
247 | @TargetApi(29 )
248 | private fun requestForegroundAndBackgroundLocationPermissions() {
249 | if (foregroundAndBackgroundLocationPermissionApproved())
250 | return
251 |
252 | // Else request the permission
253 | // this provides the result[LOCATION_PERMISSION_INDEX]
254 | var permissionsArray = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
255 |
256 | val resultCode = when {
257 | runningQOrLater -> {
258 | // this provides the result[BACKGROUND_LOCATION_PERMISSION_INDEX]
259 | permissionsArray += Manifest.permission.ACCESS_BACKGROUND_LOCATION
260 | REQUEST_FOREGROUND_AND_BACKGROUND_PERMISSION_RESULT_CODE
261 | }
262 | else -> REQUEST_FOREGROUND_ONLY_PERMISSIONS_REQUEST_CODE
263 | }
264 |
265 | Log.d(TAG, "Request foreground only location permission")
266 | ActivityCompat.requestPermissions(
267 | this@HuntMainActivity,
268 | permissionsArray,
269 | resultCode
270 | )
271 | }
272 |
273 | /*
274 | * Adds a Geofence for the current clue if needed, and removes any existing Geofence. This
275 | * method should be called after the user has granted the location permission. If there are
276 | * no more geofences, we remove the geofence and let the viewmodel know that the ending hint
277 | * is now "active."
278 | */
279 | private fun addGeofenceForClue() {
280 | if (viewModel.geofenceIsActive()) return
281 | val currentGeofenceIndex = viewModel.nextGeofenceIndex()
282 | if(currentGeofenceIndex >= GeofencingConstants.NUM_LANDMARKS) {
283 | removeGeofences()
284 | viewModel.geofenceActivated()
285 | return
286 | }
287 | val currentGeofenceData = GeofencingConstants.LANDMARK_DATA[currentGeofenceIndex]
288 |
289 | // Build the Geofence Object
290 | val geofence = Geofence.Builder()
291 | // Set the request ID, string to identify the geofence.
292 | .setRequestId(currentGeofenceData.id)
293 | // Set the circular region of this geofence.
294 | .setCircularRegion(currentGeofenceData.latLong.latitude,
295 | currentGeofenceData.latLong.longitude,
296 | GeofencingConstants.GEOFENCE_RADIUS_IN_METERS
297 | )
298 | // Set the expiration duration of the geofence. This geofence gets
299 | // automatically removed after this period of time.
300 | .setExpirationDuration(GeofencingConstants.GEOFENCE_EXPIRATION_IN_MILLISECONDS)
301 | // Set the transition types of interest. Alerts are only generated for these
302 | // transition. We track entry and exit transitions in this sample.
303 | .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
304 | .build()
305 |
306 | // Build the geofence request
307 | val geofencingRequest = GeofencingRequest.Builder()
308 | // The INITIAL_TRIGGER_ENTER flag indicates that geofencing service should trigger a
309 | // GEOFENCE_TRANSITION_ENTER notification when the geofence is added and if the device
310 | // is already inside that geofence.
311 | .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
312 |
313 | // Add the geofences to be monitored by geofencing service.
314 | .addGeofence(geofence)
315 | .build()
316 |
317 | // First, remove any existing geofences that use our pending intent
318 | geofencingClient.removeGeofences(geofencePendingIntent)?.run {
319 | // Regardless of success/failure of the removal, add the new geofence
320 | addOnCompleteListener {
321 | // Add the new geofence request with the new geofence
322 | geofencingClient.addGeofences(geofencingRequest, geofencePendingIntent)?.run {
323 | addOnSuccessListener {
324 | // Geofences added.
325 | Toast.makeText(this@HuntMainActivity, R.string.geofences_added,
326 | Toast.LENGTH_SHORT)
327 | .show()
328 | Log.e("Add Geofence", geofence.requestId)
329 | // Tell the viewmodel that we've reached the end of the game and
330 | // activated the last "geofence" --- by removing the Geofence.
331 | viewModel.geofenceActivated()
332 | }
333 | addOnFailureListener {
334 | // Failed to add geofences.
335 | Toast.makeText(this@HuntMainActivity, R.string.geofences_not_added,
336 | Toast.LENGTH_SHORT).show()
337 | if ((it.message != null)) {
338 | Log.w(TAG, it.message)
339 | }
340 | }
341 | }
342 | }
343 | }
344 | }
345 |
346 | /**
347 | * Removes geofences. This method should be called after the user has granted the location
348 | * permission.
349 | */
350 | private fun removeGeofences() {
351 | if (!foregroundAndBackgroundLocationPermissionApproved()) {
352 | return
353 | }
354 | geofencingClient.removeGeofences(geofencePendingIntent)?.run {
355 | addOnSuccessListener {
356 | // Geofences removed
357 | Log.d(TAG, getString(R.string.geofences_removed))
358 | Toast.makeText(applicationContext, R.string.geofences_removed, Toast.LENGTH_SHORT)
359 | .show()
360 | }
361 | addOnFailureListener {
362 | // Failed to remove geofences
363 | Log.d(TAG, getString(R.string.geofences_not_removed))
364 | }
365 | }
366 | }
367 | companion object {
368 | internal const val ACTION_GEOFENCE_EVENT =
369 | "HuntMainActivity.treasureHunt.action.ACTION_GEOFENCE_EVENT"
370 | }
371 | }
372 |
373 | private const val REQUEST_FOREGROUND_AND_BACKGROUND_PERMISSION_RESULT_CODE = 33
374 | private const val REQUEST_FOREGROUND_ONLY_PERMISSIONS_REQUEST_CODE = 34
375 | private const val REQUEST_TURN_DEVICE_LOCATION_ON = 29
376 | private const val TAG = "HuntMainActivity"
377 | private const val LOCATION_PERMISSION_INDEX = 0
378 | private const val BACKGROUND_LOCATION_PERMISSION_INDEX = 1
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | All image and audio files (including *.png, *.jpg, *.svg, *.mp3, *.wav
2 | and *.ogg) are licensed under the CC BY 4.0 license. All other files are
3 | licensed under the Apache 2 license.
4 |
5 | =======================================================================
6 |
7 | Apache License
8 | --------------
9 |
10 | Version 2.0, January 2004
11 | http://www.apache.org/licenses/
12 |
13 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14 |
15 | 1. Definitions.
16 |
17 | "License" shall mean the terms and conditions for use, reproduction,
18 | and distribution as defined by Sections 1 through 9 of this document.
19 |
20 | "Licensor" shall mean the copyright owner or entity authorized by
21 | the copyright owner that is granting the License.
22 |
23 | "Legal Entity" shall mean the union of the acting entity and all
24 | other entities that control, are controlled by, or are under common
25 | control with that entity. For the purposes of this definition,
26 | "control" means (i) the power, direct or indirect, to cause the
27 | direction or management of such entity, whether by contract or
28 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
29 | outstanding shares, or (iii) beneficial ownership of such entity.
30 |
31 | "You" (or "Your") shall mean an individual or Legal Entity
32 | exercising permissions granted by this License.
33 |
34 | "Source" form shall mean the preferred form for making modifications,
35 | including but not limited to software source code, documentation
36 | source, and configuration files.
37 |
38 | "Object" form shall mean any form resulting from mechanical
39 | transformation or translation of a Source form, including but
40 | not limited to compiled object code, generated documentation,
41 | and conversions to other media types.
42 |
43 | "Work" shall mean the work of authorship, whether in Source or
44 | Object form, made available under the License, as indicated by a
45 | copyright notice that is included in or attached to the work
46 | (an example is provided in the Appendix below).
47 |
48 | "Derivative Works" shall mean any work, whether in Source or Object
49 | form, that is based on (or derived from) the Work and for which the
50 | editorial revisions, annotations, elaborations, or other modifications
51 | represent, as a whole, an original work of authorship. For the purposes
52 | of this License, Derivative Works shall not include works that remain
53 | separable from, or merely link (or bind by name) to the interfaces of,
54 | the Work and Derivative Works thereof.
55 |
56 | "Contribution" shall mean any work of authorship, including
57 | the original version of the Work and any modifications or additions
58 | to that Work or Derivative Works thereof, that is intentionally
59 | submitted to Licensor for inclusion in the Work by the copyright owner
60 | or by an individual or Legal Entity authorized to submit on behalf of
61 | the copyright owner. For the purposes of this definition, "submitted"
62 | means any form of electronic, verbal, or written communication sent
63 | to the Licensor or its representatives, including but not limited to
64 | communication on electronic mailing lists, source code control systems,
65 | and issue tracking systems that are managed by, or on behalf of, the
66 | Licensor for the purpose of discussing and improving the Work, but
67 | excluding communication that is conspicuously marked or otherwise
68 | designated in writing by the copyright owner as "Not a Contribution."
69 |
70 | "Contributor" shall mean Licensor and any individual or Legal Entity
71 | on behalf of whom a Contribution has been received by Licensor and
72 | subsequently incorporated within the Work.
73 |
74 | 2. Grant of Copyright License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | copyright license to reproduce, prepare Derivative Works of,
78 | publicly display, publicly perform, sublicense, and distribute the
79 | Work and such Derivative Works in Source or Object form.
80 |
81 | 3. Grant of Patent License. Subject to the terms and conditions of
82 | this License, each Contributor hereby grants to You a perpetual,
83 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
84 | (except as stated in this section) patent license to make, have made,
85 | use, offer to sell, sell, import, and otherwise transfer the Work,
86 | where such license applies only to those patent claims licensable
87 | by such Contributor that are necessarily infringed by their
88 | Contribution(s) alone or by combination of their Contribution(s)
89 | with the Work to which such Contribution(s) was submitted. If You
90 | institute patent litigation against any entity (including a
91 | cross-claim or counterclaim in a lawsuit) alleging that the Work
92 | or a Contribution incorporated within the Work constitutes direct
93 | or contributory patent infringement, then any patent licenses
94 | granted to You under this License for that Work shall terminate
95 | as of the date such litigation is filed.
96 |
97 | 4. Redistribution. You may reproduce and distribute copies of the
98 | Work or Derivative Works thereof in any medium, with or without
99 | modifications, and in Source or Object form, provided that You
100 | meet the following conditions:
101 |
102 | (a) You must give any other recipients of the Work or
103 | Derivative Works a copy of this License; and
104 |
105 | (b) You must cause any modified files to carry prominent notices
106 | stating that You changed the files; and
107 |
108 | (c) You must retain, in the Source form of any Derivative Works
109 | that You distribute, all copyright, patent, trademark, and
110 | attribution notices from the Source form of the Work,
111 | excluding those notices that do not pertain to any part of
112 | the Derivative Works; and
113 |
114 | (d) If the Work includes a "NOTICE" text file as part of its
115 | distribution, then any Derivative Works that You distribute must
116 | include a readable copy of the attribution notices contained
117 | within such NOTICE file, excluding those notices that do not
118 | pertain to any part of the Derivative Works, in at least one
119 | of the following places: within a NOTICE text file distributed
120 | as part of the Derivative Works; within the Source form or
121 | documentation, if provided along with the Derivative Works; or,
122 | within a display generated by the Derivative Works, if and
123 | wherever such third-party notices normally appear. The contents
124 | of the NOTICE file are for informational purposes only and
125 | do not modify the License. You may add Your own attribution
126 | notices within Derivative Works that You distribute, alongside
127 | or as an addendum to the NOTICE text from the Work, provided
128 | that such additional attribution notices cannot be construed
129 | as modifying the License.
130 |
131 | You may add Your own copyright statement to Your modifications and
132 | may provide additional or different license terms and conditions
133 | for use, reproduction, or distribution of Your modifications, or
134 | for any such Derivative Works as a whole, provided Your use,
135 | reproduction, and distribution of the Work otherwise complies with
136 | the conditions stated in this License.
137 |
138 | 5. Submission of Contributions. Unless You explicitly state otherwise,
139 | any Contribution intentionally submitted for inclusion in the Work
140 | by You to the Licensor shall be under the terms and conditions of
141 | this License, without any additional terms or conditions.
142 | Notwithstanding the above, nothing herein shall supersede or modify
143 | the terms of any separate license agreement you may have executed
144 | with Licensor regarding such Contributions.
145 |
146 | 6. Trademarks. This License does not grant permission to use the trade
147 | names, trademarks, service marks, or product names of the Licensor,
148 | except as required for reasonable and customary use in describing the
149 | origin of the Work and reproducing the content of the NOTICE file.
150 |
151 | 7. Disclaimer of Warranty. Unless required by applicable law or
152 | agreed to in writing, Licensor provides the Work (and each
153 | Contributor provides its Contributions) on an "AS IS" BASIS,
154 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155 | implied, including, without limitation, any warranties or conditions
156 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
157 | PARTICULAR PURPOSE. You are solely responsible for determining the
158 | appropriateness of using or redistributing the Work and assume any
159 | risks associated with Your exercise of permissions under this License.
160 |
161 | 8. Limitation of Liability. In no event and under no legal theory,
162 | whether in tort (including negligence), contract, or otherwise,
163 | unless required by applicable law (such as deliberate and grossly
164 | negligent acts) or agreed to in writing, shall any Contributor be
165 | liable to You for damages, including any direct, indirect, special,
166 | incidental, or consequential damages of any character arising as a
167 | result of this License or out of the use or inability to use the
168 | Work (including but not limited to damages for loss of goodwill,
169 | work stoppage, computer failure or malfunction, or any and all
170 | other commercial damages or losses), even if such Contributor
171 | has been advised of the possibility of such damages.
172 |
173 | 9. Accepting Warranty or Additional Liability. While redistributing
174 | the Work or Derivative Works thereof, You may choose to offer,
175 | and charge a fee for, acceptance of support, warranty, indemnity,
176 | or other liability obligations and/or rights consistent with this
177 | License. However, in accepting such obligations, You may act only
178 | on Your own behalf and on Your sole responsibility, not on behalf
179 | of any other Contributor, and only if You agree to indemnify,
180 | defend, and hold each Contributor harmless for any liability
181 | incurred by, or claims asserted against, such Contributor by reason
182 | of your accepting any such warranty or additional liability.
183 |
184 | END OF TERMS AND CONDITIONS
185 |
186 | APPENDIX: How to apply the Apache License to your work.
187 |
188 | To apply the Apache License to your work, attach the following
189 | boilerplate notice, with the fields enclosed by brackets "{}"
190 | replaced with your own identifying information. (Don't include
191 | the brackets!) The text should be enclosed in the appropriate
192 | comment syntax for the file format. We also recommend that a
193 | file or class name and description of purpose be included on the
194 | same "printed page" as the copyright notice for easier
195 | identification within third-party archives.
196 |
197 | Copyright {yyyy} {name of copyright owner}
198 |
199 | Licensed under the Apache License, Version 2.0 (the "License");
200 | you may not use this file except in compliance with the License.
201 | You may obtain a copy of the License at
202 |
203 | http://www.apache.org/licenses/LICENSE-2.0
204 |
205 | Unless required by applicable law or agreed to in writing, software
206 | distributed under the License is distributed on an "AS IS" BASIS,
207 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208 | See the License for the specific language governing permissions and
209 | limitations under the License.
210 |
211 | All image and audio files (including *.png, *.jpg, *.svg, *.mp3, *.wav
212 | and *.ogg) are licensed under the CC BY 4.0 license. All other files are
213 | licensed under the Apache 2 license.
214 |
215 | CC-BY License
216 | ----------------
217 |
218 | Attribution 4.0 International
219 |
220 | =======================================================================
221 |
222 | Creative Commons Corporation ("Creative Commons") is not a law firm and
223 | does not provide legal services or legal advice. Distribution of
224 | Creative Commons public licenses does not create a lawyer-client or
225 | other relationship. Creative Commons makes its licenses and related
226 | information available on an "as-is" basis. Creative Commons gives no
227 | warranties regarding its licenses, any material licensed under their
228 | terms and conditions, or any related information. Creative Commons
229 | disclaims all liability for damages resulting from their use to the
230 | fullest extent possible.
231 |
232 | Using Creative Commons Public Licenses
233 |
234 | Creative Commons public licenses provide a standard set of terms and
235 | conditions that creators and other rights holders may use to share
236 | original works of authorship and other material subject to copyright
237 | and certain other rights specified in the public license below. The
238 | following considerations are for informational purposes only, are not
239 | exhaustive, and do not form part of our licenses.
240 |
241 | Considerations for licensors: Our public licenses are
242 | intended for use by those authorized to give the public
243 | permission to use material in ways otherwise restricted by
244 | copyright and certain other rights. Our licenses are
245 | irrevocable. Licensors should read and understand the terms
246 | and conditions of the license they choose before applying it.
247 | Licensors should also secure all rights necessary before
248 | applying our licenses so that the public can reuse the
249 | material as expected. Licensors should clearly mark any
250 | material not subject to the license. This includes other CC-
251 | licensed material, or material used under an exception or
252 | limitation to copyright. More considerations for licensors:
253 | wiki.creativecommons.org/Considerations_for_licensors
254 |
255 | Considerations for the public: By using one of our public
256 | licenses, a licensor grants the public permission to use the
257 | licensed material under specified terms and conditions. If
258 | the licensor's permission is not necessary for any reason--for
259 | example, because of any applicable exception or limitation to
260 | copyright--then that use is not regulated by the license. Our
261 | licenses grant only permissions under copyright and certain
262 | other rights that a licensor has authority to grant. Use of
263 | the licensed material may still be restricted for other
264 | reasons, including because others have copyright or other
265 | rights in the material. A licensor may make special requests,
266 | such as asking that all changes be marked or described.
267 | Although not required by our licenses, you are encouraged to
268 | respect those requests where reasonable. More_considerations
269 | for the public:
270 | wiki.creativecommons.org/Considerations_for_licensees
271 |
272 | =======================================================================
273 |
274 | Creative Commons Attribution 4.0 International Public License
275 |
276 | By exercising the Licensed Rights (defined below), You accept and agree
277 | to be bound by the terms and conditions of this Creative Commons
278 | Attribution 4.0 International Public License ("Public License"). To the
279 | extent this Public License may be interpreted as a contract, You are
280 | granted the Licensed Rights in consideration of Your acceptance of
281 | these terms and conditions, and the Licensor grants You such rights in
282 | consideration of benefits the Licensor receives from making the
283 | Licensed Material available under these terms and conditions.
284 |
285 |
286 | Section 1 -- Definitions.
287 |
288 | a. Adapted Material means material subject to Copyright and Similar
289 | Rights that is derived from or based upon the Licensed Material
290 | and in which the Licensed Material is translated, altered,
291 | arranged, transformed, or otherwise modified in a manner requiring
292 | permission under the Copyright and Similar Rights held by the
293 | Licensor. For purposes of this Public License, where the Licensed
294 | Material is a musical work, performance, or sound recording,
295 | Adapted Material is always produced where the Licensed Material is
296 | synched in timed relation with a moving image.
297 |
298 | b. Adapter's License means the license You apply to Your Copyright
299 | and Similar Rights in Your contributions to Adapted Material in
300 | accordance with the terms and conditions of this Public License.
301 |
302 | c. Copyright and Similar Rights means copyright and/or similar rights
303 | closely related to copyright including, without limitation,
304 | performance, broadcast, sound recording, and Sui Generis Database
305 | Rights, without regard to how the rights are labeled or
306 | categorized. For purposes of this Public License, the rights
307 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
308 | Rights.
309 |
310 | d. Effective Technological Measures means those measures that, in the
311 | absence of proper authority, may not be circumvented under laws
312 | fulfilling obligations under Article 11 of the WIPO Copyright
313 | Treaty adopted on December 20, 1996, and/or similar international
314 | agreements.
315 |
316 | e. Exceptions and Limitations means fair use, fair dealing, and/or
317 | any other exception or limitation to Copyright and Similar Rights
318 | that applies to Your use of the Licensed Material.
319 |
320 | f. Licensed Material means the artistic or literary work, database,
321 | or other material to which the Licensor applied this Public
322 | License.
323 |
324 | g. Licensed Rights means the rights granted to You subject to the
325 | terms and conditions of this Public License, which are limited to
326 | all Copyright and Similar Rights that apply to Your use of the
327 | Licensed Material and that the Licensor has authority to license.
328 |
329 | h. Licensor means the individual(s) or entity(ies) granting rights
330 | under this Public License.
331 |
332 | i. Share means to provide material to the public by any means or
333 | process that requires permission under the Licensed Rights, such
334 | as reproduction, public display, public performance, distribution,
335 | dissemination, communication, or importation, and to make material
336 | available to the public including in ways that members of the
337 | public may access the material from a place and at a time
338 | individually chosen by them.
339 |
340 | j. Sui Generis Database Rights means rights other than copyright
341 | resulting from Directive 96/9/EC of the European Parliament and of
342 | the Council of 11 March 1996 on the legal protection of databases,
343 | as amended and/or succeeded, as well as other essentially
344 | equivalent rights anywhere in the world.
345 |
346 | k. You means the individual or entity exercising the Licensed Rights
347 | under this Public License. Your has a corresponding meaning.
348 |
349 |
350 | Section 2 -- Scope.
351 |
352 | a. License grant.
353 |
354 | 1. Subject to the terms and conditions of this Public License,
355 | the Licensor hereby grants You a worldwide, royalty-free,
356 | non-sublicensable, non-exclusive, irrevocable license to
357 | exercise the Licensed Rights in the Licensed Material to:
358 |
359 | a. reproduce and Share the Licensed Material, in whole or
360 | in part; and
361 |
362 | b. produce, reproduce, and Share Adapted Material.
363 |
364 | 2. Exceptions and Limitations. For the avoidance of doubt, where
365 | Exceptions and Limitations apply to Your use, this Public
366 | License does not apply, and You do not need to comply with
367 | its terms and conditions.
368 |
369 | 3. Term. The term of this Public License is specified in Section
370 | 6(a).
371 |
372 | 4. Media and formats; technical modifications allowed. The
373 | Licensor authorizes You to exercise the Licensed Rights in
374 | all media and formats whether now known or hereafter created,
375 | and to make technical modifications necessary to do so. The
376 | Licensor waives and/or agrees not to assert any right or
377 | authority to forbid You from making technical modifications
378 | necessary to exercise the Licensed Rights, including
379 | technical modifications necessary to circumvent Effective
380 | Technological Measures. For purposes of this Public License,
381 | simply making modifications authorized by this Section 2(a)
382 | (4) never produces Adapted Material.
383 |
384 | 5. Downstream recipients.
385 |
386 | a. Offer from the Licensor -- Licensed Material. Every
387 | recipient of the Licensed Material automatically
388 | receives an offer from the Licensor to exercise the
389 | Licensed Rights under the terms and conditions of this
390 | Public License.
391 |
392 | b. No downstream restrictions. You may not offer or impose
393 | any additional or different terms or conditions on, or
394 | apply any Effective Technological Measures to, the
395 | Licensed Material if doing so restricts exercise of the
396 | Licensed Rights by any recipient of the Licensed
397 | Material.
398 |
399 | 6. No endorsement. Nothing in this Public License constitutes or
400 | may be construed as permission to assert or imply that You
401 | are, or that Your use of the Licensed Material is, connected
402 | with, or sponsored, endorsed, or granted official status by,
403 | the Licensor or others designated to receive attribution as
404 | provided in Section 3(a)(1)(A)(i).
405 |
406 | b. Other rights.
407 |
408 | 1. Moral rights, such as the right of integrity, are not
409 | licensed under this Public License, nor are publicity,
410 | privacy, and/or other similar personality rights; however, to
411 | the extent possible, the Licensor waives and/or agrees not to
412 | assert any such rights held by the Licensor to the limited
413 | extent necessary to allow You to exercise the Licensed
414 | Rights, but not otherwise.
415 |
416 | 2. Patent and trademark rights are not licensed under this
417 | Public License.
418 |
419 | 3. To the extent possible, the Licensor waives any right to
420 | collect royalties from You for the exercise of the Licensed
421 | Rights, whether directly or through a collecting society
422 | under any voluntary or waivable statutory or compulsory
423 | licensing scheme. In all other cases the Licensor expressly
424 | reserves any right to collect such royalties.
425 |
426 |
427 | Section 3 -- License Conditions.
428 |
429 | Your exercise of the Licensed Rights is expressly made subject to the
430 | following conditions.
431 |
432 | a. Attribution.
433 |
434 | 1. If You Share the Licensed Material (including in modified
435 | form), You must:
436 |
437 | a. retain the following if it is supplied by the Licensor
438 | with the Licensed Material:
439 |
440 | i. identification of the creator(s) of the Licensed
441 | Material and any others designated to receive
442 | attribution, in any reasonable manner requested by
443 | the Licensor (including by pseudonym if
444 | designated);
445 |
446 | ii. a copyright notice;
447 |
448 | iii. a notice that refers to this Public License;
449 |
450 | iv. a notice that refers to the disclaimer of
451 | warranties;
452 |
453 | v. a URI or hyperlink to the Licensed Material to the
454 | extent reasonably practicable;
455 |
456 | b. indicate if You modified the Licensed Material and
457 | retain an indication of any previous modifications; and
458 |
459 | c. indicate the Licensed Material is licensed under this
460 | Public License, and include the text of, or the URI or
461 | hyperlink to, this Public License.
462 |
463 | 2. You may satisfy the conditions in Section 3(a)(1) in any
464 | reasonable manner based on the medium, means, and context in
465 | which You Share the Licensed Material. For example, it may be
466 | reasonable to satisfy the conditions by providing a URI or
467 | hyperlink to a resource that includes the required
468 | information.
469 |
470 | 3. If requested by the Licensor, You must remove any of the
471 | information required by Section 3(a)(1)(A) to the extent
472 | reasonably practicable.
473 |
474 | 4. If You Share Adapted Material You produce, the Adapter's
475 | License You apply must not prevent recipients of the Adapted
476 | Material from complying with this Public License.
477 |
478 |
479 | Section 4 -- Sui Generis Database Rights.
480 |
481 | Where the Licensed Rights include Sui Generis Database Rights that
482 | apply to Your use of the Licensed Material:
483 |
484 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
485 | to extract, reuse, reproduce, and Share all or a substantial
486 | portion of the contents of the database;
487 |
488 | b. if You include all or a substantial portion of the database
489 | contents in a database in which You have Sui Generis Database
490 | Rights, then the database in which You have Sui Generis Database
491 | Rights (but not its individual contents) is Adapted Material; and
492 |
493 | c. You must comply with the conditions in Section 3(a) if You Share
494 | all or a substantial portion of the contents of the database.
495 |
496 | For the avoidance of doubt, this Section 4 supplements and does not
497 | replace Your obligations under this Public License where the Licensed
498 | Rights include other Copyright and Similar Rights.
499 |
500 |
501 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
502 |
503 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
504 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
505 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
506 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
507 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
508 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
509 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
510 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
511 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
512 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
513 |
514 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
515 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
516 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
517 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
518 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
519 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
520 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
521 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
522 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
523 |
524 | c. The disclaimer of warranties and limitation of liability provided
525 | above shall be interpreted in a manner that, to the extent
526 | possible, most closely approximates an absolute disclaimer and
527 | waiver of all liability.
528 |
529 |
530 | Section 6 -- Term and Termination.
531 |
532 | a. This Public License applies for the term of the Copyright and
533 | Similar Rights licensed here. However, if You fail to comply with
534 | this Public License, then Your rights under this Public License
535 | terminate automatically.
536 |
537 | b. Where Your right to use the Licensed Material has terminated under
538 | Section 6(a), it reinstates:
539 |
540 | 1. automatically as of the date the violation is cured, provided
541 | it is cured within 30 days of Your discovery of the
542 | violation; or
543 |
544 | 2. upon express reinstatement by the Licensor.
545 |
546 | For the avoidance of doubt, this Section 6(b) does not affect any
547 | right the Licensor may have to seek remedies for Your violations
548 | of this Public License.
549 |
550 | c. For the avoidance of doubt, the Licensor may also offer the
551 | Licensed Material under separate terms or conditions or stop
552 | distributing the Licensed Material at any time; however, doing so
553 | will not terminate this Public License.
554 |
555 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
556 | License.
557 |
558 |
559 | Section 7 -- Other Terms and Conditions.
560 |
561 | a. The Licensor shall not be bound by any additional or different
562 | terms or conditions communicated by You unless expressly agreed.
563 |
564 | b. Any arrangements, understandings, or agreements regarding the
565 | Licensed Material not stated herein are separate from and
566 | independent of the terms and conditions of this Public License.
567 |
568 |
569 | Section 8 -- Interpretation.
570 |
571 | a. For the avoidance of doubt, this Public License does not, and
572 | shall not be interpreted to, reduce, limit, restrict, or impose
573 | conditions on any use of the Licensed Material that could lawfully
574 | be made without permission under this Public License.
575 |
576 | b. To the extent possible, if any provision of this Public License is
577 | deemed unenforceable, it shall be automatically reformed to the
578 | minimum extent necessary to make it enforceable. If the provision
579 | cannot be reformed, it shall be severed from this Public License
580 | without affecting the enforceability of the remaining terms and
581 | conditions.
582 |
583 | c. No term or condition of this Public License will be waived and no
584 | failure to comply consented to unless expressly agreed to by the
585 | Licensor.
586 |
587 | d. Nothing in this Public License constitutes or may be interpreted
588 | as a limitation upon, or waiver of, any privileges and immunities
589 | that apply to the Licensor or You, including from the legal
590 | processes of any jurisdiction or authority.
591 |
592 |
593 | =======================================================================
594 |
595 | Creative Commons is not a party to its public
596 | licenses. Notwithstanding, Creative Commons may elect to apply one of
597 | its public licenses to material it publishes and in those instances
598 | will be considered the “Licensor.” The text of the Creative Commons
599 | public licenses is dedicated to the public domain under the CC0 Public
600 | Domain Dedication. Except for the limited purpose of indicating that
601 | material is shared under a Creative Commons public license or as
602 | otherwise permitted by the Creative Commons policies published at
603 | creativecommons.org/policies, Creative Commons does not authorize the
604 | use of the trademark "Creative Commons" or any other trademark or logo
605 | of Creative Commons without its prior written consent including,
606 | without limitation, in connection with any unauthorized modifications
607 | to any of its public licenses or any other arrangements,
608 | understandings, or agreements concerning use of licensed material. For
609 | the avoidance of doubt, this paragraph does not form part of the
610 | public licenses.
611 |
612 | Creative Commons may be contacted at creativecommons.org.
613 |
614 |
615 |
--------------------------------------------------------------------------------