Create Android Audio Widget Overlay View

If you have already developed a music player and you feel that you want to make it even better, then you’re welcome to use this library and enjoy the results. Let firstly show you the demo :

Now let’s find out what’s behind these juicy audio widget overlay view.

Gradle file

To start, you need to add the following dependency to your project in the build.gradle file:

dependencies {
compile 'com.cleveroad:audiowidget:0.9.0'
}

Manifest file

As always, to make sure that no user’s data or any other application on a device would be impacted, we need to add two permissions to the app manifest:

<!-- used for drawing widget. This permission must be granted before calling AudioWidget.show(). -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<!-- used for notifing user that he is about to remove widget when he drags it on remove widget icon. -->
<!-- This permission granted by default on Android 6.0+ devices. -->
<uses-permission android:name="android.permission.VIBRATE"/>

As you can see, the first one will help you draw a widget over other applications. The second one is needed to inform a user that he is about to make a widget disappear when dragging it to the remove icon at the bottom of the screen. Although, the latter is optional.

Widget builder

The next is to create a new instance of your future widget by using the Builder:

AudioWidget audioWidget = new AudioWidget.Builder(context)       
.lightColor(...)
.darkColor(...)
.expandWidgetColor(...)
.progressColor(...)
.progressStrokeWidth(...)
.crossColor(...)
.crossOverlappedColor(...)
.crossStrokeWidth(...)
.buttonPadding(...)
.bubblesMinSize(...)
.bubblesMaxSize(...)
.shadowColor(...)
.shadowRadius(...)
.shadowDx(...)
.shadowDy(...)
.playDrawable(...)
.pauseDrawable(...)
.playlistDrawable(...)
.prevTrackDrawale(...)
.nextTrackDrawable(...)
.defaultAlbumDrawable(...)
.edgeOffsetXCollapsed(...)
.edgeOffsetYCollapsed(...)
.edgeOffsetXExpanded(...)
.edgeOffsetYExpanded(...)
.build();

Or you can use default configuration. Just call:

AudioWidget audioWidget = new AudioWidget.Builder(context).build();

Find more configuration here :