• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

Simple Notepad Application for Android OS


Commit MetaInfo

Revision8418af9158ae4852a31e8aa609d2e5db45f3d9ff (tree)
Time2012-09-05 16:28:50
AuthorMasahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

テンプレートの書式を変更

* とりあえず以下の変数を実装した

  • #{date} : 日付
  • #{time} : 時間

* 変数名の大文字小文字は無視する

Change Summary

Incremental Difference

--- a/ToDo.txt
+++ b/ToDo.txt
@@ -58,9 +58,6 @@ Title, Content, Focus
5858 #############################
5959 !! notepad-common
6060
61-* テンプレートの書式を変更
62-** '#{date}' '#{time}' など?
63-
6461 * TimeFormatUtils 修正
6562 ** 西暦部分のないフォーマットにできないか?
6663
@@ -135,6 +132,11 @@ Title, Content, Focus
135132 #############################
136133 !! notepad-common
137134
135+#* テンプレートの書式を変更
136+#** 変数名を変更、変数名の大文字小文字は無視する
137+#*** #{date} : 日付
138+#*** #{time} : 時間
139+
138140 #* 定数定義用インターフェースを notepad-comon に移動
139141 #** NotepadConstants
140142 #** NoteTemplateConstants
--- a/notepad-app-level-11/res/values/note_template_data.xml
+++ b/notepad-app-level-11/res/values/note_template_data.xml
@@ -6,12 +6,12 @@
66 <bool name="template_blank_note_title_locked">false</bool>
77
88 <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>
1010 <string name="template_diary_note_content"></string>
1111 <bool name="template_diary_note_title_locked">true</bool>
1212
1313 <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>
1515 <string name="template_quick_note_content"></string>
1616 <bool name="template_quick_note_title_locked">true</bool>
1717
--- a/notepad-app-level-11/src/org/routine_work/notepad/NotepadActivity.java
+++ b/notepad-app-level-11/src/org/routine_work/notepad/NotepadActivity.java
@@ -403,14 +403,21 @@ public class NotepadActivity extends Activity implements NotepadConstants,
403403 {
404404 Log.v(LOG_TAG, "Hello");
405405
406-// Intent intent = new Intent(Intent.ACTION_INSERT, NoteStore.Note.CONTENT_URI);
407-// startActivityForResult(intent, REQUEST_CODE_ADD_NOTE);
408-
409406 // Intent intent = new Intent(this, AddNewNoteActivity.class);
410407 // startActivityForResult(intent, REQUEST_CODE_ADD_NOTE);
411408
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+
414421 Log.v(LOG_TAG, "Bye");
415422 }
416423
--- a/notepad-app-level-11/src/org/routine_work/notepad/fragment/EditNoteFragment.java
+++ b/notepad-app-level-11/src/org/routine_work/notepad/fragment/EditNoteFragment.java
@@ -34,6 +34,7 @@ import android.content.ContentResolver;
3434 import android.content.ContentValues;
3535 import android.content.CursorLoader;
3636 import android.content.DialogInterface;
37+import android.content.Intent;
3738 import android.content.Loader;
3839 import android.database.Cursor;
3940 import android.net.Uri;
@@ -541,8 +542,17 @@ public class EditNoteFragment extends Fragment
541542 // startActivityForResult(intent, REQUEST_CODE_ADD_NOTE);
542543
543544 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+ }
546556
547557 Log.v(LOG_TAG, "Bye");
548558 }
--- a/notepad-app/res/values/note_template_data.xml
+++ b/notepad-app/res/values/note_template_data.xml
@@ -6,12 +6,12 @@
66 <bool name="template_blank_note_title_locked">false</bool>
77
88 <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>
1010 <string name="template_diary_note_content"></string>
1111 <bool name="template_diary_note_title_locked">true</bool>
1212
1313 <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>
1515 <string name="template_quick_note_content"></string>
1616 <bool name="template_quick_note_title_locked">true</bool>
1717
--- a/notepad-app/src/org/routine_work/notepad/NoteDetailActivity.java
+++ b/notepad-app/src/org/routine_work/notepad/NoteDetailActivity.java
@@ -940,8 +940,16 @@ public class NoteDetailActivity extends Activity
940940 // Intent intent = new Intent(this, AddNewNoteActivity.class);
941941 // startActivityForResult(intent, REQUEST_CODE_ADD_NOTE);
942942
943- if (NoteStore.getNoteTemplateCount(getContentResolver()) > 0)
943+ if (NoteStore.getNoteTemplateCount(getContentResolver()) == 0)
944944 {
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
945953 showDialog(DIALOG_ID_NOTE_TEMPLATE_PICKER);
946954 }
947955
--- a/notepad-app/src/org/routine_work/notepad/NotepadActivity.java
+++ b/notepad-app/src/org/routine_work/notepad/NotepadActivity.java
@@ -555,7 +555,18 @@ public class NotepadActivity extends ListActivity
555555 // Intent intent = new Intent(this, AddNewNoteActivity.class);
556556 // startActivityForResult(intent, REQUEST_CODE_ADD_NOTE);
557557
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+ }
559570
560571 Log.v(LOG_TAG, "Bye");
561572 }
--- a/notepad-common/src/org/routine_work/notepad/utils/NoteUtils.java
+++ b/notepad-common/src/org/routine_work/notepad/utils/NoteUtils.java
@@ -13,6 +13,8 @@ import android.net.Uri;
1313 import android.text.TextUtils;
1414 import android.text.format.DateFormat;
1515 import java.util.Date;
16+import java.util.HashMap;
17+import java.util.Map;
1618 import org.routine_work.notepad.provider.NoteStore;
1719 import org.routine_work.utils.Log;
1820
@@ -102,15 +104,18 @@ public class NoteUtils implements NotepadConstants
102104 int titleIndex = cursor.getColumnIndex(NoteStore.NoteTemplate.Columns.TITLE);
103105 int contentIndex = cursor.getColumnIndex(NoteStore.NoteTemplate.Columns.CONTENT);
104106 int titleLockedIndex = cursor.getColumnIndex(NoteStore.NoteTemplate.Columns.TITLE_LOCKED);
105- boolean titleLocked = (cursor.getInt(titleLockedIndex) != 0);
106107
107- Date now = new Date();
108- String dateText = DateFormat.getDateFormat(context).format(now);
109- String timeText = DateFormat.getTimeFormat(context).format(now);
110108 String titleTemplate = cursor.getString(titleIndex);
111109 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);
114119
115120 Uri noteUri = searchNoteByTitle(context, title);
116121 Log.d(LOG_TAG, "noteUri => " + noteUri);
@@ -182,4 +187,21 @@ public class NoteUtils implements NotepadConstants
182187 Log.v(LOG_TAG, "Bye");
183188 return result;
184189 }
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+ }
185207 }