From 7da979a577693fbf4c9d1493156c8a7fc469a501 Mon Sep 17 00:00:00 2001 From: Michael Ritchie Date: Fri, 21 May 2021 15:42:18 -0300 Subject: [PATCH] ** If the user is using the screensaver feature, a wake command now disables the screensaver, screensaver is allowed after wake timeout or if user sends wake command with false value. ** Added feature to open settings with command "settings" and completely disable and remove the settings button. There is a new setting under the general settings screen to remove the settings button and settings has been added to the command list in the documentation. --- WallPanelApp/build.gradle | 18 +++-- .../wallpanel/BrowserActivityNativeTest.kt | 2 - .../thanksmister/iot/wallpanel/WallPanel.kt | 2 + .../iot/wallpanel/di/AndroidBindingModule.kt | 4 + .../wallpanel/di/ApplicationComponent.java | 1 - .../iot/wallpanel/di/ServicesModule.java | 20 ++--- .../iot/wallpanel/network/WallPanelService.kt | 73 +++++++++++++------ .../wallpanel/persistence/Configuration.kt | 5 ++ .../ui/activities/BaseBrowserActivity.kt | 23 +++++- .../ui/activities/BrowserActivityNative.kt | 46 ++++++++---- .../ui/activities/LiveCameraActivity.kt | 4 +- .../ui/activities/SettingsActivity.kt | 10 --- .../ui/fragments/SettingsFragment.kt | 11 +++ .../iot/wallpanel/utils/MqttUtils.kt | 1 + .../main/res/drawable/ic_baseline_lock.xml | 10 +++ .../src/main/res/xml/pref_general.xml | 25 +++++-- build.gradle | 13 ++-- gradle/wrapper/gradle-wrapper.properties | 4 +- 18 files changed, 184 insertions(+), 88 deletions(-) create mode 100644 WallPanelApp/src/main/res/drawable/ic_baseline_lock.xml diff --git a/WallPanelApp/build.gradle b/WallPanelApp/build.gradle index 91b6a7d..be66049 100644 --- a/WallPanelApp/build.gradle +++ b/WallPanelApp/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.google.firebase.crashlytics' def versionMajor = 0 def versionMinor = 9 def versionPatch = 4 -def versionBuild = 5 // bump for dog food builds, public betas, etc. +def versionBuild = 7 // bump for dog food builds, public betas, etc. android { kapt { @@ -75,6 +75,11 @@ android { versionName "${versionMajor}.${versionMinor}.${versionPatch} Build ${versionBuild}" } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { @@ -86,6 +91,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-preference-v14:1.0.0' implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' @@ -126,9 +132,7 @@ dependencies { // MQTT implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5' - implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1', { - exclude module: 'support-v4' - } + implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1' implementation 'com.koushikdutta.async:androidasync:2.1.9' @@ -136,9 +140,9 @@ dependencies { implementation 'com.jakewharton.timber:timber:4.5.1' // Firebase - implementation 'com.google.firebase:firebase-core:18.0.2' - implementation 'com.google.firebase:firebase-crashlytics:17.4.1' - implementation 'com.google.firebase:firebase-analytics:18.0.2' + implementation 'com.google.firebase:firebase-core:19.0.0' + implementation 'com.google.firebase:firebase-crashlytics:18.0.0' + implementation 'com.google.firebase:firebase-analytics:19.0.0' // Picasso image loading implementation 'com.squareup.picasso:picasso:2.71828' diff --git a/WallPanelApp/src/androidTest/java/com/thanksmister/iot/wallpanel/BrowserActivityNativeTest.kt b/WallPanelApp/src/androidTest/java/com/thanksmister/iot/wallpanel/BrowserActivityNativeTest.kt index 1b8c3be..1971b89 100644 --- a/WallPanelApp/src/androidTest/java/com/thanksmister/iot/wallpanel/BrowserActivityNativeTest.kt +++ b/WallPanelApp/src/androidTest/java/com/thanksmister/iot/wallpanel/BrowserActivityNativeTest.kt @@ -23,8 +23,6 @@ import org.junit.After import org.junit.Before import org.junit.Test -import org.junit.Assert.* - class BrowserActivityNativeTest : TestCase() { @Before diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/WallPanel.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/WallPanel.kt index 26503bc..2b68f4f 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/WallPanel.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/WallPanel.kt @@ -18,6 +18,7 @@ package com.thanksmister.iot.wallpanel import android.content.Context import androidx.multidex.MultiDex +import com.google.firebase.FirebaseApp import com.thanksmister.iot.wallpanel.di.DaggerApplicationComponent import com.thanksmister.iot.wallpanel.utils.LauncherShortcuts import dagger.android.AndroidInjector @@ -36,6 +37,7 @@ class WallPanel : DaggerApplication() { Timber.plant(Timber.DebugTree()) } LauncherShortcuts.createShortcuts(this) + FirebaseApp.initializeApp(applicationContext) } override fun attachBaseContext(base: Context) { diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/AndroidBindingModule.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/AndroidBindingModule.kt index fc8209d..216bcd4 100755 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/AndroidBindingModule.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/AndroidBindingModule.kt @@ -18,6 +18,7 @@ package com.thanksmister.iot.wallpanel.di import androidx.lifecycle.ViewModel import com.thanksmister.iot.wallpanel.BootUpReceiver +import com.thanksmister.iot.wallpanel.network.WallPanelService import com.thanksmister.iot.wallpanel.ui.* import com.thanksmister.iot.wallpanel.ui.activities.* import com.thanksmister.iot.wallpanel.ui.fragments.* @@ -34,6 +35,9 @@ internal abstract class AndroidBindingModule { @ViewModelKey(DetectionViewModel::class) abstract fun cameraViewModel(viewModel: DetectionViewModel): ViewModel + @ContributesAndroidInjector + internal abstract fun alarmService(): WallPanelService + @ContributesAndroidInjector internal abstract fun settingsActivity(): SettingsActivity diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/ApplicationComponent.java b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/ApplicationComponent.java index 053bdb5..195e869 100755 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/ApplicationComponent.java +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/ApplicationComponent.java @@ -28,7 +28,6 @@ @Component(modules = { AndroidSupportInjectionModule.class, ApplicationModule.class, - ServicesModule.class, ActivityModule.class, AndroidBindingModule.class, DaggerViewModelInjectionModule.class diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/ServicesModule.java b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/ServicesModule.java index 6e52641..fbb602b 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/ServicesModule.java +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/di/ServicesModule.java @@ -16,22 +16,14 @@ package com.thanksmister.iot.wallpanel.di; -import android.app.Service; - import com.thanksmister.iot.wallpanel.network.WallPanelService; -import dagger.Binds; import dagger.Module; -import dagger.android.AndroidInjector; -import dagger.android.ServiceKey; -import dagger.multibindings.IntoMap; +import dagger.android.ContributesAndroidInjector; + +@Module +abstract class ServicesModule { -@Module(subcomponents = { - ServiceSubcomponent.class -}) -public abstract class ServicesModule { - @Binds - @IntoMap - @ServiceKey(WallPanelService.class) - abstract AndroidInjector.Factory syncServiceInjectorFactory(ServiceSubcomponent.Builder builder); + @ContributesAndroidInjector + abstract WallPanelService contributeMyService(); } \ No newline at end of file diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/WallPanelService.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/WallPanelService.kt index bf1989d..a9ccce3 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/WallPanelService.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/WallPanelService.kt @@ -27,7 +27,6 @@ import android.media.MediaPlayer import android.net.wifi.WifiManager import android.os.* import androidx.core.content.ContextCompat -import androidx.core.os.postDelayed import androidx.lifecycle.LifecycleService import androidx.lifecycle.Observer import androidx.localbroadcastmanager.content.LocalBroadcastManager @@ -43,6 +42,7 @@ import com.thanksmister.iot.wallpanel.persistence.Configuration import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_CLEAR_BROWSER_CACHE import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_JS_EXEC import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_LOAD_URL +import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_OPEN_SETTINGS import com.thanksmister.iot.wallpanel.ui.activities.BaseBrowserActivity.Companion.BROADCAST_ACTION_RELOAD_PAGE import com.thanksmister.iot.wallpanel.utils.MqttUtils import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_AUDIO @@ -56,6 +56,7 @@ import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SENSOR import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SENSOR_FACE import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SENSOR_MOTION import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SENSOR_QR_CODE +import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SETTINGS import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_SPEAK import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_STATE import com.thanksmister.iot.wallpanel.utils.MqttUtils.Companion.COMMAND_URL @@ -75,6 +76,7 @@ import java.util.* import java.util.concurrent.atomic.AtomicBoolean import javax.inject.Inject +// TODO move this to internal class within application, no longer run as service class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { @Inject @@ -103,6 +105,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { private val appStateClearHandler = Handler() private val qrCodeClearHandler = Handler() private val faceClearHandler = Handler() + private val wakeScreenHandler = Handler() private var textToSpeechModule: TextToSpeechModule? = null private var mqttModule: MQTTModule? = null private var connectionLiveData: ConnectionLiveData? = null @@ -183,7 +186,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { filter.addAction(Intent.ACTION_SCREEN_OFF) filter.addAction(Intent.ACTION_USER_PRESENT) localBroadCastManager = LocalBroadcastManager.getInstance(this) - localBroadCastManager!!.registerReceiver(mBroadcastReceiver, filter) + localBroadCastManager?.registerReceiver(mBroadcastReceiver, filter) } override fun onDestroy() { @@ -572,14 +575,11 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { } } if (commandJson.has(COMMAND_WAKE)) { - if (commandJson.getBoolean(COMMAND_WAKE)) { + if (commandJson.getBoolean(COMMAND_WAKE).or(false)) { val wakeTime = commandJson.optLong(COMMAND_WAKETIME, SCREEN_WAKE_TIME / 1000) * 1000 - switchScreenOn(wakeTime) + wakeScreenOn(wakeTime) } else { - if (partialWakeLock != null && partialWakeLock!!.isHeld) { - Timber.d("Release wakelock") - partialWakeLock!!.release() - } + wakeScreenOff() } } if (commandJson.has(COMMAND_BRIGHTNESS)) { @@ -606,6 +606,9 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { if (commandJson.has(COMMAND_SPEAK)) { speakMessage(commandJson.getString(COMMAND_SPEAK)) } + if (commandJson.has(COMMAND_SETTINGS)) { + openSettings() + } if (commandJson.has(COMMAND_VOLUME)) { setVolume((commandJson.getInt(COMMAND_VOLUME).toFloat() / 100)) } @@ -668,19 +671,30 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { } } - private fun switchScreenOn() { - switchScreenOn(SCREEN_WAKE_TIME) + // TODO temporarily wake screen + private fun switchScreen() { + val intent = Intent(BROADCAST_SCREEN_WAKE) + val bm = LocalBroadcastManager.getInstance(applicationContext) + bm.sendBroadcast(intent) } @SuppressLint("WakelockTimeout") - private fun switchScreenOn(wakeTime: Long) { + private fun wakeScreenOn(wakeTime: Long) { if (partialWakeLock != null && !partialWakeLock!!.isHeld) { - partialWakeLock!!.acquire(wakeTime) - } else if (partialWakeLock != null && partialWakeLock!!.isHeld) { - partialWakeLock!!.release() - partialWakeLock!!.acquire(wakeTime) + partialWakeLock?.acquire(wakeTime) + wakeScreenHandler.postDelayed({ + wakeScreenOff() + }, wakeTime) + sendWakeScreenOn() + } + } + + @SuppressLint("WakelockTimeout") + private fun wakeScreenOff() { + if (partialWakeLock != null && partialWakeLock!!.isHeld) { + partialWakeLock?.release() + sendWakeScreenOff() } - sendWakeScreen() } private fun changeScreenBrightness(brightness: Int) { @@ -703,6 +717,12 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { bm.sendBroadcast(intent) } + private fun openSettings() { + val intent = Intent(BROADCAST_ACTION_OPEN_SETTINGS) + val bm = LocalBroadcastManager.getInstance(applicationContext) + bm.sendBroadcast(intent) + } + private fun clearBrowserCache() { val intent = Intent(BROADCAST_ACTION_CLEAR_BROWSER_CACHE) val bm = LocalBroadcastManager.getInstance(applicationContext) @@ -916,9 +936,16 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { bm.sendBroadcast(intent) } - private fun sendWakeScreen() { + private fun sendWakeScreenOn() { Timber.d("sendWakeScreen") - val intent = Intent(BROADCAST_SCREEN_WAKE) + val intent = Intent(BROADCAST_SCREEN_WAKE_ON) + val bm = LocalBroadcastManager.getInstance(applicationContext) + bm.sendBroadcast(intent) + } + + private fun sendWakeScreenOff() { + Timber.d("sendWakeScreenOff") + val intent = Intent(BROADCAST_SCREEN_WAKE_OFF) val bm = LocalBroadcastManager.getInstance(applicationContext) bm.sendBroadcast(intent) } @@ -975,7 +1002,9 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { private val cameraDetectorCallback = object : CameraCallback { override fun onDetectorError() { - sendToastMessage(getString(R.string.error_missing_vision_lib)) + if (configuration.cameraFaceEnabled || configuration.cameraQRCodeEnabled) { + sendToastMessage(getString(R.string.error_missing_vision_lib)) + } } override fun onCameraError() { @@ -985,7 +1014,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { override fun onMotionDetected() { Timber.i("Motion detected") if (configuration.cameraMotionWake) { - switchScreenOn() + switchScreen() } publishMotionDetected() } @@ -999,7 +1028,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { Timber.d("configuration.cameraMotionBright ${configuration.cameraMotionBright}") if (configuration.cameraFaceWake) { configurePowerOptions() - switchScreenOn() + switchScreen() // temp turn on screen } publishFaceDetected() } @@ -1020,6 +1049,8 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { const val BROADCAST_TOAST_MESSAGE = "BROADCAST_TOAST_MESSAGE" const val BROADCAST_SERVICE_STARTED = "BROADCAST_SERVICE_STARTED" const val BROADCAST_SCREEN_WAKE = "BROADCAST_SCREEN_WAKE" + const val BROADCAST_SCREEN_WAKE_ON = "BROADCAST_SCREEN_WAKE_ON" + const val BROADCAST_SCREEN_WAKE_OFF = "BROADCAST_SCREEN_WAKE_OFF" const val BROADCAST_SCREEN_BRIGHTNESS_CHANGE = "BROADCAST_SCREEN_BRIGHTNESS_CHANGE" } } \ No newline at end of file diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/persistence/Configuration.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/persistence/Configuration.kt index 9baf1aa..36e7aaf 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/persistence/Configuration.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/persistence/Configuration.kt @@ -61,6 +61,10 @@ constructor(private val context: Context, private val sharedPreferences: SharedP get() = this.sharedPreferences.getBoolean(PREF_SETTINGS_TRANSPARENT, false) set(value) = this.sharedPreferences.edit().putBoolean(PREF_SETTINGS_TRANSPARENT, value).apply() + var settingsDisabled: Boolean + get() = this.sharedPreferences.getBoolean(PREF_SETTINGS_DISABLE, false) + set(value) = this.sharedPreferences.edit().putBoolean(PREF_SETTINGS_DISABLE, value).apply() + var writeScreenPermissionsShown: Boolean get() = sharedPreferences.getBoolean(PREF_WRITE_SCREEN_PERMISSIONS, false) set(value) { @@ -348,6 +352,7 @@ constructor(private val context: Context, private val sharedPreferences: SharedP private const val PREF_SETTINGS_CODE = "pref_settings_code" private const val PREF_SETTINGS_CODE_STRING = "pref_settings_code_string" private const val PREF_SETTINGS_TRANSPARENT = "pref_settings_transparent" + private const val PREF_SETTINGS_DISABLE = "pref_settings_disable" private const val PREF_SETTINGS_LOCATION = "pref_settings_location" const val PREF_FIRST_TIME = "pref_first_time" const val PREF_WRITE_SCREEN_PERMISSIONS = "pref_write_screen_permissions" diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BaseBrowserActivity.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BaseBrowserActivity.kt index bd83286..3e5404c 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BaseBrowserActivity.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BaseBrowserActivity.kt @@ -37,6 +37,8 @@ import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCA import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_EVENT_SCREEN_TOUCH import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_SCREEN_BRIGHTNESS_CHANGE import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_SCREEN_WAKE +import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_SCREEN_WAKE_OFF +import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_SCREEN_WAKE_ON import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_SERVICE_STARTED import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_TOAST_MESSAGE import com.thanksmister.iot.wallpanel.persistence.Configuration @@ -95,6 +97,9 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() { Timber.d("Browser page reloading.") stopDisconnectTimer() reload() + } else if (BROADCAST_ACTION_OPEN_SETTINGS == intent.action) { + Timber.d("Browser open settings.") + openSettings() } else if (BROADCAST_TOAST_MESSAGE == intent.action && !isFinishing) { val message = intent.getStringExtra(BROADCAST_TOAST_MESSAGE) stopDisconnectTimer() @@ -111,6 +116,12 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() { resetScreenBrightness(false) } else if (BROADCAST_SCREEN_WAKE == intent.action && !isFinishing) { stopDisconnectTimer() + } else if (BROADCAST_SCREEN_WAKE_ON == intent.action && !isFinishing) { + userPresent = true + resetScreenBrightness(false) + clearInactivityTimer() + } else if (BROADCAST_SCREEN_WAKE_OFF == intent.action && !isFinishing) { + resetInactivityTimer() } else if (BROADCAST_ACTION_RELOAD_PAGE == intent.action && !isFinishing) { hideScreenSaver() } else if (BROADCAST_SERVICE_STARTED == intent.action && !isFinishing) { @@ -147,11 +158,14 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() { filter.addAction(BROADCAST_ACTION_JS_EXEC) filter.addAction(BROADCAST_ACTION_CLEAR_BROWSER_CACHE) filter.addAction(BROADCAST_ACTION_RELOAD_PAGE) + filter.addAction(BROADCAST_ACTION_OPEN_SETTINGS) filter.addAction(BROADCAST_SCREEN_BRIGHTNESS_CHANGE) filter.addAction(BROADCAST_CLEAR_ALERT_MESSAGE) filter.addAction(BROADCAST_ALERT_MESSAGE) filter.addAction(BROADCAST_TOAST_MESSAGE) filter.addAction(BROADCAST_SCREEN_WAKE) + filter.addAction(BROADCAST_SCREEN_WAKE_ON) + filter.addAction(BROADCAST_SCREEN_WAKE_OFF) filter.addAction(BROADCAST_SERVICE_STARTED) val bm = LocalBroadcastManager.getInstance(this) bm.registerReceiver(mBroadcastReceiver, filter) @@ -278,9 +292,14 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() { inactivityHandler.postDelayed(inactivityCallback, configuration.inactivityTime) } + private fun clearInactivityTimer() { + hideScreenSaver() + inactivityHandler.removeCallbacks(inactivityCallback) + } + fun stopDisconnectTimer() { Timber.d("stopDisconnectTimer") - if (!userPresent) { + if (userPresent.not()) { userPresent = true resetScreenBrightness(false) } @@ -330,11 +349,13 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() { protected abstract fun clearCache() protected abstract fun reload() protected abstract fun complete() + protected abstract fun openSettings() companion object { const val BROADCAST_ACTION_LOAD_URL = "BROADCAST_ACTION_LOAD_URL" const val BROADCAST_ACTION_JS_EXEC = "BROADCAST_ACTION_JS_EXEC" const val BROADCAST_ACTION_CLEAR_BROWSER_CACHE = "BROADCAST_ACTION_CLEAR_BROWSER_CACHE" const val BROADCAST_ACTION_RELOAD_PAGE = "BROADCAST_ACTION_RELOAD_PAGE" + const val BROADCAST_ACTION_OPEN_SETTINGS = "BROADCAST_ACTION_OPEN_SETTINGS" } } \ No newline at end of file diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivityNative.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivityNative.kt index 7919234..b1ff19c 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivityNative.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivityNative.kt @@ -18,6 +18,7 @@ package com.thanksmister.iot.wallpanel.ui.activities import android.annotation.SuppressLint import android.content.DialogInterface +import android.content.Intent import android.net.http.SslError import android.os.Build import android.os.Bundle @@ -31,6 +32,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.content.ContextCompat import com.google.android.material.snackbar.Snackbar import com.thanksmister.iot.wallpanel.R +import com.thanksmister.iot.wallpanel.network.WallPanelService import com.thanksmister.iot.wallpanel.ui.fragments.CodeBottomSheetFragment import com.thanksmister.iot.wallpanel.utils.BrowserUtils import kotlinx.android.synthetic.main.activity_browser.* @@ -85,8 +87,7 @@ class BrowserActivityNative : BaseBrowserActivity() { launchSettingsFab.setOnClickListener { if (configuration.isFirstTime) { - val intent = SettingsActivity.createStartIntent(this) - startActivity(intent) + openSettings() } else { showCodeBottomSheet() } @@ -241,6 +242,15 @@ class BrowserActivityNative : BaseBrowserActivity() { } } + override fun openSettings() { + hideScreenSaver() + // Stop our service for performance reasons and to pick up changes + val wallPanelService = Intent(this, WallPanelService::class.java) + stopService(wallPanelService) + val intent = SettingsActivity.createStartIntent(this) + startActivity(intent) + } + @SuppressLint("SetJavaScriptEnabled") override fun configureWebSettings(userAgent: String) { if(webSettings == null) { @@ -317,8 +327,7 @@ class BrowserActivityNative : BaseBrowserActivity() { object : CodeBottomSheetFragment.OnAlarmCodeFragmentListener { override fun onComplete(code: String) { codeBottomSheet?.dismiss() - val intent = SettingsActivity.createStartIntent(this@BrowserActivityNative) - startActivity(intent) + openSettings() } override fun onCodeError() { @@ -354,22 +363,29 @@ class BrowserActivityNative : BaseBrowserActivity() { } } launchSettingsFab.layoutParams = params - if (configuration.settingsTransparent) { - launchSettingsFab.backgroundTintList = ContextCompat.getColorStateList(this, R.color.transparent) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - launchSettingsFab.compatElevation = 0f + when { + configuration.settingsDisabled -> { + launchSettingsFab.visibility = View.GONE } - launchSettingsFab.imageAlpha = 0 - } else { - launchSettingsFab.backgroundTintList = ContextCompat.getColorStateList(this, R.color.colorAccent) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - launchSettingsFab.compatElevation = 4f + configuration.settingsTransparent -> { + launchSettingsFab.visibility = View.VISIBLE + launchSettingsFab.backgroundTintList = ContextCompat.getColorStateList(this, R.color.transparent) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + launchSettingsFab.compatElevation = 0f + } + launchSettingsFab.imageAlpha = 0 + } + else -> { + launchSettingsFab.visibility = View.VISIBLE + launchSettingsFab.backgroundTintList = ContextCompat.getColorStateList(this, R.color.colorAccent) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + launchSettingsFab.compatElevation = 4f + } + launchSettingsFab.imageAlpha = 180 } - launchSettingsFab.imageAlpha = 180 } } - /*private fun hideNavigationBar() { try { val process = Runtime.getRuntime().exec("su") diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/LiveCameraActivity.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/LiveCameraActivity.kt index f04537c..ddd7451 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/LiveCameraActivity.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/LiveCameraActivity.kt @@ -166,7 +166,9 @@ class LiveCameraActivity : DaggerAppCompatActivity() { private val cameraCallback = object : CameraCallback { override fun onDetectorError() { - Toast.makeText(this@LiveCameraActivity,getString(R.string.error_missing_vision_lib), Toast.LENGTH_LONG).show() + if(configuration.cameraFaceEnabled || configuration.cameraQRCodeEnabled) { + Toast.makeText(this@LiveCameraActivity,getString(R.string.error_missing_vision_lib), Toast.LENGTH_LONG).show() + } } override fun onCameraError() { Toast.makeText(this@LiveCameraActivity, getString(R.string.toast_camera_source_error), Toast.LENGTH_LONG).show() diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/SettingsActivity.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/SettingsActivity.kt index 65932bc..f5776ae 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/SettingsActivity.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/SettingsActivity.kt @@ -48,10 +48,6 @@ class SettingsActivity : DaggerAppCompatActivity() { setContentView(R.layout.activity_settings) - // Stop our service for performance reasons and to pick up changes - val wallPanelService = Intent(this, WallPanelService::class.java) - stopService(wallPanelService) - supportActionBar?.show() supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) @@ -60,11 +56,6 @@ class SettingsActivity : DaggerAppCompatActivity() { lifecycle.addObserver(dialogUtils) } - public override fun onResume() { - super.onResume() - - } - override fun onOptionsItemSelected(item: MenuItem): Boolean { val id = item.itemId if (id == android.R.id.home) { @@ -76,7 +67,6 @@ class SettingsActivity : DaggerAppCompatActivity() { companion object { const val PERMISSIONS_REQUEST_WRITE_SETTINGS = 200 - fun createStartIntent(context: Context): Intent { return Intent(context, SettingsActivity::class.java) } diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/SettingsFragment.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/SettingsFragment.kt index 53b687a..e6758a1 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/SettingsFragment.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/SettingsFragment.kt @@ -89,6 +89,10 @@ class SettingsFragment : BaseSettingsFragment() { findPreference(PREF_SETTINGS_BUTTON_TRANSPARENT) as SwitchPreference } + private val settingsDisablePreference: SwitchPreference by lazy { + findPreference(PREF_SETTINGS_BUTTON_DISABLE) as SwitchPreference + } + private val settingsLocationPreference: ListPreference by lazy { findPreference(PREF_SETTINGS_BUTTON_LOCATION) as ListPreference } @@ -175,6 +179,7 @@ class SettingsFragment : BaseSettingsFragment() { fullScreenPreference.isChecked = configuration.fullScreen settingsTransparentPreference.isChecked = configuration.settingsTransparent + settingsDisablePreference.isChecked = configuration.settingsDisabled useDarkThemeSettings.isChecked = configuration.useDarkTheme userAgentPreference.text = configuration.browserUserAgent dashboardPreference?.text = configuration.appLaunchUrl @@ -308,12 +313,17 @@ class SettingsFragment : BaseSettingsFragment() { PREF_SETTINGS_BUTTON_TRANSPARENT -> { configuration.settingsTransparent = settingsTransparentPreference.isChecked } + PREF_SETTINGS_BUTTON_DISABLE -> { + configuration.settingsDisabled = settingsDisablePreference.isChecked + } PREF_SETTINGS_THEME -> { configuration.useDarkTheme = useDarkThemeSettings.isChecked if (configuration.useDarkTheme) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) + requireActivity().recreate() } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) + requireActivity().recreate() } } PREF_SETTINGS_BUTTON_LOCATION -> { @@ -444,6 +454,7 @@ class SettingsFragment : BaseSettingsFragment() { const val PREF_SCREEN_INACTIVITY_TIME = "pref_screensaver_inactivity_time" const val PREF_SETTINGS_FULL_SCREEN = "pref_settings_fullscreen" const val PREF_SETTINGS_BUTTON_TRANSPARENT = "pref_settings_button_transparent" + const val PREF_SETTINGS_BUTTON_DISABLE = "pref_settings_button_disable" const val PREF_SETTINGS_BUTTON_LOCATION = "pref_settings_button_location" const val PREF_SETTINGS_THEME = "pref_settings_theme" const val PREF_SETTINGS_DASHBOARD_URL = "pref_settings_dashboard_url" diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/MqttUtils.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/MqttUtils.kt index 789412a..935b923 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/MqttUtils.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/MqttUtils.kt @@ -48,6 +48,7 @@ class MqttUtils { const val COMMAND_SENSOR = "sensor/" const val COMMAND_URL = "url" const val COMMAND_CAMERA = "camera" + const val COMMAND_SETTINGS = "settings" const val COMMAND_RELAUNCH = "relaunch" const val COMMAND_WAKE = "wake" const val COMMAND_WAKETIME = "wakeTime" diff --git a/WallPanelApp/src/main/res/drawable/ic_baseline_lock.xml b/WallPanelApp/src/main/res/drawable/ic_baseline_lock.xml new file mode 100644 index 0000000..d619102 --- /dev/null +++ b/WallPanelApp/src/main/res/drawable/ic_baseline_lock.xml @@ -0,0 +1,10 @@ + + + diff --git a/WallPanelApp/src/main/res/xml/pref_general.xml b/WallPanelApp/src/main/res/xml/pref_general.xml index cac2798..d2d59a2 100644 --- a/WallPanelApp/src/main/res/xml/pref_general.xml +++ b/WallPanelApp/src/main/res/xml/pref_general.xml @@ -21,6 +21,7 @@ @@ -28,7 +29,7 @@ android:key="button_alarm_code" android:negativeButtonText="@android:string/cancel" android:positiveButtonText="@android:string/ok" - android:icon="@drawable/ic_baseline_lock_open" + android:icon="@drawable/ic_baseline_lock" android:summary="@string/preference_summary_security_code" android:title="@string/preference_title_security_code" /> @@ -87,10 +88,25 @@ android:summary="Show the dashboard screen in fullscreen mode." android:key="pref_settings_fullscreen"/> + + + + + + + + - - diff --git a/build.gradle b/build.gradle index 92a6eae..f0f5a5c 100644 --- a/build.gradle +++ b/build.gradle @@ -17,19 +17,18 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.4.32' repositories { google() jcenter() maven { url "https://repo.eclipse.org/content/repositories/paho-snapshots/" } - maven { url 'https://maven.fabric.io/public' } mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.2' + 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.firebase:firebase-crashlytics-gradle:2.4.1' + classpath 'com.google.gms:google-services:4.3.8' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.6.1' } } @@ -50,12 +49,12 @@ ext.deps = [:] def versions = [:] versions.lifecycle = "2.1.0" versions.support = "28.0.0" -versions.kotlin = "1.2.20" +versions.kotlin = "1.4.32" versions.navigation = "1.0.0" versions.constraint_layout = "1.1.0" versions.retrofit = "2.2.0" versions.stetho = "1.3.1" -versions.dagger = "2.16" +versions.dagger = "2.35.1" versions.archVersion = '1.1.1' versions.archRoomVersion = '1.1.0' ext.versions = versions \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a2bb1fe..cca6954 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri May 03 10:01:01 ART 2019 +#Wed May 19 11:27:42 ART 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip