aboutsummaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
Diffstat (limited to 'library/src')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/searchview/SearchCard.kt31
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt11
-rw-r--r--library/src/main/res/layout/kau_search_view.xml7
3 files changed, 42 insertions, 7 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()
}
}
diff --git a/library/src/main/res/layout/kau_search_view.xml b/library/src/main/res/layout/kau_search_view.xml
index 8b07403..4a46e90 100644
--- a/library/src/main/res/layout/kau_search_view.xml
+++ b/library/src/main/res/layout/kau_search_view.xml
@@ -2,7 +2,7 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
- android:layout_height="wrap_content">
+ android:layout_height="match_parent">
<View
android:id="@+id/search_shadow"
@@ -11,7 +11,7 @@
android:background="@color/kau_search_full_shadow"
android:visibility="gone" />
- <android.support.v7.widget.CardView
+ <ca.allanwang.kau.searchview.SearchCard
android:id="@+id/search_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -101,11 +101,12 @@
android:id="@+id/search_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+
android:overScrollMode="never"
android:visibility="gone" />
</LinearLayout>
- </android.support.v7.widget.CardView>
+ </ca.allanwang.kau.searchview.SearchCard>
</merge> \ No newline at end of file