use dark dialogs if the user has dark background

This commit is contained in:
tibbi 2017-01-03 21:17:08 +01:00
parent e04ec15c7f
commit 8e7aee1fe3
3 changed files with 22 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.activities
import android.app.DatePickerDialog import android.app.DatePickerDialog
import android.app.TimePickerDialog import android.app.TimePickerDialog
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -23,6 +24,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
private var mWasReminderInit = false private var mWasReminderInit = false
private var mWasEndDateSet = false private var mWasEndDateSet = false
private var mWasEndTimeSet = false private var mWasEndTimeSet = false
private var mDialogTheme = 0
lateinit var mEventStartDateTime: DateTime lateinit var mEventStartDateTime: DateTime
lateinit var mEventEndDateTime: DateTime lateinit var mEventEndDateTime: DateTime
@ -33,6 +35,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
setContentView(R.layout.activity_event) setContentView(R.layout.activity_event)
val intent = intent ?: return val intent = intent ?: return
mDialogTheme = if (config.backgroundColor.getContrastColor() == Color.WHITE) R.style.DialogTheme_Dark else R.style.DialogTheme
mWasReminderInit = false mWasReminderInit = false
val eventId = intent.getIntExtra(EVENT_ID, 0) val eventId = intent.getIntExtra(EVENT_ID, 0)
@ -297,24 +300,25 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
fun setupStartDate() { fun setupStartDate() {
hideKeyboard() hideKeyboard()
DatePickerDialog(this, startDateSetListener, mEventStartDateTime.year, mEventStartDateTime.monthOfYear - 1, config.backgroundColor.getContrastColor()
DatePickerDialog(this, mDialogTheme, startDateSetListener, mEventStartDateTime.year, mEventStartDateTime.monthOfYear - 1,
mEventStartDateTime.dayOfMonth).show() mEventStartDateTime.dayOfMonth).show()
} }
fun setupStartTime() { fun setupStartTime() {
hideKeyboard() hideKeyboard()
TimePickerDialog(this, startTimeSetListener, mEventStartDateTime.hourOfDay, mEventStartDateTime.minuteOfHour, true).show() TimePickerDialog(this, mDialogTheme, startTimeSetListener, mEventStartDateTime.hourOfDay, mEventStartDateTime.minuteOfHour, true).show()
} }
fun setupEndDate() { fun setupEndDate() {
hideKeyboard() hideKeyboard()
DatePickerDialog(this, endDateSetListener, mEventEndDateTime.year, mEventEndDateTime.monthOfYear - 1, DatePickerDialog(this, mDialogTheme, endDateSetListener, mEventEndDateTime.year, mEventEndDateTime.monthOfYear - 1,
mEventEndDateTime.dayOfMonth).show() mEventEndDateTime.dayOfMonth).show()
} }
fun setupEndTime() { fun setupEndTime() {
hideKeyboard() hideKeyboard()
TimePickerDialog(this, endTimeSetListener, mEventEndDateTime.hourOfDay, mEventEndDateTime.minuteOfHour, true).show() TimePickerDialog(this, mDialogTheme, endTimeSetListener, mEventEndDateTime.hourOfDay, mEventEndDateTime.minuteOfHour, true).show()
} }
private val startDateSetListener = DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth -> private val startDateSetListener = DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="dark_theme_dialog_background">#ff444444</color>
</resources>

View File

@ -17,4 +17,14 @@
<style name="MonthStyle"> <style name="MonthStyle">
<item name="android:background">@drawable/transparent_button</item> <item name="android:background">@drawable/transparent_button</item>
</style> </style>
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">@android:color/white</item>
<item name="colorAccent">@color/color_primary</item>
</style>
<style name="DialogTheme.Dark" parent="Theme.AppCompat.Dialog">
<item name="android:windowBackground">@color/dark_theme_dialog_background</item>
<item name="colorAccent">@color/color_primary</item>
</style>
</resources> </resources>