polyhorn_android_sys/
image_view.rs

1use jni::objects::JValue;
2
3use super::{Bitmap, Context, Env, Object, Rect, Reference, View};
4
5#[derive(Clone)]
6pub struct ImageView {
7    reference: Reference,
8}
9
10impl ImageView {
11    pub fn new(env: &Env, context: impl Into<Context>) -> ImageView {
12        unsafe {
13            let context = context.into();
14
15            let object = env.call_constructor(
16                "com/glacyr/polyhorn/ImageView",
17                "(Landroid/content/Context;)V",
18                &[JValue::Object(context.as_reference().as_object()).into()],
19            );
20
21            ImageView {
22                reference: env.retain(object),
23            }
24        }
25    }
26
27    pub fn set_image_bitmap(&mut self, env: &Env, bitmap: &Bitmap) {
28        unsafe {
29            env.call_method(
30                self.reference.as_object(),
31                "setImageBitmap",
32                "(Landroid/graphics/Bitmap;)V",
33                &[JValue::Object(bitmap.as_reference().as_object())],
34            );
35        }
36    }
37
38    pub fn set_frame(&mut self, env: &Env, frame: Rect) {
39        unsafe {
40            env.call_method(
41                self.reference.as_object(),
42                "setFrame",
43                "(Lcom/glacyr/polyhorn/Rect;)V",
44                &[JValue::Object(frame.as_reference().as_object())],
45            );
46        }
47    }
48
49    pub fn to_view(&self) -> View {
50        View::from_reference(self.reference.clone())
51    }
52}