Skip to content

Commit

Permalink
Merge pull request #432 from lapism/dev
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
lapism authored Nov 30, 2022
2 parents a6c93b1 + 5570269 commit 666e1ad
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 109 deletions.
95 changes: 51 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,43 @@
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

# Search

- Search component for Android
- Material You Design
- Styling
- Kotlin

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

## Apps with this library

* [LapIcons](https://play.google.com/store/apps/details?id=com.lapism.lapicons)

## Api
- minSdkVersion = 26

- minSdkVersion = 21
- targetSdkVersion = 31
- Java = 1.8
- Kotlin = 1.8

Add the dependency to your gradle file:
```groovy
repositories {
google()
mavenCentral()
}

dependencies {
implementation 'io.github.lapism:search:1.2.1'
}
```groovy
repositories {
google()
mavenCentral()
}
dependencies {
implementation 'io.github.lapism:search:2.0.0'
}
```

## Usage

```java
binding.materialSearchView.requestFocus()
binding.materialSearchView.clearFocus()
```

### MaterialSearchBar

```java
val toolbar = binding.materialSearchBar.getToolbar()
setSupportActionBar(toolbar)
Expand All @@ -57,6 +58,7 @@ Add the dependency to your gradle file:
```

### MaterialSearchView

```java
binding.materialSearchView.apply {
addView(recyclerView)
Expand All @@ -83,6 +85,7 @@ Add the dependency to your gradle file:
```

### Layout

You have to use app theme Theme.Material3.* or Theme.MaterialComponents.*.

```xml
Expand Down Expand Up @@ -138,42 +141,46 @@ You have to use app theme Theme.Material3.* or Theme.MaterialComponents.*.
```

### XML attributes

```xml
<declare-styleable name="MaterialSearchBar">
<attr name="search_navigationIconCompat" format="enum">
<enum name="none" value="0" />
<enum name="arrow" value="1" />
<enum name="search" value="2" />
</attr>
<attr name="search_navigationIcon" format="reference" />
<attr name="search_navigationContentDescription" format="reference" />
<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" />
<attr name="android:layout_marginTop" />
<attr name="android:layout_marginBottom" />
</declare-styleable>

<declare-styleable name="MaterialSearchView">
<attr name="search_navigationIconCompat" />
<attr name="search_navigationIcon" />
<attr name="search_navigationContentDescription" />
<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" />
<attr name="android:hint" />
<attr name="android:imeOptions" />
<attr name="android:inputType" />
</declare-styleable>

<declare-styleable name="MaterialSearchBar">
<attr name="search_navigationIconCompat" format="enum">
<enum name="none" value="0" />
<enum name="arrow" value="1" />
<enum name="search" value="2" />
</attr>
<attr name="search_navigationIcon" format="reference" />
<attr name="search_navigationContentDescription" format="reference" />
<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" />
<attr name="android:layout_marginTop" />
<attr name="android:layout_marginBottom" />
</declare-styleable>

<declare-styleable name="MaterialSearchView">
<attr name="search_navigationIconCompat" />
<attr name="search_navigationIcon" />
<attr name="search_navigationContentDescription" />
<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" />
<attr name="android:hint" />
<attr name="android:imeOptions" />
<attr name="android:inputType" />
</declare-styleable>
```

## Todo

**Animation**

- animation like Google, needs help :)

## Author
Expand Down
31 changes: 19 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk 31
buildToolsVersion "31.0.0"
namespace 'com.lapism.search'
compileSdk 33
buildToolsVersion "33.0.0"

defaultConfig {
minSdk 26
targetSdk 31
versionCode 1020100
versionName "1.2.1"
minSdk 21
targetSdk 33
versionCode 2000000
versionName "2.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
Expand All @@ -32,24 +33,30 @@ android {
jvmTarget = '1.8'
}

buildFeatures {
viewBinding true
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

buildFeatures {
viewBinding true
publishing {
singleVariant('release') {
withSourcesJar()
}
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.6.0-alpha01'
implementation 'androidx.appcompat:appcompat:1.7.0-alpha01'
implementation 'com.google.android.material:material:1.8.0-alpha03'
}

ext {
PUBLISH_GROUP_ID = 'io.github.lapism'
PUBLISH_VERSION = '1.2.1'
PUBLISH_VERSION = '2.0.0'
PUBLISH_ARTIFACT_ID = 'search'
PUBLISH_DESCRIPTION = 'Material You Search component for Android, SearchView'
PUBLISH_URL = 'https://github.com/lapism/search'
Expand Down
3 changes: 1 addition & 2 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lapism.search">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application android:supportsRtl="true" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.lapism.search.internal
import android.content.Context
import android.graphics.Canvas
import android.graphics.Path
import android.graphics.RectF
import android.util.AttributeSet
import android.widget.FrameLayout

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

// *********************************************************************************************
// TODO CLIP ANIMATION
var path: Path? = null
private var radius: Float = 0.0f

// *********************************************************************************************
init {
setWillNotDraw(false)
}

// *********************************************************************************************
override fun dispatchDraw(canvas: Canvas?) {
if (path == null) {
canvas?.let {
val rect = RectF(0F, 0F, canvas.width.toFloat(), canvas.height.toFloat())
val path = Path()
path.addRoundRect(rect, radius, radius, Path.Direction.CW)

val save = canvas.save()
canvas.clipPath(path)
super.dispatchDraw(canvas)
return
canvas.restoreToCount(save)
}
val save = canvas?.save()
canvas?.clipPath(path!!)
super.dispatchDraw(canvas)
canvas?.restoreToCount(save!!)
}

fun setRadius(radius: Float) {
this.radius = radius
invalidate()
}

}
15 changes: 11 additions & 4 deletions src/main/kotlin/com/lapism/search/internal/FocusEditText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ class FocusEditText @JvmOverloads constructor(
) : AppCompatEditText(context, attrs, defStyleAttr) {

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

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

override fun clearFocus() {
super.clearFocus()
text?.clear() // TODO FIX
if (clearFocus) {
text?.clear()
}
}

// *********************************************************************************************
fun setTextClearOnBackPressed(clear: Boolean) {
textClear = clear
this.clear = clear
}

fun setTextClearOnClearFocus(clearFocus: Boolean) {
this.clearFocus = clearFocus
}

}
Loading

0 comments on commit 666e1ad

Please sign in to comment.