Mercurial > dwindows
comparison android/DWindows.kt @ 2490:62e124eecd82
Android: Implement timers and beep. Some general code cleanup.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 30 Apr 2021 04:56:52 +0000 |
parents | 6c01b0132813 |
children | bf4fe6bb512b |
comparison
equal
deleted
inserted
replaced
2489:6c01b0132813 | 2490:62e124eecd82 |
---|---|
2 | 2 |
3 import android.content.ClipData | 3 import android.content.ClipData |
4 import android.content.ClipboardManager | 4 import android.content.ClipboardManager |
5 import android.content.DialogInterface | 5 import android.content.DialogInterface |
6 import android.content.pm.ActivityInfo | 6 import android.content.pm.ActivityInfo |
7 import android.graphics.drawable.GradientDrawable | |
8 import android.media.AudioManager | |
9 import android.media.ToneGenerator | |
7 import android.os.Bundle | 10 import android.os.Bundle |
8 import android.os.Looper | 11 import android.os.Looper |
9 import android.text.method.PasswordTransformationMethod | 12 import android.text.method.PasswordTransformationMethod |
10 import android.util.Log | 13 import android.util.Log |
11 import android.view.* | 14 import android.view.Gravity |
15 import android.view.LayoutInflater | |
16 import android.view.View | |
17 import android.view.ViewGroup | |
12 import android.widget.* | 18 import android.widget.* |
13 import androidx.appcompat.app.AlertDialog | 19 import androidx.appcompat.app.AlertDialog |
14 import androidx.appcompat.app.AppCompatActivity | 20 import androidx.appcompat.app.AppCompatActivity |
15 import androidx.collection.SimpleArrayMap | 21 import androidx.collection.SimpleArrayMap |
16 import androidx.core.content.res.TypedArrayUtils.getText | |
17 import androidx.fragment.app.Fragment | |
18 import androidx.fragment.app.FragmentActivity | |
19 import androidx.fragment.app.FragmentManager | |
20 import androidx.fragment.app.FragmentStatePagerAdapter | |
21 import androidx.recyclerview.widget.RecyclerView | 22 import androidx.recyclerview.widget.RecyclerView |
22 import androidx.viewpager.widget.ViewPager | |
23 import androidx.viewpager2.adapter.FragmentStateAdapter | |
24 import androidx.viewpager2.widget.ViewPager2 | 23 import androidx.viewpager2.widget.ViewPager2 |
25 import com.google.android.material.tabs.TabLayout | 24 import com.google.android.material.tabs.TabLayout |
26 import com.google.android.material.tabs.TabLayoutMediator | 25 import com.google.android.material.tabs.TabLayoutMediator |
26 import java.util.* | |
27 | |
27 | 28 |
28 class TabViewPagerAdapter : RecyclerView.Adapter<TabViewPagerAdapter.EventViewHolder>() { | 29 class TabViewPagerAdapter : RecyclerView.Adapter<TabViewPagerAdapter.EventViewHolder>() { |
29 val eventList = listOf("0", "1", "2") | 30 val eventList = listOf("0", "1", "2") |
30 | 31 |
31 // Layout "layout_demo_viewpager2_cell.xml" will be defined later | 32 // Layout "layout_demo_viewpager2_cell.xml" will be defined later |
125 | 126 |
126 fun windowSetText(window: View, text: String) | 127 fun windowSetText(window: View, text: String) |
127 { | 128 { |
128 if(window is TextView) | 129 if(window is TextView) |
129 { | 130 { |
130 var textview: TextView = window as TextView | 131 var textview: TextView = window |
131 textview.text = text | 132 textview.text = text |
132 } | 133 } |
133 else if(window is Button) | 134 else if(window is Button) |
134 { | 135 { |
135 var button: Button = window as Button | 136 var button: Button = window |
136 button.text = text | 137 button.text = text |
137 } | 138 } |
138 else if(window is LinearLayout) | 139 else if(window is LinearLayout) |
139 { | 140 { |
140 // TODO: Make sure this is actually the top-level layout, not just a box | 141 // TODO: Make sure this is actually the top-level layout, not just a box |
144 | 145 |
145 fun windowGetText(window: View): String? | 146 fun windowGetText(window: View): String? |
146 { | 147 { |
147 if(window is TextView) | 148 if(window is TextView) |
148 { | 149 { |
149 var textview: TextView = window as TextView | 150 var textview: TextView = window |
150 return textview.text.toString() | 151 return textview.text.toString() |
151 } | 152 } |
152 else if(window is Button) | 153 else if(window is Button) |
153 { | 154 { |
154 var button: Button = window as Button | 155 var button: Button = window |
155 return button.text.toString() | 156 return button.text.toString() |
156 } | 157 } |
157 else if(window is LinearLayout) | 158 else if(window is LinearLayout) |
158 { | 159 { |
159 // TODO: Make sure this is actually the top-level layout, not just a box | 160 // TODO: Make sure this is actually the top-level layout, not just a box |
193 if (type > 0) { | 194 if (type > 0) { |
194 box.orientation = LinearLayout.VERTICAL | 195 box.orientation = LinearLayout.VERTICAL |
195 } else { | 196 } else { |
196 box.orientation = LinearLayout.HORIZONTAL | 197 box.orientation = LinearLayout.HORIZONTAL |
197 } | 198 } |
199 box.setPadding(pad, pad, pad, pad) | |
198 return box | 200 return box |
199 } | 201 } |
200 | 202 |
201 fun boxPack(box: LinearLayout, item: View, index: Int, width: Int, height: Int, hsize: Int, vsize: Int, pad: Int) | 203 fun boxPack(box: LinearLayout, item: View, index: Int, width: Int, height: Int, hsize: Int, vsize: Int, pad: Int) |
202 { | 204 { |
286 val entryfield = EditText(this) | 288 val entryfield = EditText(this) |
287 var dataArrayMap = SimpleArrayMap<String, Long>() | 289 var dataArrayMap = SimpleArrayMap<String, Long>() |
288 | 290 |
289 entryfield.tag = dataArrayMap | 291 entryfield.tag = dataArrayMap |
290 entryfield.id = cid | 292 entryfield.id = cid |
291 if(password > 0) { | 293 if(password > 0) |
294 { | |
292 entryfield.transformationMethod = PasswordTransformationMethod.getInstance() | 295 entryfield.transformationMethod = PasswordTransformationMethod.getInstance() |
293 } | 296 } |
294 entryfield.setText(text) | 297 entryfield.setText(text) |
295 return entryfield | 298 return entryfield |
296 } | 299 } |
329 var dataArrayMap = SimpleArrayMap<String, Long>() | 332 var dataArrayMap = SimpleArrayMap<String, Long>() |
330 | 333 |
331 textview.tag = dataArrayMap | 334 textview.tag = dataArrayMap |
332 textview.id = cid | 335 textview.id = cid |
333 textview.text = text | 336 textview.text = text |
337 if(status != 0) | |
338 { | |
339 val border = GradientDrawable() | |
340 | |
341 // Set a black border on white background... | |
342 // might need to change this to invisible... | |
343 // or the color from windowSetColor | |
344 border.setColor(-0x1) | |
345 border.setStroke(1, -0x1000000) | |
346 textview.background = border | |
347 } | |
334 return textview | 348 return textview |
335 } | 349 } |
336 | 350 |
337 fun notebookNew(cid: Int, top: Int) | 351 fun notebookNew(cid: Int, top: Int) |
338 { | 352 { |
351 }.attach() | 365 }.attach() |
352 | 366 |
353 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) | 367 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) |
354 tabs.layoutParams = params | 368 tabs.layoutParams = params |
355 notebook.addView(tabs) | 369 notebook.addView(tabs) |
356 notebook.addView(pager) | 370 if(top != 0) { |
371 notebook.addView(pager, 0) | |
372 } else { | |
373 notebook.addView(pager) | |
374 } | |
375 } | |
376 | |
377 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer | |
378 { | |
379 // creating timer task, timer | |
380 val t = Timer() | |
381 val tt: TimerTask = object : TimerTask() { | |
382 override fun run() { | |
383 if(eventHandlerTimer(sigfunc, data) == 0) { | |
384 t.cancel() | |
385 } | |
386 } | |
387 } | |
388 t.scheduleAtFixedRate(tt, interval, interval) | |
389 return t | |
390 } | |
391 | |
392 fun timerDisconnect(timer: Timer) | |
393 { | |
394 timer.cancel() | |
395 } | |
396 | |
397 fun doBeep(duration: Int) | |
398 { | |
399 val toneGen = ToneGenerator(AudioManager.STREAM_MUSIC, 100) | |
400 toneGen.startTone(ToneGenerator.TONE_CDMA_PIP, duration) | |
357 } | 401 } |
358 | 402 |
359 fun debugMessage(text: String) | 403 fun debugMessage(text: String) |
360 { | 404 { |
361 Log.d(null, text) | 405 Log.d(null, text) |
413 * which is packaged with this application. | 457 * which is packaged with this application. |
414 */ | 458 */ |
415 external fun dwindowsInit(dataDir: String): String | 459 external fun dwindowsInit(dataDir: String): String |
416 external fun eventHandler(obj1: View, obj2: View?, message: Int, str1: String?, str2: String?, int1: Int, int2: Int, int3: Int, int4: Int): Int | 460 external fun eventHandler(obj1: View, obj2: View?, message: Int, str1: String?, str2: String?, int1: Int, int2: Int, int3: Int, int4: Int): Int |
417 external fun eventHandlerSimple(obj1: View, message: Int) | 461 external fun eventHandlerSimple(obj1: View, message: Int) |
462 external fun eventHandlerTimer(sigfunc: Long, data: Long): Int | |
418 | 463 |
419 companion object | 464 companion object |
420 { | 465 { |
421 // Used to load the 'dwindows' library on application startup. | 466 // Used to load the 'dwindows' library on application startup. |
422 init | 467 init |