Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Michael Diente kheldiente

🎯
Focusing
View GitHub Profile
View AppSettings.kt
import android.content.Context
import android.content.SharedPreferences
import org.json.JSONObject
object AppSettings {
private val PREF_NAME = "settings_pref"
// Settings
val EQUALIZER_ENABLED = "settings_eq_enabled"
@kheldiente
kheldiente / activity_main.xml
Created May 29, 2018
Final activity layout
View activity_main.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 / MainActivity.kt
Created May 29, 2018
Final code for activity
View MainActivity.kt
import android.media.MediaPlayer
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.media.audiofx.Equalizer
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.widget.CompoundButton
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.layout_switch.*
import midien.kheldiente.equalizer.adapter.PresetAdapter
View OnCheckChanged.kt
override fun onCheckedChanged(compoundButton: CompoundButton?, checked: Boolean) {
enableEqualizer(checked)
presetAdapter?.enableAll(checked) // Update color state of list
}
private fun enableEqualizer(enable: Boolean) {
equalizer?.enabled = enable
}
View layout_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:paddingLeft="15dp"
android:paddingTop="15dp"
android:paddingRight="10dp"
View item_preset.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="wrap_content"
android:background="@color/colorPrimary"
android:padding="15dp"
>
@kheldiente
kheldiente / PresetAdapter.kt
Last active May 29, 2018
Preset adapter for Equalizer presets
View PresetAdapter.kt
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.CompoundButton
import android.widget.TextView
import kotlinx.android.synthetic.main.item_preset.view.*
@kheldiente
kheldiente / GetAllPresets.kt
Last active May 28, 2018
Get all available presets from Equalizer class
View GetAllPresets.kt
private val presetList = ArrayList<Preset>(0)
private var presetAdapter: PresetAdapter? = null
private fun setupPresetList() {
presetAdapter = PresetAdapter(this) { position: Int, preset: Preset ->
setSelectedPreset(position, preset)
}
presetAdapter?.enabled = eqEnabled
presetAdapter?.currentPreset = eqPreset
@kheldiente
kheldiente / OnBandLevelChanged.kt
Created May 28, 2018
On band level changed on equalizer view
View OnBandLevelChanged.kt
override fun onBandLevelChanged(bandId: Int, value: Int, fromUser: Boolean) {
val lowestBandLevel = equalizer?.bandLevelRange?.get(0)
val bandLevel = (value.plus(lowestBandLevel!!)).toShort()
// Manipulate equalizer band level
setBandLevel(bandId.toShort(), bandLevel)
... Cached current value of band
}
@kheldiente
kheldiente / SetEqualizerViewValues.kt
Last active May 28, 2018
Set equalizer class values to equalizer view
View SetEqualizerViewValues.kt
private fun setupEqualizerView() {
val numberOfBands = equalizer?.numberOfBands
val lowestBandLevel = equalizer?.bandLevelRange?.get(0)
val highestBandLevel = equalizer?.bandLevelRange?.get(1)
val max = highestBandLevel?.minus(lowestBandLevel!!)!!
var bands = ArrayList<Integer>(0)
// Get center frequency for each band
(0 until numberOfBands!!)
.map { equalizer?.getCenterFreq(it.toShort()) }
You can’t perform that action at this time.