comparison android/DWindows.kt @ 2685:17c34bdaec6c

Android: Put in some list bounds safety checks... them getting hit however... means the app is in an unexpected state. But getting it from time to time in the simulator.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 26 Oct 2021 06:17:53 +0000
parents a26e5a2d94be
children 95f61d3f3d0d
comparison
equal deleted inserted replaced
2684:a26e5a2d94be 2685:17c34bdaec6c
947 // Send a DW_SIGNAL_CONFIGURE on orientation change 947 // Send a DW_SIGNAL_CONFIGURE on orientation change
948 if(windowLayout != null) { 948 if(windowLayout != null) {
949 val width: Int = windowLayout!!.width 949 val width: Int = windowLayout!!.width
950 val height: Int = windowLayout!!.height 950 val height: Int = windowLayout!!.height
951 val adapter: DWTabViewPagerAdapter = windowLayout!!.adapter as DWTabViewPagerAdapter 951 val adapter: DWTabViewPagerAdapter = windowLayout!!.adapter as DWTabViewPagerAdapter
952 val window = adapter.viewList[windowLayout!!.currentItem] 952 val index = windowLayout!!.currentItem
953 953 val count = adapter.viewList.count()
954 eventHandlerInt(window, DWEvent.CONFIGURE, width, height, 0, 0) 954
955 if(count > 0 && index < count) {
956 val window = adapter.viewList[index]
957
958 eventHandlerInt(window, DWEvent.CONFIGURE, width, height, 0, 0)
959 }
955 } 960 }
956 } 961 }
957 962
958 override fun onCreateOptionsMenu(menu: Menu?): Boolean { 963 override fun onCreateOptionsMenu(menu: Menu?): Boolean {
959 if(windowLayout != null) { 964 if(windowLayout != null) {
960 val index = windowLayout!!.currentItem 965 val index = windowLayout!!.currentItem
961 966 val count = windowMenuBars.count()
962 if (windowMenuBars.count() > 0) { 967
968 if (count > 0 && index < count) {
963 var menuBar = windowMenuBars[index] 969 var menuBar = windowMenuBars[index]
964 970
965 if(menuBar == null) { 971 if(menuBar == null) {
966 menuBar = DWMenu() 972 menuBar = DWMenu()
967 windowMenuBars[index] = menuBar 973 windowMenuBars[index] = menuBar
974 } 980 }
975 981
976 override fun onPrepareOptionsMenu(menu: Menu?): Boolean { 982 override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
977 if(windowLayout != null) { 983 if(windowLayout != null) {
978 val index = windowLayout!!.currentItem 984 val index = windowLayout!!.currentItem
979 985 val count = windowMenuBars.count()
980 if (windowMenuBars.count() > 0) { 986
987 if (count > 0 && index < count) {
981 var menuBar = windowMenuBars[index] 988 var menuBar = windowMenuBars[index]
982 989
983 if(menuBar != null) { 990 if(menuBar != null) {
984 menuBar!!.createMenu(menu, true) 991 menuBar!!.createMenu(menu, true)
985 } else { 992 } else {
995 1002
996 override fun onBackPressed() { 1003 override fun onBackPressed() {
997 if(windowLayout != null) { 1004 if(windowLayout != null) {
998 val adapter: DWTabViewPagerAdapter = windowLayout!!.adapter as DWTabViewPagerAdapter 1005 val adapter: DWTabViewPagerAdapter = windowLayout!!.adapter as DWTabViewPagerAdapter
999 val index = windowLayout!!.currentItem 1006 val index = windowLayout!!.currentItem
1007 val count = windowStyles.count()
1000 1008
1001 // If the current window has a close button... 1009 // If the current window has a close button...
1002 if (index > 0 && (windowStyles[index] and 1) == 1) { 1010 if (count > 1 && index > 0 && index < count && (windowStyles[index] and 1) == 1) {
1003 // Send the DW_SIGNAL_DELETE to the event handler 1011 // Send the DW_SIGNAL_DELETE to the event handler
1004 eventHandlerSimple(adapter.viewList[index], DWEvent.DELETE) 1012 eventHandlerSimple(adapter.viewList[index], DWEvent.DELETE)
1005 } 1013 }
1006 } 1014 }
1007 } 1015 }