Contenu connexe Similaire à Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android (20) Meetup 2013:01: Uwe Kubosh - Ruboto - JRuby on Android2. Ruboto
JRuby on Android
Saturday, January 26, 13 1
3. Uwe Kubosch
Work at Datek Wireless in
Norway
Ruboto core developer
JRuby rookie committer
Saturday, January 26, 13 2
4. Ruboto?
Platform for developing
Android apps using Ruby
Builds on JRuby and the
Android SDK
Application and component
generators
Test framework
Compact GUI definition
Saturday, January 26, 13 3
5. _why Ruboto?
Write Ruby instead of
Java/XML
Use Ruby libraries (gems)
Focus on testing
Faster development cycles
Saturday, January 26, 13 4
6. Topics covered
History
Ruboto IRB
Installation & development
tools
Hello world!
Demos
Limitations
Roadmap
Saturday, January 26, 13 5
7. Android basics/terms
Activity: A screen
View: A screen component
Service: Background process
Intent: Definition of action
BroadcastReceiver: Listener for Intents
Saturday, January 26, 13 6
8. History 2009
PoC by Charles Nutter
(headius) February 24,
2009
ruboto-irb by headius
August 1, 2009
Saturday, January 26, 13 7
9. History 2009
PoC by Charles Nutter
(headius) February 24,
2009
ruboto-irb by headius
August 1, 2009
Saturday, January 26, 13 7
10. History 2009
PoC by Charles Nutter
(headius) February 24,
2009
ruboto-irb by headius
August 1, 2009
Saturday, January 26, 13 7
11. History 2009
PoC by Charles Nutter
(headius) February 24,
2009
ruboto-irb by headius
August 1, 2009
Saturday, January 26, 13 7
12. History 2009
PoC by Charles Nutter
(headius) February 24,
2009
ruboto-irb by headius
August 1, 2009
Saturday, January 26, 13 7
14. class Cube class RubotoGLSurfaceViewRenderer
def initialize def initialize
@translucent_background = false
one = 0x10000
@cube = Cube.new
vertices = [ @angle = 0.0
-one,-one,-one,one,-one,-one,one,one,-one,-one,one,-one,-one,-
@offset = 1.2
one,one,one,-one,one,one,one,one,-one,one,one end
]
colors = [ def onDrawFrame(gl)
0,0,0,one,one,0,0,one,one,one,0,one,0,one,0,one, gl.glClear(GL10::GL_COLOR_BUFFER_BIT | GL10::GL_DEPTH_BUFFER_BIT)
gl.glMatrixMode(GL10::GL_MODELVIEW)
0,0,one,one,one,0,one,one,one,one,one,one,0,one,one,one
gl.glLoadIdentity
] gl.glTranslatef(0, 0, -3.0)
indices = [ gl.glRotatef(@angle, 0, 1, 0)
0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2, 7, 3, 3, 7, 4,
gl.glRotatef(@angle*0.25, 1, 0, 0)
3, 4, 0, 4, 7, 6, 4, 6, 5, 3, 0, 1, 3, 1, 2 gl.glEnableClientState(GL10::GL_VERTEX_ARRAY)
] gl.glEnableClientState(GL10::GL_COLOR_ARRAY)
@cube.draw(gl)
gl.glRotatef(@angle*2.0, 0, 1, 1)
vbb = ByteBuffer.allocateDirect(vertices.length*4)
gl.glTranslatef(0.5, 0.5, 0.5)
vbb.order(ByteOrder.nativeOrder) @cube.draw(gl)
@vertex_buffer = vbb.asIntBuffer @angle += @offset
@vertex_buffer.put(vertices.to_java(:int)) end
Demo: OpenGL
@vertex_buffer.position(0)
def onSurfaceChanged(gl, width, height)
cbb = ByteBuffer.allocateDirect(colors.length*4) gl.glViewport(0, 0, width, height)
ratio = width.to_f / height.to_f
cbb.order(ByteOrder.nativeOrder)
ruboto_generate(android.opengl.GLSurfaceView => "TouchSurfaceView") gl.glMatrixMode(GL10::GL_PROJECTION)
@color_buffer = cbb.asIntBuffer gl.glLoadIdentity
@color_buffer.put(colors.to_java(:int))
class TouchSurfaceView gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10)
@color_buffer.position(0)
def initialize(context) end
super context
@index_buffer = ByteBuffer.allocateDirect(indices.length) def onSurfaceCreated(gl, config)
$activity.start_ruboto_activity "$glsurface" do
@index_buffer.put(indices.to_java(:byte)) gl.glDisable(GL10::GL_DITHER)
setTitle "GLSurfaceView"
self.initialize_ruboto_callbacks do gl.glHint(GL10::GL_PERSPECTIVE_CORRECTION_HINT, GL10::GL_FASTEST)
@index_buffer.position(0)
def on_touch_event(event) if (@translucent_background)
end if event.getAction == MotionEvent::ACTION_DOWN def on_create(bundle)
gl.glClearColor(0,0,0,0)
@renderer.changeAngle @surface_view = TouchSurfaceView.new(self)
else
def draw(gl)
request_render @surface_view.renderer = RubotoGLSurfaceViewRenderer.new
gl.glClearColor(1,1,1,1)
gl.glFrontFace(GL10::GL_CW)
end end
self.content_view = @surface_view
gl.glVertexPointer(3, GL10::GL_FIXED, 0, @vertex_buffer) gl.glEnable(GL10::GL_CULL_FACE)
end
return true
gl.glColorPointer(4, GL10::GL_FIXED, 0, @color_buffer) gl.glShadeModel(GL10::GL_SMOOTH)
end gl.glEnable(GL10::GL_DEPTH_TEST)
gl.glDrawElements(GL10::GL_TRIANGLES, 36, GL10::GL_UNSIGNED_BYTE,
end def on_resume
end
@index_buffer)
end @surface_view.on_resume
end end
def changeAngle
end def renderer= renderer @offset = -@offset
@renderer = renderer end
def on_pause
end @surface_view.on_pause
super renderer
end end
end end
Saturday, January 26, 13 8
16. History 2010
ruboto-core : GSoC 2010 by Daniel Jackoway
Version 0.0.3 released December 19, 2010
Saturday, January 26, 13 10
17. History 2011
Testing framework: Feb 13, Rename to just “ruboto”:
2011 (my first contribution) december 24, 2011
Bundler support: may 21,
2011
New Logo & Icons by
RedNifre: july 20, 2011
RubotoCore platform
package: august 2011
Saturday, January 26, 13 11
18. History 2011
Testing framework: Feb 13, Rename to just “ruboto”:
2011 (my first contribution) december 24, 2011
Bundler support: may 21,
2011
New Logo & Icons by
RedNifre: july 20, 2011
RubotoCore platform
package: august 2011
Saturday, January 26, 13 11
19. History 2012
Class oriented component definition, 2012
On-device generation of subclasses may 10,
2012
Subclassing of Java classes (next release)
Saturday, January 26, 13 12
20. History 2012
$activity.handle_create do |bundle|
setTitle ‘Hello World!’
setup_content do
linear_layout :orientation => LinearLayout::VERTICAL do
@text_view = text_view :text => 'What hath Matz wrought?'
button :text => ‘Click me!’, :width => :wrap_content, :id => 43
Class oriented component definition, 2012
end
end
handle_click do |view|
if view.id == 43
On-device generation of subclasses may 10,
@text_view.setText 'What hath Matz wrought!'
toast 'Flipped a bit via butterfly'
end
2012 end
end
Subclassing of Java classes (next release)
Saturday, January 26, 13 12
21. $activity.handle_create do |bundle|
History 2012
setTitle ‘Hello World!’
setup_content do
linear_layout :orientation => LinearLayout::VERTICAL do
@text_view = text_view :text => 'What hath Matz wrought?'
button :text => ‘Click me!’, :width => :wrap_content, :id => 43
end
end
handle_click do |view|
if view.id == 43 $activity.start_ruboto_activity do
@text_view.setText 'Whaton_create(bundle)
def hath Matz wrought!'
toast 'Flipped a bit via butterfly'
setTitle ‘Hello World!’
end
end click_handler = proc do |view|
end @text_view.setText 'What hath Matz wrought!'
toast 'Flipped a bit via butterfly'
Class oriented component definition, 2012
end
self.content_view =
linear_layout :orientation => LinearLayout::VERTICAL do
@text_view = text_view :text => 'What hath Matz wrought?'
On-device generation of subclasses may 10,
button :text => ‘Click me!, :width => :wrap_content,
end
:on_click_listener => click_handler
2012 end
end
Subclassing of Java classes (next release)
Saturday, January 26, 13 12
22. $activity.handle_create do |bundle|
$activity.start_ruboto_activity do
History 2012
setTitle ‘Hello World!’
def on_create(bundle)
setup_content do setTitle ‘Hello World!’
linear_layout :orientation => LinearLayout::VERTICAL do
click_handler = proc do |view|
@text_view = text_view :text => 'What hath Matz wrought?'
@text_view.setText 'What hath Matz wrought!'
button :text => ‘Click me!’, :width => :wrap_content, :id => 43
end toast 'Flipped a bit via butterfly'
end end
handle_click do |view| self.content_view =
if view.id == 43 class ImageButtonActivity linear_layout :orientation => LinearLayout::VERTICAL do
def on_create(bundle)
@text_view.setText 'What hath Matz wrought!' @text_view = text_view :text => 'What hath Matz wrought?'
super
toast 'Flipped a bit via butterfly' button :text => ‘Click me!, :width => :wrap_content,
end set_title ‘Hello World!’ :on_click_listener => click_handler
end end
end click_handler = proc do |view|
end
@text_view.setTextend
'What hath Matz wrought!'
toast 'Flipped a bit via butterfly'
Class oriented component definition, 2012
end
self.content_view =
linear_layout :orientation => :vertical do
On-device generation of subclasses may 10,
@text_view = text_view :text => 'What hath Matz wrought?'
button :text => ‘Click me!’, :width => :wrap_content, :id => 43,
:on_click_listener => click_handler
2012
end
end
end
Subclassing of Java classes (next release)
Saturday, January 26, 13 12
23. History 2012
Class oriented component definition, 2012
On-device generation of subclasses may 10,
2012
Subclassing of Java classes (next release)
Saturday, January 26, 13 13
24. History 2012
require 'ruboto/generate'
ruboto_generate("android.widget.ArrayAdapter" => $package_name + ".MyArrayAdapter")
adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1 , [...])
Class oriented component definition, 2012
adapter.initialize_ruboto_callbacks do
def get_view(position, convert_view, parent)
@inflater ||= context.getSystemService(Context::LAYOUT_INFLATER_SERVICE)
row = convert_view ? convert_view : @inflater.inflate(mResource, nil)
row.findViewById(mFieldId).text = get_item(position)
On-device generation of subclasses may 10,
row
end
end
2012
Subclassing of Java classes (next release)
Saturday, January 26, 13 13
25. require 'ruboto/generate'
History 2012
ruboto_generate("android.widget.ArrayAdapter" => $package_name + ".MyArrayAdapter")
adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1 , [...])
adapter.initialize_ruboto_callbacks do
def get_view(position, convert_view, parent)
@inflater ||= context.getSystemService(Context::LAYOUT_INFLATER_SERVICE)
row = convert_view ? convert_view : @inflater.inflate(mResource, nil)
row.findViewById(mFieldId).text = get_item(position)
row
end
end
class MyArrayAdapter < android.widget.ArrayAdapter
def get_view(position, convert_view, parent)
@inflater ||= context.getSystemService(Context::LAYOUT_INFLATER_SERVICE)
row = convert_view ? convert_view : @inflater.inflate(mResource, nil)
Class oriented component definition, 2012
row.findViewById(mFieldId).text = get_item(position)
row
end
end
On-device generation of subclasses may 10,
adapter = MyArrayAdapter.new(self, android.R.layout.simple_list_item_1, [...])
2012
Subclassing of Java classes (next release)
Saturday, January 26, 13 13
26. Installation
Android toolset: Java JDK, Apache ANT,
Android SDK + Platform SDK
A Ruby implementation
[sudo] gem install ruboto
Saturday, January 26, 13 14
27. Tooling
The “ruboto” command
Rake
Saturday, January 26, 13 15
28. Tooling - create project
ruboto gen app --package my.cool.super_app
Saturday, January 26, 13 16
29. Tooling - create project
$ ruboto gen app --package my.cool.super_app
Generating Android app SuperApp in /Users/uwe/workspace/jruby/super_app...
...
Added file super_app/src/my/cool/super_app/SuperAppActivity.java
...
Added file super_app/res/values/strings.xml
Added file super_app/res/layout/main.xml
The “ruboto” command
Added file super_app/AndroidManifest.xml
Added file super_app/build.xml
Added file super_app/proguard-project.txt
ruboto gem app --package my.cool.
Removed file src/my/cool/super_app/SuperAppActivity.java
Removed file res/layout/main.xml
...
Rake based
Added file /Users/uwe/workspace/jruby/super_app/src/my/cool/super_app/SuperAppActivity.java.
Added file /Users/uwe/workspace/jruby/super_app/src/super_app_activity.rb.
Added file /Users/uwe/workspace/jruby/super_app/test/src/super_app_activity_test.rb.
Saturday, January 26, 13 17
30. Tooling - create component
ruboto gen class Activity --name MyActivity
Saturday, January 26, 13 18
31. Tooling - create component
$ ruboto gen class Activity --name MyActivity
Added file /Users/uwe/workspace/jruby/hello_world/src/presentation/hello_world/MyActivity.java.
Added file /Users/uwe/workspace/jruby/hello_world/src/my_activity.rb.
Added file /Users/uwe/workspace/jruby/hello_world/test/src/my_activity_test.rb.
Added activity to manifest.
ruboto gen class Activity --name MyActivity
Saturday, January 26, 13 19
32. Tooling - build APK
rake debug
rake release
Saturday, January 26, 13 20
33. Tooling - Install and run APK
rake install
rake start
rake install start
rake update_scripts:restart
Saturday, January 26, 13 21
34. Eclipse
http://download.eclipse.org/
releases/juno
https://dl-ssl.google.com/
android/eclipse/
Saturday, January 26, 13 22
35. Eclipse
http://download.eclipse.org/
releases/juno
https://dl-ssl.google.com/
android/eclipse/
Saturday, January 26, 13 23
36. Eclipse
GUI Editor
Saturday, January 26, 13 24
39. Hello world!
$ android create project --target android-8 --path hello_world --package presentation.hello_world --activity HelloWorldActivity
Generates file src/presentation/HelloWorldActivity.java
Saturday, January 26, 13 26
40. Hello world!
$ android create project --target android-8 --path hello_world --package presentation.hello_world --activity HelloWorldActiv
Generates file src/presentation/HelloWorldActivity.java
Saturday, January 26, 13 26
41. Hello world!
$ android create project --target android-8 --pat...
Generates file src/presentation/HelloWorldActivity.java
package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;
public class HelloWorldActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
}
public void changeIt(View view) {
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!");
}
}
Saturday, January 26, 13 27
42. Hello world!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
$ android create project --target android-8 --pat...
android:orientation="vertical"
Generates file src/presentation/HelloWorldActivity.java
android:layout_width="match_parent"
package com.example.examplejavaxml;
android:layout_height="match_parent"
android:gravity="center" >
import android.os.Bundle;
import android.app.Activity; <TextView
import android.view.View;
android:id="@+id/textView1"
import android.widget.TextView;
android:layout_width="wrap_content"
android:layout_height="wrap_content"
public class HelloWorldActivity extends Activity {
@Override android:gravity="center"
android:text="@string/hello_world"
public void onCreate(Bundle savedInstanceState) {
tools:context=".HelloWorldActivity"
super.onCreate(savedInstanceState);
android:textSize="46dip" />
setContentView(R.layout.activity_hello_world);
}
<Button
public void changeIt(View view)android:id="@+id/button1"
{
TextView tv = (TextView) findViewById(R.id.textView1);
android:layout_width="wrap_content"
tv.setText("Hello JavaZone!");
android:layout_height="wrap_content"
} android:gravity="center"
} android:layout_marginTop="75dp"
android:onClick="changeIt"
android:text="Say hello" />
</LinearLayout>
Saturday, January 26, 13 27
43. Hello world!
$ android create project --target android-8 --pat...
Generates file src/presentation/HelloWorldActivity.java
package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;
public class HelloWorldActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
}
public void changeIt(View view) {
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!");
}
}
Saturday, January 26, 13 27
44. Hello world!
$ android create project --target android-8 --pat...
Generates file src/presentation/HelloWorldActivity.java
package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;
public class HelloWorldActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world);
}
public void changeIt(View view) {
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!");
}
}
Saturday, January 26, 13 28
45. Hello world!
$ android create project --target android-8 --pat... $ android create project --target android-8 --pat...
Generates file src/presentation/HelloWorldActivity.java Generates file src/presentation/HelloWorldActivity.java
package com.example.examplejavaxml; package com.example.examplejavaxml;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world);
} }
public void changeIt(View view) { public void changeIt(View view) {
TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
} }
Saturday, January 26, 13 28
46. Hello world!
$ android create project --target android-8 --pat... $ android create project --target android-8 --pat...
Generates file src/presentation/HelloWorldActivity.java Generates file src/presentation/HelloWorldActivity.java
package com.example.examplejavaxml; package com.example.examplejavaxml;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world);
} }
public void changeIt(View view) { public void changeIt(View view) {
TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
} }
Saturday, January 26, 13 29
47. Hello world!
$ android create project --target android-8 --pat... $ android create project --target android-8 --pat...
Generates file src/presentation/HelloWorldActivity.java Generates file src/presentation/HelloWorldActivity.java
package com.example.examplejavaxml; package com.example.examplejavaxml;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity {
@Override @Override
$ ruboto gen app --package presentation.hello_world
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
Generates file src/hello_world_activity.rb
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world);
} }
public void changeIt(View view) { public void changeIt(View view) {
TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
} }
Saturday, January 26, 13 29
48. Hello world!
$ ruboto gen appproject --target android-8 --pat...
$ android create --package presentation.hello_world $ android create project --target android-8 --pat...
Generates file src/presentation/HelloWorldActivity.java Generates file src/presentation/HelloWorldActivity.java
Generates file src/hello_world_activity.rb
package com.example.examplejavaxml; package com.example.examplejavaxml;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world);
} }
public void changeIt(View view) { public void changeIt(View view) {
TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
} }
Saturday, January 26, 13 29
49. Hello world!
$ ruboto gen app --package presentation.hello_world $ android create project --target android-8 --pat...
Generates file src/hello_world_activity.rb Generates file src/presentation/HelloWorldActivity.java
package com.example.examplejavaxml; package com.example.examplejavaxml;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
public class HelloWorldActivity extends Activity { public class HelloWorldActivity extends Activity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_world); setContentView(R.layout.activity_hello_world);
} }
public void changeIt(View view) { public void changeIt(View view) {
TextView tv = (TextView) findViewById(R.id.textView1); TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
} }
Saturday, January 26, 13 30
50. Hello world!
package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;
class HelloWorldActivity public class HelloWorldActivity extends Activity {
def on_create(bundle) @Override
super public void onCreate(Bundle savedInstanceState) {
setContentView R.layout.activity_hello_world super.onCreate(savedInstance State);
end setContentView(R.layout.activity_hello_world);
}
def change_it(view)
tv = findViewById(AndroidIds::textView1) public void changeIt(View view) {
tv.text = "Hello JavaZone!" TextView tv = (TextView) findViewById(R.id.textView1);
end tv.setText("Hello JavaZone!");
end }
}
Saturday, January 26, 13 31
51. Hello world!
<LinearLayout package com.example.examplejavaxml;
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" import android.os.Bundle;
android:orientation="vertical" import android.app.Activity;
android:layout_width="match_parent" import android.view.View;
android:layout_height="match_parent" import android.widget.TextView;
android:gravity="center" >
public class HelloWorldActivity extends Activity {
<TextView @Override
android:id="@+id/textView1" public void onCreate(Bundle savedInstanceState) {
android:layout_width="wrap_content" super.onCreate(savedInstance State);
android:layout_height="wrap_content" setContentView(R.layout.activity_hello_world);
android:gravity="center" }
android:text="@string/hello_world"
tools:context=".HelloWorldActivity" public void changeIt(View view) {
android:textSize="46dip" /> TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!");
<Button }
android:id="@+id/button1" }
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="75dp"
android:onClick="changeIt"
android:text="Say hello" />
</LinearLayout>
Saturday, January 26, 13 32
52. <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/hello_world"
tools:context=".HelloWorldActivity"
android:textSize="46dip" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="75dp"
android:onClick="changeIt"
android:text="Say hello" />
</LinearLayout>
package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;
public class HelloWorldActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstance State);
setContentView(R.layout.activity_hello_world);
}
public void changeIt(View view) {
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText("Hello JavaZone!");
}
}
Saturday, January 26, 13 33
53. package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class HelloWorldActivity extends Activity implements
OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(this);
tv.setId(42);
tv.setText("Hello World!");
LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46);
Button btn = new Button(this);
btn.setText("Say hello");
LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this);
layout.addView(tv, tvlp);
layout.addView(btn, btnlp);
setContentView(layout);
}
public void changeIt(View view) {
TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!");
}
@Override
public void onClick(View v) {
changeIt(v);
}
}
Saturday, January 26, 13 34
54. package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class HelloWorldActivity extends Activity implements
OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(this);
tv.setId(42);
tv.setText("Hello World!");
LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46);
Button btn = new Button(this);
btn.setText("Say hello");
LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this);
layout.addView(tv, tvlp);
layout.addView(btn, btnlp);
setContentView(layout);
}
public void changeIt(View view) {
TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!");
}
@Override
public void onClick(View v) {
changeIt(v);
}
}
Saturday, January 26, 13 35
55. package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class HelloWorldActivity extends Activity implements
OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(this);
tv.setId(42);
tv.setText("Hello World!");
LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46);
Button btn = new Button(this);
btn.setText("Say hello");
LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this);
layout.addView(tv, tvlp);
layout.addView(btn, btnlp);
setContentView(layout);
}
public void changeIt(View view) {
TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!");
}
@Override
public void onClick(View v) {
changeIt(v);
}
}
Saturday, January 26, 13 36
56. package com.example.examplejavaxml; package com.example.examplejavaxml;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
public class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements
OnClickListener { OnClickListener {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(this); TextView tv = new TextView(this);
tv.setId(42); tv.setId(42);
tv.setText("Hello World!"); tv.setText("Hello World!");
LayoutParams tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46); tv.setTextSize(46);
Button btn = new Button(this); Button btn = new Button(this);
btn.setText("Say hello"); btn.setText("Say hello");
LayoutParams btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75; btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this); btn.setOnClickListener(this);
layout.addView(tv, tvlp); layout.addView(tv, tvlp);
layout.addView(btn, btnlp); layout.addView(btn, btnlp);
setContentView(layout); setContentView(layout);
} }
public void changeIt(View view) { public void changeIt(View view) {
TextView tv = (TextView) findViewById(42); TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
changeIt(v); changeIt(v);
} }
} }
Saturday, January 26, 13 37
57. package com.example.examplejavaxml; package com.example.examplejavaxml;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
public class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements
OnClickListener { OnClickListener {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(this); TextView tv = new TextView(this);
tv.setId(42); tv.setId(42);
tv.setText("Hello World!"); tv.setText("Hello World!");
LayoutParams tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46); tv.setTextSize(46);
Button btn = new Button(this); Button btn = new Button(this);
btn.setText("Say hello"); btn.setText("Say hello");
LayoutParams btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75; btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this); btn.setOnClickListener(this);
layout.addView(tv, tvlp); layout.addView(tv, tvlp);
layout.addView(btn, btnlp); layout.addView(btn, btnlp);
setContentView(layout); setContentView(layout);
} }
public void changeIt(View view) { public void changeIt(View view) {
TextView tv = (TextView) findViewById(42); TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
changeIt(v); changeIt(v);
} }
} }
Saturday, January 26, 13 38
58. package com.example.examplejavaxml;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
public class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements
OnClickListener { OnClickListener {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(this); TextView tv = new TextView(this);
tv.setId(42); tv.setId(42);
tv.setText("Hello World!"); tv.setText("Hello World!");
LayoutParams tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46); tv.setTextSize(46);
Button btn = new Button(this); Button btn = new Button(this);
btn.setText("Say hello"); btn.setText("Say hello");
LayoutParams btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75; btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this); btn.setOnClickListener(this);
layout.addView(tv, tvlp); layout.addView(tv, tvlp);
layout.addView(btn, btnlp); layout.addView(btn, btnlp);
setContentView(layout); setContentView(layout);
} }
public void changeIt(View view) { public void changeIt(View view) {
TextView tv = (TextView) findViewById(42); TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
changeIt(v); changeIt(v);
} }
} }
Saturday, January 26, 13 39
59. package com.example.examplejavaxml;
import android.os.Bundle; import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
public class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements
OnClickListener { OnClickListener {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
TextView tv = new TextView(this); TextView tv = new TextView(this);
tv.setId(42); tv.setId(42);
tv.setText("Hello World!"); tv.setText("Hello World!");
LayoutParams tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46); tv.setTextSize(46);
Button btn = new Button(this); Button btn = new Button(this);
btn.setText("Say hello"); btn.setText("Say hello");
LayoutParams btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75; btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this); btn.setOnClickListener(this);
layout.addView(tv, tvlp); layout.addView(tv, tvlp);
layout.addView(btn, btnlp); layout.addView(btn, btnlp);
setContentView(layout); setContentView(layout);
} }
public void changeIt(View view) { public void changeIt(View view) {
TextView tv = (TextView) findViewById(42); TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
changeIt(v); changeIt(v);
} }
} }
Saturday, January 26, 13 40
60. package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.Gravity; import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements
OnClickListener OnClickListener {
@Override
public onCreate( savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
tv = new TextView(this); TextView tv = new TextView(this);
tv.setId(42); tv.setId(42);
tv.setText("Hello World!"); tv.setText("Hello World!");
tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46); tv.setTextSize(46);
btn = new Button(this); Button btn = new Button(this);
btn.setText("Say hello"); btn.setText("Say hello");
btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75; btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this); btn.setOnClickListener(this);
layout.addView(tv, tvlp); layout.addView(tv, tvlp);
layout.addView(btn, btnlp); layout.addView(btn, btnlp);
setContentView(layout); setContentView(layout);
} }
public changeIt( view) { public void changeIt(View view) {
tv = findViewById(42); TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
@Override
public onClick( v) { public void onClick(View v) {
changeIt(v); changeIt(v);
} }
end }
Saturday, January 26, 13 41
61. package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.Gravity; import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements
OnClickListener OnClickListener {
@Override
public onCreate( savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
tv = new TextView(this); TextView tv = new TextView(this);
tv.setId(42); tv.setId(42);
tv.setText("Hello World!"); tv.setText("Hello World!");
tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46); tv.setTextSize(46);
btn = new Button(this); Button btn = new Button(this);
btn.setText("Say hello"); btn.setText("Say hello");
btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75; btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this); btn.setOnClickListener(this);
layout.addView(tv, tvlp); layout.addView(tv, tvlp);
layout.addView(btn, btnlp); layout.addView(btn, btnlp);
setContentView(layout); setContentView(layout);
} }
public changeIt( view) { public void changeIt(View view) {
tv = findViewById(42); TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
} }
@Override
public onClick( v) { public void onClick(View v) {
changeIt(v); changeIt(v);
} }
end }
Saturday, January 26, 13 42
62. package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.Gravity; import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements
OnClickListener OnClickListener {
@Override
def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
tv = new TextView(this); TextView tv = new TextView(this);
tv.setId(42); tv.setId(42);
tv.setText("Hello World!"); tv.setText("Hello World!");
tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46); tv.setTextSize(46);
btn = new Button(this); Button btn = new Button(this);
btn.setText("Say hello"); btn.setText("Say hello");
btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75; btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this); btn.setOnClickListener(this);
layout.addView(tv, tvlp); layout.addView(tv, tvlp);
layout.addView(btn, btnlp); layout.addView(btn, btnlp);
setContentView(layout); setContentView(layout);
end }
def changeIt( view) public void changeIt(View view) {
tv = findViewById(42); TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
end }
! @Override
def onClick( v) ! public void onClick(View v) {
changeIt(v); ! ! changeIt(v);
end ! }
end }
Saturday, January 26, 13 43
63. package com.example.examplejavaxml;
import android.os.Bundle;
import android.app.Activity; import android.app.Activity;
import android.view.Gravity; import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView; import android.widget.TextView;
class HelloWorldActivity extends Activity implements public class HelloWorldActivity extends Activity implements
OnClickListener OnClickListener {
@Override
def onCreate( savedInstanceState) public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
layout = new LinearLayout(this); LinearLayout layout = new LinearLayout(this);
layout.setGravity(Gravity.CENTER); layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.VERTICAL); layout.setOrientation(LinearLayout.VERTICAL);
tv = new TextView(this); TextView tv = new TextView(this);
tv.setId(42); tv.setId(42);
tv.setText("Hello World!"); tv.setText("Hello World!");
tvlp = new LayoutParams( LayoutParams tvlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
tvlp.gravity = Gravity.CENTER; tvlp.gravity = Gravity.CENTER;
tv.setTextSize(46); tv.setTextSize(46);
btn = new Button(this); Button btn = new Button(this);
btn.setText("Say hello"); btn.setText("Say hello");
btnlp = new LayoutParams( LayoutParams btnlp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT); LayoutParams.WRAP_CONTENT);
btnlp.topMargin = 75; btnlp.topMargin = 75;
btnlp.gravity = Gravity.CENTER; btnlp.gravity = Gravity.CENTER;
btn.setOnClickListener(this); btn.setOnClickListener(this);
layout.addView(tv, tvlp); layout.addView(tv, tvlp);
layout.addView(btn, btnlp); layout.addView(btn, btnlp);
setContentView(layout); setContentView(layout);
end }
def changeIt( view) public void changeIt(View view) {
tv = findViewById(42); TextView tv = (TextView) findViewById(42);
tv.setText("Hello JavaZone!"); tv.setText("Hello JavaZone!");
end }
! @Override
def onClick( v) ! public void onClick(View v) {
changeIt(v); ! ! changeIt(v);
end ! }
end }
Saturday, January 26, 13 44