176 lines
6.3 KiB
Odin
176 lines
6.3 KiB
Odin
#+build ignore
|
|
// JNI binding spec. Never compiled -- jnigen parses this file and emits
|
|
// jni_generated.odin. Regenerate with:
|
|
//
|
|
// odin run jnigen -- jni_spec.odin jni_generated.odin main
|
|
//
|
|
// Attributes:
|
|
// java_class="a/b/C" required; the class, or the type's Java class
|
|
// java_name="foo" Java-side name (defaults to the Odin proc name)
|
|
// java_static static method or field
|
|
// java_ctor constructor; must return a registered object type
|
|
// java_field field access; 1 result = getter, 0 results = setter
|
|
// java_sig="..." override the computed signature
|
|
package main
|
|
|
|
import "shared:android"
|
|
|
|
//
|
|
// Object types. Each becomes `Name :: distinct android.jobject` and lets
|
|
// signatures resolve the Odin type to its Java class.
|
|
//
|
|
|
|
@(java_class = "android/content/Context")
|
|
Context :: distinct android.jobject
|
|
|
|
@(java_class = "android/widget/Toast")
|
|
Toast :: distinct android.jobject
|
|
|
|
@(java_class = "java/lang/StringBuilder")
|
|
StringBuilder :: distinct android.jobject
|
|
|
|
@(java_class = "android/os/Looper")
|
|
Looper :: distinct android.jobject
|
|
|
|
@(java_class = "android/app/Activity")
|
|
Activity :: distinct android.jobject
|
|
|
|
@(java_class = "android/view/Window")
|
|
Window :: distinct android.jobject
|
|
|
|
@(java_class = "android/view/View")
|
|
View :: distinct android.jobject
|
|
|
|
@(java_class = "android/view/WindowInsets")
|
|
WindowInsets :: distinct android.jobject
|
|
|
|
@(java_class = "android/graphics/Insets")
|
|
Insets :: distinct android.jobject
|
|
|
|
//
|
|
// Static methods
|
|
//
|
|
|
|
@(java_class = "java/lang/System", java_static, java_name = "currentTimeMillis")
|
|
system_current_time_millis :: proc() -> i64
|
|
|
|
// makeText takes a CharSequence, not a String, so the computed signature would
|
|
// not match. java_sig pins the real one while `string` stays in the Odin API.
|
|
@(
|
|
java_class = "android/widget/Toast",
|
|
java_static,
|
|
java_name = "makeText",
|
|
java_sig = "(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;",
|
|
)
|
|
toast_make_text :: proc(ctx: Context, text: string, duration: i32) -> Toast
|
|
|
|
// Toast's constructor reads Looper.myLooper() and throws if the thread has
|
|
// none. The engine loop runs on a glue-spawned thread that only ever got a
|
|
// native ALooper, so the Java-side looper has to be prepared once by hand.
|
|
@(java_class = "android/os/Looper", java_static, java_name = "prepare")
|
|
looper_prepare :: proc()
|
|
|
|
@(java_class = "android/os/Looper", java_static, java_name = "myLooper")
|
|
looper_my_looper :: proc() -> Looper
|
|
|
|
//
|
|
// Instance methods -- the first parameter is the receiver.
|
|
//
|
|
|
|
@(java_class = "android/widget/Toast", java_name = "show")
|
|
toast_show :: proc(self: Toast)
|
|
|
|
@(java_class = "java/lang/StringBuilder", java_name = "append", java_sig = "(Ljava/lang/String;)Ljava/lang/StringBuilder;")
|
|
sb_append :: proc(self: StringBuilder, s: string) -> StringBuilder
|
|
|
|
@(java_class = "java/lang/StringBuilder", java_name = "toString")
|
|
sb_to_string :: proc(self: StringBuilder) -> string
|
|
|
|
//
|
|
// Constructor
|
|
//
|
|
|
|
@(java_class = "java/lang/StringBuilder", java_ctor)
|
|
sb_new :: proc() -> StringBuilder
|
|
|
|
//
|
|
// Fields
|
|
//
|
|
|
|
@(java_class = "android/os/Build$VERSION", java_static, java_field, java_name = "SDK_INT")
|
|
build_sdk_int :: proc() -> i32
|
|
|
|
@(java_class = "android/os/Build", java_static, java_field, java_name = "MODEL")
|
|
build_model :: proc() -> string
|
|
|
|
//
|
|
// Arrays
|
|
//
|
|
|
|
@(java_class = "java/util/Arrays", java_static, java_name = "sort", java_sig = "([I)V")
|
|
arrays_sort :: proc(vals: []i32)
|
|
|
|
@(java_class = "android/os/Build", java_static, java_field, java_name = "SUPPORTED_ABIS")
|
|
build_supported_abis :: proc() -> []string
|
|
|
|
//
|
|
// Window insets: Activity -> Window -> decor View -> WindowInsets -> Insets.
|
|
//
|
|
// getRootWindowInsets returns null until the decor view is attached, so the
|
|
// first frames after launch will come back nil -- retry rather than treating
|
|
// it as an error.
|
|
//
|
|
|
|
@(java_class = "android/app/Activity", java_name = "getWindow")
|
|
activity_get_window :: proc(self: Activity) -> Window
|
|
|
|
@(java_class = "android/view/Window", java_name = "getDecorView")
|
|
window_get_decor_view :: proc(self: Window) -> View
|
|
|
|
@(java_class = "android/view/View", java_name = "getRootWindowInsets")
|
|
view_get_root_window_insets :: proc(self: View) -> WindowInsets
|
|
|
|
// WindowInsets.Type is a nested class, hence the $ separator.
|
|
@(java_class = "android/view/WindowInsets$Type", java_static, java_name = "systemBars")
|
|
insets_type_system_bars :: proc() -> i32
|
|
|
|
// A fullscreen theme hides the system bars, so systemBars() alone reports 0.
|
|
// The cutout is what still needs avoiding -- the two are OR'd into one mask.
|
|
@(java_class = "android/view/WindowInsets$Type", java_static, java_name = "displayCutout")
|
|
insets_type_display_cutout :: proc() -> i32
|
|
|
|
// Reports bar sizes even while hidden, which is what a fullscreen app wants
|
|
// when it draws its own chrome where the bars would otherwise sit.
|
|
@(java_class = "android/view/WindowInsets", java_name = "getInsetsIgnoringVisibility")
|
|
window_insets_get_ignoring_visibility :: proc(self: WindowInsets, type_mask: i32) -> Insets
|
|
|
|
// API 30+. The computed signature (I)Landroid/graphics/Insets; is already right.
|
|
@(java_class = "android/view/WindowInsets", java_name = "getInsets")
|
|
window_insets_get :: proc(self: WindowInsets, type_mask: i32) -> Insets
|
|
|
|
// Insets exposes its edges as public final int fields.
|
|
@(java_class = "android/graphics/Insets", java_field, java_name = "left")
|
|
insets_left :: proc(self: Insets) -> i32
|
|
|
|
@(java_class = "android/graphics/Insets", java_field, java_name = "top")
|
|
insets_top :: proc(self: Insets) -> i32
|
|
|
|
@(java_class = "android/graphics/Insets", java_field, java_name = "right")
|
|
insets_right :: proc(self: Insets) -> i32
|
|
|
|
@(java_class = "android/graphics/Insets", java_field, java_name = "bottom")
|
|
insets_bottom :: proc(self: Insets) -> i32
|
|
|
|
// Deprecated in API 30 but present since 20 -- the fallback below minSdk 30.
|
|
@(java_class = "android/view/WindowInsets", java_name = "getSystemWindowInsetLeft")
|
|
window_insets_sys_left :: proc(self: WindowInsets) -> i32
|
|
|
|
@(java_class = "android/view/WindowInsets", java_name = "getSystemWindowInsetTop")
|
|
window_insets_sys_top :: proc(self: WindowInsets) -> i32
|
|
|
|
@(java_class = "android/view/WindowInsets", java_name = "getSystemWindowInsetRight")
|
|
window_insets_sys_right :: proc(self: WindowInsets) -> i32
|
|
|
|
@(java_class = "android/view/WindowInsets", java_name = "getSystemWindowInsetBottom")
|
|
window_insets_sys_bottom :: proc(self: WindowInsets) -> i32
|