Revision | ee006ec46b68c2bd855cbf03593450ffde6bf679 (tree) |
---|---|
Zeit | 2013-01-30 17:56:31 |
Autor | Masahiko, SAWAI <say@user...> |
Commiter | Masahiko, SAWAI |
Added intent name edit function
@@ -49,12 +49,14 @@ | ||
49 | 49 | </activity> |
50 | 50 | |
51 | 51 | <!-- Activity List Viewer --> |
52 | - <activity android:name=".ResolveInfoListActivity" | |
53 | - /> | |
52 | + <activity android:name=".ResolveInfoListActivity" /> | |
54 | 53 | <!-- |
55 | 54 | android:theme="@android:style/Theme.Dialog" |
56 | 55 | --> |
57 | 56 | |
57 | + <!-- Common Activity --> | |
58 | + <activity android:name=".common.EditTextActivity" /> | |
59 | + | |
58 | 60 | <!-- content provider --> |
59 | 61 | <provider android:name=".intent.provider.IntentProvider" |
60 | 62 | android:authorities="org.routine_work.intent_laboratory.intentsprovider" |
@@ -27,6 +27,7 @@ Intent の実験場ツールです. 以下のようなことができます。 | ||
27 | 27 | ** カテゴリ(リスト) |
28 | 28 | ** エクストラ(マップ) |
29 | 29 | |
30 | + | |
30 | 31 | ------------------------------------------------------------ |
31 | 32 | !! ビルドターゲット |
32 | 33 |
@@ -0,0 +1,53 @@ | ||
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 | + <!-- action bar --> | |
9 | + <LinearLayout | |
10 | + style="@style/actionbar" | |
11 | + android:id="@+id/actionbar_container" | |
12 | + > | |
13 | + <ImageButton | |
14 | + style="@style/actionbar_left_button" | |
15 | + android:id="@+id/cancel_button" | |
16 | + android:src="?attr/ic_clear" | |
17 | + /> | |
18 | + <TextView | |
19 | + style="@style/actionbar_title" | |
20 | + android:id="@+id/title_textview" | |
21 | + /> | |
22 | + <ImageButton | |
23 | + style="@style/actionbar_right_button" | |
24 | + android:id="@+id/ok_button" | |
25 | + android:src="?attr/ic_ok" | |
26 | + /> | |
27 | + </LinearLayout> | |
28 | + | |
29 | + | |
30 | + <!-- body --> | |
31 | + <FrameLayout | |
32 | + style="@style/body" | |
33 | + > | |
34 | + <EditText | |
35 | + android:id="@+id/singleLine_edittext" | |
36 | + android:layout_width="fill_parent" | |
37 | + android:layout_height="wrap_content" | |
38 | + android:layout_marginTop="8dip" | |
39 | + android:inputType="text" | |
40 | + android:gravity="left" | |
41 | + android:visibility="visible" | |
42 | + /> | |
43 | + <EditText | |
44 | + android:id="@+id/multiLine_edittext" | |
45 | + android:layout_width="fill_parent" | |
46 | + android:layout_height="fill_parent" | |
47 | + android:inputType="textMultiLine" | |
48 | + android:gravity="left|top" | |
49 | + android:visibility="gone" | |
50 | + /> | |
51 | + </FrameLayout> | |
52 | + | |
53 | +</LinearLayout> | |
\ No newline at end of file |
@@ -1,14 +1,15 @@ | ||
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
3 | - android:id="@+id/list_frame" | |
2 | +<FrameLayout | |
3 | + xmlns:android="http://schemas.android.com/apk/res/android" | |
4 | 4 | android:layout_width="fill_parent" |
5 | 5 | android:layout_height="fill_parent" |
6 | - android:padding="2dip" | |
7 | 6 | > |
8 | 7 | <ListView |
9 | 8 | android:id="@android:id/list" |
10 | 9 | android:layout_width="fill_parent" |
11 | 10 | android:layout_height="fill_parent" |
11 | + android:drawSelectorOnTop="false" | |
12 | + android:fastScrollEnabled="true" | |
12 | 13 | /> |
13 | 14 | <TextView |
14 | 15 | android:id="@android:id/empty" |
@@ -0,0 +1,132 @@ | ||
1 | +/* | |
2 | + * The MIT License | |
3 | + * | |
4 | + * Copyright 2012 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 org.routine_work.intent_lab.common; | |
25 | + | |
26 | +import android.app.Activity; | |
27 | +import android.content.Intent; | |
28 | +import android.os.Bundle; | |
29 | +import android.text.InputType; | |
30 | +import android.text.TextUtils; | |
31 | +import android.view.View; | |
32 | +import android.view.WindowManager; | |
33 | +import android.widget.EditText; | |
34 | +import android.widget.ImageButton; | |
35 | +import android.widget.TextView; | |
36 | +import org.routine_work.intent_lab.R; | |
37 | +import org.routine_work.utils.Log; | |
38 | + | |
39 | +/** | |
40 | + * | |
41 | + * @author Masahiko, SAWAI <masahiko.sawai@gmail.com> | |
42 | + */ | |
43 | +public class EditTextActivity extends Activity | |
44 | + implements View.OnClickListener | |
45 | +{ | |
46 | + | |
47 | + public static final String EXTRA_INPUT_TYPE = EditTextActivity.class.getPackage().getName() + ".INPUT_TYPE"; | |
48 | + private static final String LOG_TAG = "simple-notepad"; | |
49 | + private EditText mainEditText; | |
50 | + | |
51 | + @Override | |
52 | + protected void onCreate(Bundle savedInstanceState) | |
53 | + { | |
54 | + Log.v(LOG_TAG, "Hello"); | |
55 | +// setTheme(NotepadPreferenceUtils.getTheme(this)); | |
56 | + super.onCreate(savedInstanceState); | |
57 | + | |
58 | + getWindow().setSoftInputMode( | |
59 | + WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | |
60 | + | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); | |
61 | + setContentView(R.layout.edit_text_activity); | |
62 | + | |
63 | + EditText singleLineEditText = (EditText) findViewById(R.id.singleLine_edittext); | |
64 | + EditText multiLineEditText = (EditText) findViewById(R.id.multiLine_edittext); | |
65 | + ImageButton cancelImageButton = (ImageButton) findViewById(R.id.cancel_button); | |
66 | + ImageButton okImageButton = (ImageButton) findViewById(R.id.ok_button); | |
67 | + | |
68 | + cancelImageButton.setOnClickListener(this); | |
69 | + okImageButton.setOnClickListener(this); | |
70 | + | |
71 | + Intent intent = getIntent(); | |
72 | + | |
73 | + int defaultInputType = singleLineEditText.getInputType(); | |
74 | + int inputType = intent.getIntExtra(EXTRA_INPUT_TYPE, defaultInputType); | |
75 | + Log.v(LOG_TAG, "EXTRA_INPUT_TYPE => " + inputType); | |
76 | + if (((inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE) != 0) | |
77 | + || ((inputType & InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE) != 0)) | |
78 | + { | |
79 | + mainEditText = multiLineEditText; | |
80 | + singleLineEditText.setVisibility(View.GONE); | |
81 | + multiLineEditText.setVisibility(View.VISIBLE); | |
82 | + } | |
83 | + else | |
84 | + { | |
85 | + mainEditText = singleLineEditText; | |
86 | + singleLineEditText.setVisibility(View.VISIBLE); | |
87 | + multiLineEditText.setVisibility(View.GONE); | |
88 | + } | |
89 | + | |
90 | + if (inputType != mainEditText.getInputType()) | |
91 | + { | |
92 | + mainEditText.setInputType(inputType); | |
93 | + } | |
94 | + | |
95 | + String title = intent.getStringExtra(Intent.EXTRA_TITLE); | |
96 | + Log.v(LOG_TAG, "EXTRA_TITLE => " + title); | |
97 | + if (!TextUtils.isEmpty(title)) | |
98 | + { | |
99 | + TextView titleTextView = (TextView) findViewById(R.id.title_textview); | |
100 | + titleTextView.setText(title); | |
101 | + mainEditText.setHint(title); | |
102 | + } | |
103 | + | |
104 | + String text = intent.getStringExtra(Intent.EXTRA_TEXT); | |
105 | + Log.v(LOG_TAG, "EXTRA_TEXT => " + text); | |
106 | + if (!TextUtils.isEmpty(text)) | |
107 | + { | |
108 | + mainEditText.setText(text); | |
109 | + } | |
110 | + | |
111 | + mainEditText.requestFocus(); | |
112 | + | |
113 | + Log.v(LOG_TAG, "Bye"); | |
114 | + } | |
115 | + | |
116 | + public void onClick(View v) | |
117 | + { | |
118 | + switch (v.getId()) | |
119 | + { | |
120 | + case R.id.ok_button: | |
121 | + Intent okData = new Intent(); | |
122 | + okData.putExtra(Intent.EXTRA_TEXT, mainEditText.getText().toString()); | |
123 | + setResult(RESULT_OK, okData); | |
124 | + finish(); | |
125 | + break; | |
126 | + case R.id.cancel_button: | |
127 | + setResult(RESULT_CANCELED); | |
128 | + finish(); | |
129 | + break; | |
130 | + } | |
131 | + } | |
132 | +} |
@@ -19,6 +19,7 @@ import android.widget.TextView; | ||
19 | 19 | import android.widget.Toast; |
20 | 20 | import java.util.Set; |
21 | 21 | import org.routine_work.intent_lab.R; |
22 | +import org.routine_work.intent_lab.common.EditTextActivity; | |
22 | 23 | import org.routine_work.intent_lab.intent.provider.IntentStore; |
23 | 24 | import org.routine_work.utils.Log; |
24 | 25 |
@@ -35,11 +36,20 @@ public class IntentDetailActivity extends ListActivity | ||
35 | 36 | private static final int POSITION_CATEGORIES = 5; |
36 | 37 | private static final int POSITION_FLAGS = 6; |
37 | 38 | private static final int POSITION_EXTRAS = 7; |
39 | + private static final int REQUEST_CODE_EDIT_INTENT_NAME = 101; | |
40 | + private static final int REQUEST_CODE_EDIT_INTENT_ACTION = 102; | |
41 | + private static final int REQUEST_CODE_EDIT_INTENT_COMPONENT = 103; | |
42 | + private static final int REQUEST_CODE_EDIT_INTENT_DATA_URI = 104; | |
43 | + private static final int REQUEST_CODE_EDIT_INTENT_DATA_TYPE = 105; | |
44 | + private static final int REQUEST_CODE_EDIT_INTENT_CATEGORIES = 106; | |
45 | + private static final int REQUEST_CODE_EDIT_INTENT_FLAGS = 106; | |
46 | + private static final int REQUEST_CODE_EDIT_INTENT_EXTRAS = 108; | |
38 | 47 | // data |
39 | 48 | private Uri targetUri; |
40 | 49 | private String targetName; |
41 | 50 | private Intent targetIntent; |
42 | 51 | private IntentDetailListAdapter intentDetailListAdapter; |
52 | + private boolean modified; | |
43 | 53 | |
44 | 54 | public void onClick(View view) |
45 | 55 | { |
@@ -52,6 +62,19 @@ public class IntentDetailActivity extends ListActivity | ||
52 | 62 | } |
53 | 63 | } |
54 | 64 | |
65 | + public void onItemClick(AdapterView<?> parent, View view, int position, long id) | |
66 | + { | |
67 | + Log.d(LOG_TAG, "onItemClick() : Hello"); | |
68 | + Log.d(LOG_TAG, "position => " + position); | |
69 | + switch (position) | |
70 | + { | |
71 | + case POSITION_NAME: | |
72 | + startNameEditActivity(); | |
73 | + break; | |
74 | + } | |
75 | + Log.d(LOG_TAG, "onItemClick() : Bye"); | |
76 | + } | |
77 | + | |
55 | 78 | @Override |
56 | 79 | protected void onCreate(Bundle savedInstanceState) |
57 | 80 | { |
@@ -89,6 +112,23 @@ public class IntentDetailActivity extends ListActivity | ||
89 | 112 | Log.v(LOG_TAG, "Bye"); |
90 | 113 | } |
91 | 114 | |
115 | + @Override | |
116 | + protected void onActivityResult(int requestCode, int resultCode, Intent data) | |
117 | + { | |
118 | + switch (requestCode) | |
119 | + { | |
120 | + case REQUEST_CODE_EDIT_INTENT_NAME: | |
121 | + if (resultCode == RESULT_OK) | |
122 | + { | |
123 | + targetName = data.getStringExtra(Intent.EXTRA_TEXT); | |
124 | + intentDetailListAdapter.notifyDataSetChanged(); | |
125 | + } | |
126 | + break; | |
127 | + default: | |
128 | + super.onActivityResult(requestCode, resultCode, data); | |
129 | + } | |
130 | + } | |
131 | + | |
92 | 132 | private String loadName(ContentResolver cr) |
93 | 133 | { |
94 | 134 | String title = null; |
@@ -117,9 +157,13 @@ public class IntentDetailActivity extends ListActivity | ||
117 | 157 | return title; |
118 | 158 | } |
119 | 159 | |
120 | - public void onItemClick(AdapterView<?> parent, View view, int position, long id) | |
160 | + private void startNameEditActivity() | |
121 | 161 | { |
122 | - Log.d(LOG_TAG, "position => " + position); | |
162 | + Intent intent = new Intent(this, EditTextActivity.class); | |
163 | + String title = getString(R.string.name); | |
164 | + intent.putExtra(Intent.EXTRA_TITLE, title); | |
165 | + intent.putExtra(Intent.EXTRA_TEXT, targetName); | |
166 | + startActivityForResult(intent, REQUEST_CODE_EDIT_INTENT_NAME); | |
123 | 167 | } |
124 | 168 | |
125 | 169 | class IntentDetailListAdapter extends BaseAdapter |