Drop LayoutUtils
This commit is contained in:
1 parent
635de44299
commit
fb8de517a0
6 files changed
+35
-76
No files matched your search
@@ -17,7 +17,7 @@ import androidx.drawerlayout.widget.DrawerLayout.DrawerListener
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import com.drakeet.drawer.FullDraggableHelper
|
||||
import com.google.android.material.snackbar.Snackbar.SnackbarLayout
|
||||
import com.hippo.ehviewer.yorozuya.LayoutUtils.dp2pix
|
||||
import com.hippo.ehviewer.yorozuya.dp2px
|
||||
|
||||
class AboveSnackerLayout : FrameLayout, AttachedBehavior, FullDraggableHelper.Callback {
|
||||
private val helper: FullDraggableHelper
|
||||
@@ -195,7 +195,7 @@ class AboveSnackerLayout : FrameLayout, AttachedBehavior, FullDraggableHelper.Ca
|
||||
val view = child.getAboveSnackViewAt(i)
|
||||
if (view != null) {
|
||||
val translationY =
|
||||
(dependency.translationY - dependency.height - dp2pix(view.context, 8f))
|
||||
(dependency.translationY - dependency.height - dp2px(view.context, 8f))
|
||||
.coerceAtMost(0f)
|
||||
ViewCompat.animate(view).setInterpolator(FastOutSlowInInterpolator())
|
||||
.translationY(translationY).setDuration(150).start()
|
||||
|
||||
@@ -35,8 +35,8 @@ import com.hippo.ehviewer.ui.legacy.ViewTransition.OnShowViewListener
|
||||
import com.hippo.ehviewer.util.ExceptionUtils
|
||||
import com.hippo.ehviewer.util.getParcelableCompat
|
||||
import com.hippo.ehviewer.yorozuya.IntIdGenerator
|
||||
import com.hippo.ehviewer.yorozuya.LayoutUtils
|
||||
import com.hippo.ehviewer.yorozuya.collect.IntList
|
||||
import com.hippo.ehviewer.yorozuya.dp2px
|
||||
import rikka.core.res.resolveColor
|
||||
|
||||
class ContentLayout(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
|
||||
@@ -82,7 +82,7 @@ class ContentLayout(context: Context, attrs: AttributeSet? = null) : FrameLayout
|
||||
binding.refreshLayout.setProgressViewOffset(
|
||||
true,
|
||||
0,
|
||||
fitPaddingTop + LayoutUtils.dp2pix(context, 32f),
|
||||
fitPaddingTop + dp2px(context, 32f),
|
||||
) // TODO
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class ContentLayout(context: Context, attrs: AttributeSet? = null) : FrameLayout
|
||||
binding.fastScroller.paddingRight,
|
||||
mFastScrollerOriginBottom + fitPaddingBottom,
|
||||
)
|
||||
if (fitPaddingBottom > LayoutUtils.dp2pix(context, 16f)) {
|
||||
if (fitPaddingBottom > dp2px(context, 16f)) {
|
||||
binding.bottomProgress.setPadding(0, 0, 0, fitPaddingBottom)
|
||||
} else {
|
||||
binding.bottomProgress.setPadding(0, 0, 0, 0)
|
||||
@@ -235,7 +235,7 @@ class ContentLayout(context: Context, attrs: AttributeSet? = null) : FrameLayout
|
||||
}
|
||||
fun init(contentLayout: ContentLayout) {
|
||||
binding = contentLayout.binding
|
||||
mNextPageScrollSize = LayoutUtils.dp2pix(contentLayout.context, 48f)
|
||||
mNextPageScrollSize = dp2px(contentLayout.context, 48f)
|
||||
val drawable = ContextCompat.getDrawable(context, R.drawable.big_sad_pandroid)!!
|
||||
drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
|
||||
binding.tip.setCompoundDrawables(null, drawable, null, null)
|
||||
|
||||
@@ -30,9 +30,9 @@ import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver
|
||||
import com.google.android.material.math.MathUtils.dist
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.yorozuya.AnimationUtils
|
||||
import com.hippo.ehviewer.yorozuya.LayoutUtils.dp2pix
|
||||
import com.hippo.ehviewer.yorozuya.SimpleAnimatorListener
|
||||
import com.hippo.ehviewer.yorozuya.SimpleHandler
|
||||
import com.hippo.ehviewer.yorozuya.dp2px
|
||||
import kotlin.math.abs
|
||||
|
||||
class FastScroller : View {
|
||||
@@ -79,7 +79,7 @@ class FastScroller : View {
|
||||
a.recycle()
|
||||
alpha = 0.0f
|
||||
visibility = INVISIBLE
|
||||
mMinHandlerHeight = dp2pix(context, MIN_HANDLER_HEIGHT_DP.toFloat())
|
||||
mMinHandlerHeight = dp2px(context, MIN_HANDLER_HEIGHT_DP.toFloat())
|
||||
mTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||
mShowAnimator = ObjectAnimator.ofFloat(this, "alpha", 1.0f).apply {
|
||||
interpolator = AnimationUtils.FAST_SLOW_INTERPOLATOR
|
||||
|
||||
@@ -32,7 +32,7 @@ import com.hippo.ehviewer.ui.legacy.AutoStaggeredGridLayoutManager
|
||||
import com.hippo.ehviewer.ui.legacy.MarginItemDecoration
|
||||
import com.hippo.ehviewer.ui.legacy.STRATEGY_MIN_SIZE
|
||||
import com.hippo.ehviewer.ui.legacy.STRATEGY_SUITABLE_SIZE
|
||||
import com.hippo.ehviewer.yorozuya.LayoutUtils.dp2pix
|
||||
import com.hippo.ehviewer.yorozuya.dp2px
|
||||
import splitties.init.appCtx
|
||||
|
||||
abstract class GalleryAdapter(
|
||||
@@ -100,7 +100,7 @@ abstract class GalleryAdapter(
|
||||
}
|
||||
|
||||
TYPE_GRID -> {
|
||||
val columnWidth = dp2pix(appCtx, thumbSizeDp.toFloat())
|
||||
val columnWidth = dp2px(appCtx, thumbSizeDp.toFloat())
|
||||
mLayoutManager.setColumnSize(columnWidth)
|
||||
mLayoutManager.setStrategy(STRATEGY_SUITABLE_SIZE)
|
||||
if (null != mListDecoration) {
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.yorozuya;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public final class LayoutUtils {
|
||||
private LayoutUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* dp conversion to pix
|
||||
*
|
||||
* @param context The context
|
||||
* @param dp The value you want to conversion
|
||||
* @return value in pix
|
||||
*/
|
||||
public static int dp2pix(Context context, float dp) {
|
||||
return (int) (dp * context.getResources().getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* pix conversion to dp
|
||||
*
|
||||
* @param context The context
|
||||
* @param pix The value you want to conversion
|
||||
* @return value in dp
|
||||
*/
|
||||
public static float pix2dp(Context context, int pix) {
|
||||
return pix / context.getResources().getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
/**
|
||||
* sp conversion to pix
|
||||
*
|
||||
* @param sp The value you want to conversion
|
||||
* @return value in pix
|
||||
*/
|
||||
public static int sp2pix(Context context, float sp) {
|
||||
return (int) (sp * context.getResources().getDisplayMetrics().scaledDensity + 0.5f);
|
||||
}
|
||||
|
||||
/**
|
||||
* pix conversion to sp
|
||||
*
|
||||
* @param pix The value you want to conversion
|
||||
* @return value in sp
|
||||
*/
|
||||
public static float pix2sp(Context context, float pix) {
|
||||
return pix / context.getResources().getDisplayMetrics().scaledDensity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.yorozuya
|
||||
|
||||
import android.content.Context
|
||||
import android.util.TypedValue.COMPLEX_UNIT_DIP
|
||||
import android.util.TypedValue.applyDimension
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
fun dp2px(context: Context, dp: Float): Int {
|
||||
return applyDimension(COMPLEX_UNIT_DIP, dp, context.resources.displayMetrics).roundToInt()
|
||||
}
|
||||
Reference in new issue
Block a user