项目作者: alxrm

项目描述 :
Lightweight audiowave progressbar for Android
高级语言: Kotlin
项目地址: git://github.com/alxrm/audiowave-progressbar.git
创建时间: 2016-10-23T20:58:11Z
项目社区:https://github.com/alxrm/audiowave-progressbar

开源协议:MIT License

下载


Audiogram


License

Super lightweight audiowave progressbar written in Kotlin

Getting started

Add to your root build.gradle:

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url "https://jitpack.io" }
  5. }
  6. }

Add the dependency:

  1. dependencies {
  2. implementation 'com.github.alxrm:audiowave-progressbar:0.9.2'
  3. }

Attrs

attr format description
waveColor color with this color chunks will be filled
chunkWidth dimension every chunk will have this width
chunkHeight dimension maximum height all the chunks can be
minChunkHeight dimension minimum height all the chunks can be
chunkSpacing dimension spacing between chunks
chunkRadius dimension how much corners of every chunk will be rounded
progress float should be 0..100, it’s float so you can easily animate this
animateExpansion boolean toggle the animated expansion
touchable boolean toggle to use it as a seekbar, default value is true

Note: If you are going to place this in a RecyclerView item, you have to set animateExpansion to false, otherwise you’ll see an incredibly laggy scroll (check out the example)

In code

Settle the wave somewhere in your XML like this:

  1. <rm.com.audiowave.AudioWaveView
  2. android:id="@+id/wave"
  3. android:layout_width="match_parent"
  4. android:layout_height="32dp"
  5. android:layout_margin="16dp"
  6. app:animateExpansion="false"
  7. app:chunkWidth="3dp"
  8. app:chunkHeight="24dp"
  9. app:minChunkHeight="2dp"
  10. app:chunkSpacing="1dp"
  11. app:chunkRadius="1dp"
  12. app:touchable="true"
  13. app:waveColor="@android:color/white"
  14. ></rm.com.audiowave.AudioWaveView>

API

Set raw byte array asynchronously

  1. // does downsampling in O(N) and shows the animation you see in a gif above (the inflation-like one)
  2. setRawData(byte[] data);
  3. // you also have the ability to listen, when does the downsampling complete
  4. setRawData(byte[] data, OnSamplingListener callback);

In case you have a scaled byte array you want to draw, i. e. an array whose size is the amount of chunks to draw

  1. // instantly redraws the wave without async downsampling process
  2. setScaledData(byte[] scaledData);

You can use it like a Seekbar, it reacts on touches, just attach listener

  1. wave.setOnProgressListener(OnProgressListener listener);

Note: that setOnProgressListener is a Java style API and with Kotlin you have to set it like this:

  1. wave.onProgressListener = object : OnProgressListener {...}

This listener has 3 methods like a built-in Seekbar

  1. void onStartTracking(float progress) {
  2. // invokes when user touches the view
  3. }
  4. void onStopTracking(float progress) {
  5. // invokes when user releases the touch
  6. }
  7. void onProgressChanged(float progress, boolean byUser) {
  8. // invokes every time the progress's been changed
  9. }

Kotlin users can listen Seekbar event in a more convenient and clean way with properties:

  1. wave.onStopTracking = {
  2. Log.d("wave", "Progress set: $it")
  3. }
  4. wave.onStartTracking = {
  5. Log.d("wave", "Started tracking from: $it")
  6. }
  7. wave.onProgressChanged = {progress, byUser ->
  8. Log.d("wave", "Progress set: $progress, and it's $byUser that user did this")
  9. }

Contribution

There are some features(like better precision) I am about to implement, but a little bit later.
If you’d like to help, you are always free to send pull requests or issues if you only want to suggest something

Note: All your pull requests should be written in kotlin

License

  1. MIT License
  2. Copyright (c) 2016 Alexey Derbyshev
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.