ruboto gen app --package ru.nitrodev.demo_app
demo_app
directory and admire the carefully prepared application structure. In the src
folder is already our first activation, and we’ll move on to it.ruboto/widget.rb
which is a wrapper over the API and provides a simple DSL to create the interface. java_import "android.widget.Button" java_import "android.widget.TextView" java_import "android.widget.LinearLayout"
ll = LinearLayout.new(@ruboto_java_instance) ll.orientation = LinearLayout::VERTICAL tv = TextView.new(@ruboto_java_instance) tv.text = " Java" ll.add_view tv # TextView LinearLayout params = tv.get_layout_params params.width = ViewGroup::LayoutParams::MATCH_PARENT btn1 = Button.new(@ruboto_java_instance) btn1.text = "Play" btn1.on_click_listener = proc{ Play } ll.add_view btn1 params = search_b.get_layout_params params.width = ViewGroup::LayoutParams::MATCH_PARENT btn2 = Button.new(@ruboto_java_instance) btn2.text = "Pause" btn2.on_click_listener = proc{ Pause } ll.add_view btn2 params = search_b.get_layout_params params.width = ViewGroup::LayoutParams::MATCH_PARENT btn3 = Button.new(@ruboto_java_instance) btn3.text = " " btn3.on_click_listener = proc{ twoActivity } ll.add_view btn3 params = search_b.get_layout_params params.width = ViewGroup::LayoutParams::MATCH_PARENT btn4 = Button.new(@ruboto_java_instance) btn4.text = " " btn4.on_click_listener = proc{ threeActivity } ll.add_view btn4 params = search_b.get_layout_params params.width = ViewGroup::LayoutParams::MATCH_PARENT setContentView ll
ruboto_import_widgets :Button, :LinearLayout, :TextView self.content_view = linear_layout :orientation => :vertical do text_view :text => ' Ruby - ', :width => :match_parent button :text => 'Play', :width => :match_parent, :on_click_listener => proc { play } button :text => 'Pause', :width => :match_parent, :on_click_listener => proc { pause } button :text => ' ', :width => :match_parent, :on_click_listener => proc { twoActivity } button :text => ' ', :width => :match_parent, :on_click_listener => proc { threeActivity } end
java_import "android.media.MediaPlayer" java_import "android.media.AudioManager" java_import "android.net.Uri"
java_file = java.io.File.new("/mnt/sdcard/naive.mp3") uri = Uri.fromFile(java_file) @player = MediaPlayer.create(self, uri);
@player.start @player.pause
start_ruboto_activity
.start_ruboto_activity
is the equivalent of Android startActivity in Ruboto. It has two required parameters: a string containing a global reference to the activity being created and a block that will be executed once when the activity is created. start_ruboto_activity("$activity_two") do def on_create(bundle) super setTitle ' ' end end
def on_touch_event(event) index = event.find_pointer_index(0) x = event.getX(index) y = event.getY(index) toast "Position: #{x}, #{y}" true end
java_import "android.content.Intent"
intent = Intent.new(Intent::ACTION_CALL) intent.setData(Uri.parse("tel:5551234")) startActivity(intent) intent = Intent.new(Intent::ACTION_VIEW) intent.setData(Uri.parse("http://ruboto.org/")) startActivity(intent)
<uses-permission android:name="android.permission.CALL_PHONE" />
on_create_options_menu
used to work with the menu. Everything is simple: create menu items and hang the listener on them, when you click on toast
message will be displayed with the name of the menu item. def on_create_options_menu(menu) m1 = menu.add('Action 1') m1.set_on_menu_item_click_listener do |menu_item| @text_view.text = menu_item_title toast menu_item.title true end m2 = menu.add('Action 2') m2.set_on_menu_item_click_listener do |menu_item| @text_view.text = menu_item.title toast menu_item.title true end true end
Source: https://habr.com/ru/post/165071/
All Articles