优化导航栏位置

pull/1395/head
gedoor 3 years ago
parent da62ad1df3
commit 8cfa0984f6
  1. 18
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  2. 51
      app/src/main/java/io/legado/app/utils/ActivityExtensions.kt
  3. 7
      app/src/main/res/layout/view_read_menu.xml

@ -24,8 +24,7 @@ import io.legado.app.model.ReadBook
import io.legado.app.ui.browser.WebViewActivity import io.legado.app.ui.browser.WebViewActivity
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.* import io.legado.app.utils.*
import splitties.views.onClick import splitties.views.*
import splitties.views.onLongClick
/** /**
* 阅读界面菜单 * 阅读界面菜单
@ -84,7 +83,6 @@ class ReadMenu @JvmOverloads constructor(
brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f)) brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f))
llBrightness.background = brightnessBackground llBrightness.background = brightnessBackground
llBottomBg.setBackgroundColor(bgColor) llBottomBg.setBackgroundColor(bgColor)
vwNavigationBar.setBackgroundColor(bgColor)
fabSearch.backgroundTintList = bottomBackgroundList fabSearch.backgroundTintList = bottomBackgroundList
fabSearch.setColorFilter(textColor) fabSearch.setColorFilter(textColor)
fabAutoPage.backgroundTintList = bottomBackgroundList fabAutoPage.backgroundTintList = bottomBackgroundList
@ -104,7 +102,6 @@ class ReadMenu @JvmOverloads constructor(
ivSetting.setColorFilter(textColor) ivSetting.setColorFilter(textColor)
tvSetting.setTextColor(textColor) tvSetting.setTextColor(textColor)
vwBg.setOnClickListener(null) vwBg.setOnClickListener(null)
vwNavigationBar.setOnClickListener(null)
llBrightness.setOnClickListener(null) llBrightness.setOnClickListener(null)
seekBrightness.post { seekBrightness.post {
seekBrightness.progress = AppConfig.readBrightness seekBrightness.progress = AppConfig.readBrightness
@ -309,14 +306,19 @@ class ReadMenu @JvmOverloads constructor(
} }
override fun onAnimationEnd(animation: Animation) { override fun onAnimationEnd(animation: Animation) {
binding.vwMenuBg.setOnClickListener { runMenuOut() } val navigationBarHeight =
binding.vwNavigationBar.run { if (ReadBookConfig.hideNavigationBar) {
layoutParams = layoutParams.apply {
height = if (ReadBookConfig.hideNavigationBar) {
activity?.navigationBarHeight ?: 0 activity?.navigationBarHeight ?: 0
} else { } else {
0 0
} }
binding.run {
vwMenuBg.setOnClickListener { runMenuOut() }
root.padding = 0
when (activity?.navigationBarPos) {
3 -> root.bottomPadding = navigationBarHeight
1 -> root.leftPadding = navigationBarHeight
2 -> root.rightPadding = navigationBarHeight
} }
} }
if (!LocalConfig.readMenuHelpVersionIsLast) { if (!LocalConfig.readMenuHelpVersionIsLast) {

@ -4,10 +4,7 @@ import android.app.Activity
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.view.View import android.view.*
import android.view.ViewGroup
import android.view.WindowInsets
import android.view.WindowMetrics
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
@ -73,3 +70,49 @@ val Activity.navigationBarHeight: Int
} }
return 0 return 0
} }
/**
* 返回导航栏位置
* 0 bottom
* 1 left
* 2 right
*/
val Activity.navigationBarPos: Int
get() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
var pos = 0
val display: Display = windowManager.defaultDisplay
val rotate: Int = display.rotation
val height: Int = display.height
val width: Int = display.width
pos = if (width > height) {
if (rotate == Surface.ROTATION_270) {
1 //left
} else {
2 //right
}
} else {
0 //bottom
}
return pos
} else {
val display: Display = windowManager.defaultDisplay
val metricsReal = DisplayMetrics()
display.getRealMetrics(metricsReal)
val metricsCurrent = DisplayMetrics()
display.getMetrics(metricsCurrent)
val currH = metricsCurrent.heightPixels
val currW = metricsCurrent.widthPixels
val realW = metricsReal.widthPixels
val realH = metricsReal.heightPixels
return if (currW != realW && currH == realH) {
2
} else {
0
}
}
}

@ -484,13 +484,6 @@
android:layout_height="match_parent" /> android:layout_height="match_parent" />
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
<View
android:id="@+id/vwNavigationBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/background_menu" />
</LinearLayout> </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save