//! The smallest ltk app on Android: a counter in a NativeActivity, on the default theme the APK carries. `make android-apk` builds and packages it, `make android-install` puts it on the device `adb` sees. //! //! An Android app is a library the activity loads, so this example builds as a `cdylib` whose entry point is `android_main`. #![ cfg( target_os = "android" ) ] use ltk::{ App, ButtonVariant, Element, button, column, spacer, text }; #[ derive( Clone ) ] enum Msg { Press, } #[ derive( Default ) ] struct Hello { presses: u32, } impl App for Hello { type Message = Msg; fn app_id( &self ) -> &str { "net.liberux.ltk.Hello" } fn save_state( &self ) -> Option> { None } fn restore_state( &mut self, _state: Vec ) {} fn view( &self ) -> Element { let palette = ltk::theme_palette(); column::() .spacing( 16.0 ) .push( spacer() ) .push( text( "ltk on Android" ).size( 28.0 ).color( palette.text_primary ) ) .push( text( format!( "Pressed {} times", self.presses ) ).size( 18.0 ).color( palette.text_secondary ) ) .push( button::( "Press" ).variant( ButtonVariant::Primary ).on_press( Msg::Press ) ) .push( spacer() ) .into() } fn update( &mut self, msg: Msg ) { match msg { Msg::Press => self.presses += 1, } } } #[ no_mangle ] fn android_main( app: ltk::AndroidApp ) { ltk::set_android_app( app ); ltk::run( Hello::default() ); }