diff options
Diffstat (limited to 'core-ui/src/main/kotlin/ca/allanwang/kau/ui/views')
3 files changed, 33 insertions, 4 deletions
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/BoundedCardView.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/BoundedCardView.kt index db002b9..5fc3e06 100644 --- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/BoundedCardView.kt +++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/BoundedCardView.kt @@ -1,10 +1,11 @@ package ca.allanwang.kau.ui.views import android.content.Context +import android.graphics.Rect import android.support.v7.widget.CardView import android.util.AttributeSet import ca.allanwang.kau.ui.R -import ca.allanwang.kau.utils.parentVisibleHeight +import ca.allanwang.kau.utils.parentViewGroup /** @@ -29,6 +30,8 @@ class BoundedCardView @JvmOverloads constructor( */ var maxHeightPercent: Float = -1.0f + private val parentFrame = Rect() + init { if (attrs != null) { val styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.BoundedCardView) @@ -39,7 +42,8 @@ class BoundedCardView @JvmOverloads constructor( } override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - var maxMeasureHeight = if (maxHeight > 0) maxHeight else parentVisibleHeight + parentViewGroup.getWindowVisibleDisplayFrame(parentFrame) + var maxMeasureHeight = if (maxHeight > 0) maxHeight else parentFrame.height() if (maxHeightPercent > 0f) maxMeasureHeight = (maxMeasureHeight * maxHeightPercent).toInt() val trueHeightMeasureSpec = MeasureSpec.makeMeasureSpec(maxMeasureHeight, MeasureSpec.AT_MOST) super.onMeasure(widthMeasureSpec, trueHeightMeasureSpec) diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt index 42f19b9..9e8ac11 100644 --- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt +++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt @@ -27,7 +27,7 @@ import android.view.View import ca.allanwang.kau.ui.R import ca.allanwang.kau.utils.dimenPixelSize import ca.allanwang.kau.utils.getFont -import ca.allanwang.kau.utils.parentVisibleHeight +import ca.allanwang.kau.utils.parentViewGroup import ca.allanwang.kau.utils.toBitmap /** @@ -66,6 +66,7 @@ class CutoutView @JvmOverloads constructor( private var heightPercentage: Float = 0f private var minHeight: Float = 0f private val maxTextSize: Float + private val parentFrame = Rect() init { if (attrs != null) { @@ -121,7 +122,8 @@ class CutoutView @JvmOverloads constructor( * If height percent is specified, ensure it is met */ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - val minHeight = Math.max(minHeight, heightPercentage * parentVisibleHeight) + parentViewGroup.getWindowVisibleDisplayFrame(parentFrame) + val minHeight = Math.max(minHeight, heightPercentage * parentFrame.height()) val trueHeightMeasureSpec = if (minHeight > 0) MeasureSpec.makeMeasureSpec(Math.max(minHeight.toInt(), measuredHeight), MeasureSpec.EXACTLY) else heightMeasureSpec diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/MeasuredImageView.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/MeasuredImageView.kt new file mode 100644 index 0000000..2627d13 --- /dev/null +++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/MeasuredImageView.kt @@ -0,0 +1,23 @@ +package ca.allanwang.kau.ui.views + +import android.content.Context +import android.util.AttributeSet +import android.widget.ImageView + +/** + * Created by Allan Wang on 2017-07-14. + */ +class MeasuredImageView @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 +) : ImageView(context, attrs, defStyleAttr, defStyleRes), MeasureSpecContract by MeasureSpecDelegate() { + + init { + initAttrs(context, attrs) + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + val result = onMeasure(this, widthMeasureSpec, heightMeasureSpec) + super.onMeasure(result.first, result.second) + } + +}
\ No newline at end of file |