Mercurial > dwindows
comparison android/DWindows.kt @ 2476:20c9e83cba2a
Android: Implement dw_entryfield_new, dw_entryfield_password_new() dw_button_new(),
dw_text_new(), dw_status_text_new(), dw_checkbox_new() and dw_radiobutton_new().
Fix the signatures used in GetMethodID(), Android Studio can apparently do it autoamtically.
Add a LinearLayout to the DWindows activity, use it as the content view so we don't need XML.
dw_dwindow_new() will now return the LinearLayout instead of the Activity object... so the
handle can be used with dw_box_pack*().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 22 Apr 2021 00:04:01 +0000 |
parents | 16d195d46f2a |
children | 3fbf8783122d |
comparison
equal
deleted
inserted
replaced
2475:16d195d46f2a | 2476:20c9e83cba2a |
---|---|
1 package org.dbsoft.dwindows.dwtest | 1 package org.dbsoft.dwindows.dwtest |
2 | 2 |
3 import android.os.Bundle | 3 import android.os.Bundle |
4 import android.text.method.PasswordTransformationMethod | |
4 import android.view.View | 5 import android.view.View |
5 import android.widget.LinearLayout | 6 import android.widget.* |
6 import android.widget.TextView | |
7 import androidx.appcompat.app.AppCompatActivity | 7 import androidx.appcompat.app.AppCompatActivity |
8 | 8 |
9 | 9 |
10 class DWindows : AppCompatActivity() | 10 class DWindows : AppCompatActivity() |
11 { | 11 { |
12 public var windowLayout: LinearLayout = LinearLayout(this) | |
13 | |
12 override fun onCreate(savedInstanceState: Bundle?) | 14 override fun onCreate(savedInstanceState: Bundle?) |
13 { | 15 { |
14 super.onCreate(savedInstanceState) | 16 super.onCreate(savedInstanceState) |
15 setContentView(R.layout.dwindows_main) | 17 setContentView(windowLayout) |
16 | 18 |
17 val m = packageManager | 19 val m = packageManager |
18 var s = packageName | 20 var s = packageName |
19 val p = m.getPackageInfo(s!!, 0) | 21 val p = m.getPackageInfo(s!!, 0) |
20 s = p.applicationInfo.dataDir | 22 s = p.applicationInfo.dataDir |
21 | 23 |
22 // Example of a call to a native method | 24 // Initialize the Dynamic Windows code... |
23 findViewById<TextView>(R.id.sample_text).text = dwindowsInit(s) | 25 // This will start a new thread that calls the app's dwmain() |
26 dwindowsInit(s) | |
24 } | 27 } |
25 /* | 28 /* |
26 * These are the Android calls to actually create the UI... | 29 * These are the Android calls to actually create the UI... |
27 * forwarded from the C Dynamic Windows API | 30 * forwarded from the C Dynamic Windows API |
28 */ | 31 */ |
29 fun windowNew(title: String, style: Int): DWindows | 32 fun windowNew(title: String, style: Int): LinearLayout |
30 { | 33 { |
31 // For now we just return our DWindows activity... | 34 // For now we just return our DWindows' main activity layout... |
32 // in the future, later calls should create new activities | 35 // in the future, later calls should create new activities |
33 return this | 36 return windowLayout |
34 } | 37 } |
35 | 38 |
36 fun boxNew(type: Int, pad: Int): LinearLayout | 39 fun boxNew(type: Int, pad: Int): LinearLayout |
37 { | 40 { |
38 val box = LinearLayout(this) | 41 val box = LinearLayout(this) |
50 { | 53 { |
51 var w: Int = width; | 54 var w: Int = width; |
52 var h: Int = height; | 55 var h: Int = height; |
53 | 56 |
54 if(hsize > 0) { | 57 if(hsize > 0) { |
55 w = LinearLayout.LayoutParams.FILL_PARENT | 58 w = LinearLayout.LayoutParams.MATCH_PARENT |
56 } else if(w < 1) { | 59 } else if(w < 1) { |
57 w = LinearLayout.LayoutParams.WRAP_CONTENT | 60 w = LinearLayout.LayoutParams.WRAP_CONTENT |
58 } | 61 } |
59 if(vsize > 0) { | 62 if(vsize > 0) { |
60 h = LinearLayout.LayoutParams.FILL_PARENT | 63 h = LinearLayout.LayoutParams.MATCH_PARENT |
61 } else if(h < 1) { | 64 } else if(h < 1) { |
62 h = LinearLayout.LayoutParams.WRAP_CONTENT | 65 h = LinearLayout.LayoutParams.WRAP_CONTENT |
63 } | 66 } |
64 item.layoutParams = LinearLayout.LayoutParams(w, h) | 67 item.layoutParams = LinearLayout.LayoutParams(w, h) |
65 box.addView(item) | 68 box.addView(item) |
69 } | |
70 | |
71 fun buttonNew(text: String, cid: Int): Button | |
72 { | |
73 val button = Button(this) | |
74 button.text = text | |
75 return button | |
76 } | |
77 | |
78 fun entryfieldNew(text: String, cid: Int, password: Int): EditText | |
79 { | |
80 val entryfield = EditText(this) | |
81 if(password > 0) { | |
82 entryfield.transformationMethod = PasswordTransformationMethod.getInstance() | |
83 } | |
84 entryfield.setText(text) | |
85 return entryfield | |
86 } | |
87 | |
88 fun radioButtonNew(text: String, cid: Int): RadioButton | |
89 { | |
90 val radiobutton = RadioButton(this) | |
91 radiobutton.text = text | |
92 return radiobutton | |
93 } | |
94 | |
95 fun checkboxNew(text: String, cid: Int): CheckBox | |
96 { | |
97 val checkbox = CheckBox(this) | |
98 checkbox.text = text | |
99 return checkbox | |
100 } | |
101 | |
102 fun textNew(text: String, cid: Int, status: Int): TextView | |
103 { | |
104 val textview = TextView(this) | |
105 textview.text = text | |
106 return textview | |
66 } | 107 } |
67 | 108 |
68 /* | 109 /* |
69 * Native methods that are implemented by the 'dwindows' native library, | 110 * Native methods that are implemented by the 'dwindows' native library, |
70 * which is packaged with this application. | 111 * which is packaged with this application. |