Last active
May 28, 2018 12:14
-
-
Save kheldiente/5cea6a2ccf2115e50de0a58eb0c40a10 to your computer and use it in GitHub Desktop.
Get all available presets from Equalizer class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
list_preset.layoutManager = LinearLayoutManager(this) | |
list_preset.isNestedScrollingEnabled = true | |
list_preset.adapter = presetAdapter | |
presetList.clear() | |
val presets = equalizer?.numberOfPresets | |
// Get preset names | |
(0 until presets!!) | |
.map { equalizer?.getPresetName(it.toShort()) } | |
.mapTo(presetList) { Preset(it) } | |
.run { | |
presetAdapter?.notifyDataSetChanged() | |
} | |
} | |
private fun setSelectedPreset(position: Int, preset: Preset) { | |
var currentEqPreset = equalizer?.getCurrentPreset() | |
if(currentEqPreset !== preset.name) { | |
val presets = equalizer?.numberOfPresets | |
// To set the preset in Equalizer class | |
equalizer?.usePreset(position.toShort()) | |
// Get the band level values of the preset, then display to UI | |
val numberOfBands = equalizer?.numberOfBands | |
val lowestBandLevel = equalizer?.bandLevelRange?.get(0) | |
(0 until numberOfBands!!) | |
.forEach { | |
val band = it | |
val level = equalizer?.getBandLevel(it.toShort())?.minus(lowestBandLevel!!) | |
view_eq.setBandLevel(band, level!!) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment