This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| tools:context=".MainActivity" | |
| android:orientation="vertical"> | |
| <Button |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val walkingWithHeadphonesFence = AwarenessFence.and( | |
| walkingFence, headphoneFence | |
| ) | |
| addFence("walkingWithHeadphonesFence", walkingWithHeadphonesFence) | |
| /* in FenceReceiver | |
| "walkingWithHeadphonesFence" -> when (fenceState.currentState) { | |
| FenceState.TRUE -> fenceInfo = "TRUE | Walking with headphones plugged in." | |
| FenceState.FALSE -> fenceInfo = "FALSE | Not walking with headphones plugged in." | |
| FenceState.UNKNOWN -> fenceInfo = "Error: unknown state." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun onClick_button_remove(view: View?) { | |
| removeFences() | |
| } | |
| private fun removeFences() { | |
| Awareness.getFenceClient(this).updateFences( | |
| FenceUpdateRequest.Builder() | |
| .removeFence(myPendingIntent) | |
| .build() | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private inner class FenceReceiver : BroadcastReceiver() { | |
| override fun onReceive(context: Context?, intent: Intent) { | |
| if (intent.action != "FENCE_RECEIVER_ACTION") { | |
| Log.e( | |
| "TAG_FENCES", "Received an unsupported action in FenceReceiver: action=$intent.action" | |
| ) | |
| return | |
| } | |
| val fenceState: FenceState = FenceState.extract(intent) | |
| var fenceInfo: String? = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun addFence(fenceKey: String, fence: AwarenessFence) { | |
| Awareness.getFenceClient(this).updateFences( | |
| FenceUpdateRequest.Builder() | |
| .addFence(fenceKey, fence, myPendingIntent) | |
| .build() | |
| ) | |
| .addOnSuccessListener { | |
| val timestamp = Timestamp(System.currentTimeMillis()) | |
| val text = "[Fences @ $timestamp] Fence $fenceKey was successfully registered.".trimIndent() | |
| textViewMain.text = text + "\n" + textViewMain.text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun onClick_button_register(view: View?) { | |
| val headphoneFence: AwarenessFence = HeadphoneFence.during(HeadphoneState.PLUGGED_IN) | |
| addFence("headphoneFence", headphoneFence) | |
| val walkingFence: AwarenessFence = DetectedActivityFence.during(DetectedActivityFence.WALKING) | |
| addFence("walkingFence", walkingFence) | |
| val nowMillis = System.currentTimeMillis() | |
| val oneMinuteMilis = 60L * 1000L | |
| val thirtySecondsMillis = 30L * 1000L | |
| val timeFence: AwarenessFence = TimeFence.inInterval( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // FENCES | |
| // | |
| private lateinit var fenceReceiver: FenceReceiver | |
| private lateinit var myPendingIntent: PendingIntent | |
| private fun setupFences() { | |
| val intent = Intent("FENCE_RECEIVER_ACTION") | |
| myPendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0) | |
| fenceReceiver = FenceReceiver() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private String buildTextualExperiment() { | |
| StringBuilder sb = new StringBuilder(); | |
| // time config file num runs Population size Max generations Selection Recombination Mutation Prob1s Fitness type | |
| sb.append(new Timestamp(System.currentTimeMillis()) + "\t"); | |
| sb.append(configFileName + "\t"); | |
| sb.append(numRuns + "\t"); | |
| sb.append(populationSize + "\t"); | |
| sb.append(maxGenerations + "\t"); | |
| sb.append(selection + "\t"); | |
| sb.append(recombination + "\t"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Migrating to the New Places SDK Client | |
| https://developers.google.com/places/android-sdk/client-migration#methods | |
| */ | |
| private void printNearbyPlaces() { | |
| checkFineLocationPermission(); | |
| // Initialize Places. | |
| Places.initialize(getApplicationContext(), MY_API_KEY); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package pt.ipleiria.awarenesspdm; | |
| import android.Manifest; | |
| import android.content.pm.PackageManager; | |
| import android.graphics.Bitmap; | |
| import android.location.Location; | |
| import android.os.AsyncTask; | |
| import android.os.Bundle; | |
| import android.provider.Settings; | |
| import android.support.annotation.NonNull; |
NewerOlder