Simple Notepad Application for Android OS
Revision | 8418af9158ae4852a31e8aa609d2e5db45f3d9ff (tree) |
---|---|
Time | 2012-09-05 16:28:50 |
Author | Masahiko, SAWAI <say@user...> |
Commiter | Masahiko, SAWAI |
テンプレートの書式を変更
* とりあえず以下の変数を実装した
* 変数名の大文字小文字は無視する
@@ -58,9 +58,6 @@ Title, Content, Focus | ||
58 | 58 | ############################# |
59 | 59 | !! notepad-common |
60 | 60 | |
61 | -* テンプレートの書式を変更 | |
62 | -** '#{date}' '#{time}' など? | |
63 | - | |
64 | 61 | * TimeFormatUtils 修正 |
65 | 62 | ** 西暦部分のないフォーマットにできないか? |
66 | 63 |
@@ -135,6 +132,11 @@ Title, Content, Focus | ||
135 | 132 | ############################# |
136 | 133 | !! notepad-common |
137 | 134 | |
135 | +#* テンプレートの書式を変更 | |
136 | +#** 変数名を変更、変数名の大文字小文字は無視する | |
137 | +#*** #{date} : 日付 | |
138 | +#*** #{time} : 時間 | |
139 | + | |
138 | 140 | #* 定数定義用インターフェースを notepad-comon に移動 |
139 | 141 | #** NotepadConstants |
140 | 142 | #** NoteTemplateConstants |
@@ -6,12 +6,12 @@ | ||
6 | 6 | <bool name="template_blank_note_title_locked">false</bool> |
7 | 7 | |
8 | 8 | <string name="template_diary_note_name">Diary</string> |
9 | - <string name="template_diary_note_title">%1$s</string> | |
9 | + <string name="template_diary_note_title">#{date}</string> | |
10 | 10 | <string name="template_diary_note_content"></string> |
11 | 11 | <bool name="template_diary_note_title_locked">true</bool> |
12 | 12 | |
13 | 13 | <string name="template_quick_note_name">Quick Note</string> |
14 | - <string name="template_quick_note_title">%1$s %2$s</string> | |
14 | + <string name="template_quick_note_title">#{date} #{time}</string> | |
15 | 15 | <string name="template_quick_note_content"></string> |
16 | 16 | <bool name="template_quick_note_title_locked">true</bool> |
17 | 17 |
@@ -403,14 +403,21 @@ public class NotepadActivity extends Activity implements NotepadConstants, | ||
403 | 403 | { |
404 | 404 | Log.v(LOG_TAG, "Hello"); |
405 | 405 | |
406 | -// Intent intent = new Intent(Intent.ACTION_INSERT, NoteStore.Note.CONTENT_URI); | |
407 | -// startActivityForResult(intent, REQUEST_CODE_ADD_NOTE); | |
408 | - | |
409 | 406 | // Intent intent = new Intent(this, AddNewNoteActivity.class); |
410 | 407 | // startActivityForResult(intent, REQUEST_CODE_ADD_NOTE); |
411 | 408 | |
412 | - NoteTemplatePickerDialogFragment dialogFragment = new NoteTemplatePickerDialogFragment(); | |
413 | - dialogFragment.show(getFragmentManager(), FT_NOTE_TEMPLATE_PICKER); | |
409 | + if (NoteStore.getNoteTemplateCount(getContentResolver()) == 0) | |
410 | + { | |
411 | + Intent intent = new Intent(Intent.ACTION_INSERT, NoteStore.Note.CONTENT_URI); | |
412 | + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
413 | + startActivityForResult(intent, REQUEST_CODE_ADD_NOTE); | |
414 | + } | |
415 | + else | |
416 | + { | |
417 | + NoteTemplatePickerDialogFragment dialogFragment = new NoteTemplatePickerDialogFragment(); | |
418 | + dialogFragment.show(getFragmentManager(), FT_NOTE_TEMPLATE_PICKER); | |
419 | + } | |
420 | + | |
414 | 421 | Log.v(LOG_TAG, "Bye"); |
415 | 422 | } |
416 | 423 |
@@ -34,6 +34,7 @@ import android.content.ContentResolver; | ||
34 | 34 | import android.content.ContentValues; |
35 | 35 | import android.content.CursorLoader; |
36 | 36 | import android.content.DialogInterface; |
37 | +import android.content.Intent; | |
37 | 38 | import android.content.Loader; |
38 | 39 | import android.database.Cursor; |
39 | 40 | import android.net.Uri; |
@@ -541,8 +542,17 @@ public class EditNoteFragment extends Fragment | ||
541 | 542 | // startActivityForResult(intent, REQUEST_CODE_ADD_NOTE); |
542 | 543 | |
543 | 544 | saveNote(); |
544 | - NoteTemplatePickerDialogFragment dialogFragment = new NoteTemplatePickerDialogFragment(); | |
545 | - dialogFragment.show(getFragmentManager(), FT_NOTE_TEMPLATE_PICKER); | |
545 | + if (NoteStore.getNoteTemplateCount(getActivity().getContentResolver()) == 0) | |
546 | + { | |
547 | + Intent intent = new Intent(Intent.ACTION_INSERT, NoteStore.Note.CONTENT_URI); | |
548 | + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
549 | + startActivityForResult(intent, REQUEST_CODE_ADD_NOTE); | |
550 | + } | |
551 | + else | |
552 | + { | |
553 | + NoteTemplatePickerDialogFragment dialogFragment = new NoteTemplatePickerDialogFragment(); | |
554 | + dialogFragment.show(getFragmentManager(), FT_NOTE_TEMPLATE_PICKER); | |
555 | + } | |
546 | 556 | |
547 | 557 | Log.v(LOG_TAG, "Bye"); |
548 | 558 | } |
@@ -6,12 +6,12 @@ | ||
6 | 6 | <bool name="template_blank_note_title_locked">false</bool> |
7 | 7 | |
8 | 8 | <string name="template_diary_note_name">Diary</string> |
9 | - <string name="template_diary_note_title">%1$s</string> | |
9 | + <string name="template_diary_note_title">#{date}</string> | |
10 | 10 | <string name="template_diary_note_content"></string> |
11 | 11 | <bool name="template_diary_note_title_locked">true</bool> |
12 | 12 | |
13 | 13 | <string name="template_quick_note_name">Quick Note</string> |
14 | - <string name="template_quick_note_title">%1$s %2$s</string> | |
14 | + <string name="template_quick_note_title">#{date} #{time}</string> | |
15 | 15 | <string name="template_quick_note_content"></string> |
16 | 16 | <bool name="template_quick_note_title_locked">true</bool> |
17 | 17 |
@@ -940,8 +940,16 @@ public class NoteDetailActivity extends Activity | ||
940 | 940 | // Intent intent = new Intent(this, AddNewNoteActivity.class); |
941 | 941 | // startActivityForResult(intent, REQUEST_CODE_ADD_NOTE); |
942 | 942 | |
943 | - if (NoteStore.getNoteTemplateCount(getContentResolver()) > 0) | |
943 | + if (NoteStore.getNoteTemplateCount(getContentResolver()) == 0) | |
944 | 944 | { |
945 | + // Add Blank Note | |
946 | + Intent intent = new Intent(Intent.ACTION_INSERT, NoteStore.Note.CONTENT_URI); | |
947 | + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
948 | + startActivityForResult(intent, REQUEST_CODE_ADD_NOTE); | |
949 | + } | |
950 | + else | |
951 | + { | |
952 | + // Select Note Template | |
945 | 953 | showDialog(DIALOG_ID_NOTE_TEMPLATE_PICKER); |
946 | 954 | } |
947 | 955 |
@@ -555,7 +555,18 @@ public class NotepadActivity extends ListActivity | ||
555 | 555 | // Intent intent = new Intent(this, AddNewNoteActivity.class); |
556 | 556 | // startActivityForResult(intent, REQUEST_CODE_ADD_NOTE); |
557 | 557 | |
558 | - showDialog(DIALOG_ID_NOTE_TEMPLATE_PICKER); | |
558 | + if (NoteStore.getNoteTemplateCount(getContentResolver()) == 0) | |
559 | + { | |
560 | + // Add Blank Note | |
561 | + Intent intent = new Intent(Intent.ACTION_INSERT, NoteStore.Note.CONTENT_URI); | |
562 | + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
563 | + startActivityForResult(intent, REQUEST_CODE_ADD_NOTE); | |
564 | + } | |
565 | + else | |
566 | + { | |
567 | + // Select Note Template | |
568 | + showDialog(DIALOG_ID_NOTE_TEMPLATE_PICKER); | |
569 | + } | |
559 | 570 | |
560 | 571 | Log.v(LOG_TAG, "Bye"); |
561 | 572 | } |
@@ -13,6 +13,8 @@ import android.net.Uri; | ||
13 | 13 | import android.text.TextUtils; |
14 | 14 | import android.text.format.DateFormat; |
15 | 15 | import java.util.Date; |
16 | +import java.util.HashMap; | |
17 | +import java.util.Map; | |
16 | 18 | import org.routine_work.notepad.provider.NoteStore; |
17 | 19 | import org.routine_work.utils.Log; |
18 | 20 |
@@ -102,15 +104,18 @@ public class NoteUtils implements NotepadConstants | ||
102 | 104 | int titleIndex = cursor.getColumnIndex(NoteStore.NoteTemplate.Columns.TITLE); |
103 | 105 | int contentIndex = cursor.getColumnIndex(NoteStore.NoteTemplate.Columns.CONTENT); |
104 | 106 | int titleLockedIndex = cursor.getColumnIndex(NoteStore.NoteTemplate.Columns.TITLE_LOCKED); |
105 | - boolean titleLocked = (cursor.getInt(titleLockedIndex) != 0); | |
106 | 107 | |
107 | - Date now = new Date(); | |
108 | - String dateText = DateFormat.getDateFormat(context).format(now); | |
109 | - String timeText = DateFormat.getTimeFormat(context).format(now); | |
110 | 108 | String titleTemplate = cursor.getString(titleIndex); |
111 | 109 | String contentTemplate = cursor.getString(contentIndex); |
112 | - String title = String.format(titleTemplate, dateText, timeText); | |
113 | - String content = String.format(contentTemplate, dateText, timeText); | |
110 | + boolean titleLocked = (cursor.getInt(titleLockedIndex) != 0); | |
111 | + | |
112 | + Map<String, String> templateContextMap = new HashMap<String, String>(); | |
113 | + Date now = new Date(); | |
114 | + templateContextMap.put("date", DateFormat.getDateFormat(context).format(now)); | |
115 | + templateContextMap.put("time", DateFormat.getTimeFormat(context).format(now)); | |
116 | + | |
117 | + String title = expandTemplate(titleTemplate, templateContextMap); | |
118 | + String content = expandTemplate(contentTemplate, templateContextMap); | |
114 | 119 | |
115 | 120 | Uri noteUri = searchNoteByTitle(context, title); |
116 | 121 | Log.d(LOG_TAG, "noteUri => " + noteUri); |
@@ -182,4 +187,21 @@ public class NoteUtils implements NotepadConstants | ||
182 | 187 | Log.v(LOG_TAG, "Bye"); |
183 | 188 | return result; |
184 | 189 | } |
190 | + | |
191 | + public static String expandTemplate(String template, Map<String, String> templateContextMap) | |
192 | + { | |
193 | + String text = template; | |
194 | + | |
195 | + for (String key : templateContextMap.keySet()) | |
196 | + { | |
197 | + String value = templateContextMap.get(key); | |
198 | + Log.d(LOG_TAG, "key => " + key); | |
199 | + Log.d(LOG_TAG, "value => " + value); | |
200 | + String regexp = "(?i)#\\{" + key + "\\}"; | |
201 | + Log.d(LOG_TAG, "regexp => " + regexp); | |
202 | + text = text.replaceAll(regexp, value); | |
203 | + } | |
204 | + | |
205 | + return text; | |
206 | + } | |
185 | 207 | } |