Skip to content

Commit 66b9d28

Browse files
q-litzlerPLNech
authored andcommitted
Compatibility with SDK 16
1 parent 03cb6ba commit 66b9d28

File tree

14 files changed

+69
-50
lines changed

14 files changed

+69
-50
lines changed

app/src/main/res/layout/main.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
style="@style/Widget.MaterialComponents.Button"
2929
app:layout_constraintBottom_toTopOf="@id/buttonPermission"
3030
android:layout_marginEnd="24dp"
31+
android:layout_marginRight="24dp"
3132
android:text="@string/button_voice"
3233
android:textAllCaps="false"
3334
android:textAppearance="?attr/textAppearanceSubtitle2"
3435
android:textSize="16sp"
3536
app:cornerRadius="6dp"
3637
android:layout_marginStart="24dp"
38+
android:layout_marginLeft="24dp"
3739
app:layout_constraintVertical_chainStyle="packed"
3840
android:layout_width="0dp"
3941
android:layout_height="56dp"/>

dependency.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ext.with {
22
sdkCompile = 28
3-
sdkMin = 14
3+
sdkMin = 16
44
sdkTarget = 28
55

66
versioningName = '1.0'

ui/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ android {
3434
versionName versioningName
3535

3636
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
37-
37+
vectorDrawables.useSupportLibrary = true
3838
}
3939
buildTypes {
4040
release {

ui/src/main/kotlin/com/algolia/instantsearch/voice/ui/RippleView.kt

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class RippleView : View {
3939

4040
override fun run() {
4141
invalidate()
42-
postRunnableFps(this, fps)
42+
postOnAnimation(this)
4343
}
4444
}
4545

@@ -51,7 +51,7 @@ class RippleView : View {
5151
override fun run() {
5252
animations[index] = circles[index].circleAnimation().also { it.start() }
5353
index = if (index == circles.lastIndex) 0 else index + 1
54-
postRunnableAnimation(this)
54+
postOnAnimationDelayed(this, delay)
5555
}
5656
}
5757

@@ -68,7 +68,7 @@ class RippleView : View {
6868
State.Playing -> {
6969
animations.values.forEach { it.end() }
7070
animations.clear()
71-
postRunnableAnimation(runnableAnimation)
71+
postOnAnimationDelayed(runnableAnimation, delay)
7272
}
7373
State.Stopped -> removeCallbacks(runnableAnimation)
7474
State.None -> Unit
@@ -77,7 +77,7 @@ class RippleView : View {
7777

7878
override fun onAttachedToWindow() {
7979
super.onAttachedToWindow()
80-
postRunnableFps(runnableFps, fps)
80+
postOnAnimation(runnableFps)
8181
}
8282

8383
override fun onDetachedFromWindow() {
@@ -100,22 +100,6 @@ class RippleView : View {
100100
}.recycle()
101101
}
102102

103-
private fun postRunnableAnimation(runnable: Runnable) {
104-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
105-
postOnAnimationDelayed(runnable, delay)
106-
} else {
107-
postDelayed(runnable, delay)
108-
}
109-
}
110-
111-
private fun postRunnableFps(runnable: Runnable, fps: Long) {
112-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
113-
postOnAnimation(runnable)
114-
} else {
115-
postDelayed(runnable, fps)
116-
}
117-
}
118-
119103
private fun DrawableSprite.circleAnimation(): AnimatorSet =
120104
AnimatorSet().also {
121105
it.duration = duration

ui/src/main/kotlin/com/algolia/instantsearch/voice/ui/VoiceMicrophone.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package com.algolia.instantsearch.voice.ui
22

33
import android.content.Context
44
import android.content.res.ColorStateList
5+
import android.graphics.ColorFilter
6+
import android.graphics.PorterDuff
7+
import android.graphics.PorterDuffColorFilter
58
import android.support.v4.content.ContextCompat
9+
import android.support.v7.widget.AppCompatImageView
610
import android.util.AttributeSet
711
import android.widget.ImageView
812
import com.algolia.instantsearch.voice.ui.R
913

1014

11-
class VoiceMicrophone(context: Context, attrs: AttributeSet) : ImageView(context, attrs) {
15+
class VoiceMicrophone(context: Context, attrs: AttributeSet) : AppCompatImageView(context, attrs) {
1216

1317
enum class State {
1418
Activated,
@@ -21,13 +25,14 @@ class VoiceMicrophone(context: Context, attrs: AttributeSet) : ImageView(context
2125
var state = State.Deactivated
2226
set(value) {
2327
field = value
24-
imageTintList = ColorStateList.valueOf(when (value) {
28+
drawable.colorFilter = PorterDuffColorFilter(when (value) {
2529
State.Activated -> white
2630
State.Deactivated -> blue
27-
})
28-
backgroundTintList = when (value) {
31+
}, PorterDuff.Mode.SRC_IN)
32+
33+
background.colorFilter = when (value) {
2934
State.Activated -> null
30-
State.Deactivated -> ColorStateList.valueOf(white)
35+
State.Deactivated -> PorterDuffColorFilter(white, PorterDuff.Mode.SRC_IN)
3136
}
3237
}
3338
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:color="?attr/colorControlHighlight">
5+
6+
<item android:drawable="@drawable/button_negative_background"/>
7+
</ripple>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:color="?attr/colorControlHighlight">
5+
6+
<item android:drawable="@drawable/button_positive_background"/>
7+
</ripple>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:color="?attr/colorControlHighlight">
5+
6+
<item android:drawable="@drawable/microphone_background"/>
7+
</ripple>
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<ripple
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:color="?attr/colorControlHighlight">
5-
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
63
<item android:drawable="@drawable/button_negative_background"/>
7-
</ripple>
4+
</selector>
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<ripple
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:color="?attr/colorControlHighlight">
5-
6-
<item android:drawable="@drawable/button_positive_background"/>
7-
</ripple>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:drawable="@drawable/button_positive_background" />
4+
</selector>

0 commit comments

Comments
 (0)