Skip to content

Instantly share code, notes, and snippets.

View kheldiente's full-sized avatar
🎯
Focusing

Mike Diente kheldiente

🎯
Focusing
View GitHub Profile
@kheldiente
kheldiente / TCPClientNIO.java
Last active December 19, 2017 04:52
Non blocking socket channel
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.channels.SocketChannel;
@kheldiente
kheldiente / AndroidManifest.xml
Created May 26, 2018 17:23
Setup permission to modify audio settings
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="midien.kheldiente.equalizer">
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
... Other android manifest stuff
</manifest>
@kheldiente
kheldiente / MediaPlayerSetup.kt
Last active May 26, 2018 17:24
Setup the MediaPlayer class
private var mediaPlayer: MediaPlayer? = null
override fun onCreate(savedInstanceState: Bundle?) {
... Other stuff to initalize
setupMediaPlayer()
startMediaPlayer()
}
@kheldiente
kheldiente / GetEqualizerValues.kt
Last active May 27, 2018 03:22
Get Equalizer values
private var equalizer: Equalizer? = null
private fun initEqualizer() {
equalizer = Equalizer(0, mediaPlayer?.audioSessionId!!)
equalizer?.enabled = eqEnabled
}
private fun setupEqualizer() {
val numberOfBands = equalizer?.numberOfBands
val lowestBandLevel = equalizer?.bandLevelRange?.get(0
@kheldiente
kheldiente / PixelUtil.kt
Last active May 27, 2018 03:57
Calculate pixel to dp and vice versa
import android.content.Context
object PixelUtil {
fun pxToDp(context: Context, px: Float): Float {
return px / context.resources.displayMetrics.density
}
fun dpToPx(context: Context, dp: Float): Float {
return dp * context.resources.displayMetrics.density
@kheldiente
kheldiente / EqualizerView.kt
Last active May 27, 2018 04:03
Equalizer view
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.SeekBar
import kotlin.collections.ArrayList
import midien.kheldiente.equalizer.R
import midien.kheldiente.equalizer.util.PixelUtil
@kheldiente
kheldiente / activity_main.xml
Last active May 27, 2018 04:40
Use Equalizer view in xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:orientation="vertical"
tools:context="midien.kheldiente.equalizer.MainActivity"
>
@kheldiente
kheldiente / seekbar_style.xml
Created May 28, 2018 09:52
Seekbar style for equalizer
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@android:color/transparent" >
</item>
<item
android:id="@android:id/progress" >
<clip
android:drawable="@drawable/seekbar_progress" />
@kheldiente
kheldiente / seekbar_progress.xml
Created May 28, 2018 09:53
Progress style on seekbar
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/progressshape" >
<clip>
<shape
android:shape="rectangle" >
<size android:height="5dp"/>
<corners
@kheldiente
kheldiente / seekbar_thumb.xml
Last active May 28, 2018 09:57
Seekbar thumb style for equalizer
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@android:color/white"/>
<size
android:width="20dp"
android:height="20dp"/>
</shape>
</item>