Skip to content

Commit

Permalink
* wake screen time command
Browse files Browse the repository at this point in the history
* audio permissions for web pages
* new web page screensaver
  • Loading branch information
thanksmister committed Jun 10, 2021
1 parent 6fbf0eb commit 1f5ab8e
Show file tree
Hide file tree
Showing 18 changed files with 372 additions and 59 deletions.
6 changes: 3 additions & 3 deletions WallPanelApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ apply plugin: 'com.google.firebase.crashlytics'

def versionMajor = 0
def versionMinor = 9
def versionPatch = 4
def versionBuild = 9 // bump for dog food builds, public betas, etc.
def versionPatch = 5
def versionBuild = 3 // bump for dog food builds, public betas, etc.

def CODE() {
Properties properties = new Properties()
Expand Down Expand Up @@ -181,7 +181,7 @@ dependencies {

// Firebase
implementation 'com.google.firebase:firebase-core:19.0.0'
implementation 'com.google.firebase:firebase-crashlytics:18.0.0'
implementation 'com.google.firebase:firebase-crashlytics:18.0.1'
implementation 'com.google.firebase:firebase-analytics:19.0.0'

// Picasso image loading
Expand Down
16 changes: 10 additions & 6 deletions WallPanelApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />

<!-- Features supported -->
<uses-feature android:name="android.hardware.audio.low_latency" />
<uses-feature android:name="android.hardware.audio.pro" />
<uses-feature android:name="android.hardware.microphone" />

<!-- Optional supported features -->
<uses-feature
android:name="android.hardware.audio.low_latency"
android:required="false" />
<uses-feature
android:name="android.hardware.audio.pro"
android:required="false" />
<uses-feature
android:name="android.hardware.microphone"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
Expand Down Expand Up @@ -73,7 +78,6 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:enabled="true"
android:exported="true"
android:hardwareAccelerated="true"
android:label="@string/app_name"
android:theme="@style/AppThemeFullScreen">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,33 @@ constructor(private val context: Context, private val sharedPreferences: SharedP
get() = sharedPreferences.getInt(PREF_IMAGE_ROTATION, ROTATE_TIME_IN_MINUTES)
set(value) = this.sharedPreferences.edit().putInt(PREF_IMAGE_ROTATION, value).apply()

val hasBlankScreenSaver: Boolean
var hasBlankScreenSaver: Boolean
get() = getBoolPref(R.string.key_screensaver_blank, R.string.default_screensaver_blank)
set(value) =
sharedPreferences.edit().putBoolean(context.getString(R.string.key_screensaver_blank), value).apply()

val hasDimScreenSaver: Boolean
get() = getBoolPref(R.string.key_screensaver_dim, R.string.default_screensaver_dim);
var hasDimScreenSaver: Boolean
get() = getBoolPref(R.string.key_screensaver_dim, R.string.default_screensaver_dim)
set(value) =
sharedPreferences.edit().putBoolean(context.getString(R.string.key_screensaver_dim), value).apply()

var hasClockScreenSaver: Boolean
get() = getBoolPref(R.string.key_screensaver, R.string.default_screensaver)
set(value) =
sharedPreferences.edit().putBoolean(context.getString(R.string.key_screensaver), value).apply()

val hasScreenSaverWallpaper: Boolean
var hasScreenSaverWallpaper: Boolean
get() = getBoolPref(R.string.key_screensaver_wallpaper, R.string.default_screensaver_wallpaper)
set(value) =
sharedPreferences.edit().putBoolean(context.getString(R.string.key_screensaver_wallpaper), value).apply()

var webScreenSaver: Boolean
get() = this.sharedPreferences.getBoolean(PREF_WEB_SCREENSAVER, false)
set(value) = this.sharedPreferences.edit().putBoolean(PREF_WEB_SCREENSAVER, value).apply()

var webScreenSaverUrl: String
get() = sharedPreferences.getString(PREF_WEB_SCREENSAVER_URL, WEB_SCREEN_SAVER).orEmpty()
set(value) = this.sharedPreferences.edit().putString(PREF_WEB_SCREENSAVER_URL, value).apply()

var screenBrightness: Int
get() = sharedPreferences.getInt(context.getString(R.string.key_setting_screen_brightness), 150)
Expand Down Expand Up @@ -372,5 +386,8 @@ constructor(private val context: Context, private val sharedPreferences: SharedP
const val PREF_IMAGE_ROTATION = "pref_image_rotation"
private val PREF_CAMERA_FACE_SIZE = "pref_camera_face_size"
private val PREF_CAMERA_MOTION_LATENCY = "pref_camera_motion_latency"
private val PREF_WEB_SCREENSAVER_URL = "pref_web_screensaver_url"
private val PREF_WEB_SCREENSAVER = "pref_web_screensaver"
const val WEB_SCREEN_SAVER = "https://thanksmister.com/mqtt_alarm_panel/gif_background.html"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() {
lateinit var screenUtils: ScreenUtils

var mOnScrollChangedListener: ViewTreeObserver.OnScrollChangedListener? = null
private var wallPanelService: Intent? = null
var wallPanelService: Intent? = null
private var decorView: View? = null
private val inactivityHandler: Handler = Handler()
private var userPresent: Boolean = false
private var hasWakeScreen = false
var displayProgress = true
var zoomLevel = 1.0f

Expand Down Expand Up @@ -116,16 +117,19 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() {
}
} else if (BROADCAST_CLEAR_ALERT_MESSAGE == intent.action && !isFinishing) {
dialogUtils.clearDialogs()
resetInactivityTimer()
resetScreenBrightness(false)
if (hasWakeScreen.not()) {
resetInactivityTimer()
resetScreenBrightness(false)
}
} else if (BROADCAST_SCREEN_WAKE == intent.action && !isFinishing) {
stopDisconnectTimer()
} else if (BROADCAST_SCREEN_WAKE_ON == intent.action && !isFinishing) {
userPresent = true
hasWakeScreen = true
resetScreenBrightness(false)
clearInactivityTimer()
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else if (BROADCAST_SCREEN_WAKE_OFF == intent.action && !isFinishing) {
hasWakeScreen = false
resetInactivityTimer()
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} else if (BROADCAST_ACTION_RELOAD_PAGE == intent.action && !isFinishing) {
Expand Down Expand Up @@ -223,7 +227,9 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() {
val bm = LocalBroadcastManager.getInstance(applicationContext)
bm.sendBroadcast(intent)
}
resetInactivityTimer()
if (hasWakeScreen.not()) {
resetInactivityTimer()
}
}

fun setDarkTheme() {
Expand Down Expand Up @@ -309,7 +315,9 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() {
userPresent = true
resetScreenBrightness(false)
}
resetInactivityTimer()
if (hasWakeScreen.not()) {
resetInactivityTimer()
}
}

open fun hideScreenSaver() {
Expand All @@ -326,21 +334,27 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() {
* with the alarm disabled because the disable time will be longer than this.
*/
open fun showScreenSaver() {
if ((configuration.hasBlankScreenSaver || configuration.hasClockScreenSaver || configuration.hasScreenSaverWallpaper || configuration.hasDimScreenSaver) && !isFinishing) {
if (configuration.hasDimScreenSaver) {
inactivityHandler.removeCallbacks(inactivityCallback)
if (!configuration.hasDimScreenSaver) {
try {
dialogUtils.showScreenSaver(this@BaseBrowserActivity,
View.OnClickListener {
dialogUtils.hideScreenSaverDialog()
resetScreenBrightness(false)
resetInactivityTimer()
},
configuration.hasScreenSaverWallpaper, configuration.hasClockScreenSaver, configuration.imageRotation.toLong(), configuration.appPreventSleep)
} catch (e: Exception) {
Timber.e(e.message)
}
}
resetScreenBrightness(true)
} else if ((configuration.hasClockScreenSaver
|| configuration.webScreenSaver
|| configuration.hasScreenSaverWallpaper
|| configuration.hasDimScreenSaver)
&& !isFinishing) {
inactivityHandler.removeCallbacks(inactivityCallback)
dialogUtils.showScreenSaver(this@BaseBrowserActivity,
{
dialogUtils.hideScreenSaverDialog()
resetScreenBrightness(false)
resetInactivityTimer()
},
configuration.webScreenSaver,
configuration.webScreenSaverUrl,
configuration.hasScreenSaverWallpaper,
configuration.hasClockScreenSaver,
configuration.imageRotation.toLong(),
configuration.appPreventSleep)
resetScreenBrightness(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import com.google.android.material.snackbar.Snackbar
import com.thanksmister.iot.wallpanel.BuildConfig
import com.thanksmister.iot.wallpanel.R
import com.thanksmister.iot.wallpanel.network.ConnectionLiveData
import com.thanksmister.iot.wallpanel.network.WallPanelService
import com.thanksmister.iot.wallpanel.ui.fragments.CodeBottomSheetFragment
import kotlinx.android.synthetic.main.activity_browser.*
import timber.log.Timber
Expand Down Expand Up @@ -301,7 +300,6 @@ class BrowserActivityNative : BaseBrowserActivity(), LifecycleObserver {
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)
Expand All @@ -326,6 +324,8 @@ class BrowserActivityNative : BaseBrowserActivity(), LifecycleObserver {
webSettings?.loadWithOverviewMode = true
webSettings?.useWideViewPort = true
webSettings?.pluginState = WebSettings.PluginState.ON
webSettings?.setRenderPriority(WebSettings.RenderPriority.HIGH);
// webSettings?.cacheMode = WebSettings.LOAD_NO_CACHE;

if (userAgent.isNotEmpty()) {
webSettings?.userAgentString = userAgent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ class SettingsFragment : BaseSettingsFragment() {
findPreference<EditTextPreference>(PREF_SETTINGS_USER_AGENT) as EditTextPreference
}

private val dimScreensaver: SwitchPreference by lazy {
findPreference<SwitchPreference>(PREF_SETTINGS_SCREENSAVER_DIM) as SwitchPreference
}

/*private val blankScreensaver: SwitchPreference by lazy {
findPreference<SwitchPreference>(PREF_SETTINGS_SCREENSAVER_BLANK) as SwitchPreference
}*/

private val webScreenSaver: SwitchPreference by lazy {
findPreference<SwitchPreference>(PREF_SETTINGS_WEB_SCREENSAVER) as SwitchPreference
}

private val webScreenSaverUrl: EditTextPreference by lazy {
findPreference<EditTextPreference>(PREF_SETTINGS_WEB_SCREENSAVER_URL) as EditTextPreference
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
Expand Down Expand Up @@ -183,6 +199,7 @@ class SettingsFragment : BaseSettingsFragment() {
useDarkThemeSettings.isChecked = configuration.useDarkTheme
userAgentPreference.text = configuration.browserUserAgent
dashboardPreference?.text = configuration.appLaunchUrl

if(configuration.appLaunchUrl.isNotEmpty()) {
dashboardPreference?.summary = configuration.appLaunchUrl
}
Expand Down Expand Up @@ -233,6 +250,15 @@ class SettingsFragment : BaseSettingsFragment() {
rotationPreference?.summary = getString(R.string.preference_summary_image_rotation, configuration.imageRotation.toString())
rotationPreference?.setDefaultValue(configuration.imageRotation.toString())

// Setup additional screensaver options
webScreenSaver.isChecked = configuration.webScreenSaver
dimScreensaver.isChecked = configuration.hasDimScreenSaver
//blankScreensaver.isChecked = configuration.hasBlankScreenSaver
val webScreensaverUrlValue = configuration.webScreenSaverUrl
if(webScreensaverUrlValue.isNotEmpty()) {
webScreenSaverUrl.text = webScreensaverUrlValue
}

try {
cameraPreference?.onPreferenceClickListener = Preference.OnPreferenceClickListener { preference ->
view.let { Navigation.findNavController(it).navigate(R.id.camera_action) }
Expand Down Expand Up @@ -347,6 +373,25 @@ class SettingsFragment : BaseSettingsFragment() {
userAgentPreference.summary = value
}
}
PREF_SETTINGS_WEB_SCREENSAVER_URL -> {
val value = webScreenSaverUrl.text.orEmpty()
if (value.isNotEmpty()) {
configuration.webScreenSaverUrl = value
webScreenSaverUrl.summary = value
}
}
PREF_SETTINGS_WEB_SCREENSAVER -> {
val value = webScreenSaver.isChecked
configuration.webScreenSaver = value
}
PREF_SETTINGS_SCREENSAVER_DIM -> {
val value = dimScreensaver.isChecked
configuration.hasDimScreenSaver = value
}
/*PREF_SETTINGS_SCREENSAVER_BLANK -> {
val value = blankScreensaver.isChecked
configuration.hasBlankScreenSaver = value
}*/
"pref_settings_image_rotation" -> {
rotationPreference?.text?.let {
val rotation = it.toIntOrNull()
Expand All @@ -361,6 +406,22 @@ class SettingsFragment : BaseSettingsFragment() {
}
}

/* private fun setDimScreensaver(value: Boolean) {
webScreenSaver.isChecked = value
configuration.webScreenSaver = value
if(value) {
configuration.hasClockScreenSaver = false
configuration.hasBlankScreenSaver = false
configuration.hasScreenSaverWallpaper = false
configuration.hasDimScreenSaver = false
clockSaverPreference?.isChecked = false
wallpaperSaverPreference?.isChecked = false
dimScreensaver.isChecked = false
blankScreensaver.isChecked = false
}
}
*/

private fun checkWriteSettings() {
if (!configuration.writeScreenPermissionsShown && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Settings.System.canWrite(requireActivity().applicationContext)) {
Expand Down Expand Up @@ -459,5 +520,9 @@ class SettingsFragment : BaseSettingsFragment() {
const val PREF_SETTINGS_THEME = "pref_settings_theme"
const val PREF_SETTINGS_DASHBOARD_URL = "pref_settings_dashboard_url"
const val PREF_SETTINGS_USER_AGENT = "pref_settings_user_agent"
const val PREF_SETTINGS_SCREENSAVER_DIM = "settings_screensaver_dim"
const val PREF_SETTINGS_SCREENSAVER_BLANK = "settings_screensaver_blank"
const val PREF_SETTINGS_WEB_SCREENSAVER = "settings_screensaver_web"
const val PREF_SETTINGS_WEB_SCREENSAVER_URL = "settings_screensaver_web_url"
}
}
Loading

0 comments on commit 1f5ab8e

Please sign in to comment.