Skip to content

Commit

Permalink
Updated AndroidThingsApp
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Dylag committed Jun 27, 2018
1 parent 5359dc7 commit 53e2f07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
4 changes: 2 additions & 2 deletions example/AndroidThingsApp/things/build.gradle
Expand Up @@ -25,14 +25,14 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-v4:27.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compileOnly 'com.google.android.things:androidthings:+'

// ESTIMOTE PROXIMITY SDK DEPENDENCY
implementation 'com.estimote:proximity-sdk:0.3.3'
implementation 'com.estimote:proximity-sdk:0.6.1'

// ESTIMOTE UTILITY LIBRARY THAT CONTAINS REQUIREMENTS WIZARD
implementation "com.estimote:mustard:0.2.1"
Expand Down
Expand Up @@ -30,17 +30,15 @@ class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Get your app_id and app_token from your Estimote Cloud account ("apps" section).
// Also your beacon should have attachment with ZONE_KEY and ZONE_VALUE set in Cloud.
// Read more about setting attachments here:
// https://github.com/Estimote/Android-Proximity-SDK#attachment-based-identification-explanation
startProximityDemo(YOUR_APP_ID, YOUR_APP_TOKEN, ZONE_KEY, ZONE_VALUE)
// Also your beacon should have tag ZONE_TAG assigned in Estimote Cloud.
startProximityDemo(YOUR_APP_ID, YOUR_APP_TOKEN, ZONE_TAG)
// startLightSensorDemo("", "", 20.0)
// startMotionDemo("", "")
// startTemperatureDemo("", "", 20.0)
}

fun startProximityDemo(appId: String, appToken: String, zoneKey: String, zoneValue: String) =
startActivity(createProximityIntent(this, ProximityDemoActivity::class.java, appId, appToken, zoneKey, zoneValue))
fun startProximityDemo(appId: String, appToken: String, zoneKey: String) =
startActivity(createProximityIntent(this, ProximityDemoActivity::class.java, appId, appToken, zoneKey))

fun startLightSensorDemo(gpioPinName: String, beaconId: String, lightLevelThreshold: Double) =
startActivity(createSensorsIntent(this, LightLevelDemoActivity::class.java, gpioPinName, beaconId, lightLevelThreshold = lightLevelThreshold))
Expand All @@ -58,8 +56,7 @@ class MainActivity : Activity() {
private val TEMPERATURE_THRESHOLD_KEY = "temperature_threshold"
private val APP_ID_KEY = "app_id"
private val APP_TOKEN_KEY = "app_token"
private val ZONE_KEY_KEY = "zone_key"
private val ZONE_VALUE_KEY = "zone_value"
private val ZONE_TAG_KEY = "zone_key"

fun <T> createSensorsIntent(context: Context,
activityClass: Class<T>,
Expand All @@ -79,13 +76,11 @@ class MainActivity : Activity() {
activityClass: Class<T>,
appId: String,
appToken: String,
zoneKey: String,
zoneValue: String): Intent {
zoneTag: String): Intent {
val intent = Intent(context, activityClass)
intent.putExtra(APP_ID_KEY, appId)
intent.putExtra(APP_TOKEN_KEY, appToken)
intent.putExtra(ZONE_KEY_KEY, zoneKey)
intent.putExtra(ZONE_VALUE_KEY, zoneValue)
intent.putExtra(ZONE_TAG_KEY, zoneTag)
return intent
}

Expand All @@ -95,8 +90,7 @@ class MainActivity : Activity() {
fun getTemperatureThreshold(intent: Intent) = intent.extras.getDouble(TEMPERATURE_THRESHOLD_KEY)
fun getAppId(intent: Intent) = intent.extras.getString(APP_ID_KEY)
fun getAppToken(intent: Intent) = intent.extras.getString(APP_TOKEN_KEY)
fun getZoneKey(intent: Intent) = intent.extras.getString(ZONE_KEY_KEY)
fun getZoneValue(intent: Intent) = intent.extras.getString(ZONE_VALUE_KEY)
fun getZoneTag(intent: Intent) = intent.extras.getString(ZONE_TAG_KEY)
}

}
Expand Up @@ -3,10 +3,9 @@ package com.estimote.estimotethings
import android.app.Activity
import android.os.Bundle
import android.util.Log
import com.estimote.cloud_plugin.common.EstimoteCloudCredentials
import com.estimote.internal_plugins_api.cloud.CloudCredentials
import com.estimote.internal_plugins_api.cloud.proximity.ProximityAttachment
import com.estimote.mustard.rx_goodness.rx_requirements_wizard.RequirementsWizardFactory
import com.estimote.proximity_sdk.proximity.EstimoteCloudCredentials
import com.estimote.proximity_sdk.proximity.ProximityContext
import com.estimote.proximity_sdk.proximity.ProximityObserver
import com.estimote.proximity_sdk.proximity.ProximityObserverBuilder

Expand All @@ -19,14 +18,12 @@ class ProximityDemoActivity : Activity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_proximity_demo)
val cloudCredentials = EstimoteCloudCredentials(MainActivity.getAppId(intent), MainActivity.getAppToken(intent))
val zoneKey = MainActivity.getZoneKey(intent)
val zoneValue = MainActivity.getZoneValue(intent)
val zoneKey = MainActivity.getZoneTag(intent)
RequirementsWizardFactory.createEstimoteRequirementsWizardForAndroidThings().fulfillRequirements(
this,
onRequirementsFulfilled = {
whenBeaconIsCloseThenTriggerAnAction(
zoneKey,
zoneValue,
cloudCredentials,
{ Log.d(TAG, "Beacon is now close!") },
{ Log.d(TAG, "Beacon is now far!") })
Expand All @@ -36,17 +33,16 @@ class ProximityDemoActivity : Activity() {
}

private fun whenBeaconIsCloseThenTriggerAnAction(key: String,
value: String,
cloudCredentials: CloudCredentials,
actionToTriggerWhenBeaconComesClose: (ProximityAttachment) -> Unit,
actionToTriggerWhenBeaconGetsOutOfRange: (ProximityAttachment) -> Unit) {
cloudCredentials: EstimoteCloudCredentials,
actionToTriggerWhenBeaconComesClose: (ProximityContext) -> Unit,
actionToTriggerWhenBeaconGetsOutOfRange: (ProximityContext) -> Unit) {
val proximityObserver = ProximityObserverBuilder(applicationContext, cloudCredentials)
.withLowLatencyPowerMode()
.withOnErrorAction { Log.d(TAG, "Proximity observation error: ${it.message}") }
.withAnalyticsReportingDisabled()
.build()
val beaconZone = proximityObserver.zoneBuilder()
.forAttachmentKeyAndValue(key, value)
.forTag(key)
.inNearRange()
.withOnEnterAction(actionToTriggerWhenBeaconComesClose)
.withOnExitAction(actionToTriggerWhenBeaconGetsOutOfRange)
Expand Down

0 comments on commit 53e2f07

Please sign in to comment.