Skip to content

Commit

Permalink
fix: incorrect navigation bar appearance in the activities of the app
Browse files Browse the repository at this point in the history
refactor: slightly refactor to app theme scheme
  • Loading branch information
WhiredPlanck committed Feb 9, 2024
1 parent 3f13fa8 commit 9aa9d0e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
android:label="@string/trime_app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_app_icon_round"
android:theme="@style/PreferenceTheme">
android:theme="@style/Theme.TrimeAppTheme">

<service
android:name=".TrimeImeService"
Expand Down
11 changes: 3 additions & 8 deletions app/src/main/java/com/osfans/trime/ui/main/PrefMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.osfans.trime.util.isStorageAvailable
import com.osfans.trime.util.progressBarDialogIndeterminate
import com.osfans.trime.util.rimeActionWithResultDialog
import kotlinx.coroutines.launch
import splitties.views.topPadding

class PrefMainActivity : AppCompatActivity() {
private val viewModel: MainViewModel by viewModels()
Expand Down Expand Up @@ -67,17 +68,11 @@ class PrefMainActivity : AppCompatActivity() {
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, windowInsets ->
val statusBars = windowInsets.getInsets(WindowInsetsCompat.Type.statusBars())
val navBars = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars())
binding.prefToolbar.appBar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = navBars.left
rightMargin = navBars.right
}
binding.prefToolbar.toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = statusBars.top
}
binding.navHostFragment.updateLayoutParams<ViewGroup.MarginLayoutParams> {
binding.root.updateLayoutParams<ViewGroup.MarginLayoutParams> {
leftMargin = navBars.left
rightMargin = navBars.right
}
binding.prefToolbar.root.topPadding = statusBars.top
windowInsets
}

Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/osfans/trime/util/Activity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.osfans.trime.util

import android.app.Activity
import android.graphics.Color
import android.os.Build
import androidx.core.view.WindowCompat

fun Activity.applyTranslucentSystemBars() {
WindowCompat.setDecorFitsSystemWindows(window, false)
// windowLightNavigationBar is available for 27+
window.navigationBarColor =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Color.TRANSPARENT
} else {
// com.android.internal.R.color.system_bar_background_semi_transparent
0x66000000
}
WindowCompat.getInsetsController(window, window.decorView)
.isAppearanceLightNavigationBars = !resources.configuration.isNightMode()
}
15 changes: 0 additions & 15 deletions app/src/main/java/com/osfans/trime/util/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.osfans.trime.util

import android.app.Activity
import android.content.Context
import android.content.res.Configuration
import android.graphics.Color
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand All @@ -12,7 +10,6 @@ import android.util.TypedValue
import android.view.View
import androidx.annotation.AttrRes
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import androidx.preference.Preference
Expand Down Expand Up @@ -96,18 +93,6 @@ inline fun CharSequence.startsWithAsciiChar(): Boolean {
return firstCodePoint in 0x20 until 0x80
}

fun Activity.applyTranslucentSystemBars() {
WindowCompat.setDecorFitsSystemWindows(window, false)
// windowLightNavigationBar is available for 27+
window.navigationBarColor =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
Color.TRANSPARENT
} else {
// com.android.internal.R.color.system_bar_background_semi_transparent
0x66000000
}
}

fun RecyclerView.applyNavBarInsetsBottomPadding() {
clipToPadding = false
ViewCompat.setOnApplyWindowInsetsListener(this) { _, windowInsets ->
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="toolbarForegroundColor">#FFFFFF</color> <!-- 工具栏前景色 -->
<color name="windowBackground">#202020</color>
</resources>
<color name="colorOnSurface">#000000</color>
<color name="colorBackground">#1E2B38</color>
</resources>
12 changes: 6 additions & 6 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<color name="grey_700">#616161</color>

<!-- 本色彩方案取自 Rime 官网(https://rime.im) -->
<color name="colorPrimary">#3F4144</color> <!-- 浅主题色 -->
<color name="colorPrimaryDark">#37393D</color> <!-- 深主题色 -->
<color name="colorPrimary">#2C3E50</color> <!-- 浅主题色 -->
<color name="colorPrimaryDark">#1E2B38</color> <!-- 深主题色 -->
<color name="colorAccent">#009BD1</color> <!-- 浅强调色 -->
<color name="colorAccentDark">#1976D2</color> <!-- 深强调色 -->
<color name="colorAccentDark">#006C92</color> <!-- 深强调色 -->
<color name="colorBackground">#FAFAFA</color>
<color name="toolbarForegroundColor">#FFFFFF</color> <!-- 工具栏前景色 -->

<color name="windowBackground">#FAFAFA</color>
</resources>

</resources>
11 changes: 5 additions & 6 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="PreferenceTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<style name="Theme.TrimeAppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorAccent" tools:targetApi="lollipop">@color/colorAccent</item>

<item name="android:windowBackground">@color/windowBackground</item>
<item name="android:colorBackground">@color/windowBackground</item>
<item name="colorOnSurface">@color/colorOnSurface</item>
<item name="android:colorBackground">@color/colorBackground</item>
<item name="android:colorAccent" >@color/colorAccent</item>
</style>
</resources>
</resources>

0 comments on commit 9aa9d0e

Please sign in to comment.