aboutsummaryrefslogtreecommitdiff
path: root/library/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/main')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt2
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt30
2 files changed, 26 insertions, 6 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt
index 0c6b768..6103e50 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/kpref/KPrefActivity.kt
@@ -75,7 +75,7 @@ abstract class KPrefActivity : AppCompatActivity(), KPrefActivityContract {
toolbar.setNavigationOnClickListener { onBackPressed() }
setDisplayShowTitleEnabled(false)
}
- window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+ window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
statusBarColor = 0x30000000
toolbarCanvas.set(resolveColor(R.attr.colorPrimary))
bgCanvas.set(resolveColor(android.R.attr.colorBackground))
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 4f2bf50..8ffc871 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
@@ -47,6 +47,12 @@ class SearchView @JvmOverloads constructor(
field = value
tintForeground(value)
}
+ var backgroundColor: Int = 0xfffafafa.toInt()
+ set(value) {
+ if (field == value) return
+ field = value
+ tintBackground(value)
+ }
var navIcon: IIcon? = GoogleMaterial.Icon.gmd_arrow_back
set(value) {
field = value
@@ -65,7 +71,7 @@ class SearchView @JvmOverloads constructor(
iconClear.setIcon(value)
if (value == null) iconClear.gone()
}
- var revealDuration: Long = 700L
+ var revealDuration: Long = 300L
var shouldClearOnOpen: Boolean = true
var openListener: (() -> Unit)? = null
var closeListener: (() -> Unit)? = null
@@ -96,6 +102,7 @@ class SearchView @JvmOverloads constructor(
iconMic.setIcon(configs.micIcon)
iconClear.setIcon(configs.clearIcon)
tintForeground(configs.foregroundColor)
+ tintBackground(configs.backgroundColor)
with(recycler) {
layoutManager = LinearLayoutManager(context)
addOnScrollListener(object : RecyclerView.OnScrollListener() {
@@ -108,6 +115,10 @@ class SearchView @JvmOverloads constructor(
}
}
+ internal fun ImageView.setSearchIcon(iicon: IIcon) {
+ setIcon(iicon, sizeDp = 20, color = configs.foregroundColor)
+ }
+
fun config(config: Configs.() -> Unit) {
configs.config()
}
@@ -118,16 +129,21 @@ class SearchView @JvmOverloads constructor(
val item = menu.findItem(id)
if (item.icon == null) item.icon = GoogleMaterial.Icon.gmd_search.toDrawable(context, 20)
card.gone()
- item.setOnMenuItemClickListener { KL.e("Click"); getMenuItemCoords(it); revealOpen(); true }
+ item.setOnMenuItemClickListener { configureCoords(it); revealOpen(); true }
shadow.setOnClickListener { revealClose() }
}
- fun getMenuItemCoords(item: MenuItem) {
+ fun configureCoords(item: MenuItem) {
val view = parent.findViewById<View>(item.itemId) ?: return
val locations = IntArray(2)
view.getLocationOnScreen(locations)
- revealX = locations[0]
- revealY = locations[1]
+ revealX = (locations[0] + view.width / 2)
+ revealY = (locations[1] + view.height / 2)
+ val topAlignment = revealY - card.height / 2
+ val params = (card.layoutParams as MarginLayoutParams).apply {
+ topMargin = topAlignment
+ }
+ card.layoutParams = params
}
fun tintForeground(@ColorInt color: Int) {
@@ -137,6 +153,10 @@ class SearchView @JvmOverloads constructor(
SearchItem.foregroundColor = color
}
+ fun tintBackground(@ColorInt color: Int) {
+ card.setCardBackgroundColor(color)
+ }
+
fun revealOpen() {
if (isOpen) return
card.circularReveal(revealX, revealY, duration = configs.revealDuration,