comparison android/DWindows.kt @ 2498:4ae2b3b77f25

Android: Get the notebook control functional. Disable recylcing of the views. Even though we are using the RecylerView we don't actually want the views recycled. Attempt to prevent the activity from restarting immediately in the simulator by enabling the required options in the AndroidManifest.xml. This didn't work so I am putting that ugly workaround back in, since in the simulator we get called twice and we want to actually run dwmain() on the second call in the simulator.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 05 May 2021 09:15:08 +0000
parents 7b210f156eef
children ff3310fa6d72
comparison
equal deleted inserted replaced
2497:7b210f156eef 2498:4ae2b3b77f25
21 import android.widget.* 21 import android.widget.*
22 import android.widget.SeekBar.OnSeekBarChangeListener 22 import android.widget.SeekBar.OnSeekBarChangeListener
23 import androidx.appcompat.app.AlertDialog 23 import androidx.appcompat.app.AlertDialog
24 import androidx.appcompat.app.AppCompatActivity 24 import androidx.appcompat.app.AppCompatActivity
25 import androidx.collection.SimpleArrayMap 25 import androidx.collection.SimpleArrayMap
26 import androidx.core.view.marginStart
27 import androidx.recyclerview.widget.RecyclerView 26 import androidx.recyclerview.widget.RecyclerView
28 import androidx.viewpager2.widget.ViewPager2 27 import androidx.viewpager2.widget.ViewPager2
29 import com.google.android.material.tabs.TabLayout 28 import com.google.android.material.tabs.TabLayout
30 import com.google.android.material.tabs.TabLayout.OnTabSelectedListener 29 import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
31 import com.google.android.material.tabs.TabLayoutMediator 30 import com.google.android.material.tabs.TabLayoutMediator
36 public val viewList = mutableListOf<LinearLayout>() 35 public val viewList = mutableListOf<LinearLayout>()
37 public val pageList = mutableListOf<Long>() 36 public val pageList = mutableListOf<Long>()
38 public var currentPageID = 0L 37 public var currentPageID = 0L
39 38
40 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = 39 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
41 DWEventViewHolder(viewList.get(0)) 40 DWEventViewHolder(viewList.get(viewType))
42 41
43 override fun getItemCount() = viewList.count() 42 override fun getItemCount() = viewList.count()
43 override fun getItemViewType(position: Int): Int {
44 return position
45 }
44 override fun onBindViewHolder(holder: DWEventViewHolder, position: Int) { 46 override fun onBindViewHolder(holder: DWEventViewHolder, position: Int) {
45 //(holder.view as? TextView)?.also{ 47 holder.setIsRecyclable(false);
46 // it.text = "Page " + eventList.get(position) 48 }
47 //} 49
48 } 50 class DWEventViewHolder(var view: View) : RecyclerView.ViewHolder(view)
49
50 class DWEventViewHolder(val view: View) : RecyclerView.ViewHolder(view)
51 } 51 }
52 52
53 class DWindows : AppCompatActivity() { 53 class DWindows : AppCompatActivity() {
54 var firstWindow: Boolean = true 54 var firstWindow: Boolean = true
55 55
56 // We only want to call this once when the app starts up
57 // By default Android will call onCreate for rotation and other
58 // changes. This is incompatible with Dynamic Windows...
59 // Make sure the following is in your AndroidManifest.xml
60 // android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
56 override fun onCreate(savedInstanceState: Bundle?) { 61 override fun onCreate(savedInstanceState: Bundle?) {
57 super.onCreate(savedInstanceState) 62 super.onCreate(savedInstanceState)
58 63
59 // Turn on rotation 64 // Turn on rotation
60 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR) 65 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR)
61 66
62 // We only want to call this once when the app starts up 67 // Get the Android app path
63 // By default Android will call onCreate for rotation and other 68 val m = packageManager
64 // changes. This is incompatible with Dynamic Windows... 69 var s = packageName
65 // Make sure the following is in your AndroidManifest.xml 70 val p = m.getPackageInfo(s!!, 0)
66 // android:configChanges="orientation|screenSize|screenLayout|keyboardHidden" 71 s = p.applicationInfo.dataDir
67 if(savedInstanceState == null) { 72
68 // Get the Android app path 73 // Initialize the Dynamic Windows code...
69 val m = packageManager 74 // This will start a new thread that calls the app's dwmain()
70 var s = packageName 75 dwindowsInit(s)
71 val p = m.getPackageInfo(s!!, 0)
72 s = p.applicationInfo.dataDir
73
74 // Initialize the Dynamic Windows code...
75 // This will start a new thread that calls the app's dwmain()
76 dwindowsInit(s)
77 }
78 } 76 }
79 77
80 override fun onConfigurationChanged(newConfig: Configuration) { 78 override fun onConfigurationChanged(newConfig: Configuration) {
81 super.onConfigurationChanged(newConfig) 79 super.onConfigurationChanged(newConfig)
82 80
397 notebook.id = cid 395 notebook.id = cid
398 tabs.id = View.generateViewId() 396 tabs.id = View.generateViewId()
399 pager.id = View.generateViewId() 397 pager.id = View.generateViewId()
400 pager.adapter = DWTabViewPagerAdapter() 398 pager.adapter = DWTabViewPagerAdapter()
401 TabLayoutMediator(tabs, pager) { tab, position -> 399 TabLayoutMediator(tabs, pager) { tab, position ->
402 //tab.text = "OBJECT ${(position + 1)}" 400 // This code never gets called?
403 }.attach() 401 }.attach()
404 402
405 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) 403 var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h)
406 if(top != 0) { 404 if(top != 0) {
407 params.addRule(RelativeLayout.ALIGN_PARENT_TOP) 405 params.addRule(RelativeLayout.ALIGN_PARENT_TOP)