comparison android/DWindows.kt @ 2756:4f09bf72b391

Android: Attempt to get the selection background color from the theme. This doesn't always seem to work, so default to GRAY.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 03 Jan 2022 00:35:21 +0000
parents 9477910393ac
children f207b7ee177f
comparison
equal deleted inserted replaced
2755:9477910393ac 2756:4f09bf72b391
1 // (C) 2021-2022 Brian Smith <brian@dbsoft.org> 1 // (C) 2021-2022 Brian Smith <brian@dbsoft.org>
2 // (C) 2019 Anton Popov 2 // (C) 2019 Anton Popov
3 package org.dbsoft.dwindows 3 package org.dbsoft.dwindows
4 4
5 import android.R 5 import android.R
6 import android.animation.ArgbEvaluator
7 import android.annotation.SuppressLint 6 import android.annotation.SuppressLint
8 import android.app.Activity 7 import android.app.Activity
9 import android.app.Dialog 8 import android.app.Dialog
10 import android.app.NotificationChannel 9 import android.app.NotificationChannel
11 import android.app.NotificationManager 10 import android.app.NotificationManager
64 import android.content.Intent 63 import android.content.Intent
65 import android.util.* 64 import android.util.*
66 import android.util.Base64 65 import android.util.Base64
67 import kotlin.math.* 66 import kotlin.math.*
68 import android.content.ContentUris 67 import android.content.ContentUris
69 import androidx.appcompat.widget.AppCompatSeekBar
70 import android.content.DialogInterface 68 import android.content.DialogInterface
71 import android.graphics.pdf.PdfDocument 69 import android.graphics.pdf.PdfDocument
72 import android.print.* 70 import android.print.*
73 import android.print.pdf.PrintedPdfDocument 71 import android.print.pdf.PrintedPdfDocument
74 import android.widget.Checkable 72 import android.widget.Checkable
75 73
76 import android.widget.LinearLayout 74 import android.widget.LinearLayout
75 import android.graphics.BitmapFactory
76
77 import android.graphics.Bitmap
78
79
80
77 81
78 82
79 83
80 84
81 85
1218 textview.setBackgroundColor(colorBack!!) 1222 textview.setBackgroundColor(colorBack!!)
1219 } 1223 }
1220 return thisview 1224 return thisview
1221 } 1225 }
1222 } 1226 }
1227 colorSelected = getPlatformSelectionColor(context)
1223 onItemClickListener = this 1228 onItemClickListener = this
1224 } 1229 }
1225 1230
1226 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) { 1231 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
1227 selected = position 1232 selected = position
1656 } 1661 }
1657 } 1662 }
1658 1663
1659 class DWContainerRow : LinearLayout, Checkable { 1664 class DWContainerRow : LinearLayout, Checkable {
1660 private var mChecked = false 1665 private var mChecked = false
1661 1666 private var colorSelection = Color.DKGRAY
1662 constructor(context: Context?) : super(context) {} 1667
1663 constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {} 1668 constructor(context: Context?) : super(context) {
1664 constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {} 1669 colorSelection = context?.let { getPlatformSelectionColor(it) }!!
1670 }
1671 constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
1672 colorSelection = context?.let { getPlatformSelectionColor(it) }!!
1673 }
1674 constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
1675 colorSelection = context?.let { getPlatformSelectionColor(it) }!!
1676 }
1665 1677
1666 fun updateBackground() { 1678 fun updateBackground() {
1667 if(mChecked) { 1679 if(mChecked) {
1668 this.setBackgroundColor(Color.DKGRAY) 1680 this.setBackgroundColor(colorSelection)
1669 } else { 1681 } else {
1670 this.setBackgroundColor(Color.TRANSPARENT) 1682 this.setBackgroundColor(Color.TRANSPARENT)
1671 } 1683 }
1672 } 1684 }
1673 1685
1820 } 1832 }
1821 super.onSizeChanged(w, h, oldw, oldh) 1833 super.onSizeChanged(w, h, oldw, oldh)
1822 } 1834 }
1823 } 1835 }
1824 1836
1837 fun getPlatformSelectionColor(context: Context): Int {
1838 val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.list_selector_background)
1839 var redBucket: Float = 0f
1840 var greenBucket: Float = 0f
1841 var blueBucket: Float = 0f
1842 var pixelCount: Float = 0f
1843
1844 if(bitmap != null) {
1845 for (y in 0 until bitmap.height) {
1846 for (x in 0 until bitmap.width) {
1847 val c = bitmap.getPixel(x, y)
1848 pixelCount++
1849 redBucket += Color.red(c)
1850 greenBucket += Color.green(c)
1851 blueBucket += Color.blue(c)
1852 }
1853 }
1854
1855 return Color.rgb(
1856 (redBucket / pixelCount).toInt(),
1857 (greenBucket / pixelCount).toInt(),
1858 (blueBucket / pixelCount).toInt()
1859 )
1860 }
1861 return Color.GRAY
1862 }
1863
1825 class DWindows : AppCompatActivity() { 1864 class DWindows : AppCompatActivity() {
1826 var windowLayout: ViewPager2? = null 1865 var windowLayout: ViewPager2? = null
1827 var threadLock = ReentrantLock() 1866 var threadLock = ReentrantLock()
1828 var threadCond = threadLock.newCondition() 1867 var threadCond = threadLock.newCondition()
1829 var notificationID: Int = 0 1868 var notificationID: Int = 0
1830 var darkMode: Int = -1 1869 var darkMode: Int = -1
1831 var lastClickView: View? = null 1870 var lastClickView: View? = null
1871 var colorSelection: Int = Color.DKGRAY
1832 private var appID: String? = null 1872 private var appID: String? = null
1833 private var paint = Paint() 1873 private var paint = Paint()
1834 private var bgcolor: Int? = null 1874 private var bgcolor: Int? = null
1835 private var fileURI: Uri? = null 1875 private var fileURI: Uri? = null
1836 private var fileLock = ReentrantLock() 1876 private var fileLock = ReentrantLock()
1949 windowLayout!!.layoutParams = 1989 windowLayout!!.layoutParams =
1950 ViewGroup.LayoutParams( 1990 ViewGroup.LayoutParams(
1951 ViewGroup.LayoutParams.MATCH_PARENT, 1991 ViewGroup.LayoutParams.MATCH_PARENT,
1952 ViewGroup.LayoutParams.MATCH_PARENT 1992 ViewGroup.LayoutParams.MATCH_PARENT
1953 ) 1993 )
1994
1995 colorSelection = getPlatformSelectionColor(this)
1954 1996
1955 // Initialize the Dynamic Windows code... 1997 // Initialize the Dynamic Windows code...
1956 // This will start a new thread that calls the app's dwmain() 1998 // This will start a new thread that calls the app's dwmain()
1957 dwindowsInit(s, c, this.getPackageName()) 1999 dwindowsInit(s, c, this.getPackageName())
1958 } 2000 }