Просмотр исходного кода

增加阅读菜单透明度调整 #81

HapeLee 1 год назад
Родитель
Сommit
554dbb3e1e

+ 1 - 0
app/src/main/java/io/legato/kazusa/constant/PreferKey.kt

@@ -204,4 +204,5 @@ object PreferKey {
     const val tabletInterface = "tabletInterface"
     const val pureBlack = "pure_black"
     const val labelVisibilityMode = "labelVisibilityMode"
+    const val menuAlpha = "menuAlpha"
 }

+ 6 - 0
app/src/main/java/io/legato/kazusa/help/config/AppConfig.kt

@@ -820,5 +820,11 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
         set(value) {
             appCtx.putPrefString(PreferKey.labelVisibilityMode, value)
         }
+
+    var menuAlpha
+        get() = appCtx.getPrefInt(PreferKey.menuAlpha, 100)
+        set(value) {
+            appCtx.putPrefInt(PreferKey.menuAlpha, value)
+        }
 }
 

+ 6 - 1
app/src/main/java/io/legato/kazusa/ui/book/read/ReadMenu.kt

@@ -12,6 +12,7 @@ import android.view.animation.Animation
 import android.widget.FrameLayout
 import android.widget.SeekBar
 import androidx.appcompat.widget.PopupMenu
+import androidx.core.graphics.ColorUtils
 import androidx.core.view.isGone
 import androidx.core.view.isVisible
 import com.google.android.material.button.MaterialButton
@@ -181,7 +182,6 @@ class ReadMenu @JvmOverloads constructor(
         llBrightness.background = brightnessBackground
         if (AppConfig.isEInkMode) {
             titleBar.setBackgroundResource(R.drawable.bg_eink_border_bottom)
-            llBottomBg.setBackgroundResource(R.drawable.bg_eink_border_top)
         } else {
             //llBottomBg.setBackgroundColor(bgColor)
         }
@@ -195,6 +195,11 @@ class ReadMenu @JvmOverloads constructor(
         } else {
             titleBarAddition.gone()
         }
+        val alpha = (AppConfig.menuAlpha / 100f * 255).toInt()
+        val color = context.themeColor(com.google.android.material.R.attr.colorSurfaceContainer)
+        titleBar.setBackgroundColor(ColorUtils.setAlphaComponent(color, alpha))
+        bottomView.setBackgroundColor(ColorUtils.setAlphaComponent(color, alpha))
+        llSlider.alpha = AppConfig.menuAlpha / 100f
         upBrightnessVwPos()
         /**
          * 确保视图不被导航栏遮挡

+ 16 - 0
app/src/main/java/io/legato/kazusa/ui/book/read/config/MoreConfigDialog.kt

@@ -50,6 +50,7 @@ class MoreConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_more_conf
         @SuppressLint("RestrictedApi")
         override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
             addPreferencesFromResource(R.xml.pref_config_read)
+            upPreferenceSummary(PreferKey.menuAlpha, AppConfig.menuAlpha.toString())
             upPreferenceSummary(PreferKey.pageTouchSlop, slopSquare.toString())
             if (!CanvasRecorderFactory.isSupport) {
                 removePref(PreferKey.optimizeRender)
@@ -144,6 +145,19 @@ class MoreConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_more_conf
                     (activity as? ReadBookActivity)?.showClickRegionalConfig()
                 }
 
+                PreferKey.menuAlpha -> {
+                    NumberPickerDialog(requireContext())
+                        .setTitle(getString(R.string.menu_alpha))
+                        .setMaxValue(100)
+                        .setMinValue(0)
+                        .setValue(AppConfig.menuAlpha)
+                        .show {
+                            AppConfig.menuAlpha = it
+                            upPreferenceSummary(PreferKey.menuAlpha, it.toString())
+                            postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
+                        }
+                }
+
                 PreferKey.pageTouchSlop -> {
                     NumberPickerDialog(requireContext())
                         .setTitle(getString(R.string.page_touch_slop_dialog_title))
@@ -163,6 +177,8 @@ class MoreConfigDialog : BaseBottomSheetDialogFragment(R.layout.dialog_more_conf
         private fun upPreferenceSummary(preferenceKey: String, value: String?) {
             val preference = findPreference<Preference>(preferenceKey) ?: return
             when (preferenceKey) {
+                PreferKey.menuAlpha -> preference.summary =
+                    getString(R.string.menu_alpha_sum, AppConfig.menuAlpha)
                 PreferKey.pageTouchSlop -> preference.summary =
                     getString(R.string.page_touch_slop_summary, value)
             }

+ 65 - 73
app/src/main/res/layout-land/view_read_menu.xml

@@ -20,7 +20,6 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="?attr/colorSurfaceContainer"
-        android:alpha="0.92"
         app:layout_constraintTop_toTopOf="parent">
 
         <LinearLayout
@@ -121,85 +120,78 @@
         android:id="@+id/bottom_menu"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:alpha="0.92"
         android:orientation="horizontal"
+        android:background="@android:color/transparent"
         app:layout_constraintBottom_toBottomOf="parent">
 
-            <LinearLayout
-                android:id="@+id/ll_bottom_bg"
-                android:layout_width="match_parent"
+        <View
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="2" />
+
+        <!--章节设置-->
+        <LinearLayout
+            android:id="@+id/ll_slider"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="2"
+            android:layout_marginVertical="8dp"
+            android:importantForAccessibility="no"
+            android:gravity="center"
+            android:orientation="horizontal">
+
+            <com.google.android.material.button.MaterialButton
+                android:id="@+id/tv_pre"
+                style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
+                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:background="@android:color/transparent"
-                android:importantForAccessibility="no"
-                android:orientation="horizontal">
+                android:clickable="true"
+                android:enabled="false"
+                android:focusable="true"
+                app:icon="@drawable/ic_previous"
+                android:contentDescription="@string/previous_chapter"
+                tools:ignore="TouchTargetSizeCheck" />
+
+            <com.google.android.material.card.MaterialCardView
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                app:cardCornerRadius="32dp"
+                app:cardBackgroundColor="?attr/colorSurfaceContainer"
+                app:strokeWidth="0dp">
+                <com.google.android.material.slider.Slider
+                    android:id="@+id/seek_read_page"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_gravity="center_vertical"/>
+            </com.google.android.material.card.MaterialCardView>
 
-                <View
-                    android:layout_width="0dp"
-                    android:layout_height="match_parent"
-                    android:layout_weight="2" />
+            <com.google.android.material.button.MaterialButton
+                android:id="@+id/tv_next"
+                style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:clickable="true"
+                android:enabled="false"
+                android:focusable="true"
+                app:icon="@drawable/ic_next"
+                android:contentDescription="@string/next_chapter"
+                tools:ignore="TouchTargetSizeCheck"/>
+        </LinearLayout>
 
-                <!--章节设置-->
-                <LinearLayout
-                    android:layout_width="0dp"
-                    android:layout_height="wrap_content"
-                    android:layout_weight="2"
-                    android:layout_marginVertical="8dp"
-                    android:importantForAccessibility="no"
-                    android:gravity="center"
-                    android:orientation="horizontal">
-
-                    <com.google.android.material.button.MaterialButton
-                        android:id="@+id/tv_pre"
-                        style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:clickable="true"
-                        android:enabled="false"
-                        android:focusable="true"
-                        app:icon="@drawable/ic_previous"
-                        android:contentDescription="@string/previous_chapter"
-                        tools:ignore="TouchTargetSizeCheck" />
-
-                    <com.google.android.material.card.MaterialCardView
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1"
-                        app:cardCornerRadius="32dp"
-                        app:cardBackgroundColor="?attr/colorSurfaceContainer"
-                        app:strokeWidth="0dp">
-                        <com.google.android.material.slider.Slider
-                            android:id="@+id/seek_read_page"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:layout_gravity="center_vertical"/>
-                    </com.google.android.material.card.MaterialCardView>
-
-                    <com.google.android.material.button.MaterialButton
-                        android:id="@+id/tv_next"
-                        style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:clickable="true"
-                        android:enabled="false"
-                        android:focusable="true"
-                        app:icon="@drawable/ic_next"
-                        android:contentDescription="@string/next_chapter"
-                        tools:ignore="TouchTargetSizeCheck"/>
-                </LinearLayout>
-
-                <com.google.android.material.button.MaterialButtonGroup
-                    android:id="@+id/bottom_view"
-                    android:layout_width="0dp"
-                    android:layout_height="wrap_content"
-                    android:layout_weight="2"
-                    android:importantForAccessibility="no"
-                    android:paddingVertical="8dp"
-                    android:gravity="center"
-                    android:paddingHorizontal="16dp"
-                    android:orientation="horizontal">
+        <com.google.android.material.button.MaterialButtonGroup
+            android:id="@+id/bottom_view"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_weight="2"
+            android:importantForAccessibility="no"
+            android:paddingVertical="8dp"
+            android:gravity="center"
+            android:paddingHorizontal="16dp"
+            android:orientation="horizontal">
+
+        </com.google.android.material.button.MaterialButtonGroup>
 
-                </com.google.android.material.button.MaterialButtonGroup>
-            </LinearLayout>
     </LinearLayout>
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 61 - 69
app/src/main/res/layout/view_read_menu.xml

@@ -20,7 +20,6 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="?attr/colorSurfaceContainer"
-        android:alpha="0.92"
         app:layout_constraintTop_toTopOf="parent">
 
         <LinearLayout
@@ -118,82 +117,75 @@
         android:id="@+id/bottom_menu"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:alpha="0.92"
         android:orientation="vertical"
         app:layout_constraintBottom_toBottomOf="parent">
 
-            <LinearLayout
-                android:id="@+id/ll_bottom_bg"
-                android:layout_width="match_parent"
+        <!--章节设置-->
+        <LinearLayout
+            android:id="@+id/ll_slider"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginVertical="8dp"
+            android:layout_marginHorizontal="16dp"
+            android:importantForAccessibility="no"
+            android:gravity="center"
+            android:orientation="horizontal">
+
+            <com.google.android.material.button.MaterialButton
+                android:id="@+id/tv_pre"
+                style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
+                android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:background="@android:color/transparent"
-                android:importantForAccessibility="no"
-                android:orientation="vertical">
-                <!--章节设置-->
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:layout_marginVertical="8dp"
-                    android:layout_marginHorizontal="16dp"
-                    android:importantForAccessibility="no"
-                    android:gravity="center"
-                    android:orientation="horizontal">
-
-                    <com.google.android.material.button.MaterialButton
-                        android:id="@+id/tv_pre"
-                        style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:clickable="true"
-                        android:enabled="false"
-                        android:focusable="true"
-                        app:icon="@drawable/ic_previous"
-                        android:contentDescription="@string/previous_chapter"
-                        tools:ignore="TouchTargetSizeCheck" />
-
-                    <com.google.android.material.card.MaterialCardView
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1"
-                        app:cardCornerRadius="32dp"
-                        app:cardBackgroundColor="?attr/colorSurfaceContainer"
-                        app:strokeWidth="0dp">
-                        <com.google.android.material.slider.Slider
-                            android:id="@+id/seek_read_page"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:layout_gravity="center_vertical"/>
-                    </com.google.android.material.card.MaterialCardView>
-
-
-
-                    <com.google.android.material.button.MaterialButton
-                        android:id="@+id/tv_next"
-                        style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:clickable="true"
-                        android:enabled="false"
-                        android:focusable="true"
-                        app:icon="@drawable/ic_next"
-                        android:contentDescription="@string/next_chapter"
-                        tools:ignore="TouchTargetSizeCheck"/>
-                </LinearLayout>
-
-                <com.google.android.material.button.MaterialButtonGroup
-                    android:id="@+id/bottom_view"
+                android:clickable="true"
+                android:enabled="false"
+                android:focusable="true"
+                app:icon="@drawable/ic_previous"
+                android:contentDescription="@string/previous_chapter"
+                tools:ignore="TouchTargetSizeCheck" />
+
+            <com.google.android.material.card.MaterialCardView
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                app:cardCornerRadius="32dp"
+                app:cardBackgroundColor="?attr/colorSurfaceContainer"
+                app:strokeWidth="0dp">
+                <com.google.android.material.slider.Slider
+                    android:id="@+id/seek_read_page"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:importantForAccessibility="no"
-                    android:paddingVertical="8dp"
-                    android:paddingHorizontal="16dp"
-                    android:background="?attr/colorSurfaceContainer"
-                    android:gravity="center"
-                    android:orientation="horizontal">
+                    android:layout_gravity="center_vertical"/>
+            </com.google.android.material.card.MaterialCardView>
 
 
-                </com.google.android.material.button.MaterialButtonGroup>
-            </LinearLayout>
+
+            <com.google.android.material.button.MaterialButton
+                android:id="@+id/tv_next"
+                style="@style/Widget.Material3Expressive.Button.IconButton.Tonal"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:clickable="true"
+                android:enabled="false"
+                android:focusable="true"
+                app:icon="@drawable/ic_next"
+                android:contentDescription="@string/next_chapter"
+                tools:ignore="TouchTargetSizeCheck"/>
+        </LinearLayout>
+
+        <com.google.android.material.button.MaterialButtonGroup
+            android:id="@+id/bottom_view"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:importantForAccessibility="no"
+            android:paddingVertical="8dp"
+            android:paddingHorizontal="16dp"
+            android:background="?attr/colorSurfaceContainer"
+            android:gravity="center"
+            android:orientation="horizontal">
+
+
+        </com.google.android.material.button.MaterialButtonGroup>
+
     </LinearLayout>
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 2 - 0
app/src/main/res/values-zh/strings.xml

@@ -1286,4 +1286,6 @@
     <string name="delay_book_load">延缓书籍加载</string>
     <string name="compact_list">紧凑列表</string>
     <string name="author_read">%s • %d章未读</string>
+    <string name="menu_alpha_sum">当前 %d%%</string>
+    <string name="menu_alpha">菜单透明度</string>
 </resources>

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -1287,4 +1287,6 @@
     <string name="delay_book_load">Delay Book Loading</string>
     <string name="compact_list">Compact List</string>
     <string name="author_read">%s • %dNot read</string>
+    <string name="menu_alpha_sum">Current %d%%</string>
+    <string name="menu_alpha">Menu transparency</string>
 </resources>

+ 7 - 0
app/src/main/res/xml/pref_config_read.xml

@@ -28,6 +28,13 @@
         app:iconSpaceReserved="false"
         app:isBottomBackground="true" />
 
+    <io.legato.kazusa.lib.prefs.Preference
+        android:key="menuAlpha"
+        android:summary="@string/menu_alpha_sum"
+        android:title="@string/menu_alpha"
+        app:iconSpaceReserved="false"
+        app:isBottomBackground="true" />
+
     <io.legato.kazusa.lib.prefs.SwitchPreference
         android:defaultValue="false"
         android:key="hideStatusBar"