# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1620004660 0 # Node ID 5664c91d03fb354b9c78412dc1ad382a5eccfe41 # Parent b3e28eed0e509dec3fbf403a2845c1f09620fdcf Android: Attempts to sort out the various issues... still not working but... Wanted to commit so I can change locations later tonight. diff -r b3e28eed0e50 -r 5664c91d03fb android/DWindows.kt --- a/android/DWindows.kt Sun May 02 10:46:21 2021 +0000 +++ b/android/DWindows.kt Mon May 03 01:17:40 2021 +0000 @@ -15,7 +15,6 @@ import android.text.method.PasswordTransformationMethod import android.util.Log import android.view.Gravity -import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.* @@ -26,26 +25,27 @@ import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.widget.ViewPager2 import com.google.android.material.tabs.TabLayout +import com.google.android.material.tabs.TabLayout.OnTabSelectedListener import com.google.android.material.tabs.TabLayoutMediator import java.util.* -class DWTabViewPagerAdapter : RecyclerView.Adapter() { +class DWTabViewPagerAdapter : RecyclerView.Adapter() { public val viewList = mutableListOf() public val pageList = mutableListOf() public var currentPageID = 0L override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = - EventViewHolder(viewList.get(0)) + DWEventViewHolder(viewList.get(0)) override fun getItemCount() = viewList.count() - override fun onBindViewHolder(holder: EventViewHolder, position: Int) { + override fun onBindViewHolder(holder: DWEventViewHolder, position: Int) { //(holder.view as? TextView)?.also{ // it.text = "Page " + eventList.get(position) //} } - class EventViewHolder(val view: View) : RecyclerView.ViewHolder(view) + class DWEventViewHolder(val view: View) : RecyclerView.ViewHolder(view) } class DWindows : AppCompatActivity() { @@ -169,7 +169,10 @@ box.tag = dataArrayMap box.layoutParams = - LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT) + LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ) if (type > 0) { box.orientation = LinearLayout.VERTICAL } else { @@ -179,7 +182,16 @@ return box } - fun boxPack(box: LinearLayout, item: View, index: Int, width: Int, height: Int, hsize: Int, vsize: Int, pad: Int) { + fun boxPack( + box: LinearLayout, + item: View, + index: Int, + width: Int, + height: Int, + hsize: Int, + vsize: Int, + pad: Int + ) { var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT @@ -249,9 +261,7 @@ fun boxUnpackAtIndex(box: LinearLayout, index: Int): View? { var item: View = box.getChildAt(index) - if (item != null) { - box.removeView(item) - } + box.removeView(item) return item } @@ -354,7 +364,8 @@ return textview } - fun notebookNew(cid: Int, top: Int): RelativeLayout { + fun notebookNew(cid: Int, top: Int): RelativeLayout + { val notebook = RelativeLayout(this) val pager = ViewPager2(this) val tabs = TabLayout(this) @@ -367,9 +378,6 @@ tabs.id = View.generateViewId() pager.id = View.generateViewId() pager.adapter = DWTabViewPagerAdapter() - TabLayoutMediator(tabs, pager) { tab, position -> - //tab.text = "OBJECT ${(position + 1)}" - }.attach() var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, h) if(top != 0) { @@ -381,6 +389,16 @@ tabs.tabMode = TabLayout.MODE_FIXED notebook.addView(tabs, params) notebook.addView(pager, RelativeLayout.LayoutParams(w, w)) + tabs.addOnTabSelectedListener(object : OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab) { + val adapter = pager.adapter as DWTabViewPagerAdapter + + pager.currentItem = tab.position + eventHandlerNotebook(notebook, 15, adapter.pageList[tab.position]) + } + override fun onTabUnselected(tab: TabLayout.Tab) {} + override fun onTabReselected(tab: TabLayout.Tab) {} + }) return notebook } @@ -490,8 +508,10 @@ val index = adapter.pageList.indexOf(pageID) // Make sure the box is MATCH_PARENT - box.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, - LinearLayout.LayoutParams.MATCH_PARENT); + box.layoutParams = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.MATCH_PARENT + ); adapter.viewList[index] = box } @@ -553,8 +573,10 @@ slider.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { override fun onStopTrackingTouch(seekBar: SeekBar) { } + override fun onStartTrackingTouch(seekBar: SeekBar) { } + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { eventHandler(slider, null, 14, null, null, slider.progress, 0, 0, 0) } @@ -632,28 +654,36 @@ alert.setTitle(title) alert.setMessage(body) if((flags and (1 shl 3)) != 0) { - alert.setPositiveButton("Yes", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> - retval = 1 - throw java.lang.RuntimeException() - }); + alert.setPositiveButton( + "Yes", + DialogInterface.OnClickListener { _: DialogInterface, _: Int -> + retval = 1 + throw java.lang.RuntimeException() + }); } if((flags and ((1 shl 1) or (1 shl 2))) != 0) { - alert.setNegativeButton("Ok", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> - retval = 0 - throw java.lang.RuntimeException() - }); + alert.setNegativeButton( + "Ok", + DialogInterface.OnClickListener { _: DialogInterface, _: Int -> + retval = 0 + throw java.lang.RuntimeException() + }); } if((flags and ((1 shl 3) or (1 shl 4))) != 0) { - alert.setNegativeButton("No", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> - retval = 0 - throw java.lang.RuntimeException() - }); + alert.setNegativeButton( + "No", + DialogInterface.OnClickListener { _: DialogInterface, _: Int -> + retval = 0 + throw java.lang.RuntimeException() + }); } if((flags and ((1 shl 2) or (1 shl 4))) != 0) { - alert.setNeutralButton("Cancel", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> - retval = 2 - throw java.lang.RuntimeException() - }); + alert.setNeutralButton( + "Cancel", + DialogInterface.OnClickListener { _: DialogInterface, _: Int -> + retval = 2 + throw java.lang.RuntimeException() + }); } alert.show(); @@ -681,8 +711,19 @@ * which is packaged with this application. */ external fun dwindowsInit(dataDir: String) - external fun eventHandler(obj1: View, obj2: View?, message: Int, str1: String?, str2: String?, int1: Int, int2: Int, int3: Int, int4: Int): Int + external fun eventHandler( + obj1: View, + obj2: View?, + message: Int, + str1: String?, + str2: String?, + int1: Int, + int2: Int, + int3: Int, + int4: Int + ): Int external fun eventHandlerSimple(obj1: View, message: Int) + external fun eventHandlerNotebook(obj1: View, message: Int, pageID: Long) external fun eventHandlerTimer(sigfunc: Long, data: Long): Int companion object diff -r b3e28eed0e50 -r 5664c91d03fb android/dw.cpp --- a/android/dw.cpp Sun May 02 10:46:21 2021 +0000 +++ b/android/dw.cpp Mon May 03 01:17:40 2021 +0000 @@ -89,8 +89,15 @@ { static int runcount = 0; - /* Safety check to prevent multiple initializations */ + /* Safety check to prevent multiple initializations... + * In the simulator I get multiple calls, and code only works on the second call. + * On actual hardware we only get called once... so this works around that. + */ +#if defined(__arm__) || defined(__aarch64__) + if(runcount == 0) +#else if(runcount == 1) +#endif { char *arg = strdup(env->GetStringUTFChars((jstring) path, NULL)); @@ -303,9 +310,9 @@ case 15: { int (* API switchpagefunc)(HWND, unsigned long, void *) = (int (* API)(HWND, unsigned long, void *))handler->signalfunction; - int pageid = DW_POINTER_TO_INT(params[3]); - - return switchpagefunc(handler->window, pageid, handler->data); + unsigned long pageID = DW_POINTER_TO_INT(params[3]); + + return switchpagefunc(handler->window, pageID, handler->data); } /* Tree expand event */ case 16: @@ -367,6 +374,15 @@ _dw_event_handler(obj1, params, message); } +/* A more simple method for quicker calls */ +JNIEXPORT void JNICALL +Java_org_dbsoft_dwindows_DWindows_eventHandlerNotebook(JNIEnv* env, jobject obj, jobject obj1, jint message, jlong pageID) { + void *params[8] = { NULL }; + + params[3] = DW_INT_TO_POINTER(pageID); + _dw_event_handler(obj1, params, message); +} + /* Handler for Timer events */ JNIEXPORT jint JNICALL Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) { @@ -814,9 +830,10 @@ * Returns: * A handle to a scrollbox or NULL on failure. */ -HWND API dw_scrollbox_new( int type, int pad ) -{ - return 0; +HWND API dw_scrollbox_new(int type, int pad) +{ + /* TODO: Just create a normal box for now */ + return dw_box_new(type, pad); } /*