-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,93 @@ | ||
# WaveformSeekBar | ||
SeekBar variant that shows waveform data | ||
|
||
![WaveformSeekBar](https://github.com/alexei-frolo/WaveformSeekBar/blob/master/media/src/waveform_seek_bar.png) | ||
|
||
## Getting started | ||
|
||
### Setting up the dependency | ||
|
||
First of all, include the library in your project. | ||
In Gradle, this looks like: | ||
|
||
```groovy | ||
implementation 'com.github.alexei-frolo:WaveformSeekBar:1.0' | ||
``` | ||
|
||
### WaveformSeekBar example | ||
|
||
This section explains how to use **WaveformSeekBar**. | ||
|
||
First, add the view to xml layout: | ||
|
||
```xml | ||
... | ||
|
||
<com.frolo.waveformseekbar.WaveformSeekBar | ||
android:id="@+id/waveform_seek_bar" | ||
android:layout_width="match_parent" | ||
android:layout_gravity="center" | ||
android:layout_height="100dp" | ||
android:layout_margin="16dp"/> | ||
|
||
... | ||
|
||
``` | ||
|
||
Then you can set up waveform data and listen to progress changes as shown below: | ||
|
||
```java | ||
... | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_waveformseekbar_example); | ||
|
||
final WaveformSeekBar seekBar = findViewById(R.id.waveform_seek_bar); | ||
seekBar.setOnSeekBarChangeListener(new WaveformSeekBar.OnSeekBarChangeListener() { | ||
@Override | ||
public void onProgressInPercentageChanged(WaveformSeekBar seekBar, float percent, boolean fromUser) { | ||
|
||
} | ||
|
||
@Override | ||
public void onStartTrackingTouch(WaveformSeekBar seekBar) { | ||
|
||
} | ||
|
||
@Override | ||
public void onStopTrackingTouch(WaveformSeekBar seekBar) { | ||
Toast.makeText( | ||
WaveformSeekBarExampleActivity.this, | ||
"Tracked: percent=" + seekBar.getProgressPercent(), | ||
Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
seekBar.setWaveform(createWaveform(), true); | ||
|
||
findViewById(R.id.btn_regenerate).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
seekBar.setWaveform(createWaveform(), true); | ||
} | ||
}); | ||
} | ||
|
||
private int[] createWaveform() { | ||
final Random random = new Random(System.currentTimeMillis()); | ||
|
||
final int length = 50 + random.nextInt(50); | ||
final int[] values = new int[length]; | ||
int maxValue = 0; | ||
|
||
for (int i = 0; i < length; i++) { | ||
final int newValue = 5 + random.nextInt(50); | ||
if (newValue > maxValue) { | ||
maxValue = newValue; | ||
} | ||
values[i] = newValue; | ||
} | ||
return values; | ||
} | ||
... | ||
``` |