diff options
Diffstat (limited to 'library/src/main/kotlin/ca')
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/searchview/SearchCard.kt | 31 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt | 11 |
2 files changed, 38 insertions, 4 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchCard.kt b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchCard.kt new file mode 100644 index 0000000..77da6b0 --- /dev/null +++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchCard.kt @@ -0,0 +1,31 @@ +package ca.allanwang.kau.searchview + +import android.content.Context +import android.graphics.Rect +import android.support.v7.widget.CardView +import android.util.AttributeSet +import android.view.ViewGroup + +/** + * Created by Allan Wang on 2017-06-26. + * + * CardView with a limited height + * Leaves space for users to tap to exit and ensures that all search items are visible + */ +class SearchCard @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 +) : CardView(context, attrs, defStyleAttr) { + + val parentVisibleHeight: Int + get() { + val r = Rect() + (parent as ViewGroup).getWindowVisibleDisplayFrame(r) + return r.height() + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + val trueHeightMeasureSpec = MeasureSpec.makeMeasureSpec((parentVisibleHeight * 0.9f).toInt(), MeasureSpec.AT_MOST) + super.onMeasure(widthMeasureSpec, trueHeightMeasureSpec) + } + +}
\ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt index c85450b..3b4afae 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt @@ -8,7 +8,10 @@ import android.support.annotation.ColorInt import android.support.annotation.IdRes import android.support.annotation.StringRes import android.support.transition.AutoTransition -import android.support.v7.widget.* +import android.support.v7.widget.AppCompatEditText +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.support.v7.widget.SimpleItemAnimator import android.util.AttributeSet import android.view.* import android.widget.FrameLayout @@ -154,7 +157,7 @@ class SearchView @JvmOverloads constructor( val configs = Configs() //views private val shadow: View by bindView(R.id.search_shadow) - private val card: CardView by bindView(R.id.search_cardview) + private val card: SearchCard by bindView(R.id.search_cardview) private val iconNav: ImageView by bindView(R.id.search_nav) private val editText: AppCompatEditText by bindView(R.id.search_edit_text) val textEvents: Observable<String> @@ -302,8 +305,8 @@ class SearchView @JvmOverloads constructor( * The cardView matches the parent's width, so menuX is correct */ configs.openListener?.invoke(this) + editText.showKeyboard() card.circularReveal(menuX, menuHalfHeight, duration = configs.revealDuration) { - editText.showKeyboard() cardTransition() recycler.visible() shadow.fadeIn() @@ -312,7 +315,6 @@ class SearchView @JvmOverloads constructor( fun revealClose() { if (!isOpen) return - editText.hideKeyboard() shadow.fadeOut(duration = configs.transitionDuration) cardTransition { addEndListener { @@ -325,6 +327,7 @@ class SearchView @JvmOverloads constructor( } } recycler.gone() + editText.hideKeyboard() } } |