Basic UI: View, ViewGroups : Intents, Activities : Life Cycle

108 views
Skip to first unread message

Jose Collas

unread,
Jan 3, 2012, 11:14:01 PM1/3/12
to Seattle Java Android Study Sessions
This is the news group subject for the study topic:
Basic UI: View, ViewGroups : Intents, Activities : Life Cycle

Presenter: Jose Collas

I will be using this material:
the web site:
http://developer.android.com/guide/index.html
and the book: Programming Android
http://shop.oreilly.com/product/0636920010364.do

To create Vivace:

https://github.com/goatstone/Vivace

A general purpose application to demonstrate the topics covered in the
second series of Java/Android Study sessions.

I will present this materiel to the group.
On the 9th of January 2012 : 6:30PM
At Vivace cafe:
227 Yale Ave N
Seattle, WA 98109

Jose Collas

unread,
Jan 9, 2012, 5:21:47 PM1/9/12
to Seattle Java Android Study Sessions
Getting the Code:

the git command:

git clone g...@github.com:goatstone/Vivace.git


Go to Eclipse, under:
File ->
New -> Android Project

When the dialog appears:
For Name put in:

Vivace

click:
"Create project from existing source"

and under "Location" select the folder you have just cloned from
github "Vivace"

and click

"Finnish"
Message has been deleted

Jose Collas

unread,
Jan 9, 2012, 5:26:34 PM1/9/12
to Seattle Java Android Study Sessions

Jose Collas

unread,
Jan 9, 2012, 6:24:35 PM1/9/12
to Seattle Java Android Study Sessions
Notes for the study session 1.9.2012

"View, ViewGroups : Intents, Activities : Life Cycle"

======================
Views

Extends Object

Built in:
Button restart

Custom to Vivace:
SpriteCanvas spriteCanvas

"This class represents the basic building block for user interface
components."
"View is the base class for widgets, which are used to create
interactive UI components (buttons, text fields, etc.)."*


======================
ViewGroups

Extends View

Application ViewGroups:
MainLayout(Programmatic)
Preferences(XML)

The Base class for layouts

"A ViewGroup is a special view that can contain other views (called
children.)
The view group is the base class for layouts and views containers.
This class also defines the ViewGroup.LayoutParams class
which serves as the base class for layouts parameters."*

It can be defined with XML or with code. What are the pros and cons of
the two?


======================
Intents

Vivace uses intents to navigate from the Main screen to the
Preferences screen.

"An intent is an abstract description of an operation to be performed.
It can be used with startActivity to launch an Activity,"*

Intent intent = new Intent(spriteCanvas.getContext(),
Preferences.class);
// intent.putExtra("ballSize", String.valueOf(ballSize));
intent.putExtra("ballSize", String.valueOf((int) Ball.rad));
// startActivity(intent);
startActivityForResult(intent, 1);


======================
Activities

"An activity is a single, focused thing that the user can do. Almost
all activities interact with the user, so the Activity class takes
care of creating a window for you in which you can place your UI with
setContentView(View)."*

The example app. Vivace has two Activities:

Vivace
Preferences

The activity Vivacy is the main screen while, Preferences only
modifies a user preference.
The Activity Preferences takes a dotSize value and returns dotSize
value that the user has selected.
This Activity simply gets a value and returns a value, promoting
Activity independence.


======================
Object Independence With Events.
This is about Java not Android specifically.
I am only suggesting and experimenting with this in the context of
Android.
How else can this be done?
How do different classes communicate?

In Vivace the Sprites have a event system.
The Ball objects raise BallCaught events and scoring is done based on
these.

In the com.vivace.event package:

interface SpiteEventListener extends EventListener

class BallCaught extends EventObject
public BallCaught(Object source, int points) {
super(source);
this.points = points;
}


Inside Sprite:

public void setSpriteListener(SpiteEventListener listener) {
events.add(listener);
}


protected void trigger(EventObject evt) {
for (Object o : events) {
((SpiteEventListener) o).eventOccurred(evt);
}
}

Inside Vivace:
// b is the sprite 'Ball'.
b.setSpriteListener(new SpiteEventListener() {
@Override
public void eventOccurred(EventObject evt) {
if (evt.getClass().getSimpleName().equals("BallCaught")) {
// do something when the "BallCaught" event occurs
}
}
});

Inside Ball:
// trigger the event BallCaught with the points for this ball
trigger(new BallCaught(this, points));

// listen for the events internally
setSpriteListener(new SpiteEventListener() {
public void eventOccurred(EventObject evt) {
// do something when the event occurs
}
});



* Quotes from Google Reference Site:
http://developer.android.com/reference/

Jose Collas

unread,
Jan 9, 2012, 6:25:39 PM1/9/12
to Seattle Java Android Study Sessions
-

Jose Collas

unread,
Jan 10, 2012, 4:03:42 PM1/10/12
to Seattle Java Android Study Sessions
!!! UPDATE !!!!

A lot of people are ending up with a target SDK version 4 set when the
app. should have SDK 2.1.

So instead of clicking,

"Finish"

on the last step, as above,

Click:

"Next"

and select as the build target:

Android 2.1



Jose Collas

unread,
Jan 10, 2012, 4:06:54 PM1/10/12
to Seattle Java Android Study Sessions
-
Reply all
Reply to author
Forward
0 new messages