Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit d779d42

Browse files
committed
isTouchable property(also as xml attribute) + bug fix for issue #15
1 parent 82ffbbb commit d779d42

File tree

7 files changed

+21
-3
lines changed

7 files changed

+21
-3
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ dependencies {
2828
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
2929
implementation "com.android.support:recyclerview-v7:27.1.1"
3030
implementation 'com.android.support:appcompat-v7:27.1.1'
31-
implementation 'com.github.alxrm:audiowave-progressbar:0.9.1'
31+
implementation 'com.github.alxrm:audiowave-progressbar:0.9.2'
3232

3333
implementation "com.jakewharton:butterknife:8.8.1"
3434
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"
3535

36-
// compile project(':audiowave')
36+
// implementation project(':audiowave')
3737
}
3838
repositories {
3939
mavenCentral()

app/src/main/kotlin/rm/com/audiogram/MainActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package rm.com.audiogram
33
import android.animation.ObjectAnimator
44
import android.content.Intent
55
import android.os.Bundle
6+
import android.support.v4.content.ContextCompat
67
import android.support.v7.app.AppCompatActivity
78
import android.util.Log
89
import android.view.animation.LinearInterpolator
@@ -41,6 +42,11 @@ class MainActivity : AppCompatActivity() {
4142

4243
wave.onProgressChanged = { progress, byUser ->
4344
Log.e("wave", "Progress set: $progress, and it's $byUser that user did this")
45+
46+
if (progress == 100F && !byUser) {
47+
wave.waveColor = ContextCompat.getColor(this, R.color.colorAccent)
48+
wave.isTouchable = true
49+
}
4450
}
4551

4652
wave.onStartTracking = {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
app:chunkRadius="1dp"
2424
app:chunkSpacing="1dp"
2525
app:chunkWidth="3dp"
26+
app:touchable="true"
2627
app:minChunkHeight="2dp"
2728
app:progress="0.0"
2829
app:waveColor="@android:color/black"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
android:layout_margin="16dp"
2020
app:chunkHeight="24dp"
2121
app:chunkRadius="1dp"
22+
app:touchable="false"
2223
app:chunkSpacing="1dp"
2324
app:chunkWidth="3dp"
2425
app:minChunkHeight="2dp"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
app:animateExpansion="false"
3232
app:chunkHeight="16dp"
3333
app:chunkRadius="1dp"
34+
app:touchable="true"
3435
app:chunkSpacing="1dp"
3536
app:chunkWidth="3dp"
3637
app:minChunkHeight="2dp"

audiowave/src/main/kotlin/rm/com/audiowave/AudioWaveView.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class AudioWaveView : View {
7171
set(value) {
7272
wavePaint = smoothPaint(value.withAlpha(0xAA))
7373
waveFilledPaint = filterPaint(value)
74-
postInvalidate()
74+
redrawData()
7575
}
7676

7777
var progress: Float = 0F
@@ -105,6 +105,8 @@ class AudioWaveView : View {
105105

106106
var isExpansionAnimated: Boolean = true
107107

108+
var isTouchable = true
109+
108110
var isTouched = false
109111
private set
110112

@@ -175,9 +177,14 @@ class AudioWaveView : View {
175177
}
176178
}
177179

180+
@SuppressLint("ClickableViewAccessibility")
178181
override fun onTouchEvent(event: MotionEvent?): Boolean {
179182
event ?: return super.onTouchEvent(event)
180183

184+
if (!isTouchable || !isEnabled) {
185+
return false
186+
}
187+
181188
when (event.action) {
182189
MotionEvent.ACTION_DOWN -> {
183190
isTouched = true
@@ -275,6 +282,7 @@ class AudioWaveView : View {
275282
minChunkHeight = getDimensionPixelSize(R.styleable.AudioWaveView_minChunkHeight,
276283
minChunkHeight)
277284
chunkRadius = getDimensionPixelSize(R.styleable.AudioWaveView_chunkRadius, chunkRadius)
285+
isTouchable = getBoolean(R.styleable.AudioWaveView_touchable, isTouchable)
278286
waveColor = getColor(R.styleable.AudioWaveView_waveColor, waveColor)
279287
progress = getFloat(R.styleable.AudioWaveView_progress, progress)
280288
isExpansionAnimated = getBoolean(R.styleable.AudioWaveView_animateExpansion,

audiowave/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<attr format="dimension" name="chunkSpacing"/>
1010
<attr format="float" name="progress"/>
1111
<attr format="boolean" name="animateExpansion"/>
12+
<attr format="boolean" name="touchable"/>
1213
</declare-styleable>
1314
</resources>

0 commit comments

Comments
 (0)