Mercurial > dwindows
comparison android/DWindows.kt @ 2543:f9367eb9a6e7
Android: Initial menu support, incomplete but basics functional.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 13 May 2021 19:54:15 +0000 |
parents | bb75e64e6138 |
children | dbfcc0e357d6 |
comparison
equal
deleted
inserted
replaced
2542:bb75e64e6138 | 2543:f9367eb9a6e7 |
---|---|
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.view.Gravity | 28 import android.view.* |
29 import android.view.MotionEvent | |
30 import android.view.View | |
31 import android.view.View.OnTouchListener | 29 import android.view.View.OnTouchListener |
32 import android.view.ViewGroup | |
33 import android.view.inputmethod.EditorInfo | 30 import android.view.inputmethod.EditorInfo |
34 import android.webkit.WebView | 31 import android.webkit.WebView |
35 import android.webkit.WebViewClient | 32 import android.webkit.WebViewClient |
36 import android.widget.* | 33 import android.widget.* |
37 import android.widget.AdapterView.OnItemClickListener | 34 import android.widget.AdapterView.OnItemClickListener |
395 dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) | 392 dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) |
396 refresh(Environment.getExternalStorageDirectory()) | 393 refresh(Environment.getExternalStorageDirectory()) |
397 } | 394 } |
398 } | 395 } |
399 | 396 |
397 // On Android we can't pre-create submenus... | |
398 // So create our own placeholder classes, and create the actual menus | |
399 // on demand when required by Android | |
400 class DWMenuItem | |
401 { | |
402 var title: String? = null | |
403 var menu: DWMenu? = null | |
404 var submenu: DWMenu? = null | |
405 var checked: Boolean = false | |
406 var check: Boolean = false | |
407 var menuitem: MenuItem? = null | |
408 var submenuitem: SubMenu? = null | |
409 var id: Int = 0 | |
410 } | |
411 | |
412 class DWMenu { | |
413 var menu: Menu? = null | |
414 var children = mutableListOf<DWMenuItem>() | |
415 var id: Int = 0 | |
416 | |
417 fun createMenu(newmenu: Menu?) { | |
418 if(menu == null) { | |
419 menu = newmenu | |
420 } | |
421 if(menu != null) { | |
422 for (menuitem in children) { | |
423 // Submenus on Android can't have submenus, so stop at depth 1 | |
424 if (menuitem.submenu != null && menu !is SubMenu) { | |
425 if(menuitem.submenuitem == null) { | |
426 menuitem.submenuitem = menu?.addSubMenu(0, menuitem.id, 0, menuitem.title) | |
427 } | |
428 menuitem.submenu!!.createMenu(menuitem.submenuitem) | |
429 } else if(menuitem.submenu == null) { | |
430 if(menuitem.menuitem == null) { | |
431 menuitem.menuitem = menu?.add(0, menuitem.id, 0, menuitem.title) | |
432 } | |
433 } | |
434 } | |
435 } | |
436 } | |
437 } | |
438 | |
400 class DWindows : AppCompatActivity() { | 439 class DWindows : AppCompatActivity() { |
401 var firstWindow: Boolean = true | 440 var firstWindow: Boolean = true |
402 var windowLayout: LinearLayout? = null | 441 var windowLayout: LinearLayout? = null |
403 var threadLock = ReentrantLock() | 442 var threadLock = ReentrantLock() |
404 var threadCond = threadLock.newCondition() | 443 var threadCond = threadLock.newCondition() |
405 var notificationID: Int = 0 | 444 var notificationID: Int = 0 |
406 private var paint = Paint() | 445 private var paint = Paint() |
407 private var bgcolor: Int = 0 | 446 private var bgcolor: Int = 0 |
447 private var menuBar: DWMenu? = null | |
408 | 448 |
409 // Our version of runOnUiThread that waits for execution | 449 // Our version of runOnUiThread that waits for execution |
410 fun waitOnUiThread(runnable: Runnable) | 450 fun waitOnUiThread(runnable: Runnable) |
411 { | 451 { |
412 if(Looper.myLooper() == Looper.getMainLooper()) { | 452 if(Looper.myLooper() == Looper.getMainLooper()) { |
455 var width: Int = windowLayout!!.width | 495 var width: Int = windowLayout!!.width |
456 var height: Int = windowLayout!!.height | 496 var height: Int = windowLayout!!.height |
457 | 497 |
458 eventHandlerInt(windowLayout as View, 1, width, height, 0, 0) | 498 eventHandlerInt(windowLayout as View, 1, width, height, 0, 0) |
459 } | 499 } |
500 } | |
501 | |
502 override fun onCreateOptionsMenu(menu: Menu?): Boolean { | |
503 if(menuBar == null) { | |
504 menuBar = DWMenu() | |
505 menuBar!!.menu = menu | |
506 } | |
507 return super.onCreateOptionsMenu(menu) | |
508 } | |
509 | |
510 override fun onPrepareOptionsMenu(menu: Menu?): Boolean { | |
511 if(menuBar != null) { | |
512 menuBar!!.createMenu(menu) | |
513 } else { | |
514 menuBar = DWMenu() | |
515 menuBar!!.createMenu(menu) | |
516 } | |
517 return super.onPrepareOptionsMenu(menu) | |
518 } | |
519 | |
520 fun menuBarNew(location: View): DWMenu? | |
521 { | |
522 // TODO: Make sure location is this activity | |
523 return menuBar | |
524 } | |
525 | |
526 fun menuNew(cid: Int): DWMenu | |
527 { | |
528 val menu = DWMenu() | |
529 menu.id = cid | |
530 return menu | |
531 } | |
532 | |
533 fun menuAppendItem(menu: DWMenu, title: String, cid: Int, flags: Int, end: Int, check: Int, submenu: DWMenu?): DWMenuItem | |
534 { | |
535 val menuitem = DWMenuItem() | |
536 menuitem.id = cid | |
537 menuitem.title = title | |
538 menuitem.check = check != 0 | |
539 if(submenu != null) { | |
540 menuitem.submenu = submenu | |
541 } | |
542 if((flags and (1 shl 2)) != 0) { | |
543 menuitem.checked = true | |
544 } | |
545 if(end == 0) { | |
546 menu.children.add(0, menuitem) | |
547 } else { | |
548 menu.children.add(menuitem) | |
549 } | |
550 return menuitem | |
460 } | 551 } |
461 | 552 |
462 /* | 553 /* |
463 * These are the Android calls to actually create the UI... | 554 * These are the Android calls to actually create the UI... |
464 * forwarded from the C Dynamic Windows API | 555 * forwarded from the C Dynamic Windows API |
2274 getSystemService(NOTIFICATION_SERVICE) as NotificationManager | 2365 getSystemService(NOTIFICATION_SERVICE) as NotificationManager |
2275 notificationManager.createNotificationChannel(mChannel) | 2366 notificationManager.createNotificationChannel(mChannel) |
2276 } | 2367 } |
2277 } | 2368 } |
2278 return Build.VERSION.SDK_INT | 2369 return Build.VERSION.SDK_INT |
2370 } | |
2371 | |
2372 fun dwMain() | |
2373 { | |
2374 runOnUiThread { | |
2375 // Trigger the options menu to update when dw_main() is called | |
2376 invalidateOptionsMenu() | |
2377 } | |
2279 } | 2378 } |
2280 | 2379 |
2281 fun androidGetRelease(): String | 2380 fun androidGetRelease(): String |
2282 { | 2381 { |
2283 return Build.VERSION.RELEASE | 2382 return Build.VERSION.RELEASE |