# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1619917520 0 # Node ID bca7e0ab0ccc9feab7156540da1ebb27ada758a4 # Parent e2ca6c1a4661682387f8f79847fed5d90952bf96 Android: Work on the notebook control, doesn't work yet but everything filled in. diff -r e2ca6c1a4661 -r bca7e0ab0ccc android/DWindows.kt --- a/android/DWindows.kt Sat May 01 00:41:53 2021 +0000 +++ b/android/DWindows.kt Sun May 02 01:05:20 2021 +0000 @@ -30,18 +30,17 @@ import java.util.* -class TabViewPagerAdapter : RecyclerView.Adapter() { - val eventList = listOf("0", "1", "2") +class DWTabViewPagerAdapter : RecyclerView.Adapter() { + public val viewList = mutableListOf() - // Layout "layout_demo_viewpager2_cell.xml" will be defined later override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = - EventViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.dwindows_main, parent, false)) + EventViewHolder(viewList.get(0)) - override fun getItemCount() = eventList.count() + override fun getItemCount() = viewList.count() override fun onBindViewHolder(holder: EventViewHolder, position: Int) { - (holder.view as? TextView)?.also{ - it.text = "Page " + eventList.get(position) - } + //(holder.view as? TextView)?.also{ + // it.text = "Page " + eventList.get(position) + //} } class EventViewHolder(val view: View) : RecyclerView.ViewHolder(view) @@ -353,7 +352,7 @@ return textview } - fun notebookNew(cid: Int, top: Int) { + fun notebookNew(cid: Int, top: Int): RelativeLayout { val notebook = RelativeLayout(this) val pager = ViewPager2(this) val tabs = TabLayout(this) @@ -363,7 +362,7 @@ notebook.tag = dataArrayMap notebook.id = cid - pager.adapter = TabViewPagerAdapter() + pager.adapter = DWTabViewPagerAdapter() TabLayoutMediator(tabs, pager) { tab, position -> tab.text = "OBJECT ${(position + 1)}" }.attach() @@ -376,6 +375,133 @@ } else { notebook.addView(pager) } + return notebook + } + + fun notebookPageNew(notebook: RelativeLayout, flags: Long, front: Int): Any? + { + var pager: ViewPager2? = null + var tabs: TabLayout? = null + var tab: Any? = null + + if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { + pager = notebook.getChildAt(0) as ViewPager2 + tabs = notebook.getChildAt(1) as TabLayout + } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { + pager = notebook.getChildAt(1) as ViewPager2 + tabs = notebook.getChildAt(0) as TabLayout + } + + if(pager != null && tabs != null) { + var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter + + tab = tabs.newTab() + // Temporarily add a black tab with an empty layout/box + if(front != 0) { + adapter.viewList.add(0, LinearLayout(this)) + tabs.addTab(tab, 0) + } else { + adapter.viewList.add(LinearLayout(this)) + tabs.addTab(tab) + } + } + return tab + } + + fun notebookPageDestroy(notebook: RelativeLayout, tab: TabLayout.Tab) + { + var pager: ViewPager2? = null + var tabs: TabLayout? = null + + if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { + pager = notebook.getChildAt(0) as ViewPager2 + tabs = notebook.getChildAt(1) as TabLayout + } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { + pager = notebook.getChildAt(1) as ViewPager2 + tabs = notebook.getChildAt(0) as TabLayout + } + + if(pager != null && tabs != null) { + var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter + + adapter.viewList.removeAt(tab.position) + tabs.removeTab(tab) + } + } + + fun notebookPageSetText(notebook: RelativeLayout, tab: TabLayout.Tab, text: String) + { + var pager: ViewPager2? = null + var tabs: TabLayout? = null + + if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { + pager = notebook.getChildAt(0) as ViewPager2 + tabs = notebook.getChildAt(1) as TabLayout + } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { + pager = notebook.getChildAt(1) as ViewPager2 + tabs = notebook.getChildAt(0) as TabLayout + } + + if(pager != null && tabs != null) { + tab.text = text + } + } + + fun notebookPack(notebook: RelativeLayout, tab: TabLayout.Tab, box: LinearLayout) + { + var pager: ViewPager2? = null + var tabs: TabLayout? = null + + if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { + pager = notebook.getChildAt(0) as ViewPager2 + tabs = notebook.getChildAt(1) as TabLayout + } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { + pager = notebook.getChildAt(1) as ViewPager2 + tabs = notebook.getChildAt(0) as TabLayout + } + + if(pager != null && tabs != null) { + var adapter: DWTabViewPagerAdapter = pager.adapter as DWTabViewPagerAdapter + + adapter.viewList[tab.position] = box + } + } + + fun notebookPageGet(notebook: RelativeLayout): TabLayout.Tab? + { + var pager: ViewPager2? = null + var tabs: TabLayout? = null + + if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { + pager = notebook.getChildAt(0) as ViewPager2 + tabs = notebook.getChildAt(1) as TabLayout + } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { + pager = notebook.getChildAt(1) as ViewPager2 + tabs = notebook.getChildAt(0) as TabLayout + } + + if(pager != null && tabs != null) { + return tabs.getTabAt(tabs.selectedTabPosition) + } + return null + } + + fun notebookPageSet(notebook: RelativeLayout, tab: TabLayout.Tab) + { + var pager: ViewPager2? = null + var tabs: TabLayout? = null + + if(notebook.getChildAt(0) is ViewPager2 && notebook.getChildAt(1) is TabLayout) { + pager = notebook.getChildAt(0) as ViewPager2 + tabs = notebook.getChildAt(1) as TabLayout + } else if(notebook.getChildAt(1) is ViewPager2 && notebook.getChildAt(0) is TabLayout) { + pager = notebook.getChildAt(1) as ViewPager2 + tabs = notebook.getChildAt(0) as TabLayout + } + + if(pager != null && tabs != null) { + tabs.selectTab(tab) + } } fun sliderNew(vertical: Int, increments: Int, cid: Int): SeekBar diff -r e2ca6c1a4661 -r bca7e0ab0ccc android/dw.cpp --- a/android/dw.cpp Sat May 01 00:41:53 2021 +0000 +++ b/android/dw.cpp Sun May 02 01:05:20 2021 +0000 @@ -2933,6 +2933,19 @@ */ HWND API dw_notebook_new(ULONG cid, int top) { + JNIEnv *env; + + if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID notebookNew = env->GetMethodID(clazz, "notebookNew", + "(II)Landroid/widget/RelativeLayout;"); + // Call the method on the object + jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, notebookNew, (int)cid, top)); + return result; + } return 0; } @@ -2947,7 +2960,20 @@ */ unsigned long API dw_notebook_page_new(HWND handle, ULONG flags, int front) { - return 0; + JNIEnv *env; + unsigned long result = 0; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID notebookPageNew = env->GetMethodID(clazz, "notebookPageNew", + "(Landroid/widget/RelativeLayout;JI)Ljava/lang/Object;"); + // Call the method on the object + result = DW_POINTER_TO_INT(env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, notebookPageNew, handle, (jlong)flags, front))); + } + return result; } /* @@ -2958,6 +2984,23 @@ */ void API dw_notebook_page_destroy(HWND handle, unsigned int pageid) { + JNIEnv *env; + + if(handle && pageid && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + jobject tab = (jobject)DW_INT_TO_POINTER(pageid); + + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID notebookPageDestroy = env->GetMethodID(clazz, "notebookPageDestroy", + "(Landroid/widget/RelativeLayout;Lcom/google/android/material/tabs/TabLayout/Tab;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, notebookPageDestroy, handle, tab); + + // Release the global reference + env->DeleteWeakGlobalRef(tab); + } } /* @@ -2969,7 +3012,19 @@ */ unsigned long API dw_notebook_page_get(HWND handle) { - return 0; + JNIEnv *env; + unsigned long result = 0; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID notebookPageGet = env->GetMethodID(clazz, "notebookPageGet", + "(Landroid/widget/RelativeLayout;)Lcom/google/android/material/tabs/TabLayout/Tab;"); + // Call the method on the object + result = DW_POINTER_TO_INT(env->CallObjectMethod(_dw_obj, notebookPageGet, handle)); + } + return result; } /* @@ -2980,6 +3035,19 @@ */ void API dw_notebook_page_set(HWND handle, unsigned int pageid) { + JNIEnv *env; + + if(handle && pageid && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { + jobject tab = (jobject) DW_INT_TO_POINTER(pageid); + + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID notebookPageSet = env->GetMethodID(clazz, "notebookPageSet", + "(Landroid/widget/RelativeLayout;Lcom/google/android/material/tabs/TabLayout/Tab;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, notebookPageSet, handle, tab); + } } /* @@ -2991,6 +3059,22 @@ */ void API dw_notebook_page_set_text(HWND handle, ULONG pageid, const char *text) { + JNIEnv *env; + + if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + jobject tab = (jobject)DW_INT_TO_POINTER(pageid); + + // Construct a String + jstring jstr = env->NewStringUTF(text); + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID notebookPageSetText = env->GetMethodID(clazz, "notebookPageSetText", + "(Landroid/widget/RelativeLayout;Lcom/google/android/material/tabs/TabLayout/Tab;Ljava/lang/String;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, notebookPageSetText, handle, tab, jstr); + } } /* @@ -3013,6 +3097,20 @@ */ void API dw_notebook_pack(HWND handle, ULONG pageid, HWND page) { + JNIEnv *env; + + if(handle && pageid && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + jobject tab = (jobject)DW_INT_TO_POINTER(pageid); + + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID notebookPack = env->GetMethodID(clazz, "notebookPack", + "(Landroid/widget/RelativeLayout;Lcom/google/android/material/tabs/TabLayout/Tab;Landroid/widget/LinearLayout;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, notebookPack, handle, tab, page); + } } /*