add the equalizer bands dynamically

This commit is contained in:
tibbi 2021-02-03 22:57:43 +01:00
parent 8ea631713c
commit 4810f497cd
3 changed files with 55 additions and 117 deletions

View file

@ -8,6 +8,7 @@ import android.view.Menu
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.musicplayer.R
import kotlinx.android.synthetic.main.activity_equalizer.*
import kotlinx.android.synthetic.main.equalizer_band.view.*
import java.text.DecimalFormat
class EqualizerActivity : SimpleActivity() {
@ -27,13 +28,24 @@ class EqualizerActivity : SimpleActivity() {
private fun initMediaPlayer() {
val player = MediaPlayer()
val equalizer = Equalizer(0, player.audioSessionId)
equalizer_label_bottom.text = (equalizer.bandLevelRange[0] / 100).toString()
equalizer_label_top.text = "+${equalizer.bandLevelRange[1] / 100}"
val minValue = equalizer.bandLevelRange[0] / 100
val maxValue = equalizer.bandLevelRange[1] / 100
equalizer_label_top.text = "+$maxValue"
equalizer_label_bottom.text = minValue.toString()
equalizer_label_0.text = (minValue + maxValue).toString()
equalizer_bands_holder.removeAllViews()
val bands = equalizer.numberOfBands
for (i in 0 until bands) {
val frequency = equalizer.getCenterFreq(i.toShort()) / 1000
val formatted = formatFrequency(frequency)
val range = equalizer.getBandFreqRange(i.toShort())
layoutInflater.inflate(R.layout.equalizer_band, equalizer_bands_holder, false).apply {
equalizer_bands_holder.addView(this)
this.equalizer_band_label.text = formatted
}
}
}

View file

@ -10,16 +10,14 @@
android:id="@+id/equalizer_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin"
tools:ignore="HardcodedText">
android:padding="@dimen/activity_margin">
<RelativeLayout
android:id="@+id/db_labels_holder"
android:id="@+id/equalizer_db_labels_holder"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:padding="@dimen/medium_margin"
app:layout_constraintBottom_toBottomOf="@+id/equalizer_60"
app:layout_constraintEnd_toStartOf="@+id/equalizer_60"
android:layout_height="@dimen/equalizer_seekbar_height"
android:paddingTop="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@ -29,8 +27,8 @@
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="+15"
android:textSize="@dimen/normal_text_size" />
android:textSize="@dimen/normal_text_size"
tools:text="+15" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/equalizer_label_0"
@ -38,8 +36,8 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingBottom="@dimen/medium_margin"
android:text="0"
android:textSize="@dimen/normal_text_size" />
android:textSize="@dimen/normal_text_size"
tools:text="0" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/equalizer_label_bottom"
@ -47,116 +45,19 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="-15"
android:textSize="@dimen/normal_text_size" />
android:textSize="@dimen/normal_text_size"
tools:text="-15" />
</RelativeLayout>
<com.simplemobiletools.musicplayer.views.VerticalSeekBar
android:id="@+id/equalizer_60"
<LinearLayout
android:id="@+id/equalizer_bands_holder"
android:layout_width="0dp"
android:layout_height="@dimen/equalizer_seekbar_height"
android:paddingStart="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
app:layout_constraintEnd_toStartOf="@+id/equalizer_230"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/db_labels_holder"
app:layout_constraintTop_toTopOf="parent" />
<com.simplemobiletools.musicplayer.views.VerticalSeekBar
android:id="@+id/equalizer_230"
android:layout_width="0dp"
android:layout_height="@dimen/equalizer_seekbar_height"
android:padding="@dimen/activity_margin"
app:layout_constraintEnd_toStartOf="@+id/equalizer_960"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/equalizer_60"
app:layout_constraintTop_toTopOf="parent" />
<com.simplemobiletools.musicplayer.views.VerticalSeekBar
android:id="@+id/equalizer_960"
android:layout_width="0dp"
android:layout_height="@dimen/equalizer_seekbar_height"
android:padding="@dimen/activity_margin"
app:layout_constraintEnd_toStartOf="@+id/equalizer_3600"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/equalizer_230"
app:layout_constraintTop_toTopOf="parent" />
<com.simplemobiletools.musicplayer.views.VerticalSeekBar
android:id="@+id/equalizer_3600"
android:layout_width="0dp"
android:layout_height="@dimen/equalizer_seekbar_height"
android:padding="@dimen/activity_margin"
app:layout_constraintEnd_toStartOf="@+id/equalizer_14000"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/equalizer_960"
app:layout_constraintTop_toTopOf="parent" />
<com.simplemobiletools.musicplayer.views.VerticalSeekBar
android:id="@+id/equalizer_14000"
android:layout_width="0dp"
android:layout_height="@dimen/equalizer_seekbar_height"
android:padding="@dimen/activity_margin"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/equalizer_3600"
app:layout_constraintStart_toEndOf="@+id/equalizer_db_labels_holder"
app:layout_constraintTop_toTopOf="parent" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/equalizer_60_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:text="60 Hz"
android:textSize="@dimen/normal_text_size"
app:layout_constraintEnd_toEndOf="@id/equalizer_60"
app:layout_constraintStart_toStartOf="@id/equalizer_60"
app:layout_constraintTop_toBottomOf="@+id/equalizer_60" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/equalizer_230_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:text="230 Hz"
android:textSize="@dimen/normal_text_size"
app:layout_constraintEnd_toEndOf="@id/equalizer_230"
app:layout_constraintStart_toStartOf="@id/equalizer_230"
app:layout_constraintTop_toBottomOf="@+id/equalizer_230" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/equalizer_960_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:text="960 Hz"
android:textSize="@dimen/normal_text_size"
app:layout_constraintEnd_toEndOf="@id/equalizer_960"
app:layout_constraintStart_toStartOf="@id/equalizer_960"
app:layout_constraintTop_toBottomOf="@+id/equalizer_960" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/equalizer_3600_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:text="3.6 kHz"
android:textSize="@dimen/normal_text_size"
app:layout_constraintEnd_toEndOf="@id/equalizer_3600"
app:layout_constraintStart_toStartOf="@id/equalizer_3600"
app:layout_constraintTop_toBottomOf="@+id/equalizer_3600" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/equalizer_14000_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:text="14 kHz"
android:textSize="@dimen/normal_text_size"
app:layout_constraintEnd_toEndOf="@id/equalizer_14000"
app:layout_constraintStart_toStartOf="@id/equalizer_14000"
app:layout_constraintTop_toBottomOf="@+id/equalizer_14000" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/equalizer_band_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.simplemobiletools.musicplayer.views.VerticalSeekBar
android:id="@+id/equalizer_band_seek_bar"
android:layout_width="wrap_content"
android:layout_height="@dimen/equalizer_seekbar_height"
android:padding="@dimen/activity_margin" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/equalizer_band_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/equalizer_band_seek_bar"
android:layout_alignStart="@+id/equalizer_band_seek_bar"
android:layout_alignEnd="@+id/equalizer_band_seek_bar"
android:layout_marginTop="@dimen/medium_margin"
android:gravity="center_horizontal"
android:textSize="@dimen/normal_text_size" />
</RelativeLayout>