Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Updates Android code to match background location policy

Michael Rademakerf13cffad6a3b
diff --git a/console/android/GenericApp/app/build.gradle b/console/android/GenericApp/app/build.gradle
index f115ff420..1deb9ad02 100644
--- a/console/android/GenericApp/app/build.gradle
+++ b/console/android/GenericApp/app/build.gradle
@@ -1,18 +1,17 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
-apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {
- compileSdkVersion 29
+ compileSdkVersion 30
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "io.openremote.app"
minSdkVersion 25
- targetSdkVersion 29
- versionCode 19
- versionName "1.0.2"
+ targetSdkVersion 30
+ versionCode 20
+ versionName "1.0.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -20,7 +19,6 @@ android {
}
-
buildTypes {
release {
minifyEnabled false
@@ -28,6 +26,10 @@ android {
}
}
+ buildFeatures {
+ viewBinding true
+ }
+
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
@@ -36,14 +38,13 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
- implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.preference:preference-ktx:1.1.1'
- implementation "com.google.android.gms:play-services-location:17.1.0"
+ implementation "com.google.android.gms:play-services-location:18.0.0"
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.8"
implementation platform('com.google.firebase:firebase-bom:26.0.0')
implementation 'com.google.firebase:firebase-messaging-ktx'
- implementation 'com.google.android.material:material:1.2.1'
+ implementation 'com.google.android.material:material:1.3.0'
}
\ No newline at end of file
diff --git a/console/android/GenericApp/app/src/main/AndroidManifest.xml b/console/android/GenericApp/app/src/main/AndroidManifest.xml
index e48ffe70b..a5b62db75 100644
--- a/console/android/GenericApp/app/src/main/AndroidManifest.xml
+++ b/console/android/GenericApp/app/src/main/AndroidManifest.xml
@@ -18,7 +18,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
- android:theme="@style/AppTheme">
+ android:theme="@style/OpenRemoteTheme">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
@@ -46,9 +46,8 @@
</activity>
<activity
android:name=".ui.ProjectActivity"
- android:label="@string/title_activity_project"
- android:exported="true">
- </activity>
+ android:exported="true"
+ android:label="@string/title_activity_project" />
<activity android:name=".ui.MainActivity" />
<service android:name="io.openremote.app.service.ORFirebaseMessagingService">
diff --git a/console/android/GenericApp/app/src/main/java/io/openremote/app/network/ApiManager.kt b/console/android/GenericApp/app/src/main/java/io/openremote/app/network/ApiManager.kt
index 468738bc0..7652644da 100644
--- a/console/android/GenericApp/app/src/main/java/io/openremote/app/network/ApiManager.kt
+++ b/console/android/GenericApp/app/src/main/java/io/openremote/app/network/ApiManager.kt
@@ -13,10 +13,6 @@ typealias ResponseBlock<T> = (statusCode: Int, model: T?, error: Throwable?) ->
class ApiManager(private val baseUrl: String) {
- companion object {
- var accessToken: String? = null
- }
-
enum class HttpMethod {
GET,
POST,
@@ -67,7 +63,7 @@ class ApiManager(private val baseUrl: String) {
) {
thread(start = true) {
val urlRequest = createUrlRequest(HttpMethod.GET, pathComponents, queryParameters)
- parseResponse<T>(urlRequest, callback)
+ parseResponse(urlRequest, callback)
}
}
@@ -103,34 +99,26 @@ class ApiManager(private val baseUrl: String) {
noinline callback: ResponseBlock<T>?
) {
with(httpConnection) {
- val model = if (this.responseCode == 200) {
- try {
- jacksonObjectMapper().readValue(
- this.inputStream.bufferedReader().readText(),
- T::class.java
+ val parsedResult = try {
+ if (this.responseCode in 200..299) {
+ Triple(
+ this.responseCode, jacksonObjectMapper().readValue(
+ this.inputStream.bufferedReader().readText(),
+ T::class.java
+ ), null
)
- } catch (e: Exception) {
- Log.e(this::class.simpleName, e.message, e)
- null
- }
- } else {
- null
- }
- val error = try {
-
- if (this.responseCode !in 200..299) {
- val errorResponse = this.errorStream.bufferedReader().readText()
- Throwable(errorResponse)
} else {
- null
+ val errorResponse = this.errorStream.bufferedReader().readText()
+ Triple(this.responseCode, null, Throwable(errorResponse))
}
} catch (e: Exception) {
- e
+ Triple(0, null, e)
}
- error?.let {
+
+ parsedResult.third?.let {
Log.e(this::class.simpleName, it.message, it)
}
- callback?.invoke(this.responseCode, model, error)
+ callback?.invoke(parsedResult.first, parsedResult.second, parsedResult.third)
this.disconnect()
}
}
diff --git a/console/android/GenericApp/app/src/main/java/io/openremote/app/service/GeofenceProvider.kt b/console/android/GenericApp/app/src/main/java/io/openremote/app/service/GeofenceProvider.kt
index 215b408e6..bfebe74cf 100644
--- a/console/android/GenericApp/app/src/main/java/io/openremote/app/service/GeofenceProvider.kt
+++ b/console/android/GenericApp/app/src/main/java/io/openremote/app/service/GeofenceProvider.kt
@@ -7,8 +7,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
-import androidx.core.app.ActivityCompat
-import androidx.core.content.ContextCompat
+import androidx.appcompat.app.AlertDialog
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.android.gms.location.*
import io.openremote.app.R
@@ -19,7 +18,7 @@ import java.util.logging.Level
import java.util.logging.Logger
import kotlin.concurrent.schedule
-class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissionsResultCallback {
+class GeofenceProvider(val context: Context) {
interface GeofenceCallback {
fun accept(responseData: Map<String, Any>)
@@ -44,17 +43,21 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
val consoleIdKey = MainActivity.CONSOLE_ID_KEY
val geofencesKey = "geofences"
val geofenceDisabledKey = "geofenceDisabled"
- val locationReponseCode = 101
+ val locationResponseCode = 101
val JSON = ObjectMapper()
val LOG = Logger.getLogger(GeofenceProvider::class.java.name)
fun getGeofences(context: Context): Array<GeofenceDefinition> {
- val sharedPreferences = context.getSharedPreferences(context.getString(R.string.OR_CONSOLE_NAME), Context.MODE_PRIVATE)
+ val sharedPreferences = context.getSharedPreferences(
+ context.getString(R.string.app_name),
+ Context.MODE_PRIVATE
+ )
val existingGeofencesJson = sharedPreferences.getString(geofencesKey, null)
var geofences: Array<GeofenceDefinition> = arrayOf()
if (existingGeofencesJson != null) {
- geofences = JSON.readValue(existingGeofencesJson, Array<GeofenceDefinition>::class.java)
+ geofences =
+ JSON.readValue(existingGeofencesJson, Array<GeofenceDefinition>::class.java)
}
LOG.info("Found geofences=${geofences.size}")
@@ -81,22 +84,30 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
}
@SuppressLint("MissingPermission")
- private fun addGeofence(geofencingClient: GeofencingClient, geofencePendingIntent: PendingIntent, geofenceDefinition: GeofenceDefinition) {
+ private fun addGeofence(
+ geofencingClient: GeofencingClient,
+ geofencePendingIntent: PendingIntent,
+ geofenceDefinition: GeofenceDefinition
+ ) {
LOG.info("Adding geofence: $geofenceDefinition")
val geofence = Geofence.Builder()
- .setRequestId(geofenceDefinition.id)
- .setCircularRegion(geofenceDefinition.lat, geofenceDefinition.lng, geofenceDefinition.radius)
- .setExpirationDuration(Geofence.NEVER_EXPIRE)
- .setNotificationResponsiveness(5000)
- .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER or Geofence.GEOFENCE_TRANSITION_EXIT)
- .build()
+ .setRequestId(geofenceDefinition.id)
+ .setCircularRegion(
+ geofenceDefinition.lat,
+ geofenceDefinition.lng,
+ geofenceDefinition.radius
+ )
+ .setExpirationDuration(Geofence.NEVER_EXPIRE)
+ .setNotificationResponsiveness(5000)
+ .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER or Geofence.GEOFENCE_TRANSITION_EXIT)
+ .build()
val geofencingRequest = GeofencingRequest.Builder()
- .addGeofence(geofence)
- .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
- .build()
+ .addGeofence(geofence)
+ .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
+ .build()
geofencingClient.addGeofences(geofencingRequest, geofencePendingIntent).run {
addOnSuccessListener {
@@ -104,7 +115,11 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
}
addOnFailureListener { exception ->
- LOG.log(Level.SEVERE, "Add geofence failed: ${geofenceDefinition.id}", exception)
+ LOG.log(
+ Level.SEVERE,
+ "Add geofence failed: ${geofenceDefinition.id}",
+ exception
+ )
}
}
}
@@ -118,12 +133,18 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
}
private fun getBaseUrl(context: Context): String? {
- val sharedPreferences = context.getSharedPreferences(context.getString(R.string.OR_CONSOLE_NAME), Context.MODE_PRIVATE)
+ val sharedPreferences = context.getSharedPreferences(
+ context.getString(R.string.app_name),
+ Context.MODE_PRIVATE
+ )
return sharedPreferences.getString(baseUrlKey, null)
}
private fun getConsoleId(context: Context): String? {
- val sharedPreferences = context.getSharedPreferences(context.getString(R.string.OR_CONSOLE_NAME), Context.MODE_PRIVATE)
+ val sharedPreferences = context.getSharedPreferences(
+ context.getString(R.string.app_name),
+ Context.MODE_PRIVATE
+ )
return sharedPreferences.getString(consoleIdKey, null)
}
}
@@ -144,14 +165,16 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
override fun onLocationResult(locationResult: LocationResult?) {
locationResult?.lastLocation?.let {
locationClient.removeLocationUpdates(this)
- locationCallback?.accept(hashMapOf(
+ locationCallback?.accept(
+ hashMapOf(
"action" to "GET_LOCATION",
"provider" to "geofence",
"data" to hashMapOf(
- "latitude" to it.latitude,
- "longitude" to it.longitude
+ "latitude" to it.latitude,
+ "longitude" to it.longitude
)
- ))
+ )
+ )
locationCallback = null
}
}
@@ -164,46 +187,52 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
private var locationCallback: GeofenceCallback? = null
fun initialize(): Map<String, Any> {
- val sharedPreferences = context.getSharedPreferences(context.getString(R.string.OR_CONSOLE_NAME), Context.MODE_PRIVATE)
+ val sharedPreferences =
+ context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE)
return hashMapOf(
- "action" to "PROVIDER_INIT",
- "provider" to "geofence",
- "version" to version,
- "requiresPermission" to true,
- "hasPermission" to (ContextCompat.checkSelfPermission(context, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED),
- "success" to true,
- "enabled" to false, // Always require enabling to ensure geofences are refresh at startup
- "disabled" to sharedPreferences.contains(geofenceDisabledKey)
+ "action" to "PROVIDER_INIT",
+ "provider" to "geofence",
+ "version" to version,
+ "requiresPermission" to true,
+ "hasPermission" to (
+ context.checkSelfPermission(
+ ACCESS_FINE_LOCATION
+ ) == PackageManager.PERMISSION_GRANTED),
+ "success" to true,
+ "enabled" to false, // Always require enabling to ensure geofences are refresh at startup
+ "disabled" to sharedPreferences.contains(geofenceDisabledKey)
)
}
@SuppressLint("MissingPermission")
fun enable(activity: Activity, baseUrl: String, consoleId: String, callback: GeofenceCallback) {
- val sharedPreferences = context.getSharedPreferences(context.getString(R.string.OR_CONSOLE_NAME), Context.MODE_PRIVATE)
+ val sharedPreferences =
+ context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE)
sharedPreferences.edit()
- .putString(baseUrlKey, baseUrl)
- .putString(consoleIdKey, consoleId)
- .remove(geofenceDisabledKey)
- .apply()
+ .putString(baseUrlKey, baseUrl)
+ .putString(consoleIdKey, consoleId)
+ .remove(geofenceDisabledKey)
+ .apply()
- val hasPermission = when(android.os.Build.VERSION.SDK_INT) {
+ val hasPermission = when (android.os.Build.VERSION.SDK_INT) {
android.os.Build.VERSION_CODES.Q -> {
- ContextCompat.checkSelfPermission(
- context,
+ context.checkSelfPermission(
ACCESS_BACKGROUND_LOCATION
) == PackageManager.PERMISSION_GRANTED
- } else -> {
- ContextCompat.checkSelfPermission(
- context,
+ }
+ else -> {
+ context.checkSelfPermission(
ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED
}
}
if (!hasPermission && !sharedPreferences.getBoolean(
- locationPermissionAskedKey, false)) {
+ locationPermissionAskedKey, false
+ )
+ ) {
sharedPreferences.edit().putBoolean(locationPermissionAskedKey, true).apply()
enableCallback = callback
registerPermissions(activity)
@@ -214,16 +243,17 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
}
fun disable() {
- val sharedPreferences = context.getSharedPreferences(context.getString(R.string.OR_CONSOLE_NAME), Context.MODE_PRIVATE)
+ val sharedPreferences =
+ context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE)
removeGeofences(getGeofences(context))
sharedPreferences.edit()
- .remove(baseUrlKey)
- .remove(consoleIdKey)
- .remove(geofencesKey)
- .putBoolean(geofenceDisabledKey, true)
- .apply()
+ .remove(baseUrlKey)
+ .remove(consoleIdKey)
+ .remove(geofencesKey)
+ .putBoolean(geofenceDisabledKey, true)
+ .apply()
//context.stopService(Intent(context, LocationService::class.java))
}
@@ -233,7 +263,9 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
locationCallback = callback
- val hasPermission = ContextCompat.checkSelfPermission(context, ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
+ val hasPermission = context.checkSelfPermission(
+ ACCESS_FINE_LOCATION
+ ) == PackageManager.PERMISSION_GRANTED
if (hasPermission) {
locationRequest = LocationRequest.create()
@@ -243,11 +275,13 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
locationClient.requestLocationUpdates(locationRequest, locationUpdateCallback, null)
} else {
registerPermissions(activity)
- locationCallback?.accept(hashMapOf(
+ locationCallback?.accept(
+ hashMapOf(
"action" to "GET_LOCATION",
"provider" to "geofence",
"data" to hashMapOf<String, Any>()
- ))
+ )
+ )
locationCallback = null
}
}
@@ -255,7 +289,8 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
fun refreshGeofences() {
LOG.info("Refresh geofences")
- val sharedPreferences = context.getSharedPreferences(context.getString(R.string.OR_CONSOLE_NAME), Context.MODE_PRIVATE)
+ val sharedPreferences =
+ context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE)
val url = "${getBaseUrl(context)}/$geofenceFetchEndpoint${getConsoleId(context)}"
LOG.info("Fetching geofences from server: ${url}")
@@ -284,8 +319,8 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
}
sharedPreferences.edit()
- .putString(geofencesKey, geofencesJson)
- .apply()
+ .putString(geofencesKey, geofencesJson)
+ .apply()
} catch (e: Exception) {
LOG.log(Level.SEVERE, "Failed to refresh geofences", e)
}
@@ -297,26 +332,27 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
Thread {
- val hasPermission = when(android.os.Build.VERSION.SDK_INT) {
+ val hasPermission = when (android.os.Build.VERSION.SDK_INT) {
android.os.Build.VERSION_CODES.Q -> {
- ContextCompat.checkSelfPermission(
- context,
+ context.checkSelfPermission(
ACCESS_BACKGROUND_LOCATION
) == PackageManager.PERMISSION_GRANTED
- } else -> {
- ContextCompat.checkSelfPermission(
- context,
+ }
+ else -> {
+ context.checkSelfPermission(
ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED
}
}
- callback?.accept(hashMapOf(
+ callback?.accept(
+ hashMapOf(
"action" to "PROVIDER_ENABLE",
"provider" to "geofence",
"hasPermission" to hasPermission,
"success" to true
- ))
+ )
+ )
if (hasPermission) {
LOG.info("Has permission so fetching geofences")
@@ -335,18 +371,48 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio
private fun registerPermissions(activity: Activity) {
LOG.info("Requesting geofence permissions")
- val permissions = mutableListOf(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION)
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
- permissions.add(ACCESS_BACKGROUND_LOCATION)
+ if (context.checkSelfPermission(ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
+ activity.requestPermissions(
+ arrayOf(
+ ACCESS_BACKGROUND_LOCATION
+ ),
+ locationResponseCode
+ )
+ }
+ } else {
+ activity.requestPermissions(
+ arrayOf(ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION),
+ locationResponseCode
+ )
}
- ActivityCompat.requestPermissions(activity, permissions.toTypedArray(), locationReponseCode)
}
- override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
+ fun onRequestPermissionsResult(activity: Activity) {
if (enableCallback != null) {
onEnable(enableCallback!!)
enableCallback = null
}
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
+ if (context.checkSelfPermission(ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
+ context.checkSelfPermission(ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED
+ ) {
+ AlertDialog.Builder(activity)
+ .setIcon(R.mipmap.ic_launcher)
+ .setTitle(R.string.background_location_alert_title)
+ .setMessage(R.string.background_location_alert_body)
+ .setNegativeButton(R.string.background_location_decline, null)
+ .setPositiveButton(R.string.background_location_accept) { dialog, which ->
+ activity.requestPermissions(
+ arrayOf(
+ ACCESS_BACKGROUND_LOCATION
+ ),
+ locationResponseCode
+ )
+ }
+ .show()
+ }
+ }
}
private fun removeGeofence(id: String) {
diff --git a/console/android/GenericApp/app/src/main/java/io/openremote/app/service/ORFirebaseMessagingService.kt b/console/android/GenericApp/app/src/main/java/io/openremote/app/service/ORFirebaseMessagingService.kt
index f52aa196b..c93c9d450 100644
--- a/console/android/GenericApp/app/src/main/java/io/openremote/app/service/ORFirebaseMessagingService.kt
+++ b/console/android/GenericApp/app/src/main/java/io/openremote/app/service/ORFirebaseMessagingService.kt
@@ -74,7 +74,7 @@ class ORFirebaseMessagingService : com.google.firebase.messaging.FirebaseMessagi
if (notificationIdStr != null && notificationIdStr.isNotEmpty()) {
notificationId = notificationIdStr.toLong()
val consoleId: String? = getSharedPreferences(
- applicationContext.getString(R.string.OR_CONSOLE_NAME),
+ applicationContext.getString(R.string.app_name),
Context.MODE_PRIVATE
).getString("consoleId", "")
if (!consoleId.isNullOrBlank()) {
diff --git a/console/android/GenericApp/app/src/main/java/io/openremote/app/service/ORMessagingActionService.kt b/console/android/GenericApp/app/src/main/java/io/openremote/app/service/ORMessagingActionService.kt
index 9a159dc25..26a84c363 100644
--- a/console/android/GenericApp/app/src/main/java/io/openremote/app/service/ORMessagingActionService.kt
+++ b/console/android/GenericApp/app/src/main/java/io/openremote/app/service/ORMessagingActionService.kt
@@ -23,7 +23,7 @@ class ORMessagingActionService : IntentService("org.openremote.android.ORMessagi
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
manager.cancel(java.lang.Long.hashCode(notificationId))
val consoleId = getSharedPreferences(
- applicationContext.getString(R.string.OR_CONSOLE_NAME),
+ applicationContext.getString(R.string.app_name),
MODE_PRIVATE
).getString("consoleId", "")
if (!TextUtils.isEmpty(consoleId)) {
diff --git a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/MainActivity.kt b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/MainActivity.kt
index 2e58a29bf..206273618 100644
--- a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/MainActivity.kt
+++ b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/MainActivity.kt
@@ -2,7 +2,6 @@ package io.openremote.app.ui
import android.Manifest
import android.annotation.SuppressLint
-import android.annotation.TargetApi
import android.app.Activity
import android.app.DownloadManager
import android.content.*
@@ -23,19 +22,18 @@ import android.widget.ProgressBar
import android.widget.RelativeLayout
import android.widget.Toast
import androidx.appcompat.widget.PopupMenu
-import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.google.android.material.floatingactionbutton.FloatingActionButton
-import com.google.firebase.iid.FirebaseInstanceId
+import com.google.firebase.messaging.FirebaseMessaging
import io.openremote.app.R
+import io.openremote.app.databinding.ActivityMainBinding
import io.openremote.app.models.ORAppConfig
import io.openremote.app.network.ApiManager
import io.openremote.app.service.GeofenceProvider
-import kotlinx.android.synthetic.main.activity_main.*
import org.json.JSONException
import org.json.JSONObject
import java.util.*
@@ -43,6 +41,9 @@ import java.util.logging.Level
import java.util.logging.Logger
class MainActivity : Activity() {
+
+ private lateinit var binding: ActivityMainBinding
+
private val connectivityChangeReceiver: ConnectivityChangeReceiver =
ConnectivityChangeReceiver()
private var timeOutHandler: Handler? = null
@@ -81,6 +82,10 @@ class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ binding = ActivityMainBinding.inflate(layoutInflater)
+ val view = binding.root
+ setContentView(view)
+
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
try {
@@ -95,9 +100,9 @@ class MainActivity : Activity() {
LOG.info("Enabling remote debugging")
WebView.setWebContentsDebuggingEnabled(true)
}
- setContentView(R.layout.activity_main)
+
if (savedInstanceState != null) {
- webView?.restoreState(savedInstanceState)
+ binding.webView.restoreState(savedInstanceState)
} else {
initializeWebView()
}
@@ -210,7 +215,7 @@ class MainActivity : Activity() {
popupMenu.show()
}
- activity_web.addView(floatingActionButton)
+ binding.activityWeb.addView(floatingActionButton)
}
}
}
@@ -261,17 +266,15 @@ class MainActivity : Activity() {
}
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
- if (webView != null) {
- if (event.action == KeyEvent.ACTION_DOWN) {
- when (keyCode) {
- KeyEvent.KEYCODE_BACK -> {
- if (webView.canGoBack()) {
- webView.goBack()
- } else {
- finish()
- }
- return true
+ if (event.action == KeyEvent.ACTION_DOWN) {
+ when (keyCode) {
+ KeyEvent.KEYCODE_BACK -> {
+ if (binding.webView.canGoBack()) {
+ binding.webView.goBack()
+ } else {
+ finish()
}
+ return true
}
}
}
@@ -279,11 +282,11 @@ class MainActivity : Activity() {
}
override fun onSaveInstanceState(outState: Bundle) {
- webView.saveState(outState)
+ binding.webView.saveState(outState)
}
private fun reloadWebView() {
- var url = webView.url
+ var url = binding.webView.url
if ("about:blank" == url) {
url = clientUrl
LOG.fine("Reloading web view: $url")
@@ -295,211 +298,201 @@ class MainActivity : Activity() {
fun initializeWebView() {
LOG.fine("Initializing web view")
val webAppInterface = WebAppInterface(this)
- webView.addJavascriptInterface(webAppInterface, "MobileInterface")
- val webSettings = webView.settings
- webSettings.javaScriptEnabled = true
- webSettings.mixedContentMode = WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE
- webSettings.cacheMode = WebSettings.LOAD_DEFAULT
- webSettings.domStorageEnabled = true
- webSettings.databaseEnabled = true
- webSettings.setSupportMultipleWindows(true)
- webView.setOnLongClickListener { true }
- webView.isLongClickable = false
- webView.webViewClient = object : WebViewClient() {
- override fun onReceivedHttpError(
- view: WebView,
- request: WebResourceRequest,
- errorResponse: WebResourceResponse
- ) {
- // When initialising Keycloak with an invalid offline refresh token (e.g. wrong nonce because
- // server was reinstalled), we detect the failure and then don't show an error view. We clear the stored
- // invalid token. The web app will then start a new login.
- if (request.url.lastPathSegment != null && request.url.lastPathSegment == "token" && request.method == "POST" && errorResponse.statusCode == 400) {
- storeData(getString(R.string.SHARED_PREF_REFRESH_TOKEN), null)
- return
- }
- handleError(
- errorResponse.statusCode,
- errorResponse.reasonPhrase,
- request.url.toString(),
- request.isForMainFrame
- )
- }
+ binding.webView.apply {
+ addJavascriptInterface(webAppInterface, "MobileInterface")
+ settings.javaScriptEnabled = true
+ settings.mixedContentMode = WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE
+ settings.cacheMode = WebSettings.LOAD_DEFAULT
+ settings.domStorageEnabled = true
+ settings.databaseEnabled = true
+ settings.setSupportMultipleWindows(true)
+ webViewClient = object : WebViewClient() {
+ override fun onReceivedHttpError(
+ view: WebView,
+ request: WebResourceRequest,
+ errorResponse: WebResourceResponse
+ ) {
+ //When initialising Keycloak with an invalid offline refresh token (e.g. wrong nonce because
+ // server was reinstalled), we detect the failure and then don't show an error view. We clear the stored
+ // invalid token. The web app will then start a new login.
+ if (request.url.lastPathSegment != null && request.url.lastPathSegment == "token" && request.method == "POST" && errorResponse.statusCode == 400) {
+ storeData(getString(R.string.SHARED_PREF_REFRESH_TOKEN), null)
+ return
+ }
- override fun onReceivedError(
- view: WebView,
- errorCode: Int,
- description: String,
- failingUrl: String
- ) {
- handleError(errorCode, description, failingUrl, true)
- }
+ handleError(
+ errorResponse.statusCode,
+ errorResponse.reasonPhrase,
+ request.url.toString(),
+ request.isForMainFrame
+ )
+ }
- @TargetApi(Build.VERSION_CODES.M)
- override fun onReceivedError(
- view: WebView,
- request: WebResourceRequest,
- error: WebResourceError
- ) {
+ override fun onReceivedError(
+ view: WebView,
+ request: WebResourceRequest,
+ error: WebResourceError
+ ) {
+ // Remote debugging session from Chrome wants to load about:blank and then fails with "ERROR_UNSUPPORTED_SCHEME", ignore
+ if ("net::ERR_CACHE_MISS".contentEquals(error.description)) {
+ return
+ }
+ if (request.url.toString() == "about:blank" && error.errorCode == ERROR_UNSUPPORTED_SCHEME) {
+ return
+ }
+ handleError(
+ error.errorCode,
+ error.description.toString(),
+ request.url.toString(),
+ request.isForMainFrame
+ )
+ }
- // Remote debugging session from Chrome wants to load about:blank and then fails with "ERROR_UNSUPPORTED_SCHEME", ignore
- if ("net::ERR_CACHE_MISS".contentEquals(error.description)) {
- return
+ override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
+ progressBar!!.visibility = View.VISIBLE
+ timeOutRunnable = Runnable {
+ if (!webViewLoaded) {
+ handleError(ERROR_TIMEOUT, "Connection timed out", url, true)
+ }
+ }
+ timeOutHandler = Looper.myLooper()?.let { Handler(it) }
+ timeOutHandler!!.postDelayed(timeOutRunnable!!, 5000)
}
- if (request.url.toString() == "about:blank" && error.errorCode == ERROR_UNSUPPORTED_SCHEME) {
- return
+
+ override fun onPageFinished(view: WebView, url: String) {
+ webViewLoaded = true
+ progressBar!!.visibility = View.GONE
+ timeOutRunnable?.let { timeOutHandler!!.removeCallbacks(it) }
}
- handleError(
- error.errorCode, error.description.toString(),
- request.url.toString(), request.isForMainFrame
- )
- }
- override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
- progressBar!!.visibility = View.VISIBLE
- timeOutRunnable = Runnable {
- if (!webViewLoaded) {
- handleError(ERROR_TIMEOUT, "Connection timed out", url, true)
+ override fun shouldOverrideUrlLoading(
+ view: WebView,
+ request: WebResourceRequest
+ ): Boolean {
+ if (request.url.scheme.equals("webbrowser", ignoreCase = true)) {
+ val newUrl = request.url.buildUpon().scheme("https").build().toString()
+ val i = Intent(Intent.ACTION_VIEW)
+ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ i.data = Uri.parse(newUrl)
+ startActivity(i)
+ return true
}
+ return super.shouldOverrideUrlLoading(view, request)
}
- timeOutHandler = Handler(Looper.myLooper())
- timeOutHandler!!.postDelayed(timeOutRunnable, 5000)
}
+ webChromeClient = object : WebChromeClient() {
+ override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean {
+ val msg =
+ "WebApp console (" + consoleMessage.sourceId() + ":" + consoleMessage.lineNumber() + "): " + consoleMessage.message()
+ when (consoleMessage.messageLevel()) {
+ MessageLevel.DEBUG, MessageLevel.TIP -> LOG.fine(msg)
+ MessageLevel.LOG -> LOG.info(msg)
+ else -> LOG.severe(msg)
+ }
+ return true
+ }
- override fun onPageFinished(view: WebView, url: String) {
- webViewLoaded = true
- progressBar!!.visibility = View.GONE
- timeOutHandler!!.removeCallbacks(timeOutRunnable)
- }
+ override fun onProgressChanged(view: WebView, progress: Int) {
+ progressBar!!.progress = progress
+ }
- override fun shouldOverrideUrlLoading(
- view: WebView,
- request: WebResourceRequest
- ): Boolean {
- if (request.url.scheme.equals("webbrowser", ignoreCase = true)) {
- val newUrl = request.url.buildUpon().scheme("https").build().toString()
- val i = Intent(Intent.ACTION_VIEW)
- i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- i.data = Uri.parse(newUrl)
- startActivity(i)
+ override fun onCreateWindow(
+ view: WebView,
+ dialog: Boolean,
+ userGesture: Boolean,
+ resultMsg: Message
+ ): Boolean {
+ val newWebView = WebView(this@MainActivity)
+ view.addView(newWebView)
+ val transport = resultMsg.obj as WebViewTransport
+ transport.webView = newWebView
+ resultMsg.sendToTarget()
+ newWebView.webViewClient = object : WebViewClient() {
+ override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
+ val browserIntent = Intent(Intent.ACTION_VIEW)
+ browserIntent.data = Uri.parse(url)
+ startActivity(browserIntent)
+ return true
+ }
+ }
return true
}
- return super.shouldOverrideUrlLoading(view, request)
}
- private fun handleError(
- errorCode: Int,
- description: String,
- failingUrl: String?,
- isForMainFrame: Boolean
- ) {
- LOG.warning("Error requesting '$failingUrl': $errorCode($description)")
-
- // This will be the URL loaded into the webview itself (false for images etc. of the main page)
- if (isForMainFrame) {
-
- // Check page load error URL
- val errorUrl = getString(R.string.OR_CONSOLE_LOAD_ERROR_URL)
- if (!TextUtils.isEmpty(errorUrl) && failingUrl != errorUrl) {
- LOG.info("Loading error URL: $errorUrl")
- loadUrl(errorUrl)
- return
- }
+ setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
+ val writePermission = Manifest.permission.WRITE_EXTERNAL_STORAGE
+ if (ContextCompat.checkSelfPermission(
+ this@MainActivity,
+ writePermission
+ ) != PackageManager.PERMISSION_GRANTED
+ ) {
+ // Write permission has not been granted yet, request it.
+ requestPermissions(
+ arrayOf(writePermission),
+ WRITE_PERMISSION_FOR_DOWNLOAD
+ )
} else {
- if (java.lang.Boolean.parseBoolean(getString(R.string.OR_CONSOLE_IGNORE_PAGE_ERRORS))) {
- return
- }
-
- //TODO should we always ignore image errors?
- if (failingUrl != null && (failingUrl.endsWith("png")
- || failingUrl.endsWith("jpg")
- || failingUrl.endsWith("ico"))
- ) {
- LOG.info("Ignoring error loading image resource")
- return
- }
+ val request = DownloadManager.Request(Uri.parse(url))
+ request.setMimeType(mimetype)
+ //------------------------COOKIE!!------------------------
+ val cookies = CookieManager.getInstance().getCookie(url)
+ request.addRequestHeader("cookie", cookies)
+ //------------------------COOKIE!!------------------------
+ request.addRequestHeader("User-Agent", userAgent)
+ request.setDescription("Downloading file...")
+ request.setTitle(
+ URLUtil.guessFileName(
+ url,
+ contentDisposition,
+ mimetype
+ )
+ )
+ request.allowScanningByMediaScanner()
+ request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
+ request.setDestinationInExternalPublicDir(
+ Environment.DIRECTORY_DOWNLOADS,
+ URLUtil.guessFileName(url, contentDisposition, mimetype)
+ )
+ val dm =
+ getSystemService(DOWNLOAD_SERVICE) as DownloadManager
+ Toast.makeText(applicationContext, R.string.downloading_file, Toast.LENGTH_LONG)
+ .show()
+ dm.enqueue(request)
}
}
}
- webView.webChromeClient = object : WebChromeClient() {
- override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean {
- val msg =
- "WebApp console (" + consoleMessage.sourceId() + ":" + consoleMessage.lineNumber() + "): " + consoleMessage.message()
- when (consoleMessage.messageLevel()) {
- MessageLevel.DEBUG, MessageLevel.TIP -> LOG.fine(msg)
- MessageLevel.LOG -> LOG.info(msg)
- else -> LOG.severe(msg)
- }
- return true
- }
+ }
- override fun onProgressChanged(view: WebView, progress: Int) {
- progressBar!!.progress = progress
- }
+ private fun handleError(
+ errorCode: Int,
+ description: String,
+ failingUrl: String?,
+ isForMainFrame: Boolean
+ ) {
+ LOG.warning("Error requesting '$failingUrl': $errorCode($description)")
- override fun onCreateWindow(
- view: WebView,
- dialog: Boolean,
- userGesture: Boolean,
- resultMsg: Message
- ): Boolean {
- val newWebView = WebView(this@MainActivity)
- view.addView(newWebView)
- val transport = resultMsg.obj as WebViewTransport
- transport.webView = newWebView
- resultMsg.sendToTarget()
- newWebView.webViewClient = object : WebViewClient() {
- override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
- val browserIntent = Intent(Intent.ACTION_VIEW)
- browserIntent.data = Uri.parse(url)
- startActivity(browserIntent)
- return true
- }
- }
- return true
+ // This will be the URL loaded into the webview itself (false for images etc. of the main page)
+ if (isForMainFrame) {
+
+ // Check page load error URL
+ val errorUrl = getString(R.string.OR_CONSOLE_LOAD_ERROR_URL)
+ if (!TextUtils.isEmpty(errorUrl) && failingUrl != errorUrl) {
+ LOG.info("Loading error URL: $errorUrl")
+ loadUrl(errorUrl)
+ return
+ }
+ } else {
+ if (java.lang.Boolean.parseBoolean(getString(R.string.OR_CONSOLE_IGNORE_PAGE_ERRORS))) {
+ return
}
- }
- webView.setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
- val writePermission = Manifest.permission.WRITE_EXTERNAL_STORAGE
- if (ContextCompat.checkSelfPermission(
- this@MainActivity,
- writePermission
- ) != PackageManager.PERMISSION_GRANTED
+ //TODO should we always ignore image errors?
+ if (failingUrl != null && (failingUrl.endsWith("png")
+ || failingUrl.endsWith("jpg")
+ || failingUrl.endsWith("ico"))
) {
- // Write permission has not been granted yet, request it.
- ActivityCompat.requestPermissions(
- this@MainActivity,
- arrayOf(writePermission),
- WRITE_PERMISSION_FOR_DOWNLOAD
- )
- } else {
- val request = DownloadManager.Request(Uri.parse(url))
- request.setMimeType(mimetype)
- //------------------------COOKIE!!------------------------
- val cookies = CookieManager.getInstance().getCookie(url)
- request.addRequestHeader("cookie", cookies)
- //------------------------COOKIE!!------------------------
- request.addRequestHeader("User-Agent", userAgent)
- request.setDescription("Downloading file...")
- request.setTitle(
- URLUtil.guessFileName(
- url,
- contentDisposition,
- mimetype
- )
- )
- request.allowScanningByMediaScanner()
- request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
- request.setDestinationInExternalPublicDir(
- Environment.DIRECTORY_DOWNLOADS,
- URLUtil.guessFileName(url, contentDisposition, mimetype)
- )
- val dm =
- getSystemService(DOWNLOAD_SERVICE) as DownloadManager
- Toast.makeText(applicationContext, R.string.downloading_file, Toast.LENGTH_LONG)
- .show()
- dm.enqueue(request)
+ LOG.info("Ignoring error loading image resource")
+ return
}
}
}
@@ -507,7 +500,7 @@ class MainActivity : Activity() {
private fun loadUrl(url: String?) {
webViewLoaded = false
val temp = url!!.replace(" ", "%20")
- webView.loadUrl(temp)
+ binding.webView.loadUrl(temp)
}
override fun onRequestPermissionsResult(
@@ -520,11 +513,10 @@ class MainActivity : Activity() {
Toast.makeText(applicationContext, R.string.downloading_file, Toast.LENGTH_LONG)
.show()
}
- } else if (requestCode == GeofenceProvider.locationReponseCode) {
- geofenceProvider?.onRequestPermissionsResult(requestCode, permissions, grantResults)
- } else {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ } else if (requestCode == GeofenceProvider.locationResponseCode) {
+ geofenceProvider?.onRequestPermissionsResult(this)
}
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
private inner class WebAppInterface(
@@ -644,7 +636,7 @@ class MainActivity : Activity() {
.remove(PUSH_PROVIDER_DISABLED_KEY)
.apply()
// TODO: Implement topic support
- FirebaseInstanceId.getInstance().instanceId.addOnCompleteListener { task ->
+ FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
val response: MutableMap<String, Any?> =
HashMap()
response["action"] = "PROVIDER_ENABLE"
@@ -654,7 +646,7 @@ class MainActivity : Activity() {
val responseData: MutableMap<String, Any> =
HashMap()
if (task.isSuccessful) {
- responseData["token"] = task.result.token
+ responseData["token"] = task.result
}
response["data"] = responseData
notifyClient(response)
@@ -724,10 +716,11 @@ class MainActivity : Activity() {
}
private fun notifyClient(data: Map<String, Any?>?) {
+ LOG.info("notifyClient with message: $data")
try {
val jsonString = ObjectMapper().writeValueAsString(data)
runOnUiThread {
- webView.evaluateJavascript(
+ binding.webView.evaluateJavascript(
String.format(
"OpenRemoteConsole._handleProviderResponse('%s')",
jsonString
diff --git a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/ProjectActivity.kt b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/ProjectActivity.kt
index c8bb352fd..9c243e5f0 100644
--- a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/ProjectActivity.kt
+++ b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/ProjectActivity.kt
@@ -9,24 +9,28 @@ import android.view.inputmethod.EditorInfo
import android.widget.Toast
import androidx.preference.PreferenceManager
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
-import io.openremote.app.R
+import io.openremote.app.databinding.ActivityProjectBinding
import io.openremote.app.network.ApiManager
-import kotlinx.android.synthetic.main.activity_project.*
class ProjectActivity : Activity() {
+
+ private lateinit var binding: ActivityProjectBinding
+
var sharedPreferences: SharedPreferences? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_project)
+ binding = ActivityProjectBinding.inflate(layoutInflater)
+ val view = binding.root
+ setContentView(view)
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
- realm_input.setOnEditorActionListener { textView, actionId, keyEvent ->
+ binding.realmInput.setOnEditorActionListener { textView, actionId, keyEvent ->
if (actionId == EditorInfo.IME_ACTION_GO) {
- if (!project_input.text.isNullOrBlank() && !realm_input.text.isNullOrBlank()) {
- requestAppConfig(project_input.text.toString(), realm_input.text.toString())
+ if (!binding.projectInput.text.isNullOrBlank() && !binding.realmInput.text.isNullOrBlank()) {
+ requestAppConfig(binding.projectInput.text.toString(), binding.realmInput.text.toString())
}
true
} else {
@@ -34,18 +38,18 @@ class ProjectActivity : Activity() {
}
}
- connect_button.setOnClickListener {
- if (!project_input.text.isNullOrBlank() && !realm_input.text.isNullOrBlank()) {
- requestAppConfig(project_input.text.toString(), realm_input.text.toString())
+ binding.connectButton.setOnClickListener {
+ if (!binding.projectInput.text.isNullOrBlank() && !binding.realmInput.text.isNullOrBlank()) {
+ requestAppConfig(binding.projectInput.text.toString(), binding.realmInput.text.toString())
}
}
}
private fun requestAppConfig(project: String, realm: String) {
- progressBar.visibility = View.VISIBLE
+ binding.progressBar.visibility = View.VISIBLE
val apiManager = ApiManager("https://${project}.openremote.io/api/${realm}")
apiManager.getAppConfig { statusCode, appConfig, error ->
- progressBar.visibility = View.INVISIBLE
+ binding.progressBar.visibility = View.INVISIBLE
if (statusCode in 200..299) {
sharedPreferences?.edit()?.putString("project", project)?.apply()
sharedPreferences?.edit()?.putString("realm", realm)?.apply()
@@ -54,11 +58,13 @@ class ProjectActivity : Activity() {
startActivity(intent)
finish()
} else {
- Toast.makeText(
- this,
- "Error occurred getting app config. Check your input and try again",
- Toast.LENGTH_LONG
- ).show()
+ runOnUiThread {
+ Toast.makeText(
+ this,
+ "Error occurred getting app config. Check your input and try again",
+ Toast.LENGTH_LONG
+ ).show()
+ }
}
}
}
diff --git a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/SplashActivity.kt b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/SplashActivity.kt
index 32d1b4a4e..c710e22e8 100644
--- a/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/SplashActivity.kt
+++ b/console/android/GenericApp/app/src/main/java/io/openremote/app/ui/SplashActivity.kt
@@ -6,16 +6,21 @@ import android.content.SharedPreferences
import android.os.Bundle
import androidx.preference.PreferenceManager
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
-import io.openremote.app.R
+import io.openremote.app.databinding.ActivitySplashBinding
import io.openremote.app.network.ApiManager
import io.openremote.app.ui.MainActivity.Companion.APP_CONFIG_KEY
class SplashActivity : Activity() {
+
+ private lateinit var binding: ActivitySplashBinding
+
var sharedPreferences: SharedPreferences? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_splash)
+ binding = ActivitySplashBinding.inflate(layoutInflater)
+ val view = binding.root
+ setContentView(view)
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
diff --git a/console/android/GenericApp/app/src/main/res/layout/activity_main.xml b/console/android/GenericApp/app/src/main/res/layout/activity_main.xml
index b2b8f4a37..be316fb52 100644
--- a/console/android/GenericApp/app/src/main/res/layout/activity_main.xml
+++ b/console/android/GenericApp/app/src/main/res/layout/activity_main.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_web"
android:layout_width="match_parent"
diff --git a/console/android/GenericApp/app/src/main/res/layout/activity_project.xml b/console/android/GenericApp/app/src/main/res/layout/activity_project.xml
index 04ab94f8d..978782688 100644
--- a/console/android/GenericApp/app/src/main/res/layout/activity_project.xml
+++ b/console/android/GenericApp/app/src/main/res/layout/activity_project.xml
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.constraintlayout.widget.ConstraintLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:padding="@dimen/box_inset_layout_padding"
- tools:context=".ui.SplashActivity"
+ tools:context=".ui.ProjectActivity"
tools:deviceIds="wear">
@@ -89,7 +90,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
- android:background="@color/colorPrimary"
+ android:background="@color/medium_green"
android:text="Connect"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
diff --git a/console/android/GenericApp/app/src/main/res/layout/activity_splash.xml b/console/android/GenericApp/app/src/main/res/layout/activity_splash.xml
index 00c34e57b..846f5ac49 100644
--- a/console/android/GenericApp/app/src/main/res/layout/activity_splash.xml
+++ b/console/android/GenericApp/app/src/main/res/layout/activity_splash.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
diff --git a/console/android/GenericApp/app/src/main/res/values/styles.xml b/console/android/GenericApp/app/src/main/res/values/styles.xml
index a6b3daec9..b911207b3 100644
--- a/console/android/GenericApp/app/src/main/res/values/styles.xml
+++ b/console/android/GenericApp/app/src/main/res/values/styles.xml
@@ -1,2 +1,10 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources></resources>
\ No newline at end of file
+<resources>
+
+ <style name="OpenRemoteTheme" parent="Theme.AppCompat.Light.NoActionBar">
+ <item name="android:actionMenuTextColor">@color/dark_grey</item>
+ <item name="colorPrimary">@color/medium_green</item>
+ <item name="colorPrimaryDark">@color/dark_green</item>
+ <item name="colorAccent">@color/light_green</item>
+ </style>
+
+</resources>
\ No newline at end of file
diff --git a/console/android/GenericApp/build.gradle b/console/android/GenericApp/build.gradle
index 9907c9ad8..92d351395 100644
--- a/console/android/GenericApp/build.gradle
+++ b/console/android/GenericApp/build.gradle
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
- ext.kotlin_version = "1.4.10"
+ ext.kotlin_version = "1.4.31"
repositories {
google()
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:4.1.0'
+ classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
- classpath 'com.google.gms:google-services:4.3.4'
+ classpath 'com.google.gms:google-services:4.3.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}