properly save and restore Custom equalizer values
This commit is contained in:
parent
31bf3b2e98
commit
d7f79979d3
5 changed files with 23 additions and 13 deletions
4
app/proguard-rules.pro
vendored
4
app/proguard-rules.pro
vendored
|
@ -20,7 +20,3 @@
|
|||
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
|
||||
-dontwarn org.codehaus.mojo.animal_sniffer.*
|
||||
-dontwarn okhttp3.internal.platform.ConscryptPlatform
|
||||
|
||||
-keep class com.simplemobiletools.musicplayer.models.* {
|
||||
<fields>;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import android.media.MediaPlayer
|
|||
import android.media.audiofx.Equalizer
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.onSeekBarChangeListener
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
|
@ -18,7 +20,7 @@ import kotlinx.android.synthetic.main.equalizer_band.view.*
|
|||
import java.text.DecimalFormat
|
||||
|
||||
class EqualizerActivity : SimpleActivity() {
|
||||
private val bandsMap = HashMap<Short, Int>()
|
||||
private var bands = HashMap<Short, Int>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -44,33 +46,43 @@ class EqualizerActivity : SimpleActivity() {
|
|||
private fun setupBands(equalizer: Equalizer) {
|
||||
val minValue = equalizer.bandLevelRange[0]
|
||||
val maxValue = equalizer.bandLevelRange[1]
|
||||
val middle = (maxValue - minValue) / 2
|
||||
equalizer_label_top.text = "+${maxValue / 100}"
|
||||
equalizer_label_bottom.text = "${minValue / 100}"
|
||||
equalizer_label_0.text = (minValue + maxValue).toString()
|
||||
|
||||
equalizer_bands_holder.removeAllViews()
|
||||
|
||||
val bands = equalizer.numberOfBands
|
||||
for (band in 0 until bands) {
|
||||
bandsMap[band.toShort()] = 0
|
||||
val bandsCnt = equalizer.numberOfBands
|
||||
val bandType = object : TypeToken<HashMap<Short, Int>>() {}.type
|
||||
bands = Gson().fromJson<HashMap<Short, Int>>(config.equalizerBands, bandType) ?: HashMap()
|
||||
|
||||
for (band in 0 until bandsCnt) {
|
||||
val frequency = equalizer.getCenterFreq(band.toShort()) / 1000
|
||||
val formatted = formatFrequency(frequency)
|
||||
val defaultValue = if (bands.containsKey(band.toShort())) {
|
||||
bands[band.toShort()]
|
||||
} else {
|
||||
middle
|
||||
}
|
||||
|
||||
layoutInflater.inflate(R.layout.equalizer_band, equalizer_bands_holder, false).apply {
|
||||
equalizer_bands_holder.addView(this)
|
||||
this.equalizer_band_label.text = formatted
|
||||
this.equalizer_band_label.setTextColor(config.textColor)
|
||||
this.equalizer_band_seek_bar.max = maxValue - minValue
|
||||
this.equalizer_band_seek_bar.progress = defaultValue!!.toInt()
|
||||
|
||||
this.equalizer_band_seek_bar.onSeekBarChangeListener {
|
||||
val newValue = it + minValue
|
||||
equalizer.setBandLevel(band.toShort(), newValue.toShort())
|
||||
bandsMap[band.toShort()] = newValue
|
||||
bands[band.toShort()] = newValue
|
||||
}
|
||||
|
||||
// classic onStopTrackingTouch doesn't work with the VerticalSeekBar, so use a custom solution
|
||||
this.equalizer_band_seek_bar.seekBarStopListener = { value ->
|
||||
|
||||
bands[band.toShort()] = value
|
||||
config.equalizerBands = Gson().toJson(bands)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,4 +68,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
var equalizerPreset: Int
|
||||
get() = prefs.getInt(EQUALIZER_PRESET, 0)
|
||||
set(equalizerPreset) = prefs.edit().putInt(EQUALIZER_PRESET, equalizerPreset).apply()
|
||||
|
||||
var equalizerBands: String
|
||||
get() = prefs.getString(EQUALIZER_BANDS, "")!!
|
||||
set(equalizerBands) = prefs.edit().putString(EQUALIZER_BANDS, equalizerBands).apply()
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ const val SWAP_PREV_NEXT = "swap_prev_next"
|
|||
const val LAST_SLEEP_TIMER_SECONDS = "last_sleep_timer_seconds"
|
||||
const val SLEEP_IN_TS = "sleep_in_ts"
|
||||
const val EQUALIZER_PRESET = "EQUALIZER_PRESET"
|
||||
const val EQUALIZER_BANDS = "EQUALIZER_BANDS"
|
||||
|
||||
const val LOWER_ALPHA = 0.5f
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
package com.simplemobiletools.musicplayer.models
|
||||
|
||||
data class EqualizerBand(val id: Short, val value: Short)
|
Loading…
Reference in a new issue