From f68c73041612eb4a55ca25b5b88eb20f3ba01cb9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 13 Mar 2022 10:41:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/lib/theme/MaterialValueHelper.kt | 6 ++--- .../app/lib/theme/view/ThemeRadioNoButton.kt | 10 ++++---- .../ui/association/ImportBookSourceDialog.kt | 2 +- .../ui/association/ImportReplaceRuleDialog.kt | 2 +- .../ui/association/ImportRssSourceDialog.kt | 2 +- .../app/ui/book/info/BookInfoActivity.kt | 2 +- .../io/legado/app/ui/book/read/ReadMenu.kt | 2 +- .../ui/book/read/config/MoreConfigDialog.kt | 4 ++-- .../ui/book/read/config/ReadStyleDialog.kt | 2 +- .../legado/app/ui/book/read/page/PageView.kt | 16 ++++++------- .../read/page/provider/ChapterProvider.kt | 18 +++++++-------- .../book/source/manage/BookSourceActivity.kt | 4 ++-- .../legado/app/ui/login/SourceLoginDialog.kt | 2 +- .../app/ui/main/explore/ExploreAdapter.kt | 4 ++-- .../io/legado/app/ui/widget/BatteryView.kt | 18 +++++++-------- .../java/io/legado/app/ui/widget/LabelsBar.kt | 6 ++--- .../app/ui/widget/anima/RotateLoading.kt | 8 +++---- .../app/ui/widget/checkbox/SmoothCheckBox.kt | 4 ++-- .../app/ui/widget/image/CircleImageView.kt | 5 ++-- .../app/ui/widget/image/FilletImageView.kt | 4 ++-- .../widget/keyboard/KeyboardAssistsConfig.kt | 4 ++-- .../app/ui/widget/text/AccentBgTextView.kt | 4 ++-- .../ui/widget/text/AccentStrokeTextView.kt | 6 ++--- .../app/ui/widget/text/StrokeTextView.kt | 12 +++++----- .../io/legado/app/utils/ConvertExtensions.kt | 23 ++++++++----------- 25 files changed, 82 insertions(+), 88 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt index 116fa7a18..d19b6634c 100644 --- a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt @@ -11,7 +11,7 @@ import androidx.fragment.app.Fragment import io.legado.app.R import io.legado.app.help.config.AppConfig import io.legado.app.utils.ColorUtils -import io.legado.app.utils.dp +import io.legado.app.utils.dpToPx /** * @author Karim Abou Zeid (kabouzeid) @@ -127,14 +127,14 @@ val Context.elevation: Float resources.getDimension(R.dimen.design_appbar_elevation) ) } else { - AppConfig.elevation.dp.toFloat() + AppConfig.elevation.toFloat().dpToPx() } } val Context.filletBackground: GradientDrawable get() { val background = GradientDrawable() - background.cornerRadius = 3F.dp + background.cornerRadius = 3f.dpToPx() background.setColor(backgroundColor) return background } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/theme/view/ThemeRadioNoButton.kt b/app/src/main/java/io/legado/app/lib/theme/view/ThemeRadioNoButton.kt index 34724ca9d..40ea925d1 100644 --- a/app/src/main/java/io/legado/app/lib/theme/view/ThemeRadioNoButton.kt +++ b/app/src/main/java/io/legado/app/lib/theme/view/ThemeRadioNoButton.kt @@ -9,7 +9,7 @@ import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.utils.ColorUtils -import io.legado.app.utils.dp +import io.legado.app.utils.dpToPx import io.legado.app.utils.getCompatColor class ThemeRadioNoButton(context: Context, attrs: AttributeSet) : @@ -32,8 +32,8 @@ class ThemeRadioNoButton(context: Context, attrs: AttributeSet) : val isLight = ColorUtils.isColorLight(context.bottomBackground) val textColor = context.getPrimaryTextColor(isLight) background = Selector.shapeBuild() - .setCornerRadius(2.dp) - .setStrokeWidth(2.dp) + .setCornerRadius(2.dpToPx()) + .setStrokeWidth(2.dpToPx()) .setCheckedBgColor(context.accentColor) .setCheckedStrokeColor(context.accentColor) .setDefaultStrokeColor(textColor) @@ -48,8 +48,8 @@ class ThemeRadioNoButton(context: Context, attrs: AttributeSet) : else -> { val textColor = context.getCompatColor(R.color.primaryText) background = Selector.shapeBuild() - .setCornerRadius(2.dp) - .setStrokeWidth(2.dp) + .setCornerRadius(2.dpToPx()) + .setStrokeWidth(2.dpToPx()) .setCheckedBgColor(context.accentColor) .setCheckedStrokeColor(context.accentColor) .setDefaultStrokeColor(textColor) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt index ccc7820e9..bd47e6470 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceDialog.kt @@ -164,7 +164,7 @@ class ImportBookSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_vie } textInputLayout.setHint(R.string.group_name) editView.setFilterValues(groups.toList()) - editView.dropDownHeight = 180.dp + editView.dropDownHeight = 180.dpToPx() } customView { alertBinding.root diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt index 66490bf7a..895b0f8eb 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleDialog.kt @@ -140,7 +140,7 @@ class ImportReplaceRuleDialog() : BaseDialogFragment(R.layout.dialog_recycler_vi } textInputLayout.setHint(R.string.group_name) editView.setFilterValues(groups.toList()) - editView.dropDownHeight = 180.dp + editView.dropDownHeight = 180.dpToPx() } customView { alertBinding.root diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt index 8334a9b10..8ac19ba45 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceDialog.kt @@ -163,7 +163,7 @@ class ImportRssSourceDialog() : BaseDialogFragment(R.layout.dialog_recycler_view } textInputLayout.setHint(R.string.group_name) editView.setFilterValues(groups.toList()) - editView.dropDownHeight = 180.dp + editView.dropDownHeight = 180.dpToPx() } customView { alertBinding.root diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 46e8efe38..2f799f20e 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -394,7 +394,7 @@ class BookInfoActivity : setText(R.string.delete_book_file) } val view = LinearLayout(this@BookInfoActivity).apply { - setPadding(16.dp, 0, 16.dp, 0) + setPadding(16.dpToPx(), 0, 16.dpToPx(), 0) addView(checkBox) } customView { view } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 77489307a..0d4eec250 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -86,7 +86,7 @@ class ReadMenu @JvmOverloads constructor( } initAnimation() val brightnessBackground = GradientDrawable() - brightnessBackground.cornerRadius = 5F.dp + brightnessBackground.cornerRadius = 5F.dpToPx() brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f)) llBrightness.background = brightnessBackground llBottomBg.setBackgroundColor(bgColor) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 12cb2e23e..adf6afd12 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -18,7 +18,7 @@ import io.legado.app.lib.theme.primaryColor import io.legado.app.model.ReadBook import io.legado.app.ui.book.read.ReadBookActivity 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.postEvent import io.legado.app.utils.setEdgeEffectColor @@ -36,7 +36,7 @@ class MoreConfigDialog : DialogFragment() { attr.dimAmount = 0.0f attr.gravity = Gravity.BOTTOM attributes = attr - setLayout(ViewGroup.LayoutParams.MATCH_PARENT, 360.dp) + setLayout(ViewGroup.LayoutParams.MATCH_PARENT, 360.dpToPx()) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index cea371594..eca08ee46 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -80,7 +80,7 @@ class ReadStyleDialog : BaseDialogFragment(R.layout.dialog_read_book_style), rvStyle.adapter = styleAdapter styleAdapter.addFooterView { 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.setColorFilter(textColor) ivStyle.borderColor = textColor diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 8dab898b4..f09bc7195 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -73,16 +73,16 @@ class PageView(context: Context) : FrameLayout(context) { tvFooterRight.setColor(tipColor) upStatusBar() llHeader.setPadding( - it.headerPaddingLeft.dp, - it.headerPaddingTop.dp, - it.headerPaddingRight.dp, - it.headerPaddingBottom.dp + it.headerPaddingLeft.dpToPx(), + it.headerPaddingTop.dpToPx(), + it.headerPaddingRight.dpToPx(), + it.headerPaddingBottom.dpToPx() ) llFooter.setPadding( - it.footerPaddingLeft.dp, - it.footerPaddingTop.dp, - it.footerPaddingRight.dp, - it.footerPaddingBottom.dp + it.footerPaddingLeft.dpToPx(), + it.footerPaddingTop.dpToPx(), + it.footerPaddingRight.dpToPx(), + it.footerPaddingBottom.dpToPx() ) vwTopDivider.visible(it.showHeaderLine) vwBottomDivider.visible(it.showFooterLine) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index e3c35e0b5..8a676c873 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -181,7 +181,7 @@ object ChapterProvider { } } } - textPages.last().height = durY + 20.dp + textPages.last().height = durY + 20.dpToPx() textPages.last().text = stringBuilder.toString() textPages.forEachIndexed { index, item -> item.index = index @@ -537,8 +537,8 @@ object ChapterProvider { //间距 lineSpacingExtra = ReadBookConfig.lineSpacingExtra / 10f paragraphSpacing = ReadBookConfig.paragraphSpacing - titleTopSpacing = ReadBookConfig.titleTopSpacing.dp - titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dp + titleTopSpacing = ReadBookConfig.titleTopSpacing.dpToPx() + titleBottomSpacing = ReadBookConfig.titleBottomSpacing.dpToPx() upLayout() } @@ -593,14 +593,14 @@ object ChapterProvider { tPaint.color = ReadBookConfig.textColor tPaint.letterSpacing = ReadBookConfig.letterSpacing tPaint.typeface = titleFont - tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.sp.toFloat() + tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.toFloat().spToPx() tPaint.isAntiAlias = true //正文 val cPaint = TextPaint() cPaint.color = ReadBookConfig.textColor cPaint.letterSpacing = ReadBookConfig.letterSpacing cPaint.typeface = textFont - cPaint.textSize = ReadBookConfig.textSize.sp.toFloat() + cPaint.textSize = ReadBookConfig.textSize.toFloat().spToPx() cPaint.isAntiAlias = true return Pair(tPaint, cPaint) } @@ -625,10 +625,10 @@ object ChapterProvider { && ReadBook.pageAnim() != 3 && AppConfig.doublePageHorizontal if (viewWidth > 0 && viewHeight > 0) { - paddingLeft = ReadBookConfig.paddingLeft.dp - paddingTop = ReadBookConfig.paddingTop.dp - paddingRight = ReadBookConfig.paddingRight.dp - paddingBottom = ReadBookConfig.paddingBottom.dp + paddingLeft = ReadBookConfig.paddingLeft.dpToPx() + paddingTop = ReadBookConfig.paddingTop.dpToPx() + paddingRight = ReadBookConfig.paddingRight.dpToPx() + paddingBottom = ReadBookConfig.paddingBottom.dpToPx() visibleWidth = if (doublePage) { viewWidth / 2 - paddingLeft - paddingRight } else { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index d9ced7f7f..19b473a02 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -389,7 +389,7 @@ class BookSourceActivity : VMBaseActivity { background = Selector.shapeBuild() .setCornerRadius(radius) - .setStrokeWidth(1.dp) + .setStrokeWidth(1.dpToPx()) .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) .setDefaultStrokeColor(context.getCompatColor(R.color.secondaryText)) .setSelectedStrokeColor(context.getCompatColor(R.color.accent)) @@ -53,7 +53,7 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) : val isLight = ColorUtils.isColorLight(context.bottomBackground) background = Selector.shapeBuild() .setCornerRadius(radius) - .setStrokeWidth(1.dp) + .setStrokeWidth(1.dpToPx()) .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) .setDefaultStrokeColor(context.getPrimaryTextColor(isLight)) .setSelectedStrokeColor(context.accentColor) @@ -70,7 +70,7 @@ open class StrokeTextView(context: Context, attrs: AttributeSet?) : else -> { background = Selector.shapeBuild() .setCornerRadius(radius) - .setStrokeWidth(1.dp) + .setStrokeWidth(1.dpToPx()) .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500)) .setDefaultStrokeColor(ThemeStore.textColorSecondary(context)) .setSelectedStrokeColor(ThemeStore.accentColor(context)) diff --git a/app/src/main/java/io/legado/app/utils/ConvertExtensions.kt b/app/src/main/java/io/legado/app/utils/ConvertExtensions.kt index 0453efcd6..214cc207a 100644 --- a/app/src/main/java/io/legado/app/utils/ConvertExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ConvertExtensions.kt @@ -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 get() = Integer.toHexString(this) +fun Int.dpToPx(): Int = this.toFloat().dpToPx().toInt() + +fun Int.spToPx(): Int = this.toFloat().spToPx().toInt() -val Float.dp: Float - get() = android.util.TypedValue.applyDimension( - android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics - ) +fun Float.dpToPx(): Float = android.util.TypedValue.applyDimension( + android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics +) -val Float.sp: Float - get() = android.util.TypedValue.applyDimension( - android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics - ) \ No newline at end of file +fun Float.spToPx(): Float = android.util.TypedValue.applyDimension( + android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics +) \ No newline at end of file