Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Lapiš committed Oct 29, 2021
1 parent 81f4272 commit 92678fd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ class ClippableRoundedCornerLayout @JvmOverloads constructor(
defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {

// *********************************************************************************************
// TODO CLIP ANIMATION
var path: Path? = null

// *********************************************************************************************
override fun dispatchDraw(canvas: Canvas?) {
if (path == null) {
super.dispatchDraw(canvas)
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/lapism/search/internal/FocusEditText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class FocusEditText @JvmOverloads constructor(
defStyleAttr: Int = 0
) : AppCompatEditText(context, attrs, defStyleAttr) {

// *********************************************************************************************
private var textClear: Boolean = false

// *********************************************************************************************
override fun onKeyPreIme(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_BACK && event?.action == KeyEvent.ACTION_UP && textClear) {
if (hasFocus()) {
Expand All @@ -29,6 +31,7 @@ class FocusEditText @JvmOverloads constructor(
text?.clear()
}

// *********************************************************************************************
fun setTextClearOnBackPressed(clear: Boolean) {
textClear = clear
}
Expand Down
42 changes: 18 additions & 24 deletions src/main/kotlin/com/lapism/search/widget/MaterialSearchBar.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package com.lapism.search.widget

import android.content.Context
import android.content.res.ColorStateList
import android.content.res.TypedArray
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.annotation.Nullable
import androidx.annotation.StringRes
import androidx.annotation.*
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.ViewCompat
import com.google.android.material.appbar.AppBarLayout
import com.lapism.search.R
import com.lapism.search.databinding.MaterialSearchBarBinding


@Suppress("unused", "MemberVisibilityCanBePrivate")
class MaterialSearchBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
Expand Down Expand Up @@ -157,37 +156,32 @@ class MaterialSearchBar @JvmOverloads constructor(
binding.searchBarToolbar.setHint(hint)
}

/*
fun setForegroundColor(){
}
fun setBackgroundColor(){
}
fun setForegroundColor(@Nullable foregroundColor: ColorStateList?) {
binding.searchBarCard.setCardForegroundColor(foregroundColor)
}

fun setStrokeWidth(){
fun setStrokeWidth(@Dimension strokeWidth: Int) {
binding.searchBarCard.strokeWidth = strokeWidth
}

}
fun setStrokeColor(strokeColor: ColorStateList) {
binding.searchBarCard.setStrokeColor(strokeColor)
}

fun setStrokeColor{
card?.setStrokeColor()
}
*/
fun setRadius(radius: Float) {
binding.searchBarCard.radius = radius
}

fun setMargins(left: Int, top: Int, right: Int, bottom: Int) {
// *********************************************************************************************
// TODO PUBLIC ? and requestLayout()
private fun setMargins(left: Int, top: Int, right: Int, bottom: Int) {
if (binding.searchBarCard.layoutParams is MarginLayoutParams) {
val params = binding.searchBarCard.layoutParams as? MarginLayoutParams
params?.setMargins(left, top, right, bottom)
binding.searchBarCard.layoutParams = params
// requestLayout() TODO
}
}

fun setRadius(radius: Float) {
binding.searchBarCard.radius = radius
}

// *********************************************************************************************
@Suppress("unused")
class ScrollingViewBehavior : AppBarLayout.ScrollingViewBehavior {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ abstract class MaterialSearchLayout @JvmOverloads constructor(
defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {

// *********************************************************************************************
@NavigationIconCompat
@get:NavigationIconCompat
var navigationIconCompat: Int = 0
Expand Down Expand Up @@ -47,6 +48,7 @@ abstract class MaterialSearchLayout @JvmOverloads constructor(
}
}

// *********************************************************************************************
abstract fun setNavigationIcon(@DrawableRes resId: Int)

abstract fun setNavigationIcon(@Nullable drawable: Drawable?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import com.lapism.search.databinding.MaterialSearchToolbarBinding

class MaterialSearchToolbar : MaterialToolbar {

// *********************************************************************************************
private var binding: MaterialSearchToolbarBinding

// *********************************************************************************************
constructor(context: Context) : super(context)

constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
Expand All @@ -26,11 +28,13 @@ class MaterialSearchToolbar : MaterialToolbar {
defStyleAttr
)

// *********************************************************************************************
init {
val inflater = LayoutInflater.from(context)
binding = MaterialSearchToolbarBinding.inflate(inflater, this, true)
}

// *********************************************************************************************
override fun setTitle(resId: Int) {

}
Expand Down Expand Up @@ -58,17 +62,17 @@ class MaterialSearchToolbar : MaterialToolbar {
}
}

override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo?) {
override fun onInitializeAccessibilityNodeInfo(info: AccessibilityNodeInfo) {
super.onInitializeAccessibilityNodeInfo(info)
info?.className = TextView::class.java.canonicalName
info.className = TextView::class.java.canonicalName
var text: CharSequence? = getText()
val isEmpty = TextUtils.isEmpty(text)
info?.hintText = getHint()
info?.isShowingHintText = isEmpty
info.hintText = getHint()
info.isShowingHintText = isEmpty
if (isEmpty) {
text = getHint()
}
info?.text = text
info.text = text
}

// *********************************************************************************************
Expand Down
24 changes: 12 additions & 12 deletions src/main/kotlin/com/lapism/search/widget/MaterialSearchView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.lapism.search.R
import com.lapism.search.databinding.MaterialSearchViewBinding


@Suppress("MemberVisibilityCanBePrivate", "unused")
class MaterialSearchView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
Expand All @@ -33,7 +34,6 @@ class MaterialSearchView @JvmOverloads constructor(
private var binding: MaterialSearchViewBinding
private var focusListener: OnFocusChangeListener? = null
private var queryListener: OnQueryTextListener? = null
private var clearClickListener: OnClearClickListener? = null

// *********************************************************************************************
init {
Expand Down Expand Up @@ -79,7 +79,6 @@ class MaterialSearchView @JvmOverloads constructor(

binding.searchViewClearButton.visibility = View.GONE
binding.searchViewClearButton.setOnClickListener {
clearClickListener?.onClearClick()
binding.searchViewEditText.text?.clear()
}

Expand Down Expand Up @@ -151,11 +150,18 @@ class MaterialSearchView @JvmOverloads constructor(

a.recycle()

// TODO ANIMATE binding.seachViewClip.path

visibility = View.GONE
}

/* TODO styles + codes, ANIMATE binding.searchViewClip.path, SCALE, path
private fun setTransition() {
val mTransition = LayoutTransition()
mTransition.enableTransitionType(LayoutTransition.CHANGING)
mTransition.setDuration(3000L)
binding.searchViewBackground.layoutTransition = mTransition
}*/

// *********************************************************************************************
override fun setNavigationIcon(@DrawableRes resId: Int) {
binding.searchViewToolbar.setNavigationIcon(resId)
Expand All @@ -182,7 +188,7 @@ class MaterialSearchView @JvmOverloads constructor(
binding.searchViewBackground.setBackgroundColor(color)
}

override fun addView(child: View?) {
override fun addView(child: View) {
binding.searchViewContentContainer.addView(child)
}

Expand Down Expand Up @@ -219,7 +225,6 @@ class MaterialSearchView @JvmOverloads constructor(
}

// *********************************************************************************************
// TODO ANOTACE, NAZVY PROMENNCYH
fun setClearIcon(@Nullable drawable: Drawable?) {
binding.searchViewClearButton.setImageDrawable(drawable)
}
Expand Down Expand Up @@ -340,14 +345,9 @@ class MaterialSearchView @JvmOverloads constructor(
fun onQueryTextSubmit(query: CharSequence): Boolean
}

interface OnClearClickListener {

fun onClearClick()
}

// *********************************************************************************************
@Suppress("unused")
class SavedState : AbsSavedState {
private class SavedState : AbsSavedState {

var text: String? = null
var focus: Boolean = false
Expand Down

0 comments on commit 92678fd

Please sign in to comment.