Skip to content

Commit

Permalink
Cutout mode as configuration option
Browse files Browse the repository at this point in the history
Close #604
  • Loading branch information
Slion committed Feb 15, 2024
1 parent 17e0c98 commit 25d2741
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 11 deletions.
18 changes: 18 additions & 0 deletions app/src/main/java/fulguris/activity/WebBrowserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ abstract class WebBrowserActivity : ThemedBrowserActivity(),
super.onCreate(savedInstanceState)
// We want to control our decor
WindowCompat.setDecorFitsSystemWindows(window,false)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
window.attributes.layoutInDisplayCutoutMode = configPrefs.cutoutMode.value
}

// Register lifecycle observers
lifecycle.addObserver(tabsManager)
Expand Down Expand Up @@ -482,6 +485,16 @@ abstract class WebBrowserActivity : ThemedBrowserActivity(),
private fun updateConfiguration(aConfig: Configuration = resources.configuration) {
Timber.d("updateConfiguration")

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (window.attributes.layoutInDisplayCutoutMode != configPrefs.cutoutMode.value) {
// We don't seem to be able to apply that without restarting the activity
window.attributes.layoutInDisplayCutoutMode = configPrefs.cutoutMode.value
// This makes sure the newly set cutout mode is applied
window.attributes = window.attributes
// TODO adjust attributes for all our dialog windows
}
}

setupDrawers()
setFullscreenIfNeeded(aConfig)
if (!setupTabBar(aConfig)) {
Expand Down Expand Up @@ -534,6 +547,11 @@ abstract class WebBrowserActivity : ThemedBrowserActivity(),
// Set up BottomSheetDialog
dialog.window?.decorView?.systemUiVisibility = window.decorView.systemUiVisibility
dialog.window?.setFlags(window.attributes.flags, WindowManager.LayoutParams.FLAG_FULLSCREEN)
// TODO: All windows should have consistent cutout modes
//dialog.window?.let {WindowCompat.setDecorFitsSystemWindows(it,false)}
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// dialog.window?.attributes?.layoutInDisplayCutoutMode = configPrefs.cutoutMode.value
//}
//dialog.window?.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
//dialog.window?.setFlags(dialog.window?.attributes!!.flags, WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
//dialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/fulguris/constant/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ object Uris {
const val AboutHistory = "${Schemes.About}:${Hosts.History}"
}

/**
* Not sure why we needed those here now.
* Could have been needed for our configuration preferences architecture.
*/
object PrefKeys {
const val HideStatusBar = "pref_key_hide_status_bar"
const val HideToolBar = "pref_key_hide_tool_bar"
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/fulguris/enums/CutoutMode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fulguris.enums

import android.util.Log
import fulguris.settings.preferences.IntEnum
import android.view.WindowManager

enum class CutoutMode(override val value: Int) : IntEnum {
/**
* See: [WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT]
*/
Default(0),
/**
* See: [WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES]
*/
ShortEdges(1),
/**
* See: [WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER]
*/
Never(2),
/**
* See: [WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS]
*/
Always(3)
}

/*
enum class CutoutMode {
Default = 0,
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package fulguris.settings.preferences

import fulguris.enums.CutoutMode

/**
* Provide access to settings default values.
* That was needed as our instantiated configuration settings can not rely on defaults defined in XML.
Expand All @@ -44,9 +46,15 @@ interface ConfigurationDefaults {
*/
fun getDefaultFloat(aKey: String) : Float

/**
*
*/
fun getDefaultCutoutMode() : CutoutMode

/**
* Provide a map of settings preference keys to their default values.
*/
fun getDefaults() : Map<String,Any>


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import fulguris.constant.PrefKeys
import fulguris.device.ScreenSize
import android.content.SharedPreferences
import fulguris.settings.preferences.delegates.booleanPreference
import fulguris.settings.preferences.delegates.enumPreference
import fulguris.settings.preferences.delegates.floatPreference

/**
Expand Down Expand Up @@ -88,5 +89,14 @@ abstract class ConfigurationPreferences constructor(
*/
var desktopWidth by preferences.floatPreference(R.string.pref_key_desktop_width, getDefaultFloat(PrefKeys.DesktopWidth))


/**
* Define if we render around display cutouts.
*
* See: https://developer.android.com/reference/android/view/WindowManager.LayoutParams
* See: https://developer.android.com/reference/android/view/WindowManager.LayoutParams#LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
*/
var cutoutMode by preferences.enumPreference(R.string.pref_key_cutout_mode, getDefaultCutoutMode())

}

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import fulguris.constant.PrefKeys
import fulguris.device.ScreenSize
import fulguris.di.PrefsLandscape
import android.content.SharedPreferences
import fulguris.enums.CutoutMode
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -50,6 +51,10 @@ class LandscapePreferences @Inject constructor(
return iDefaults[aKey] as Float
}

override fun getDefaultCutoutMode(): CutoutMode {
return CutoutMode.Default
}

override fun getDefaults(): Map<String, Any> {
return iDefaults
}
Expand All @@ -64,11 +69,12 @@ class LandscapePreferences @Inject constructor(
PrefKeys.ShowToolBarOnPageTop to true,
PrefKeys.PullToRefresh to true,
PrefKeys.ToolbarsBottom to false,
PrefKeys.DesktopWidth to 200F,
PrefKeys.DesktopWidth to 200F
// Omitted the following as they have non static default values specified in the base class
//PrefKeys.TabBarVertical to !screenSize.isTablet(),
//PrefKeys.TabBarInDrawer to !screenSize.isTablet(),
)

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import fulguris.constant.PrefKeys
import fulguris.device.ScreenSize
import fulguris.di.PrefsPortrait
import android.content.SharedPreferences
import fulguris.enums.CutoutMode
import javax.inject.Inject
import javax.inject.Singleton

Expand Down Expand Up @@ -53,6 +54,10 @@ import javax.inject.Singleton
return LandscapePreferences.iDefaults[aKey] as Float
}

override fun getDefaultCutoutMode(): CutoutMode {
return CutoutMode.Default
}

override fun getDefaults(): Map<String, Any> {
return iDefaults
}
Expand All @@ -67,7 +72,7 @@ import javax.inject.Singleton
PrefKeys.ShowToolBarOnPageTop to true,
PrefKeys.PullToRefresh to true,
PrefKeys.ToolbarsBottom to false,
PrefKeys.DesktopWidth to 200F,
PrefKeys.DesktopWidth to 200F
// Omitted the following as they have non static default values specified in the base class
//PrefKeys.TabBarVertical to !screenSize.isTablet(),
//PrefKeys.TabBarInDrawer to !screenSize.isTablet(),
Expand Down
20 changes: 11 additions & 9 deletions app/src/main/res/values-v27/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@
See: https://github.com/Slion/Fulguris/issues/603
However I reckon we better do that in code and make it configurable.
See: https://stackoverflow.com/a/58361683/3969362
We are now indeed doing that in code and using a configuration option.
-->

<style name="Theme.App.Light" parent="Theme.App.Light.Base">
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges <!-- default, shortEdges, or never -->
</item>
<!-- <item name="android:windowLayoutInDisplayCutoutMode">-->
<!-- shortEdges &lt;!&ndash; default, shortEdges, or never &ndash;&gt;-->
<!-- </item>-->
</style>>

<style name="Theme.App.Dark" parent="Theme.App.Dark.Base">
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges <!-- default, shortEdges, or never -->
</item>
<!-- <item name="android:windowLayoutInDisplayCutoutMode">-->
<!-- shortEdges &lt;!&ndash; default, shortEdges, or never &ndash;&gt;-->
<!-- </item>-->
</style>

<style name="Theme.App.Black" parent="Theme.App.Black.Base">
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges <!-- default, shortEdges, or never -->
</item>
<!-- <item name="android:windowLayoutInDisplayCutoutMode">-->
<!-- shortEdges &lt;!&ndash; default, shortEdges, or never &ndash;&gt;-->
<!-- </item>-->
</style>

</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@
<item>@string/log_level_assert</item>
</string-array>

<string-array name="CutoutMode">
<item>@string/cutout_mode_default</item>
<item>@string/cutout_mode_short_edges</item>
<item>@string/cutout_mode_never</item>
<item>@string/cutout_mode_always</item>
</string-array>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
<string name="pref_key_tab_bar_vertical">pref_key_tab_bar_vertical</string>
<string name="pref_key_tab_bar_in_drawer">pref_key_tab_bar_in_drawer</string>
<string name="pref_key_toolbars_bottom">pref_key_toolbars_bottom</string>
<string name="pref_key_cutout_mode">pref_key_cutout_mode</string>
<string name="pref_key_user_agent">pref_key_user_agent</string>


<!-- On tab close -->
<string name="pref_key_on_tab_close_show_snackbar">pref_key_on_tab_close_show_snackbar</string>
<string name="pref_key_on_tab_close_vibrate">pref_key_on_tab_close_vibrate</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
<string name="pref_title_hide_tool_bar">Hide tool bar when scrolling down</string>
<string name="pref_title_show_tool_bar_when_scroll_up">Show tool bar when scrolling up</string>
<string name="pref_title_show_tool_bar_on_page_top">Show tool bar at the top of the page</string>
<string name="pref_title_cutout_mode">Cutout mode</string>
<string name="pref_title_locked_drawers">Locked panels</string>
<string name="pref_summary_locked_drawers">Tabs and Bookmarks panels can\'t be dragged</string>
<string name="pref_title_use_bottom_sheets">Use bottom sheets</string>
Expand Down Expand Up @@ -656,6 +657,11 @@ See: https://stackoverflow.com/a/42884713/3969362
<string name="log_level_error">Error</string>
<string name="log_level_assert">Assert</string>

<string name="cutout_mode_default">Default</string>
<string name="cutout_mode_short_edges">Short edges</string>
<string name="cutout_mode_never">Never</string>
<string name="cutout_mode_always">Always</string>

<!-- TODO: link to existing strings -->
<string name="label_url">URL</string>
<string name="label_short_url">Short URL</string>
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/xml/preference_configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@
a:iconSpaceReserved="false"
a:singleLineTitle="false" />

<fulguris.preference.EnumListPreference
a:key="@string/pref_key_cutout_mode"
a:title="@string/pref_title_cutout_mode"
a:useSimpleSummaryProvider="true"
a:defaultValue="Default"
a:entries="@array/CutoutMode"
a:icon="@drawable/ic_short_text"
a:singleLineTitle="false"
a:enumClassName="fulguris.enums.CutoutMode"
/>

<fulguris.preference.SliderPreference
a:key="@string/pref_key_desktop_width"
a:title="@string/pref_title_desktop_width"
Expand Down

0 comments on commit 25d2741

Please sign in to comment.