• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Révision66e9850b98a642c3c11b5b2724db7c38718fa5a2 (tree)
l'heure2013-04-20 10:46:11
AuteurMasahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Message de Log

IntentDetailActivity にアクション編集機能を実装

Change Summary

Modification

--- a/doc/ToDo.txt
+++ b/doc/ToDo.txt
@@ -12,4 +12,5 @@
1212
1313 * ResolveInfoListActivity
1414 ** 各項目にデフォルト設定済みかどうかが分かるようにしたい
15+** 可能かどうか調べる
1516
--- a/intent-lab/AndroidManifest.xml
+++ b/intent-lab/AndroidManifest.xml
@@ -60,8 +60,9 @@
6060 <activity android:name=".common.EditTextActivity" />
6161
6262 <!-- content provider -->
63- <provider android:name=".intent.provider.IntentProvider"
64- android:authorities="org.routine_work.intent_laboratory.intentsprovider"
63+ <provider
64+ android:name=".intent.provider.IntentProvider"
65+ android:authorities="org.routine_work.intent_laboratory.intentsprovider"
6566 />
6667
6768 </application>
--- a/intent-lab/res/layout/action_list_activity.xml
+++ b/intent-lab/res/layout/action_list_activity.xml
@@ -13,14 +13,31 @@
1313 android:id="@+id/home_button"
1414 android:src="?attr/ic_home"
1515 />
16+ <!-- View Mode -->
1617 <TextView
1718 style="@style/actionbar_title"
19+ android:id="@+id/title_textview"
1820 android:text="@string/select_action"
1921 />
2022 <ImageButton
2123 style="@style/actionbar_right_button"
22- android:id="@+id/ok_button"
23- android:src="?attr/ic_ok"
24+ android:id="@+id/search_button"
25+ android:src="?attr/ic_search"
26+ />
27+ <!-- Search Mode -->
28+ <EditText
29+ style="@style/actionbar_edittext"
30+ android:id="@+id/search_edittext"
31+ android:hint="@string/search_action_hint"
32+ android:inputType="text"
33+ android:visibility="gone"
34+ android:imeOptions="actionSearch"
35+ />
36+ <ImageButton
37+ style="@style/actionbar_right_button"
38+ android:id="@+id/cancel_search_button"
39+ android:src="?attr/ic_clear"
40+ android:visibility="gone"
2441 />
2542 </LinearLayout>
2643
--- a/intent-lab/res/layout/intent_detail_activity.xml
+++ b/intent-lab/res/layout/intent_detail_activity.xml
@@ -17,11 +17,13 @@
1717 style="@style/actionbar_title"
1818 android:text="@string/edit_intent"
1919 />
20+ <!--
2021 <ImageButton
2122 style="@style/actionbar_right_button"
2223 android:id="@+id/ok_button"
2324 android:src="?attr/ic_ok"
2425 />
26+ -->
2527 </LinearLayout>
2628
2729 <!-- list -->
--- a/intent-lab/res/values/strings.xml
+++ b/intent-lab/res/values/strings.xml
@@ -49,5 +49,7 @@
4949 <!-- ActionList -->
5050 <string name="action_list">Action List</string>
5151 <string name="select_action">Select Action</string>
52+ <string name="search_action_hint">Select action</string>
53+ <string name="search_action_description">Select action</string>
5254
5355 </resources>
--- a/intent-lab/src/org/routine_work/intent_lab/action/ActionListActivity.java
+++ b/intent-lab/src/org/routine_work/intent_lab/action/ActionListActivity.java
@@ -3,33 +3,70 @@ package org.routine_work.intent_lab.action;
33 import android.app.ListActivity;
44 import android.content.Intent;
55 import android.os.Bundle;
6+import android.view.KeyEvent;
67 import android.view.View;
78 import android.view.View.OnClickListener;
9+import android.view.inputmethod.EditorInfo;
10+import android.widget.AdapterView;
11+import android.widget.EditText;
812 import android.widget.ImageButton;
913 import android.widget.ListView;
1014 import android.widget.SimpleAdapter;
15+import android.widget.TextView;
1116 import java.lang.reflect.Field;
1217 import java.lang.reflect.Modifier;
1318 import java.util.ArrayList;
1419 import java.util.HashMap;
1520 import java.util.List;
1621 import java.util.Map;
22+import java.util.Map.Entry;
1723 import org.routine_work.intent_lab.R;
24+import org.routine_work.utils.IMEUtils;
1825 import org.routine_work.utils.Log;
1926
2027 /**
2128 * 端末のOSの android.content.Intent クラスに定義されているアクションの一覧を表示する.
2229 * 他のクラスで定義されているアクションは表示されない.
30+ *
2331 * @author sawai
2432 */
2533 public class ActionListActivity extends ListActivity
26- implements OnClickListener
34+ implements OnClickListener,
35+ AdapterView.OnItemClickListener,
36+ TextView.OnEditorActionListener
2737 {
38+
2839 public static final String EXTRA_ACTION_STRING = "EXTRA_ACTION_NAME";
2940 private static final String LOG_TAG = "intent-lab";
3041 private static final String KEY_ACTION_NAME = "ActionName";
3142 private static final String KEY_ACTION_STRING = "ActionValue";
43+ private static final String SAVE_KEY_ACTION_MODE = "actionMode";
3244 private static final List<Map<String, String>> ACTION_DATA_LIST;
45+ private static final int ACTION_MODE_NORMAL = 0;
46+ private static final int ACTION_MODE_SEARCH = 1;
47+ private static final Map<Integer, Boolean>[] ACTION_ITEM_VISIBILITY = new Map[]
48+ {
49+ new HashMap<Integer, Boolean>()
50+ { // view mode
51+
52+ {
53+ this.put(R.id.title_textview, true);
54+ this.put(R.id.search_button, true);
55+ this.put(R.id.search_edittext, false);
56+ this.put(R.id.cancel_search_button, false);
57+ }
58+ },
59+ new HashMap<Integer, Boolean>()
60+ { // search mode
61+
62+ {
63+ this.put(R.id.title_textview, false);
64+ this.put(R.id.search_button, false);
65+ this.put(R.id.search_edittext, true);
66+ this.put(R.id.cancel_search_button, true);
67+ }
68+ },
69+ };
3370 private static final String[] MAPPING_FROM = new String[]
3471 {
3572 KEY_ACTION_NAME,
@@ -40,7 +77,9 @@ public class ActionListActivity extends ListActivity
4077 android.R.id.text1,
4178 android.R.id.text2,
4279 };
80+ private int actionMode = -1;
4381 private ListView listView;
82+ private EditText searchEditText;
4483
4584 static
4685 {
@@ -80,66 +119,71 @@ public class ActionListActivity extends ListActivity
80119 }
81120 }
82121
83- /** Called when the activity is first created. */
122+ /**
123+ * Called when the activity is first created.
124+ */
84125 @Override
85- public void onCreate(Bundle savedInstanceState)
126+ protected void onCreate(Bundle savedInstanceState)
86127 {
87128 Log.d(LOG_TAG, "ActionListActivity#onCreate() Hello");
88129 super.onCreate(savedInstanceState);
89130 setContentView(R.layout.action_list_activity);
90131
91- Intent intent = getIntent();
92- String action = intent.getAction();
93- String actionString = intent.getStringExtra(EXTRA_ACTION_STRING);
94- Log.d(LOG_TAG, "action => " + action);
95132
96133 listView = (ListView) findViewById(android.R.id.list);
97- ImageButton okButton = (ImageButton) findViewById(R.id.ok_button);
98134 ImageButton homeButton = (ImageButton) findViewById(R.id.home_button);
135+ homeButton.setOnClickListener(this);
99136
100- if (Intent.ACTION_PICK.equals(action))
101- {
102- Log.d(LOG_TAG, "ActionListActivity#onCreate() ACTION_PICK");
137+ // view mode items
138+ ImageButton searchButton = (ImageButton) findViewById(R.id.search_button);
139+ searchButton.setOnClickListener(this);
140+
141+ // search mode items
142+ searchEditText = (EditText) findViewById(R.id.search_edittext);
143+ searchEditText.setOnEditorActionListener(this);
144+ ImageButton cancelSearchButton = (ImageButton) findViewById(R.id.cancel_search_button);
145+ cancelSearchButton.setOnClickListener(this);
103146
104- SimpleAdapter simpleAdapter = new SimpleAdapter(this, ACTION_DATA_LIST,
105- R.layout.action_list_item_single_choice,
106- MAPPING_FROM, MAPPING_TO);
107- setListAdapter(simpleAdapter);
147+ SimpleAdapter simpleAdapter = new SimpleAdapter(this,
148+ ACTION_DATA_LIST,
149+ R.layout.action_list_item,
150+ MAPPING_FROM, MAPPING_TO);
151+ setListAdapter(simpleAdapter);
108152
109- listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
110- setItemCheckedByActionString(actionString);
153+ listView.setChoiceMode(ListView.CHOICE_MODE_NONE);
154+ listView.setOnItemClickListener(this);
111155
112- okButton.setOnClickListener(this);
113- okButton.setVisibility(View.VISIBLE);
114- homeButton.setOnClickListener(this);
115- homeButton.setVisibility(View.VISIBLE);
156+ if (savedInstanceState != null)
157+ {
158+ int mode = savedInstanceState.getInt(SAVE_KEY_ACTION_MODE);
159+ setActionMode(mode);
116160 }
117161 else
118162 {
119- Log.d(LOG_TAG, "ActionListActivity#onCreate() ACTION_VIEW");
120-
121- SimpleAdapter simpleAdapter = new SimpleAdapter(this, ACTION_DATA_LIST,
122- R.layout.action_list_item,
123- MAPPING_FROM, MAPPING_TO);
124- setListAdapter(simpleAdapter);
125-
126- listView.setChoiceMode(ListView.CHOICE_MODE_NONE);
127-
128- okButton.setVisibility(View.GONE);
129- homeButton.setOnClickListener(this);
130- homeButton.setVisibility(View.VISIBLE);
163+ setActionMode(ACTION_MODE_NORMAL);
131164 }
132165
133166 Log.d(LOG_TAG, "ActionListActivity#onCreate() Bye");
134167 }
135168
169+ @Override
170+ protected void onSaveInstanceState(Bundle outState)
171+ {
172+ outState.putInt(SAVE_KEY_ACTION_MODE, actionMode);
173+ super.onSaveInstanceState(outState);
174+ }
175+
176+ @Override
136177 public void onClick(View view)
137178 {
138179 int id = view.getId();
139180 switch (id)
140181 {
141- case R.id.ok_button:
142- ok();
182+ case R.id.search_button:
183+ enterSearchMode();
184+ break;
185+ case R.id.cancel_search_button:
186+ leaveSearchMode();
143187 break;
144188 case R.id.home_button:
145189 cancel();
@@ -148,23 +192,29 @@ public class ActionListActivity extends ListActivity
148192 }
149193 }
150194
151- private void ok()
195+ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
152196 {
153- int position = listView.getCheckedItemPosition();
154- Log.d(LOG_TAG, "checkedItemPosition => " + position);
155- if (position >= 0)
156- {
157- Map<String, String> data = ACTION_DATA_LIST.get(position);
158- String actionString = data.get(KEY_ACTION_STRING);
159- Intent resultIntent = new Intent();
160- resultIntent.putExtra(EXTRA_ACTION_STRING, actionString);
161- setResult(RESULT_OK, resultIntent);
162- }
163- else
197+ Log.v(LOG_TAG, "Hello");
198+ Log.v(LOG_TAG, "position => " + position + ", id => " + id);
199+
200+ Map<String, String> actionData = ACTION_DATA_LIST.get(position);
201+ String actionString = actionData.get(KEY_ACTION_STRING);
202+ Intent resultIntent = new Intent();
203+ resultIntent.putExtra(EXTRA_ACTION_STRING, actionString);
204+ setResult(RESULT_OK, resultIntent);
205+ finish();
206+
207+ Log.v(LOG_TAG, "Bye");
208+ }
209+
210+ // TextView.OnEditorActionListener
211+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
212+ {
213+ if (actionId == EditorInfo.IME_ACTION_SEARCH)
164214 {
165- setResult(RESULT_CANCELED);
215+ IMEUtils.hideSoftKeyboardWindow(this, v);
166216 }
167- finish();
217+ return true;
168218 }
169219
170220 private void cancel()
@@ -173,26 +223,59 @@ public class ActionListActivity extends ListActivity
173223 finish();
174224 }
175225
176- private void setItemCheckedByActionString(String actionString)
226+ private void setActionMode(int newActionMode)
177227 {
178- Log.d(LOG_TAG, "ActionListActivity#setItemCheckedByActionString() Hello");
179- Log.d(LOG_TAG, " actionString => " + actionString);
180- if (actionString == null || actionString.length() == 0)
181- {
182- return;
183- }
228+ Log.v(LOG_TAG, "Hello");
184229
185- int size = ACTION_DATA_LIST.size();
186- for (int i = 0; i < size; i++)
230+ if (actionMode != newActionMode)
187231 {
188- Map<String, String> actionData = ACTION_DATA_LIST.get(i);
189- String string = actionData.get(KEY_ACTION_STRING);
190- if (string.equals(actionString))
232+ actionMode = newActionMode;
233+ Log.d(LOG_TAG, "update actionMode => " + actionMode);
234+
235+ // update visibility
236+ for (Entry<Integer, Boolean> e : ACTION_ITEM_VISIBILITY[actionMode].entrySet())
191237 {
192- Log.d(LOG_TAG, " found! i => " + i);
193- listView.setItemChecked(i, true);
194- break;
238+ View actionItemView = findViewById(e.getKey());
239+ if (actionItemView != null)
240+ {
241+ if (e.getValue())
242+ {
243+ actionItemView.setVisibility(View.VISIBLE);
244+ }
245+ else
246+ {
247+ actionItemView.setVisibility(View.GONE);
248+ }
249+ }
195250 }
196251 }
252+
253+ Log.v(LOG_TAG, "Bye");
254+ }
255+
256+ private void leaveSearchMode()
257+ {
258+ Log.v(LOG_TAG, "Hello");
259+
260+ if (actionMode != ACTION_MODE_NORMAL)
261+ {
262+ searchEditText.setText(null);
263+ getListView().requestFocus();
264+ setActionMode(ACTION_MODE_NORMAL);
265+ }
266+
267+ Log.v(LOG_TAG, "Bye");
268+ }
269+
270+ private void enterSearchMode()
271+ {
272+ Log.v(LOG_TAG, "Hello");
273+ if (actionMode != ACTION_MODE_SEARCH)
274+ {
275+ setActionMode(ACTION_MODE_SEARCH);
276+ IMEUtils.requestKeyboardFocus(searchEditText);
277+ searchEditText.requestFocus();
278+ }
279+ Log.v(LOG_TAG, "Bye");
197280 }
198281 }
--- a/intent-lab/src/org/routine_work/intent_lab/intent/IntentDetailActivity.java
+++ b/intent-lab/src/org/routine_work/intent_lab/intent/IntentDetailActivity.java
@@ -19,6 +19,7 @@ import android.widget.TextView;
1919 import android.widget.Toast;
2020 import java.util.Set;
2121 import org.routine_work.intent_lab.R;
22+import org.routine_work.intent_lab.action.ActionListActivity;
2223 import org.routine_work.intent_lab.common.EditTextActivity;
2324 import org.routine_work.intent_lab.intent.provider.IntentStore;
2425 import org.routine_work.utils.Log;
@@ -66,12 +67,17 @@ public class IntentDetailActivity extends ListActivity
6667 {
6768 Log.d(LOG_TAG, "onItemClick() : Hello");
6869 Log.d(LOG_TAG, "position => " + position);
70+
6971 switch (position)
7072 {
7173 case POSITION_NAME:
7274 startNameEditActivity();
7375 break;
76+ case POSITION_ACTION:
77+ startActionPickActivity();
78+ break;
7479 }
80+
7581 Log.d(LOG_TAG, "onItemClick() : Bye");
7682 }
7783
@@ -124,6 +130,14 @@ public class IntentDetailActivity extends ListActivity
124130 intentDetailListAdapter.notifyDataSetChanged();
125131 }
126132 break;
133+ case REQUEST_CODE_EDIT_INTENT_ACTION:
134+ if (resultCode == RESULT_OK)
135+ {
136+ String actionString = data.getStringExtra(ActionListActivity.EXTRA_ACTION_STRING);
137+ targetIntent.setAction(actionString);
138+ intentDetailListAdapter.notifyDataSetChanged();
139+ }
140+ break;
127141 default:
128142 super.onActivityResult(requestCode, resultCode, data);
129143 }
@@ -166,6 +180,15 @@ public class IntentDetailActivity extends ListActivity
166180 startActivityForResult(intent, REQUEST_CODE_EDIT_INTENT_NAME);
167181 }
168182
183+ private void startActionPickActivity()
184+ {
185+ Intent intent = new Intent(this, ActionListActivity.class);
186+ intent.setAction(Intent.ACTION_PICK);
187+ String actionSring = targetIntent.getAction();
188+ intent.putExtra(ActionListActivity.EXTRA_ACTION_STRING, actionSring);
189+ startActivityForResult(intent, REQUEST_CODE_EDIT_INTENT_ACTION);
190+ }
191+
169192 class IntentDetailListAdapter extends BaseAdapter
170193 {
171194
--- a/intent-lab/src/org/routine_work/utils/IMEUtils.java
+++ b/intent-lab/src/org/routine_work/utils/IMEUtils.java
@@ -88,7 +88,6 @@ public class IMEUtils
8888 public static void requestKeyboardFocusByClick(EditText editText)
8989 {
9090 requestKeyboardFocusByClick(editText, 200);
91-
9291 }
9392
9493 public static void requestKeyboardFocusByClick(EditText editText, long delayInMillis)