Mercurial > dwindows
changeset 2499:ff3310fa6d72
Android: Implment DW_SIGNA_CONFIGURE on orientation change.
Seems like my dream of having a single C entrypoint for events
is dead, passing any NULL objects for unused parameters results
in a sementation violation. Leaving the general purpose function
in the code for now, but eventually it will go away.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 05 May 2021 19:53:33 +0000 |
parents | 4ae2b3b77f25 |
children | ac0b7e579229 |
files | android/DWindows.kt android/dw.cpp |
diffstat | 2 files changed, 36 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/android/DWindows.kt Wed May 05 09:15:08 2021 +0000 +++ b/android/DWindows.kt Wed May 05 19:53:33 2021 +0000 @@ -24,6 +24,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.collection.SimpleArrayMap import androidx.recyclerview.widget.RecyclerView +import androidx.viewpager.widget.ViewPager import androidx.viewpager2.widget.ViewPager2 import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout.OnTabSelectedListener @@ -52,6 +53,7 @@ class DWindows : AppCompatActivity() { var firstWindow: Boolean = true + var windowLayout: LinearLayout? = null // We only want to call this once when the app starts up // By default Android will call onCreate for rotation and other @@ -78,11 +80,12 @@ override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) - // Checks the orientation of the screen - if (newConfig.orientation === Configuration.ORIENTATION_LANDSCAPE) { - Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show() - } else if (newConfig.orientation === Configuration.ORIENTATION_PORTRAIT) { - Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show() + // Send a DW_SIGNAL_CONFIGURE on orientation change + if(windowLayout != null) { + var width: Int = windowLayout!!.width + var height: Int = windowLayout!!.height + + eventHandlerInt(windowLayout as View, 1, width, height, 0, 0) } } @@ -92,10 +95,10 @@ */ fun windowNew(title: String, style: Int): LinearLayout? { if (firstWindow) { - var windowLayout: LinearLayout = LinearLayout(this) var dataArrayMap = SimpleArrayMap<String, Long>() + windowLayout = LinearLayout(this) - windowLayout.tag = dataArrayMap + windowLayout!!.tag = dataArrayMap setContentView(windowLayout) this.title = title // For now we just return our DWindows' main activity layout... @@ -739,16 +742,24 @@ */ external fun dwindowsInit(dataDir: String) external fun eventHandler( - obj1: View, + obj1: View?, obj2: View?, message: Int, str1: String?, str2: String?, - int1: Int, - int2: Int, - int3: Int, - int4: Int + inta: Int, + intb: Int, + intc: Int, + intd: Int ): Int + external fun eventHandlerInt( + obj1: View, + message: Int, + inta: Int, + intb: Int, + intc: Int, + intd: 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
--- a/android/dw.cpp Wed May 05 09:15:08 2021 +0000 +++ b/android/dw.cpp Wed May 05 19:53:33 2021 +0000 @@ -353,12 +353,12 @@ JNIEXPORT jint JNICALL Java_org_dbsoft_dwindows_DWindows_eventHandler(JNIEnv* env, jobject obj, jobject obj1, jobject obj2, jint message, jstring str1, jstring str2, - jint int1, jint int2, jint int3, jint int4) { + jint inta, jint intb, jint intc, jint intd) { const char *utf81 = str1 ? env->GetStringUTFChars(str1, NULL) : NULL; const char *utf82 = str2 ? env->GetStringUTFChars(str2, NULL) : NULL; void *params[8] = { (void *)obj2, (void *)utf81, (void *)utf82, - DW_INT_TO_POINTER(int1), DW_INT_TO_POINTER(int2), - DW_INT_TO_POINTER(int3), DW_INT_TO_POINTER(int4), NULL }; + DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), + DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), NULL }; return _dw_event_handler(obj1, params, message); } @@ -380,6 +380,16 @@ _dw_event_handler(obj1, params, message); } +JNIEXPORT void JNICALL +Java_org_dbsoft_dwindows_DWindows_eventHandlerInt(JNIEnv* env, jobject obj, jobject obj1, jint message, + jint inta, jint intb, jint intc, jint intd) { + void *params[8] = { NULL, NULL, NULL, + DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), + DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), NULL }; + + _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) {