comparison android/DWindows.kt @ 2552:303f544d14fa

Android: Refactor boxPack() to try to fix non-expandable items expanding. This didn't work, so more needs to be done but I liked the refactoring.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 15 May 2021 19:11:53 +0000
parents 127779860ac1
children 2b4f2929408e
comparison
equal deleted inserted replaced
2551:127779860ac1 2552:303f544d14fa
544 menuBar!!.createMenu(menu) 544 menuBar!!.createMenu(menu)
545 } 545 }
546 return super.onPrepareOptionsMenu(menu) 546 return super.onPrepareOptionsMenu(menu)
547 } 547 }
548 548
549 // These are the Android calls to actually create the UI...
550 // forwarded from the C Dynamic Windows API
551
549 fun darkModeDetected(): Int 552 fun darkModeDetected(): Int
550 { 553 {
551 return darkMode 554 return darkMode
552 } 555 }
553 556
644 } 647 }
645 } 648 }
646 } 649 }
647 } 650 }
648 651
649 /*
650 * These are the Android calls to actually create the UI...
651 * forwarded from the C Dynamic Windows API
652 */
653 fun windowNew(title: String, style: Int): LinearLayout? { 652 fun windowNew(title: String, style: Int): LinearLayout? {
654 if (firstWindow) { 653 if (firstWindow) {
655 waitOnUiThread { 654 waitOnUiThread {
656 var dataArrayMap = SimpleArrayMap<String, Long>() 655 var dataArrayMap = SimpleArrayMap<String, Long>()
657 windowLayout = LinearLayout(this) 656 windowLayout = LinearLayout(this)
952 } 951 }
953 952
954 if (box != null) { 953 if (box != null) {
955 if ((item is LinearLayout) or (item is ScrollView)) { 954 if ((item is LinearLayout) or (item is ScrollView)) {
956 if (box.orientation == LinearLayout.VERTICAL) { 955 if (box.orientation == LinearLayout.VERTICAL) {
957 if (hsize > 0) { 956 if (hsize != 0) {
958 w = LinearLayout.LayoutParams.MATCH_PARENT 957 w = LinearLayout.LayoutParams.MATCH_PARENT
959 } 958 }
960 } else { 959 } else {
961 if (vsize > 0) { 960 if (vsize != 0) {
962 h = LinearLayout.LayoutParams.MATCH_PARENT 961 h = LinearLayout.LayoutParams.MATCH_PARENT
963 } 962 }
964 } 963 }
965 } 964 }
966 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) 965 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h)
967 966
968 if (item !is LinearLayout && (width != -1 || height != -1)) { 967 // If it isn't a box... set or calculate the size as needed
969 item.measure(0, 0) 968 if (item !is LinearLayout) {
970 if (width > 0) { 969 if(width != -1 || height != -1) {
970 item.measure(0, 0)
971 }
972 if(width > 0) {
971 w = width 973 w = width
972 } else if (width == -1) { 974 } else if (width == -1) {
973 w = item.getMeasuredWidth() 975 w = item.getMeasuredWidth()
974 } 976 }
975 if (height > 0) { 977 if(height > 0) {
976 h = height 978 h = height
977 } else if (height == -1) { 979 } else if(height == -1) {
978 h = item.getMeasuredHeight() 980 h = item.getMeasuredHeight()
979 } 981 }
980 } 982 // Handle non-expandable items
983 if(hsize == 0 && w > 0) {
984 params.width = w
985 }
986 if(vsize == 0 && h > 0) {
987 params.height = h
988 }
989 }
990
991 // Handle expandable items by giving them a weight...
992 // in the direction of the box.
981 if (box.orientation == LinearLayout.VERTICAL) { 993 if (box.orientation == LinearLayout.VERTICAL) {
982 if (vsize > 0) { 994 if (vsize != 0) {
983 if (w > 0) { 995 if (w > 0) {
984 params.weight = w.toFloat() 996 params.weight = w.toFloat()
985 } else { 997 } else {
986 params.weight = 1F 998 params.weight = 1F
987 } 999 }
988 } 1000 }
989 } else { 1001 } else {
990 if (hsize > 0) { 1002 if (hsize != 0) {
991 if (h > 0) { 1003 if (h > 0) {
992 params.weight = h.toFloat() 1004 params.weight = h.toFloat()
993 } else { 1005 } else {
994 params.weight = 1F 1006 params.weight = 1F
995 } 1007 }
996 } 1008 }
997 } 1009 }
1010 // Gravity needs to match the expandable settings
1011 var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL
1012 if (hsize != 0 && vsize != 0) {
1013 params.gravity = Gravity.FILL or grav
1014 } else if (hsize != 0) {
1015 params.gravity = Gravity.FILL_HORIZONTAL or grav
1016 } else if (vsize != 0) {
1017 params.gravity = Gravity.FILL_VERTICAL or grav
1018 }
1019 // Finally add the padding
998 if (pad > 0) { 1020 if (pad > 0) {
999 params.setMargins(pad, pad, pad, pad) 1021 params.setMargins(pad, pad, pad, pad)
1000 }
1001 var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL
1002 if (hsize > 0 && vsize > 0) {
1003 params.gravity = Gravity.FILL or grav
1004 } else if (hsize > 0) {
1005 params.gravity = Gravity.FILL_HORIZONTAL or grav
1006 } else if (vsize > 0) {
1007 params.gravity = Gravity.FILL_VERTICAL or grav
1008 } 1022 }
1009 item.layoutParams = params 1023 item.layoutParams = params
1010 box.addView(item, index) 1024 box.addView(item, index)
1011 } 1025 }
1012 } 1026 }