winio-ui-android 0.2.0-beta.1

Android backend for winio.
use super::{
    content::{Context, res::Resources},
    graphics::{Insets, Rect},
};
use crate::impl_listener;

jni::bind_java_type! {
    pub KeyEvent => android.view.KeyEvent,
    methods {
        fn get_action() -> jint,
        fn get_key_code() -> jint,
        fn get_meta_state() -> jint,
        fn get_unicode_char(meta_state: jint) -> jint,
    },
}

jni::bind_java_type! {
    pub MotionEvent => android.view.MotionEvent,
    methods {
        fn get_action() -> jint,
        fn get_action_button() -> jint,
        fn get_x() -> jfloat,
        fn get_y() -> jfloat,
        fn get_axis_value(axis: jint) -> jfloat,
    },
}

jni::bind_java_type! {
    pub View => "android.view.View",
    type_map {
        Context => android.content.Context,
        Resources => android.content.res.Resources,
        ViewParent => android.view.ViewParent,
        ViewGroupLayoutParams => "android.view.ViewGroup$LayoutParams",
        ViewOnLayoutChangeListener => "android.view.View$OnLayoutChangeListener",
        ViewOnTouchListener => "android.view.View$OnTouchListener",
        ViewOnKeyListener => "android.view.View$OnKeyListener",
        WindowInsets => android.view.WindowInsets,
    },
    constructors {
        fn new(context: &Context),
    },
    methods {
        fn get_x() -> jfloat,
        fn get_y() -> jfloat,
        fn set_x(x: jfloat),
        fn set_y(y: jfloat),
        fn get_width() -> jint,
        fn get_height() -> jint,
        fn get_layout_params() -> ViewGroupLayoutParams,
        fn set_layout_params(params: &ViewGroupLayoutParams),
        fn measure(width_spec: jint, height_spec: jint),
        fn get_measured_width() -> jint,
        fn get_measured_height() -> jint,
        fn get_minimum_width() -> jint,
        fn get_minimum_height() -> jint,
        fn get_visibility() -> jint,
        fn set_visibility(visibility: jint),
        fn set_id(id: jint),
        fn is_enabled() -> jboolean,
        fn set_enabled(enabled: jboolean),
        fn get_parent() -> ViewParent,
        fn get_resources() -> Resources,
        fn add_on_layout_change_listener(listener: &ViewOnLayoutChangeListener),
        fn set_on_touch_listener(listener: &ViewOnTouchListener),
        fn set_on_key_listener(listener: &ViewOnKeyListener),
        fn set_focusable_in_touch_mode(focusable: jboolean),
        fn request_focus() -> jboolean,
        fn get_root_window_insets() -> WindowInsets,
    }
}

jni::bind_java_type! {
    pub ViewParent => android.view.ViewParent,
}

jni::bind_java_type! {
    pub ViewGroupLayoutParams => "android.view.ViewGroup$LayoutParams",
    fields {
        width: jint,
        height: jint,
    }
}

jni::bind_java_type! {
    pub ViewGroupMarginLayoutParams => "android.view.ViewGroup$MarginLayoutParams",
    type_map {
        ViewGroupLayoutParams => "android.view.ViewGroup$LayoutParams",
    },
    constructors {
        fn new(width: jint, height: jint),
    },
    fields {
        left_margin: jint,
        top_margin: jint,
        right_margin: jint,
        bottom_margin: jint,
    },
    is_instance_of = {
        base = ViewGroupLayoutParams,
    }
}

jni::bind_java_type! {
    pub ViewOnLayoutChangeListener => "android.view.View$OnLayoutChangeListener",
}

impl_listener!(ViewOnLayoutChangeListener);

jni::bind_java_type! {
    pub ViewOnTouchListener => "android.view.View$OnTouchListener",
}

impl_listener!(ViewOnTouchListener);

jni::bind_java_type! {
    pub ViewOnKeyListener => "android.view.View$OnKeyListener",
}

impl_listener!(ViewOnKeyListener);

jni::bind_java_type! {
    pub ViewOnClickListener => "android.view.View$OnClickListener",
}

impl_listener!(ViewOnClickListener);

jni::bind_java_type! {
    pub ViewGroup => android.view.ViewGroup,
    type_map {
        View => android.view.View,
    },
    methods {
        fn add_view(view: &View),
        fn remove_view(view: &View),
        fn get_child_count() -> jint,
    },
    is_instance_of = {
        view = View,
    }
}

jni::bind_java_type! {
    pub WindowInsets => android.view.WindowInsets,
    type_map {
        Insets => android.graphics.Insets,
    },
    methods {
        fn get_insets_ignoring_visibility(type_mask: jint) -> Insets,
    }
}

jni::bind_java_type! {
    pub WindowInsetsType => "android.view.WindowInsets$Type",
    methods {
        static fn system_bars() -> jint,
    }
}

jni::bind_java_type! {
    pub SurfaceView => android.view.SurfaceView,
    type_map {
        View => android.view.View,
        Context => android.content.Context,
        SurfaceHolder => android.view.SurfaceHolder,
    },
    constructors {
        fn new(context: &Context),
    },
    methods {
        fn get_holder() -> SurfaceHolder,
    },
    is_instance_of = {
        view = View,
    }
}

jni::bind_java_type! {
    pub SurfaceHolder => android.view.SurfaceHolder,
    type_map {
        Surface => android.view.Surface,
        Rect => android.graphics.Rect,
    },
    methods {
        fn get_surface() -> Surface,
        fn get_surface_frame() -> Rect,
    }
}

jni::bind_java_type! {
    pub Surface => android.view.Surface,
}

pub mod gravity {
    pub const CENTER_HORIZONTAL: i32 = 0x1;
    pub const CENTER_VERTICAL: i32 = 0x10;
    pub const FILL_HORIZONTAL: i32 = 0x7;
    pub const LEFT: i32 = 0x3;
    pub const RIGHT: i32 = 0x5;
    pub const TOP: i32 = 0x30;
}

pub mod motion_event {
    pub const ACTION_DOWN: i32 = 0x0;
    pub const ACTION_UP: i32 = 0x1;
    pub const ACTION_MOVE: i32 = 0x2;
    pub const ACTION_HOVER_MOVE: i32 = 0x7;
    pub const ACTION_SCROLL: i32 = 0x8;

    pub const AXIS_VSCROLL: i32 = 0x9;
    pub const AXIS_HSCROLL: i32 = 0xA;

    pub const BUTTON_PRIMARY: i32 = 0x1;
    pub const BUTTON_SECONDARY: i32 = 0x2;
    pub const BUTTON_TERTIARY: i32 = 0x4;
}

jni::bind_java_type! {
    pub Menu => android.view.Menu,
    type_map {
        MenuItem => android.view.MenuItem,
        SubMenu => android.view.SubMenu,
    },
    methods {
        fn add(group_id: jint, item_id: jint, order: jint, title: &JCharSequence) -> MenuItem,
        fn add_sub_menu(
            group_id: jint,
            item_id: jint,
            order: jint,
            title: &JCharSequence,
        ) -> SubMenu,
        fn remove_item(id: jint),
        fn set_group_checkable(group: jint, checkable: jboolean, exclusive: jboolean),
    }
}

jni::bind_java_type! {
    pub MenuItem => android.view.MenuItem,
    type_map {
        MenuItemOnMenuItemClickListener => "android.view.MenuItem$OnMenuItemClickListener",
    },
    methods {
        fn get_title() -> JCharSequence,
        fn set_title(title: &JCharSequence) -> MenuItem,
        fn is_enabled() -> jboolean,
        fn set_enabled(enabled: jboolean) -> MenuItem,
        fn is_checked() -> jboolean,
        fn set_checked(checked: jboolean) -> MenuItem,
        fn set_checkable(checkable: jboolean) -> MenuItem,
        fn set_show_as_action(action: jint),
        fn set_on_menu_item_click_listener(
            listener: &MenuItemOnMenuItemClickListener,
        ) -> MenuItem,
    }
}

jni::bind_java_type! {
    pub SubMenu => android.view.SubMenu,
    type_map {
        Menu => android.view.Menu,
        MenuItem => android.view.MenuItem,
    },
    methods {
        fn get_item() -> MenuItem,
    },
    is_instance_of = {
        menu = Menu,
    }
}

jni::bind_java_type! {
    pub MenuItemOnMenuItemClickListener => "android.view.MenuItem$OnMenuItemClickListener",
}

impl_listener!(MenuItemOnMenuItemClickListener);

jni::bind_java_type! {
    pub MeasureSpec => "android.view.View$MeasureSpec",
    methods {
        static fn make_measure_spec(size: jint, mode: jint) -> jint,
    }
}

pub mod menu {
    pub const NONE: i32 = 0;
}

pub mod menu_item {
    pub const SHOW_AS_ACTION_ALWAYS: i32 = 0x2;
}

pub mod measure_spec {
    pub const UNSPECIFIED: i32 = 0x0 << 30;
    pub const EXACTLY: i32 = 0x1 << 30;
}

pub mod visibility {
    pub const VISIBLE: i32 = 0x0;
    pub const GONE: i32 = 0x8;
}