Skip to content

Commit

Permalink
Merge pull request #18 from yahoo/piano-tones
Browse files Browse the repository at this point in the history
Piano keys, clean up, updated settings
  • Loading branch information
jgbirk authored Mar 11, 2021
2 parents fe6f87e + 3748f3b commit ecbf725
Show file tree
Hide file tree
Showing 75 changed files with 503 additions and 395 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:supportsRtl="true"
android:theme="@style/SongbirdAppTheme"
android:name=".base.ApplicationBase">
<activity android:name="com.yahoo.mobile.android.audiocharts.sample.settings.AudioChartSettingsActivity"/>
<activity android:name="com.yahoo.mobile.android.audiocharts.sample.settings.SettingsActivity"/>
<activity android:name="com.yahoo.mobile.android.audiocharts.sample.SampleSongbirdChartActivity"/>
<activity android:name=".main.MainActivity">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.yahoo.mobile.android.audiocharts.repository

import com.yahoo.mobile.android.audiocharts.R
import com.yahoo.mobile.android.audiocharts.base.ApplicationBase
import com.yahoo.mobile.android.songbird.model.AudioChartPointViewModel
import com.yahoo.mobile.android.songbird.model.AudioChartViewModel
import com.yahoo.mobile.android.songbird.model.ScrubPointViewModel
import com.yahoo.mobile.android.songbird.model.ChartViewModel
import com.yahoo.mobile.android.songbird.model.XAxisLabel
import com.yahoo.mobile.android.songbird.util.AudioChartSettingsHelper
import com.yahoo.mobile.android.songbird.util.SettingsHelper
import com.yahoo.mobile.android.songbird.util.DateTimeUtils
import com.yahoo.mobile.android.songbird.util.ValueFormatter
import java.util.concurrent.TimeUnit
Expand All @@ -14,15 +14,15 @@ import kotlin.random.Random
object AudioChartRepository {

private const val NUMBER_OF_POINTS = 15
private val audioChartSettingsHelper = AudioChartSettingsHelper(ApplicationBase.instance)
private val audioChartSettingsHelper = SettingsHelper(ApplicationBase.instance)

/**
* Sample Songbird chart for demo purposes
*/
fun loadSampleSongbirdChart(showXAxis: Boolean, showYAxis: Boolean): AudioChartViewModel {
fun loadSampleSongbirdChart(showXAxis: Boolean, showYAxis: Boolean): ChartViewModel {
val points = generateSamplePoints()
val benchmark = points.random().value
return AudioChartViewModel(
return ChartViewModel(
contentDescription = "",
benchmark = benchmark,
chartDataPoints = points,
Expand All @@ -49,18 +49,18 @@ object AudioChartRepository {
)
}

private fun generateSamplePoints(): List<AudioChartPointViewModel> {
val points = mutableListOf<AudioChartPointViewModel>()
private fun generateSamplePoints(): List<ScrubPointViewModel> {
val points = mutableListOf<ScrubPointViewModel>()
val startTime = System.currentTimeMillis()
for (i in 0 until NUMBER_OF_POINTS) {
val value = Random.nextDouble(0.0, 1000.0)
val value = Random.nextDouble(0.0, 100.0)
val timestamp = startTime + TimeUnit.MINUTES.toMillis(i.toLong())
points.add(
AudioChartPointViewModel(
ScrubPointViewModel(
value = value,
timestamp = timestamp,
index = i,
defaultTalkbackString = audioChartSettingsHelper.getTalkBackString(
talkbackString = audioChartSettingsHelper.getTalkBackString(
formattedPrice = ValueFormatter.getAsFormattedPrice(value, 2.0),
timestampMs = timestamp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import com.yahoo.mobile.android.audiocharts.R
import com.yahoo.mobile.android.songbird.model.AudioChartViewModel
import com.yahoo.mobile.android.songbird.model.ChartViewModel
import com.yahoo.mobile.android.songbird.view.SongbirdChartView
import com.yahoo.mobile.android.audiocharts.sample.settings.AudioChartSettingsActivity
import com.yahoo.mobile.android.audiocharts.sample.settings.SettingsActivity
import com.yahoo.mobile.android.audiocharts.repository.AudioChartRepository

class SampleSongbirdChartActivity : AppCompatActivity() {
Expand All @@ -26,7 +26,7 @@ class SampleSongbirdChartActivity : AppCompatActivity() {
}
}

private lateinit var chartViewModel: AudioChartViewModel
private lateinit var chartViewModel: ChartViewModel
private lateinit var songbirdChartView: SongbirdChartView

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -61,11 +61,9 @@ class SampleSongbirdChartActivity : AppCompatActivity() {
)
}

private fun setChartViewModel(chartViewModel: AudioChartViewModel) {
private fun setChartViewModel(chartViewModel: ChartViewModel) {
this.chartViewModel = chartViewModel
chartViewModel.apply {
songbirdChartView.setViewModel(chartViewModel)
}
songbirdChartView.setViewModel(chartViewModel)
}

private fun playSummaryAudio() {
Expand All @@ -90,7 +88,7 @@ class SampleSongbirdChartActivity : AppCompatActivity() {
}
R.id.settings -> {
startActivity(
AudioChartSettingsActivity.intent(this)
SettingsActivity.intent(this)
)
return true
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.yahoo.mobile.android.audiocharts.sample.settings

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import com.yahoo.mobile.android.songbird.util.SettingsHelper
import com.yahoo.mobile.android.audiocharts.R
import com.yahoo.mobile.android.audiocharts.base.ApplicationBase
import com.yahoo.mobile.android.songbird.player.AudioPlayer

class SettingsActivity : AppCompatActivity() {

companion object {
@JvmStatic
fun intent(context: Context) = Intent(context, SettingsActivity::class.java)
}

private val settingsHelper: SettingsHelper = SettingsHelper(
ApplicationBase.instance
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_settings)

setSupportActionBar(findViewById(R.id.toolbar))

supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
title = getString(R.string.settings)
}
val orderButtons: RadioGroup = findViewById(R.id.order_buttons)
orderButtons.setOnCheckedChangeListener { _, checkedId ->
settingsHelper.setOrderPosition(orderButtons.indexOfChild(orderButtons.findViewById(checkedId)))
}

val dateButtons: RadioGroup = findViewById(R.id.date_buttons)
dateButtons.setOnCheckedChangeListener { _, checkedId ->
settingsHelper.setDatePosition(dateButtons.indexOfChild(dateButtons.findViewById(checkedId)))
}

val highToneInput = findViewById<Spinner>(R.id.high_tone_input)
ArrayAdapter.createFromResource(
this,
R.array.high_tones,
android.R.layout.simple_spinner_item
).also { adapter ->
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
highToneInput.adapter = adapter
highToneInput.setSelection(AudioPlayer.tones.size-1-settingsHelper.getMaximumTone())
}
highToneInput.onItemSelectedListener =
object: AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
settingsHelper.setMaximumTone(AudioPlayer.tones.size-1-position)
}

override fun onNothingSelected(parent: AdapterView<*>?) {
settingsHelper.setMaximumTone(AudioPlayer.tones.size-1)
}
}

val lowToneInput = findViewById<Spinner>(R.id.low_tone_input)
ArrayAdapter.createFromResource(
this,
R.array.low_tones,
android.R.layout.simple_spinner_item
).also { adapter ->
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
lowToneInput.adapter = adapter
lowToneInput.setSelection(settingsHelper.getMinimumTone())
}
lowToneInput.onItemSelectedListener =
object: AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
settingsHelper.setMinimumTone(position)
}

override fun onNothingSelected(parent: AdapterView<*>?) {
settingsHelper.setMinimumTone(0)
}
}

val echoButton = findViewById<ToggleButton>(R.id.echo_button)
echoButton.setOnClickListener {
settingsHelper.switchEchoToggle()
}

val feedbackButton = findViewById<Button>(R.id.feedback)
feedbackButton.setOnClickListener {
Toast.makeText(this, getString(R.string.visit_us_at_repo), Toast.LENGTH_LONG).show()
}

(orderButtons.getChildAt(settingsHelper.getSavedOrderPosition()) as RadioButton).isChecked = true
(dateButtons.getChildAt(settingsHelper.getSavedDateOrderPosition()) as RadioButton).isChecked = true
echoButton.isChecked = settingsHelper.getEchoChecked()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
finish()
true
}
else -> super.onOptionsItemSelected(item)
}
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
android:layout_height="wrap_content"
android:textColor="@color/songbird_primary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/y_axis"/>
app:layout_constraintTop_toBottomOf="@id/y_axis"
style="@style/SongbirdButtonStyle"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Expand Down
Loading

0 comments on commit ecbf725

Please sign in to comment.