CS 683 Emerging Technologies Fall Semester, 2008 Doc 17 Android 2 Nov 18 2008
CS 683 Emerging Technologies Fall Semester, 2008 Doc 17 Android 2 Nov 18 2008
2
Building Blocks Of Android Application
AndroidManifest.xml
Activities
Views
Intents
Services
Notifications
Content Providers
3
AndroidManifest.xml
Contains information about the application needed by the phone to run it
@string/app_name indicates that the string is to be found in the string resource file under the label app_name.
Activities
5
View
6
Intent
Used to move from screen to screen
Contains
Data
Action
What you want done
MAIN, VIEW, PICK, EDIT, etc
Intent filter
What intents an activity can handle
7
Service
No UI
Example
music player
8
Notifications
9
Content Holder
Address book
10
XML Views Example
package com.android.hello2;
import android.app.Activity;
import android.os.Bundle;
11
src/com.android/hello2/R.java
package com.android.hello2;
//Autogenerated
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int Foo=0x7f040002;
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
12
res/layout/main.xml
13
Measurement Units
px pixels
dip device independent pixels
sp scaled pixels — best for text size
pt points
in inches
mm millimeters
14
XML Attributes
android.R.styleable
Defines all xml attributes
http://code.google.com/android/reference/android/R.styleable.html
15
package com.android.hello2;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
16
Viewing the Log
Start ddms
Al pro 12->ddms
17
Log Methods
Error In order of verbosity
e(String tag, String message, Throwable throw)
e(String tag, String message)
WARN
w(String tag, String message, Throwable throw)
w(String tag, String message)
INFO
i(String tag, String message, Throwable throw)
i(String tag, String message)
DEBUG
d(String tag, String message, Throwable throw)
d(String tag, String message)
VERBOSE (only for development)
v(String tag, String message, Throwable throw)
v(String tag, String message)
18
Development Tools
Android Emulator
sqlite3 Database
Traceview
19
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
20
main.xml with id
21
@ symbol in the id tells the XML parser should parse and expand the rest
"+" indicates that a resource should be created if is does not already exist
See id.message exists now
23
Listeners
GestureDetector.OnGestureListener Notify when gestures occur
MenuItem.OnMenuItemClickListener a menu item is clicked.
View.OnClickListener a view is clicked.
View.OnCreateContextMenuListener the context menu for this view is being built.
View.OnFocusChangeListener the focus state of a view changed.
View.OnKeyListener a key event is dispatched to this view.
View.OnLongClickListener a view has been clicked and held.
View.OnTouchListener a touch event is dispatched to this view.
ViewGroup.OnHierarchyChangeListener the hierarchy within this view changed.
ViewStub.OnInflateListener ViewStub has successfully inflated its layout resource.
ViewTreeObserver.OnGlobalFocusChangeListener the focus state within the view tree changes.
the global layout state or the visibility of views within
ViewTreeObserver.OnGlobalLayoutListener
the view tree changes.
ViewTreeObserver.OnPreDrawListener the view tree is about to be drawn.
ViewTreeObserver.OnTouchModeChangeListener the touch mode changes.
24
26
27
Menus
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
29
Menus Cont.
30
This method is called just before your menu is to be displayed. In it you can modify the menu to meet the current needs. In this
example it is not needed, but is here to make sure you know about it.
res/values/strings.xml
<string name="menu_click">Click</string>
<string name="menu_mom">Hi Mom</string>
</resources>
31
Display
32