Mercurial > dwindows
comparison android/DWindows.kt @ 2493:bca7e0ab0ccc
Android: Work on the notebook control, doesn't work yet but everything filled in.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 02 May 2021 01:05:20 +0000 |
parents | e2ca6c1a4661 |
children | b3e28eed0e50 |
comparison
equal
deleted
inserted
replaced
2492:e2ca6c1a4661 | 2493:bca7e0ab0ccc |
---|---|
28 import com.google.android.material.tabs.TabLayout | 28 import com.google.android.material.tabs.TabLayout |
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 TabViewPagerAdapter : RecyclerView.Adapter<TabViewPagerAdapter.EventViewHolder>() { | 33 class DWTabViewPagerAdapter : RecyclerView.Adapter<DWTabViewPagerAdapter.EventViewHolder>() { |
34 val eventList = listOf("0", "1", "2") | 34 public val viewList = mutableListOf<LinearLayout>() |
35 | 35 |
36 // Layout "layout_demo_viewpager2_cell.xml" will be defined later | |
37 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = | 36 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = |
38 EventViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.dwindows_main, parent, false)) | 37 EventViewHolder(viewList.get(0)) |
39 | 38 |
40 override fun getItemCount() = eventList.count() | 39 override fun getItemCount() = viewList.count() |
41 override fun onBindViewHolder(holder: EventViewHolder, position: Int) { | 40 override fun onBindViewHolder(holder: EventViewHolder, position: Int) { |
42 (holder.view as? TextView)?.also{ | 41 //(holder.view as? TextView)?.also{ |
43 it.text = "Page " + eventList.get(position) | 42 // it.text = "Page " + eventList.get(position) |
44 } | 43 //} |
45 } | 44 } |
46 | 45 |
47 class EventViewHolder(val view: View) : RecyclerView.ViewHolder(view) | 46 class EventViewHolder(val view: View) : RecyclerView.ViewHolder(view) |
48 } | 47 } |
49 | 48 |
351 textview.background = border | 350 textview.background = border |
352 } | 351 } |
353 return textview | 352 return textview |
354 } | 353 } |
355 | 354 |
356 fun notebookNew(cid: Int, top: Int) { | 355 fun notebookNew(cid: Int, top: Int): RelativeLayout { |
357 val notebook = RelativeLayout(this) | 356 val notebook = RelativeLayout(this) |
358 val pager = ViewPager2(this) | 357 val pager = ViewPager2(this) |
359 val tabs = TabLayout(this) | 358 val tabs = TabLayout(this) |
360 var w: Int = RelativeLayout.LayoutParams.MATCH_PARENT | 359 var w: Int = RelativeLayout.LayoutParams.MATCH_PARENT |
361 var h: Int = RelativeLayout.LayoutParams.WRAP_CONTENT | 360 var h: Int = RelativeLayout.LayoutParams.WRAP_CONTENT |
362 var dataArrayMap = SimpleArrayMap<String, Long>() | 361 var dataArrayMap = SimpleArrayMap<String, Long>() |
363 | 362 |
364 notebook.tag = dataArrayMap | 363 notebook.tag = dataArrayMap |
365 notebook.id = cid | 364 notebook.id = cid |
366 pager.adapter = TabViewPagerAdapter() | 365 pager.adapter = DWTabViewPagerAdapter() |
367 TabLayoutMediator(tabs, pager) { tab, position -> | 366 TabLayoutMediator(tabs, pager) { tab, position -> |
368 tab.text = "OBJECT ${(position + 1)}" | 367 tab.text = "OBJECT ${(position + 1)}" |
369 }.attach() | 368 }.attach() |
370 | 369 |
371 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) | 370 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) |
373 notebook.addView(tabs) | 372 notebook.addView(tabs) |
374 if (top != 0) { | 373 if (top != 0) { |
375 notebook.addView(pager, 0) | 374 notebook.addView(pager, 0) |
376 } else { | 375 } else { |
377 notebook.addView(pager) | 376 notebook.addView(pager) |
377 } | |
378 return notebook | |
379 } | |
380 | |
381 fun notebookPageNew(notebook: RelativeLayout, flags: Long, front: Int): Any? | |
382 { | |
383 var pager: ViewPager2? = null | |
384 var tabs: TabLayout? = null | |
385 var tab: Any? = null | |
386 | |
387 if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { | |
388 pager = notebook.getChildAt(0) as ViewPager2 | |
389 tabs = notebook.getChildAt(1) as TabLayout | |
390 } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { | |
391 pager = notebook.getChildAt(1) as ViewPager2 | |
392 tabs = notebook.getChildAt(0) as TabLayout | |
393 } | |
394 | |
395 if(pager != null && tabs != null) { | |
396 var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter | |
397 | |
398 tab = tabs.newTab() | |
399 // Temporarily add a black tab with an empty layout/box | |
400 if(front != 0) { | |
401 adapter.viewList.add(0, LinearLayout(this)) | |
402 tabs.addTab(tab, 0) | |
403 } else { | |
404 adapter.viewList.add(LinearLayout(this)) | |
405 tabs.addTab(tab) | |
406 } | |
407 } | |
408 return tab | |
409 } | |
410 | |
411 fun notebookPageDestroy(notebook: RelativeLayout, tab: TabLayout.Tab) | |
412 { | |
413 var pager: ViewPager2? = null | |
414 var tabs: TabLayout? = null | |
415 | |
416 if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { | |
417 pager = notebook.getChildAt(0) as ViewPager2 | |
418 tabs = notebook.getChildAt(1) as TabLayout | |
419 } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { | |
420 pager = notebook.getChildAt(1) as ViewPager2 | |
421 tabs = notebook.getChildAt(0) as TabLayout | |
422 } | |
423 | |
424 if(pager != null && tabs != null) { | |
425 var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter | |
426 | |
427 adapter.viewList.removeAt(tab.position) | |
428 tabs.removeTab(tab) | |
429 } | |
430 } | |
431 | |
432 fun notebookPageSetText(notebook: RelativeLayout, tab: TabLayout.Tab, text: String) | |
433 { | |
434 var pager: ViewPager2? = null | |
435 var tabs: TabLayout? = null | |
436 | |
437 if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { | |
438 pager = notebook.getChildAt(0) as ViewPager2 | |
439 tabs = notebook.getChildAt(1) as TabLayout | |
440 } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { | |
441 pager = notebook.getChildAt(1) as ViewPager2 | |
442 tabs = notebook.getChildAt(0) as TabLayout | |
443 } | |
444 | |
445 if(pager != null && tabs != null) { | |
446 tab.text = text | |
447 } | |
448 } | |
449 | |
450 fun notebookPack(notebook: RelativeLayout, tab: TabLayout.Tab, box: LinearLayout) | |
451 { | |
452 var pager: ViewPager2? = null | |
453 var tabs: TabLayout? = null | |
454 | |
455 if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { | |
456 pager = notebook.getChildAt(0) as ViewPager2 | |
457 tabs = notebook.getChildAt(1) as TabLayout | |
458 } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { | |
459 pager = notebook.getChildAt(1) as ViewPager2 | |
460 tabs = notebook.getChildAt(0) as TabLayout | |
461 } | |
462 | |
463 if(pager != null && tabs != null) { | |
464 var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter | |
465 | |
466 adapter.viewList[tab.position] = box | |
467 } | |
468 } | |
469 | |
470 fun notebookPageGet(notebook: RelativeLayout): TabLayout.Tab? | |
471 { | |
472 var pager: ViewPager2? = null | |
473 var tabs: TabLayout? = null | |
474 | |
475 if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { | |
476 pager = notebook.getChildAt(0) as ViewPager2 | |
477 tabs = notebook.getChildAt(1) as TabLayout | |
478 } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { | |
479 pager = notebook.getChildAt(1) as ViewPager2 | |
480 tabs = notebook.getChildAt(0) as TabLayout | |
481 } | |
482 | |
483 if(pager != null && tabs != null) { | |
484 return tabs.getTabAt(tabs.selectedTabPosition) | |
485 } | |
486 return null | |
487 } | |
488 | |
489 fun notebookPageSet(notebook: RelativeLayout, tab: TabLayout.Tab) | |
490 { | |
491 var pager: ViewPager2? = null | |
492 var tabs: TabLayout? = null | |
493 | |
494 if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { | |
495 pager = notebook.getChildAt(0) as ViewPager2 | |
496 tabs = notebook.getChildAt(1) as TabLayout | |
497 } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { | |
498 pager = notebook.getChildAt(1) as ViewPager2 | |
499 tabs = notebook.getChildAt(0) as TabLayout | |
500 } | |
501 | |
502 if(pager != null && tabs != null) { | |
503 tabs.selectTab(tab) | |
378 } | 504 } |
379 } | 505 } |
380 | 506 |
381 fun sliderNew(vertical: Int, increments: Int, cid: Int): SeekBar | 507 fun sliderNew(vertical: Int, increments: Int, cid: Int): SeekBar |
382 { | 508 { |