comparison android/DWindows.kt @ 2495:5664c91d03fb

Android: Attempts to sort out the various issues... still not working but... Wanted to commit so I can change locations later tonight.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 03 May 2021 01:17:40 +0000
parents b3e28eed0e50
children 3bf2f08fdc45
comparison
equal deleted inserted replaced
2494:b3e28eed0e50 2495:5664c91d03fb
13 import android.text.InputFilter 13 import android.text.InputFilter
14 import android.text.InputFilter.LengthFilter 14 import android.text.InputFilter.LengthFilter
15 import android.text.method.PasswordTransformationMethod 15 import android.text.method.PasswordTransformationMethod
16 import android.util.Log 16 import android.util.Log
17 import android.view.Gravity 17 import android.view.Gravity
18 import android.view.LayoutInflater
19 import android.view.View 18 import android.view.View
20 import android.view.ViewGroup 19 import android.view.ViewGroup
21 import android.widget.* 20 import android.widget.*
22 import android.widget.SeekBar.OnSeekBarChangeListener 21 import android.widget.SeekBar.OnSeekBarChangeListener
23 import androidx.appcompat.app.AlertDialog 22 import androidx.appcompat.app.AlertDialog
24 import androidx.appcompat.app.AppCompatActivity 23 import androidx.appcompat.app.AppCompatActivity
25 import androidx.collection.SimpleArrayMap 24 import androidx.collection.SimpleArrayMap
26 import androidx.recyclerview.widget.RecyclerView 25 import androidx.recyclerview.widget.RecyclerView
27 import androidx.viewpager2.widget.ViewPager2 26 import androidx.viewpager2.widget.ViewPager2
28 import com.google.android.material.tabs.TabLayout 27 import com.google.android.material.tabs.TabLayout
28 import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
29 import com.google.android.material.tabs.TabLayoutMediator 29 import com.google.android.material.tabs.TabLayoutMediator
30 import java.util.* 30 import java.util.*
31 31
32 32
33 class DWTabViewPagerAdapter : RecyclerView.Adapter<DWTabViewPagerAdapter.EventViewHolder>() { 33 class DWTabViewPagerAdapter : RecyclerView.Adapter<DWTabViewPagerAdapter.DWEventViewHolder>() {
34 public val viewList = mutableListOf<LinearLayout>() 34 public val viewList = mutableListOf<LinearLayout>()
35 public val pageList = mutableListOf<Long>() 35 public val pageList = mutableListOf<Long>()
36 public var currentPageID = 0L 36 public var currentPageID = 0L
37 37
38 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = 38 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
39 EventViewHolder(viewList.get(0)) 39 DWEventViewHolder(viewList.get(0))
40 40
41 override fun getItemCount() = viewList.count() 41 override fun getItemCount() = viewList.count()
42 override fun onBindViewHolder(holder: EventViewHolder, position: Int) { 42 override fun onBindViewHolder(holder: DWEventViewHolder, position: Int) {
43 //(holder.view as? TextView)?.also{ 43 //(holder.view as? TextView)?.also{
44 // it.text = "Page " + eventList.get(position) 44 // it.text = "Page " + eventList.get(position)
45 //} 45 //}
46 } 46 }
47 47
48 class EventViewHolder(val view: View) : RecyclerView.ViewHolder(view) 48 class DWEventViewHolder(val view: View) : RecyclerView.ViewHolder(view)
49 } 49 }
50 50
51 class DWindows : AppCompatActivity() { 51 class DWindows : AppCompatActivity() {
52 var firstWindow: Boolean = true 52 var firstWindow: Boolean = true
53 53
167 val box = LinearLayout(this) 167 val box = LinearLayout(this)
168 var dataArrayMap = SimpleArrayMap<String, Long>() 168 var dataArrayMap = SimpleArrayMap<String, Long>()
169 169
170 box.tag = dataArrayMap 170 box.tag = dataArrayMap
171 box.layoutParams = 171 box.layoutParams =
172 LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT) 172 LinearLayout.LayoutParams(
173 LinearLayout.LayoutParams.WRAP_CONTENT,
174 LinearLayout.LayoutParams.WRAP_CONTENT
175 )
173 if (type > 0) { 176 if (type > 0) {
174 box.orientation = LinearLayout.VERTICAL 177 box.orientation = LinearLayout.VERTICAL
175 } else { 178 } else {
176 box.orientation = LinearLayout.HORIZONTAL 179 box.orientation = LinearLayout.HORIZONTAL
177 } 180 }
178 box.setPadding(pad, pad, pad, pad) 181 box.setPadding(pad, pad, pad, pad)
179 return box 182 return box
180 } 183 }
181 184
182 fun boxPack(box: LinearLayout, item: View, index: Int, width: Int, height: Int, hsize: Int, vsize: Int, pad: Int) { 185 fun boxPack(
186 box: LinearLayout,
187 item: View,
188 index: Int,
189 width: Int,
190 height: Int,
191 hsize: Int,
192 vsize: Int,
193 pad: Int
194 ) {
183 var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT 195 var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT
184 var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT 196 var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT
185 197
186 if (item is LinearLayout) { 198 if (item is LinearLayout) {
187 if (box.orientation == LinearLayout.VERTICAL) { 199 if (box.orientation == LinearLayout.VERTICAL) {
247 } 259 }
248 260
249 fun boxUnpackAtIndex(box: LinearLayout, index: Int): View? { 261 fun boxUnpackAtIndex(box: LinearLayout, index: Int): View? {
250 var item: View = box.getChildAt(index) 262 var item: View = box.getChildAt(index)
251 263
252 if (item != null) { 264 box.removeView(item)
253 box.removeView(item)
254 }
255 return item 265 return item
256 } 266 }
257 267
258 fun buttonNew(text: String, cid: Int): Button { 268 fun buttonNew(text: String, cid: Int): Button {
259 val button = Button(this) 269 val button = Button(this)
352 textview.background = border 362 textview.background = border
353 } 363 }
354 return textview 364 return textview
355 } 365 }
356 366
357 fun notebookNew(cid: Int, top: Int): RelativeLayout { 367 fun notebookNew(cid: Int, top: Int): RelativeLayout
368 {
358 val notebook = RelativeLayout(this) 369 val notebook = RelativeLayout(this)
359 val pager = ViewPager2(this) 370 val pager = ViewPager2(this)
360 val tabs = TabLayout(this) 371 val tabs = TabLayout(this)
361 var w: Int = RelativeLayout.LayoutParams.MATCH_PARENT 372 var w: Int = RelativeLayout.LayoutParams.MATCH_PARENT
362 var h: Int = RelativeLayout.LayoutParams.WRAP_CONTENT 373 var h: Int = RelativeLayout.LayoutParams.WRAP_CONTENT
365 notebook.tag = dataArrayMap 376 notebook.tag = dataArrayMap
366 notebook.id = cid 377 notebook.id = cid
367 tabs.id = View.generateViewId() 378 tabs.id = View.generateViewId()
368 pager.id = View.generateViewId() 379 pager.id = View.generateViewId()
369 pager.adapter = DWTabViewPagerAdapter() 380 pager.adapter = DWTabViewPagerAdapter()
370 TabLayoutMediator(tabs, pager) { tab, position ->
371 //tab.text = "OBJECT ${(position + 1)}"
372 }.attach()
373 381
374 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) 382 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h)
375 if(top != 0) { 383 if(top != 0) {
376 params.addRule(RelativeLayout.ABOVE, pager.id) 384 params.addRule(RelativeLayout.ABOVE, pager.id)
377 } else { 385 } else {
379 } 387 }
380 tabs.tabGravity = TabLayout.GRAVITY_FILL 388 tabs.tabGravity = TabLayout.GRAVITY_FILL
381 tabs.tabMode = TabLayout.MODE_FIXED 389 tabs.tabMode = TabLayout.MODE_FIXED
382 notebook.addView(tabs, params) 390 notebook.addView(tabs, params)
383 notebook.addView(pager, RelativeLayout.LayoutParams(w, w)) 391 notebook.addView(pager, RelativeLayout.LayoutParams(w, w))
392 tabs.addOnTabSelectedListener(object : OnTabSelectedListener {
393 override fun onTabSelected(tab: TabLayout.Tab) {
394 val adapter = pager.adapter as DWTabViewPagerAdapter
395
396 pager.currentItem = tab.position
397 eventHandlerNotebook(notebook, 15, adapter.pageList[tab.position])
398 }
399 override fun onTabUnselected(tab: TabLayout.Tab) {}
400 override fun onTabReselected(tab: TabLayout.Tab) {}
401 })
384 return notebook 402 return notebook
385 } 403 }
386 404
387 fun notebookPageNew(notebook: RelativeLayout, flags: Long, front: Int): Long 405 fun notebookPageNew(notebook: RelativeLayout, flags: Long, front: Int): Long
388 { 406 {
488 if(pager != null && tabs != null) { 506 if(pager != null && tabs != null) {
489 var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter 507 var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter
490 val index = adapter.pageList.indexOf(pageID) 508 val index = adapter.pageList.indexOf(pageID)
491 509
492 // Make sure the box is MATCH_PARENT 510 // Make sure the box is MATCH_PARENT
493 box.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 511 box.layoutParams = LinearLayout.LayoutParams(
494 LinearLayout.LayoutParams.MATCH_PARENT); 512 LinearLayout.LayoutParams.MATCH_PARENT,
513 LinearLayout.LayoutParams.MATCH_PARENT
514 );
495 515
496 adapter.viewList[index] = box 516 adapter.viewList[index] = box
497 } 517 }
498 } 518 }
499 519
551 slider.rotation = 270F 571 slider.rotation = 270F
552 } 572 }
553 slider.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { 573 slider.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
554 override fun onStopTrackingTouch(seekBar: SeekBar) { 574 override fun onStopTrackingTouch(seekBar: SeekBar) {
555 } 575 }
576
556 override fun onStartTrackingTouch(seekBar: SeekBar) { 577 override fun onStartTrackingTouch(seekBar: SeekBar) {
557 } 578 }
579
558 override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { 580 override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
559 eventHandler(slider, null, 14, null, null, slider.progress, 0, 0, 0) 581 eventHandler(slider, null, 14, null, null, slider.progress, 0, 0, 0)
560 } 582 }
561 }) 583 })
562 return slider 584 return slider
630 var retval: Int = 0 652 var retval: Int = 0
631 653
632 alert.setTitle(title) 654 alert.setTitle(title)
633 alert.setMessage(body) 655 alert.setMessage(body)
634 if((flags and (1 shl 3)) != 0) { 656 if((flags and (1 shl 3)) != 0) {
635 alert.setPositiveButton("Yes", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> 657 alert.setPositiveButton(
636 retval = 1 658 "Yes",
637 throw java.lang.RuntimeException() 659 DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
638 }); 660 retval = 1
661 throw java.lang.RuntimeException()
662 });
639 } 663 }
640 if((flags and ((1 shl 1) or (1 shl 2))) != 0) { 664 if((flags and ((1 shl 1) or (1 shl 2))) != 0) {
641 alert.setNegativeButton("Ok", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> 665 alert.setNegativeButton(
642 retval = 0 666 "Ok",
643 throw java.lang.RuntimeException() 667 DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
644 }); 668 retval = 0
669 throw java.lang.RuntimeException()
670 });
645 } 671 }
646 if((flags and ((1 shl 3) or (1 shl 4))) != 0) { 672 if((flags and ((1 shl 3) or (1 shl 4))) != 0) {
647 alert.setNegativeButton("No", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> 673 alert.setNegativeButton(
648 retval = 0 674 "No",
649 throw java.lang.RuntimeException() 675 DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
650 }); 676 retval = 0
677 throw java.lang.RuntimeException()
678 });
651 } 679 }
652 if((flags and ((1 shl 2) or (1 shl 4))) != 0) { 680 if((flags and ((1 shl 2) or (1 shl 4))) != 0) {
653 alert.setNeutralButton("Cancel", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> 681 alert.setNeutralButton(
654 retval = 2 682 "Cancel",
655 throw java.lang.RuntimeException() 683 DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
656 }); 684 retval = 2
685 throw java.lang.RuntimeException()
686 });
657 } 687 }
658 alert.show(); 688 alert.show();
659 689
660 // loop till a runtime exception is triggered. 690 // loop till a runtime exception is triggered.
661 try { 691 try {
679 /* 709 /*
680 * Native methods that are implemented by the 'dwindows' native library, 710 * Native methods that are implemented by the 'dwindows' native library,
681 * which is packaged with this application. 711 * which is packaged with this application.
682 */ 712 */
683 external fun dwindowsInit(dataDir: String) 713 external fun dwindowsInit(dataDir: String)
684 external fun eventHandler(obj1: View, obj2: View?, message: Int, str1: String?, str2: String?, int1: Int, int2: Int, int3: Int, int4: Int): Int 714 external fun eventHandler(
715 obj1: View,
716 obj2: View?,
717 message: Int,
718 str1: String?,
719 str2: String?,
720 int1: Int,
721 int2: Int,
722 int3: Int,
723 int4: Int
724 ): Int
685 external fun eventHandlerSimple(obj1: View, message: Int) 725 external fun eventHandlerSimple(obj1: View, message: Int)
726 external fun eventHandlerNotebook(obj1: View, message: Int, pageID: Long)
686 external fun eventHandlerTimer(sigfunc: Long, data: Long): Int 727 external fun eventHandlerTimer(sigfunc: Long, data: Long): Int
687 728
688 companion object 729 companion object
689 { 730 {
690 // Used to load the 'dwindows' library on application startup. 731 // Used to load the 'dwindows' library on application startup.