@@ -3,7 +3,6 @@ package com.lapism.search.widget
33import android.content.Context
44import android.graphics.Rect
55import android.graphics.drawable.Drawable
6- import android.os.Build
76import android.os.Parcel
87import android.os.Parcelable
98import android.text.Editable
@@ -16,11 +15,9 @@ import android.widget.FrameLayout
1615import android.widget.ImageButton
1716import android.widget.LinearLayout
1817import androidx.annotation.*
19- import androidx.coordinatorlayout.widget.CoordinatorLayout
2018import androidx.core.content.ContextCompat
2119import androidx.customview.view.AbsSavedState
2220import androidx.transition.*
23- import com.google.android.material.appbar.AppBarLayout
2421import com.google.android.material.appbar.MaterialToolbar
2522import com.lapism.search.R
2623import com.lapism.search.internal.FocusEditText
@@ -32,8 +29,7 @@ class MaterialSearchView @JvmOverloads constructor(
3229 attrs : AttributeSet ? = null ,
3330 defStyleAttr : Int = 0 ,
3431 defStyleRes : Int = 0
35- ) : MaterialSearchLayout(context, attrs, defStyleAttr, defStyleRes),
36- CoordinatorLayout .AttachedBehavior {
32+ ) : MaterialSearchLayout(context, attrs, defStyleAttr, defStyleRes) {
3733
3834 private var scrim: View ? = null
3935 private var background: LinearLayout ? = null
@@ -234,6 +230,14 @@ class MaterialSearchView @JvmOverloads constructor(
234230 queryListener = listener
235231 }
236232
233+ private fun showAnimation () {
234+ // TODO
235+ }
236+
237+ private fun hideAnimation () {
238+ // TODO
239+ }
240+
237241 fun showKeyboard () {
238242 if (! isInEditMode) {
239243 val inputMethodManager =
@@ -245,14 +249,6 @@ class MaterialSearchView @JvmOverloads constructor(
245249 }
246250 }
247251
248- private fun showAnimation () {
249- // TODO
250- }
251-
252- private fun hideAnimation () {
253- // TODO
254- }
255-
256252 fun hideKeyboard () {
257253 if (! isInEditMode) {
258254 val inputMethodManager =
@@ -299,7 +295,6 @@ class MaterialSearchView @JvmOverloads constructor(
299295 superState?.let {
300296 val state = SavedState (it)
301297 state.text = getTextQuery().toString()
302- state.hasFocus = editText?.hasFocus()!!
303298 return state
304299 } ? : run {
305300 return superState
@@ -310,18 +305,11 @@ class MaterialSearchView @JvmOverloads constructor(
310305 if (state is SavedState ) {
311306 super .onRestoreInstanceState(state.superState)
312307 setTextQuery(state.text, false )
313- if (state.hasFocus) {
314- editText?.requestFocus()
315- }
316308 } else {
317309 super .onRestoreInstanceState(state)
318310 }
319311 }
320312
321- override fun getBehavior (): CoordinatorLayout .Behavior <* > {
322- return Behavior ()
323- }
324-
325313 interface OnFocusChangeListener {
326314
327315 fun onFocusChange (hasFocus : Boolean )
@@ -339,35 +327,20 @@ class MaterialSearchView @JvmOverloads constructor(
339327 fun onClearClick ()
340328 }
341329
342- // NOT INNER CLASS = STATIC,
343330 @Suppress(" unused" )
344331 class SavedState : AbsSavedState {
345332
346333 var text: String? = null
347- var textChar: CharSequence? = null // TODO unused
348- var hasFocus = false
349334
350335 constructor (superState: Parcelable ) : super (superState)
351336
352337 constructor (source: Parcel , loader: ClassLoader ? = null ) : super (source, loader) {
353338 text = source.readString()
354- textChar = TextUtils .CHAR_SEQUENCE_CREATOR .createFromParcel(source)
355- hasFocus = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
356- source.readBoolean()
357- } else {
358- source.readInt() == 1
359- }
360339 }
361340
362341 override fun writeToParcel (dest : Parcel , flags : Int ) {
363342 super .writeToParcel(dest, flags)
364343 dest.writeString(text)
365- TextUtils .writeToParcel(textChar, dest, flags)
366- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
367- dest.writeBoolean(hasFocus)
368- } else {
369- dest.writeInt(if (hasFocus) 1 else 0 )
370- }
371344 }
372345
373346 companion object {
@@ -392,31 +365,4 @@ class MaterialSearchView @JvmOverloads constructor(
392365
393366 }
394367
395- class Behavior : CoordinatorLayout .Behavior <MaterialSearchView >() {
396-
397- override fun layoutDependsOn (
398- parent : CoordinatorLayout ,
399- child : MaterialSearchView ,
400- dependency : View
401- ): Boolean {
402- return if (dependency is AppBarLayout ) {
403- true
404- } else {
405- super .layoutDependsOn(parent, child, dependency)
406- }
407- }
408-
409- override fun onDependentViewChanged (
410- parent : CoordinatorLayout ,
411- child : MaterialSearchView ,
412- dependency : View
413- ): Boolean {
414- if (dependency is AppBarLayout ) {
415- return true
416- }
417- return super .onDependentViewChanged(parent, child, dependency)
418- }
419-
420- }
421-
422368}
0 commit comments