mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
6bea7a6ac2
commit
209662f323
@ -6,7 +6,6 @@ import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.view.get
|
||||
import androidx.core.view.isVisible
|
||||
@ -475,27 +474,17 @@ class ReadBookActivity : ReadBookBaseActivity(),
|
||||
/**
|
||||
* 显示文本操作菜单
|
||||
*/
|
||||
override fun showTextActionMenu() = binding.run {
|
||||
textActionMenu.contentView.measure(
|
||||
View.MeasureSpec.UNSPECIFIED,
|
||||
View.MeasureSpec.UNSPECIFIED
|
||||
override fun showTextActionMenu() {
|
||||
val nbh = if (ReadBookConfig.hideNavigationBar) navigationBarHeight else 0
|
||||
textActionMenu.show(
|
||||
binding.textMenuPosition,
|
||||
binding.root.height + nbh,
|
||||
binding.textMenuPosition.x.toInt(),
|
||||
binding.textMenuPosition.y.toInt(),
|
||||
binding.cursorLeft.y.toInt() + binding.cursorLeft.height,
|
||||
binding.cursorRight.x.toInt(),
|
||||
binding.cursorRight.y.toInt() + binding.cursorRight.height
|
||||
)
|
||||
val popupHeight = textActionMenu.contentView.measuredHeight
|
||||
val x = textMenuPosition.x.toInt()
|
||||
var y = textMenuPosition.y.toInt() - popupHeight
|
||||
if (y < statusBarHeight) {
|
||||
y = (cursorLeft.y + cursorLeft.height).toInt()
|
||||
}
|
||||
if (cursorRight.y > y && cursorRight.y < y + popupHeight) {
|
||||
y = (cursorRight.y + cursorRight.height).toInt()
|
||||
}
|
||||
if (!textActionMenu.isShowing) {
|
||||
textActionMenu.showAtLocation(
|
||||
textMenuPosition, Gravity.TOP or Gravity.START, x, y
|
||||
)
|
||||
} else {
|
||||
textActionMenu.update(x, y, WRAP_CONTENT, WRAP_CONTENT)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,11 +149,7 @@ abstract class ReadBookBaseActivity :
|
||||
binding.navigationBar.run {
|
||||
if (bottomDialog > 0 || binding.readMenu.isVisible) {
|
||||
val navigationBarHeight =
|
||||
if (ReadBookConfig.hideNavigationBar) {
|
||||
activity?.navigationBarHeight ?: 0
|
||||
} else {
|
||||
0
|
||||
}
|
||||
if (ReadBookConfig.hideNavigationBar) navigationBarHeight else 0
|
||||
when (navigationBarGravity) {
|
||||
Gravity.BOTTOM -> layoutParams =
|
||||
(layoutParams as FrameLayout.LayoutParams).apply {
|
||||
|
@ -9,9 +9,7 @@ import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.speech.tts.TextToSpeech
|
||||
import android.speech.tts.UtteranceProgressListener
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.ViewGroup
|
||||
import android.view.*
|
||||
import android.widget.PopupWindow
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.view.SupportMenuInflater
|
||||
@ -41,6 +39,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
private val ttsListener by lazy {
|
||||
TTSUtteranceListener()
|
||||
}
|
||||
private val expandTextMenu get() = context.getPrefBoolean(PreferKey.expandTextMenu)
|
||||
|
||||
init {
|
||||
@SuppressLint("InflateParams")
|
||||
@ -86,7 +85,6 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
}
|
||||
|
||||
fun upMenu() {
|
||||
val expandTextMenu = context.getPrefBoolean(PreferKey.expandTextMenu)
|
||||
if (expandTextMenu) {
|
||||
adapter.setItems(menuItems)
|
||||
binding.ivMenuMore.gone()
|
||||
@ -96,6 +94,67 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
|
||||
}
|
||||
}
|
||||
|
||||
fun show(
|
||||
view: View,
|
||||
windowHeight: Int,
|
||||
startX: Int,
|
||||
startTopY: Int,
|
||||
startBottomY: Int,
|
||||
endX: Int,
|
||||
endBottomY: Int
|
||||
) {
|
||||
if (expandTextMenu) {
|
||||
when {
|
||||
startTopY > 300 -> {
|
||||
showAtLocation(
|
||||
view,
|
||||
Gravity.BOTTOM or Gravity.START,
|
||||
startX,
|
||||
windowHeight - startTopY
|
||||
)
|
||||
}
|
||||
endBottomY - startBottomY > 500 -> {
|
||||
showAtLocation(view, Gravity.TOP or Gravity.START, startX, startBottomY)
|
||||
}
|
||||
else -> {
|
||||
showAtLocation(view, Gravity.TOP or Gravity.START, endX, endBottomY)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
contentView.measure(
|
||||
View.MeasureSpec.UNSPECIFIED,
|
||||
View.MeasureSpec.UNSPECIFIED,
|
||||
)
|
||||
val popupHeight = contentView.measuredHeight
|
||||
when {
|
||||
startBottomY > 300 -> {
|
||||
showAtLocation(
|
||||
view,
|
||||
Gravity.TOP or Gravity.START,
|
||||
startX,
|
||||
startTopY - popupHeight
|
||||
)
|
||||
}
|
||||
endBottomY - startBottomY > 500 -> {
|
||||
showAtLocation(
|
||||
view,
|
||||
Gravity.TOP or Gravity.START,
|
||||
startX,
|
||||
startBottomY
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
showAtLocation(
|
||||
view,
|
||||
Gravity.TOP or Gravity.START,
|
||||
endX,
|
||||
endBottomY
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class Adapter(context: Context) :
|
||||
RecyclerAdapter<MenuItemImpl, ItemTextBinding>(context) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user