Skip to content

Commit

Permalink
feat: allow user to determine navigation bar background behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Apr 27, 2024
1 parent 73d6929 commit cfd6b65
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 23 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/com/osfans/trime/data/AppPrefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ class AppPrefs(
const val SELECTED_COLOR = "theme_selected_color"
const val AUTO_DARK = "theme_auto_dark"
const val USE_MINI_KEYBOARD = "theme_use_mini_keyboard"
const val NAVBAR_BACKGROUND = "navbar_background"
}

var selectedTheme: String
Expand All @@ -330,6 +331,16 @@ class AppPrefs(
var useMiniKeyboard: Boolean = false
get() = prefs.getPref(USE_MINI_KEYBOARD, false)
private set

enum class NavbarBackground {
NONE,
COLOR_ONLY,
FULL,
}

var navbarBackground: NavbarBackground
get() = NavbarBackground.valueOf(prefs.getPref(NAVBAR_BACKGROUND, NavbarBackground.COLOR_ONLY.name))
set(value) = prefs.setPref(NAVBAR_BACKGROUND, value.name)
}

/**
Expand Down
57 changes: 35 additions & 22 deletions app/src/main/java/com/osfans/trime/ime/core/InputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.core.view.updateLayoutParams
import androidx.lifecycle.lifecycleScope
import com.osfans.trime.core.RimeNotification
import com.osfans.trime.daemon.RimeSession
import com.osfans.trime.data.AppPrefs
import com.osfans.trime.data.theme.ColorManager
import com.osfans.trime.data.theme.ThemeManager
import com.osfans.trime.ime.bar.QuickBar
Expand Down Expand Up @@ -65,6 +66,7 @@ class InputView(
private val theme get() = ThemeManager.activeTheme
private var shouldUpdateNavbarForeground = false
private var shouldUpdateNavbarBackground = false
private val navbarBackground get() = AppPrefs.defaultInstance().theme.navbarBackground

private val keyboardBackground =
imageView {
Expand Down Expand Up @@ -143,30 +145,41 @@ class InputView(
windowManager.cacheResidentWindow(keyboardWindow, createView = true)
windowManager.cacheResidentWindow(liquidKeyboard)

service.window.window!!.also { it ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
shouldUpdateNavbarForeground = true
// allow draw behind navigation bar
WindowCompat.setDecorFitsSystemWindows(it, false)
it.navigationBarColor = Color.TRANSPARENT
// don't apply scrim to transparent navigation bar
it.isNavigationBarContrastEnforced = false
ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets ->
insets.getInsets(WindowInsetsCompat.Type.navigationBars()).let {
bottomPaddingSpace.updateLayoutParams<LayoutParams> {
bottomMargin = it.bottom
}
service.window.window!!.also {
when (navbarBackground) {
AppPrefs.Theme.NavbarBackground.NONE -> {
WindowCompat.setDecorFitsSystemWindows(it, true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
it.isNavigationBarContrastEnforced = true
}
}
AppPrefs.Theme.NavbarBackground.COLOR_ONLY -> {
shouldUpdateNavbarForeground = true
shouldUpdateNavbarBackground = true
// don't draw behind navigation bar
WindowCompat.setDecorFitsSystemWindows(it, true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// don't apply scrim to transparent navigation bar
it.isNavigationBarContrastEnforced = false
}
WindowInsetsCompat.CONSUMED
}
} else {
shouldUpdateNavbarForeground = true
shouldUpdateNavbarBackground = true
// don't draw behind navigation bar
WindowCompat.setDecorFitsSystemWindows(it, true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// don't apply scrim to transparent navigation bar
it.isNavigationBarContrastEnforced = false
AppPrefs.Theme.NavbarBackground.FULL -> {
shouldUpdateNavbarForeground = true
// allow draw behind navigation bar
WindowCompat.setDecorFitsSystemWindows(it, false)
it.navigationBarColor = Color.TRANSPARENT
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// don't apply scrim to transparent navigation bar
it.isNavigationBarContrastEnforced = false
}
ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets ->
insets.getInsets(WindowInsetsCompat.Type.navigationBars()).let {
bottomPaddingSpace.updateLayoutParams<LayoutParams> {
bottomMargin = it.bottom
}
}
WindowInsetsCompat.CONSUMED
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="no_schema_to_enable">没有方案可启用。请确保您已在用户文件夹中放入了前置文件和方案文件。</string>
<string name="schemata">方案</string>
<string name="schemata_hint">选择当前方案或启用更多方案</string>
<string name="navbar_background">导航栏背景</string>
<string-array name="navbar_bkg_labels">
<item>无背景</item>
<item>跟随键盘背景色</item>
<item>键盘背景图片</item>
</string-array>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="no_schema_to_enable">沒有方案可啟用。請確保您已在使用者資料夾中放入了前置檔案和方案檔案。</string>
<string name="schemata">方案</string>
<string name="schemata_hint">選擇當前方案或啓用更多方案</string>
<string name="navbar_background">導航欄背景</string>
<string-array name="navbar_bkg_labels">
<item>無背景</item>
<item>跟隨鍵盤背景色</item>
<item>鍵盤背景圖片</item>
</string-array>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
<item>50</item>
<item>100</item>
</string-array>
<string-array name="navbar_bkg_values">
<item>NONE</item>
<item>COLOR_ONLY</item>
<item>FULL</item>
</string-array>
</resources>
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 @@ -279,4 +279,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string name="no_schema_to_enable">No schema to enable. Make sure you have prelude and schema files in the user directory.</string>
<string name="schemata">Schemata</string>
<string name="schemata_hint">Select current schema or enable more schemata</string>
<string name="navbar_background">Navigation bar background</string>
<string-array name="navbar_bkg_labels">
<item>No background</item>
<item>Follow keyboard color</item>
<item>Keyboard background image</item>
</string-array>
</resources>
9 changes: 8 additions & 1 deletion app/src/main/res/xml/theme_color_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
app:iconSpaceReserved="false"
android:title="@string/looks__selected_color_title"
android:summary="@string/looks__selected_color_summary" />
<ListPreference android:key="navbar_background"
app:iconSpaceReserved="false"
android:title="@string/navbar_background"
android:defaultValue="COLOR_ONLY"
android:entryValues="@array/navbar_bkg_values"
android:entries="@array/navbar_bkg_labels"
app:useSimpleSummaryProvider="true"/>
<SwitchPreferenceCompat android:key="theme_auto_dark"
app:iconSpaceReserved="false"
android:title="@string/keyboard__auto_dark_title"
Expand All @@ -24,4 +31,4 @@ SPDX-License-Identifier: GPL-3.0-or-later
app:iconSpaceReserved="false"
android:title="@string/keyboard__use_mini_keyboard_title"
android:defaultValue="false"/>
</PreferenceScreen>
</PreferenceScreen>

0 comments on commit cfd6b65

Please sign in to comment.