annotate android/DWindows.kt @ 2545:f803f3b164cf

Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy(). Also enable checkbox handling.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 13 May 2021 22:03:48 +0000
parents dbfcc0e357d6
children 897d94c20365
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2484
cb5b67154399 Android: The DWindows class should be org.dbsoft.dwindows, remove dwtest.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2483
diff changeset
1 package org.dbsoft.dwindows
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2
2526
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
3 import android.R
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
4 import android.app.Activity
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
5 import android.app.Dialog
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
6 import android.app.NotificationChannel
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
7 import android.app.NotificationManager
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
8 import android.content.ClipData
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
9 import android.content.ClipboardManager
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
10 import android.content.Context
2486
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
11 import android.content.DialogInterface
2480
878d36588aaa Android: Enable app rotation and fix some issues with layout.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2479
diff changeset
12 import android.content.pm.ActivityInfo
2496
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
13 import android.content.res.Configuration
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
14 import android.graphics.*
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
15 import android.graphics.drawable.BitmapDrawable
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
16 import android.graphics.drawable.Drawable
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
17 import android.graphics.drawable.GradientDrawable
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
18 import android.media.AudioManager
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
19 import android.media.ToneGenerator
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
20 import android.os.*
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
21 import android.text.InputFilter
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
22 import android.text.InputFilter.LengthFilter
2510
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
23 import android.text.InputType
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
24 import android.text.method.PasswordTransformationMethod
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
25 import android.util.Base64
2482
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
26 import android.util.Log
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
27 import android.util.SparseBooleanArray
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
28 import android.view.*
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
29 import android.view.View.OnTouchListener
2510
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
30 import android.view.inputmethod.EditorInfo
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
31 import android.webkit.WebView
2505
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
32 import android.webkit.WebViewClient
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
33 import android.widget.*
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
34 import android.widget.AdapterView.OnItemClickListener
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
35 import android.widget.SeekBar.OnSeekBarChangeListener
2486
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
36 import androidx.appcompat.app.AlertDialog
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
37 import androidx.appcompat.app.AppCompatActivity
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
38 import androidx.appcompat.widget.AppCompatEditText
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
39 import androidx.collection.SimpleArrayMap
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
40 import androidx.core.app.NotificationCompat
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
41 import androidx.core.app.NotificationManagerCompat
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
42 import androidx.core.content.res.ResourcesCompat
2544
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
43 import androidx.core.view.MenuCompat
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
44 import androidx.recyclerview.widget.RecyclerView
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
45 import androidx.viewpager2.widget.ViewPager2
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
46 import com.google.android.material.tabs.TabLayout
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
47 import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
48 import com.google.android.material.tabs.TabLayoutMediator
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
49 import java.io.File
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
50 import java.io.FileInputStream
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
51 import java.io.FileNotFoundException
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
52 import java.util.*
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
53 import java.util.concurrent.locks.ReentrantLock
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
54
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
55
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
56 class DWTabViewPagerAdapter : RecyclerView.Adapter<DWTabViewPagerAdapter.DWEventViewHolder>() {
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
57 val viewList = mutableListOf<LinearLayout>()
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
58 val pageList = mutableListOf<Long>()
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
59 var currentPageID = 0L
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
60
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
61 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
62 DWEventViewHolder(viewList.get(viewType))
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
63
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
64 override fun getItemCount() = viewList.count()
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
65 override fun getItemViewType(position: Int): Int {
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
66 return position
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
67 }
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
68 override fun onBindViewHolder(holder: DWEventViewHolder, position: Int) {
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
69 holder.setIsRecyclable(false);
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
70 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
71
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
72 class DWEventViewHolder(var view: View) : RecyclerView.ViewHolder(view)
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
73 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
74
2505
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
75 private class DWWebViewClient : WebViewClient() {
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
76 //Implement shouldOverrideUrlLoading//
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
77 override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
78 // We always want to load in our own WebView,
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
79 // to match the behavior on the other platforms
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
80 return false
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
81 }
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
82 override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
83 // Handle the DW_HTML_CHANGE_STARTED event
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
84 eventHandlerHTMLChanged(view, 19, url, 1)
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
85 }
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
86
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
87 override fun onPageFinished(view: WebView, url: String) {
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
88 // Handle the DW_HTML_CHANGE_COMPLETE event
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
89 eventHandlerHTMLChanged(view, 19, url, 4)
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
90 }
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
91
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
92 external fun eventHandlerHTMLChanged(obj1: View, message: Int, URI: String, status: Int)
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
93 }
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
94
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
95 class DWSpinButton(context: Context) : AppCompatEditText(context), OnTouchListener {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
96 var value: Long = 0
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
97 var minimum: Long = 0
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
98 var maximum: Long = 65535
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
99
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
100 init {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
101 setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_media_previous, 0, android.R.drawable.ic_media_next, 0);
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
102 setOnTouchListener(this)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
103 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
104
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
105 override fun onTouch(v: View, event: MotionEvent): Boolean {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
106 val DRAWABLE_RIGHT = 2
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
107 val DRAWABLE_LEFT = 0
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
108
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
109 if (event.action == MotionEvent.ACTION_UP) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
110 if (event.x >= v.width - (v as EditText)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
111 .compoundDrawables[DRAWABLE_RIGHT].bounds.width()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
112 ) {
2527
eec926265888 Android: Use toLongOrNull() whenever converting from string to long...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2526
diff changeset
113 val newvalue = this.text.toString().toLongOrNull()
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
114
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
115 if(newvalue != null) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
116 value = newvalue + 1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
117 } else {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
118 value += 1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
119 }
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
120 if(value > maximum) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
121 value = maximum
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
122 }
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
123 if(value < minimum) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
124 value = minimum
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
125 }
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
126 setText(value.toString())
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
127 eventHandlerInt(14, value.toInt(), 0, 0, 0)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
128 return true
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
129 } else if (event.x <= (v as EditText)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
130 .compoundDrawables[DRAWABLE_LEFT].bounds.width()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
131 ) {
2527
eec926265888 Android: Use toLongOrNull() whenever converting from string to long...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2526
diff changeset
132 val newvalue = this.text.toString().toLongOrNull()
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
133
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
134 if(newvalue != null) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
135 value = newvalue - 1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
136 } else {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
137 value -= 1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
138 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
139 if(value > maximum) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
140 value = maximum
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
141 }
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
142 if(value < minimum) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
143 value = minimum
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
144 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
145 setText(value.toString())
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
146 eventHandlerInt(14, value.toInt(), 0, 0, 0)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
147 return true
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
148 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
149 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
150 return false
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
151 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
152
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
153 external fun eventHandlerInt(
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
154 message: Int,
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
155 inta: Int,
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
156 intb: Int,
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
157 intc: Int,
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
158 intd: Int
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
159 )
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
160 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
161
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
162 class DWComboBox(context: Context) : AppCompatEditText(context), OnTouchListener, OnItemClickListener {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
163 var lpw: ListPopupWindow? = null
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
164 var list = mutableListOf<String>()
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
165 var selected: Int = -1
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
166
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
167 init {
2516
8f5d064b7054 Android: Fix the down arrow on the comboboxes, found a system resource that works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2515
diff changeset
168 setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.arrow_down_float, 0);
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
169 setOnTouchListener(this)
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
170 lpw = ListPopupWindow(context)
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
171 lpw!!.setAdapter(
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
172 ArrayAdapter(
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
173 context,
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
174 android.R.layout.simple_list_item_1, list
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
175 )
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
176 )
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
177 lpw!!.anchorView = this
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
178 lpw!!.isModal = true
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
179 lpw!!.setOnItemClickListener(this)
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
180 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
181
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
182 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
183 val item = list[position]
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
184 selected = position
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
185 setText(item)
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
186 lpw!!.dismiss()
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
187 eventHandlerInt(11, position, 0, 0, 0)
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
188 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
189
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
190 override fun onTouch(v: View, event: MotionEvent): Boolean {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
191 val DRAWABLE_RIGHT = 2
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
192
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
193 if (event.action == MotionEvent.ACTION_UP) {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
194 if (event.x >= v.width - (v as EditText)
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
195 .compoundDrawables[DRAWABLE_RIGHT].bounds.width()
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
196 ) {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
197 lpw!!.show()
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
198 return true
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
199 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
200 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
201 return false
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
202 }
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
203
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
204 external fun eventHandlerInt(
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
205 message: Int,
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
206 inta: Int,
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
207 intb: Int,
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
208 intc: Int,
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
209 intd: Int
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
210 )
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
211 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
212
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
213 class DWListBox(context: Context) : ListView(context), OnItemClickListener {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
214 var list = mutableListOf<String>()
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
215 var selected: Int = -1
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
216
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
217 init {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
218 setAdapter(
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
219 ArrayAdapter(
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
220 context,
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
221 android.R.layout.simple_list_item_1, list
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
222 )
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
223 )
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
224 setOnItemClickListener(this)
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
225 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
226
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
227 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
228 selected = position
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
229 eventHandlerInt(11, position, 0, 0, 0)
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
230 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
231
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
232 external fun eventHandlerInt(
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
233 message: Int,
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
234 inta: Int,
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
235 intb: Int,
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
236 intc: Int,
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
237 intd: Int
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
238 )
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
239 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
240
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
241 class DWRender(context: Context) : View(context) {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
242 var cachedCanvas: Canvas? = null
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
243
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
244 override fun onSizeChanged(width: Int, height: Int, oldWidth: Int, oldHeight: Int) {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
245 super.onSizeChanged(width, height, oldWidth, oldHeight)
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
246 // Send DW_SIGNAL_CONFIGURE
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
247 eventHandlerInt(1, width, height, 0, 0)
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
248 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
249
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
250 override fun onDraw(canvas: Canvas) {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
251 super.onDraw(canvas)
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
252 cachedCanvas = canvas
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
253 // Send DW_SIGNAL_EXPOSE
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
254 eventHandlerInt(7, 0, 0, this.width, this.height)
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
255 cachedCanvas = null
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
256 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
257
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
258 external fun eventHandlerInt(
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
259 message: Int,
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
260 inta: Int,
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
261 intb: Int,
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
262 intc: Int,
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
263 intd: Int
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
264 )
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
265 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
266
2526
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
267 class DWFileChooser(private val activity: Activity) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
268 private val list: ListView = ListView(activity)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
269 private val dialog: Dialog = Dialog(activity)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
270 private var currentPath: File? = null
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
271
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
272 // filter on file extension
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
273 private var extension: String? = null
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
274 fun setExtension(extension: String?) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
275 this.extension = extension?.toLowerCase(Locale.ROOT)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
276 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
277
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
278 // file selection event handling
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
279 interface FileSelectedListener {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
280 fun fileSelected(file: File?)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
281 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
282
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
283 fun setFileListener(fileListener: FileSelectedListener?): DWFileChooser {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
284 this.fileListener = fileListener
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
285 return this
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
286 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
287
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
288 private var fileListener: FileSelectedListener? = null
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
289 fun showDialog() {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
290 dialog.show()
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
291 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
292
2527
eec926265888 Android: Use toLongOrNull() whenever converting from string to long...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2526
diff changeset
293 /*
2526
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
294 * Sort, filter and display the files for the given path.
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
295 */
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
296 private fun refresh(path: File?) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
297 currentPath = path
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
298 if (path != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
299 if (path.exists()) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
300 val dirs = path.listFiles { file -> file.isDirectory && file.canRead() }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
301 val files = path.listFiles { file ->
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
302 if (!file.isDirectory) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
303 if (!file.canRead()) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
304 false
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
305 } else if (extension == null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
306 true
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
307 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
308 file.name.toLowerCase(Locale.ROOT).endsWith(extension!!)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
309 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
310 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
311 false
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
312 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
313 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
314
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
315 // convert to an array
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
316 var i = 0
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
317 val fileList: Array<String?>
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
318 var filecount = 0
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
319 var dircount = 0
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
320 if(files != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
321 filecount = files.size
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
322 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
323 if(dirs != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
324 dircount = dirs.size
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
325 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
326 if (path.parentFile == null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
327 fileList = arrayOfNulls(dircount + filecount)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
328 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
329 fileList = arrayOfNulls(dircount + filecount + 1)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
330 fileList[i++] = PARENT_DIR
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
331 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
332 if(dirs != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
333 Arrays.sort(dirs)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
334 for (dir in dirs) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
335 fileList[i++] = dir.name
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
336 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
337 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
338 if(files != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
339 Arrays.sort(files)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
340 for (file in files) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
341 fileList[i++] = file.name
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
342 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
343 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
344
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
345 // refresh the user interface
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
346 dialog.setTitle(currentPath!!.path)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
347 list.adapter = object : ArrayAdapter<Any?>(
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
348 activity,
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
349 R.layout.simple_list_item_1, fileList
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
350 ) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
351 override fun getView(pos: Int, view: View?, parent: ViewGroup): View {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
352 val thisview = super.getView(pos, view, parent)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
353 (thisview as TextView).isSingleLine = true
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
354 return thisview
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
355 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
356 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
357 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
358 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
359 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
360
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
361 /**
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
362 * Convert a relative filename into an actual File object.
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
363 */
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
364 private fun getChosenFile(fileChosen: String): File? {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
365 return if (fileChosen == PARENT_DIR) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
366 currentPath!!.parentFile
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
367 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
368 File(currentPath, fileChosen)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
369 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
370 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
371
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
372 companion object {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
373 private const val PARENT_DIR = ".."
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
374 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
375
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
376 init {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
377 list.onItemClickListener =
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
378 OnItemClickListener { parent, view, which, id ->
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
379 val fileChosen = list.getItemAtPosition(which) as String
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
380 val chosenFile: File? = getChosenFile(fileChosen)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
381 if (chosenFile != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
382 if (chosenFile.isDirectory) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
383 refresh(chosenFile)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
384 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
385 if (fileListener != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
386 fileListener!!.fileSelected(chosenFile)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
387 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
388 dialog.dismiss()
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
389 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
390 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
391 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
392 dialog.setContentView(list)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
393 dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
394 refresh(Environment.getExternalStorageDirectory())
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
395 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
396 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
397
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
398 // On Android we can't pre-create submenus...
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
399 // So create our own placeholder classes, and create the actual menus
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
400 // on demand when required by Android
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
401 class DWMenuItem
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
402 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
403 var title: String? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
404 var menu: DWMenu? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
405 var submenu: DWMenu? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
406 var checked: Boolean = false
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
407 var check: Boolean = false
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
408 var menuitem: MenuItem? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
409 var submenuitem: SubMenu? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
410 var id: Int = 0
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
411 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
412
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
413 class DWMenu {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
414 var menu: Menu? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
415 var children = mutableListOf<DWMenuItem>()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
416 var id: Int = 0
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
417
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
418 fun createMenu(newmenu: Menu?) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
419 if(menu == null) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
420 menu = newmenu
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
421 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
422 if(menu != null) {
2544
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
423 var group: Int = 0
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
424
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
425 // Enable group dividers for separators
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
426 MenuCompat.setGroupDividerEnabled(menu, true);
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
427
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
428 for (menuitem in children) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
429 // Submenus on Android can't have submenus, so stop at depth 1
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
430 if (menuitem.submenu != null && menu !is SubMenu) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
431 if(menuitem.submenuitem == null) {
2544
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
432 menuitem.submenuitem = menu?.addSubMenu(group, menuitem.id, 0, menuitem.title)
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
433 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
434 menuitem.submenu!!.createMenu(menuitem.submenuitem)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
435 } else if(menuitem.submenu == null) {
2544
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
436 if(menuitem.title!!.isEmpty()) {
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
437 group += 1
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
438 } else if(menuitem.menuitem == null) {
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
439 menuitem.menuitem = menu?.add(group, menuitem.id, 0, menuitem.title)
2545
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
440 menuitem.menuitem!!.isCheckable = menuitem.check
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
441 menuitem.menuitem!!.isChecked = menuitem.checked
2544
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
442 menuitem.menuitem!!.setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener { item: MenuItem? ->
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
443 eventHandlerSimple(menuitem, 8)
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
444 true
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
445 })
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
446 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
447 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
448 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
449 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
450 }
2544
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
451
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
452 external fun eventHandlerSimple(item: DWMenuItem, message: Int)
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
453 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
454
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
455 class DWindows : AppCompatActivity() {
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
456 var firstWindow: Boolean = true
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
457 var windowLayout: LinearLayout? = null
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
458 var threadLock = ReentrantLock()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
459 var threadCond = threadLock.newCondition()
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
460 var notificationID: Int = 0
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
461 private var paint = Paint()
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
462 private var bgcolor: Int = 0
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
463 private var menuBar: DWMenu? = null
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
464
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
465 // Our version of runOnUiThread that waits for execution
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
466 fun waitOnUiThread(runnable: Runnable)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
467 {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
468 if(Looper.myLooper() == Looper.getMainLooper()) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
469 runnable.run()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
470 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
471 threadLock.lock()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
472 val ourRunnable = Runnable {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
473 threadLock.lock()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
474 runnable.run()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
475 threadCond.signal()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
476 threadLock.unlock()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
477 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
478 runOnUiThread(ourRunnable)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
479 threadCond.await()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
480 threadLock.unlock()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
481 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
482 }
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
483
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
484 // We only want to call this once when the app starts up
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
485 // By default Android will call onCreate for rotation and other
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
486 // changes. This is incompatible with Dynamic Windows...
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
487 // Make sure the following is in your AndroidManifest.xml
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
488 // android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
489 override fun onCreate(savedInstanceState: Bundle?) {
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
490 super.onCreate(savedInstanceState)
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
491
2480
878d36588aaa Android: Enable app rotation and fix some issues with layout.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2479
diff changeset
492 // Turn on rotation
878d36588aaa Android: Enable app rotation and fix some issues with layout.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2479
diff changeset
493 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR)
878d36588aaa Android: Enable app rotation and fix some issues with layout.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2479
diff changeset
494
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
495 // Get the Android app path
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
496 val m = packageManager
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
497 var s = packageName
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
498 val p = m.getPackageInfo(s!!, 0)
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
499 s = p.applicationInfo.dataDir
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
500
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
501 // Initialize the Dynamic Windows code...
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
502 // This will start a new thread that calls the app's dwmain()
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
503 dwindowsInit(s, this.getPackageName())
2496
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
504 }
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
505
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
506 override fun onConfigurationChanged(newConfig: Configuration) {
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
507 super.onConfigurationChanged(newConfig)
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
508
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
509 // Send a DW_SIGNAL_CONFIGURE on orientation change
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
510 if(windowLayout != null) {
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
511 var width: Int = windowLayout!!.width
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
512 var height: Int = windowLayout!!.height
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
513
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
514 eventHandlerInt(windowLayout as View, 1, width, height, 0, 0)
2496
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
515 }
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
516 }
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
517
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
518 override fun onCreateOptionsMenu(menu: Menu?): Boolean {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
519 if(menuBar == null) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
520 menuBar = DWMenu()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
521 menuBar!!.menu = menu
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
522 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
523 return super.onCreateOptionsMenu(menu)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
524 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
525
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
526 override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
527 if(menuBar != null) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
528 menuBar!!.createMenu(menu)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
529 } else {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
530 menuBar = DWMenu()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
531 menuBar!!.createMenu(menu)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
532 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
533 return super.onPrepareOptionsMenu(menu)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
534 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
535
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
536 fun menuBarNew(location: View): DWMenu?
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
537 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
538 // TODO: Make sure location is this activity
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
539 return menuBar
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
540 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
541
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
542 fun menuNew(cid: Int): DWMenu
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
543 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
544 val menu = DWMenu()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
545 menu.id = cid
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
546 return menu
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
547 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
548
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
549 fun menuAppendItem(menu: DWMenu, title: String, cid: Int, flags: Int, end: Int, check: Int, submenu: DWMenu?): DWMenuItem
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
550 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
551 val menuitem = DWMenuItem()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
552 menuitem.id = cid
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
553 menuitem.title = title
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
554 menuitem.check = check != 0
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
555 if(submenu != null) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
556 menuitem.submenu = submenu
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
557 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
558 if((flags and (1 shl 2)) != 0) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
559 menuitem.checked = true
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
560 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
561 if(end == 0) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
562 menu.children.add(0, menuitem)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
563 } else {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
564 menu.children.add(menuitem)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
565 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
566 return menuitem
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
567 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
568
2545
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
569 fun menuDestroy(menu: DWMenu)
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
570 {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
571 menu.children.clear()
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
572 runOnUiThread {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
573 menu.menu!!.clear()
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
574 invalidateOptionsMenu()
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
575 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
576 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
577
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
578 fun menuDeleteItem(menu: DWMenu, cid: Int)
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
579 {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
580 for(menuitem in menu.children) {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
581 if(menuitem.id == cid) {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
582 menu.children.remove(menuitem)
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
583 runOnUiThread {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
584 menu.menu!!.removeItem(menuitem.id)
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
585 invalidateOptionsMenu()
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
586 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
587 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
588 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
589 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
590
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
591 fun menuSetState(menu: DWMenu, cid: Int, state: Int)
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
592 {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
593 for(menuitem in menu.children) {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
594 if(menuitem.id == cid) {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
595 // Handle DW_MIS_CHECKED/UNCHECKED
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
596 if((state and ((1 shl 2) or (1 shl 3))) != 0) {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
597 var checked: Boolean = false
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
598
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
599 // Handle DW_MIS_CHECKED
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
600 if ((state and (1 shl 2)) != 0) {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
601 checked = true
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
602 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
603 menuitem.checked = checked
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
604 runOnUiThread {
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
605 menuitem.menuitem!!.isChecked = checked
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
606 invalidateOptionsMenu()
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
607 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
608 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
609 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
610 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
611 }
f803f3b164cf Android: Implement dw_menu_item_set_state/check() dw_menu_item_delete() and dw_menu_destroy().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2544
diff changeset
612
2475
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
613 /*
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
614 * These are the Android calls to actually create the UI...
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
615 * forwarded from the C Dynamic Windows API
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
616 */
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
617 fun windowNew(title: String, style: Int): LinearLayout? {
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
618 if (firstWindow) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
619 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
620 var dataArrayMap = SimpleArrayMap<String, Long>()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
621 windowLayout = LinearLayout(this)
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
622
2503
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
623 windowLayout!!.visibility = View.GONE
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
624 windowLayout!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
625 setContentView(windowLayout)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
626 this.title = title
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
627 // For now we just return our DWindows' main activity layout...
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
628 // in the future, later calls should create new activities
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
629 firstWindow = false
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
630 }
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
631 return windowLayout
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
632 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
633 return null
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
634 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
635
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
636 fun windowFromId(window: View, cid: Int): View {
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
637 return window.findViewById(cid)
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
638 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
639
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
640 fun windowSetData(window: View, name: String, data: Long) {
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
641 if (window.tag != null) {
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
642 var dataArrayMap: SimpleArrayMap<String, Long> = window.tag as SimpleArrayMap<String, Long>
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
643
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
644 if (data != 0L) {
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
645 dataArrayMap.put(name, data)
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
646 } else {
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
647 dataArrayMap.remove(name)
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
648 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
649 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
650 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
651
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
652 fun windowGetData(window: View, name: String): Long {
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
653 var retval: Long = 0L
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
654
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
655 if (window.tag != null) {
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
656 var dataArrayMap: SimpleArrayMap<String, Long> = window.tag as SimpleArrayMap<String, Long>
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
657
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
658 retval = dataArrayMap.get(name)!!
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
659 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
660 return retval
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
661 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
662
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
663 fun windowSetEnabled(window: View, state: Boolean) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
664 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
665 window.setEnabled(state)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
666 }
2475
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
667 }
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
668
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
669 fun windowSetText(window: View, text: String) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
670 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
671 if (window is TextView) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
672 var textview: TextView = window
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
673 textview.text = text
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
674 } else if (window is Button) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
675 var button: Button = window
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
676 button.text = text
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
677 } else if (window is LinearLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
678 // TODO: Make sure this is actually the top-level layout, not just a box
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
679 this.title = text
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
680 }
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
681 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
682 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
683
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
684 fun windowGetText(window: View): String? {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
685 var text: String? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
686
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
687 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
688 if (window is TextView) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
689 var textview: TextView = window
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
690 text = textview.text.toString()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
691 } else if (window is Button) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
692 var button: Button = window
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
693 text = button.text.toString()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
694 } else if (window is LinearLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
695 // TODO: Make sure this is actually the top-level layout, not just a box
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
696 text = this.title.toString()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
697 }
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
698 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
699 return text
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
700 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
701
2503
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
702 fun windowHideShow(window: View, state: Int)
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
703 {
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
704 waitOnUiThread {
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
705 if(state == 0) {
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
706 window.visibility = View.GONE
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
707 } else {
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
708 window.visibility = View.VISIBLE
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
709 }
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
710 }
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
711 }
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
712
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
713 fun clipboardGetText(): String {
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
714 var cm: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
715 var clipdata = cm.primaryClip
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
716
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
717 if (clipdata != null && clipdata.itemCount > 0) {
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
718 return clipdata.getItemAt(0).coerceToText(this).toString()
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
719 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
720 return ""
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
721 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
722
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
723 fun clipboardSetText(text: String) {
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
724 var cm: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
725 var clipdata = ClipData.newPlainText("text", text)
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
726
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
727 cm.setPrimaryClip(clipdata)
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
728 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
729
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
730 fun boxNew(type: Int, pad: Int): LinearLayout? {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
731 var box: LinearLayout? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
732 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
733 box = LinearLayout(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
734 var dataArrayMap = SimpleArrayMap<String, Long>()
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
735
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
736 box!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
737 box!!.layoutParams =
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
738 LinearLayout.LayoutParams(
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
739 LinearLayout.LayoutParams.WRAP_CONTENT,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
740 LinearLayout.LayoutParams.WRAP_CONTENT
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
741 )
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
742 if (type > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
743 box!!.orientation = LinearLayout.VERTICAL
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
744 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
745 box!!.orientation = LinearLayout.HORIZONTAL
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
746 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
747 box!!.setPadding(pad, pad, pad, pad)
2475
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
748 }
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
749 return box
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
750 }
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
751
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
752 fun scrollBoxNew(type: Int, pad: Int) : ScrollView? {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
753 var scrollBox: ScrollView? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
754
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
755 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
756 val box = LinearLayout(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
757 scrollBox = ScrollView(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
758 var dataArrayMap = SimpleArrayMap<String, Long>()
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
759
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
760 scrollBox!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
761 box.layoutParams =
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
762 LinearLayout.LayoutParams(
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
763 LinearLayout.LayoutParams.MATCH_PARENT,
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
764 LinearLayout.LayoutParams.MATCH_PARENT
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
765 )
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
766 if (type > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
767 box.orientation = LinearLayout.VERTICAL
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
768 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
769 box.orientation = LinearLayout.HORIZONTAL
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
770 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
771 box.setPadding(pad, pad, pad, pad)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
772 // Add a pointer back to the ScrollView
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
773 box.tag = scrollBox
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
774 scrollBox!!.addView(box)
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
775 }
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
776 return scrollBox
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
777 }
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
778
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
779 fun boxPack(
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
780 boxview: View,
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
781 item: View,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
782 index: Int,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
783 width: Int,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
784 height: Int,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
785 hsize: Int,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
786 vsize: Int,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
787 pad: Int
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
788 ) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
789 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
790 var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
791 var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
792 var box: LinearLayout? = null
2475
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
793
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
794 // Handle scrollboxes by pulling the LinearLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
795 // out of the ScrollView to pack into
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
796 if (boxview is LinearLayout) {
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
797 box = boxview
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
798 } else if (boxview is ScrollView) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
799 var sv: ScrollView = boxview
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
800
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
801 if (sv.getChildAt(0) is LinearLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
802 box = sv.getChildAt(0) as LinearLayout
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
803 }
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
804 }
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
805
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
806 if (box != null) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
807 if ((item is LinearLayout) or (item is ScrollView)) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
808 if (box.orientation == LinearLayout.VERTICAL) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
809 if (hsize > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
810 w = LinearLayout.LayoutParams.MATCH_PARENT
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
811 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
812 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
813 if (vsize > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
814 h = LinearLayout.LayoutParams.MATCH_PARENT
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
815 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
816 }
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
817 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
818 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
819
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
820 if (item !is LinearLayout && (width != -1 || height != -1)) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
821 item.measure(0, 0)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
822 if (width > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
823 w = width
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
824 } else if (width == -1) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
825 w = item.getMeasuredWidth()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
826 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
827 if (height > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
828 h = height
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
829 } else if (height == -1) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
830 h = item.getMeasuredHeight()
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
831 }
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
832 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
833 if (box.orientation == LinearLayout.VERTICAL) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
834 if (vsize > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
835 if (w > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
836 params.weight = w.toFloat()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
837 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
838 params.weight = 1F
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
839 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
840 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
841 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
842 if (hsize > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
843 if (h > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
844 params.weight = h.toFloat()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
845 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
846 params.weight = 1F
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
847 }
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
848 }
2480
878d36588aaa Android: Enable app rotation and fix some issues with layout.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2479
diff changeset
849 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
850 if (pad > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
851 params.setMargins(pad, pad, pad, pad)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
852 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
853 var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
854 if (hsize > 0 && vsize > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
855 params.gravity = Gravity.FILL or grav
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
856 } else if (hsize > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
857 params.gravity = Gravity.FILL_HORIZONTAL or grav
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
858 } else if (vsize > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
859 params.gravity = Gravity.FILL_VERTICAL or grav
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
860 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
861 item.layoutParams = params
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
862 box.addView(item, index)
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
863 }
2478
b0230e378667 Android: Improvements to boxPack to handle more parameters...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2477
diff changeset
864 }
2475
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
865 }
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
866
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
867 fun boxUnpack(item: View) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
868 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
869 var box: LinearLayout = item.parent as LinearLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
870 box.removeView(item)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
871 }
2477
3fbf8783122d Android: First functional version. Notebook-less first page of dwtest works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2476
diff changeset
872 }
3fbf8783122d Android: First functional version. Notebook-less first page of dwtest works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2476
diff changeset
873
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
874 fun boxUnpackAtIndex(box: LinearLayout, index: Int): View? {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
875 var item: View? = null
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
876
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
877 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
878 item = box.getChildAt(index)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
879
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
880 box.removeView(item)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
881 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
882 return item
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
883 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
884
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
885 fun buttonNew(text: String, cid: Int): Button? {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
886 var button: Button? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
887 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
888 button = Button(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
889 var dataArrayMap = SimpleArrayMap<String, Long>()
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
890
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
891 button!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
892 button!!.text = text
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
893 button!!.id = cid
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
894 button!!.setOnClickListener {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
895 eventHandlerSimple(button!!, 8)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
896 }
2482
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
897 }
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
898 return button
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
899 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
900
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
901 fun bitmapButtonNew(text: String, resid: Int): ImageButton? {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
902 var button: ImageButton? = null
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
903 waitOnUiThread {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
904 button = ImageButton(this)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
905 var dataArrayMap = SimpleArrayMap<String, Long>()
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
906
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
907 button!!.tag = dataArrayMap
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
908 button!!.id = resid
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
909 button!!.setImageResource(resid)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
910 button!!.setOnClickListener {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
911 eventHandlerSimple(button!!, 8)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
912 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
913 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
914 return button
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
915 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
916
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
917 fun bitmapButtonNewFromFile(text: String, cid: Int, filename: String): ImageButton? {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
918 var button: ImageButton? = null
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
919 waitOnUiThread {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
920 button = ImageButton(this)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
921 var dataArrayMap = SimpleArrayMap<String, Long>()
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
922
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
923 button!!.tag = dataArrayMap
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
924 button!!.id = cid
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
925 button!!.setOnClickListener {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
926 eventHandlerSimple(button!!, 8)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
927 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
928 // Try to load the image, and protect against exceptions
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
929 try {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
930 val f = File(filename)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
931 val b = BitmapFactory.decodeStream(FileInputStream(f))
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
932 button!!.setImageBitmap(b)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
933 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
934 catch (e: FileNotFoundException)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
935 {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
936 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
937 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
938 return button
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
939 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
940
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
941 fun bitmapButtonNewFromData(text: String, cid: Int, data: ByteArray, length: Int): ImageButton? {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
942 var button: ImageButton? = null
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
943 waitOnUiThread {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
944 button = ImageButton(this)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
945 var dataArrayMap = SimpleArrayMap<String, Long>()
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
946 val b = BitmapFactory.decodeByteArray(data,0, length)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
947
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
948 button!!.tag = dataArrayMap
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
949 button!!.id = cid
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
950 button!!.setOnClickListener {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
951 eventHandlerSimple(button!!, 8)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
952 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
953 button!!.setImageBitmap(b)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
954 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
955 return button
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
956 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
957
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
958 fun entryfieldNew(text: String, cid: Int, password: Int): EditText? {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
959 var entryfield: EditText? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
960
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
961 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
962 var dataArrayMap = SimpleArrayMap<String, Long>()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
963 entryfield = EditText(this)
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
964
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
965 entryfield!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
966 entryfield!!.id = cid
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
967 if (password > 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
968 entryfield!!.transformationMethod = PasswordTransformationMethod.getInstance()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
969 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
970 entryfield!!.setText(text)
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
971 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
972 return entryfield
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
973 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
974
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
975 fun entryfieldSetLimit(entryfield: EditText, limit: Long) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
976 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
977 entryfield.filters = arrayOf<InputFilter>(LengthFilter(limit.toInt()))
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
978 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
979 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
980
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
981 fun radioButtonNew(text: String, cid: Int): RadioButton? {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
982 var radiobutton: RadioButton? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
983
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
984 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
985 var dataArrayMap = SimpleArrayMap<String, Long>()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
986 radiobutton = RadioButton(this)
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
987
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
988 radiobutton!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
989 radiobutton!!.id = cid
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
990 radiobutton!!.text = text
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
991 radiobutton!!.setOnClickListener {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
992 eventHandlerSimple(radiobutton!!, 8)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
993 }
2482
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
994 }
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
995 return radiobutton
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
996 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
997
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
998 fun checkboxNew(text: String, cid: Int): CheckBox? {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
999 var checkbox: CheckBox? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1000
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1001 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1002 var dataArrayMap = SimpleArrayMap<String, Long>()
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
1003
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1004 checkbox = CheckBox(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1005 checkbox!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1006 checkbox!!.id = cid
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1007 checkbox!!.text = text
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1008 checkbox!!.setOnClickListener {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1009 eventHandlerSimple(checkbox!!, 8)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1010 }
2482
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
1011 }
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1012 return checkbox
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1013 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1014
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1015 fun checkOrRadioSetChecked(control: View, state: Int)
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1016 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1017 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1018 if (control is CheckBox) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1019 var checkbox: CheckBox = control
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1020 checkbox.isChecked = state != 0
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1021 } else if (control is RadioButton) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1022 var radiobutton: RadioButton = control
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1023 radiobutton.isChecked = state != 0
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1024 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1025 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1026 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1027
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1028 fun checkOrRadioGetChecked(control: View): Boolean
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1029 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1030 var retval: Boolean = false
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1031
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1032 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1033 if (control is CheckBox) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1034 var checkbox: CheckBox = control
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1035 retval = checkbox.isChecked
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1036 } else if (control is RadioButton) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1037 var radiobutton: RadioButton = control
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1038 retval = radiobutton.isChecked
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1039 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1040 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1041 return retval
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1042 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1043
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1044 fun textNew(text: String, cid: Int, status: Int): TextView? {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1045 var textview: TextView? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1046
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1047 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1048 var dataArrayMap = SimpleArrayMap<String, Long>()
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
1049
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1050 textview = TextView(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1051 textview!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1052 textview!!.id = cid
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1053 textview!!.text = text
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1054 if (status != 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1055 val border = GradientDrawable()
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1056
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1057 // Set a black border on white background...
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1058 // might need to change this to invisible...
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1059 // or the color from windowSetColor
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1060 border.setColor(-0x1)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1061 border.setStroke(1, -0x1000000)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1062 textview!!.background = border
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1063 }
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1064 }
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1065 return textview
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1066 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1067
2510
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1068 fun mleNew(cid: Int): EditText?
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1069 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1070 var mle: EditText? = null
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1071
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1072 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1073 var dataArrayMap = SimpleArrayMap<String, Long>()
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1074
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1075 mle = EditText(this)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1076 mle!!.tag = dataArrayMap
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1077 mle!!.id = cid
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1078 mle!!.isSingleLine = false
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1079 mle!!.imeOptions = EditorInfo.IME_FLAG_NO_ENTER_ACTION
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1080 mle!!.inputType = (InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1081 mle!!.isVerticalScrollBarEnabled = true
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1082 mle!!.scrollBarStyle = View.SCROLLBARS_INSIDE_INSET
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1083 mle!!.setHorizontallyScrolling(true)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1084 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1085 return mle
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1086 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1087
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1088 fun mleSetWordWrap(mle: EditText, state: Int)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1089 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1090 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1091 if (state != 0) {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1092 mle.setHorizontallyScrolling(false)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1093 } else {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1094 mle.setHorizontallyScrolling(true)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1095 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1096 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1097 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1098
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1099 fun mleSetEditable(mle: EditText, state: Int)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1100 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1101 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1102 if (state != 0) {
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1103 mle.inputType = (InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE)
2510
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1104 } else {
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1105 mle.inputType = InputType.TYPE_NULL
2510
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1106 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1107 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1108 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1109
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1110 fun mleSetCursor(mle: EditText, point: Int)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1111 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1112 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1113 mle.setSelection(point)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1114 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1115 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1116
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1117 fun mleClear(mle: EditText)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1118 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1119 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1120 mle.setText("")
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1121 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1122 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1123
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1124 fun mleImport(mle: EditText, text: String, startpoint: Int): Int
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1125 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1126 var retval: Int = startpoint
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1127
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1128 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1129 val origtext = mle.text
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1130 val origlen = origtext.toString().length
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1131
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1132 if(startpoint < 1) {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1133 val newtext = text + origtext.toString()
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1134
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1135 mle.setText(newtext)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1136 retval = origlen + text.length
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1137 } else if(startpoint >= origlen) {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1138 val newtext = origtext.toString() + text
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1139
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1140 mle.setText(newtext)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1141 retval = origlen + text.length
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1142 } else {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1143 val newtext = origtext.substring(0, startpoint) + text + origtext.substring(startpoint)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1144
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1145 mle.setText(newtext)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1146 retval = startpoint + text.length
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1147 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1148 mle.setSelection(retval)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1149 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1150 return retval
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1151 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1152
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1153 fun mleDelete(mle: EditText, startpoint: Int, length: Int)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1154 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1155 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1156 val origtext = mle.text
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1157 val newtext = origtext.substring(0, startpoint) + origtext.substring(startpoint + length)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1158
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1159 mle.setText(newtext)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1160 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1161 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1162
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1163 fun notebookNew(cid: Int, top: Int): RelativeLayout?
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
1164 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1165 var notebook: RelativeLayout? = null
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
1166
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1167 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1168 val pager = ViewPager2(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1169 val tabs = TabLayout(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1170 var w: Int = RelativeLayout.LayoutParams.MATCH_PARENT
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1171 var h: Int = RelativeLayout.LayoutParams.WRAP_CONTENT
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1172 var dataArrayMap = SimpleArrayMap<String, Long>()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1173
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1174 notebook = RelativeLayout(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1175 notebook!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1176 notebook!!.id = cid
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1177 tabs.id = View.generateViewId()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1178 pager.id = View.generateViewId()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1179 pager.adapter = DWTabViewPagerAdapter()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1180 TabLayoutMediator(tabs, pager) { tab, position ->
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1181 // This code never gets called?
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1182 }.attach()
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
1183
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1184 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1185 if (top != 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1186 params.addRule(RelativeLayout.ALIGN_PARENT_TOP)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1187 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1188 params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1189 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1190 tabs.tabGravity = TabLayout.GRAVITY_FILL
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1191 tabs.tabMode = TabLayout.MODE_FIXED
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1192 notebook!!.addView(tabs, params)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1193 params = RelativeLayout.LayoutParams(w, w)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1194 if (top != 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1195 params.addRule(RelativeLayout.BELOW, tabs.id)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1196 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1197 params.addRule(RelativeLayout.ABOVE, tabs.id)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1198 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1199 notebook!!.addView(pager, params)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1200 tabs.addOnTabSelectedListener(object : OnTabSelectedListener {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1201 override fun onTabSelected(tab: TabLayout.Tab) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1202 val adapter = pager.adapter as DWTabViewPagerAdapter
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1203
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1204 pager.currentItem = tab.position
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1205 eventHandlerNotebook(notebook!!, 15, adapter.pageList[tab.position])
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1206 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1207
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1208 override fun onTabUnselected(tab: TabLayout.Tab) {}
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1209 override fun onTabReselected(tab: TabLayout.Tab) {}
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1210 })
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1211 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1212 return notebook
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1213 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1214
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1215 fun notebookPageNew(notebook: RelativeLayout, flags: Long, front: Int): Long
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1216 {
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1217 var pageID = 0L
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1218
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1219 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1220 var pager: ViewPager2? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1221 var tabs: TabLayout? = null
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1222
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1223 if (notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1224 pager = notebook.getChildAt(0) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1225 tabs = notebook.getChildAt(1) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1226 } else if (notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1227 pager = notebook.getChildAt(1) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1228 tabs = notebook.getChildAt(0) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1229 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1230
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1231 if (pager != null && tabs != null) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1232 var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1233 var tab = tabs.newTab()
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1234
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1235 // Increment our page ID... making sure no duplicates exist
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1236 do {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1237 adapter.currentPageID += 1
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1238 } while (adapter.currentPageID == 0L || adapter.pageList.contains(adapter.currentPageID))
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1239 pageID = adapter.currentPageID
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1240 // Temporarily add a black tab with an empty layout/box
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1241 if (front != 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1242 adapter.viewList.add(0, LinearLayout(this))
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1243 adapter.pageList.add(0, pageID)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1244 tabs.addTab(tab, 0)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1245 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1246 adapter.viewList.add(LinearLayout(this))
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1247 adapter.pageList.add(pageID)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1248 tabs.addTab(tab)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1249 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1250 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1251 }
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1252 return pageID
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1253 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1254
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1255 fun notebookPageDestroy(notebook: RelativeLayout, pageID: Long)
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1256 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1257 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1258 var pager: ViewPager2? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1259 var tabs: TabLayout? = null
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1260
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1261 if (notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1262 pager = notebook.getChildAt(0) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1263 tabs = notebook.getChildAt(1) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1264 } else if (notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1265 pager = notebook.getChildAt(1) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1266 tabs = notebook.getChildAt(0) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1267 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1268
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1269 if (pager != null && tabs != null) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1270 var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1271 val index = adapter.pageList.indexOf(pageID)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1272 val tab = tabs.getTabAt(index)
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1273
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1274 if (tab != null) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1275 adapter.viewList.removeAt(index)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1276 adapter.pageList.removeAt(index)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1277 tabs.removeTab(tab)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1278 }
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1279 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1280 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1281 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1282
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1283 fun notebookPageSetText(notebook: RelativeLayout, pageID: Long, text: String)
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1284 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1285 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1286 var pager: ViewPager2? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1287 var tabs: TabLayout? = null
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1288
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1289 if (notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1290 pager = notebook.getChildAt(0) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1291 tabs = notebook.getChildAt(1) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1292 } else if (notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1293 pager = notebook.getChildAt(1) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1294 tabs = notebook.getChildAt(0) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1295 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1296
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1297 if (pager != null && tabs != null) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1298 val adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1299 val index = adapter.pageList.indexOf(pageID)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1300 val tab = tabs.getTabAt(index)
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1301
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1302 if (tab != null) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1303 tab.text = text
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1304 }
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1305 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1306 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1307 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1308
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1309 fun notebookPagePack(notebook: RelativeLayout, pageID: Long, box: LinearLayout)
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1310 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1311 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1312 var pager: ViewPager2? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1313 var tabs: TabLayout? = null
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1314
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1315 if (notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1316 pager = notebook.getChildAt(0) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1317 tabs = notebook.getChildAt(1) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1318 } else if (notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1319 pager = notebook.getChildAt(1) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1320 tabs = notebook.getChildAt(0) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1321 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1322
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1323 if (pager != null && tabs != null) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1324 var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1325 val index = adapter.pageList.indexOf(pageID)
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1326
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1327 // Make sure the box is MATCH_PARENT
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1328 box.layoutParams = LinearLayout.LayoutParams(
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1329 LinearLayout.LayoutParams.MATCH_PARENT,
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1330 LinearLayout.LayoutParams.MATCH_PARENT
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1331 );
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1332
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1333 adapter.viewList[index] = box
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1334 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1335 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1336 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1337
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1338 fun notebookPageGet(notebook: RelativeLayout): Long
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1339 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1340 var retval: Long = 0L
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1341
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1342 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1343 var pager: ViewPager2? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1344 var tabs: TabLayout? = null
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1345
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1346 if (notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1347 pager = notebook.getChildAt(0) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1348 tabs = notebook.getChildAt(1) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1349 } else if (notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1350 pager = notebook.getChildAt(1) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1351 tabs = notebook.getChildAt(0) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1352 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1353
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1354 if (pager != null && tabs != null) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1355 var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1356 retval = adapter.pageList.get(tabs.selectedTabPosition)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1357 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1358 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1359 return retval
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1360 }
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1361
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1362 fun notebookPageSet(notebook: RelativeLayout, pageID: Long)
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1363 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1364 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1365 var pager: ViewPager2? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1366 var tabs: TabLayout? = null
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1367
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1368 if (notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1369 pager = notebook.getChildAt(0) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1370 tabs = notebook.getChildAt(1) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1371 } else if (notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1372 pager = notebook.getChildAt(1) as ViewPager2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1373 tabs = notebook.getChildAt(0) as TabLayout
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1374 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1375
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1376 if (pager != null && tabs != null) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1377 val adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1378 val index = adapter.pageList.indexOf(pageID)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1379 val tab = tabs.getTabAt(index)
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1380
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1381 tabs.selectTab(tab)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1382 }
2493
bca7e0ab0ccc Android: Work on the notebook control, doesn't work yet but everything filled in.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2492
diff changeset
1383 }
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1384 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1385
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1386 fun sliderNew(vertical: Int, increments: Int, cid: Int): SeekBar?
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1387 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1388 var slider: SeekBar? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1389
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1390 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1391 var dataArrayMap = SimpleArrayMap<String, Long>()
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1392
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1393 slider = SeekBar(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1394 slider!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1395 slider!!.id = cid
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1396 slider!!.max = increments
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1397 if (vertical != 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1398 slider!!.rotation = 270F
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1399 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1400 slider!!.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1401 override fun onStopTrackingTouch(seekBar: SeekBar) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1402 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1403
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1404 override fun onStartTrackingTouch(seekBar: SeekBar) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1405 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1406
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1407 override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
2510
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1408 eventHandlerInt(slider as View, 14, slider!!.progress, 0, 0, 0)
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1409 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1410 })
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1411 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1412 return slider
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1413 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1414
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1415 fun percentNew(cid: Int): ProgressBar?
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1416 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1417 var percent: ProgressBar? = null
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1418
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1419 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1420 var dataArrayMap = SimpleArrayMap<String, Long>()
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1421
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1422 percent = ProgressBar(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1423 percent!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1424 percent!!.id = cid
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1425 percent!!.max = 100
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1426 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1427 return percent
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1428 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1429
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1430 fun percentGetPos(percent: ProgressBar): Int
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1431 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1432 var retval: Int = 0
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1433
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1434 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1435 retval = percent.progress
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1436 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1437 return retval
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1438 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1439
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1440 fun percentSetPos(percent: ProgressBar, position: Int)
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1441 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1442 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1443 percent.progress = position
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1444 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1445 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1446
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1447 fun percentSetRange(percent: ProgressBar, range: Int)
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1448 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1449 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1450 percent.max = range
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1451 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1452 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1453
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1454 fun htmlNew(cid: Int): WebView?
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1455 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1456 var html: WebView? = null
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1457
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1458 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1459 var dataArrayMap = SimpleArrayMap<String, Long>()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1460
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1461 html = WebView(this)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1462 html!!.tag = dataArrayMap
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1463 html!!.id = cid
2505
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
1464 // Configure a few settings to make it behave as we expect
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
1465 html!!.webViewClient = DWWebViewClient()
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
1466 html!!.settings.javaScriptEnabled = true
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1467 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1468 return html
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1469 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1470
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1471 fun htmlLoadURL(html: WebView, url: String)
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1472 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1473 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1474 html.loadUrl(url)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1475 }
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1476 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1477
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1478 fun htmlRaw(html: WebView, data: String)
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1479 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1480 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1481 val encodedHtml: String = Base64.encodeToString(data.toByteArray(), Base64.NO_PADDING)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1482 html.loadData(encodedHtml, "text/html", "base64")
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1483 }
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1484 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1485
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1486 fun htmlJavascriptRun(html: WebView, javascript: String, data: Long)
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1487 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1488 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1489 html.evaluateJavascript(javascript) { value ->
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1490 // Execute onReceiveValue's code
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1491 eventHandlerHTMLResult(html, 18, value, data)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1492 }
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1493 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1494 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1495
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1496 fun htmlAction(html: WebView, action: Int)
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1497 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1498 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1499 when (action) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1500 0 -> html.goBack()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1501 1 -> html.goForward()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1502 2 -> html.loadUrl("http://dwindows.netlabs.org")
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1503 4 -> html.reload()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1504 5 -> html.stopLoading()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1505 }
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1506 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1507 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1508
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1509 fun spinButtonNew(text: String, cid: Int): DWSpinButton?
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1510 {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1511 var spinbutton: DWSpinButton? = null
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1512
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1513 waitOnUiThread {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1514 var dataArrayMap = SimpleArrayMap<String, Long>()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1515 val newval = text.toLongOrNull()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1516
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1517 spinbutton = DWSpinButton(this)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1518 spinbutton!!.tag = dataArrayMap
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1519 spinbutton!!.id = cid
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1520 spinbutton!!.setText(text)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1521 if(newval != null) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1522 spinbutton!!.value = newval
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1523 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1524 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1525 return spinbutton
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1526 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1527
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1528 fun spinButtonSetPos(spinbutton: DWSpinButton, position: Long)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1529 {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1530 waitOnUiThread {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1531 spinbutton.value = position
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1532 spinbutton.setText(position.toString())
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1533 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1534 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1535
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1536 fun spinButtonSetLimits(spinbutton: DWSpinButton, upper: Long, lower: Long)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1537 {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1538 waitOnUiThread {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1539 spinbutton.maximum = upper
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1540 spinbutton.minimum = lower
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1541 if(spinbutton.value > upper) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1542 spinbutton.value = upper
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1543 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1544 if(spinbutton.value < lower) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1545 spinbutton.value = lower
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1546 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1547 spinbutton.setText(spinbutton.value.toString())
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1548 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1549 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1550
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1551 fun spinButtonGetPos(spinbutton: DWSpinButton): Long
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1552 {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1553 var retval: Long = 0
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1554
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1555 waitOnUiThread {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1556 val newvalue = spinbutton.text.toString().toLongOrNull()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1557
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1558 if(newvalue == null) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1559 retval = spinbutton.value
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1560 } else {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1561 retval = newvalue
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1562 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1563 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1564 return retval
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1565 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1566
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1567 fun comboBoxNew(text: String, cid: Int): DWComboBox?
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1568 {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1569 var combobox: DWComboBox? = null
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1570
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1571 waitOnUiThread {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1572 var dataArrayMap = SimpleArrayMap<String, Long>()
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1573
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1574 combobox = DWComboBox(this)
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1575 combobox!!.tag = dataArrayMap
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1576 combobox!!.id = cid
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1577 combobox!!.setText(text)
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1578 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1579 return combobox
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1580 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1581
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1582 fun listBoxNew(cid: Int, multi: Int): DWListBox?
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1583 {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1584 var listbox: DWListBox? = null
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1585
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1586 waitOnUiThread {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1587 var dataArrayMap = SimpleArrayMap<String, Long>()
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1588
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1589 listbox = DWListBox(this)
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1590 listbox!!.tag = dataArrayMap
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1591 listbox!!.id = cid
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1592 if(multi != 0) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1593 listbox!!.choiceMode = ListView.CHOICE_MODE_MULTIPLE;
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1594 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1595 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1596 return listbox
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1597 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1598
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1599 fun listOrComboBoxAppend(window: View, text: String)
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1600 {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1601 waitOnUiThread {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1602 if(window is DWComboBox) {
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1603 val combobox = window
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1604
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1605 combobox.list.add(text)
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1606 } else if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1607 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1608
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1609 listbox.list.add(text)
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1610 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1611 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1612 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1613
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1614 fun listOrComboBoxInsert(window: View, text: String, pos: Int)
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1615 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1616 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1617 if(window is DWComboBox) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1618 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1619
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1620 combobox.list.add(pos, text)
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1621 } else if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1622 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1623
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1624 listbox.list.add(pos, text)
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1625 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1626 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1627 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1628
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1629 fun listOrComboBoxClear(window: View)
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1630 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1631 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1632 if(window is DWComboBox) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1633 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1634
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1635 combobox.list.clear()
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1636 } else if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1637 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1638
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1639 listbox.list.clear()
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1640 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1641 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1642 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1643
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1644 fun listOrComboBoxCount(window: View): Int
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1645 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1646 var retval: Int = 0
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1647
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1648 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1649 if(window is DWComboBox) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1650 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1651
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1652 retval = combobox.list.count()
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1653 } else if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1654 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1655
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1656 retval = listbox.list.count()
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1657 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1658 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1659 return retval
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1660 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1661
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1662 fun listOrComboBoxSetText(window: View, index: Int, text: String)
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1663 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1664 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1665 if(window is DWComboBox) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1666 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1667
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1668 if(index > -1 && index < combobox.list.count())
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1669 combobox.list[index] = text
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1670 } else if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1671 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1672
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1673 if(index > -1 && index < listbox.list.count())
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1674 listbox.list[index] = text
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1675 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1676 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1677 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1678
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1679 fun listOrComboBoxGetText(window: View, index: Int): String?
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1680 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1681 var retval: String? = null
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1682
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1683 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1684 if(window is DWComboBox) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1685 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1686
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1687 if(index > -1 && index < combobox.list.count())
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1688 retval = combobox.list[index]
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1689 } else if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1690 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1691
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1692 if(index > -1 && index < listbox.list.count())
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1693 retval = listbox.list[index]
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1694 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1695 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1696 return retval
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1697 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1698
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1699 fun listOrComboBoxGetSelected(window: View): Int
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1700 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1701 var retval: Int = -1
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1702
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1703 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1704 if(window is DWComboBox) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1705 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1706
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1707 retval = combobox.selected
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1708 } else if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1709 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1710
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1711 retval = listbox.selected
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1712 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1713 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1714 return retval
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1715 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1716
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1717 fun listOrComboBoxSelect(window: View, index: Int, state: Int)
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1718 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1719 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1720 if(window is DWComboBox) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1721 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1722
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1723 if(index < combobox.list.count() && state != 0) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1724 combobox.selected = index
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1725 combobox.setText(combobox.list[index])
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1726 }
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1727 } else if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1728 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1729
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1730 if(index < listbox.list.count()) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1731 if(state != 0) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1732 listbox.selected = index
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1733 listbox.setItemChecked(index, true);
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1734 } else {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1735 listbox.setItemChecked(index, false);
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1736 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1737 }
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1738 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1739 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1740 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1741
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1742 fun listOrComboBoxDelete(window: View, index: Int)
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1743 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1744 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1745 if(window is DWComboBox) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1746 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1747
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1748 if(index < combobox.list.count()) {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1749 combobox.list.removeAt(index)
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1750 }
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1751 } else if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1752 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1753
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1754 if(index < listbox.list.count()) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1755 listbox.list.removeAt(index)
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1756 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1757 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1758 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1759 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1760
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1761 fun listBoxSetTop(window: View, top: Int)
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1762 {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1763 waitOnUiThread {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1764 if(window is DWListBox) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1765 val listbox = window
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1766
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1767 if(top < listbox.list.count()) {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1768 listbox.smoothScrollToPosition(top)
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1769 }
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1770 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1771 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1772 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1773
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1774 fun listBoxSelectedMulti(window: View, where: Int): Int
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1775 {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1776 var retval: Int = -1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1777
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1778 waitOnUiThread {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1779 if(window is DWListBox) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1780 val listbox = window
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1781 val checked: SparseBooleanArray = listbox.getCheckedItemPositions()
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1782
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1783 // If we are starting over....
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1784 if(where == -1 && checked.size() > 0) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1785 retval = checked.keyAt(0)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1786 } else {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1787 // Otherwise loop until we find our current place
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1788 for (i in 0 until checked.size()) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1789 // Item position in adapter
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1790 val position: Int = checked.keyAt(i)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1791 // If we are at our current point... check to see
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1792 // if there is another one, and return it...
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1793 // otherwise we will return -1 to indicated we are done.
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1794 if (where == position && (i+1) < checked.size()) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1795 retval = checked.keyAt(i+1)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1796 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1797 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1798 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1799 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1800 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1801 return retval
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1802 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1803
2523
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1804 fun calendarNew(cid: Int): CalendarView?
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1805 {
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1806 var calendar: CalendarView? = null
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1807
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1808 waitOnUiThread {
2528
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1809 var dataArrayMap = SimpleArrayMap<String, Long>()
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1810
2523
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1811 calendar = CalendarView(this)
2528
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1812 calendar!!.tag = dataArrayMap
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1813 calendar!!.id = cid
2524
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
1814 calendar!!.setOnDateChangeListener { calendar, year, month, day ->
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
1815 val c: Calendar = Calendar.getInstance();
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
1816 c.set(year, month, day);
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
1817 calendar.date = c.timeInMillis
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
1818 }
2523
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1819 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1820
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1821 return calendar
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1822 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1823
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1824 fun calendarSetDate(calendar: CalendarView, date: Long)
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1825 {
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1826 waitOnUiThread {
2524
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
1827 // Convert from seconds to milliseconds
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
1828 calendar.setDate(date * 1000, true, true)
2523
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1829 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1830 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1831
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1832 fun calendarGetDate(calendar: CalendarView): Long
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1833 {
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1834 var date: Long = 0
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1835
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1836 waitOnUiThread {
2524
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
1837 // Convert from milliseconds to seconds
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
1838 date = calendar.date / 1000
2523
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1839 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1840 return date
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1841 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1842
2528
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1843 fun bitmapNew(cid: Int): ImageView?
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1844 {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1845 var imageview: ImageView? = null
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1846
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1847 waitOnUiThread {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1848 var dataArrayMap = SimpleArrayMap<String, Long>()
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1849
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1850 imageview = ImageView(this)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1851 imageview!!.tag = dataArrayMap
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1852 imageview!!.id = cid
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1853 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1854
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1855 return imageview
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1856 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1857
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1858 fun windowSetBitmap(window: View, resID: Int, filename: String?)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1859 {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1860 waitOnUiThread {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1861 if(resID != 0) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1862 if(window is ImageButton) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1863 val button = window
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1864
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1865 button.setImageResource(resID)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1866 } else if(window is ImageView) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1867 val imageview = window
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1868
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1869 imageview.setImageResource(resID)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1870 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1871 } else if(filename != null) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1872 // Try to load the image, and protect against exceptions
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1873 try {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1874 val f = File(filename)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1875 val b = BitmapFactory.decodeStream(FileInputStream(f))
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1876 if(window is ImageButton) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1877 val button = window
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1878
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1879 button.setImageBitmap(b)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1880 } else if(window is ImageView) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1881 val imageview = window
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1882
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1883 imageview.setImageBitmap(b)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1884 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1885 } catch (e: FileNotFoundException) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1886 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1887 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1888 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1889 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1890
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1891 fun windowSetBitmapFromData(window: View, resID: Int, data: ByteArray?, length: Int)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1892 {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1893 waitOnUiThread {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1894 if(resID != 0) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1895 if (window is ImageButton) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1896 val button = window
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1897
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1898 button.setImageResource(resID)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1899 } else if (window is ImageView) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1900 val imageview = window
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1901
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1902 imageview.setImageResource(resID)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1903 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1904 } else if(data != null) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1905 val b = BitmapFactory.decodeByteArray(data, 0, length)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1906
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1907 if (window is ImageButton) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1908 val button = window
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1909
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1910 button.setImageBitmap(b)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1911 } else if (window is ImageView) {
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1912 val imageview = window
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1913
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1914 imageview.setImageBitmap(b)
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1915 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1916 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1917 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1918 }
03f6870bcfcc Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2527
diff changeset
1919
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1920 fun iconNew(filename: String?, data: ByteArray?, length: Int, resID: Int): Drawable?
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1921 {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1922 var icon: Drawable? = null
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1923
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1924 waitOnUiThread {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1925 if(resID != 0) {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1926 icon = ResourcesCompat.getDrawable(resources, resID, null);
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1927 } else if(filename != null) {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1928 // Try to load the image, and protect against exceptions
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1929 try {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1930 icon = Drawable.createFromPath(filename)
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1931 } catch (e: FileNotFoundException) {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1932 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1933 } else if(data != null) {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1934 icon = BitmapDrawable(resources, BitmapFactory.decodeByteArray(data, 0, length))
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1935 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1936 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1937 return icon
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1938 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1939
2529
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1940 fun pixmapNew(width: Int, height: Int, filename: String?, data: ByteArray?, length: Int, resID: Int): Bitmap?
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1941 {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1942 var pixmap: Bitmap? = null
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1943
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1944 waitOnUiThread {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1945 if(width > 0 && height > 0) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1946 pixmap = Bitmap.createBitmap(null, width, height, Bitmap.Config.ARGB_8888)
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1947 } else if(resID != 0) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1948 pixmap = BitmapFactory.decodeResource(resources, resID);
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1949 } else if(filename != null) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1950 // Try to load the image, and protect against exceptions
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1951 try {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1952 val f = File(filename)
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1953 pixmap = BitmapFactory.decodeStream(FileInputStream(f))
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1954 } catch (e: FileNotFoundException) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1955 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1956 } else if(data != null) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1957 pixmap = BitmapFactory.decodeByteArray(data, 0, length)
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1958 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1959 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1960 return pixmap
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1961 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1962
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1963 fun pixmapGetDimensions(pixmap: Bitmap): Long
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1964 {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1965 var dimensions: Long = 0
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1966
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1967 waitOnUiThread {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1968 dimensions = pixmap.width.toLong() or (pixmap.height.toLong() shl 32)
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1969 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1970 return dimensions
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1971 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
1972
2542
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
1973 fun screenGetDimensions(): Long
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
1974 {
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
1975 val dm = resources.displayMetrics
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
1976 return dm.widthPixels.toLong() or (dm.heightPixels.toLong() shl 32)
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
1977 }
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
1978
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1979 fun renderNew(cid: Int): DWRender?
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1980 {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1981 var render: DWRender? = null
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1982
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1983 waitOnUiThread {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1984 var dataArrayMap = SimpleArrayMap<String, Long>()
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1985
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1986 render = DWRender(this)
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1987 render!!.tag = dataArrayMap
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1988 render!!.id = cid
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1989 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1990 return render
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1991 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1992
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1993 fun renderRedraw(render: DWRender)
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1994 {
2539
822f814a54f4 Android: Fix memory corruption issue due to incorrectly allocating HPIXMAP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2538
diff changeset
1995 runOnUiThread {
822f814a54f4 Android: Fix memory corruption issue due to incorrectly allocating HPIXMAP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2538
diff changeset
1996 render.invalidate()
822f814a54f4 Android: Fix memory corruption issue due to incorrectly allocating HPIXMAP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2538
diff changeset
1997 }
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1998 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
1999
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2000 fun pixmapBitBlt(dstr: DWRender?, dstp: Bitmap?, dstx: Int, dsty: Int, dstw: Int, dsth: Int,
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2001 srcr: DWRender?, srcp: Bitmap?, srcy: Int, srcx: Int, srcw: Int, srch: Int): Int
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2002 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2003 val dst = Rect(dstx, dsty, dstx + dstw, dsty + dsth)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2004 var src = Rect(srcx, srcy, srcx + srcw, srcy + srch)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2005 var retval: Int = 1
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2006
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2007 if(srcw == -1) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2008 src.right = srcx + dstw
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2009 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2010 if(srch == -1) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2011 src.bottom = srcy + dsth
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2012 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2013
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2014 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2015 var canvas: Canvas? = null
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2016 var bitmap: Bitmap? = null
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2017
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2018 if(dstr != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2019 canvas = dstr.cachedCanvas
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2020 } else if(dstp != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2021 canvas = Canvas(dstp)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2022 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2023
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2024 if(srcp != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2025 bitmap = srcp
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2026 } else if(srcr != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2027 bitmap = Bitmap.createBitmap(srcr.layoutParams.width,
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2028 srcr.layoutParams.height, Bitmap.Config.ARGB_8888)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2029 val c = Canvas(bitmap)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2030 srcr.layout(srcr.left, srcr.top, srcr.right, srcr.bottom)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2031 srcr.draw(c)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2032 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2033
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2034 if(canvas != null && bitmap != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2035 canvas.drawBitmap(bitmap, src, dst, null)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2036 retval = 0
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2037 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2038 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2039 return retval
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2040 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2041
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2042 fun drawPoint(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2043 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2044 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2045 var canvas: Canvas? = null
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2046
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2047 if(render != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2048 canvas = render.cachedCanvas
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2049 } else if(bitmap != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2050 canvas = Canvas(bitmap)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2051 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2052
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2053 if(canvas != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2054 canvas.drawPoint(x.toFloat(), y.toFloat(), Paint())
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2055 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2056 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2057 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2058
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2059 fun drawLine(render: DWRender?, bitmap: Bitmap?, x1: Int, y1: Int, x2: Int, y2: Int)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2060 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2061 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2062 var canvas: Canvas? = null
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2063
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2064 if(render != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2065 canvas = render.cachedCanvas
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2066 } else if(bitmap != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2067 canvas = Canvas(bitmap)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2068 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2069
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2070 if(canvas != null) {
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2071 paint.flags = 0
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2072 paint.style = Paint.Style.STROKE
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2073 canvas.drawLine(x1.toFloat(), y1.toFloat(), x2.toFloat(), y2.toFloat(), paint)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2074 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2075 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2076 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2077
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2078 fun drawText(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, text:String)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2079 {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2080 waitOnUiThread {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2081 var canvas: Canvas? = null
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2082
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2083 if(render != null) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2084 canvas = render.cachedCanvas
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2085 } else if(bitmap != null) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2086 canvas = Canvas(bitmap)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2087 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2088
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2089 if(canvas != null) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2090 // Save the old color for later...
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2091 var rect = Rect()
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2092 val oldcolor = paint.color
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2093 // Prepare to draw the background rect
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2094 paint.color = bgcolor
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2095 paint.flags = 0
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2096 paint.style = Paint.Style.FILL_AND_STROKE
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2097 paint.textAlign = Paint.Align.LEFT
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2098 paint.getTextBounds(text, 0, text.length, rect)
2538
1b3b40c89cd0 Android: Move the text to below the point, not above it.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2537
diff changeset
2099 val textheight = rect.bottom - rect.top
1b3b40c89cd0 Android: Move the text to below the point, not above it.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2537
diff changeset
2100 rect.top += y + textheight
1b3b40c89cd0 Android: Move the text to below the point, not above it.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2537
diff changeset
2101 rect.bottom += y + textheight
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2102 rect.left += x
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2103 rect.right += x
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2104 canvas.drawRect(rect, paint)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2105 // Restore the color and prepare to draw text
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2106 paint.color = oldcolor
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2107 paint.style = Paint.Style.STROKE
2538
1b3b40c89cd0 Android: Move the text to below the point, not above it.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2537
diff changeset
2108 canvas.drawText(text, x.toFloat(), y.toFloat() + textheight.toFloat(), paint)
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2109 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2110 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2111 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2112
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2113 fun drawRect(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, width: Int, height: Int)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2114 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2115 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2116 var canvas: Canvas? = null
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2117
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2118 if(render != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2119 canvas = render.cachedCanvas
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2120 } else if(bitmap != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2121 canvas = Canvas(bitmap)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2122 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2123
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2124 if(canvas != null) {
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2125 paint.flags = 0
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2126 paint.style = Paint.Style.FILL_AND_STROKE
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2127 canvas.drawRect(x.toFloat(), y.toFloat(), x.toFloat() + width.toFloat(), y.toFloat() + height.toFloat(), paint)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2128 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2129 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2130 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2131
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2132 fun drawPolygon(render: DWRender?, bitmap: Bitmap?, flags: Int, npoints: Int, x: IntArray, y: IntArray)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2133 {
2537
cd9d2ba251d5 Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2536
diff changeset
2134 // Create a path with all our points
cd9d2ba251d5 Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2536
diff changeset
2135 val path = Path()
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2136
2537
cd9d2ba251d5 Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2536
diff changeset
2137 path.moveTo(x[0].toFloat(), y[0].toFloat())
cd9d2ba251d5 Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2536
diff changeset
2138 for (i in 1 until npoints) {
cd9d2ba251d5 Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2536
diff changeset
2139 path.lineTo(x[i].toFloat(), y[i].toFloat())
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2140 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2141
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2142 waitOnUiThread {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2143 var canvas: Canvas? = null
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2144
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2145 if(render != null) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2146 canvas = render.cachedCanvas
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2147 } else if(bitmap != null) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2148 canvas = Canvas(bitmap)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2149 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2150
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2151 if(canvas != null) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2152 // Handle the DW_DRAW_NOAA flag
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2153 if((flags and (1 shl 2)) == 0) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2154 paint.flags = Paint.ANTI_ALIAS_FLAG
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2155 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2156 paint.flags = 0
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2157 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2158 // Handle the DW_DRAW_FILL flag
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2159 if((flags and 1) == 1) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2160 paint.style = Paint.Style.FILL_AND_STROKE
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2161 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2162 paint.style = Paint.Style.STROKE
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2163 }
2537
cd9d2ba251d5 Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2536
diff changeset
2164 canvas.drawPath(path, paint)
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2165 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2166 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2167 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2168
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2169 fun drawArc(render: DWRender?, bitmap: Bitmap?, flags: Int, xorigin: Int, yorigin: Int,
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2170 x1: Int, y1: Int, x2: Int, y2: Int)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2171 {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2172 waitOnUiThread {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2173 var canvas: Canvas? = null
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2174
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2175 if(render != null) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2176 canvas = render.cachedCanvas
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2177 } else if(bitmap != null) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2178 canvas = Canvas(bitmap)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2179 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2180
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2181 if(canvas != null) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2182 var a1: Double = Math.atan2((y1 - yorigin).toDouble(), (x1 - xorigin).toDouble())
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2183 var a2: Double = Math.atan2((y2 - yorigin).toDouble(), (x2 - xorigin).toDouble())
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2184 val dx = (xorigin - x1).toDouble()
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2185 val dy = (yorigin - y1).toDouble()
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2186 val r: Double = Math.sqrt(dx * dx + dy * dy)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2187 val left = (xorigin-r).toFloat()
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2188 val top = (yorigin-r).toFloat()
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2189 val rect = RectF(left, top, (left + (r*2)).toFloat(), (top + (r*2)).toFloat())
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2190
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2191 /* Convert to degrees */
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2192 a1 *= 180.0 / Math.PI
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2193 a2 *= 180.0 / Math.PI
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2194 val sweep = Math.abs(a1 - a2)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2195
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2196 // Handle the DW_DRAW_NOAA flag
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2197 if((flags and (1 shl 2)) == 0) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2198 paint.flags = Paint.ANTI_ALIAS_FLAG
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2199 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2200 paint.flags = 0
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2201 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2202 // Handle the DW_DRAW_FILL flag
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2203 if((flags and 1) == 1) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2204 paint.style = Paint.Style.FILL_AND_STROKE
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2205 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2206 paint.style = Paint.Style.STROKE
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2207 }
2536
d172ab2eddb6 Android: Implement DW_DRAW_FULL flag for dw_draw_arc().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2535
diff changeset
2208 // Handle the DW_DRAW_FULL flag
d172ab2eddb6 Android: Implement DW_DRAW_FULL flag for dw_draw_arc().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2535
diff changeset
2209 if((flags and (1 shl 1)) != 0) {
d172ab2eddb6 Android: Implement DW_DRAW_FULL flag for dw_draw_arc().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2535
diff changeset
2210 canvas.drawOval(rect, paint)
d172ab2eddb6 Android: Implement DW_DRAW_FULL flag for dw_draw_arc().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2535
diff changeset
2211 } else {
d172ab2eddb6 Android: Implement DW_DRAW_FULL flag for dw_draw_arc().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2535
diff changeset
2212 canvas.drawArc(rect, a1.toFloat(), sweep.toFloat(), false, paint)
d172ab2eddb6 Android: Implement DW_DRAW_FULL flag for dw_draw_arc().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2535
diff changeset
2213 }
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2214 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2215 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2216 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2217
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2218 fun colorSet(alpha: Int, red: Int, green: Int, blue: Int)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2219 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2220 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2221 if(alpha != 0) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2222 paint.color = Color.argb(alpha, red, green, blue)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2223 } else {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2224 paint.color = Color.rgb(red, green, blue)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2225 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2226 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2227 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2228
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2229 fun bgColorSet(alpha: Int, red: Int, green: Int, blue: Int)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2230 {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2231 if(alpha != 0) {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2232 this.bgcolor = Color.argb(alpha, red, green, blue)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2233 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2234 this.bgcolor = Color.rgb(red, green, blue)
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2235 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2236 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2237
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2238 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2239 {
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2240 // creating timer task, timer
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2241 val t = Timer()
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2242 val tt: TimerTask = object : TimerTask() {
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2243 override fun run() {
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2244 if(eventHandlerTimer(sigfunc, data) == 0) {
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2245 t.cancel()
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2246 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2247 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2248 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2249 t.scheduleAtFixedRate(tt, interval, interval)
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2250 return t
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2251 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2252
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2253 fun timerDisconnect(timer: Timer)
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2254 {
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2255 timer.cancel()
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2256 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2257
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2258 fun doBeep(duration: Int)
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2259 {
2491
bf4fe6bb512b Android: Fix the permission error on the beep...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2490
diff changeset
2260 val toneGen = ToneGenerator(AudioManager.STREAM_ALARM, 100)
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2261 toneGen.startTone(ToneGenerator.TONE_CDMA_PIP, duration)
2491
bf4fe6bb512b Android: Fix the permission error on the beep...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2490
diff changeset
2262 val handler = Handler(Looper.getMainLooper())
bf4fe6bb512b Android: Fix the permission error on the beep...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2490
diff changeset
2263 handler.postDelayed({
bf4fe6bb512b Android: Fix the permission error on the beep...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2490
diff changeset
2264 toneGen.release()
bf4fe6bb512b Android: Fix the permission error on the beep...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2490
diff changeset
2265 }, (duration + 50).toLong())
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
2266 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
2267
2482
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2268 fun debugMessage(text: String)
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2269 {
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2270 Log.d(null, text)
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2271 }
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2272
2526
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2273 fun fileBrowse(title: String, defpath: String?, ext: String?, flags: Int): String?
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2274 {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2275 var retval: String? = null
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2276
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2277 waitOnUiThread {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2278 val fc = DWFileChooser(this)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2279 fc.setFileListener(object: DWFileChooser.FileSelectedListener {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2280 override fun fileSelected(file: File?) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2281 // do something with the file
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2282 retval = file!!.absolutePath
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2283 throw java.lang.RuntimeException()
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2284 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2285 })
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2286 if(ext != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2287 fc.setExtension(ext)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2288 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2289 fc.showDialog()
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2290 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2291
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2292 // loop till a runtime exception is triggered.
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2293 try {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2294 Looper.loop()
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2295 } catch (e2: RuntimeException) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2296 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2297
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2298 return retval
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2299 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2300
2486
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2301 fun messageBox(title: String, body: String, flags: Int): Int
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2302 {
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2303 var retval: Int = 0
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2304
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2305 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2306 // make a text input dialog and show it
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2307 var alert = AlertDialog.Builder(this)
2486
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2308
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2309 alert.setTitle(title)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2310 alert.setMessage(body)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2311 if ((flags and (1 shl 3)) != 0) {
2516
8f5d064b7054 Android: Fix the down arrow on the comboboxes, found a system resource that works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2515
diff changeset
2312 alert.setPositiveButton("Yes",
8f5d064b7054 Android: Fix the down arrow on the comboboxes, found a system resource that works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2515
diff changeset
2313 //android.R.string.yes,
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2314 DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2315 retval = 1
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2316 throw java.lang.RuntimeException()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2317 });
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2318 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2319 if ((flags and ((1 shl 1) or (1 shl 2))) != 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2320 alert.setNegativeButton(
2516
8f5d064b7054 Android: Fix the down arrow on the comboboxes, found a system resource that works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2515
diff changeset
2321 android.R.string.ok,
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2322 DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2323 retval = 0
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2324 throw java.lang.RuntimeException()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2325 });
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2326 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2327 if ((flags and ((1 shl 3) or (1 shl 4))) != 0) {
2516
8f5d064b7054 Android: Fix the down arrow on the comboboxes, found a system resource that works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2515
diff changeset
2328 alert.setNegativeButton("No",
8f5d064b7054 Android: Fix the down arrow on the comboboxes, found a system resource that works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2515
diff changeset
2329 //android.R.string.no,
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2330 DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2331 retval = 0
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2332 throw java.lang.RuntimeException()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2333 });
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2334 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2335 if ((flags and ((1 shl 2) or (1 shl 4))) != 0) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2336 alert.setNeutralButton(
2516
8f5d064b7054 Android: Fix the down arrow on the comboboxes, found a system resource that works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2515
diff changeset
2337 android.R.string.cancel,
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2338 DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2339 retval = 2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2340 throw java.lang.RuntimeException()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2341 });
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2342 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2343 alert.show();
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2344
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2345 // loop till a runtime exception is triggered.
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2346 try {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2347 Looper.loop()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2348 } catch (e2: RuntimeException) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2349 }
2486
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2350 }
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2351 return retval
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2352 }
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2353
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2354 fun isUIThread(): Boolean
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2355 {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2356 if(Looper.getMainLooper() == Looper.myLooper()) {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2357 return true
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2358 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2359 return false
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2360 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2361
2514
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2362 fun mainSleep(milliseconds: Int)
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2363 {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2364 // If we are on the main UI thread... add an idle handler
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2365 // Then loop until we throw an exception when the time expires
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2366 // in the idle handler, if we are already thrown... remove the handler
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2367 if(Looper.getMainLooper() == Looper.myLooper()) {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2368 val starttime = System.currentTimeMillis()
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2369
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2370 // Waiting for Idle to make sure Toast gets rendered.
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2371 Looper.myQueue().addIdleHandler(object : MessageQueue.IdleHandler {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2372 var thrown: Boolean = false
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2373
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2374 override fun queueIdle(): Boolean {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2375 if(System.currentTimeMillis() - starttime >= milliseconds) {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2376 if (thrown == false) {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2377 thrown = true
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2378 throw java.lang.RuntimeException()
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2379 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2380 return false
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2381 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2382 return true
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2383 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2384 })
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2385
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2386 // loop till a runtime exception is triggered.
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2387 try {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2388 Looper.loop()
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2389 } catch (e2: RuntimeException) {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2390 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2391 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2392 else
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2393 {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2394 // If we are in a different thread just sleep
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2395 Thread.sleep(milliseconds.toLong())
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2396 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2397 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2398
2487
83f8f4f58a98 Android: Implement dw_exit() using Activity.finishActivity() instead of exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2486
diff changeset
2399 fun dwindowsExit(exitcode: Int)
83f8f4f58a98 Android: Implement dw_exit() using Activity.finishActivity() instead of exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2486
diff changeset
2400 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2401 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2402 this.finishAffinity()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2403 System.exit(exitcode)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2404 }
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
2405 }
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
2406
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
2407 fun dwindowsShutdown()
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
2408 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2409 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2410 this.finishAffinity()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2411 }
2487
83f8f4f58a98 Android: Implement dw_exit() using Activity.finishActivity() instead of exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2486
diff changeset
2412 }
83f8f4f58a98 Android: Implement dw_exit() using Activity.finishActivity() instead of exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2486
diff changeset
2413
2542
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2414 fun dwInit(appid: String, appname: String): Int
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2415 {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2416 waitOnUiThread {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2417 // Create the notification channel in dw_init()
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2418 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2419 // Create the NotificationChannel
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2420 val importance = NotificationManager.IMPORTANCE_DEFAULT
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2421 val mChannel = NotificationChannel(appid, appname, importance)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2422 // Register the channel with the system; you can't change the importance
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2423 // or other notification behaviors after this
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2424 val notificationManager =
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2425 getSystemService(NOTIFICATION_SERVICE) as NotificationManager
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2426 notificationManager.createNotificationChannel(mChannel)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2427 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2428 }
2542
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2429 return Build.VERSION.SDK_INT
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2430 }
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2431
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2432 fun dwMain()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2433 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2434 runOnUiThread {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2435 // Trigger the options menu to update when dw_main() is called
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2436 invalidateOptionsMenu()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2437 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2438 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2439
2542
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2440 fun androidGetRelease(): String
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2441 {
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2442 return Build.VERSION.RELEASE
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2443 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2444
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2445 fun notificationNew(title: String, imagepath: String, text: String, appid: String): NotificationCompat.Builder?
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2446 {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2447 var builder: NotificationCompat.Builder? = null
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2448
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2449 waitOnUiThread {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2450 builder = NotificationCompat.Builder(this, appid)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2451 .setContentTitle(title)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2452 .setContentText(text)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2453 .setPriority(NotificationCompat.PRIORITY_DEFAULT)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2454 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2455 return builder
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2456 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2457
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2458 fun notificationSend(builder: NotificationCompat.Builder)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2459 {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2460 waitOnUiThread {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2461 notificationID += 1
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2462 with(NotificationManagerCompat.from(this)) {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2463 // notificationId is a unique int for each notification that you must define
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2464 notify(notificationID, builder.build())
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2465 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2466 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2467 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2468
2475
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
2469 /*
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
2470 * Native methods that are implemented by the 'dwindows' native library,
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2471 * which is packaged with this application.
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2472 */
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2473 external fun dwindowsInit(dataDir: String, appid: String)
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
2474 external fun eventHandler(
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2475 obj1: View?,
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
2476 obj2: View?,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
2477 message: Int,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
2478 str1: String?,
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
2479 str2: String?,
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2480 inta: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2481 intb: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2482 intc: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2483 intd: Int
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
2484 ): Int
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2485 external fun eventHandlerInt(
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2486 obj1: View,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2487 message: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2488 inta: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2489 intb: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2490 intc: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2491 intd: Int
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2492 )
2483
9f7af6d8c6a4 Android: Fix signal handlers so they actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2482
diff changeset
2493 external fun eventHandlerSimple(obj1: View, message: Int)
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
2494 external fun eventHandlerNotebook(obj1: View, message: Int, pageID: Long)
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2495 external fun eventHandlerTimer(sigfunc: Long, data: Long): Int
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
2496 external fun eventHandlerHTMLResult(obj1: View, message: Int, result: String, data: Long)
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2497
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
2498 companion object
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
2499 {
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2500 // Used to load the 'dwindows' library on application startup.
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
2501 init
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
2502 {
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2503 System.loadLibrary("dwindows")
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2504 }
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2505 }
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2506 }