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 / AppSettings.kt
Created May 29, 2018 03:30
Settings cache
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 03:28
Final activity layout
<?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 03:25
Final code for activity
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
@kheldiente
kheldiente / OnCheckChanged.kt
Created May 29, 2018 03:19
On switch toggled
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
}
@kheldiente
kheldiente / layout_switch.xml
Created May 29, 2018 03:13
Layout for switch
<?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"
@kheldiente
kheldiente / item_preset.xml
Created May 28, 2018 11:56
Item list preset
<?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 03:53
Preset adapter for Equalizer presets
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 12:14
Get all available presets from Equalizer class
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 10:13
On band level changed on equalizer view
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 10:04
Set equalizer class values to equalizer view
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()) }