Added setting to use the app in fullscreen
This commit is contained in:
parent
253e2dc654
commit
c657156ee8
6 changed files with 81 additions and 0 deletions
|
@ -24,8 +24,14 @@ import android.content.pm.ActivityInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Surface
|
import android.view.Surface
|
||||||
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import java.util.*
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
import org.linphone.LinphoneApplication.Companion.ensureCoreExists
|
import org.linphone.LinphoneApplication.Companion.ensureCoreExists
|
||||||
|
@ -33,11 +39,14 @@ import org.linphone.R
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
|
|
||||||
abstract class GenericActivity : AppCompatActivity() {
|
abstract class GenericActivity : AppCompatActivity() {
|
||||||
|
private var timer: Timer? = null
|
||||||
|
|
||||||
@SuppressLint("SourceLockedOrientationActivity")
|
@SuppressLint("SourceLockedOrientationActivity")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
ensureCoreExists(applicationContext)
|
ensureCoreExists(applicationContext)
|
||||||
|
hideSystemUI()
|
||||||
|
|
||||||
if (corePreferences.forcePortrait) {
|
if (corePreferences.forcePortrait) {
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||||
|
@ -59,6 +68,28 @@ abstract class GenericActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.decorView.setOnSystemUiVisibilityChangeListener { visibility ->
|
||||||
|
if (visibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0) {
|
||||||
|
timer?.cancel()
|
||||||
|
|
||||||
|
timer = Timer("Hide Android top & bottom bars")
|
||||||
|
timer?.schedule(object : TimerTask() {
|
||||||
|
override fun run() {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
hideSystemUI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||||
|
super.onWindowFocusChanged(hasFocus)
|
||||||
|
if (hasFocus) hideSystemUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -83,4 +114,18 @@ abstract class GenericActivity : AppCompatActivity() {
|
||||||
fun isTablet(): Boolean {
|
fun isTablet(): Boolean {
|
||||||
return resources.getBoolean(R.bool.isTablet)
|
return resources.getBoolean(R.bool.isTablet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hideSystemUI() {
|
||||||
|
if (corePreferences.fullScreen) {
|
||||||
|
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
|
||||||
|
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
|
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showSystemUI() {
|
||||||
|
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
|
import org.linphone.activities.GenericActivity
|
||||||
import org.linphone.activities.main.settings.viewmodels.AdvancedSettingsViewModel
|
import org.linphone.activities.main.settings.viewmodels.AdvancedSettingsViewModel
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.core.tools.compatibility.DeviceUtils
|
import org.linphone.core.tools.compatibility.DeviceUtils
|
||||||
|
@ -75,6 +76,16 @@ class AdvancedSettingsFragment : Fragment() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
viewModel.fullScreenChangedEvent.observe(viewLifecycleOwner, {
|
||||||
|
it.consume { hideUI ->
|
||||||
|
if (hideUI) {
|
||||||
|
(activity as GenericActivity).hideSystemUI()
|
||||||
|
} else {
|
||||||
|
(activity as GenericActivity).showSystemUI()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
viewModel.backgroundModeEnabled.value = !DeviceUtils.isAppUserRestricted(requireContext())
|
viewModel.backgroundModeEnabled.value = !DeviceUtils.isAppUserRestricted(requireContext())
|
||||||
|
|
||||||
viewModel.goToBatterySettingsEvent.observe(viewLifecycleOwner, { it.consume {
|
viewModel.goToBatterySettingsEvent.observe(viewLifecycleOwner, { it.consume {
|
||||||
|
|
|
@ -68,6 +68,15 @@ class AdvancedSettingsViewModel : GenericSettingsViewModel() {
|
||||||
private val darkModeValues = arrayListOf(-1, 0, 1)
|
private val darkModeValues = arrayListOf(-1, 0, 1)
|
||||||
val setNightModeEvent = MutableLiveData<Event<Int>>()
|
val setNightModeEvent = MutableLiveData<Event<Int>>()
|
||||||
|
|
||||||
|
val fullScreenListener = object : SettingListenerStub() {
|
||||||
|
override fun onBoolValueChanged(newValue: Boolean) {
|
||||||
|
prefs.fullScreen = newValue
|
||||||
|
fullScreenChangedEvent.value = Event(newValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val fullScreen = MutableLiveData<Boolean>()
|
||||||
|
val fullScreenChangedEvent = MutableLiveData<Event<Boolean>>()
|
||||||
|
|
||||||
val deviceNameListener = object : SettingListenerStub() {
|
val deviceNameListener = object : SettingListenerStub() {
|
||||||
override fun onTextValueChanged(newValue: String) {
|
override fun onTextValueChanged(newValue: String) {
|
||||||
prefs.deviceName = newValue
|
prefs.deviceName = newValue
|
||||||
|
@ -128,6 +137,7 @@ class AdvancedSettingsViewModel : GenericSettingsViewModel() {
|
||||||
darkModeLabels.value = labels
|
darkModeLabels.value = labels
|
||||||
darkModeIndex.value = darkModeValues.indexOf(prefs.darkMode)
|
darkModeIndex.value = darkModeValues.indexOf(prefs.darkMode)
|
||||||
|
|
||||||
|
fullScreen.value = prefs.fullScreen
|
||||||
deviceName.value = prefs.deviceName
|
deviceName.value = prefs.deviceName
|
||||||
remoteProvisioningUrl.value = core.provisioningUri
|
remoteProvisioningUrl.value = core.provisioningUri
|
||||||
logsServerUrl.value = core.logCollectionUploadServerUrl
|
logsServerUrl.value = core.logCollectionUploadServerUrl
|
||||||
|
|
|
@ -62,6 +62,12 @@ class CorePreferences constructor(private val context: Context) {
|
||||||
config.setBool("app", "force_portrait_orientation", value)
|
config.setBool("app", "force_portrait_orientation", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fullScreen: Boolean
|
||||||
|
get() = config.getBool("app", "full_screen_activities", false)
|
||||||
|
set(value) {
|
||||||
|
config.setBool("app", "full_screen_activities", value)
|
||||||
|
}
|
||||||
|
|
||||||
/** -1 means auto, 0 no, 1 yes */
|
/** -1 means auto, 0 no, 1 yes */
|
||||||
var darkMode: Int
|
var darkMode: Int
|
||||||
get() {
|
get() {
|
||||||
|
|
|
@ -95,6 +95,13 @@
|
||||||
linphone:selectedIndex="@{viewModel.darkModeIndex}"
|
linphone:selectedIndex="@{viewModel.darkModeIndex}"
|
||||||
linphone:labels="@{viewModel.darkModeLabels}"/>
|
linphone:labels="@{viewModel.darkModeLabels}"/>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/settings_widget_switch"
|
||||||
|
linphone:title="@{@string/advanced_settings_full_screen_title}"
|
||||||
|
linphone:subtitle="@{@string/advanced_settings_full_screen_summary}"
|
||||||
|
linphone:listener="@{viewModel.fullScreenListener}"
|
||||||
|
linphone:checked="@={viewModel.fullScreen}"/>
|
||||||
|
|
||||||
<include
|
<include
|
||||||
layout="@layout/settings_widget_text"
|
layout="@layout/settings_widget_text"
|
||||||
linphone:title="@{@string/advanced_settings_device_name_title}"
|
linphone:title="@{@string/advanced_settings_device_name_title}"
|
||||||
|
|
|
@ -454,6 +454,8 @@
|
||||||
<string name="advanced_settings_dark_mode_label_auto">Auto</string>
|
<string name="advanced_settings_dark_mode_label_auto">Auto</string>
|
||||||
<string name="advanced_settings_dark_mode_label_no">No</string>
|
<string name="advanced_settings_dark_mode_label_no">No</string>
|
||||||
<string name="advanced_settings_dark_mode_label_yes">Yes</string>
|
<string name="advanced_settings_dark_mode_label_yes">Yes</string>
|
||||||
|
<string name="advanced_settings_full_screen_title">Full screen</string>
|
||||||
|
<string name="advanced_settings_full_screen_summary"></string>
|
||||||
<string name="advanced_settings_device_name_title">Device name</string>
|
<string name="advanced_settings_device_name_title">Device name</string>
|
||||||
<string name="advanced_settings_device_name_summary">Changes will be applied at next start up</string>
|
<string name="advanced_settings_device_name_summary">Changes will be applied at next start up</string>
|
||||||
<string name="advanced_settings_remote_provisioning_url_title">Remote provisioning URL</string>
|
<string name="advanced_settings_remote_provisioning_url_title">Remote provisioning URL</string>
|
||||||
|
|
Loading…
Reference in a new issue