• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

Commit MetaInfo

修訂7e1c94641d80172a607f016ae490389e5fa2cabd (tree)
時間2012-10-22 00:53:25
作者Masahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

IntentDetailActivity2 を ListView としてテスト実装

Change Summary

差異

--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
1+/intent-lab/target/
\ No newline at end of file
--- a/intent-lab/AndroidManifest.xml
+++ b/intent-lab/AndroidManifest.xml
@@ -29,8 +29,8 @@
2929 </intent-filter>
3030 </activity>
3131
32- <!-- Intent Detail Viewer -->
33- <activity android:name=".intent.IntentDetailViewerActivity" >
32+ <!-- Intent Detail -->
33+ <activity android:name=".intent.IntentDetailActivity" >
3434 <intent-filter>
3535 <action android:name="android.intent.action.VIEW" />
3636 <category android:name="android.intent.category.DEFAULT" />
@@ -38,10 +38,10 @@
3838 </intent-filter>
3939 </activity>
4040
41- <!-- Intent Editor -->
42- <activity android:name=".intent.IntentDetailEditorActivity" >
41+ <!-- Intent Detail -->
42+ <activity android:name=".intent.IntentDetailActivity2" >
4343 <intent-filter>
44- <action android:name="android.intent.action.EDIT" />
44+ <action android:name="android.intent.action.VIEW" />
4545 <category android:name="android.intent.category.DEFAULT" />
4646 <data android:mimeType="vnd.android.cursor.item/vnd.routine_work.intent" />
4747 </intent-filter>
--- /dev/null
+++ b/intent-lab/res/layout/intent_detail_activity2.xml
@@ -0,0 +1,30 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+ android:layout_width="fill_parent"
4+ android:layout_height="fill_parent"
5+ android:orientation="vertical"
6+>
7+ <!-- action bar -->
8+ <LinearLayout
9+ style="@style/actionbar"
10+ >
11+ <ImageButton
12+ style="@style/actionbar_left_button"
13+ android:id="@+id/home_button"
14+ android:src="?attr/ic_home"
15+ />
16+ <TextView
17+ style="@style/actionbar_title"
18+ android:text="@string/edit_intent"
19+ />
20+ <ImageButton
21+ style="@style/actionbar_right_button"
22+ android:id="@+id/ok_button"
23+ android:src="?attr/ic_ok"
24+ />
25+ </LinearLayout>
26+
27+ <!-- list -->
28+ <include layout="@layout/simple_list" />
29+
30+</LinearLayout>
\ No newline at end of file
--- /dev/null
+++ b/intent-lab/res/layout/intent_detail_item.xml
@@ -0,0 +1,119 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<FrameLayout
3+ xmlns:android="http://schemas.android.com/apk/res/android"
4+ android:layout_width="fill_parent"
5+ android:layout_height="wrap_content"
6+>
7+ <!-- Title -->
8+ <LinearLayout
9+ android:id="@+id/intent_detail_item_name"
10+ android:layout_width="fill_parent"
11+ android:layout_height="wrap_content"
12+ android:orientation="vertical"
13+ >
14+ <TextView
15+ style="@style/header"
16+ android:text="@string/title"
17+ />
18+ <TextView
19+ android:id="@+id/name_textview"
20+ android:layout_width="fill_parent"
21+ android:layout_height="wrap_content"
22+ android:layout_margin="6dip"
23+ android:textSize="20sp"
24+ android:textColor="?android:textColorPrimary"
25+ />
26+ </LinearLayout>
27+
28+ <!-- Action -->
29+ <LinearLayout
30+ android:id="@+id/intent_detail_item_action"
31+ android:layout_width="fill_parent"
32+ android:layout_height="wrap_content"
33+ android:orientation="vertical"
34+ >
35+ <TextView
36+ style="@style/header"
37+ android:text="@string/action"
38+ />
39+
40+ <TextView
41+ style="@style/key"
42+ android:text="@string/action_name"
43+ />
44+ <TextView
45+ style="@style/value"
46+ android:id="@+id/action_textview"
47+ />
48+ </LinearLayout>
49+
50+ <!-- Component -->
51+ <LinearLayout
52+ android:id="@+id/intent_detail_item_component"
53+ android:layout_width="fill_parent"
54+ android:layout_height="wrap_content"
55+ android:orientation="vertical"
56+ >
57+ <TextView
58+ style="@style/header"
59+ android:text="@string/component"
60+ />
61+ <TextView
62+ style="@style/key"
63+ android:text="@string/component_package"
64+ />
65+ <TextView
66+ style="@style/value"
67+ android:id="@+id/component_package_textview"
68+ />
69+ <TextView
70+ style="@style/key"
71+ android:text="@string/component_class"
72+ />
73+ <TextView
74+ style="@style/value"
75+ android:id="@+id/component_class_textview"
76+ />
77+ </LinearLayout>
78+
79+ <!-- Data URI-->
80+ <LinearLayout
81+ android:id="@+id/intent_detail_item_data_uri"
82+ android:layout_width="fill_parent"
83+ android:layout_height="wrap_content"
84+ android:orientation="vertical"
85+ >
86+ <TextView
87+ style="@style/header"
88+ android:text="@string/data"
89+ />
90+
91+ <TextView
92+ style="@style/key"
93+ android:text="@string/data_uri"
94+ />
95+ <TextView
96+ style="@style/value"
97+ android:id="@+id/data_uri_textview"
98+ />
99+
100+ </LinearLayout>
101+
102+ <!-- Data Type-->
103+ <LinearLayout
104+ android:id="@+id/intent_detail_item_data_type"
105+ android:layout_width="fill_parent"
106+ android:layout_height="wrap_content"
107+ android:orientation="vertical"
108+ >
109+ <TextView
110+ style="@style/key"
111+ android:text="@string/data_type"
112+ />
113+ <TextView
114+ style="@style/value"
115+ android:id="@+id/data_type_textview"
116+ />
117+ </LinearLayout>
118+
119+</FrameLayout>
\ No newline at end of file
--- a/intent-lab/src/org/routine_work/intent_lab/intent/IntentDetailActivity.java
+++ b/intent-lab/src/org/routine_work/intent_lab/intent/IntentDetailActivity.java
@@ -229,7 +229,7 @@ public class IntentDetailActivity extends Activity
229229 {
230230 if (cursor.moveToFirst())
231231 {
232- int titleColumnIndex = cursor.getColumnIndex(IntentStore.Intents.Columns.TITLE);
232+ int titleColumnIndex = cursor.getColumnIndex(IntentStore.Intents.Columns.NAME);
233233 title = cursor.getString(titleColumnIndex);
234234 }
235235 }
--- /dev/null
+++ b/intent-lab/src/org/routine_work/intent_lab/intent/IntentDetailActivity2.java
@@ -0,0 +1,332 @@
1+package org.routine_work.intent_lab.intent;
2+
3+import android.app.Activity;
4+import android.app.ListActivity;
5+import android.content.ComponentName;
6+import android.content.ContentResolver;
7+import android.content.Intent;
8+import android.database.Cursor;
9+import android.net.Uri;
10+import android.os.Bundle;
11+import android.view.LayoutInflater;
12+import android.view.View;
13+import android.view.ViewGroup;
14+import android.widget.BaseAdapter;
15+import android.widget.ImageButton;
16+import android.widget.TextView;
17+import android.widget.Toast;
18+import org.routine_work.intent_lab.R;
19+import org.routine_work.intent_lab.intent.provider.IntentStore;
20+import org.routine_work.utils.Log;
21+
22+public class IntentDetailActivity2 extends ListActivity
23+ implements View.OnClickListener
24+{
25+
26+ private static final String LOG_TAG = "intent-lab";
27+ private static final int POSITION_NAME = 0;
28+ private static final int POSITION_ACTION = 1;
29+ private static final int POSITION_COMPONENT = 2;
30+ private static final int POSITION_DATA_URI = 3;
31+ private static final int POSITION_DATA_TYPE = 4;
32+ // data
33+ private Uri targetUri;
34+ private String targetName;
35+ private Intent targetIntent;
36+ private IntentDetailListAdapter intentDetailListAdapter;
37+
38+ public void onClick(View view)
39+ {
40+ int id = view.getId();
41+ switch (id)
42+ {
43+ case R.id.home_button:
44+ finish();
45+ break;
46+ }
47+ }
48+
49+ @Override
50+ protected void onCreate(Bundle savedInstanceState)
51+ {
52+ Log.v(LOG_TAG, "Hello");
53+
54+ super.onCreate(savedInstanceState);
55+ setContentView(R.layout.intent_detail_activity2);
56+
57+ ImageButton homeButton = (ImageButton) findViewById(R.id.home_button);
58+ homeButton.setOnClickListener(this);
59+
60+ // init
61+ targetUri = getIntent().getData();
62+ if (targetUri != null)
63+ {
64+
65+ ContentResolver cr = getContentResolver();
66+ targetName = loadName(cr);
67+ targetIntent = IntentStore.fetchIntent(cr, targetUri);
68+ }
69+
70+ // init list adapter
71+ if (targetIntent == null)
72+ {
73+ Toast.makeText(this, "No such intent exist.", Toast.LENGTH_SHORT).show();
74+ finish();
75+ }
76+ else
77+ {
78+ intentDetailListAdapter = new IntentDetailListAdapter();
79+ setListAdapter(intentDetailListAdapter);
80+ }
81+
82+ Log.v(LOG_TAG, "Bye");
83+ }
84+
85+ private String loadName(ContentResolver cr)
86+ {
87+ String title = null;
88+
89+ // load title
90+ if (targetUri != null)
91+ {
92+ Cursor cursor = cr.query(targetUri, null, null, null, null);
93+ if (cursor != null)
94+ {
95+ try
96+ {
97+ if (cursor.moveToFirst())
98+ {
99+ int titleColumnIndex = cursor.getColumnIndex(IntentStore.Intents.Columns.NAME);
100+ title = cursor.getString(titleColumnIndex);
101+ }
102+ }
103+ finally
104+ {
105+ cursor.close();
106+ }
107+ }
108+ }
109+
110+ return title;
111+ }
112+
113+ /*
114+
115+ private void initializeCategories(Intent targetIntent)
116+ {
117+ Log.v(LOG_TAG, "Hello");
118+
119+ Set<String> categories = targetIntent.getCategories();
120+ Log.d(LOG_TAG, "categories => " + categories);
121+ if (categories != null)
122+ {
123+ ViewGroup categoriesViewGroup = (ViewGroup) findViewById(R.id.categories_section);
124+ categoriesViewGroup.removeAllViews();
125+
126+ LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
127+ for (String category : categories)
128+ {
129+ View categoryItem = inflater.inflate(R.layout.category_list_item, categoriesViewGroup, true);
130+ TextView categoryTextView = (TextView) categoryItem.findViewById(R.id.category_textview);
131+ categoryTextView.setText(category);
132+ }
133+ }
134+
135+ Log.v(LOG_TAG, "Bye");
136+ }
137+
138+ private void initializeExtras(Intent targetIntent)
139+ {
140+ Log.v(LOG_TAG, "Hello");
141+
142+ Bundle extras = targetIntent.getExtras();
143+ Log.d(LOG_TAG, "extras => " + extras);
144+ if (extras != null)
145+ {
146+ ViewGroup extrasViewGroup = (ViewGroup) findViewById(R.id.extras_section);
147+ extrasViewGroup.removeAllViews();
148+
149+ LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
150+ for (String key : extras.keySet())
151+ {
152+ Object value = extras.get(key);
153+ String type = value.getClass().getSimpleName();
154+ Log.d(LOG_TAG, "extra key => " + key);
155+ Log.d(LOG_TAG, "extra value => " + value);
156+
157+ View extraItem = inflater.inflate(R.layout.extra_list_item, extrasViewGroup, true);
158+ TextView keyTextView = (TextView) extraItem.findViewById(R.id.extra_key_textview);
159+ TextView typeTextView = (TextView) extraItem.findViewById(R.id.extra_type_textview);
160+ TextView valueTextView = (TextView) extraItem.findViewById(R.id.extra_value_textview);
161+
162+ keyTextView.setText(key);
163+ typeTextView.setText(type);
164+ valueTextView.setText(value.toString());
165+ }
166+ }
167+ Log.v(LOG_TAG, "Bye");
168+ }
169+
170+ private void initializeFlags(Intent targetIntent)
171+ {
172+ Log.v(LOG_TAG, "Hello");
173+
174+ int flags = targetIntent.getFlags();
175+ Log.d(LOG_TAG, "flags => " + flags);
176+ if (flags != 0)
177+ {
178+ ViewGroup flagsViewGroup = (ViewGroup) findViewById(R.id.flags_section);
179+ flagsViewGroup.removeAllViews();
180+
181+ LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
182+ for (int i = 0; i < IntentFlags.FLAG_VALUES.length; i++)
183+ {
184+ int flagValue = IntentFlags.FLAG_VALUES[i];
185+ String flagName = IntentFlags.FLAG_NAMES[i];
186+ if ((flags & flagValue) != 0)
187+ {
188+ Log.d(LOG_TAG, "flag name => " + flagName);
189+ View flagItem = inflater.inflate(R.layout.flag_list_item, flagsViewGroup, true);
190+ TextView flagNameTextView = (TextView) flagItem.findViewById(R.id.flag_name_textview);
191+ flagNameTextView.setText(flagName);
192+ }
193+ }
194+ }
195+
196+ Log.v(LOG_TAG, "Bye");
197+ }
198+ */
199+ class IntentDetailListAdapter extends BaseAdapter
200+ {
201+
202+ private LayoutInflater inflater;
203+
204+ public IntentDetailListAdapter()
205+ {
206+ inflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
207+ }
208+
209+ public int getCount()
210+ {
211+ return 5;
212+ }
213+
214+ public Object getItem(int position)
215+ {
216+ Object result = null;
217+ switch (position)
218+ {
219+ case POSITION_NAME:
220+ result = targetName;
221+ break;
222+ case POSITION_ACTION:
223+ result = targetIntent.getAction();
224+ break;
225+ case POSITION_COMPONENT:
226+ result = targetIntent.getComponent();
227+ break;
228+ case POSITION_DATA_URI:
229+ result = targetIntent.getData();
230+ break;
231+ case POSITION_DATA_TYPE:
232+ result = targetIntent.getType();
233+ break;
234+ }
235+ return result;
236+ }
237+
238+ public long getItemId(int position)
239+ {
240+ return position;
241+ }
242+
243+ public View getView(int position, View convertView, ViewGroup parent)
244+ {
245+ View itemView;
246+ Log.d(LOG_TAG, "Hello");
247+
248+ if (convertView == null)
249+ {
250+ itemView = inflater.inflate(R.layout.intent_detail_item, null);
251+ }
252+ else
253+ {
254+ itemView = convertView;
255+ }
256+ View nameView = itemView.findViewById(R.id.intent_detail_item_name);
257+ View actionView = itemView.findViewById(R.id.intent_detail_item_action);
258+ View componentView = itemView.findViewById(R.id.intent_detail_item_component);
259+ View dataUriView = itemView.findViewById(R.id.intent_detail_item_data_uri);
260+ View dataTypeView = itemView.findViewById(R.id.intent_detail_item_data_type);
261+
262+ nameView.setVisibility(View.GONE);
263+ actionView.setVisibility(View.GONE);
264+ componentView.setVisibility(View.GONE);
265+ dataUriView.setVisibility(View.GONE);
266+ dataTypeView.setVisibility(View.GONE);
267+
268+ Object item = getItem(position);
269+ switch (position)
270+ {
271+ case POSITION_NAME:
272+ String nameText = null;
273+ if (item instanceof String)
274+ {
275+ nameText = (String) item;
276+ }
277+ TextView nameTextView = (TextView) nameView.findViewById(R.id.name_textview);
278+ nameTextView.setText(nameText);
279+ nameView.setVisibility(View.VISIBLE);
280+ break;
281+ case POSITION_ACTION:
282+ String actionText = null;
283+ if (item instanceof String)
284+ {
285+ actionText = (String) item;
286+ }
287+ TextView titleTextView = (TextView) actionView.findViewById(R.id.action_textview);
288+ titleTextView.setText(actionText);
289+ actionView.setVisibility(View.VISIBLE);
290+ break;
291+ case POSITION_COMPONENT:
292+ String componentPackageText = null;
293+ String componentClassText = null;
294+ ComponentName componentName = (ComponentName) item;
295+ if (componentName != null)
296+ {
297+ componentPackageText = componentName.getPackageName();
298+ componentClassText = componentName.getClassName();
299+ }
300+ TextView componentPackageTextView = (TextView) componentView.findViewById(R.id.component_package_textview);
301+ TextView componentClassTextView = (TextView) componentView.findViewById(R.id.component_class_textview);
302+ componentPackageTextView.setText(componentPackageText);
303+ componentClassTextView.setText(componentClassText);
304+ componentView.setVisibility(View.VISIBLE);
305+ break;
306+ case POSITION_DATA_URI:
307+ String dataUriText = null;
308+ if (item instanceof Uri)
309+ {
310+ dataUriText = item.toString();
311+ }
312+ TextView dataUriTextView = (TextView) dataUriView.findViewById(R.id.data_uri_textview);
313+ dataUriTextView.setText(dataUriText);
314+ dataUriView.setVisibility(View.VISIBLE);
315+ break;
316+ case POSITION_DATA_TYPE:
317+ String dataTypeText = null;
318+ if (item instanceof String)
319+ {
320+ dataTypeText = (String) item;
321+ }
322+ TextView dataTypeTextView = (TextView) dataTypeView.findViewById(R.id.data_type_textview);
323+ dataTypeTextView.setText(dataTypeText);
324+ dataTypeView.setVisibility(View.VISIBLE);
325+ break;
326+ }
327+
328+ Log.d(LOG_TAG, "Bye");
329+ return itemView;
330+ }
331+ }
332+}
--- a/intent-lab/src/org/routine_work/intent_lab/intent/IntentListActivity.java
+++ b/intent-lab/src/org/routine_work/intent_lab/intent/IntentListActivity.java
@@ -33,7 +33,7 @@ public class IntentListActivity extends ListActivity
3333 // init ListAdapter
3434 private static final String[] MAPPING_FROM =
3535 {
36- IntentStore.Intents.Columns.TITLE,
36+ IntentStore.Intents.Columns.NAME,
3737 IntentStore.Intents.Columns.ACTION,
3838 };
3939 private static final int[] MAPPING_TO =
--- a/intent-lab/src/org/routine_work/intent_lab/intent/provider/IntentDBConstants.java
+++ b/intent-lab/src/org/routine_work/intent_lab/intent/provider/IntentDBConstants.java
@@ -45,23 +45,23 @@ interface IntentDBConstants
4545 String DATA = "_data";
4646 String CREATED = "created";
4747 String MODIFIED = "modified";
48- String TITLE = "title";
48+ String NAME = "name";
4949 String ACTION = "action"; // Intent.getAction()
5050 String DATA_URI = "data_uri"; // Intent.getData()
5151 }
5252 // CREATE SQL
5353 static final String CREATE_TABLE_SQL = "CREATE TABLE " + TABLE_NAME + "("
5454 + " " + Columns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT"
55+ + ", " + Columns.NAME + " TEXT"
5556 + ", " + Columns.DATA + " TEXT"
56- + ", " + Columns.TITLE + " TEXT"
57- + ", " + Columns.CREATED + " INTEGER"
58- + ", " + Columns.MODIFIED + " INTEGER"
57+ + ", " + Columns.CREATED + " INTEGER NOT NULL"
58+ + ", " + Columns.MODIFIED + " INTEGER NOT NULL"
5959 + ", " + Columns.ACTION + " TEXT"
6060 + ", " + Columns.DATA_URI + " TEXT"
6161 + ");";
6262 String CREATE_TITLE_INDEX_SQL = "CREATE INDEX "
63- + TABLE_NAME + "_" + Columns.TITLE + "_index "
64- + "ON " + TABLE_NAME + "(" + Columns.TITLE + ");";
63+ + TABLE_NAME + "_" + Columns.NAME + "_index "
64+ + "ON " + TABLE_NAME + "(" + Columns.NAME + ");";
6565 String CREATE_CREATED_INDEX_SQL = "CREATE INDEX "
6666 + TABLE_NAME + "_" + Columns.CREATED + "_index "
6767 + "ON " + TABLE_NAME + "(" + Columns.CREATED + ");";
--- a/intent-lab/src/org/routine_work/intent_lab/intent/provider/IntentStore.java
+++ b/intent-lab/src/org/routine_work/intent_lab/intent/provider/IntentStore.java
@@ -59,7 +59,7 @@ public class IntentStore
5959 String DATA = IntentDBConstants.Intents.Columns.DATA;
6060 String CREATED = IntentDBConstants.Intents.Columns.CREATED;
6161 String MODIFIED = IntentDBConstants.Intents.Columns.MODIFIED;
62- String TITLE = IntentDBConstants.Intents.Columns.TITLE;
62+ String NAME = IntentDBConstants.Intents.Columns.NAME;
6363 String ACTION = IntentDBConstants.Intents.Columns.ACTION;
6464 String DATA_URI = IntentDBConstants.Intents.Columns.DATA_URI;
6565 }
@@ -111,7 +111,7 @@ public class IntentStore
111111 String dataUri = intent.getDataString();
112112 long now = new Date().getTime();
113113 ContentValues initialValues = new ContentValues();
114- initialValues.put(Intents.Columns.TITLE, title);
114+ initialValues.put(Intents.Columns.NAME, title);
115115 initialValues.put(Intents.Columns.ACTION, action);
116116 initialValues.put(Intents.Columns.DATA_URI, dataUri);
117117 initialValues.put(Intents.Columns.CREATED, now);