annotate android/DWindows.kt @ 2554:4c75fb6089a9

Android: Need to set isSingleLine for entryfields. Autosize the Start Threads button, since buttons are one of the controls with forced size issues on Android.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 15 May 2021 21:16:06 +0000
parents 2b4f2929408e
children d7d163d70763
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
2551
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
28 import android.util.TypedValue
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36 import android.widget.SeekBar.OnSeekBarChangeListener
2551
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
37 import androidx.annotation.RequiresApi
2486
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
38 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
39 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
40 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
41 import androidx.collection.SimpleArrayMap
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
42 import androidx.core.app.NotificationCompat
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 import java.io.File
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
52 import java.io.FileInputStream
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
53 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
54 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
55 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
56
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
57
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
58 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
59 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
60 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
61 var currentPageID = 0L
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
62
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
63 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
64 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
65
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
66 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
67 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
68 return position
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
69 }
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
70 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
71 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
72 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
73
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
74 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
75 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
76
2505
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
77 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
78 //Implement shouldOverrideUrlLoading//
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
79 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
80 // 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
81 // 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
82 return false
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
83 }
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
84 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
85 // 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
86 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
87 }
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
88
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
89 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
90 // 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
91 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
92 }
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 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
95 }
a149dabf6a1f Android: HTML touchups, implement DW_SIGNAL_HTML_CHANGED: STARTED and COMPLETE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2503
diff changeset
96
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
97 class DWSpinButton(context: Context) : AppCompatEditText(context), OnTouchListener {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
98 var value: Long = 0
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
99 var minimum: Long = 0
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
100 var maximum: Long = 65535
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
101
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
102 init {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
103 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
104 setOnTouchListener(this)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
105 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
106
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
107 override fun onTouch(v: View, event: MotionEvent): Boolean {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
108 val DRAWABLE_RIGHT = 2
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
109 val DRAWABLE_LEFT = 0
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
110
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
111 if (event.action == MotionEvent.ACTION_UP) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
112 if (event.x >= v.width - (v as EditText)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
113 .compoundDrawables[DRAWABLE_RIGHT].bounds.width()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
114 ) {
2527
eec926265888 Android: Use toLongOrNull() whenever converting from string to long...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2526
diff changeset
115 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
116
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
117 if(newvalue != null) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
118 value = newvalue + 1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
119 } else {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
120 value += 1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
121 }
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
122 if(value > maximum) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
123 value = maximum
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
124 }
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
125 if(value < minimum) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
126 value = minimum
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
127 }
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
128 setText(value.toString())
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
129 eventHandlerInt(14, value.toInt(), 0, 0, 0)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
130 return true
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
131 } else if (event.x <= (v as EditText)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
132 .compoundDrawables[DRAWABLE_LEFT].bounds.width()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
133 ) {
2527
eec926265888 Android: Use toLongOrNull() whenever converting from string to long...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2526
diff changeset
134 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
135
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
136 if(newvalue != null) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
137 value = newvalue - 1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
138 } else {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
139 value -= 1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
140 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
141 if(value > maximum) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
142 value = maximum
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
143 }
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
144 if(value < minimum) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
145 value = minimum
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
146 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
147 setText(value.toString())
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
148 eventHandlerInt(14, value.toInt(), 0, 0, 0)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
149 return true
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
150 }
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 return false
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
153 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
154
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
155 external fun eventHandlerInt(
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
156 message: Int,
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
157 inta: Int,
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
158 intb: Int,
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
159 intc: Int,
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
160 intd: Int
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
161 )
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
162 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
163
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
164 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
165 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
166 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
167 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
168
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
169 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
170 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
171 setOnTouchListener(this)
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
172 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
173 lpw!!.setAdapter(
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
174 ArrayAdapter(
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
175 context,
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
176 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
177 )
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
178 )
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
179 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
180 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
181 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
182 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
183
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
184 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
185 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
186 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
187 setText(item)
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
188 lpw!!.dismiss()
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
189 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
190 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
191
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
192 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
193 val DRAWABLE_RIGHT = 2
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
194
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
195 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
196 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
197 .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
198 ) {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
199 lpw!!.show()
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
200 return true
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
201 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
202 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
203 return false
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
204 }
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
205
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
206 external fun eventHandlerInt(
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
207 message: Int,
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
208 inta: Int,
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
209 intb: Int,
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
210 intc: Int,
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
211 intd: Int
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
212 )
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
213 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
214
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
215 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
216 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
217 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
218
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
219 init {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
220 setAdapter(
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
221 ArrayAdapter(
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
222 context,
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
223 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
224 )
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 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
227 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
228
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
229 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
230 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
231 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
232 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
233
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
234 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
235 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
236 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
237 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
238 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
239 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
240 )
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
241 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
242
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
243 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
244 var cachedCanvas: Canvas? = null
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
245 var typeface: Typeface? = null
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
246 var fontsize: Float? = null
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
247
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
248 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
249 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
250 // 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
251 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
252 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
253
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
254 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
255 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
256 cachedCanvas = canvas
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
257 // 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
258 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
259 cachedCanvas = null
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
260 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
261
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
262 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
263 message: Int,
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
264 inta: Int,
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
265 intb: Int,
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
266 intc: Int,
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
267 intd: Int
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
268 )
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
269 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
270
2526
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
271 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
272 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
273 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
274 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
275
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
276 // 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
277 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
278 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
279 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
280 }
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 // 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
283 interface FileSelectedListener {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
284 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
285 }
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 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
288 this.fileListener = fileListener
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
289 return this
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
290 }
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 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
293 fun showDialog() {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
294 dialog.show()
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
2527
eec926265888 Android: Use toLongOrNull() whenever converting from string to long...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2526
diff changeset
297 /*
2526
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
298 * 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
299 */
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
300 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
301 currentPath = path
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
302 if (path != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
303 if (path.exists()) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
304 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
305 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
306 if (!file.isDirectory) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
307 if (!file.canRead()) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
308 false
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
309 } 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
310 true
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
311 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
312 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
313 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
314 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
315 false
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
316 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
317 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
318
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
319 // 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
320 var i = 0
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
321 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
322 var filecount = 0
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
323 var dircount = 0
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
324 if(files != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
325 filecount = files.size
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
326 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
327 if(dirs != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
328 dircount = dirs.size
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
329 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
330 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
331 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
332 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
333 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
334 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
335 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
336 if(dirs != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
337 Arrays.sort(dirs)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
338 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
339 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
340 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
341 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
342 if(files != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
343 Arrays.sort(files)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
344 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
345 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
346 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
347 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
348
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
349 // 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
350 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
351 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
352 activity,
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
353 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
354 ) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
355 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
356 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
357 (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
358 return thisview
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 }
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
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
365 /**
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
366 * 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
367 */
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
368 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
369 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
370 currentPath!!.parentFile
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
371 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
372 File(currentPath, fileChosen)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
373 }
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 companion object {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
377 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
378 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
379
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
380 init {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
381 list.onItemClickListener =
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
382 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
383 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
384 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
385 if (chosenFile != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
386 if (chosenFile.isDirectory) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
387 refresh(chosenFile)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
388 } else {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
389 if (fileListener != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
390 fileListener!!.fileSelected(chosenFile)
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.dismiss()
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
393 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
394 }
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 dialog.setContentView(list)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
397 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
398 refresh(Environment.getExternalStorageDirectory())
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
399 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
400 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
401
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
402 // 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
403 // 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
404 // 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
405 class DWMenuItem
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
406 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
407 var title: String? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
408 var menu: DWMenu? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
409 var submenu: DWMenu? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
410 var checked: Boolean = false
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
411 var check: Boolean = false
2546
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
412 var enabled: Boolean = true
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
413 var menuitem: MenuItem? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
414 var submenuitem: SubMenu? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
415 var id: Int = 0
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
416 }
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 class DWMenu {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
419 var menu: Menu? = null
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
420 var children = mutableListOf<DWMenuItem>()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
421 var id: Int = 0
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
422
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
423 fun createMenu(newmenu: Menu?) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
424 if(menu == null) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
425 menu = newmenu
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
426 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
427 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
428 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
429
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
430 // 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
431 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
432
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
433 for (menuitem in children) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
434 // 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
435 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
436 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
437 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
438 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
439 menuitem.submenu!!.createMenu(menuitem.submenuitem)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
440 } 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
441 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
442 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
443 } 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
444 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
445 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
446 menuitem.menuitem!!.isChecked = menuitem.checked
2546
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
447 menuitem.menuitem!!.isEnabled = menuitem.enabled
2544
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
448 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
449 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
450 true
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
451 })
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
452 }
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 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
455 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
456 }
2544
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
457
dbfcc0e357d6 Android: Clean up the menus... add separator, remove tildes and implement callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2543
diff changeset
458 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
459 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
460
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
461 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
462 var firstWindow: Boolean = true
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
463 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
464 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
465 var threadCond = threadLock.newCondition()
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
466 var notificationID: Int = 0
2551
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
467 var darkMode: Int = -1
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
468 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
469 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
470 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
471
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
472 // 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
473 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
474 {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
475 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
476 runnable.run()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
477 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
478 threadLock.lock()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
479 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
480 threadLock.lock()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
481 runnable.run()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
482 threadCond.signal()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
483 threadLock.unlock()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
484 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
485 runOnUiThread(ourRunnable)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
486 threadCond.await()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
487 threadLock.unlock()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
488 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
489 }
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
490
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
491 // 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
492 // 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
493 // 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
494 // 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
495 // 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
496 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
497 super.onCreate(savedInstanceState)
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
498
2480
878d36588aaa Android: Enable app rotation and fix some issues with layout.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2479
diff changeset
499 // Turn on rotation
878d36588aaa Android: Enable app rotation and fix some issues with layout.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2479
diff changeset
500 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
501
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
502 // 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
503 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
504 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
505 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
506 s = p.applicationInfo.dataDir
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
507
2498
4ae2b3b77f25 Android: Get the notebook control functional. Disable recylcing of the views.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2497
diff changeset
508 // 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
509 // 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
510 dwindowsInit(s, this.getPackageName())
2496
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
511 }
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
512
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
513 override fun onConfigurationChanged(newConfig: Configuration) {
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
514 super.onConfigurationChanged(newConfig)
3bf2f08fdc45 Android: Remove ugly workaround for initialization issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2495
diff changeset
515
2551
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
516 val currentNightMode = newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
517 when (currentNightMode) {
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
518 Configuration.UI_MODE_NIGHT_NO -> { darkMode = 0 } // Night mode is not active, we're using the light theme
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
519 Configuration.UI_MODE_NIGHT_YES -> { darkMode = 1 } // Night mode is active, we're using dark theme
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
520 }
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
521
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
522 // 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
523 if(windowLayout != null) {
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
524 var width: Int = windowLayout!!.width
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
525 var height: Int = windowLayout!!.height
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
526
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
527 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
528 }
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
529 }
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
530
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
531 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
532 if(menuBar == null) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
533 menuBar = DWMenu()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
534 menuBar!!.menu = menu
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 return super.onCreateOptionsMenu(menu)
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
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
539 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
540 if(menuBar != null) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
541 menuBar!!.createMenu(menu)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
542 } else {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
543 menuBar = DWMenu()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
544 menuBar!!.createMenu(menu)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
545 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
546 return super.onPrepareOptionsMenu(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
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
549 // These are the Android calls to actually create the UI...
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
550 // forwarded from the C Dynamic Windows API
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
551
2551
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
552 fun darkModeDetected(): Int
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
553 {
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
554 return darkMode
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
555 }
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
556
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
557 fun menuBarNew(location: View): DWMenu?
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
558 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
559 // 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
560 return menuBar
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
561 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
562
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
563 fun menuNew(cid: Int): DWMenu
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
564 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
565 val menu = DWMenu()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
566 menu.id = cid
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
567 return menu
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
568 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
569
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
570 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
571 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
572 val menuitem = DWMenuItem()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
573 menuitem.id = cid
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
574 menuitem.title = title
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
575 menuitem.check = check != 0
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
576 if(submenu != null) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
577 menuitem.submenu = submenu
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
578 }
2546
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
579 if((flags and (1 shl 1)) != 0) {
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
580 menuitem.enabled = false
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
581 }
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
582 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
583 menuitem.checked = true
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
584 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
585 if(end == 0) {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
586 menu.children.add(0, menuitem)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
587 } else {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
588 menu.children.add(menuitem)
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
589 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
590 return menuitem
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
591 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
592
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
593 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
594 {
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 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
596 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
597 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
598 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
599 }
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 }
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
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 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
603 {
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 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
605 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
606 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
607 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
608 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
609 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
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 }
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
613 }
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
614
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
615 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
616 {
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
617 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
618 if(menuitem.id == cid) {
2546
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
619 // Handle DW_MIS_ENABLED/DISABLED
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
620 if((state and (1 or (1 shl 1))) != 0) {
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
621 var enabled: Boolean = false
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
622
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
623 // Handle DW_MIS_ENABLED
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
624 if ((state and 1) != 0) {
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
625 enabled = true
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
626 }
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
627 menuitem.enabled = enabled
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
628 runOnUiThread {
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
629 menuitem.menuitem!!.isEnabled = enabled
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
630 invalidateOptionsMenu()
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
631 }
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
632 }
897d94c20365 Android: Implement disabled menu items.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2545
diff changeset
633
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
634 // 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
635 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
636 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
637
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
638 // 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
639 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
640 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
641 }
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
642 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
643 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
644 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
645 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
646 }
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
647 }
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
648 }
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
649 }
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
650 }
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
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 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
653 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
654 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
655 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
656 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
657
2503
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
658 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
659 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
660 setContentView(windowLayout)
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
661 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
662 // 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
663 // 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
664 firstWindow = false
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
665 }
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
666 return windowLayout
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
667 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
668 return null
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
669 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
670
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
671 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
672 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
673 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
674
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
675 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
676 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
677 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
678
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
679 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
680 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
681 } else {
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
682 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
683 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
684 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
685 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
686
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
687 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
688 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
689
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
690 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
691 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
692
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
693 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
694 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
695 return retval
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
696 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
697
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
698 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
699 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
700 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
701 }
2475
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
702 }
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
703
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
704 fun typefaceFromFontName(fontname: String?): Typeface?
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
705 {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
706 if(fontname != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
707 val bold: Boolean = fontname.contains(" Bold")
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
708 val italic: Boolean = fontname.contains(" Italic")
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
709 val font = fontname.substringAfter('.')
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
710 var fontFamily = font
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
711 var typeface: Typeface? = null
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
712
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
713 if (bold && font != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
714 fontFamily = font.substringBefore(" Bold")
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
715 } else if (italic && font != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
716 fontFamily = font.substringBefore(" Italic")
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
717 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
718
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
719 if (fontFamily != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
720 var style: Int = Typeface.NORMAL
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
721 if (bold && italic) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
722 style = Typeface.BOLD_ITALIC
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
723 } else if (bold) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
724 style = Typeface.BOLD
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
725 } else if (italic) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
726 style = Typeface.ITALIC
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
727 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
728 typeface = Typeface.create(fontFamily, style)
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
729 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
730 return typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
731 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
732 return Typeface.DEFAULT
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
733 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
734
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
735 fun windowSetFont(window: View, fontname: String?) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
736 var typeface: Typeface? = typefaceFromFontName(fontname)
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
737 var size: Float? = null
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
738
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
739 if(fontname != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
740 size = fontname.substringBefore('.').toFloatOrNull()
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
741 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
742
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
743 if(typeface != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
744 waitOnUiThread {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
745 if (window is TextView) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
746 var textview: TextView = window
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
747 textview.typeface = typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
748 if(size != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
749 textview.textSize = size
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
750 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
751 } else if (window is Button) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
752 var button: Button = window
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
753 button.typeface = typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
754 if(size != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
755 button.textSize = size
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
756 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
757 } else if(window is DWRender) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
758 var render: DWRender = window
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
759 render.typeface = typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
760 if(size != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
761 render.fontsize = size
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
762 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
763 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
764 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
765 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
766 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
767
2551
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
768 fun windowSetColor(window: View, fore: Int, falpha: Int, fred: Int, fgreen: Int, fblue: Int,
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
769 back: Int, balpha: Int, bred: Int, bgreen: Int, bblue: Int) {
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
770 var colorfore: Int = Color.rgb(fred, fgreen, fblue)
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
771 var colorback: Int = Color.rgb(bred, bgreen, bblue)
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
772
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
773 // DW_CLR_DEFAULT on background sets it transparent...
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
774 // so the background drawable shows through
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
775 if(back == 16) {
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
776 colorback = Color.TRANSPARENT
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
777 }
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
778
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
779 waitOnUiThread {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
780 if (window is TextView) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
781 var textview: TextView = window
2551
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
782
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
783 // Handle DW_CLR_DEFAULT
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
784 if(fore == 16) {
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
785 val value = TypedValue()
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
786 this.theme.resolveAttribute(R.attr.editTextColor, value, true)
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
787 colorfore = value.data
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
788 }
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
789 textview.setTextColor(colorfore)
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
790 textview.setBackgroundColor(colorback)
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
791 } else if (window is Button) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
792 var button: Button = window
2551
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
793
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
794 // Handle DW_CLR_DEFAULT
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
795 if(fore == 16) {
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
796 val value = TypedValue()
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
797 // colorButtonNormal requires API 21... use the editTextColor...
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
798 // on older versions as a placeholder... this is probably wrong
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
799 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
800 this.theme.resolveAttribute(R.attr.colorButtonNormal, value, true)
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
801 } else {
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
802 this.theme.resolveAttribute(R.attr.editTextColor, value, true)
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
803 }
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
804 colorfore = value.data
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
805 }
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
806 button.setTextColor(colorfore)
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
807 button.setBackgroundColor(colorback)
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
808 } else if(window is LinearLayout) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
809 var box: LinearLayout = window
2551
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
810
127779860ac1 Android: Implement DW_CLR_DEFAULT and some basic dark mode support.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2550
diff changeset
811 box.setBackgroundColor(colorback)
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
812 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
813 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
814 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
815
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
816 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
817 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
818 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
819 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
820 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
821 } 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
822 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
823 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
824 } 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
825 // 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
826 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
827 }
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
828 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
829 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
830
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
831 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
832 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
833
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
834 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
835 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
836 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
837 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
838 } 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
839 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
840 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
841 } 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
842 // 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
843 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
844 }
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
845 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
846 return text
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
847 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
848
2503
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
849 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
850 {
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
851 waitOnUiThread {
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
852 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
853 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
854 } else {
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
855 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
856 }
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
857 }
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
858 }
1c2a79313b04 Android: Implment dw_window_hide/show(). Set the initial visibility to GONE.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2502
diff changeset
859
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
860 fun clipboardGetText(): String {
2489
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
861 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
862 var clipdata = cm.primaryClip
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
863
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
864 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
865 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
866 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
867 return ""
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
868 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
869
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
870 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
871 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
872 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
873
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
874 cm.setPrimaryClip(clipdata)
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
diff changeset
875 }
6c01b0132813 Android: Implement window and clipboard text setter and getters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2488
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 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
878 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
879 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
880 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
881 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
882
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
883 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
884 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
885 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
886 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
887 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
888 )
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
889 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
890 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
891 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
892 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
893 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
894 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
895 }
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
896 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
897 }
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
898
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
899 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
900 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
901
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
902 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
903 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
904 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
905 var dataArrayMap = SimpleArrayMap<String, Long>()
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
906
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
907 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
908 box.layoutParams =
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
909 LinearLayout.LayoutParams(
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
910 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
911 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
912 )
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
913 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
914 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
915 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
916 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
917 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
918 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
919 // 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
920 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
921 scrollBox!!.addView(box)
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
922 }
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
923 return scrollBox
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
924 }
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
925
2495
5664c91d03fb Android: Attempts to sort out the various issues... still not working but...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2494
diff changeset
926 fun boxPack(
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
927 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
928 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
929 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
930 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
931 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
932 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
933 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
934 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
935 ) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
936 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
937 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
938 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
939 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
940
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
941 // 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
942 // 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
943 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
944 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
945 } 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
946 var sv: ScrollView = boxview
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
947
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
948 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
949 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
950 }
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
951 }
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
952
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
953 if (box != null) {
2553
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
954 var weight: Float = 1F
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
955
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
956 // If it is a box, match parent based on direction
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
957 if ((item is LinearLayout) || (item is ScrollView)) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
958 if (box.orientation == LinearLayout.VERTICAL) {
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
959 if (hsize != 0) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
960 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
961 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
962 } else {
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
963 if (vsize != 0) {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
964 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
965 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
966 }
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
967 // If it isn't a box... set or calculate the size as needed
2553
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
968 } else {
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
969 if(width != -1 || height != -1) {
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
970 item.measure(0, 0)
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
971 }
2553
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
972 if(hsize == 0) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
973 if (width > 0) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
974 w = width
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
975 }
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
976 } else {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
977 if (width > 0) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
978 weight = width.toFloat()
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
979 } else if (width == -1) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
980 val newwidth = item.getMeasuredWidth()
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
981
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
982 if(newwidth > 0) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
983 weight = newwidth.toFloat()
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
984 }
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
985 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
986 }
2553
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
987 if(vsize == 0) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
988 if (height > 0) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
989 h = height
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
990 }
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
991 } else {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
992 if (height > 0) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
993 weight = height.toFloat()
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
994 } else if (height == -1) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
995 val newheight = item.getMeasuredHeight()
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
996
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
997 if(newheight > 0) {
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
998 weight = newheight.toFloat()
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
999 }
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
1000 }
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1001 }
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
1002 }
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1003
2553
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
1004 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h)
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
1005
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1006 // Handle expandable items by giving them a weight...
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1007 // in the direction of the box.
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1008 if (box.orientation == LinearLayout.VERTICAL) {
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1009 if (vsize != 0) {
2553
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
1010 params.weight = weight
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1011 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1012 } else {
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1013 if (hsize != 0) {
2553
2b4f2929408e Android: Fix issue with specifying static sizes... still some issues.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2552
diff changeset
1014 params.weight = weight
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
1015 }
2480
878d36588aaa Android: Enable app rotation and fix some issues with layout.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2479
diff changeset
1016 }
2552
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1017 // Gravity needs to match the expandable settings
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1018 var grav: Int = Gravity.CLIP_HORIZONTAL or Gravity.CLIP_VERTICAL
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1019 if (hsize != 0 && vsize != 0) {
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1020 params.gravity = Gravity.FILL or grav
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1021 } else if (hsize != 0) {
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1022 params.gravity = Gravity.FILL_HORIZONTAL or grav
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1023 } else if (vsize != 0) {
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1024 params.gravity = Gravity.FILL_VERTICAL or grav
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1025 }
303f544d14fa Android: Refactor boxPack() to try to fix non-expandable items expanding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2551
diff changeset
1026 // Finally add the padding
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1027 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
1028 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
1029 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1030 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
1031 box.addView(item, index)
2500
ac0b7e579229 Android: Implement dw_scrollbox_new() using ScrollView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2499
diff changeset
1032 }
2478
b0230e378667 Android: Improvements to boxPack to handle more parameters...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2477
diff changeset
1033 }
2475
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
1034 }
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
1035
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1036 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
1037 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1038 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
1039 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
1040 }
2477
3fbf8783122d Android: First functional version. Notebook-less first page of dwtest works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2476
diff changeset
1041 }
3fbf8783122d Android: First functional version. Notebook-less first page of dwtest works.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2476
diff changeset
1042
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1043 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
1044 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
1045
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1046 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1047 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
1048
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1049 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
1050 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1051 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
1052 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1053
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1054 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
1055 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
1056 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1057 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
1058 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
1059
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1060 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
1061 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
1062 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
1063 button!!.setOnClickListener {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1064 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
1065 }
2482
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
1066 }
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1067 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
1068 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1069
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1070 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
1071 var button: ImageButton? = null
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1072 waitOnUiThread {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1073 button = ImageButton(this)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1074 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
1075
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1076 button!!.tag = dataArrayMap
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1077 button!!.id = resid
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1078 button!!.setImageResource(resid)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1079 button!!.setOnClickListener {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1080 eventHandlerSimple(button!!, 8)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1081 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1082 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1083 return button
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1084 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1085
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1086 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
1087 var button: ImageButton? = null
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1088 waitOnUiThread {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1089 button = ImageButton(this)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1090 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
1091
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1092 button!!.tag = dataArrayMap
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1093 button!!.id = cid
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1094 button!!.setOnClickListener {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1095 eventHandlerSimple(button!!, 8)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1096 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1097 // 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
1098 try {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1099 val f = File(filename)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1100 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
1101 button!!.setImageBitmap(b)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1102 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1103 catch (e: FileNotFoundException)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1104 {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1105 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1106 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1107 return button
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1108 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1109
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1110 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
1111 var button: ImageButton? = null
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1112 waitOnUiThread {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1113 button = ImageButton(this)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1114 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
1115 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
1116
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1117 button!!.tag = dataArrayMap
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1118 button!!.id = cid
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1119 button!!.setOnClickListener {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1120 eventHandlerSimple(button!!, 8)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1121 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1122 button!!.setImageBitmap(b)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1123 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1124 return button
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1125 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1126
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1127 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
1128 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
1129
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1130 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1131 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
1132 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
1133
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1134 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
1135 entryfield!!.id = cid
2554
4c75fb6089a9 Android: Need to set isSingleLine for entryfields.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2553
diff changeset
1136 entryfield!!.isSingleLine = true
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1137 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
1138 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
1139 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1140 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
1141 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1142 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
1143 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1144
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1145 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
1146 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1147 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
1148 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1149 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1150
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1151 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
1152 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
1153
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1154 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1155 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
1156 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
1157
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1158 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
1159 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
1160 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
1161 radiobutton!!.setOnClickListener {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1162 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
1163 }
2482
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
1164 }
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1165 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
1166 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1167
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1168 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
1169 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
1170
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1171 waitOnUiThread {
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>()
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
1173
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1174 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
1175 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
1176 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
1177 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
1178 checkbox!!.setOnClickListener {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1179 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
1180 }
2482
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
1181 }
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1182 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
1183 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1184
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1185 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
1186 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1187 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1188 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
1189 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
1190 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
1191 } 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
1192 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
1193 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
1194 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1195 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1196 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1197
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1198 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
1199 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1200 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
1201
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1202 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1203 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
1204 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
1205 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
1206 } 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
1207 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
1208 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
1209 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1210 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1211 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
1212 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1213
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1214 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
1215 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
1216
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1217 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1218 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
1219
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1220 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
1221 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
1222 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
1223 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
1224 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
1225 val border = GradientDrawable()
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1226
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1227 // 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
1228 // 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
1229 // 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
1230 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
1231 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
1232 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
1233 }
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1234 }
2476
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1235 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
1236 }
20c9e83cba2a Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2475
diff changeset
1237
2510
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1238 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
1239 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1240 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
1241
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1242 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1243 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
1244
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1245 mle = EditText(this)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1246 mle!!.tag = dataArrayMap
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1247 mle!!.id = cid
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1248 mle!!.isSingleLine = false
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1249 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
1250 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
1251 mle!!.isVerticalScrollBarEnabled = true
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1252 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
1253 mle!!.setHorizontallyScrolling(true)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1254 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1255 return mle
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1256 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1257
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1258 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
1259 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1260 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1261 if (state != 0) {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1262 mle.setHorizontallyScrolling(false)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1263 } else {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1264 mle.setHorizontallyScrolling(true)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1265 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1266 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1267 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1268
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1269 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
1270 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1271 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1272 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
1273 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
1274 } else {
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1275 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
1276 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1277 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1278 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1279
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1280 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
1281 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1282 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1283 mle.setSelection(point)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1284 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1285 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1286
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1287 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
1288 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1289 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1290 mle.setText("")
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1291 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1292 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1293
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1294 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
1295 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1296 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
1297
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1298 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1299 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
1300 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
1301
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1302 if(startpoint < 1) {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1303 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
1304
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1305 mle.setText(newtext)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1306 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
1307 } 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
1308 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
1309
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1310 mle.setText(newtext)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1311 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
1312 } else {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1313 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
1314
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1315 mle.setText(newtext)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1316 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
1317 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1318 mle.setSelection(retval)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1319 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1320 return retval
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1321 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1322
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1323 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
1324 {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1325 waitOnUiThread {
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1326 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
1327 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
1328
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1329 mle.setText(newtext)
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1330 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
diff changeset
1331 }
f54051c3f2a5 Android: Implement MLE functions. Fix issues with checkboxes and sliders.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2505
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 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
1334 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1335 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
1336
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1337 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1338 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
1339 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
1340 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
1341 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
1342 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
1343
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1344 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
1345 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
1346 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
1347 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
1348 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
1349 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
1350 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
1351 // 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
1352 }.attach()
2488
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
1353
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1354 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
1355 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
1356 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
1357 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1358 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
1359 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1360 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
1361 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
1362 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
1363 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
1364 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
1365 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
1366 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1367 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
1368 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1369 notebook!!.addView(pager, params)
2550
a8d90e2896bc Android: For the moment disable swiping to change notebook pages.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2547
diff changeset
1370 // TODO: Not sure if we want this all the time...
a8d90e2896bc Android: For the moment disable swiping to change notebook pages.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2547
diff changeset
1371 // Might want to make a flag for this
a8d90e2896bc Android: For the moment disable swiping to change notebook pages.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2547
diff changeset
1372 pager.isUserInputEnabled = false
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1373 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
1374 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
1375 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
1376
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1377 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
1378 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
1379 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1380
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1381 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
1382 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
1383 })
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1384 }
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
1385 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
1386 }
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
1387
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1388 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
1389 {
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1390 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
1391
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1392 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1393 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
1394 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
1395
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1396 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
1397 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
1398 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
1399 } 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
1400 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
1401 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
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 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
1405 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
1406 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
1407
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1408 // 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
1409 do {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1410 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
1411 } 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
1412 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
1413 // 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
1414 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
1415 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
1416 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
1417 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
1418 } else {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1419 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
1420 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
1421 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
1422 }
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
1423 }
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
1424 }
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1425 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
1426 }
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
1427
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1428 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
1429 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1430 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1431 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
1432 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
1433
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1434 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
1435 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
1436 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
1437 } 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
1438 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
1439 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
1440 }
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
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 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
1443 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
1444 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
1445 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
1446
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1447 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
1448 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
1449 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
1450 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
1451 }
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1452 }
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
1453 }
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
1454 }
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
1455
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1456 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
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 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
1460 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
1461
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1462 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
1463 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
1464 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
1465 } 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
1466 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
1467 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
1468 }
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
1469
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1470 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
1471 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
1472 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
1473 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
1474
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1475 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
1476 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
1477 }
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1478 }
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
1479 }
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
1480 }
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
1481
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1482 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
1483 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1484 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1485 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
1486 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
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 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
1489 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
1490 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
1491 } 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
1492 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
1493 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
1494 }
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
1495
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1496 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
1497 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
1498 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
1499
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1500 // 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
1501 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
1502 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
1503 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
1504 );
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1505
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1506 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
1507 }
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
1508 }
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
1509 }
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
1510
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1511 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
1512 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1513 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
1514
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1515 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1516 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
1517 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
1518
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1519 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
1520 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
1521 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
1522 } 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
1523 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
1524 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
1525 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1526
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1527 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
1528 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
1529 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
1530 }
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
1531 }
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1532 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
1533 }
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
1534
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
1535 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
1536 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1537 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1538 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
1539 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
1540
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1541 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
1542 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
1543 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
1544 } 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
1545 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
1546 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
1547 }
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
1548
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1549 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
1550 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
1551 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
1552 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
1553
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1554 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
1555 }
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
1556 }
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1557 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
1558
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1559 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
1560 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1561 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
1562
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1563 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1564 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
1565
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1566 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
1567 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
1568 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
1569 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
1570 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
1571 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
1572 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1573 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
1574 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
1575 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1576
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1577 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
1578 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1579
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1580 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
1581 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
1582 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1583 })
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1584 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1585 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
1586 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1587
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1588 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
1589 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1590 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
1591
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1592 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1593 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
1594
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1595 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
1596 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
1597 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
1598 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
1599 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1600 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
1601 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1602
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1603 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
1604 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1605 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
1606
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1607 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1608 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
1609 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1610 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
1611 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1612
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1613 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
1614 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1615 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1616 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
1617 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1618 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1619
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1620 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
1621 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1622 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1623 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
1624 }
2492
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1625 }
e2ca6c1a4661 Android: Implement: slider, percent, scrollbar, checkbox_set/get box_unpack_at_index(),
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2491
diff changeset
1626
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1627 fun htmlNew(cid: Int): WebView?
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1628 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1629 var html: WebView? = null
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1630
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1631 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1632 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
1633
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1634 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
1635 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
1636 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
1637 // 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
1638 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
1639 html!!.settings.javaScriptEnabled = true
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1640 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1641 return html
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1642 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1643
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1644 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
1645 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1646 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1647 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
1648 }
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1649 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1650
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1651 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
1652 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1653 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1654 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
1655 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
1656 }
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1657 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1658
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1659 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
1660 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1661 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1662 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
1663 // 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
1664 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
1665 }
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1666 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1667 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1668
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1669 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
1670 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1671 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1672 when (action) {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
1673 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
1674 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
1675 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
1676 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
1677 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
1678 }
2501
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1679 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1680 }
41984ffb5ca2 Android: Initial implement of HTML control with WebView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2500
diff changeset
1681
2520
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1682 fun spinButtonNew(text: String, cid: Int): DWSpinButton?
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1683 {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1684 var spinbutton: DWSpinButton? = null
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1685
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1686 waitOnUiThread {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1687 var dataArrayMap = SimpleArrayMap<String, Long>()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1688 val newval = text.toLongOrNull()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1689
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1690 spinbutton = DWSpinButton(this)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1691 spinbutton!!.tag = dataArrayMap
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1692 spinbutton!!.id = cid
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1693 spinbutton!!.setText(text)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1694 if(newval != null) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1695 spinbutton!!.value = newval
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1696 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1697 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1698 return spinbutton
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1699 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1700
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1701 fun spinButtonSetPos(spinbutton: DWSpinButton, position: Long)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1702 {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1703 waitOnUiThread {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1704 spinbutton.value = position
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1705 spinbutton.setText(position.toString())
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1706 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1707 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1708
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1709 fun spinButtonSetLimits(spinbutton: DWSpinButton, upper: Long, lower: Long)
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1710 {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1711 waitOnUiThread {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1712 spinbutton.maximum = upper
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1713 spinbutton.minimum = lower
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1714 if(spinbutton.value > upper) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1715 spinbutton.value = upper
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1716 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1717 if(spinbutton.value < lower) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1718 spinbutton.value = lower
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1719 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1720 spinbutton.setText(spinbutton.value.toString())
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1721 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1722 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1723
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1724 fun spinButtonGetPos(spinbutton: DWSpinButton): Long
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1725 {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1726 var retval: Long = 0
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1727
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1728 waitOnUiThread {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1729 val newvalue = spinbutton.text.toString().toLongOrNull()
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1730
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1731 if(newvalue == null) {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1732 retval = spinbutton.value
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1733 } else {
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1734 retval = newvalue
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1735 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1736 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1737 return retval
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1738 }
167af4b0004b Android: Implement spinbuttons and callbacks.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2519
diff changeset
1739
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1740 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
1741 {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1742 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
1743
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1744 waitOnUiThread {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1745 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
1746
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1747 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
1748 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
1749 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
1750 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
1751 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1752 return combobox
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1753 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1754
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1755 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
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 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
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 waitOnUiThread {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1760 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
1761
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1762 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
1763 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
1764 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
1765 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
1766 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
1767 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1768 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1769 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
1770 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1771
2515
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1772 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
1773 {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1774 waitOnUiThread {
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1775 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
1776 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
1777
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1778 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
1779 } 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
1780 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
1781
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1782 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
1783 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1784 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1785 }
211044d98e86 Android: Initial attempt at our own ComboBox class, EditText with PopupList.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2514
diff changeset
1786
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1787 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
1788 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1789 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1790 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
1791 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1792
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1793 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
1794 } 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
1795 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
1796
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1797 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
1798 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1799 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1800 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1801
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1802 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
1803 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1804 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1805 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
1806 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1807
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1808 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
1809 } 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
1810 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
1811
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1812 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
1813 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1814 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1815 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1816
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1817 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
1818 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1819 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
1820
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1821 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1822 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
1823 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1824
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1825 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
1826 } 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
1827 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
1828
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1829 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
1830 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1831 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1832 return retval
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1833 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1834
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1835 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
1836 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1837 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1838 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
1839 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1840
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1841 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
1842 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
1843 } 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
1844 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
1845
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1846 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
1847 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
1848 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1849 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1850 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1851
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1852 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
1853 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1854 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
1855
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1856 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1857 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
1858 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1859
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1860 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
1861 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
1862 } 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
1863 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
1864
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1865 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
1866 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
1867 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1868 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1869 return retval
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1870 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1871
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1872 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
1873 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1874 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
1875
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1876 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1877 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
1878 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1879
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1880 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
1881 } 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
1882 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
1883
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1884 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
1885 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1886 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1887 return retval
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1888 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1889
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1890 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
1891 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1892 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1893 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
1894 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1895
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1896 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
1897 combobox.selected = index
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1898 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
1899 }
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1900 } 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
1901 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
1902
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1903 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
1904 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
1905 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
1906 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
1907 } else {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1908 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
1909 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1910 }
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1911 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1912 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1913 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1914
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1915 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
1916 {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1917 waitOnUiThread {
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1918 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
1919 val combobox = window
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1920
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1921 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
1922 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
1923 }
2519
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1924 } 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
1925 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
1926
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1927 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
1928 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
1929 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1930 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1931 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1932 }
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1933
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1934 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
1935 {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1936 waitOnUiThread {
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1937 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
1938 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
1939
551313c064f2 Android: Implement ListBox with ListView and fill in the missing listbox functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2517
diff changeset
1940 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
1941 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
1942 }
2517
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1943 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1944 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1945 }
d746323f2841 Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2516
diff changeset
1946
2521
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1947 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
1948 {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1949 var retval: Int = -1
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1950
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1951 waitOnUiThread {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1952 if(window is DWListBox) {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1953 val listbox = window
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1954 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
1955
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1956 // 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
1957 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
1958 retval = checked.keyAt(0)
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1959 } else {
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1960 // 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
1961 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
1962 // Item position in adapter
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1963 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
1964 // 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
1965 // 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
1966 // 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
1967 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
1968 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
1969 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1970 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1971 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1972 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1973 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1974 return retval
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1975 }
5f92284e2b08 Android: Implement bitmap buttons, implement dw_listbox_selected_multi().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2520
diff changeset
1976
2523
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1977 fun calendarNew(cid: Int): CalendarView?
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1978 {
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1979 var calendar: CalendarView? = null
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1980
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1981 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
1982 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
1983
2523
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1984 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
1985 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
1986 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
1987 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
1988 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
1989 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
1990 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
1991 }
2523
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1992 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1993
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1994 return calendar
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1995 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1996
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1997 fun calendarSetDate(calendar: CalendarView, date: Long)
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1998 {
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
1999 waitOnUiThread {
2524
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
2000 // 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
2001 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
2002 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2003 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2004
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2005 fun calendarGetDate(calendar: CalendarView): Long
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2006 {
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2007 var date: Long = 0
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2008
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2009 waitOnUiThread {
2524
d5c3c573c74e Android: Calendar fixes, need to be in milliseconds not seconds... also...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2523
diff changeset
2010 // 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
2011 date = calendar.date / 1000
2523
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2012 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2013 return date
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2014 }
82cdb3ad7c25 Android: Implement the calendar widget using CalendarView.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2522
diff changeset
2015
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
2016 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
2017 {
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
2018 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
2019
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
2020 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
2021 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
2022
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
2023 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
2024 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
2025 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
2026 }
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
2027
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
2028 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
2029 }
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
2030
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
2031 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
2032 {
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
2033 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
2034 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
2035 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
2036 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
2037
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
2038 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
2039 } 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
2040 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
2041
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
2042 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
2043 }
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
2044 } 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
2045 // 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
2046 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
2047 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
2048 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
2049 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
2050 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
2051
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
2052 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
2053 } 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
2054 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
2055
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
2056 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
2057 }
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
2058 } 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
2059 }
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
2060 }
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
2061 }
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
2062 }
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
2063
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
2064 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
2065 {
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
2066 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
2067 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
2068 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
2069 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
2070
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
2071 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
2072 } 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
2073 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
2074
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
2075 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
2076 }
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
2077 } 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
2078 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
2079
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
2080 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
2081 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
2082
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
2083 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
2084 } 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
2085 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
2086
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
2087 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
2088 }
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
2089 }
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
2090 }
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
2091 }
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
2092
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2093 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
2094 {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2095 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
2096
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2097 waitOnUiThread {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2098 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
2099 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
2100 } 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
2101 // 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
2102 try {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2103 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
2104 } 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
2105 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2106 } 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
2107 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
2108 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2109 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2110 return icon
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2111 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2112
2529
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2113 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
2114 {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2115 var pixmap: Bitmap? = null
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2116
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2117 waitOnUiThread {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2118 if(width > 0 && height > 0) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2119 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
2120 } else if(resID != 0) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2121 pixmap = BitmapFactory.decodeResource(resources, resID);
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2122 } else if(filename != null) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2123 // 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
2124 try {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2125 val f = File(filename)
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2126 pixmap = BitmapFactory.decodeStream(FileInputStream(f))
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2127 } catch (e: FileNotFoundException) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2128 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2129 } else if(data != null) {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2130 pixmap = BitmapFactory.decodeByteArray(data, 0, length)
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2131 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2132 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2133 return pixmap
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2134 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2135
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2136 fun pixmapGetDimensions(pixmap: Bitmap): Long
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2137 {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2138 var dimensions: Long = 0
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2139
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2140 waitOnUiThread {
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2141 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
2142 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2143 return dimensions
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2144 }
060fdb2d807d Android: Initial pixmap implmentation using Android Bitmap.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2528
diff changeset
2145
2542
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2146 fun screenGetDimensions(): Long
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2147 {
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2148 val dm = resources.displayMetrics
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2149 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
2150 }
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2151
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2152 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
2153 {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2154 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
2155
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2156 waitOnUiThread {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2157 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
2158
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2159 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
2160 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
2161 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
2162 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2163 return render
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2164 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2165
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2166 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
2167 {
2539
822f814a54f4 Android: Fix memory corruption issue due to incorrectly allocating HPIXMAP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2538
diff changeset
2168 runOnUiThread {
822f814a54f4 Android: Fix memory corruption issue due to incorrectly allocating HPIXMAP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2538
diff changeset
2169 render.invalidate()
822f814a54f4 Android: Fix memory corruption issue due to incorrectly allocating HPIXMAP.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2538
diff changeset
2170 }
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2171 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2172
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2173 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
2174 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
2175 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2176 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
2177 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
2178 var retval: Int = 1
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2179
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2180 if(srcw == -1) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2181 src.right = srcx + dstw
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2182 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2183 if(srch == -1) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2184 src.bottom = srcy + dsth
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2185 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2186
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2187 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2188 var canvas: Canvas? = null
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2189 var bitmap: Bitmap? = null
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2190
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2191 if(dstr != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2192 canvas = dstr.cachedCanvas
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2193 } else if(dstp != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2194 canvas = Canvas(dstp)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2195 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2196
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2197 if(srcp != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2198 bitmap = srcp
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2199 } else if(srcr != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2200 bitmap = Bitmap.createBitmap(srcr.layoutParams.width,
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2201 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
2202 val c = Canvas(bitmap)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2203 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
2204 srcr.draw(c)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2205 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2206
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2207 if(canvas != null && bitmap != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2208 canvas.drawBitmap(bitmap, src, dst, null)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2209 retval = 0
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2210 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2211 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2212 return retval
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2213 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2214
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2215 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
2216 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2217 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2218 var canvas: Canvas? = null
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 if(render != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2221 canvas = render.cachedCanvas
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2222 } else if(bitmap != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2223 canvas = Canvas(bitmap)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2224 }
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 if(canvas != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2227 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
2228 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2229 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2230 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2231
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2232 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
2233 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2234 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2235 var canvas: Canvas? = null
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2236
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2237 if(render != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2238 canvas = render.cachedCanvas
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2239 } else if(bitmap != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2240 canvas = Canvas(bitmap)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2241 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2242
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2243 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
2244 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
2245 paint.style = Paint.Style.STROKE
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2246 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
2247 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2248 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2249 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2250
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2251 fun fontTextExtentsGet(render: DWRender?, bitmap: Bitmap?, text:String, typeface: Typeface?, fontsize: Int, window: View?): Long
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2252 {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2253 var dimensions: Long = 0
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2254
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2255 waitOnUiThread {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2256 var rect = Rect()
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2257
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2258 if (render != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2259 if (render.typeface != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2260 paint.typeface = render.typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2261 if (render.fontsize != null && render.fontsize!! > 0F) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2262 paint.textSize = render.fontsize!!
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2263 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2264 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2265 } else if (bitmap != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2266 if (typeface != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2267 paint.typeface = typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2268 if (fontsize > 0) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2269 paint.textSize = fontsize.toFloat()
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2270 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2271 } else if (window != null && window is DWRender) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2272 val secondary: DWRender = window as DWRender
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2273
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2274 if (secondary.typeface != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2275 paint.typeface = secondary.typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2276 if (secondary.fontsize != null && secondary.fontsize!! > 0F) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2277 paint.textSize = secondary.fontsize!!
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2278 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2279 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2280 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2281 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2282 paint.getTextBounds(text, 0, text.length, rect)
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2283 val textheight = rect.bottom - rect.top
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2284 val textwidth = rect.right - rect.left
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2285 dimensions = textwidth.toLong() or (textheight.toLong() shl 32)
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2286 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2287 return dimensions
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2288 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2289
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2290 fun drawText(render: DWRender?, bitmap: Bitmap?, x: Int, y: Int, text:String, typeface: Typeface?, fontsize: Int, window: View?)
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2291 {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2292 waitOnUiThread {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2293 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
2294
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2295 if(render != null && render.cachedCanvas != null) {
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2296 canvas = render.cachedCanvas
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2297 if(render.typeface != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2298 paint.typeface = render.typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2299 if(render.fontsize != null && render.fontsize!! > 0F) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2300 paint.textSize = render.fontsize!!
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2301 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2302 }
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2303 } 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
2304 canvas = Canvas(bitmap)
2547
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2305 if(typeface != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2306 paint.typeface = typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2307 if(fontsize > 0) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2308 paint.textSize = fontsize.toFloat()
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2309 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2310 } else if(window != null && window is DWRender) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2311 val secondary: DWRender = window as DWRender
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2312
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2313 if(secondary.typeface != null) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2314 paint.typeface = secondary.typeface
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2315 if(secondary.fontsize != null && secondary.fontsize!! > 0F) {
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2316 paint.textSize = secondary.fontsize!!
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2317 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2318 }
dbd15c13f5bb Android: Implement most of the font functions and control/widget color.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2546
diff changeset
2319 }
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2320 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2321
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2322 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
2323 // 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
2324 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
2325 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
2326 // 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
2327 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
2328 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
2329 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
2330 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
2331 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
2332 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
2333 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
2334 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
2335 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
2336 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
2337 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
2338 // 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
2339 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
2340 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
2341 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
2342 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2343 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2344 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2345
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2346 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
2347 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2348 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2349 var canvas: Canvas? = null
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2350
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2351 if(render != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2352 canvas = render.cachedCanvas
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2353 } else if(bitmap != null) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2354 canvas = Canvas(bitmap)
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2355 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2356
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2357 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
2358 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
2359 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
2360 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
2361 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2362 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2363 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2364
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2365 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
2366 {
2537
cd9d2ba251d5 Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2536
diff changeset
2367 // 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
2368 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
2369
2537
cd9d2ba251d5 Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2536
diff changeset
2370 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
2371 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
2372 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
2373 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2374
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2375 waitOnUiThread {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2376 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
2377
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2378 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
2379 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
2380 } 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
2381 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
2382 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2383
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2384 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
2385 // 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
2386 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
2387 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
2388 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2389 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
2390 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2391 // 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
2392 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
2393 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
2394 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2395 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
2396 }
2537
cd9d2ba251d5 Android: Reimplement drawPolygon() using drawPath() instead of drawLines/Points().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2536
diff changeset
2397 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
2398 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2399 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2400 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2401
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2402 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
2403 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
2404 {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2405 waitOnUiThread {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2406 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
2407
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2408 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
2409 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
2410 } 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
2411 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
2412 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2413
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2414 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
2415 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
2416 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
2417 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
2418 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
2419 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
2420 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
2421 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
2422 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
2423
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2424 /* 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
2425 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
2426 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
2427 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
2428
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2429 // 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
2430 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
2431 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
2432 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2433 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
2434 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2435 // 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
2436 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
2437 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
2438 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2439 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
2440 }
2536
d172ab2eddb6 Android: Implement DW_DRAW_FULL flag for dw_draw_arc().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2535
diff changeset
2441 // 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
2442 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
2443 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
2444 } else {
d172ab2eddb6 Android: Implement DW_DRAW_FULL flag for dw_draw_arc().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2535
diff changeset
2445 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
2446 }
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2447 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2448 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2449 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2450
2531
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2451 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
2452 {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2453 waitOnUiThread {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2454 if(alpha != 0) {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2455 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
2456 } else {
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2457 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
2458 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2459 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2460 }
f45ebd96ebe5 Android: First attempts at implementing drawing functions
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2530
diff changeset
2461
2535
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2462 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
2463 {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2464 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
2465 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
2466 } else {
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2467 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
2468 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2469 }
d862d9e4069b Android: Implement most of the rest of drawing except for fonts...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2531
diff changeset
2470
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2471 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
2472 {
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2473 // creating timer task, timer
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2474 val t = Timer()
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2475 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
2476 override fun run() {
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2477 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
2478 t.cancel()
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2479 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2480 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2481 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2482 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
2483 return t
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2484 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2485
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2486 fun timerDisconnect(timer: Timer)
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2487 {
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2488 timer.cancel()
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2489 }
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2490
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2491 fun doBeep(duration: Int)
62e124eecd82 Android: Implement timers and beep. Some general code cleanup.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2489
diff changeset
2492 {
2491
bf4fe6bb512b Android: Fix the permission error on the beep...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2490
diff changeset
2493 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
2494 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
2495 val handler = Handler(Looper.getMainLooper())
bf4fe6bb512b Android: Fix the permission error on the beep...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2490
diff changeset
2496 handler.postDelayed({
bf4fe6bb512b Android: Fix the permission error on the beep...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2490
diff changeset
2497 toneGen.release()
bf4fe6bb512b Android: Fix the permission error on the beep...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2490
diff changeset
2498 }, (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
2499 }
666af45f33b5 Android: Implment a bunch of window functions: enable/disable/data/id
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2487
diff changeset
2500
2482
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2501 fun debugMessage(text: String)
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2502 {
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2503 Log.d(null, text)
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2504 }
4888503c3e3e Android: Implement dw_debug() using the Android Log class.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2481
diff changeset
2505
2526
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2506 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
2507 {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2508 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
2509
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2510 waitOnUiThread {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2511 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
2512 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
2513 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
2514 // 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
2515 retval = file!!.absolutePath
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2516 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
2517 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2518 })
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2519 if(ext != null) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2520 fc.setExtension(ext)
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2521 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2522 fc.showDialog()
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2523 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2524
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2525 // 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
2526 try {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2527 Looper.loop()
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2528 } catch (e2: RuntimeException) {
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2529 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2530
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2531 return retval
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2532 }
d3f09b3f3703 Android: Initial dw_file_browse() implementation, still needs some work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2524
diff changeset
2533
2486
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2534 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
2535 {
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2536 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
2537
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2538 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2539 // 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
2540 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
2541
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2542 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
2543 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
2544 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
2545 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
2546 //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
2547 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
2548 retval = 1
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2549 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
2550 });
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2551 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2552 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
2553 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
2554 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
2555 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
2556 retval = 0
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2557 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
2558 });
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2559 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2560 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
2561 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
2562 //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
2563 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
2564 retval = 0
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2565 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
2566 });
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2567 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2568 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
2569 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
2570 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
2571 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
2572 retval = 2
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2573 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
2574 });
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2575 }
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2576 alert.show();
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2577
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2578 // 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
2579 try {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2580 Looper.loop()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2581 } 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
2582 }
2486
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2583 }
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2584 return retval
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2585 }
cec43818bd3e Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2484
diff changeset
2586
2530
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2587 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
2588 {
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2589 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
2590 return true
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2591 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2592 return false
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2593 }
b9923432cb1f Android: Implement View based render widget and icon support with Drawable.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2529
diff changeset
2594
2514
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2595 fun mainSleep(milliseconds: Int)
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2596 {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2597 // 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
2598 // 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
2599 // 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
2600 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
2601 val starttime = System.currentTimeMillis()
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2602
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2603 // 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
2604 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
2605 var thrown: Boolean = false
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2606
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2607 override fun queueIdle(): Boolean {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2608 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
2609 if (thrown == false) {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2610 thrown = true
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2611 throw java.lang.RuntimeException()
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2612 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2613 return false
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2614 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2615 return true
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2616 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2617 })
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2618
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2619 // 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
2620 try {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2621 Looper.loop()
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2622 } catch (e2: RuntimeException) {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2623 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2624 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2625 else
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2626 {
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2627 // 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
2628 Thread.sleep(milliseconds.toLong())
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2629 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2630 }
5f711e86a211 Android: Implement dw_main_sleep() and dw_main_iteration().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2510
diff changeset
2631
2487
83f8f4f58a98 Android: Implement dw_exit() using Activity.finishActivity() instead of exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2486
diff changeset
2632 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
2633 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2634 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2635 this.finishAffinity()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2636 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
2637 }
2494
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
2638 }
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
2639
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
2640 fun dwindowsShutdown()
b3e28eed0e50 Android: Fix the basics of notebook control... return actual page IDs.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2493
diff changeset
2641 {
2502
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2642 waitOnUiThread {
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2643 this.finishAffinity()
b6319aed3298 Android: Massive thread safety overhaul. Not quite back to fully functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2501
diff changeset
2644 }
2487
83f8f4f58a98 Android: Implement dw_exit() using Activity.finishActivity() instead of exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2486
diff changeset
2645 }
83f8f4f58a98 Android: Implement dw_exit() using Activity.finishActivity() instead of exit().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2486
diff changeset
2646
2542
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2647 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
2648 {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2649 waitOnUiThread {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2650 // 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
2651 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
2652 // Create the NotificationChannel
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2653 val importance = NotificationManager.IMPORTANCE_DEFAULT
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2654 val mChannel = NotificationChannel(appid, appname, importance)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2655 // 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
2656 // or other notification behaviors after this
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2657 val notificationManager =
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2658 getSystemService(NOTIFICATION_SERVICE) as NotificationManager
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2659 notificationManager.createNotificationChannel(mChannel)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2660 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2661 }
2542
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2662 return Build.VERSION.SDK_INT
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2663 }
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2664
2543
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2665 fun dwMain()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2666 {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2667 runOnUiThread {
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2668 // 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
2669 invalidateOptionsMenu()
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2670 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2671 }
f9367eb9a6e7 Android: Initial menu support, incomplete but basics functional.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2542
diff changeset
2672
2542
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2673 fun androidGetRelease(): String
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2674 {
bb75e64e6138 Android: Implement dw_screen_* and dw_environment_query().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2539
diff changeset
2675 return Build.VERSION.RELEASE
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2676 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2677
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2678 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
2679 {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2680 var builder: NotificationCompat.Builder? = null
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2681
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2682 waitOnUiThread {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2683 builder = NotificationCompat.Builder(this, appid)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2684 .setContentTitle(title)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2685 .setContentText(text)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2686 .setPriority(NotificationCompat.PRIORITY_DEFAULT)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2687 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2688 return builder
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2689 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2690
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2691 fun notificationSend(builder: NotificationCompat.Builder)
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2692 {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2693 waitOnUiThread {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2694 notificationID += 1
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2695 with(NotificationManagerCompat.from(this)) {
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2696 // 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
2697 notify(notificationID, builder.build())
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2698 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2699 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2700 }
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2701
2475
16d195d46f2a Android: Implement dw_window_new(), dw_box_new() and dw_box_pack().
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2474
diff changeset
2702 /*
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
2703 * 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
2704 * 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
2705 */
2522
66c490aa719d Android: Implement notifications, images on notifications incomplete.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2521
diff changeset
2706 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
2707 external fun eventHandler(
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2708 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
2709 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
2710 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
2711 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
2712 str2: String?,
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2713 inta: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2714 intb: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2715 intc: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2716 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
2717 ): Int
2499
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2718 external fun eventHandlerInt(
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2719 obj1: View,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2720 message: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2721 inta: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2722 intb: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2723 intc: Int,
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2724 intd: Int
ff3310fa6d72 Android: Implment DW_SIGNA_CONFIGURE on orientation change.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2498
diff changeset
2725 )
2483
9f7af6d8c6a4 Android: Fix signal handlers so they actually work.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2482
diff changeset
2726 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
2727 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
2728 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
2729 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
2730
2474
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
2731 companion object
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
2732 {
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2733 // 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
2734 init
a13e6db064f4 Android: Implement thread, semaphore, shared memory API functions.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents: 2473
diff changeset
2735 {
2473
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2736 System.loadLibrary("dwindows")
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2737 }
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2738 }
aa420e366b2b Android: Initial skeletal commit for Android support, almost nothing implemented...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff changeset
2739 }