• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Android Samples


Commit MetaInfo

修訂10c7e68b1a7e58202eff7ecb60161b388554a551 (tree)
時間2014-06-14 03:39:10
作者Masahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

Added ui-pattern-listview-crud-array module

Change Summary

差異

--- a/pom.xml
+++ b/pom.xml
@@ -122,6 +122,7 @@
122122 <module>service-start-at-boottime</module>
123123
124124 <module>ui-pattern-listview-detail-editor</module>
125+ <module>ui-pattern-listview-crud-array</module>
125126
126127 <module>view-composite-hello</module>
127128 <module>view-custom-drawing-animation</module>
--- /dev/null
+++ b/ui-pattern-listview-crud-array/AndroidManifest.xml
@@ -0,0 +1,33 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<manifest
3+ xmlns:android="http://schemas.android.com/apk/res/android"
4+ package="com.example.hello.android.ui_pattern_listview_crud_array"
5+ android:versionCode="1"
6+ android:versionName="1.0"
7+>
8+ <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="19" />
9+
10+ <application
11+ android:label="@string/app_name"
12+ >
13+ <activity
14+ android:name=".UserListActivity"
15+ android:label="@string/app_name"
16+ >
17+ <intent-filter>
18+ <action android:name="android.intent.action.MAIN" />
19+ <category android:name="android.intent.category.LAUNCHER" />
20+ </intent-filter>
21+ </activity>
22+
23+ <activity
24+ android:name=".UserDetailViewActivity"
25+ android:label="@string/user_detail"
26+ />
27+ <activity
28+ android:name=".UserDetailEditActivity"
29+ android:label="@string/edit_user"
30+ />
31+
32+ </application>
33+</manifest>
--- /dev/null
+++ b/ui-pattern-listview-crud-array/Makefile
@@ -0,0 +1,46 @@
1+
2+all : package
3+
4+#################### build
5+
6+compile :
7+ mvn $@
8+
9+gen :
10+ mvn android:generate-sources
11+
12+package :
13+ mvn $@
14+
15+release :
16+ mvn clean -Prelease package
17+
18+install :
19+ mvn $@
20+
21+deploy :
22+ mvn package android:deploy
23+
24+undeploy :
25+ mvn android:undeploy
26+
27+rebuild :
28+ mvn clean package
29+
30+redeploy :
31+ mvn clean package android:deploy
32+
33+#################### emulator
34+
35+start :
36+ mvn android:emulator-start
37+
38+stop :
39+ mvn android:emulator-stop
40+
41+####################
42+dist :
43+ mvn assembly:assembly
44+
45+clean :
46+ mvn $@
--- /dev/null
+++ b/ui-pattern-listview-crud-array/README.txt
@@ -0,0 +1,46 @@
1+! ui-pattern-listview-crud-array
2+
3+ListView に表示するデータの CRUD のサンプル。
4+データを作成して追加する。
5+この例ではArrayAdapter を使って、オンメモリの配列にのるデータを扱う。
6+一覧画面終了時に配列をシリアライズしてファイルに保存する。
7+
8+!! 処理の流れ
9+
10+!!! データの追加(Create)
11+* 一覧画面:オプションメニューから「新規追加」を選択
12+* 一覧画面:データ入力用アクティビティを起動
13+* 編集画面:データを編集
14+* 編集画面:OK、キャンセルボタンにより終了
15+* 一覧画面:結果がOKなら保存して ListView を更新
16+
17+!!! データの閲覧(Read)
18+* 一覧画面:データをタップ
19+* 一覧画面:データ詳細表示用アクティビティを起動
20+* 詳細画面:データを閲覧
21+* 詳細画面:バックボタンにより詳細画面を終了
22+* 一覧画面:結果がOKなら保存して ListView を更新
23+
24+!!! データの編集(Update)
25+* 一覧画面:編集したいデータを長押し
26+* 一覧画面:コンテキストメニューから編集を選択
27+* 編集画面:データを編集
28+* 編集画面:OK、キャンセルボタンにより編集画面を終了
29+* 一覧画面:結果がOKなら保存して ListView を更新
30+
31+!!! 単一データの削除(Delete)
32+* 一覧画面:削除したいデータを長押し
33+* 一覧画面:コンテキストメニューから削除を選択
34+* 一覧画面:確認ダイアログを表示してOKなら削除を実行
35+
36+!!! 複数データの一括削除(Delete)
37+* 一覧画面:オプションメニューから「一括削除」を選択
38+* 削除項目選択画面:削除したいものを一覧から選びチェックを付ける
39+* 削除項目選択画面:OK、キャンセルボタンにより終了
40+* 一覧画面:結果がOKなら削除対象のインデックスを受け取り削除を実行
41+
42+
43+扱うデータの内容が少ない場合、編集画面や詳細画面はダイアログや
44+一覧画面内の View で実装することでアクティビティを起動せずに行うこともできる。
45+
46+
--- /dev/null
+++ b/ui-pattern-listview-crud-array/pom.xml
@@ -0,0 +1,142 @@
1+<?xml version="1.0" encoding="UTF-8" ?>
2+<project
3+ xmlns="http://maven.apache.org/POM/4.0.0"
4+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
6+>
7+ <modelVersion>4.0.0</modelVersion>
8+ <groupId>com.example.hello</groupId>
9+ <artifactId>ui-pattern-listview-crud-array</artifactId>
10+ <packaging>apk</packaging>
11+ <version>1.0.0</version>
12+ <name>UI ListView CRUD Array</name>
13+ <url>http://www.example.com/</url>
14+
15+ <parent>
16+ <groupId>com.example.hello</groupId>
17+ <artifactId>android-samples</artifactId>
18+ <version>1.0.0</version>
19+ </parent>
20+
21+ <dependencies>
22+
23+ <dependency>
24+ <groupId>android</groupId>
25+ <artifactId>android</artifactId>
26+ <version>1.5_r4</version>
27+ <!--
28+ <version>1.5_r3</version>
29+ <version>1.5_r4</version>
30+ <version>1.6_r2</version>
31+ <version>2.1.2</version>
32+ <version>2.1_r1</version>
33+ <version>2.2.1</version>
34+ <version>2.3.1</version>
35+ <version>2.3.3</version>
36+ <version>4.0.1.2</version>
37+ -->
38+ <scope>provided</scope>
39+ </dependency>
40+
41+ <dependency>
42+ <groupId>junit</groupId>
43+ <artifactId>junit</artifactId>
44+ <scope>test</scope>
45+ </dependency>
46+ </dependencies>
47+
48+ <build>
49+ <sourceDirectory>src</sourceDirectory>
50+
51+ <plugins>
52+ <plugin>
53+ <groupId>com.jayway.maven.plugins.android.generation2</groupId>
54+ <artifactId>android-maven-plugin</artifactId>
55+ <configuration>
56+ <sdk>
57+ <!--<path>${env.ANDROID_HOME}</path>-->
58+ <platform>4</platform>
59+ </sdk>
60+ </configuration>
61+ <extensions>true</extensions>
62+ </plugin>
63+
64+ <!-- mvn compile -->
65+ <plugin>
66+ <groupId>org.apache.maven.plugins</groupId>
67+ <artifactId>maven-compiler-plugin</artifactId>
68+ <configuration>
69+ <source>1.5</source>
70+ <target>1.5</target>
71+ <encoding>UTF-8</encoding>
72+ </configuration>
73+ </plugin>
74+
75+ <!-- mvn assembly:assembly -->
76+ <plugin>
77+ <groupId>org.apache.maven.plugins</groupId>
78+ <artifactId>maven-assembly-plugin</artifactId>
79+ <configuration>
80+ <descriptorRefs>
81+ <!--
82+ <descriptorRef>jar-with-dependencies</descriptorRef>
83+ <descriptorRef>bin</descriptorRef>
84+ <descriptorRef>src</descriptorRef>
85+ -->
86+ <descriptorRef>project</descriptorRef>
87+ </descriptorRefs>
88+ </configuration>
89+ </plugin>
90+
91+ <!-- mvn resources:resources -->
92+ <plugin>
93+ <groupId>org.apache.maven.plugins</groupId>
94+ <artifactId>maven-resources-plugin</artifactId>
95+ <configuration>
96+ <encoding>UTF-8</encoding>
97+ </configuration>
98+ </plugin>
99+
100+ <!-- mvn site -->
101+ <plugin>
102+ <groupId>org.apache.maven.plugins</groupId>
103+ <artifactId>maven-site-plugin</artifactId>
104+ <configuration>
105+ <locales>en</locales>
106+ <inputEncoding>UTF-8</inputEncoding>
107+ <outputEncoding>UTF-8</outputEncoding>
108+
109+ <reportPlugins>
110+ <plugin>
111+ <groupId>org.apache.maven.plugins</groupId>
112+ <artifactId>maven-project-info-reports-plugin</artifactId>
113+ </plugin>
114+
115+ <!-- mvn javadoc:javadoc -->
116+ <plugin>
117+ <groupId>org.apache.maven.plugins</groupId>
118+ <artifactId>maven-javadoc-plugin</artifactId>
119+ <configuration>
120+ <charset>utf-8</charset>
121+ </configuration>
122+ </plugin>
123+ </reportPlugins>
124+ </configuration>
125+ </plugin>
126+
127+ </plugins>
128+
129+ <!-- mvn resources:resources -->
130+ <resources>
131+ <resource>
132+ <directory>res</directory>
133+ <filtering>false</filtering>
134+ <includes>
135+ <include>**/*.properties</include>
136+ </includes>
137+ </resource>
138+ </resources>
139+ </build>
140+
141+
142+</project>
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/layout/user_detail_edit_activity.xml
@@ -0,0 +1,91 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<LinearLayout
3+ xmlns:android="http://schemas.android.com/apk/res/android"
4+ android:layout_width="fill_parent"
5+ android:layout_height="fill_parent"
6+ android:orientation="vertical"
7+>
8+
9+ <ScrollView
10+ android:layout_width="fill_parent"
11+ android:layout_height="200dip"
12+ android:layout_weight="1"
13+ android:orientation="vertical"
14+ android:padding="4dip"
15+ >
16+ <LinearLayout
17+ android:layout_width="fill_parent"
18+ android:layout_height="fill_parent"
19+ android:orientation="vertical"
20+ android:padding="4dip"
21+ >
22+ <!-- Hidden TextView -->
23+ <TextView
24+ style="@style/value_text"
25+ android:id="@+id/id_textview"
26+ android:visibility="gone"
27+ />
28+ <TextView
29+ style="@style/header_text"
30+ android:text="@string/first_name"
31+ />
32+ <EditText
33+ style="@style/value_text"
34+ android:id="@+id/first_name_textview"
35+ android:inputType="textPersonName"
36+ />
37+ <TextView
38+ style="@style/header_text"
39+ android:text="@string/last_name"
40+ />
41+ <EditText
42+ style="@style/value_text"
43+ android:id="@+id/last_name_textview"
44+ android:inputType="textPersonName"
45+ />
46+ <TextView
47+ style="@style/header_text"
48+ android:text="@string/email"
49+ />
50+ <EditText
51+ style="@style/value_text"
52+ android:id="@+id/email_textview"
53+ android:inputType="textEmailAddress"
54+ />
55+ <TextView
56+ style="@style/header_text"
57+ android:text="@string/age"
58+ />
59+ <EditText
60+ style="@style/value_text"
61+ android:id="@+id/age_textview"
62+ android:inputType="number"
63+ />
64+
65+ </LinearLayout>
66+ </ScrollView>
67+
68+ <View style="@style/hline" />
69+
70+ <LinearLayout
71+ android:layout_width="fill_parent"
72+ android:layout_height="wrap_content"
73+ android:orientation="horizontal"
74+ >
75+ <Button
76+ android:id="@+id/cancel_button"
77+ android:layout_width="0dip"
78+ android:layout_height="wrap_content"
79+ android:layout_weight="1"
80+ android:text="@android:string/cancel"
81+ />
82+ <Button
83+ android:id="@+id/save_button"
84+ android:layout_width="0dip"
85+ android:layout_height="wrap_content"
86+ android:layout_weight="1"
87+ android:text="@string/save"
88+ />
89+ </LinearLayout>
90+
91+</LinearLayout>
\ No newline at end of file
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/layout/user_detail_view_activity.xml
@@ -0,0 +1,80 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<LinearLayout
3+ xmlns:android="http://schemas.android.com/apk/res/android"
4+ android:layout_width="fill_parent"
5+ android:layout_height="fill_parent"
6+ android:orientation="vertical"
7+>
8+
9+ <ScrollView
10+ android:layout_width="fill_parent"
11+ android:layout_height="wrap_content"
12+ android:layout_weight="1"
13+ android:orientation="vertical"
14+ android:padding="4dip"
15+ >
16+ <LinearLayout
17+ android:layout_width="fill_parent"
18+ android:layout_height="fill_parent"
19+ android:orientation="vertical"
20+ android:padding="4dip"
21+ >
22+ <!-- Hidden TextView -->
23+ <TextView
24+ style="@style/value_text"
25+ android:id="@+id/id_textview"
26+ android:visibility="gone"
27+ />
28+
29+ <TextView
30+ style="@style/header_text"
31+ android:text="@string/first_name"
32+ />
33+ <TextView
34+ style="@style/value_text"
35+ android:id="@+id/first_name_textview"
36+ />
37+ <TextView
38+ style="@style/header_text"
39+ android:text="@string/last_name"
40+ />
41+ <TextView
42+ style="@style/value_text"
43+ android:id="@+id/last_name_textview"
44+ />
45+ <TextView
46+ style="@style/header_text"
47+ android:text="@string/email"
48+ />
49+ <TextView
50+ style="@style/value_text"
51+ android:id="@+id/email_textview"
52+ />
53+ <TextView
54+ style="@style/header_text"
55+ android:text="@string/age"
56+ />
57+ <TextView
58+ style="@style/value_text"
59+ android:id="@+id/age_textview"
60+ />
61+
62+ </LinearLayout>
63+ </ScrollView>
64+
65+ <View style="@style/hline" />
66+
67+ <LinearLayout
68+ android:layout_width="fill_parent"
69+ android:layout_height="wrap_content"
70+ android:orientation="horizontal"
71+ >
72+ <Button
73+ android:id="@+id/edit_button"
74+ android:layout_width="0dip"
75+ android:layout_height="wrap_content"
76+ android:layout_weight="1"
77+ android:text="@string/edit"
78+ />
79+ </LinearLayout>
80+</LinearLayout>
\ No newline at end of file
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/layout/user_list_activity.xml
@@ -0,0 +1,61 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<LinearLayout
3+ xmlns:android="http://schemas.android.com/apk/res/android"
4+ android:layout_width="fill_parent"
5+ android:layout_height="fill_parent"
6+ android:orientation="vertical"
7+>
8+
9+ <FrameLayout
10+ android:layout_width="fill_parent"
11+ android:layout_height="wrap_content"
12+ android:layout_weight="1"
13+ android:padding="4dip"
14+ >
15+ <ListView
16+ android:id="@android:id/list"
17+ android:layout_width="fill_parent"
18+ android:layout_height="fill_parent"
19+ />
20+ <TextView
21+ android:id="@android:id/empty"
22+ android:layout_width="wrap_content"
23+ android:layout_height="wrap_content"
24+ android:layout_gravity="center"
25+ android:text="@string/no_data"
26+ />
27+ </FrameLayout>
28+
29+ <LinearLayout
30+ android:id="@+id/edit_mode_actionbar"
31+ android:layout_width="fill_parent"
32+ android:layout_height="wrap_content"
33+ android:layout_weight="0"
34+ android:orientation="vertical"
35+ android:visibility="gone"
36+ >
37+ <View style="@style/hline" />
38+ <LinearLayout
39+ android:layout_width="fill_parent"
40+ android:layout_height="wrap_content"
41+ android:layout_weight="0"
42+ android:orientation="horizontal"
43+ >
44+ <Button
45+ android:id="@+id/cancel_button"
46+ android:layout_width="0dip"
47+ android:layout_height="wrap_content"
48+ android:layout_weight="1"
49+ android:text="@android:string/cancel"
50+ />
51+ <Button
52+ android:id="@+id/delete_button"
53+ android:layout_width="0dip"
54+ android:layout_height="wrap_content"
55+ android:layout_weight="1"
56+ android:text="@string/delete"
57+ />
58+ </LinearLayout>
59+ </LinearLayout>
60+
61+</LinearLayout>
\ No newline at end of file
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/layout/user_list_item.xml
@@ -0,0 +1,79 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<view
3+ xmlns:android="http://schemas.android.com/apk/res/android"
4+ class="say.android.widget.CheckableLinearLayout"
5+ android:layout_width="fill_parent"
6+ android:layout_height="wrap_content"
7+ android:orientation="horizontal"
8+ android:padding="4dip"
9+>
10+ <LinearLayout
11+ android:layout_width="wrap_content"
12+ android:layout_height="wrap_content"
13+ android:layout_weight="1"
14+ android:orientation="vertical"
15+ >
16+ <LinearLayout
17+ android:layout_width="fill_parent"
18+ android:layout_height="wrap_content"
19+ android:orientation="horizontal"
20+ android:padding="2dip"
21+ >
22+ <TextView
23+ android:id="@+id/first_name_textview"
24+ android:layout_width="0dip"
25+ android:layout_height="wrap_content"
26+ android:layout_weight="1"
27+ android:gravity="left"
28+ android:text="&lt;FIRST_NAME&gt;"
29+ android:textSize="20sp"
30+ android:textColor="?android:attr/textColorPrimary"
31+ />
32+ <TextView
33+ android:id="@+id/last_name_textview"
34+ android:layout_width="0dip"
35+ android:layout_height="wrap_content"
36+ android:layout_weight="1"
37+ android:gravity="left"
38+ android:text="&lt;LAST_NAME&gt;"
39+ android:textSize="20sp"
40+ android:textColor="?android:attr/textColorPrimary"
41+ />
42+ </LinearLayout>
43+
44+ <LinearLayout
45+ android:layout_width="fill_parent"
46+ android:layout_height="wrap_content"
47+ android:orientation="horizontal"
48+ android:padding="2dip"
49+ >
50+ <TextView
51+ android:id="@+id/email_textview"
52+ android:layout_width="wrap_content"
53+ android:layout_height="wrap_content"
54+ android:layout_weight="1"
55+ android:gravity="left"
56+ android:text="&lt;EMAIL&gt;"
57+ android:textSize="16sp"
58+ />
59+ <TextView
60+ android:id="@+id/age_textview"
61+ android:layout_width="wrap_content"
62+ android:layout_height="wrap_content"
63+ android:layout_weight="0"
64+ android:gravity="right"
65+ android:text="&lt;AGE&gt;"
66+ android:textSize="16sp"
67+ />
68+ </LinearLayout>
69+ </LinearLayout>
70+
71+ <CheckedTextView
72+ android:id="@android:id/checkbox"
73+ android:layout_width="wrap_content"
74+ android:layout_height="wrap_content"
75+ android:layout_gravity="right"
76+ android:layout_weight="0"
77+ android:checkMark="?android:attr/listChoiceIndicatorMultiple"
78+ />
79+</view>
\ No newline at end of file
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/menu/user_list_context_menu.xml
@@ -0,0 +1,17 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+ <item
4+ android:id="@+id/edit_menuitem"
5+ android:title="@string/edit"
6+ android:icon="@android:drawable/ic_menu_edit"
7+ android:numericShortcut="1"
8+ android:alphabeticShortcut="e"
9+ />
10+ <item
11+ android:id="@+id/delete_menuitem"
12+ android:title="@string/delete"
13+ android:icon="@android:drawable/ic_menu_delete"
14+ android:numericShortcut="2"
15+ android:alphabeticShortcut="d"
16+ />
17+</menu>
\ No newline at end of file
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/menu/user_list_option_menu.xml
@@ -0,0 +1,17 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+ <item
4+ android:id="@+id/add_menuitem"
5+ android:title="@string/add"
6+ android:icon="@android:drawable/ic_menu_add"
7+ android:numericShortcut="1"
8+ android:alphabeticShortcut="a"
9+ />
10+ <item
11+ android:id="@+id/delete_selected_menuitem"
12+ android:title="@string/delete_users"
13+ android:icon="@android:drawable/ic_menu_delete"
14+ android:numericShortcut="2"
15+ android:alphabeticShortcut="a"
16+ />
17+</menu>
\ No newline at end of file
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/values/arrays_users.xml
@@ -0,0 +1,116 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<resources>
3+ <string-array name="first_names">
4+ <item>Alice</item>
5+ <item>Bob</item>
6+ <item>Charlie</item>
7+ <item>David</item>
8+ <item>Eve</item>
9+ <item>Frank</item>
10+ <item>George</item>
11+ <item>Harvey</item>
12+ <item>Ivan</item>
13+ <item>Justin</item>
14+ <item>Kyle</item>
15+ <item>Linda</item>
16+ <item>Matilda</item>
17+ <item>Natalia</item>
18+ <item>Oscar</item>
19+ <item>Pat</item>
20+ <item>Quincy</item>
21+ <item>Rachel</item>
22+ <item>Steave</item>
23+ <item>Trent</item>
24+ <item>Urien</item>
25+ <item>Victor</item>
26+ <item>Walter</item>
27+ <item>Xenia</item>
28+ <item>Yuriya</item>
29+ <item>Zoe</item>
30+ </string-array>
31+ <string-array name="last_names">
32+ <item>Smith</item>
33+ <item>Smith</item>
34+ <item>Smith</item>
35+ <item>Smith</item>
36+ <item>Smith</item>
37+ <item>Smith</item>
38+ <item>Smith</item>
39+ <item>Smith</item>
40+ <item>Smith</item>
41+ <item>Smith</item>
42+ <item>Smith</item>
43+ <item>Smith</item>
44+ <item>Smith</item>
45+ <item>Smith</item>
46+ <item>Smith</item>
47+ <item>Smith</item>
48+ <item>Smith</item>
49+ <item>Smith</item>
50+ <item>Smith</item>
51+ <item>Smith</item>
52+ <item>Smith</item>
53+ <item>Smith</item>
54+ <item>Smith</item>
55+ <item>Smith</item>
56+ <item>Smith</item>
57+ <item>Smith</item>
58+ </string-array>
59+ <string-array name="emails">
60+ <item>alice@example.com</item>
61+ <item>bob@example.com</item>
62+ <item>charlie@example.com</item>
63+ <item>david@example.com</item>
64+ <item>eve@example.com</item>
65+ <item>frank@example.com</item>
66+ <item>george@example.com</item>
67+ <item>harvey@example.com</item>
68+ <item>ivan@example.com</item>
69+ <item>justin@example.com</item>
70+ <item>kyle@example.com</item>
71+ <item>linda@example.com</item>
72+ <item>matilda@example.com</item>
73+ <item>natalia@example.com</item>
74+ <item>oscar@example.com</item>
75+ <item>pat@example.com</item>
76+ <item>quincy@example.com</item>
77+ <item>rachel@example.com</item>
78+ <item>steave@example.com</item>
79+ <item>trent@example.com</item>
80+ <item>urien@example.com</item>
81+ <item>victor@example.com</item>
82+ <item>walter@example.com</item>
83+ <item>xenia@example.com</item>
84+ <item>yuriya@example.com</item>
85+ <item>zoe@example.com</item>
86+ </string-array>
87+ <integer-array name="ages">
88+ <item>12</item>
89+ <item>21</item>
90+ <item>16</item>
91+ <item>12</item>
92+ <item>18</item>
93+ <item>13</item>
94+ <item>15</item>
95+ <item>19</item>
96+ <item>22</item>
97+ <item>25</item>
98+ <item>12</item>
99+ <item>21</item>
100+ <item>16</item>
101+ <item>12</item>
102+ <item>18</item>
103+ <item>13</item>
104+ <item>15</item>
105+ <item>19</item>
106+ <item>22</item>
107+ <item>25</item>
108+ <item>21</item>
109+ <item>18</item>
110+ <item>21</item>
111+ <item>18</item>
112+ <item>12</item>
113+ <item>21</item>
114+ </integer-array>
115+
116+</resources>
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/values/strings.xml
@@ -0,0 +1,22 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<resources>
3+ <string name="app_name">List CRUD Array</string>
4+
5+ <string name="no_data">NO DATA</string>
6+ <string name="no_email">NO EMAIL</string>
7+
8+ <string name="user_list">User List</string>
9+ <string name="user_detail">User Detail</string>
10+ <string name="edit_user">Edit User</string>
11+
12+ <string name="first_name">First name</string>
13+ <string name="last_name">Last name</string>
14+ <string name="email">E-Mail</string>
15+ <string name="age">Age</string>
16+
17+ <string name="add">Add</string>
18+ <string name="edit">Edit</string>
19+ <string name="delete">Delete</string>
20+ <string name="delete_users">Delete Users</string>
21+ <string name="save">Save</string>
22+</resources>
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/values/styles_lines.xml
@@ -0,0 +1,17 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<resources>
3+ <!-- common -->
4+ <style name="dot">
5+ <item name="android:layout_width">1dip</item>
6+ <item name="android:layout_height">1dip</item>
7+ <item name="android:layout_weight">0</item>
8+ <item name="android:layout_margin">4dip</item>
9+ <item name="android:background">#333</item>
10+ </style>
11+ <style name="vline" parent="dot" >
12+ <item name="android:layout_height">fill_parent</item>
13+ </style>
14+ <style name="hline" parent="dot" >
15+ <item name="android:layout_width">fill_parent</item>
16+ </style>
17+</resources>
--- /dev/null
+++ b/ui-pattern-listview-crud-array/res/values/styles_user_detail.xml
@@ -0,0 +1,20 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<resources>
3+ <style name="header_text">
4+ <item name="android:layout_width">fill_parent</item>
5+ <item name="android:layout_height">wrap_content</item>
6+ <item name="android:padding">4dip</item>
7+ <item name="android:gravity">left</item>
8+ <item name="android:textSize">16sp</item>
9+ <item name="android:textColor">#CCC</item>
10+ <item name="android:background">#333</item>
11+ </style>
12+ <style name="value_text">
13+ <item name="android:layout_width">fill_parent</item>
14+ <item name="android:layout_height">wrap_content</item>
15+ <item name="android:layout_margin">8dip</item>
16+ <item name="android:paddingLeft">8dip</item>
17+ <item name="android:gravity">left</item>
18+ <item name="android:textSize">20sp</item>
19+ </style>
20+</resources>
--- /dev/null
+++ b/ui-pattern-listview-crud-array/src/com/example/hello/android/ui_pattern_listview_crud_array/UserConstants.java
@@ -0,0 +1,35 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.ui_pattern_listview_crud_array;
25+
26+public interface UserConstants
27+{
28+ int REQUEST_CODE_EDIT_USER = 102;
29+
30+ String EXTRA_ID = "ID";
31+ String EXTRA_FIRST_NAME = "FIRST_NAME";
32+ String EXTRA_LAST_NAME = "LAST_NAME";
33+ String EXTRA_EMAIL = "EMAIL";
34+ String EXTRA_AGE = "AGE";
35+}
--- /dev/null
+++ b/ui-pattern-listview-crud-array/src/com/example/hello/android/ui_pattern_listview_crud_array/UserDetailEditActivity.java
@@ -0,0 +1,84 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.ui_pattern_listview_crud_array;
25+
26+import android.app.Activity;
27+import android.content.Intent;
28+import android.os.Bundle;
29+import android.util.Log;
30+import android.view.View;
31+import android.widget.Button;
32+
33+public class UserDetailEditActivity extends Activity
34+ implements View.OnClickListener, UserConstants
35+{
36+
37+ private static final String LOG_TAG = "XXX";
38+
39+ @Override
40+ protected void onCreate(Bundle savedInstanceState)
41+ {
42+ Log.v(LOG_TAG, "onCreate() : Hello");
43+ super.onCreate(savedInstanceState);
44+ setContentView(R.layout.user_detail_edit_activity);
45+
46+ Intent intent = getIntent();
47+
48+ // Bind view values
49+ UserDetailUtils.loadValuesFromIntent(this, intent);
50+
51+ // Init listeners
52+ Button cancelButton = (Button) findViewById(R.id.cancel_button);
53+ Button saveButton = (Button) findViewById(R.id.save_button);
54+ cancelButton.setOnClickListener(this);
55+ saveButton.setOnClickListener(this);
56+
57+ Log.v(LOG_TAG, "onCreate() : Bye");
58+ }
59+
60+ public void onClick(View view)
61+ {
62+ Log.v(LOG_TAG, "onClick() : Hello");
63+ switch (view.getId())
64+ {
65+ case R.id.save_button:
66+ Log.d(LOG_TAG, "onClick() : saveButton is clicked.");
67+ saveAndFinish();
68+ break;
69+ case R.id.cancel_button:
70+ setResult(Activity.RESULT_CANCELED);
71+ finish();
72+ break;
73+ }
74+ Log.v(LOG_TAG, "onClick() : Bye");
75+ }
76+
77+ private void saveAndFinish()
78+ {
79+ Intent resultIntent = new Intent();
80+ UserDetailUtils.saveValuesToIntent(this, resultIntent);
81+ setResult(Activity.RESULT_OK, resultIntent);
82+ finish();
83+ }
84+}
--- /dev/null
+++ b/ui-pattern-listview-crud-array/src/com/example/hello/android/ui_pattern_listview_crud_array/UserDetailUtils.java
@@ -0,0 +1,83 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.ui_pattern_listview_crud_array;
25+
26+import android.app.Activity;
27+import android.content.Intent;
28+import android.widget.TextView;
29+
30+/**
31+ *
32+ * @author Masahiko, SAWAI <masahiko.sawai@gmail.com>
33+ */
34+public class UserDetailUtils implements UserConstants
35+{
36+
37+ static void loadValuesFromIntent(Activity activity, Intent dataIntent)
38+ {
39+ TextView idTextView = (TextView) activity.findViewById(R.id.id_textview);
40+ TextView firstNameTextView = (TextView) activity.findViewById(R.id.first_name_textview);
41+ TextView lastNameTextView = (TextView) activity.findViewById(R.id.last_name_textview);
42+ TextView emailTextView = (TextView) activity.findViewById(R.id.email_textview);
43+ TextView ageTextView = (TextView) activity.findViewById(R.id.age_textview);
44+
45+ int id = dataIntent.getIntExtra(EXTRA_ID, -1);
46+ String firstName = dataIntent.getStringExtra(EXTRA_FIRST_NAME);
47+ String lastName = dataIntent.getStringExtra(EXTRA_LAST_NAME);
48+ String email = dataIntent.getStringExtra(EXTRA_EMAIL);
49+ int age = dataIntent.getIntExtra(EXTRA_AGE, -1);
50+
51+ idTextView.setText(String.valueOf(id));
52+ firstNameTextView.setText(firstName);
53+ lastNameTextView.setText(lastName);
54+ emailTextView.setText(email);
55+ if (age != -1)
56+ {
57+ ageTextView.setText(String.valueOf(age));
58+ }
59+ }
60+
61+ static void saveValuesToIntent(Activity activity, Intent dataIntent)
62+ {
63+ TextView idTextView = (TextView) activity.findViewById(R.id.id_textview);
64+ TextView firstNameTextView = (TextView) activity.findViewById(R.id.first_name_textview);
65+ TextView lastNameTextView = (TextView) activity.findViewById(R.id.last_name_textview);
66+ TextView emailTextView = (TextView) activity.findViewById(R.id.email_textview);
67+ TextView ageTextView = (TextView) activity.findViewById(R.id.age_textview);
68+
69+ String idText = idTextView.getText().toString();
70+ int id = Integer.parseInt(idText);
71+ String firstName = firstNameTextView.getText().toString();
72+ String lastName = lastNameTextView.getText().toString();
73+ String email = emailTextView.getText().toString();
74+ String ageText = ageTextView.getText().toString();
75+ int age = Integer.parseInt(ageText);
76+
77+ dataIntent.putExtra(EXTRA_ID, id);
78+ dataIntent.putExtra(EXTRA_FIRST_NAME, firstName);
79+ dataIntent.putExtra(EXTRA_LAST_NAME, lastName);
80+ dataIntent.putExtra(EXTRA_EMAIL, email);
81+ dataIntent.putExtra(EXTRA_AGE, age);
82+ }
83+}
--- /dev/null
+++ b/ui-pattern-listview-crud-array/src/com/example/hello/android/ui_pattern_listview_crud_array/UserDetailViewActivity.java
@@ -0,0 +1,125 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.ui_pattern_listview_crud_array;
25+
26+import android.app.Activity;
27+import android.content.Intent;
28+import android.net.Uri;
29+import android.os.Bundle;
30+import android.text.TextUtils;
31+import android.util.Log;
32+import android.view.View;
33+import android.widget.Button;
34+import android.widget.TextView;
35+
36+public class UserDetailViewActivity extends Activity
37+ implements View.OnClickListener, UserConstants
38+{
39+
40+ private static final String LOG_TAG = "XXX";
41+
42+ @Override
43+ protected void onCreate(Bundle savedInstanceState)
44+ {
45+ Log.v(LOG_TAG, "onCreate() : Hello");
46+ super.onCreate(savedInstanceState);
47+
48+ Intent intent = getIntent();
49+ setContentView(R.layout.user_detail_view_activity);
50+
51+ // Bind view values
52+ UserDetailUtils.loadValuesFromIntent(this, intent);
53+
54+ // Setup listeners
55+ Button editButton = (Button) findViewById(R.id.edit_button);
56+ editButton.setOnClickListener(this);
57+
58+ TextView emailTextView = (TextView) findViewById(R.id.email_textview);
59+ emailTextView.setOnClickListener(this);
60+
61+ Log.v(LOG_TAG, "onCreate() : Bye");
62+ }
63+
64+ public void onClick(View view)
65+ {
66+ Log.v(LOG_TAG, "onClick() : Hello");
67+ switch (view.getId())
68+ {
69+ case R.id.email_textview:
70+ startSendToEmailActivity();
71+ break;
72+ case R.id.edit_button:
73+ Log.d(LOG_TAG, "onClick() : editButton is clicked.");
74+ startEditUserActivity();
75+ }
76+
77+ Log.v(LOG_TAG, "onClick() : Bye");
78+ }
79+
80+ @Override
81+ protected void onActivityResult(int requestCode, int resultCode, Intent data)
82+ {
83+ Log.v(LOG_TAG, "onActivityResult() : Hello");
84+ if (requestCode == REQUEST_CODE_EDIT_USER && resultCode == RESULT_OK)
85+ {
86+ Log.d(LOG_TAG, "onActivityResult() : User edit is done.");
87+ int id = data.getIntExtra(UserDetailViewActivity.EXTRA_ID, -1);
88+ if (id != -1)
89+ {
90+ UserDetailUtils.loadValuesFromIntent(this, data);
91+ }
92+ setResult(RESULT_OK, data);
93+ }
94+ Log.v(LOG_TAG, "onActivityResult() : Bye");
95+ }
96+
97+ private void startEditUserActivity()
98+ {
99+ Log.v(LOG_TAG, "startEditUserActivity() : Hello");
100+
101+ Intent intent = new Intent(this, UserDetailEditActivity.class);
102+ intent.setAction(Intent.ACTION_EDIT);
103+ UserDetailUtils.saveValuesToIntent(this, intent);
104+ startActivityForResult(intent, REQUEST_CODE_EDIT_USER);
105+
106+ Log.v(LOG_TAG, "startEditUserActivity() : Bye");
107+ }
108+
109+ private void startSendToEmailActivity()
110+ {
111+ Log.v(LOG_TAG, "startSendToEmailActivity() : Hello");
112+
113+ TextView emailTextView = (TextView) findViewById(R.id.email_textview);
114+ CharSequence text = emailTextView.getText();
115+ if (TextUtils.isEmpty(text) == false)
116+ {
117+ Uri emailUri = Uri.parse("mailto:" + text);
118+ Log.d(LOG_TAG, "startSendToEmailActivity() : emailUri => " + emailUri);
119+ Intent intent = new Intent(Intent.ACTION_SENDTO, emailUri);
120+ startActivity(intent);
121+ }
122+
123+ Log.v(LOG_TAG, "startSendToEmailActivity() : Bye");
124+ }
125+}
--- /dev/null
+++ b/ui-pattern-listview-crud-array/src/com/example/hello/android/ui_pattern_listview_crud_array/UserInfo.java
@@ -0,0 +1,97 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.ui_pattern_listview_crud_array;
25+
26+import java.io.Serializable;
27+
28+/**
29+ *
30+ * @author sawai
31+ */
32+public class UserInfo implements Serializable
33+{
34+
35+ private String firstName;
36+ private String lastName;
37+ private String email;
38+ private int age;
39+
40+ public UserInfo()
41+ {
42+ }
43+
44+ public UserInfo(String firstName, String lastName, String email, int age)
45+ {
46+ this.firstName = firstName;
47+ this.lastName = lastName;
48+ this.email = email;
49+ this.age = age;
50+ }
51+
52+ public int getAge()
53+ {
54+ return age;
55+ }
56+
57+ public void setAge(int age)
58+ {
59+ this.age = age;
60+ }
61+
62+ public String getFirstName()
63+ {
64+ return firstName;
65+ }
66+
67+ public void setFirstName(String firstName)
68+ {
69+ this.firstName = firstName;
70+ }
71+
72+ public String getLastName()
73+ {
74+ return lastName;
75+ }
76+
77+ public void setLastName(String lastName)
78+ {
79+ this.lastName = lastName;
80+ }
81+
82+ public String getEmail()
83+ {
84+ return email;
85+ }
86+
87+ public void setEmail(String email)
88+ {
89+ this.email = email;
90+ }
91+
92+ @Override
93+ public String toString()
94+ {
95+ return "UserInfo{" + "firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + ", age=" + age + '}';
96+ }
97+}
--- /dev/null
+++ b/ui-pattern-listview-crud-array/src/com/example/hello/android/ui_pattern_listview_crud_array/UserListActivity.java
@@ -0,0 +1,448 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.ui_pattern_listview_crud_array;
25+
26+import android.app.ListActivity;
27+import android.content.Intent;
28+import android.os.Bundle;
29+import android.util.Log;
30+import android.util.SparseBooleanArray;
31+import android.view.ContextMenu;
32+import android.view.ContextMenu.ContextMenuInfo;
33+import android.view.Menu;
34+import android.view.MenuInflater;
35+import android.view.MenuItem;
36+import android.view.View;
37+import android.widget.AdapterView;
38+import android.widget.AdapterView.AdapterContextMenuInfo;
39+import android.widget.AdapterView.OnItemClickListener;
40+import android.widget.Button;
41+import android.widget.ListView;
42+import java.io.File;
43+import java.io.FileInputStream;
44+import java.io.FileOutputStream;
45+import java.io.IOException;
46+import java.io.ObjectInputStream;
47+import java.io.ObjectOutputStream;
48+import java.util.ArrayList;
49+import java.util.List;
50+
51+public class UserListActivity extends ListActivity
52+ implements OnItemClickListener, View.OnClickListener, UserConstants
53+{
54+
55+ private static final String LOG_TAG = "XXX";
56+ private static final String USER_LIST_FILE_NAME = "user_list.ser";
57+ // Child activity request code
58+ private static final int REQUEST_CODE_VIEW_USER = 101;
59+ private static final int REQUEST_CODE_EDIT_USER = 102;
60+ private static final int REQUEST_CODE_ADD_USER = 103;
61+ // instances
62+ private final List<UserInfo> userList = new ArrayList<UserInfo>();
63+ private UserListAdapter userListAdapter;
64+ private boolean editMode = false;
65+
66+ public boolean isEditMode()
67+ {
68+ return editMode;
69+ }
70+
71+ public void setEditMode(boolean newMode)
72+ {
73+ if (this.editMode != newMode)
74+ {
75+ this.editMode = newMode;
76+ if (this.editMode)
77+ {
78+ enterEditMode();
79+ }
80+ else
81+ {
82+ enterViewMode();
83+ }
84+ }
85+ }
86+
87+ @Override
88+ protected void onCreate(Bundle savedInstanceState)
89+ {
90+ Log.v(LOG_TAG, "onCreate() : Hello");
91+
92+ super.onCreate(savedInstanceState);
93+ setContentView(R.layout.user_list_activity);
94+
95+ loadUserList();
96+
97+ // Init ListAdapter
98+ userListAdapter = new UserListAdapter(this, userList);
99+ setListAdapter(userListAdapter);
100+
101+ Button cancelButton = (Button) findViewById(R.id.cancel_button);
102+ Button deleteButton = (Button) findViewById(R.id.delete_button);
103+ cancelButton.setOnClickListener(this);
104+ deleteButton.setOnClickListener(this);
105+
106+ // default mode
107+ enterViewMode();
108+
109+ Log.v(LOG_TAG, "onCreate() : Bye");
110+ }
111+
112+ @Override
113+ protected void onActivityResult(int requestCode, int resultCode, Intent data)
114+ {
115+ Log.v(LOG_TAG, "onActivityResult() : Hello");
116+ if ((requestCode == REQUEST_CODE_EDIT_USER || requestCode == REQUEST_CODE_VIEW_USER)
117+ && resultCode == RESULT_OK)
118+ {
119+ Log.d(LOG_TAG, "onActivityResult() : user edit is done.");
120+ Log.d(LOG_TAG, "onActivityResult() : data => " + data);
121+ int id = data.getIntExtra(EXTRA_ID, -1);
122+ if (id >= 0 && id < userList.size())
123+ {
124+ String firstName = data.getStringExtra(EXTRA_FIRST_NAME);
125+ String lastName = data.getStringExtra(EXTRA_LAST_NAME);
126+ String email = data.getStringExtra(EXTRA_EMAIL);
127+ int age = data.getIntExtra(EXTRA_AGE, -1);
128+
129+ UserInfo userInfo = userList.get(id);
130+ userInfo.setFirstName(firstName);
131+ userInfo.setLastName(lastName);
132+ userInfo.setEmail(email);
133+ userInfo.setAge(age);
134+ saveUserList();
135+ userListAdapter.notifyDataSetChanged();
136+ }
137+ }
138+ else if (requestCode == REQUEST_CODE_ADD_USER && resultCode == RESULT_OK)
139+ {
140+ Log.d(LOG_TAG, "onActivityResult() : new user edit is done.");
141+ String firstName = data.getStringExtra(EXTRA_FIRST_NAME);
142+ String lastName = data.getStringExtra(EXTRA_LAST_NAME);
143+ String email = data.getStringExtra(EXTRA_EMAIL);
144+ int age = data.getIntExtra(EXTRA_AGE, -1);
145+
146+ UserInfo userInfo = new UserInfo(firstName, lastName, email, age);
147+ userList.add(userInfo);
148+ saveUserList();
149+ userListAdapter.notifyDataSetChanged();
150+ }
151+ Log.v(LOG_TAG, "onActivityResult() : Bye");
152+ }
153+
154+ @Override
155+ protected void onResume()
156+ {
157+ Log.v(LOG_TAG, "onResume() : Hello");
158+ super.onResume();
159+ loadUserList();
160+ userListAdapter.notifyDataSetChanged();
161+ Log.v(LOG_TAG, "onResume() : Bye");
162+ }
163+
164+ @Override
165+ protected void onPause()
166+ {
167+ Log.v(LOG_TAG, "onPause() : Hello");
168+ saveUserList();
169+ super.onPause();
170+ Log.v(LOG_TAG, "onPause() : Bye");
171+ }
172+
173+ @Override
174+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
175+ {
176+ Log.v(LOG_TAG, "onCreateContextMenu() : Hello");
177+ super.onCreateContextMenu(menu, v, menuInfo);
178+
179+ MenuInflater menuInflater = getMenuInflater();
180+ menuInflater.inflate(R.menu.user_list_context_menu, menu);
181+ Log.v(LOG_TAG, "onCreateContextMenu() : Bye");
182+ }
183+
184+ @Override
185+ public boolean onContextItemSelected(MenuItem item)
186+ {
187+ boolean result;
188+ AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
189+ Log.v(LOG_TAG, "onCreateContextMenu() : list item position => " + menuInfo.position);
190+ Log.v(LOG_TAG, "onCreateContextMenu() : list item id => " + menuInfo.id);
191+ Log.v(LOG_TAG, "onCreateContextMenu() : list item targetView => " + menuInfo.targetView);
192+ Log.v(LOG_TAG, "onCreateContextMenu() : list item userInfo => " + userList.get(menuInfo.position));
193+
194+ int itemId = item.getItemId();
195+ switch (itemId)
196+ {
197+ case R.id.edit_menuitem:
198+ editUserAt(menuInfo.position);
199+ result = true;
200+ break;
201+ case R.id.delete_menuitem:
202+ deleteUserAt(menuInfo.position);
203+ result = true;
204+ break;
205+ default:
206+ result = super.onContextItemSelected(item);
207+ }
208+
209+ return result;
210+ }
211+
212+ public void onItemClick(AdapterView<?> parentView, View view, int position, long id)
213+ {
214+ Log.v(LOG_TAG, "onItemClick() : Hello");
215+ Log.d(LOG_TAG, "onItemClick() : position => " + position);
216+ viewUserDetailAt(position);
217+
218+ Log.v(LOG_TAG, "onItemClick() : Bye");
219+ }
220+
221+ @Override
222+ public boolean onCreateOptionsMenu(Menu menu)
223+ {
224+ MenuInflater menuInflater = getMenuInflater();
225+ menuInflater.inflate(R.menu.user_list_option_menu, menu);
226+ return true;
227+ }
228+
229+ @Override
230+ public boolean onOptionsItemSelected(MenuItem item)
231+ {
232+ int itemId = item.getItemId();
233+ switch (itemId)
234+ {
235+ case R.id.add_menuitem:
236+ addNewUser();
237+ break;
238+ case R.id.delete_selected_menuitem:
239+ setEditMode(true);
240+ break;
241+ }
242+ return super.onOptionsItemSelected(item);
243+ }
244+
245+ public void onClick(View view)
246+ {
247+ int viewId = view.getId();
248+ switch (viewId)
249+ {
250+ case R.id.cancel_button:
251+ setEditMode(false);
252+ break;
253+ case R.id.delete_button:
254+ deleteCheckedUser();
255+ setEditMode(false);
256+ break;
257+ }
258+ }
259+
260+ private void loadUserList()
261+ {
262+ try
263+ {
264+ Log.d(LOG_TAG, "Load data from file.");
265+ File userListFilePath = getFileStreamPath(USER_LIST_FILE_NAME);
266+ FileInputStream fileInputStream = new FileInputStream(userListFilePath);
267+ try
268+ {
269+ ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
270+ Object readObject = objectInputStream.readObject();
271+ if (readObject instanceof List)
272+ {
273+ List<UserInfo> loadedUserList = (List<UserInfo>) readObject;
274+ userList.clear();
275+ userList.addAll(loadedUserList);
276+ }
277+ }
278+ finally
279+ {
280+ fileInputStream.close();
281+ }
282+ }
283+ catch (IOException ex)
284+ {
285+ Log.e(LOG_TAG, "Load user list from file.", ex);
286+ }
287+ catch (ClassNotFoundException ex)
288+ {
289+ Log.e(LOG_TAG, "Load user list from file.", ex);
290+ }
291+
292+ if (userList.isEmpty())
293+ {
294+ loadInitialData();
295+ }
296+ }
297+
298+ private void loadInitialData()
299+ {
300+ Log.d(LOG_TAG, "Load initial data from resources.");
301+ // initial data
302+ String[] firstNames = getResources().getStringArray(R.array.first_names);
303+ String[] lastNames = getResources().getStringArray(R.array.last_names);
304+ String[] emails = getResources().getStringArray(R.array.emails);
305+ int[] ages = getResources().getIntArray(R.array.ages);
306+ for (int i = 0; i < firstNames.length; i++)
307+ {
308+ UserInfo userInfo = new UserInfo(firstNames[i], lastNames[i], emails[i], ages[i]);
309+ userList.add(userInfo);
310+ }
311+ }
312+
313+ private void saveUserList()
314+ {
315+ Log.v(LOG_TAG, "saveUserList() : Hello");
316+
317+ try
318+ {
319+ File userListFilePath = getFileStreamPath(USER_LIST_FILE_NAME);
320+ FileOutputStream fileOutputStream = new FileOutputStream(userListFilePath);
321+ try
322+ {
323+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
324+ objectOutputStream.writeObject(userList);
325+ }
326+ finally
327+ {
328+ fileOutputStream.close();
329+ }
330+ }
331+ catch (IOException ex)
332+ {
333+ Log.e(LOG_TAG, "Load user list from file.", ex);
334+ }
335+
336+ Log.v(LOG_TAG, "saveUserList() : Bye");
337+ }
338+
339+ private void addNewUser()
340+ {
341+ Intent intent = new Intent(this, UserDetailEditActivity.class);
342+ intent.setAction(Intent.ACTION_INSERT);
343+ startActivityForResult(intent, REQUEST_CODE_ADD_USER);
344+ }
345+
346+ private void viewUserDetailAt(int index)
347+ {
348+ UserInfo userInfo = userList.get(index);
349+ String firstName = userInfo.getFirstName();
350+ String lastName = userInfo.getLastName();
351+ String email = userInfo.getEmail();
352+ int age = userInfo.getAge();
353+
354+ Intent intent = new Intent(this, UserDetailViewActivity.class);
355+ intent.setAction(Intent.ACTION_VIEW);
356+ intent.putExtra(EXTRA_ID, index);
357+ intent.putExtra(EXTRA_FIRST_NAME, firstName);
358+ intent.putExtra(EXTRA_LAST_NAME, lastName);
359+ intent.putExtra(EXTRA_EMAIL, email);
360+ intent.putExtra(EXTRA_AGE, age);
361+ startActivityForResult(intent, REQUEST_CODE_VIEW_USER);
362+ }
363+
364+ private void editUserAt(int index)
365+ {
366+ UserInfo userInfo = userList.get(index);
367+ String firstName = userInfo.getFirstName();
368+ String lastName = userInfo.getLastName();
369+ String email = userInfo.getEmail();
370+ int age = userInfo.getAge();
371+
372+ Intent intent = new Intent(this, UserDetailEditActivity.class);
373+ intent.setAction(Intent.ACTION_EDIT);
374+ intent.putExtra(EXTRA_ID, index);
375+ intent.putExtra(EXTRA_FIRST_NAME, firstName);
376+ intent.putExtra(EXTRA_LAST_NAME, lastName);
377+ intent.putExtra(EXTRA_EMAIL, email);
378+ intent.putExtra(EXTRA_AGE, age);
379+ startActivityForResult(intent, REQUEST_CODE_EDIT_USER);
380+ }
381+
382+ private void deleteUserAt(int index)
383+ {
384+ Log.v(LOG_TAG, "deleteUser() : Hello");
385+ if (index >= 0 && index < userList.size())
386+ {
387+ userList.remove(index);
388+ userListAdapter.notifyDataSetChanged();
389+ Log.v(LOG_TAG, "deleteUser() : user removed at => " + index);
390+ }
391+ Log.v(LOG_TAG, "deleteUser() : Bye");
392+ }
393+
394+ private void enterViewMode()
395+ {
396+ Log.v(LOG_TAG, "enterViewMode() : Hello");
397+
398+ ListView listView = getListView();
399+ listView.setChoiceMode(ListView.CHOICE_MODE_NONE);
400+ listView.setOnItemClickListener(this);
401+ registerForContextMenu(listView);
402+
403+ View editModeActionbarView = findViewById(R.id.edit_mode_actionbar);
404+ editModeActionbarView.setVisibility(View.GONE);
405+
406+ userListAdapter.setCheckable(false);
407+ userListAdapter.notifyDataSetChanged();
408+
409+ Log.v(LOG_TAG, "enterViewMode() : Bye");
410+ }
411+
412+ private void enterEditMode()
413+ {
414+ Log.v(LOG_TAG, "enterEditMode() : Hello");
415+
416+ ListView listView = getListView();
417+ listView.clearChoices();
418+ listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
419+ listView.setOnItemClickListener(null);
420+ unregisterForContextMenu(listView);
421+
422+ View editModeActionbarView = findViewById(R.id.edit_mode_actionbar);
423+ editModeActionbarView.setVisibility(View.VISIBLE);
424+
425+ userListAdapter.setCheckable(true);
426+ userListAdapter.notifyDataSetChanged();
427+
428+ Log.v(LOG_TAG, "enterEditMode() : Bye");
429+ }
430+
431+ private void deleteCheckedUser()
432+ {
433+ Log.v(LOG_TAG, "deleteCheckedUser() : Hello");
434+ SparseBooleanArray checkedItemPositions = getListView().getCheckedItemPositions();
435+ for (int i = checkedItemPositions.size() - 1; i >= 0; i--)
436+ {
437+ int userListIndex = checkedItemPositions.keyAt(i);
438+ boolean checked = checkedItemPositions.get(userListIndex);
439+ Log.v(LOG_TAG, "deleteCheckedUser() : i => " + i + ", key => " + userListIndex + ", checked => " + checked);
440+ if (checked)
441+ {
442+ userList.remove(userListIndex);
443+ }
444+ }
445+
446+ Log.v(LOG_TAG, "deleteCheckedUser() : Bye");
447+ }
448+}
--- /dev/null
+++ b/ui-pattern-listview-crud-array/src/com/example/hello/android/ui_pattern_listview_crud_array/UserListAdapter.java
@@ -0,0 +1,105 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.ui_pattern_listview_crud_array;
25+
26+import android.content.Context;
27+import android.view.LayoutInflater;
28+import android.view.View;
29+import android.view.ViewGroup;
30+import android.widget.ArrayAdapter;
31+import android.widget.CheckedTextView;
32+import android.widget.TextView;
33+import java.util.List;
34+
35+public class UserListAdapter extends ArrayAdapter<UserInfo>
36+{
37+
38+ private LayoutInflater inflater;
39+ private boolean checkable;
40+
41+ public UserListAdapter(Context context, List<UserInfo> objects)
42+ {
43+ super(context, android.R.id.text1, objects);
44+ inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
45+ }
46+
47+ @Override
48+ public View getView(int position, View convertView, ViewGroup parent)
49+ {
50+ View result;
51+ if (convertView == null)
52+ {
53+ result = inflater.inflate(R.layout.user_list_item, null);
54+ }
55+ else
56+ {
57+ result = convertView;
58+ }
59+
60+ UserInfo user = getItem(position);
61+ if (user != null)
62+ {
63+ TextView firstNameTextView = (TextView) result.findViewById(R.id.first_name_textview);
64+ firstNameTextView.setText(user.getFirstName());
65+
66+ TextView lastNameTextView = (TextView) result.findViewById(R.id.last_name_textview);
67+ lastNameTextView.setText(user.getLastName());
68+
69+ TextView ageTextView = (TextView) result.findViewById(R.id.age_textview);
70+ ageTextView.setText(String.valueOf(user.getAge()));
71+
72+ String email = user.getEmail();
73+ TextView emailTextView = (TextView) result.findViewById(R.id.email_textview);
74+ if (email != null)
75+ {
76+ emailTextView.setText(email);
77+ }
78+ else
79+ {
80+ emailTextView.setText(R.string.no_email);
81+ }
82+
83+ CheckedTextView checkbox = (CheckedTextView) result.findViewById(android.R.id.checkbox);
84+ if (isCheckable())
85+ {
86+ checkbox.setVisibility(View.VISIBLE);
87+ }
88+ else
89+ {
90+ checkbox.setVisibility(View.GONE);
91+ }
92+ }
93+ return result;
94+ }
95+
96+ public boolean isCheckable()
97+ {
98+ return checkable;
99+ }
100+
101+ public void setCheckable(boolean checkable)
102+ {
103+ this.checkable = checkable;
104+ }
105+}
--- /dev/null
+++ b/ui-pattern-listview-crud-array/src/say/android/widget/CheckableLinearLayout.java
@@ -0,0 +1,83 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2014 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package say.android.widget;
25+
26+import android.content.Context;
27+import android.util.AttributeSet;
28+import android.view.View;
29+import android.widget.Checkable;
30+import android.widget.LinearLayout;
31+
32+/**
33+ *
34+ * @author sawai
35+ */
36+public class CheckableLinearLayout extends LinearLayout implements Checkable
37+{
38+
39+ private static final String LOG_TAG = "XXX";
40+ private Checkable checkableView;
41+
42+ public CheckableLinearLayout(Context context, AttributeSet attrs)
43+ {
44+ super(context, attrs);
45+ }
46+
47+ public CheckableLinearLayout(Context context)
48+ {
49+ super(context);
50+ }
51+
52+ public Checkable getCheckableView()
53+ {
54+ if (checkableView == null)
55+ {
56+ View view = this.findViewById(android.R.id.checkbox);
57+ if (view instanceof Checkable)
58+ {
59+ checkableView = (Checkable) view;
60+ }
61+ else
62+ {
63+ throw new IllegalStateException("No Checkable View");
64+ }
65+ }
66+ return checkableView;
67+ }
68+
69+ public void toggle()
70+ {
71+ getCheckableView().toggle();
72+ }
73+
74+ public void setChecked(boolean checked)
75+ {
76+ getCheckableView().setChecked(checked);
77+ }
78+
79+ public boolean isChecked()
80+ {
81+ return getCheckableView().isChecked();
82+ }
83+}