Skip to content

Commit

Permalink
Merge pull request #426 from lapism/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lapism authored Dec 29, 2021
2 parents 6726f77 + ed2e262 commit 0b47cfa
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 73 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![API](https://img.shields.io/badge/API-26%2B-brightgreen.svg?style=flat)
[![Kotlin Version](https://img.shields.io/badge/Kotlin-1.6.0-blue.svg)](https://kotlinlang.org)
[![Kotlin Version](https://img.shields.io/badge/Kotlin-blue.svg)](https://kotlinlang.org)
[![Download](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fio%2Fgithub%2Flapism%2Fsearch%2Fmaven-metadata.xml) ](https://repo1.maven.org/maven2/io/github/lapism/search/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

Expand Down Expand Up @@ -29,7 +29,7 @@ Add the dependency to your gradle file:
}
dependencies {
implementation 'io.github.lapism:search:1.1.0'
implementation 'io.github.lapism:search:1.2.0'
}
```

Expand Down Expand Up @@ -154,9 +154,9 @@ You have to use app theme Theme.Material3.* or Theme.MaterialComponents.*.
</attr>
<attr name="search_navigationIcon" format="reference" />
<attr name="search_navigationContentDescription" format="reference" />
<attr name="search_backgroundColor" format="reference" />
<attr name="search_radius" format="integer" />
<attr name="android:elevation" />
<attr name="search_navigationBackgroundColor" format="reference" />
<attr name="search_navigationElevation" format="dimension" />
<attr name="search_radius" format="dimension" />
<attr name="android:hint" />
<attr name="android:layout_marginStart" />
<attr name="android:layout_marginEnd" />
Expand All @@ -168,7 +168,8 @@ You have to use app theme Theme.Material3.* or Theme.MaterialComponents.*.
<attr name="search_navigationIconCompat" />
<attr name="search_navigationIcon" />
<attr name="search_navigationContentDescription" />
<attr name="search_backgroundColor" />
<attr name="search_navigationBackgroundColor" />
<attr name="search_navigationElevation" />
<attr name="search_clearIcon" format="reference" />
<attr name="search_dividerColor" format="reference" />
<attr name="search_scrimColor" format="reference" />
Expand Down
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ android {

dependencies {

// Core
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.5.0-beta01'
implementation 'com.google.android.material:material:1.6.0-alpha01'
}

ext {
Expand Down
44 changes: 22 additions & 22 deletions src/main/kotlin/com/lapism/search/widget/MaterialSearchBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,23 @@ class MaterialSearchBar @JvmOverloads constructor(
setNavigationContentDescription(description)
}

if (a?.hasValue(R.styleable.MaterialSearchBar_search_backgroundColor)!!) {
val color = a?.getInt(R.styleable.MaterialSearchBar_search_backgroundColor, 0)
setBackgroundColor(color!!)
if (a?.hasValue(R.styleable.MaterialSearchBar_search_navigationBackgroundColor)!!) {
val color = a?.getInt(R.styleable.MaterialSearchBar_search_navigationBackgroundColor, 0)
setNavigationBackgroundColor(color!!)
}

val defaultRadius = context.resources.getDimensionPixelSize(R.dimen.search_dp_24)
val customRadius = a?.getInt(R.styleable.MaterialSearchBar_search_radius, defaultRadius)
setRadius(customRadius?.toFloat()!!)
if (a?.hasValue(R.styleable.MaterialSearchBar_search_navigationElevation)!!) {
val navigationElevation =
a?.getDimensionPixelSize(
R.styleable.MaterialSearchBar_search_navigationElevation,
0
)
setNavigationElevation(navigationElevation?.toFloat()!!)
}

if (a?.hasValue(R.styleable.MaterialSearchBar_android_elevation)!!) {
val customElevation = a?.getInt(R.styleable.MaterialSearchBar_android_elevation, 0)
elevation = customElevation?.toFloat()!!
if (a?.hasValue(R.styleable.MaterialSearchBar_search_radius)!!) {
val customRadius = a?.getInt(R.styleable.MaterialSearchBar_search_radius, 0)
setRadius(customRadius?.toFloat()!!)
}

if (a?.hasValue(R.styleable.MaterialSearchBar_android_hint)!!) {
Expand Down Expand Up @@ -96,23 +101,19 @@ class MaterialSearchBar @JvmOverloads constructor(
binding.searchBarToolbar.setNavigationOnClickListener(listener)
}

// *********************************************************************************************
override fun setBackgroundColor(@ColorInt color: Int) {
override fun setNavigationElevation(elevation: Float) {
binding.searchBarCard.cardElevation = elevation
}

override fun setNavigationBackgroundColor(@ColorInt color: Int) {
binding.searchBarCard.setCardBackgroundColor(color)
}

// *********************************************************************************************
override fun setOnClickListener(@Nullable l: OnClickListener?) {
binding.searchBarToolbar.setOnClickListener(l)
}

override fun setElevation(elevation: Float) {
binding.searchBarCard.cardElevation = elevation
}

override fun getElevation(): Float {
return binding.searchBarCard.elevation
}

override fun onAttachedToWindow() {
super.onAttachedToWindow()

Expand Down Expand Up @@ -173,7 +174,7 @@ class MaterialSearchBar @JvmOverloads constructor(
}

// *********************************************************************************************
// TODO PUBLIC ? and requestLayout()
// TODO set public and requestLayout(), invalidate()
private fun setMargins(left: Int, top: Int, right: Int, bottom: Int) {
if (binding.searchBarCard.layoutParams is MarginLayoutParams) {
val params = binding.searchBarCard.layoutParams as? MarginLayoutParams
Expand All @@ -195,13 +196,12 @@ class MaterialSearchBar @JvmOverloads constructor(
child: View,
dependency: View
): Boolean {
super.onDependentViewChanged(parent, child, dependency)
if (dependency is AppBarLayout) {
dependency.setBackgroundColor(Color.TRANSPARENT)
dependency.stateListAnimator = null
ViewCompat.setElevation(dependency, 0.0f)
}
return false
return super.onDependentViewChanged(parent, child, dependency)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.annotation.Nullable
import androidx.annotation.StringRes
Expand Down Expand Up @@ -59,4 +60,8 @@ abstract class MaterialSearchLayout @JvmOverloads constructor(

abstract fun setNavigationOnClickListener(listener: OnClickListener)

abstract fun setNavigationElevation(elevation: Float)

abstract fun setNavigationBackgroundColor(@ColorInt color: Int)

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import android.view.LayoutInflater
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.TextView
import androidx.annotation.Nullable
import com.google.android.material.appbar.MaterialToolbar
import com.lapism.search.databinding.MaterialSearchToolbarBinding


class MaterialSearchToolbar : MaterialToolbar {
class MaterialSearchToolbar : MaterialTransparentToolbar {

// *********************************************************************************************
private var binding: MaterialSearchToolbarBinding
Expand Down
48 changes: 29 additions & 19 deletions src/main/kotlin/com/lapism/search/widget/MaterialSearchView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MaterialSearchView @JvmOverloads constructor(
})
binding.searchViewEditText.setOnEditorActionListener { _, _, _ ->
onSubmitQuery()
return@setOnEditorActionListener true // same as ,,true" :)
true
}
binding.searchViewEditText.setOnFocusChangeListener { _, hasFocus ->
visibility = if (hasFocus) {
Expand Down Expand Up @@ -104,9 +104,18 @@ class MaterialSearchView @JvmOverloads constructor(
setNavigationContentDescription(description)
}

if (a.hasValue(R.styleable.MaterialSearchView_search_backgroundColor)) {
val color = a.getInt(R.styleable.MaterialSearchView_search_backgroundColor, 0)
setBackgroundColor(color)
if (a.hasValue(R.styleable.MaterialSearchBar_search_navigationBackgroundColor)) {
val color = a.getInt(R.styleable.MaterialSearchBar_search_navigationBackgroundColor, 0)
setNavigationBackgroundColor(color)
}

if (a.hasValue(R.styleable.MaterialSearchView_search_navigationElevation)) {
val navigationElevation =
a.getDimensionPixelSize(
R.styleable.MaterialSearchView_search_navigationElevation,
0
)
setNavigationElevation(navigationElevation.toFloat())
}

if (a.hasValue(R.styleable.MaterialSearchView_search_clearIcon)) {
Expand Down Expand Up @@ -153,15 +162,6 @@ class MaterialSearchView @JvmOverloads constructor(
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 @@ -183,9 +183,17 @@ class MaterialSearchView @JvmOverloads constructor(
binding.searchViewToolbar.setNavigationOnClickListener(listener)
}

override fun setNavigationElevation(elevation: Float) {
binding.searchViewToolbar.elevation = elevation
}

override fun setNavigationBackgroundColor(@ColorInt color: Int) {
binding.searchViewToolbar.setBackgroundColor(color)
}

// *********************************************************************************************
override fun setBackgroundColor(@ColorInt color: Int) {
binding.searchViewBackground.setBackgroundColor(color)
binding.searchViewContentContainer.setBackgroundColor(color)
}

override fun addView(child: View) {
Expand Down Expand Up @@ -261,9 +269,7 @@ class MaterialSearchView @JvmOverloads constructor(
private fun onSubmitQuery() {
val query = binding.searchViewEditText.text
if (query != null && TextUtils.getTrimmedLength(query) > 0) {
if (queryListener == null || !queryListener!!.onQueryTextSubmit(query.toString())) {
hideKeyboard()
}
queryListener?.onQueryTextSubmit(query.toString())
}
}

Expand All @@ -279,6 +285,10 @@ class MaterialSearchView @JvmOverloads constructor(
binding.searchViewDivider.setBackgroundColor(color)
}

fun setDividerResource(@DrawableRes resid: Int) {
binding.searchViewDivider.setBackgroundResource(resid)
}

fun setScrimColor(@ColorInt color: Int) {
binding.searchViewScrim.setBackgroundColor(color)
}
Expand Down Expand Up @@ -340,9 +350,9 @@ class MaterialSearchView @JvmOverloads constructor(

interface OnQueryTextListener {

fun onQueryTextChange(newText: CharSequence): Boolean
fun onQueryTextChange(newText: CharSequence)

fun onQueryTextSubmit(query: CharSequence): Boolean
fun onQueryTextSubmit(query: CharSequence)
}

// *********************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.lapism.search.widget

import android.content.Context
import android.os.Build
import android.util.AttributeSet
import androidx.core.content.ContextCompat
import com.google.android.material.appbar.MaterialToolbar


open class MaterialTransparentToolbar : MaterialToolbar {

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

constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)

constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)

// *********************************************************************************************
init {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
outlineAmbientShadowColor = ContextCompat.getColor(context, android.R.color.transparent)
outlineSpotShadowColor = ContextCompat.getColor(context, android.R.color.transparent)
}
}

}
4 changes: 2 additions & 2 deletions src/main/res/layout/material_search_toolbar.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search_toolbar_text_view"
style="@style/MaterialSearchTextAppearance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:importantForAccessibility="no"
android:maxLines="1"
android:textSize="@dimen/search_sp_16" />
android:maxLines="1" />
24 changes: 11 additions & 13 deletions src/main/res/layout/material_search_view.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<View
android:id="@+id/search_view_scrim"
Expand All @@ -16,13 +15,13 @@
android:focusable="true"
android:focusableInTouchMode="true">

<LinearLayout
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/search_view_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:background="?attr/colorSurface">

<com.google.android.material.appbar.MaterialToolbar
<com.lapism.search.widget.MaterialTransparentToolbar
android:id="@+id/search_view_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -36,6 +35,7 @@

<com.lapism.search.internal.FocusEditText
android:id="@+id/search_view_edit_text"
style="@style/MaterialSearchTextAppearance"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
Expand All @@ -44,12 +44,9 @@
android:imeOptions="actionSearch|flagNoExtractUi"
android:importantForAutofill="no"
android:inputType="textNoSuggestions"
android:maxLines="1"
android:privateImeOptions="nm"
android:textColor="?android:attr/textColorPrimary"
android:textColorHint="?android:attr/textColorSecondary"
android:textDirection="firstStrong"
android:textSize="@dimen/search_sp_16"
tools:ignore="LabelFor" />
android:textDirection="firstStrong" />

<ImageButton
android:id="@+id/search_view_clear_button"
Expand All @@ -61,7 +58,7 @@

</LinearLayout>

</com.google.android.material.appbar.MaterialToolbar>
</com.lapism.search.widget.MaterialTransparentToolbar>

<View
android:id="@+id/search_view_divider"
Expand All @@ -72,9 +69,10 @@
<FrameLayout
android:id="@+id/search_view_content_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:background="?attr/colorSurface" />

</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>

</com.lapism.search.internal.ClippableRoundedCornerLayout>

Expand Down
Loading

0 comments on commit 0b47cfa

Please sign in to comment.