Mercurial > dwindows
comparison android/DWindows.kt @ 2668:917f2d1f9cae
Android: Implement dw_window_destroy() and try to add a back button to
secondary windows that will call windowDestroy() on them when pressed.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 17 Oct 2021 00:34:16 +0000 |
parents | 2ae70678c845 |
children | 2ad924c6493d |
comparison
equal
deleted
inserted
replaced
2667:2ae70678c845 | 2668:917f2d1f9cae |
---|---|
967 } | 967 } |
968 } | 968 } |
969 return false | 969 return false |
970 } | 970 } |
971 | 971 |
972 override fun onBackPressed() { | |
973 if(windowLayout != null) { | |
974 val adapter: DWTabViewPagerAdapter = windowLayout!!.adapter as DWTabViewPagerAdapter | |
975 val index = windowLayout!!.currentItem | |
976 | |
977 if (index > 0) { | |
978 windowDestroy(adapter.viewList[index]) | |
979 } | |
980 } | |
981 } | |
982 | |
972 // These are the Android calls to actually create the UI... | 983 // These are the Android calls to actually create the UI... |
973 // forwarded from the C Dynamic Windows API | 984 // forwarded from the C Dynamic Windows API |
974 | 985 |
975 fun darkModeDetected(): Int | 986 fun darkModeDetected(): Int |
976 { | 987 { |
1415 | 1426 |
1416 // If the new view has a default item, focus it | 1427 // If the new view has a default item, focus it |
1417 if(windowDefault[index] != null) { | 1428 if(windowDefault[index] != null) { |
1418 windowDefault[index]?.requestFocus() | 1429 windowDefault[index]?.requestFocus() |
1419 } | 1430 } |
1431 // Add or remove a back button depending on the visible window | |
1432 if(index > 0) { | |
1433 this.actionBar?.setDisplayHomeAsUpEnabled(true) | |
1434 } else { | |
1435 this.actionBar?.setDisplayHomeAsUpEnabled(false) | |
1436 } | |
1420 // Invalidate the menu, so it gets updated for the new window | 1437 // Invalidate the menu, so it gets updated for the new window |
1421 invalidateOptionsMenu() | 1438 invalidateOptionsMenu() |
1422 } | 1439 } |
1423 } | 1440 } |
1424 } | 1441 } |
1436 window.visibility = View.VISIBLE | 1453 window.visibility = View.VISIBLE |
1437 } | 1454 } |
1438 windowSwitchWindow(index) | 1455 windowSwitchWindow(index) |
1439 } | 1456 } |
1440 } | 1457 } |
1458 } | |
1459 | |
1460 fun windowDestroy(window: View): Int { | |
1461 var retval: Int = 1 // DW_ERROR_GENERAL | |
1462 | |
1463 if(windowLayout != null) { | |
1464 waitOnUiThread { | |
1465 val adapter: DWTabViewPagerAdapter = windowLayout!!.adapter as DWTabViewPagerAdapter | |
1466 val index = adapter.viewList.indexOf(window) | |
1467 | |
1468 // We need to have at least 1 window... | |
1469 // so only destroy secondary windows | |
1470 if(index > 0) { | |
1471 val newindex = index - 1 | |
1472 val newwindow = adapter.viewList[newindex] | |
1473 | |
1474 // Make sure the previous window is visible... | |
1475 // not sure if we should search the list for a visible | |
1476 // window or force it visible. Forcing visible for now. | |
1477 if(newwindow.visibility != View.VISIBLE) { | |
1478 newwindow.visibility = View.VISIBLE | |
1479 } | |
1480 // Switch to the previous window | |
1481 windowSwitchWindow(newindex) | |
1482 | |
1483 // Update our window list | |
1484 adapter.viewList.removeAt(index) | |
1485 windowTitles.removeAt(index) | |
1486 windowMenuBars.removeAt(index) | |
1487 windowStyles.removeAt(index) | |
1488 windowDefault.removeAt(index) | |
1489 | |
1490 retval = 0 // DW_ERROR_NONE | |
1491 } else { | |
1492 // If we are removing an individual widget, | |
1493 // find the parent layout and remove it. | |
1494 if(window.parent is ViewGroup) { | |
1495 val group = window.parent as ViewGroup | |
1496 | |
1497 group.removeView(window) | |
1498 retval = 0 // DW_ERROR_NONE | |
1499 } | |
1500 } | |
1501 } | |
1502 } | |
1503 return retval | |
1441 } | 1504 } |
1442 | 1505 |
1443 fun clipboardGetText(): String { | 1506 fun clipboardGetText(): String { |
1444 val cm: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager | 1507 val cm: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager |
1445 val clipdata = cm.primaryClip | 1508 val clipdata = cm.primaryClip |