4. Two Activities in Advent
Devotions displays a single
AdventDevos displays the
Devo
l
l
l
calendar of dates
devotion
• Intent myIntent = new Intent(AdventDevos.this, Devo.class);
• myIntent.putExtra("ButtonNum", "" + index);
• startActivity(myIntent);
5. l
l
Two Activities in Advent
Devotions
AdventDevos displays the
calendar of dates
l
Devo displays a single
devotion
• Bundle extras = getIntent().getExtras();
• String value = extras.getString("ButtonNum");
• Integer buttonNum = Integer.valueOf(value);
6. l
l
Launching an Intent you didn’t
write
Devos has button to
URL
l
Browser launched
Intent i = new Intent(Intent.ACTION_VIEW,
•
Uri.parse("http://www.biblegateway.com/passage/?search="+
•
passage +"&version=NIV"));
• startActivity(i);
l
7. l
l
Android Activity
“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).”
• http://developer.android.com/reference/android/app/
• Activity.html#ActivityLifecycle
8. l
AndroidManifest.xml
•
• <?xml version="1.0" encoding="utf-8"?> Each upload to Market requires versionCode increment
• <manifest xmlns:android="http://schemas.android.com/apk/res/android"
•
package="com.simexusa.adventdevotions"
•
android:versionCode="2"
• Specifies icon for launching app
•
android:versionName="1.0">
•
<application android:icon="@drawable/star" android:label="@string/app_name" android:debu
•
<activity android:name=".AdventDevos"
•
android:label="@string/app_name">
• Specifies icon for launching app
•
<intent-filter>
•
<action android:name="android.intent.action.MAIN" />
•
<category android:name="android.intent.category.LAUNCHER" />
•
</intent-filter>
•
</activity>
•
<activity android:name=".Devo"/>
•
</application>
• Specifies activity to be launched at startup
•
<uses-sdk android:minSdkVersion="3" />
•
<uses-permission android:name="android.permission.INTERNET" />
• </manifest>
• Security permissions requested from user on install
10. l
l
Layouts and Resources
See main.xml and devo.xml
l Activity associates with layout xml file using
setContentView(R.layout.main); or
setContentView(R.layout.devo); in onCreate()
l Note TableLayout and TableRow similar to <table>
and <tr> in html
l Note use of dimen (see values/dimens.xml) and color
(see values/colors.xml)
l Also see strings.xml
11. l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@color/background">
<TableLayout android:layout_width="wrap_content"
android:id="@+id/TableLayout01" android:layout_height="wrap_content">
<TableRow android:paddingTop="8px">
<Button android:text="Nov. 29" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="@dimen/button_width"></Button>
<Button android:text="Nov. 30" android:id="@+id/Button02"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="@dimen/button_width"></Button>
<Button android:text="Dec. 1" android:id="@+id/Button03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="@dimen/button_width"></Button>
<Button android:text="Dec. 2" android:id="@+id/Button04"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="@dimen/button_width"></Button>
</TableRow> …
12. l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
devo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center_horizontal"
android:background="@color/background">
<TextView android:text="Date" android:id="@+id/Date"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:textStyle="italic"
android:textSize="@dimen/reference_width" android:typeface="serif"
android:textColor="@color/text"></TextView>
<TextView android:text="Title" android:id="@+id/Title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:textStyle="bold"
android:textSize="@dimen/reference_width" android:typeface="serif"
android:textColor="@color/text"></TextView>
<Button android:text="Read Scripture" android:id="@+id/ButtonScripture"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:textSize="@dimen/reference_width"></Button>
<ScrollView android:id="@+id/ScrollView01"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView android:text="Body" android:id="@+id/Body"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left" android:textSize="@dimen/reference_width"
android:typeface="serif" android:textColor="@color/text"></TextView>
13. l
dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="button_width">17sp</dimen>
<dimen name="reference_width">20sp</dimen>
</resources>
l
l
l
l
l
• colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#AAFFFF99</color>
<color name="text">#FF000000</color>
</resources>
l
l
l
l
l
• strings.xml
l
l
l
l
l
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, AdventDevos!</string>
<string name="app_name">Advent Devotions</string>
</resources>