Skip to content

Instantly share code, notes, and snippets.

View arildojr7's full-sized avatar

Arildo Borges Jr arildojr7

View GitHub Profile
PitchDetectionHandler { result, audioEvent ->
val pitchInHz = result.pitch.toDouble()
if (shouldUpdateTunerState(pitchInHz, audioEvent)) {
val capturedNoteState = getCurrentPitchState(pitchInHz)
_tunerState.postValue(capturedNoteState)
saveLastUpdatedTime()
}
}
sealed class TunerState(open val note: NotesEnum, val bgColor: Color) {
class Down(override val note: NotesEnum) : TunerState(note, OutOfTuneColor)
class Tuned(override val note: NotesEnum) : TunerState(note, TunedColor)
class Up(override val note: NotesEnum) : TunerState(note, OutOfTuneColor)
}
@Preview(widthDp = 200, heightDp = 200)
@Composable
fun TunedView() {
TunerScreen(TunerState.Tuned(NotesEnum.A))
}
@Preview(widthDp = 200, heightDp = 200)
@Composable
fun OutOfTuneViewDown() {
TunerScreen(TunerState.Down(NotesEnum.A))
@Composable
fun TunerScreen(tunerState: TunerState) {
Column(
modifier = Modifier.fillMaxSize().background(tunerState.bgColor),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Row(verticalAlignment = Alignment.CenterVertically) {
LeftArrow(isVisible = tunerState is TunerState.Down)
TextNote(note = tunerState.note.title)
MaterialTheme {
Scaffold(
timeText = { TimeText() }
) {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize()
) {
Text("Hello World", color = Color.White)
@arildojr7
arildojr7 / MainActivity1.kt
Last active November 23, 2021 15:10
MainActivity.kt wearos-compose
class MainActivity : ComponentActivity() {
private val viewModel: MainViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme { }
}
}
}
implementation "androidx.wear.compose:compose-foundation:$version"
implementation "androidx.wear.compose:compose-material:$version"
implementation "androidx.wear.compose:compose-navigation:$version"
@arildojr7
arildojr7 / dependenciesBuild.gradle
Created November 20, 2021 20:07
dependencies compose + wear os
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
// Compose
implementation "androidx.activity:activity-compose:1.3.1"
implementation "androidx.compose.runtime:runtime-livedata:1.0.5"
implementation "androidx.compose.ui:ui-tooling-preview:1.0.5"
implementation "androidx.compose.ui:ui:1.0.5"
implementation "androidx.compose.compiler:compiler:1.0.5"
implementation "androidx.compose.foundation:foundation:1.0.5"
@arildojr7
arildojr7 / AndroidManifest.xml
Created November 20, 2021 20:00
AndroidManifest with wear os support
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.arildo.tuner">
<uses-feature android:name="android.hardware.type.watch" />
<application
android:allowBackup="true".........>
<uses-library android:name="com.google.android.wearable" android:required="true" />
<meta-data android:name="com.google.android.wearable.standalone" android:value="true" />
@arildojr7
arildojr7 / dipgood.kt
Created July 12, 2021 19:16
DIP Good
interface Switchable {
fun turnOn() {}
fun turnOff() {}
}
interface Switch {
fun press() {}
}
class Light : Switchable {