From 1f5ab8e19fd35d43fd6ec4fb83361656c236714b Mon Sep 17 00:00:00 2001 From: Michael Ritchie Date: Thu, 10 Jun 2021 09:45:42 -0300 Subject: [PATCH] * wake screen time command * audio permissions for web pages * new web page screensaver --- WallPanelApp/build.gradle | 6 +- WallPanelApp/src/main/AndroidManifest.xml | 16 ++- .../wallpanel/persistence/Configuration.kt | 25 +++- .../ui/activities/BaseBrowserActivity.kt | 54 ++++--- .../ui/activities/BrowserActivityNative.kt | 4 +- .../ui/fragments/SettingsFragment.kt | 65 +++++++++ .../iot/wallpanel/ui/views/ScreenSaverView.kt | 133 ++++++++++++++++-- .../iot/wallpanel/utils/DialogUtils.kt | 4 +- .../res/layout-land/dialog_screen_saver.xml | 14 ++ .../dialog_screen_saver.xml | 14 ++ .../layout-sw600dp/dialog_screen_saver.xml | 14 ++ .../dialog_screen_saver.xml | 14 ++ .../layout-sw720dp/dialog_screen_saver.xml | 14 ++ .../main/res/layout/dialog_screen_saver.xml | 14 ++ .../src/main/res/values/donottranslate.xml | 2 +- WallPanelApp/src/main/res/values/strings.xml | 4 + .../src/main/res/xml/pref_general.xml | 32 +++-- build.gradle | 2 +- 18 files changed, 372 insertions(+), 59 deletions(-) diff --git a/WallPanelApp/build.gradle b/WallPanelApp/build.gradle index a9a915a..33ccde6 100644 --- a/WallPanelApp/build.gradle +++ b/WallPanelApp/build.gradle @@ -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() @@ -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 diff --git a/WallPanelApp/src/main/AndroidManifest.xml b/WallPanelApp/src/main/AndroidManifest.xml index 2a31f27..fa13326 100644 --- a/WallPanelApp/src/main/AndroidManifest.xml +++ b/WallPanelApp/src/main/AndroidManifest.xml @@ -40,11 +40,16 @@ android:name="android.permission.WRITE_SETTINGS" tools:ignore="ProtectedPermissions" /> - - - - - + + + + @@ -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"> 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 f9749c8..39b7bf1 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 @@ -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) @@ -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" } } 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 bd5e644..8b24433 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 @@ -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 @@ -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) { @@ -223,7 +227,9 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() { val bm = LocalBroadcastManager.getInstance(applicationContext) bm.sendBroadcast(intent) } - resetInactivityTimer() + if (hasWakeScreen.not()) { + resetInactivityTimer() + } } fun setDarkTheme() { @@ -309,7 +315,9 @@ abstract class BaseBrowserActivity : DaggerAppCompatActivity() { userPresent = true resetScreenBrightness(false) } - resetInactivityTimer() + if (hasWakeScreen.not()) { + resetInactivityTimer() + } } open fun hideScreenSaver() { @@ -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) } } 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 04c5914..e8d6aae 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 @@ -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 @@ -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) @@ -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 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 e6758a1..b10a966 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 @@ -113,6 +113,22 @@ class SettingsFragment : BaseSettingsFragment() { findPreference(PREF_SETTINGS_USER_AGENT) as EditTextPreference } + private val dimScreensaver: SwitchPreference by lazy { + findPreference(PREF_SETTINGS_SCREENSAVER_DIM) as SwitchPreference + } + + /*private val blankScreensaver: SwitchPreference by lazy { + findPreference(PREF_SETTINGS_SCREENSAVER_BLANK) as SwitchPreference + }*/ + + private val webScreenSaver: SwitchPreference by lazy { + findPreference(PREF_SETTINGS_WEB_SCREENSAVER) as SwitchPreference + } + + private val webScreenSaverUrl: EditTextPreference by lazy { + findPreference(PREF_SETTINGS_WEB_SCREENSAVER_URL) as EditTextPreference + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setHasOptionsMenu(true) @@ -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 } @@ -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) } @@ -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() @@ -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)) { @@ -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" } } diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/views/ScreenSaverView.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/views/ScreenSaverView.kt index fd1d287..cbf9e00 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/views/ScreenSaverView.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/views/ScreenSaverView.kt @@ -16,20 +16,30 @@ package com.thanksmister.iot.wallpanel.ui.views +import android.annotation.SuppressLint import android.content.Context +import android.content.DialogInterface import android.content.res.Configuration +import android.net.http.SslError +import android.os.Build import android.os.Handler +import android.text.TextUtils import android.text.format.DateUtils import android.util.AttributeSet import android.util.TypedValue +import android.view.MotionEvent import android.view.View +import android.webkit.* import android.widget.RelativeLayout +import android.widget.Toast +import androidx.appcompat.app.AlertDialog import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy import com.squareup.picasso.MemoryPolicy import com.squareup.picasso.NetworkPolicy import com.squareup.picasso.Picasso import com.thanksmister.iot.wallpanel.R +import com.thanksmister.iot.wallpanel.persistence.Configuration.Companion.WEB_SCREEN_SAVER import kotlinx.android.synthetic.main.dialog_screen_saver.view.* import timber.log.Timber import java.util.* @@ -42,9 +52,12 @@ class ScreenSaverView : RelativeLayout { private var saverContext: Context? = null private var parentWidth: Int = 0 private var parentHeight: Int = 0 + private var showWebPage: Boolean = false private var showWallpaper: Boolean = false private var showClock: Boolean = false private var rotationInterval = 900L + private var webUrl = WEB_SCREEN_SAVER + private var certPermissionsShown = false val calendar: Calendar = Calendar.getInstance() @@ -104,22 +117,29 @@ class ScreenSaverView : RelativeLayout { wallPaperHandler?.removeCallbacks(wallPaperRunnable) } - fun init(hasWallpaper: Boolean, hasClock: Boolean, rotationInterval: Long) { + fun init(hasWeb: Boolean, urlWeb: String, hasWallpaper: Boolean, hasClock: Boolean, rotationInterval: Long) { this.rotationInterval = rotationInterval + showWebPage = hasWeb + webUrl = urlWeb showWallpaper = hasWallpaper showClock = hasClock + if(showClock) { setClockViews() timeHandler = Handler() timeHandler?.postDelayed(timeRunnable, 10) - } else { - screenSaverClockLayout.visibility = View.INVISIBLE - } - if (showWallpaper) { + screenSaverImageLayout.visibility = View.INVISIBLE + screenSaverWebViewLayout.visibility = View.GONE + } else if (showWallpaper) { wallPaperHandler = Handler() wallPaperHandler?.postDelayed(wallPaperRunnable, 10) - } else { + screenSaverClockLayout.visibility = View.INVISIBLE + screenSaverWebViewLayout.visibility = View.GONE + } else if (showWebPage) { + screenSaverClockLayout.visibility = View.INVISIBLE screenSaverImageLayout.visibility = View.INVISIBLE + screenSaverWebViewLayout.visibility = View.VISIBLE + startWebScreenSaver(webUrl) } } @@ -136,12 +156,103 @@ class ScreenSaverView : RelativeLayout { .centerCrop() .skipMemoryCache(true) .into(screenSaverImageLayout); + } - /* Picasso.get() - .load(String.format(UNSPLASH_IT_URL, screenSaverView.width, screenSaverView.height)) - .memoryPolicy(MemoryPolicy.NO_CACHE) - .networkPolicy(NetworkPolicy.NO_CACHE) - .into(screenSaverImageLayout)*/ + private fun closeView() { + this.callOnClick() + } + + private fun startWebScreenSaver(url: String) { + Timber.d("startWebScreenSaver $url") + loadWebPage(url) + } + + private fun loadWebPage(url: String) { + Timber.d("loadWebPage url ${url}") + configureWebSettings("") + clearCache() + screenSaverWebView?.webChromeClient = object : WebChromeClient() { + override fun onJsAlert(view: WebView, url: String, message: String, result: JsResult): Boolean { + AlertDialog.Builder(view.context, R.style.CustomAlertDialog) + .setTitle(context.getString(R.string.dialog_title_ssl_error)) + .setMessage(message) + .setPositiveButton(android.R.string.ok, null) + .show() + return true + } + } + screenSaverWebView?.setOnTouchListener(object : View.OnTouchListener { + override fun onTouch(v: View?, event: MotionEvent?): Boolean { + v?.performClick() + closeView() + return false + } + }) + screenSaverWebView?.webViewClient = object : WebViewClient() { + //If you will not use this method url links are open in new browser not in webview + override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { + view.loadUrl(url) + return true + } + + override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) { + Toast.makeText(context, description, Toast.LENGTH_SHORT).show() + } + + // TODO we need to load SSL certificates + override fun onReceivedSslError(view: WebView, handler: SslErrorHandler?, error: SslError?) { + if (!certPermissionsShown) { + var message = context.getString(R.string.dialog_message_ssl_generic) + when (error?.primaryError) { + SslError.SSL_UNTRUSTED -> message = context.getString(R.string.dialog_message_ssl_untrusted) + SslError.SSL_EXPIRED -> message = context.getString(R.string.dialog_message_ssl_expired) + SslError.SSL_IDMISMATCH -> message = context.getString(R.string.dialog_message_ssl_mismatch) + SslError.SSL_NOTYETVALID -> message = context.getString(R.string.dialog_message_ssl_not_yet_valid) + } + message += context.getString(R.string.dialog_message_ssl_continue) + AlertDialog.Builder(context, R.style.CustomAlertDialog) + .setTitle(context.getString(R.string.dialog_title_ssl_error)) + .setMessage(message) + .setPositiveButton(android.R.string.ok, DialogInterface.OnClickListener { _, _ -> + certPermissionsShown = true + handler?.proceed() + }) + .setNegativeButton(android.R.string.cancel, DialogInterface.OnClickListener { _, _ -> + certPermissionsShown = false + handler?.cancel() + }) + .show() + } else { + // we have already shown permissions, no need to show again on page refreshes or when page auto-refreshes itself + handler?.proceed() + } + } + } + screenSaverWebView?.loadUrl(url) + } + + @SuppressLint("SetJavaScriptEnabled") + private fun configureWebSettings(userAgent: String) { + val webSettings = screenSaverWebView?.settings + webSettings?.javaScriptEnabled = true + webSettings?.domStorageEnabled = true + webSettings?.databaseEnabled = true + webSettings?.setAppCacheEnabled(true) + webSettings?.javaScriptCanOpenWindowsAutomatically = true + if (!TextUtils.isEmpty(userAgent)) { + webSettings?.userAgentString = userAgent + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + webSettings?.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW + } + Timber.d(webSettings?.userAgentString) + } + + private fun clearCache() { + screenSaverWebView?.clearCache(true) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + CookieManager.getInstance().removeAllCookies(null) + } } companion object { diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/DialogUtils.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/DialogUtils.kt index 1a21b7d..e89c087 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/DialogUtils.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/DialogUtils.kt @@ -164,6 +164,8 @@ class DialogUtils(base: Context?) : ContextWrapper(base), LifecycleObserver { * with the alarm disabled because the disable time will be longer than this. */ fun showScreenSaver(activity: AppCompatActivity, onClickListener: View.OnClickListener, + hasWeb: Boolean, + webUrl: String, hasWallpaper: Boolean, hasClock: Boolean, rotationInterval: Long, @@ -176,7 +178,7 @@ class DialogUtils(base: Context?) : ContextWrapper(base), LifecycleObserver { val view = inflater.inflate(R.layout.dialog_screen_saver, null, false) val screenSaverView = view.findViewById(R.id.screenSaverView) screenSaverView.setOnClickListener(onClickListener) - screenSaverView.init(hasWallpaper, hasClock, rotationInterval) + screenSaverView.init(hasWeb, webUrl, hasWallpaper, hasClock, rotationInterval) screenSaverDialog = buildImmersiveDialog(activity, true, screenSaverView, true) if (screenSaverDialog != null && preventSleep) { screenSaverDialog?.window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) diff --git a/WallPanelApp/src/main/res/layout-land/dialog_screen_saver.xml b/WallPanelApp/src/main/res/layout-land/dialog_screen_saver.xml index ec0c43b..3817922 100644 --- a/WallPanelApp/src/main/res/layout-land/dialog_screen_saver.xml +++ b/WallPanelApp/src/main/res/layout-land/dialog_screen_saver.xml @@ -61,4 +61,18 @@ + + + + + + \ No newline at end of file diff --git a/WallPanelApp/src/main/res/layout-sw600dp-land/dialog_screen_saver.xml b/WallPanelApp/src/main/res/layout-sw600dp-land/dialog_screen_saver.xml index a01516e..a4ffec4 100644 --- a/WallPanelApp/src/main/res/layout-sw600dp-land/dialog_screen_saver.xml +++ b/WallPanelApp/src/main/res/layout-sw600dp-land/dialog_screen_saver.xml @@ -61,4 +61,18 @@ + + + + + + \ No newline at end of file diff --git a/WallPanelApp/src/main/res/layout-sw600dp/dialog_screen_saver.xml b/WallPanelApp/src/main/res/layout-sw600dp/dialog_screen_saver.xml index a01516e..a4ffec4 100644 --- a/WallPanelApp/src/main/res/layout-sw600dp/dialog_screen_saver.xml +++ b/WallPanelApp/src/main/res/layout-sw600dp/dialog_screen_saver.xml @@ -61,4 +61,18 @@ + + + + + + \ No newline at end of file diff --git a/WallPanelApp/src/main/res/layout-sw720dp-land/dialog_screen_saver.xml b/WallPanelApp/src/main/res/layout-sw720dp-land/dialog_screen_saver.xml index 11662a9..ee5ae87 100644 --- a/WallPanelApp/src/main/res/layout-sw720dp-land/dialog_screen_saver.xml +++ b/WallPanelApp/src/main/res/layout-sw720dp-land/dialog_screen_saver.xml @@ -62,4 +62,18 @@ + + + + + + \ No newline at end of file diff --git a/WallPanelApp/src/main/res/layout-sw720dp/dialog_screen_saver.xml b/WallPanelApp/src/main/res/layout-sw720dp/dialog_screen_saver.xml index 3991673..67e3820 100644 --- a/WallPanelApp/src/main/res/layout-sw720dp/dialog_screen_saver.xml +++ b/WallPanelApp/src/main/res/layout-sw720dp/dialog_screen_saver.xml @@ -61,4 +61,18 @@ + + + + + + \ No newline at end of file diff --git a/WallPanelApp/src/main/res/layout/dialog_screen_saver.xml b/WallPanelApp/src/main/res/layout/dialog_screen_saver.xml index 84a8ee2..03a05e9 100644 --- a/WallPanelApp/src/main/res/layout/dialog_screen_saver.xml +++ b/WallPanelApp/src/main/res/layout/dialog_screen_saver.xml @@ -46,4 +46,18 @@ + + + + + + \ No newline at end of file diff --git a/WallPanelApp/src/main/res/values/donottranslate.xml b/WallPanelApp/src/main/res/values/donottranslate.xml index fb1a30e..cd56ca9 100644 --- a/WallPanelApp/src/main/res/values/donottranslate.xml +++ b/WallPanelApp/src/main/res/values/donottranslate.xml @@ -141,7 +141,7 @@ settings_screensaver_blank false - settings_screensaver_dim + c false setting_screen_brightness diff --git a/WallPanelApp/src/main/res/values/strings.xml b/WallPanelApp/src/main/res/values/strings.xml index b8a85d9..790bb2e 100644 --- a/WallPanelApp/src/main/res/values/strings.xml +++ b/WallPanelApp/src/main/res/values/strings.xml @@ -293,6 +293,10 @@ Set the service password (if needed). Client Id Set the client Id if required by service. + Web Screensaver + Use a web page as a screensaver. + Web Screensaver Url + Enter the url to use as a web screensaver. diff --git a/WallPanelApp/src/main/res/xml/pref_general.xml b/WallPanelApp/src/main/res/xml/pref_general.xml index d2d59a2..7f7f234 100644 --- a/WallPanelApp/src/main/res/xml/pref_general.xml +++ b/WallPanelApp/src/main/res/xml/pref_general.xml @@ -138,22 +138,22 @@ android:summary="@string/pref_button_brightness_summary"/> + + - - + android:key="settings_screensaver_dim"/> + + + +