Skip to content

Commit 666e1ad

Browse files
authored
Merge pull request #432 from lapism/dev
2.0.0
2 parents a6c93b1 + 5570269 commit 666e1ad

File tree

13 files changed

+182
-109
lines changed

13 files changed

+182
-109
lines changed

README.md

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,43 @@
44
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
55

66
# Search
7+
78
- Search component for Android
89
- Material You Design
910
- Styling
1011
- Kotlin
1112

1213
![Search](https://github.com/lapism/Search/blob/master/images/search.png)
1314

14-
## Apps with this library
15-
16-
* [LapIcons](https://play.google.com/store/apps/details?id=com.lapism.lapicons)
17-
1815
## Api
19-
- minSdkVersion = 26
16+
17+
- minSdkVersion = 21
2018
- targetSdkVersion = 31
2119
- Java = 1.8
2220
- Kotlin = 1.8
2321

2422
Add the dependency to your gradle file:
25-
```groovy
26-
repositories {
27-
google()
28-
mavenCentral()
29-
}
3023

31-
dependencies {
32-
implementation 'io.github.lapism:search:1.2.1'
33-
}
24+
```groovy
25+
repositories {
26+
google()
27+
mavenCentral()
28+
}
29+
30+
dependencies {
31+
implementation 'io.github.lapism:search:2.0.0'
32+
}
3433
```
3534

3635
## Usage
36+
3737
```java
3838
binding.materialSearchView.requestFocus()
3939
binding.materialSearchView.clearFocus()
4040
```
4141

4242
### MaterialSearchBar
43+
4344
```java
4445
val toolbar = binding.materialSearchBar.getToolbar()
4546
setSupportActionBar(toolbar)
@@ -57,6 +58,7 @@ Add the dependency to your gradle file:
5758
```
5859

5960
### MaterialSearchView
61+
6062
```java
6163
binding.materialSearchView.apply {
6264
addView(recyclerView)
@@ -83,6 +85,7 @@ Add the dependency to your gradle file:
8385
```
8486

8587
### Layout
88+
8689
You have to use app theme Theme.Material3.* or Theme.MaterialComponents.*.
8790

8891
```xml
@@ -138,42 +141,46 @@ You have to use app theme Theme.Material3.* or Theme.MaterialComponents.*.
138141
```
139142

140143
### XML attributes
144+
141145
```xml
142-
<declare-styleable name="MaterialSearchBar">
143-
<attr name="search_navigationIconCompat" format="enum">
144-
<enum name="none" value="0" />
145-
<enum name="arrow" value="1" />
146-
<enum name="search" value="2" />
147-
</attr>
148-
<attr name="search_navigationIcon" format="reference" />
149-
<attr name="search_navigationContentDescription" format="reference" />
150-
<attr name="search_navigationBackgroundColor" format="reference" />
151-
<attr name="search_navigationElevation" format="dimension" />
152-
<attr name="search_radius" format="dimension" />
153-
<attr name="android:hint" />
154-
<attr name="android:layout_marginStart" />
155-
<attr name="android:layout_marginEnd" />
156-
<attr name="android:layout_marginTop" />
157-
<attr name="android:layout_marginBottom" />
158-
</declare-styleable>
159-
160-
<declare-styleable name="MaterialSearchView">
161-
<attr name="search_navigationIconCompat" />
162-
<attr name="search_navigationIcon" />
163-
<attr name="search_navigationContentDescription" />
164-
<attr name="search_navigationBackgroundColor" />
165-
<attr name="search_navigationElevation" />
166-
<attr name="search_clearIcon" format="reference" />
167-
<attr name="search_dividerColor" format="reference" />
168-
<attr name="search_scrimColor" format="reference" />
169-
<attr name="android:hint" />
170-
<attr name="android:imeOptions" />
171-
<attr name="android:inputType" />
172-
</declare-styleable>
146+
147+
<declare-styleable name="MaterialSearchBar">
148+
<attr name="search_navigationIconCompat" format="enum">
149+
<enum name="none" value="0" />
150+
<enum name="arrow" value="1" />
151+
<enum name="search" value="2" />
152+
</attr>
153+
<attr name="search_navigationIcon" format="reference" />
154+
<attr name="search_navigationContentDescription" format="reference" />
155+
<attr name="search_navigationBackgroundColor" format="reference" />
156+
<attr name="search_navigationElevation" format="dimension" />
157+
<attr name="search_radius" format="dimension" />
158+
<attr name="android:hint" />
159+
<attr name="android:layout_marginStart" />
160+
<attr name="android:layout_marginEnd" />
161+
<attr name="android:layout_marginTop" />
162+
<attr name="android:layout_marginBottom" />
163+
</declare-styleable>
164+
165+
<declare-styleable name="MaterialSearchView">
166+
<attr name="search_navigationIconCompat" />
167+
<attr name="search_navigationIcon" />
168+
<attr name="search_navigationContentDescription" />
169+
<attr name="search_navigationBackgroundColor" />
170+
<attr name="search_navigationElevation" />
171+
<attr name="search_clearIcon" format="reference" />
172+
<attr name="search_dividerColor" format="reference" />
173+
<attr name="search_scrimColor" format="reference" />
174+
<attr name="android:hint" />
175+
<attr name="android:imeOptions" />
176+
<attr name="android:inputType" />
177+
</declare-styleable>
173178
```
174179

175180
## Todo
181+
176182
**Animation**
183+
177184
- animation like Google, needs help :)
178185

179186
## Author

build.gradle

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
plugins {
22
id 'com.android.library'
3-
id 'kotlin-android'
3+
id 'org.jetbrains.kotlin.android'
44
}
55

66
android {
7-
compileSdk 31
8-
buildToolsVersion "31.0.0"
7+
namespace 'com.lapism.search'
8+
compileSdk 33
9+
buildToolsVersion "33.0.0"
910

1011
defaultConfig {
11-
minSdk 26
12-
targetSdk 31
13-
versionCode 1020100
14-
versionName "1.2.1"
12+
minSdk 21
13+
targetSdk 33
14+
versionCode 2000000
15+
versionName "2.0.0"
1516
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1617
consumerProguardFiles "consumer-rules.pro"
1718
}
@@ -32,24 +33,30 @@ android {
3233
jvmTarget = '1.8'
3334
}
3435

36+
buildFeatures {
37+
viewBinding true
38+
}
39+
3540
sourceSets {
3641
main.java.srcDirs += 'src/main/kotlin'
3742
}
3843

39-
buildFeatures {
40-
viewBinding true
44+
publishing {
45+
singleVariant('release') {
46+
withSourcesJar()
47+
}
4148
}
4249
}
4350

4451
dependencies {
4552

46-
implementation 'androidx.appcompat:appcompat:1.4.0'
47-
implementation 'com.google.android.material:material:1.6.0-alpha01'
53+
implementation 'androidx.appcompat:appcompat:1.7.0-alpha01'
54+
implementation 'com.google.android.material:material:1.8.0-alpha03'
4855
}
4956

5057
ext {
5158
PUBLISH_GROUP_ID = 'io.github.lapism'
52-
PUBLISH_VERSION = '1.2.1'
59+
PUBLISH_VERSION = '2.0.0'
5360
PUBLISH_ARTIFACT_ID = 'search'
5461
PUBLISH_DESCRIPTION = 'Material You Search component for Android, SearchView'
5562
PUBLISH_URL = 'https://github.com/lapism/search'

src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.lapism.search">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
43

54
<application android:supportsRtl="true" />
65

src/main/kotlin/com/lapism/search/internal/ClippableRoundedCornerLayout.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lapism.search.internal
33
import android.content.Context
44
import android.graphics.Canvas
55
import android.graphics.Path
6+
import android.graphics.RectF
67
import android.util.AttributeSet
78
import android.widget.FrameLayout
89

@@ -15,19 +16,30 @@ class ClippableRoundedCornerLayout @JvmOverloads constructor(
1516
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {
1617

1718
// *********************************************************************************************
18-
// TODO CLIP ANIMATION
19-
var path: Path? = null
19+
private var radius: Float = 0.0f
20+
21+
// *********************************************************************************************
22+
init {
23+
setWillNotDraw(false)
24+
}
2025

2126
// *********************************************************************************************
2227
override fun dispatchDraw(canvas: Canvas?) {
23-
if (path == null) {
28+
canvas?.let {
29+
val rect = RectF(0F, 0F, canvas.width.toFloat(), canvas.height.toFloat())
30+
val path = Path()
31+
path.addRoundRect(rect, radius, radius, Path.Direction.CW)
32+
33+
val save = canvas.save()
34+
canvas.clipPath(path)
2435
super.dispatchDraw(canvas)
25-
return
36+
canvas.restoreToCount(save)
2637
}
27-
val save = canvas?.save()
28-
canvas?.clipPath(path!!)
29-
super.dispatchDraw(canvas)
30-
canvas?.restoreToCount(save!!)
38+
}
39+
40+
fun setRadius(radius: Float) {
41+
this.radius = radius
42+
invalidate()
3143
}
3244

3345
}

src/main/kotlin/com/lapism/search/internal/FocusEditText.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ class FocusEditText @JvmOverloads constructor(
1313
) : AppCompatEditText(context, attrs, defStyleAttr) {
1414

1515
// *********************************************************************************************
16-
private var textClear: Boolean = false
16+
private var clear: Boolean = false
17+
private var clearFocus: Boolean = false
1718

1819
// *********************************************************************************************
1920
override fun onKeyPreIme(keyCode: Int, event: KeyEvent?): Boolean {
20-
if (keyCode == KeyEvent.KEYCODE_BACK && event?.action == KeyEvent.ACTION_UP && textClear) {
21+
if (keyCode == KeyEvent.KEYCODE_BACK && event?.action == KeyEvent.ACTION_UP && clear) {
2122
if (hasFocus()) {
2223
clearFocus()
2324
return true
@@ -28,12 +29,18 @@ class FocusEditText @JvmOverloads constructor(
2829

2930
override fun clearFocus() {
3031
super.clearFocus()
31-
text?.clear() // TODO FIX
32+
if (clearFocus) {
33+
text?.clear()
34+
}
3235
}
3336

3437
// *********************************************************************************************
3538
fun setTextClearOnBackPressed(clear: Boolean) {
36-
textClear = clear
39+
this.clear = clear
40+
}
41+
42+
fun setTextClearOnClearFocus(clearFocus: Boolean) {
43+
this.clearFocus = clearFocus
3744
}
3845

3946
}

0 commit comments

Comments
 (0)