pull/1705/head
kunfei 3 years ago
parent 54e311ac81
commit f68c730416
  1. 6
      app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt
  2. 10
      app/src/main/java/io/legado/app/lib/theme/view/ThemeRadioNoButton.kt
  3. 2
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt
  4. 2
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt
  5. 2
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  8. 4
      app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
  9. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
  10. 16
      app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt
  11. 18
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  12. 4
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  13. 2
      app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt
  14. 4
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  15. 18
      app/src/main/java/io/legado/app/ui/widget/BatteryView.kt
  16. 6
      app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt
  17. 8
      app/src/main/java/io/legado/app/ui/widget/anima/RotateLoading.kt
  18. 4
      app/src/main/java/io/legado/app/ui/widget/checkbox/SmoothCheckBox.kt
  19. 5
      app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt
  20. 4
      app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt
  21. 4
      app/src/main/java/io/legado/app/ui/widget/keyboard/KeyboardAssistsConfig.kt
  22. 4
      app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt
  23. 6
      app/src/main/java/io/legado/app/ui/widget/text/AccentStrokeTextView.kt
  24. 12
      app/src/main/java/io/legado/app/ui/widget/text/StrokeTextView.kt
  25. 23
      app/src/main/java/io/legado/app/utils/ConvertExtensions.kt

@ -11,7 +11,7 @@ import androidx.fragment.app.Fragment
import io.legado.app.R import io.legado.app.R
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
/** /**
* @author Karim Abou Zeid (kabouzeid) * @author Karim Abou Zeid (kabouzeid)
@ -127,14 +127,14 @@ val Context.elevation: Float
resources.getDimension(R.dimen.design_appbar_elevation) resources.getDimension(R.dimen.design_appbar_elevation)
) )
} else { } else {
AppConfig.elevation.dp.toFloat() AppConfig.elevation.toFloat().dpToPx()
} }
} }
val Context.filletBackground: GradientDrawable val Context.filletBackground: GradientDrawable
get() { get() {
val background = GradientDrawable() val background = GradientDrawable()
background.cornerRadius = 3F.dp background.cornerRadius = 3f.dpToPx()
background.setColor(backgroundColor) background.setColor(backgroundColor)
return background return background
} }

@ -9,7 +9,7 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
class ThemeRadioNoButton(context: Context, attrs: AttributeSet) : class ThemeRadioNoButton(context: Context, attrs: AttributeSet) :
@ -32,8 +32,8 @@ class ThemeRadioNoButton(context: Context, attrs: AttributeSet) :
val isLight = ColorUtils.isColorLight(context.bottomBackground) val isLight = ColorUtils.isColorLight(context.bottomBackground)
val textColor = context.getPrimaryTextColor(isLight) val textColor = context.getPrimaryTextColor(isLight)
background = Selector.shapeBuild() background = Selector.shapeBuild()
.setCornerRadius(2.dp) .setCornerRadius(2.dpToPx())
.setStrokeWidth(2.dp) .setStrokeWidth(2.dpToPx())
.setCheckedBgColor(context.accentColor) .setCheckedBgColor(context.accentColor)
.setCheckedStrokeColor(context.accentColor) .setCheckedStrokeColor(context.accentColor)
.setDefaultStrokeColor(textColor) .setDefaultStrokeColor(textColor)
@ -48,8 +48,8 @@ class ThemeRadioNoButton(context: Context, attrs: AttributeSet) :
else -> { else -> {
val textColor = context.getCompatColor(R.color.primaryText) val textColor = context.getCompatColor(R.color.primaryText)
background = Selector.shapeBuild() background = Selector.shapeBuild()
.setCornerRadius(2.dp) .setCornerRadius(2.dpToPx())
.setStrokeWidth(2.dp) .setStrokeWidth(2.dpToPx())
.setCheckedBgColor(context.accentColor) .setCheckedBgColor(context.accentColor)
.setCheckedStrokeColor(context.accentColor) .setCheckedStrokeColor(context.accentColor)
.setDefaultStrokeColor(textColor) .setDefaultStrokeColor(textColor)

@ -164,7 +164,7 @@ class ImportBookSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_vie
} }
textInputLayout.setHint(R.string.group_name) textInputLayout.setHint(R.string.group_name)
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dp editView.dropDownHeight = 180.dpToPx()
} }
customView { customView {
alertBinding.root alertBinding.root

@ -140,7 +140,7 @@ class ImportReplaceRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vi
} }
textInputLayout.setHint(R.string.group_name) textInputLayout.setHint(R.string.group_name)
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dp editView.dropDownHeight = 180.dpToPx()
} }
customView { customView {
alertBinding.root alertBinding.root

@ -163,7 +163,7 @@ class ImportRssSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_view
} }
textInputLayout.setHint(R.string.group_name) textInputLayout.setHint(R.string.group_name)
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dp editView.dropDownHeight = 180.dpToPx()
} }
customView { customView {
alertBinding.root alertBinding.root

@ -394,7 +394,7 @@ class BookInfoActivity :
setText(R.string.delete_book_file) setText(R.string.delete_book_file)
} }
val view = LinearLayout(this@BookInfoActivity).apply { val view = LinearLayout(this@BookInfoActivity).apply {
setPadding(16.dp, 0, 16.dp, 0) setPadding(16.dpToPx(), 0, 16.dpToPx(), 0)
addView(checkBox) addView(checkBox)
} }
customView { view } customView { view }

@ -86,7 +86,7 @@ class ReadMenu @JvmOverloads constructor(
} }
initAnimation() initAnimation()
val brightnessBackground = GradientDrawable() val brightnessBackground = GradientDrawable()
brightnessBackground.cornerRadius = 5F.dp brightnessBackground.cornerRadius = 5F.dpToPx()
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)

@ -18,7 +18,7 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.setEdgeEffectColor import io.legado.app.utils.setEdgeEffectColor
@ -36,7 +36,7 @@ class MoreConfigDialog : DialogFragment() {
attr.dimAmount = 0.0f attr.dimAmount = 0.0f
attr.gravity = Gravity.BOTTOM attr.gravity = Gravity.BOTTOM
attributes = attr attributes = attr
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, 360.dp) setLayout(ViewGroup.LayoutParams.MATCH_PARENT, 360.dpToPx())
} }
} }

@ -80,7 +80,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style),
rvStyle.adapter = styleAdapter rvStyle.adapter = styleAdapter
styleAdapter.addFooterView { styleAdapter.addFooterView {
ItemReadStyleBinding.inflate(layoutInflater, it, false).apply { ItemReadStyleBinding.inflate(layoutInflater, it, false).apply {
ivStyle.setPadding(6.dp, 6.dp, 6.dp, 6.dp) ivStyle.setPadding(6.dpToPx(), 6.dpToPx(), 6.dpToPx(), 6.dpToPx())
ivStyle.setText(null) ivStyle.setText(null)
ivStyle.setColorFilter(textColor) ivStyle.setColorFilter(textColor)
ivStyle.borderColor = textColor ivStyle.borderColor = textColor

@ -73,16 +73,16 @@ class PageView(context: Context) : FrameLayout(context) {
tvFooterRight.setColor(tipColor) tvFooterRight.setColor(tipColor)
upStatusBar() upStatusBar()
llHeader.setPadding( llHeader.setPadding(
it.headerPaddingLeft.dp, it.headerPaddingLeft.dpToPx(),
it.headerPaddingTop.dp, it.headerPaddingTop.dpToPx(),
it.headerPaddingRight.dp, it.headerPaddingRight.dpToPx(),
it.headerPaddingBottom.dp it.headerPaddingBottom.dpToPx()
) )
llFooter.setPadding( llFooter.setPadding(
it.footerPaddingLeft.dp, it.footerPaddingLeft.dpToPx(),
it.footerPaddingTop.dp, it.footerPaddingTop.dpToPx(),
it.footerPaddingRight.dp, it.footerPaddingRight.dpToPx(),
it.footerPaddingBottom.dp it.footerPaddingBottom.dpToPx()
) )
vwTopDivider.visible(it.showHeaderLine) vwTopDivider.visible(it.showHeaderLine)
vwBottomDivider.visible(it.showFooterLine) vwBottomDivider.visible(it.showFooterLine)

@ -181,7 +181,7 @@ object ChapterProvider {
} }
} }
} }
textPages.last().height = durY + 20.dp textPages.last().height = durY + 20.dpToPx()
textPages.last().text = stringBuilder.toString() textPages.last().text = stringBuilder.toString()
textPages.forEachIndexed { index, item -> textPages.forEachIndexed { index, item ->
item.index = index item.index = index
@ -537,8 +537,8 @@ object ChapterProvider {
//间距 //间距
lineSpacingExtra = ReadBookConfig.lineSpacingExtra / 10f lineSpacingExtra = ReadBookConfig.lineSpacingExtra / 10f
paragraphSpacing = ReadBookConfig.paragraphSpacing paragraphSpacing = ReadBookConfig.paragraphSpacing
titleTopSpacing = ReadBookConfig.titleTopSpacing.dp titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx()
titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dp titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx()
upLayout() upLayout()
} }
@ -593,14 +593,14 @@ object ChapterProvider {
tPaint.color = ReadBookConfig.textColor tPaint.color = ReadBookConfig.textColor
tPaint.letterSpacing = ReadBookConfig.letterSpacing tPaint.letterSpacing = ReadBookConfig.letterSpacing
tPaint.typeface = titleFont tPaint.typeface = titleFont
tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.sp.toFloat() tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.toFloat().spToPx()
tPaint.isAntiAlias = true tPaint.isAntiAlias = true
//正文 //正文
val cPaint = TextPaint() val cPaint = TextPaint()
cPaint.color = ReadBookConfig.textColor cPaint.color = ReadBookConfig.textColor
cPaint.letterSpacing = ReadBookConfig.letterSpacing cPaint.letterSpacing = ReadBookConfig.letterSpacing
cPaint.typeface = textFont cPaint.typeface = textFont
cPaint.textSize = ReadBookConfig.textSize.sp.toFloat() cPaint.textSize = ReadBookConfig.textSize.toFloat().spToPx()
cPaint.isAntiAlias = true cPaint.isAntiAlias = true
return Pair(tPaint, cPaint) return Pair(tPaint, cPaint)
} }
@ -625,10 +625,10 @@ object ChapterProvider {
&& ReadBook.pageAnim() != 3 && ReadBook.pageAnim() != 3
&& AppConfig.doublePageHorizontal && AppConfig.doublePageHorizontal
if (viewWidth > 0 && viewHeight > 0) { if (viewWidth > 0 && viewHeight > 0) {
paddingLeft = ReadBookConfig.paddingLeft.dp paddingLeft = ReadBookConfig.paddingLeft.dpToPx()
paddingTop = ReadBookConfig.paddingTop.dp paddingTop = ReadBookConfig.paddingTop.dpToPx()
paddingRight = ReadBookConfig.paddingRight.dp paddingRight = ReadBookConfig.paddingRight.dpToPx()
paddingBottom = ReadBookConfig.paddingBottom.dp paddingBottom = ReadBookConfig.paddingBottom.dpToPx()
visibleWidth = if (doublePage) { visibleWidth = if (doublePage) {
viewWidth / 2 - paddingLeft - paddingRight viewWidth / 2 - paddingLeft - paddingRight
} else { } else {

@ -389,7 +389,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.setHint(R.string.group_name) editView.setHint(R.string.group_name)
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dp editView.dropDownHeight = 180.dpToPx()
} }
customView { alertBinding.root } customView { alertBinding.root }
okButton { okButton {
@ -409,7 +409,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply {
editView.setHint(R.string.group_name) editView.setHint(R.string.group_name)
editView.setFilterValues(groups.toList()) editView.setFilterValues(groups.toList())
editView.dropDownHeight = 180.dp editView.dropDownHeight = 180.dpToPx()
} }
customView { alertBinding.root } customView { alertBinding.root }
okButton { okButton {

@ -63,7 +63,7 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login) {
binding.flexbox.addView(it.root) binding.flexbox.addView(it.root)
it.root.id = index it.root.id = index
it.textView.text = rowUi.name it.textView.text = rowUi.name
it.textView.setPadding(16.dp) it.textView.setPadding(16.dpToPx())
it.root.onClick { it.root.onClick {
if (rowUi.action.isAbsUrl()) { if (rowUi.action.isAbsUrl()) {
context?.openUrl(rowUi.action!!) context?.openUrl(rowUi.action!!)

@ -42,9 +42,9 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
) { ) {
binding.run { binding.run {
if (holder.layoutPosition == itemCount - 1) { if (holder.layoutPosition == itemCount - 1) {
root.setPadding(16.dp, 12.dp, 16.dp, 12.dp) root.setPadding(16.dpToPx(), 12.dpToPx(), 16.dpToPx(), 12.dpToPx())
} else { } else {
root.setPadding(16.dp, 12.dp, 16.dp, 0) root.setPadding(16.dpToPx(), 12.dpToPx(), 16.dpToPx(), 0)
} }
if (payloads.isEmpty()) { if (payloads.isEmpty()) {
tvName.text = item.bookSourceName tvName.text = item.bookSourceName

@ -10,7 +10,7 @@ import android.text.StaticLayout
import android.util.AttributeSet import android.util.AttributeSet
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
class BatteryView @JvmOverloads constructor( class BatteryView @JvmOverloads constructor(
context: Context, context: Context,
@ -33,8 +33,8 @@ class BatteryView @JvmOverloads constructor(
private var battery: Int = 0 private var battery: Int = 0
init { init {
setPadding(4.dp, 3.dp, 6.dp, 3.dp) setPadding(4.dpToPx(), 3.dpToPx(), 6.dpToPx(), 3.dpToPx())
batteryPaint.strokeWidth = 1.dp.toFloat() batteryPaint.strokeWidth = 1f.dpToPx()
batteryPaint.isAntiAlias = true batteryPaint.isAntiAlias = true
batteryPaint.color = paint.color batteryPaint.color = paint.color
} }
@ -67,20 +67,20 @@ class BatteryView @JvmOverloads constructor(
layout.getLineBounds(0, outFrame) layout.getLineBounds(0, outFrame)
val batteryStart = layout val batteryStart = layout
.getPrimaryHorizontal(text.length - battery.toString().length) .getPrimaryHorizontal(text.length - battery.toString().length)
.toInt() + 2.dp .toInt() + 2.dpToPx()
val batteryEnd = val batteryEnd = batteryStart +
batteryStart + StaticLayout.getDesiredWidth(battery.toString(), paint).toInt() + 4.dp StaticLayout.getDesiredWidth(battery.toString(), paint).toInt() + 4.dpToPx()
outFrame.set( outFrame.set(
batteryStart, batteryStart,
2.dp, 2.dpToPx(),
batteryEnd, batteryEnd,
height - 2.dp height - 2.dpToPx()
) )
val dj = (outFrame.bottom - outFrame.top) / 3 val dj = (outFrame.bottom - outFrame.top) / 3
polar.set( polar.set(
batteryEnd, batteryEnd,
outFrame.top + dj, outFrame.top + dj,
batteryEnd + 2.dp, batteryEnd + 2.dpToPx(),
outFrame.bottom - dj outFrame.bottom - dj
) )
batteryPaint.style = Paint.Style.STROKE batteryPaint.style = Paint.Style.STROKE

@ -5,7 +5,7 @@ import android.util.AttributeSet
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import io.legado.app.ui.widget.text.AccentBgTextView import io.legado.app.ui.widget.text.AccentBgTextView
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
@Suppress("unused", "MemberVisibilityCanBePrivate") @Suppress("unused", "MemberVisibilityCanBePrivate")
class LabelsBar @JvmOverloads constructor( class LabelsBar @JvmOverloads constructor(
@ -40,10 +40,10 @@ class LabelsBar @JvmOverloads constructor(
fun addLabel(label: String) { fun addLabel(label: String) {
val tv = if (unUsedViews.isEmpty()) { val tv = if (unUsedViews.isEmpty()) {
AccentBgTextView(context, null).apply { AccentBgTextView(context, null).apply {
setPadding(3.dp, 0, 3.dp, 0) setPadding(3.dpToPx(), 0, 3.dpToPx(), 0)
setRadius(2) setRadius(2)
val lp = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) val lp = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
lp.setMargins(0, 0, 2.dp, 0) lp.setMargins(0, 0, 2.dpToPx(), 0)
layoutParams = lp layoutParams = lp
text = label text = label
maxLines = 1 maxLines = 1

@ -11,7 +11,7 @@ import android.util.AttributeSet
import android.view.View import android.view.View
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
/** /**
* RotateLoading * RotateLoading
@ -60,8 +60,8 @@ class RotateLoading @JvmOverloads constructor(
init { init {
loadingColor = context.accentColor loadingColor = context.accentColor
thisWidth = DEFAULT_WIDTH.dp thisWidth = DEFAULT_WIDTH.dpToPx()
shadowPosition = DEFAULT_SHADOW_POSITION.dp shadowPosition = DEFAULT_SHADOW_POSITION.dpToPx()
speedOfDegree = DEFAULT_SPEED_OF_DEGREE speedOfDegree = DEFAULT_SPEED_OF_DEGREE
if (null != attrs) { if (null != attrs) {
@ -70,7 +70,7 @@ class RotateLoading @JvmOverloads constructor(
typedArray.getColor(R.styleable.RotateLoading_loading_color, loadingColor) typedArray.getColor(R.styleable.RotateLoading_loading_color, loadingColor)
thisWidth = typedArray.getDimensionPixelSize( thisWidth = typedArray.getDimensionPixelSize(
R.styleable.RotateLoading_loading_width, R.styleable.RotateLoading_loading_width,
DEFAULT_WIDTH.dp DEFAULT_WIDTH.dpToPx()
) )
shadowPosition = typedArray.getInt( shadowPosition = typedArray.getInt(
R.styleable.RotateLoading_shadow_position, R.styleable.RotateLoading_shadow_position,

@ -9,7 +9,7 @@ import android.view.animation.LinearInterpolator
import android.widget.Checkable import android.widget.Checkable
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import kotlin.math.min import kotlin.math.min
import kotlin.math.pow import kotlin.math.pow
@ -127,7 +127,7 @@ class SmoothCheckBox @JvmOverloads constructor(
} }
private fun measureSize(measureSpec: Int): Int { private fun measureSize(measureSpec: Int): Int {
val defSize: Int = DEF_DRAW_SIZE.dp val defSize: Int = DEF_DRAW_SIZE.dpToPx()
val specSize = MeasureSpec.getSize(measureSpec) val specSize = MeasureSpec.getSize(measureSpec)
val specMode = MeasureSpec.getMode(measureSpec) val specMode = MeasureSpec.getMode(measureSpec)
var result = 0 var result = 0

@ -21,8 +21,7 @@ import androidx.appcompat.widget.AppCompatImageView
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
import io.legado.app.utils.printOnDebug import io.legado.app.utils.printOnDebug
import io.legado.app.utils.spToPx
import io.legado.app.utils.sp
import kotlin.math.min import kotlin.math.min
import kotlin.math.pow import kotlin.math.pow
@ -202,7 +201,7 @@ class CircleImageView @JvmOverloads constructor(
text?.let { text?.let {
textPaint.color = textColor textPaint.color = textColor
textPaint.isFakeBoldText = textBold textPaint.isFakeBoldText = textBold
textPaint.textSize = 15.sp.toFloat() textPaint.textSize = 15f.spToPx()
val fm = textPaint.fontMetrics val fm = textPaint.fontMetrics
canvas.drawText( canvas.drawText(
it, it,

@ -7,7 +7,7 @@ import android.graphics.Path
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView import androidx.appcompat.widget.AppCompatImageView
import io.legado.app.R import io.legado.app.R
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
import kotlin.math.max import kotlin.math.max
class FilletImageView @JvmOverloads constructor( class FilletImageView @JvmOverloads constructor(
@ -24,7 +24,7 @@ class FilletImageView @JvmOverloads constructor(
init { init {
// 读取配置 // 读取配置
val array = context.obtainStyledAttributes(attrs, R.styleable.FilletImageView) val array = context.obtainStyledAttributes(attrs, R.styleable.FilletImageView)
val defaultRadius = 5.dp val defaultRadius = 5.dpToPx()
val radius = val radius =
array.getDimensionPixelOffset(R.styleable.FilletImageView_radius, defaultRadius) array.getDimensionPixelOffset(R.styleable.FilletImageView_radius, defaultRadius)
leftTopRadius = array.getDimensionPixelOffset( leftTopRadius = array.getDimensionPixelOffset(

@ -24,7 +24,7 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.applyTint import io.legado.app.utils.applyTint
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
import io.legado.app.utils.setLayout import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.visible import io.legado.app.utils.visible
@ -120,7 +120,7 @@ class KeyboardAssistsConfig : BaseDialogFragment(R.layout.dialog_recycler_view),
override fun getViewBinding(parent: ViewGroup): Item1lineTextAndDelBinding { override fun getViewBinding(parent: ViewGroup): Item1lineTextAndDelBinding {
return Item1lineTextAndDelBinding.inflate(inflater, parent, false).apply { return Item1lineTextAndDelBinding.inflate(inflater, parent, false).apply {
root.setPadding(16.dp) root.setPadding(16.dpToPx())
ivDelete.visible() ivDelete.visible()
} }
} }

@ -8,7 +8,7 @@ import io.legado.app.R
import io.legado.app.lib.theme.Selector import io.legado.app.lib.theme.Selector
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
class AccentBgTextView @JvmOverloads constructor( class AccentBgTextView @JvmOverloads constructor(
@ -27,7 +27,7 @@ class AccentBgTextView @JvmOverloads constructor(
} }
fun setRadius(radius: Int) { fun setRadius(radius: Int) {
this.radius = radius.dp this.radius = radius.dpToPx()
upBackground() upBackground()
} }

@ -8,13 +8,13 @@ import io.legado.app.lib.theme.Selector
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.bottomBackground
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
class AccentStrokeTextView(context: Context, attrs: AttributeSet) : class AccentStrokeTextView(context: Context, attrs: AttributeSet) :
AppCompatTextView(context, attrs) { AppCompatTextView(context, attrs) {
private var radius = 3.dp private var radius = 3.dpToPx()
private val isBottomBackground: Boolean private val isBottomBackground: Boolean
init { init {
@ -39,7 +39,7 @@ class AccentStrokeTextView(context: Context, attrs: AttributeSet) :
} }
background = Selector.shapeBuild() background = Selector.shapeBuild()
.setCornerRadius(radius) .setCornerRadius(radius)
.setStrokeWidth(1.dp) .setStrokeWidth(1.dpToPx())
.setDisabledStrokeColor(disableColor) .setDisabledStrokeColor(disableColor)
.setDefaultStrokeColor(ThemeStore.accentColor(context)) .setDefaultStrokeColor(ThemeStore.accentColor(context))
.setPressedBgColor(context.getCompatColor(R.color.transparent30)) .setPressedBgColor(context.getCompatColor(R.color.transparent30))

@ -6,14 +6,14 @@ import androidx.appcompat.widget.AppCompatTextView
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.* import io.legado.app.lib.theme.*
import io.legado.app.utils.ColorUtils import io.legado.app.utils.ColorUtils
import io.legado.app.utils.dp import io.legado.app.utils.dpToPx
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
@Suppress("unused") @Suppress("unused")
open class StrokeTextView(context: Context, attrs: AttributeSet?) : open class StrokeTextView(context: Context, attrs: AttributeSet?) :
AppCompatTextView(context, attrs) { AppCompatTextView(context, attrs) {
private var radius = 1.dp private var radius = 1.dpToPx()
private val isBottomBackground: Boolean private val isBottomBackground: Boolean
init { init {
@ -26,7 +26,7 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) :
} }
fun setRadius(radius: Int) { fun setRadius(radius: Int) {
this.radius = radius.dp this.radius = radius.dpToPx()
upBackground() upBackground()
} }
@ -35,7 +35,7 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) :
isInEditMode -> { isInEditMode -> {
background = Selector.shapeBuild() background = Selector.shapeBuild()
.setCornerRadius(radius) .setCornerRadius(radius)
.setStrokeWidth(1.dp) .setStrokeWidth(1.dpToPx())
.setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500))
.setDefaultStrokeColor(context.getCompatColor(R.color.secondaryText)) .setDefaultStrokeColor(context.getCompatColor(R.color.secondaryText))
.setSelectedStrokeColor(context.getCompatColor(R.color.accent)) .setSelectedStrokeColor(context.getCompatColor(R.color.accent))
@ -53,7 +53,7 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) :
val isLight = ColorUtils.isColorLight(context.bottomBackground) val isLight = ColorUtils.isColorLight(context.bottomBackground)
background = Selector.shapeBuild() background = Selector.shapeBuild()
.setCornerRadius(radius) .setCornerRadius(radius)
.setStrokeWidth(1.dp) .setStrokeWidth(1.dpToPx())
.setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500))
.setDefaultStrokeColor(context.getPrimaryTextColor(isLight)) .setDefaultStrokeColor(context.getPrimaryTextColor(isLight))
.setSelectedStrokeColor(context.accentColor) .setSelectedStrokeColor(context.accentColor)
@ -70,7 +70,7 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) :
else -> { else -> {
background = Selector.shapeBuild() background = Selector.shapeBuild()
.setCornerRadius(radius) .setCornerRadius(radius)
.setStrokeWidth(1.dp) .setStrokeWidth(1.dpToPx())
.setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500))
.setDefaultStrokeColor(ThemeStore.textColorSecondary(context)) .setDefaultStrokeColor(ThemeStore.textColorSecondary(context))
.setSelectedStrokeColor(ThemeStore.accentColor(context)) .setSelectedStrokeColor(ThemeStore.accentColor(context))

@ -114,22 +114,17 @@ object ConvertUtils {
} }
val Int.dp: Int
get() = this.toFloat().dp.toInt()
val Int.sp: Int
get() = this.toFloat().sp.toInt()
val Int.hexString: String val Int.hexString: String
get() = Integer.toHexString(this) get() = Integer.toHexString(this)
fun Int.dpToPx(): Int = this.toFloat().dpToPx().toInt()
fun Int.spToPx(): Int = this.toFloat().spToPx().toInt()
val Float.dp: Float fun Float.dpToPx(): Float = android.util.TypedValue.applyDimension(
get() = android.util.TypedValue.applyDimension( android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics
android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics )
)
val Float.sp: Float fun Float.spToPx(): Float = android.util.TypedValue.applyDimension(
get() = android.util.TypedValue.applyDimension( android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics
android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics )
)
Loading…
Cancel
Save