Aan/uit via standaard MaterialSwitch (Material 3); geen zelf-verzonnen switch-tinten meer

This commit is contained in:
eddy 2026-10-14 20:46:08 +02:00
commit 8c5c21024d
4 changed files with 8 additions and 28 deletions

View file

@ -9,13 +9,13 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.PopupMenu import android.widget.PopupMenu
import android.widget.Switch
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import com.google.android.material.materialswitch.MaterialSwitch
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import nl.eddydevink.buschauffeurswekker.core.AlarmScheduler import nl.eddydevink.buschauffeurswekker.core.AlarmScheduler
import nl.eddydevink.buschauffeurswekker.core.AlarmSpec import nl.eddydevink.buschauffeurswekker.core.AlarmSpec
@ -129,18 +129,14 @@ class MainActivity : AppCompatActivity() {
card.findViewById<TextView>(R.id.tv_name).text = spec.name card.findViewById<TextView>(R.id.tv_name).text = spec.name
val timeView = card.findViewById<TextView>(R.id.tv_time) val timeView = card.findViewById<TextView>(R.id.tv_time)
timeView.text = TIME.format(spec.time) timeView.text = TIME.format(spec.time)
val switch = card.findViewById<Switch>(R.id.switch_alarm) val switch = card.findViewById<MaterialSwitch>(R.id.switch_alarm)
switch.setOnCheckedChangeListener(null) switch.setOnCheckedChangeListener(null)
switch.isChecked = !disabled switch.isChecked = !disabled
// Helder onderscheid: blauw = aan, grijs = uit (zoals de systeemwekker). // Heldere statetoestand: blauw = aan, grijs = uit.
val cardView = card as MaterialCardView val cardView = card as MaterialCardView
if (disabled) { cardView.setCardBackgroundColor(
cardView.setCardBackgroundColor(ContextCompat.getColor(this, R.color.card_idle)) ContextCompat.getColor(this, if (disabled) R.color.card_idle else R.color.card_active),
timeView.setTextColor(ContextCompat.getColor(this, R.color.text_muted)) )
} else {
cardView.setCardBackgroundColor(ContextCompat.getColor(this, R.color.card_active))
timeView.setTextColor(ContextCompat.getColor(this, R.color.text_bright))
}
switch.setOnCheckedChangeListener { _, checked -> switch.setOnCheckedChangeListener { _, checked ->
toggleAlarm(spec, checked) toggleAlarm(spec, checked)
renderStatus() renderStatus()

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- aan: donkere knop op witte track -->
<item android:state_checked="true" android:color="#0A0A0C" />
<!-- uit: lichte grijze knop op donkere track -->
<item android:color="#9AA0A6" />
</selector>

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- helder: track wit als de wekker aan staat -->
<item android:state_checked="true" android:color="#FFFFFF" />
<!-- uit: donkergrijze track die op de grijze kaart nog zichtbaar is -->
<item android:color="#4A4A50" />
</selector>

View file

@ -55,12 +55,10 @@
android:textStyle="bold" /> android:textStyle="bold" />
</LinearLayout> </LinearLayout>
<Switch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/switch_alarm" android:id="@+id/switch_alarm"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:contentDescription="Wekker aan of uit" android:contentDescription="Wekker aan of uit" />
android:thumbTint="@color/switch_thumb"
android:trackTint="@color/switch_track" />
</LinearLayout> </LinearLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>