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

Commit

Permalink
isTouchable property(also as xml attribute) + bug fix for issue #15
Browse files Browse the repository at this point in the history
  • Loading branch information
alxrm committed May 24, 2018
1 parent 82ffbbb commit d779d42
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "com.android.support:recyclerview-v7:27.1.1"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.github.alxrm:audiowave-progressbar:0.9.1'
implementation 'com.github.alxrm:audiowave-progressbar:0.9.2'

implementation "com.jakewharton:butterknife:8.8.1"
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"

// compile project(':audiowave')
// implementation project(':audiowave')
}
repositories {
mavenCentral()
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/kotlin/rm/com/audiogram/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rm.com.audiogram
import android.animation.ObjectAnimator
import android.content.Intent
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.animation.LinearInterpolator
Expand Down Expand Up @@ -41,6 +42,11 @@ class MainActivity : AppCompatActivity() {

wave.onProgressChanged = { progress, byUser ->
Log.e("wave", "Progress set: $progress, and it's $byUser that user did this")

if (progress == 100F && !byUser) {
wave.waveColor = ContextCompat.getColor(this, R.color.colorAccent)
wave.isTouchable = true
}
}

wave.onStartTracking = {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_another.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
app:chunkRadius="1dp"
app:chunkSpacing="1dp"
app:chunkWidth="3dp"
app:touchable="true"
app:minChunkHeight="2dp"
app:progress="0.0"
app:waveColor="@android:color/black"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:layout_margin="16dp"
app:chunkHeight="24dp"
app:chunkRadius="1dp"
app:touchable="false"
app:chunkSpacing="1dp"
app:chunkWidth="3dp"
app:minChunkHeight="2dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/item_audio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
app:animateExpansion="false"
app:chunkHeight="16dp"
app:chunkRadius="1dp"
app:touchable="true"
app:chunkSpacing="1dp"
app:chunkWidth="3dp"
app:minChunkHeight="2dp"
Expand Down
10 changes: 9 additions & 1 deletion audiowave/src/main/kotlin/rm/com/audiowave/AudioWaveView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AudioWaveView : View {
set(value) {
wavePaint = smoothPaint(value.withAlpha(0xAA))
waveFilledPaint = filterPaint(value)
postInvalidate()
redrawData()
}

var progress: Float = 0F
Expand Down Expand Up @@ -105,6 +105,8 @@ class AudioWaveView : View {

var isExpansionAnimated: Boolean = true

var isTouchable = true

var isTouched = false
private set

Expand Down Expand Up @@ -175,9 +177,14 @@ class AudioWaveView : View {
}
}

@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent?): Boolean {
event ?: return super.onTouchEvent(event)

if (!isTouchable || !isEnabled) {
return false
}

when (event.action) {
MotionEvent.ACTION_DOWN -> {
isTouched = true
Expand Down Expand Up @@ -275,6 +282,7 @@ class AudioWaveView : View {
minChunkHeight = getDimensionPixelSize(R.styleable.AudioWaveView_minChunkHeight,
minChunkHeight)
chunkRadius = getDimensionPixelSize(R.styleable.AudioWaveView_chunkRadius, chunkRadius)
isTouchable = getBoolean(R.styleable.AudioWaveView_touchable, isTouchable)
waveColor = getColor(R.styleable.AudioWaveView_waveColor, waveColor)
progress = getFloat(R.styleable.AudioWaveView_progress, progress)
isExpansionAnimated = getBoolean(R.styleable.AudioWaveView_animateExpansion,
Expand Down
1 change: 1 addition & 0 deletions audiowave/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<attr format="dimension" name="chunkSpacing"/>
<attr format="float" name="progress"/>
<attr format="boolean" name="animateExpansion"/>
<attr format="boolean" name="touchable"/>
</declare-styleable>
</resources>

0 comments on commit d779d42

Please sign in to comment.