mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-03-29 09:09:07 +08:00
add Hello android sample (similar to ios/Hello sample)
This commit is contained in:
13
android-samples/Hello/.gitignore
vendored
Normal file
13
android-samples/Hello/.gitignore
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
.repl_history
|
||||
build
|
||||
tags
|
||||
.DS_Store
|
||||
nbproject
|
||||
.redcar
|
||||
#*#
|
||||
*~
|
||||
*.sw[po]
|
||||
.eprj
|
||||
.sass-cache
|
||||
.idea
|
||||
.dat*.*
|
||||
11
android-samples/Hello/Rakefile
Normal file
11
android-samples/Hello/Rakefile
Normal file
@@ -0,0 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
$:.unshift("../../lib")
|
||||
require 'motion/project/template/android'
|
||||
|
||||
Motion::Project::App.setup do |app|
|
||||
# Use `rake config' to see complete project settings.
|
||||
app.name = 'Hello'
|
||||
app.api_version = '18'
|
||||
app.sdk_path = File.expand_path('~/src/android-sdk-macosx')
|
||||
app.ndk_path = File.expand_path('~/src/android-ndk-r9d')
|
||||
end
|
||||
25
android-samples/Hello/app/main_activity.rb
Normal file
25
android-samples/Hello/app/main_activity.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class MainActivity < Android::App::Activity
|
||||
def onCreate(savedInstanceState)
|
||||
super
|
||||
|
||||
@text = Android::Widget::TextView.new(self)
|
||||
@text.text = 'Hello RubyMotion!'
|
||||
@text.textColor = Android::Graphics::Color::WHITE
|
||||
@text.textSize = 40.0
|
||||
self.contentView = @text
|
||||
end
|
||||
|
||||
def dispatchTouchEvent(event)
|
||||
@counter ||= 0
|
||||
case event.getAction
|
||||
when Android::View::MotionEvent::ACTION_UP
|
||||
@counter += 1
|
||||
@text.text = "Touched #{@counter} times!"
|
||||
@text.backgroundColor = Android::Graphics::Color::BLACK
|
||||
when Android::View::MotionEvent::ACTION_MOVE
|
||||
@text.text = "ZOMG!"
|
||||
@text.backgroundColor = Android::Graphics::Color.rgb(rand(255), rand(255), rand(255))
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user