Mercurial > dwindows
comparison android/DWindows.kt @ 2551:127779860ac1
Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 15 May 2021 00:44:24 +0000 |
parents | a8d90e2896bc |
children | 303f544d14fa |
comparison
equal
deleted
inserted
replaced
2550:a8d90e2896bc | 2551:127779860ac1 |
---|---|
23 import android.text.InputType | 23 import android.text.InputType |
24 import android.text.method.PasswordTransformationMethod | 24 import android.text.method.PasswordTransformationMethod |
25 import android.util.Base64 | 25 import android.util.Base64 |
26 import android.util.Log | 26 import android.util.Log |
27 import android.util.SparseBooleanArray | 27 import android.util.SparseBooleanArray |
28 import android.util.TypedValue | |
28 import android.view.* | 29 import android.view.* |
29 import android.view.View.OnTouchListener | 30 import android.view.View.OnTouchListener |
30 import android.view.inputmethod.EditorInfo | 31 import android.view.inputmethod.EditorInfo |
31 import android.webkit.WebView | 32 import android.webkit.WebView |
32 import android.webkit.WebViewClient | 33 import android.webkit.WebViewClient |
33 import android.widget.* | 34 import android.widget.* |
34 import android.widget.AdapterView.OnItemClickListener | 35 import android.widget.AdapterView.OnItemClickListener |
35 import android.widget.SeekBar.OnSeekBarChangeListener | 36 import android.widget.SeekBar.OnSeekBarChangeListener |
37 import androidx.annotation.RequiresApi | |
36 import androidx.appcompat.app.AlertDialog | 38 import androidx.appcompat.app.AlertDialog |
37 import androidx.appcompat.app.AppCompatActivity | 39 import androidx.appcompat.app.AppCompatActivity |
38 import androidx.appcompat.widget.AppCompatEditText | 40 import androidx.appcompat.widget.AppCompatEditText |
39 import androidx.collection.SimpleArrayMap | 41 import androidx.collection.SimpleArrayMap |
40 import androidx.core.app.NotificationCompat | 42 import androidx.core.app.NotificationCompat |
460 var firstWindow: Boolean = true | 462 var firstWindow: Boolean = true |
461 var windowLayout: LinearLayout? = null | 463 var windowLayout: LinearLayout? = null |
462 var threadLock = ReentrantLock() | 464 var threadLock = ReentrantLock() |
463 var threadCond = threadLock.newCondition() | 465 var threadCond = threadLock.newCondition() |
464 var notificationID: Int = 0 | 466 var notificationID: Int = 0 |
467 var darkMode: Int = -1 | |
465 private var paint = Paint() | 468 private var paint = Paint() |
466 private var bgcolor: Int = 0 | 469 private var bgcolor: Int = 0 |
467 private var menuBar: DWMenu? = null | 470 private var menuBar: DWMenu? = null |
468 | 471 |
469 // Our version of runOnUiThread that waits for execution | 472 // Our version of runOnUiThread that waits for execution |
508 } | 511 } |
509 | 512 |
510 override fun onConfigurationChanged(newConfig: Configuration) { | 513 override fun onConfigurationChanged(newConfig: Configuration) { |
511 super.onConfigurationChanged(newConfig) | 514 super.onConfigurationChanged(newConfig) |
512 | 515 |
516 val currentNightMode = newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK | |
517 when (currentNightMode) { | |
518 Configuration.UI_MODE_NIGHT_NO -> { darkMode = 0 } // Night mode is not active, we're using the light theme | |
519 Configuration.UI_MODE_NIGHT_YES -> { darkMode = 1 } // Night mode is active, we're using dark theme | |
520 } | |
521 | |
513 // Send a DW_SIGNAL_CONFIGURE on orientation change | 522 // Send a DW_SIGNAL_CONFIGURE on orientation change |
514 if(windowLayout != null) { | 523 if(windowLayout != null) { |
515 var width: Int = windowLayout!!.width | 524 var width: Int = windowLayout!!.width |
516 var height: Int = windowLayout!!.height | 525 var height: Int = windowLayout!!.height |
517 | 526 |
533 } else { | 542 } else { |
534 menuBar = DWMenu() | 543 menuBar = DWMenu() |
535 menuBar!!.createMenu(menu) | 544 menuBar!!.createMenu(menu) |
536 } | 545 } |
537 return super.onPrepareOptionsMenu(menu) | 546 return super.onPrepareOptionsMenu(menu) |
547 } | |
548 | |
549 fun darkModeDetected(): Int | |
550 { | |
551 return darkMode | |
538 } | 552 } |
539 | 553 |
540 fun menuBarNew(location: View): DWMenu? | 554 fun menuBarNew(location: View): DWMenu? |
541 { | 555 { |
542 // TODO: Make sure location is this activity | 556 // TODO: Make sure location is this activity |
750 } | 764 } |
751 } | 765 } |
752 } | 766 } |
753 } | 767 } |
754 | 768 |
755 fun windowSetColor(window: View, falpha: Int, fred: Int, fgreen: Int, fblue: Int, | 769 fun windowSetColor(window: View, fore: Int, falpha: Int, fred: Int, fgreen: Int, fblue: Int, |
756 balpha: Int, bred: Int, bgreen: Int, bblue: Int) { | 770 back: Int, balpha: Int, bred: Int, bgreen: Int, bblue: Int) { |
771 var colorfore: Int = Color.rgb(fred, fgreen, fblue) | |
772 var colorback: Int = Color.rgb(bred, bgreen, bblue) | |
773 | |
774 // DW_CLR_DEFAULT on background sets it transparent... | |
775 // so the background drawable shows through | |
776 if(back == 16) { | |
777 colorback = Color.TRANSPARENT | |
778 } | |
757 | 779 |
758 waitOnUiThread { | 780 waitOnUiThread { |
759 if (window is TextView) { | 781 if (window is TextView) { |
760 var textview: TextView = window | 782 var textview: TextView = window |
761 textview.setTextColor(Color.rgb(fred, fgreen, fblue)) | 783 |
762 textview.setBackgroundColor(Color.rgb(bred, bgreen, bblue)) | 784 // Handle DW_CLR_DEFAULT |
785 if(fore == 16) { | |
786 val value = TypedValue() | |
787 this.theme.resolveAttribute(R.attr.editTextColor, value, true) | |
788 colorfore = value.data | |
789 } | |
790 textview.setTextColor(colorfore) | |
791 textview.setBackgroundColor(colorback) | |
763 } else if (window is Button) { | 792 } else if (window is Button) { |
764 var button: Button = window | 793 var button: Button = window |
765 button.setTextColor(Color.rgb(fred, fgreen, fblue)) | 794 |
766 button.setBackgroundColor(Color.rgb(bred, bgreen, bblue)) | 795 // Handle DW_CLR_DEFAULT |
796 if(fore == 16) { | |
797 val value = TypedValue() | |
798 // colorButtonNormal requires API 21... use the editTextColor... | |
799 // on older versions as a placeholder... this is probably wrong | |
800 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
801 this.theme.resolveAttribute(R.attr.colorButtonNormal, value, true) | |
802 } else { | |
803 this.theme.resolveAttribute(R.attr.editTextColor, value, true) | |
804 } | |
805 colorfore = value.data | |
806 } | |
807 button.setTextColor(colorfore) | |
808 button.setBackgroundColor(colorback) | |
767 } else if(window is LinearLayout) { | 809 } else if(window is LinearLayout) { |
768 var box: LinearLayout = window | 810 var box: LinearLayout = window |
769 box.setBackgroundColor(Color.rgb(bred, bgreen, bblue)) | 811 |
812 box.setBackgroundColor(colorback) | |
770 } | 813 } |
771 } | 814 } |
772 } | 815 } |
773 | 816 |
774 fun windowSetText(window: View, text: String) { | 817 fun windowSetText(window: View, text: String) { |