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" |
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" | |
> |
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" | |
> |
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.* |
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 |
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 | |
} |
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()) } |
NewerOlder