SimpleWaveform


Source link: https://github.com/maxyou/SimpleWaveform

SimpleWaveform

Waveform Widget


SimpleWaveform is a widget to show a sequence data in waveform or bar chart.

SimpleWaveform can be highly customized:
(1)show original positive and negetive data, or show absolute of the data for amplitude
(2)data can be px or percent of full amplitude. Will automaticly detect its width and height in px
(3)choose to show bar, peak outline, x-axis
(4)choose how to connect nearby peak for outline
(5)x-axis can be located at top/center/bottom
(6)can set bar width and gap
(7)all pencil can be set include bar/outline/x-axis/background
(8)two pencil with different colors to show progress
(9)wave from left or from right
(10)return bar position when your finger touch waveform

often used:

(1)show sound amplitude when record sound. ref to advance demo1
(2)Embedded in horizontal recycler view to show a very long sound waveform. ref to advance demo2

demo apk download from github
demo apk download from googleplay

demo1: positive and negative data

demo2: bar chart

demo3: amplitude bar

demo4: sound wave

advance demo1: generate recorder amplitude bar

advance demo2: embedded in horizontal recycler view

usage:

Install by gradle:

dependencies {

  compile 'com.maxproj.simplewaveform:app:1.0.0' 
}
 

Define a SimpleWaveform in layout:

<com.maxproj.simplewaveform.SimpleWaveform
  android:id="@+id/simplewaveform"
  android:layout_width="match_parent"
  android:layout_height="300dp"
  android:layout_margin="10dp" /> 

SimpleWaveformDemo.java include demo1 4 and advance demo12 in. Let's use demo3 as an example. please notice the comments:

private void demo3() {

 //restore default setting, you can omit all following setting and goto the final refresh() show
  simpleWaveform.init();

LinkedList<Integer> ampList = new LinkedList<>();

  //generate random data
  for (int i = 0; i < 80; i++) {

ampList.add(randomInt(-50, 50));

  
}

  simpleWaveform.setDataList(ampList);
//input data to show

//define bar gap
  simpleWaveform.barGap = 30;

//define x-axis direction
  simpleWaveform.modeDirection = SimpleWaveform.MODE_DIRECTION_LEFT_RIGHT;

//define if draw opposite pole when show bars
  simpleWaveform.modeAmp = SimpleWaveform.MODE_AMP_ABSOLUTE;
  //define if the unit is px or percent of the view's height
  simpleWaveform.modeHeight = SimpleWaveform.MODE_HEIGHT_PERCENT;
  //define where is the x-axis in y-axis
  simpleWaveform.modeZero = SimpleWaveform.MODE_ZERO_CENTER;
  //if show bars?
  simpleWaveform.showBar = true;

//define how to show peaks outline
  simpleWaveform.modePeak = SimpleWaveform.MODE_PEAK_PARALLEL;
  //if show peaks outline?
  simpleWaveform.showPeak = true;

//show x-axis
  simpleWaveform.showXAxis = true;
  xAxisPencil.setStrokeWidth(1);

  xAxisPencil.setColor(0x88ffffff);
//the first 0x88 is transparency, the next 0xffffff is color
  simpleWaveform.xAxisPencil = xAxisPencil;

//define pencil to draw bar
  barPencilFirst.setStrokeWidth(15);

  barPencilFirst.setColor(0xff1dcf0f);

  simpleWaveform.barPencilFirst = barPencilFirst;
  barPencilSecond.setStrokeWidth(15);

  barPencilSecond.setColor(0xff1dcfcf);

  simpleWaveform.barPencilSecond = barPencilSecond;

//define pencil to draw peaks outline
  peakPencilFirst.setStrokeWidth(5);

  peakPencilFirst.setColor(0xfffe2f3f);

  simpleWaveform.peakPencilFirst = peakPencilFirst;
  peakPencilSecond.setStrokeWidth(5);

  peakPencilSecond.setColor(0xfffeef3f);

  simpleWaveform.peakPencilSecond = peakPencilSecond;

//the first part will be draw by PencilFirst
  simpleWaveform.firstPartNum = 20;//first 20 bars will be draw by first pencil

//define how to clear screen
  simpleWaveform.clearScreenListener = new SimpleWaveform.ClearScreenListener() {

@Override

public void clearScreen(Canvas canvas) {

 canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);

}

  
}
;
  // set touch listener
  simpleWaveform.progressTouch = new SimpleWaveform.ProgressTouch() {

@Override

public void progressTouch(int progress, MotionEvent event) {

 Log.d("", "you touch at: " + progress);

 simpleWaveform.firstPartNum = progress;//set touch position back to its progress

 simpleWaveform.refresh();

}

  
}
;
  //show...
  simpleWaveform.refresh();

demo_introduce.setText("demo3: amplitude bar");
 
}
 

License

under MIT License.

Resources

We have seen RatingBar and it's support component AppCompatRatingBar but the problem is its difficult to customize. This library helps in customizing SquareRatingView with number Rate items and so on.

An Android helper class to manage database creation and version management using an application's raw asset files.

A simple logger MyLog.d("Empty 1");

A simple index side bar.

An Android library for custom search dialog.

A simple bottom sheet view for Android.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes