From 432f24319319fe040e142059eb83279c53f90ab8 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 9 Aug 2025 08:35:03 +0200 Subject: refactor 2 --- .../android/app/src/main/AndroidManifest.xml | 24 +++++++++++++ .../android/app/src/main/java/MainActivity.kt | 40 ++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 libs/imgui-1.92.1/examples/example_android_opengl3/android/app/src/main/AndroidManifest.xml create mode 100644 libs/imgui-1.92.1/examples/example_android_opengl3/android/app/src/main/java/MainActivity.kt (limited to 'libs/imgui-1.92.1/examples/example_android_opengl3/android/app/src') diff --git a/libs/imgui-1.92.1/examples/example_android_opengl3/android/app/src/main/AndroidManifest.xml b/libs/imgui-1.92.1/examples/example_android_opengl3/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..5a1e2d9 --- /dev/null +++ b/libs/imgui-1.92.1/examples/example_android_opengl3/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/libs/imgui-1.92.1/examples/example_android_opengl3/android/app/src/main/java/MainActivity.kt b/libs/imgui-1.92.1/examples/example_android_opengl3/android/app/src/main/java/MainActivity.kt new file mode 100644 index 0000000..896a88c --- /dev/null +++ b/libs/imgui-1.92.1/examples/example_android_opengl3/android/app/src/main/java/MainActivity.kt @@ -0,0 +1,40 @@ +package imgui.example.android + +import android.app.NativeActivity +import android.os.Bundle +import android.content.Context +import android.view.inputmethod.InputMethodManager +import android.view.KeyEvent +import java.util.concurrent.LinkedBlockingQueue + +class MainActivity : NativeActivity() { + public override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + fun showSoftInput() { + val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + inputMethodManager.showSoftInput(this.window.decorView, 0) + } + + fun hideSoftInput() { + val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + inputMethodManager.hideSoftInputFromWindow(this.window.decorView.windowToken, 0) + } + + // Queue for the Unicode characters to be polled from native code (via pollUnicodeChar()) + private var unicodeCharacterQueue: LinkedBlockingQueue = LinkedBlockingQueue() + + // We assume dispatchKeyEvent() of the NativeActivity is actually called for every + // KeyEvent and not consumed by any View before it reaches here + override fun dispatchKeyEvent(event: KeyEvent): Boolean { + if (event.action == KeyEvent.ACTION_DOWN) { + unicodeCharacterQueue.offer(event.getUnicodeChar(event.metaState)) + } + return super.dispatchKeyEvent(event) + } + + fun pollUnicodeChar(): Int { + return unicodeCharacterQueue.poll() ?: 0 + } +} -- cgit v1.2.3-70-g09d2