• 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

Revision11bb0940a3a6be85e0359f68304ce05792a673af (tree)
Time2012-08-28 18:37:46
AuthorMasahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

ノートのロック状態の変更用UIを ToggleButton から Button とダイアログに変更

Change Summary

Incremental Difference

--- a/ToDo.txt
+++ b/ToDo.txt
@@ -4,11 +4,12 @@
44 !! notepad-app
55
66 * テンプレートの書式を変更
7-** #{date} #{time} など?
7+** '#{date}' '#{time}' など?
88
9-* ノート編集時のロックを ToggleButton から Button + ダイアログに変更
10-** ToggleButton はキーボードでオンオフ操作できない?
11-** ロック解除操作が簡単すぎるのはよくない?
9+#* ノート編集時のロックを ToggleButton から Button + ダイアログに変更
10+#** ToggleButton はキーボードでオンオフ操作できない
11+#** ロック解除操作が簡単すぎるのはよくない
12+** ロック、アンロックメッセージを作成
1213
1314 * ノート一覧画面の本文の表示行数を設定変更可能にする
1415
--- a/notepad-app/res/layout/note_detail_edit.xml
+++ b/notepad-app/res/layout/note_detail_edit.xml
@@ -7,30 +7,47 @@
77 android:layout_height="fill_parent"
88 android:orientation="vertical"
99 >
10- <LinearLayout
10+ <FrameLayout
1111 android:layout_width="fill_parent"
1212 android:layout_height="wrap_content"
1313 android:layout_weight="0"
14- android:orientation="horizontal"
1514 >
1615 <EditText
1716 android:id="@+id/note_title_edittext"
18- android:layout_width="wrap_content"
17+ android:layout_width="fill_parent"
1918 android:layout_height="wrap_content"
20- android:layout_weight="1"
19+ android:layout_weight="0"
20+ android:layout_gravity="bottom"
21+ android:paddingRight="44dip"
2122 android:lines="1"
2223 android:inputType="text"
2324 android:hint="@string/title"
2425 />
25- <ToggleButton
26- android:id="@+id/note_title_locked_togglebutton"
26+ <ImageButton
27+ android:id="@+id/note_title_lock_button"
28+ android:layout_width="wrap_content"
29+ android:layout_height="wrap_content"
30+ android:layout_weight="0"
31+ android:layout_gravity="right|center_vertical"
32+ android:layout_margin="4dip"
33+ android:padding="4dip"
34+ android:src="?attr/ic_unlock"
35+ android:background="@drawable/actionbar_button_bg"
36+ android:visibility="visible"
37+ />
38+ <ImageButton
39+ android:id="@+id/note_title_unlock_button"
2740 android:layout_width="wrap_content"
2841 android:layout_height="wrap_content"
2942 android:layout_weight="0"
30- android:textOn="@string/locked"
31- android:textOff="@string/unlocked"
43+ android:layout_gravity="right|center_vertical"
44+ android:layout_margin="4dip"
45+ android:padding="4dip"
46+ android:src="?attr/ic_lock"
47+ android:background="@drawable/actionbar_button_bg"
48+ android:visibility="gone"
3249 />
33- </LinearLayout>
50+ </FrameLayout>
3451
3552 <EditText
3653 android:id="@+id/note_content_edittext"
--- a/notepad-app/res/values/strings.xml
+++ b/notepad-app/res/values/strings.xml
@@ -11,6 +11,7 @@
1111 <string name="title">Title</string>
1212 <string name="text">Text</string>
1313 <string name="lock">Lock</string>
14+ <string name="unlock">Unlock</string>
1415 <string name="name">Name</string>
1516 <string name="locked">Locked</string>
1617 <string name="unlocked">Unlocked</string>
--- a/notepad-app/src/org/routine_work/notepad/NoteDetailActivity.java
+++ b/notepad-app/src/org/routine_work/notepad/NoteDetailActivity.java
@@ -24,8 +24,11 @@
2424 package org.routine_work.notepad;
2525
2626 import android.app.Activity;
27+import android.app.AlertDialog;
28+import android.app.Dialog;
2729 import android.content.ContentResolver;
2830 import android.content.ContentValues;
31+import android.content.DialogInterface;
2932 import android.content.Intent;
3033 import android.database.Cursor;
3134 import android.net.Uri;
@@ -34,13 +37,10 @@ import android.os.Parcelable;
3437 import android.text.TextUtils;
3538 import android.view.*;
3639 import android.view.View.OnFocusChangeListener;
37-import android.widget.CompoundButton;
38-import android.widget.CompoundButton.OnCheckedChangeListener;
3940 import android.widget.EditText;
4041 import android.widget.ImageButton;
4142 import android.widget.TextView;
4243 import android.widget.Toast;
43-import android.widget.ToggleButton;
4444 import org.routine_work.notepad.model.Note;
4545 import org.routine_work.notepad.prefs.NotepadPreferenceUtils;
4646 import org.routine_work.notepad.provider.NoteStore;
@@ -55,13 +55,15 @@ import org.routine_work.utils.Log;
5555 */
5656 public class NoteDetailActivity extends Activity
5757 implements View.OnClickListener, OnFocusChangeListener,
58- OnCheckedChangeListener, NotepadConstants
58+ DialogInterface.OnClickListener, NotepadConstants
5959 {
6060
61+ private static final String LOG_TAG = "simple-notepad";
6162 private static final String SAVE_KEY_CURRENT_NOTE_URI = "currentNoteUri";
6263 private static final String SAVE_KEY_CURRENT_ACTION = "currentAction";
6364 private static final String SAVE_KEY_CURRENT_NOTE = "currentNote";
64- private static final String LOG_TAG = "simple-notepad";
65+ private static final int DIALOG_ID_LOCK = 0;
66+ private static final int DIALOG_ID_UNLOCK = 1;
6567 // ActionBar items
6668 private ViewGroup actionBarContainer;
6769 private TextView titleTextView;
@@ -72,12 +74,16 @@ public class NoteDetailActivity extends Activity
7274 // Mode Edit
7375 private ViewGroup noteEditContainer;
7476 private EditText noteTitleEditText;
75- private ToggleButton noteTitleLockedToggleButton;
77+ private ImageButton noteTitleLockImageButton;
78+ private ImageButton noteTitleUnlockImageButton;
7679 private EditText noteContentEditText;
7780 // Mode View
7881 private ViewGroup noteViewContainer;
7982 private TextView noteTitleTextView;
8083 private TextView noteContentTextView;
84+ // Dialogs
85+ private Dialog lockDialog;
86+ private Dialog unlockDialog;
8187 // data
8288 private String currentAction;
8389 private Uri currentNoteUri;
@@ -104,7 +110,7 @@ public class NoteDetailActivity extends Activity
104110 // ActionBar
105111 actionBarContainer = (ViewGroup) findViewById(R.id.actionbar_container);
106112
107- // ActionBar Buttons
113+ // ActionBar Items
108114 titleTextView = (TextView) findViewById(R.id.title_textview);
109115 homeImageButton = (ImageButton) findViewById(R.id.home_button);
110116 addNewNoteImageButton = (ImageButton) findViewById(R.id.add_new_note_button);
@@ -118,10 +124,14 @@ public class NoteDetailActivity extends Activity
118124 // Edit Mode
119125 noteEditContainer = (ViewGroup) findViewById(R.id.note_edit_container);
120126 noteTitleEditText = (EditText) findViewById(R.id.note_title_edittext);
121- noteTitleLockedToggleButton = (ToggleButton) findViewById(R.id.note_title_locked_togglebutton);
127+ noteTitleLockImageButton = (ImageButton) findViewById(R.id.note_title_lock_button);
128+ noteTitleUnlockImageButton = (ImageButton) findViewById(R.id.note_title_unlock_button);
122129 noteContentEditText = (EditText) findViewById(R.id.note_content_edittext);
130+
123131 noteTitleEditText.setOnFocusChangeListener(this);
124- noteTitleLockedToggleButton.setOnCheckedChangeListener(this);
132+ noteTitleEditText.setOnClickListener(this);
133+ noteTitleLockImageButton.setOnClickListener(this);
134+ noteTitleUnlockImageButton.setOnClickListener(this);
125135 noteContentEditText.setOnFocusChangeListener(this);
126136
127137 // View Mode
@@ -208,6 +218,27 @@ public class NoteDetailActivity extends Activity
208218 }
209219
210220 @Override
221+ protected Dialog onCreateDialog(int id)
222+ {
223+ Dialog dialog = null;
224+ Log.v(LOG_TAG, "Hello");
225+
226+ switch (id)
227+ {
228+ case DIALOG_ID_LOCK:
229+ dialog = getLockDialog();
230+ break;
231+ case DIALOG_ID_UNLOCK:
232+ dialog = getUnlockDialog();
233+ break;
234+ }
235+
236+ Log.v(LOG_TAG, "dialog => " + dialog);
237+ Log.v(LOG_TAG, "Bye");
238+ return dialog;
239+ }
240+
241+ @Override
211242 public boolean onCreateOptionsMenu(Menu menu)
212243 {
213244 Log.v(LOG_TAG, "Hello");
@@ -332,11 +363,45 @@ public class NoteDetailActivity extends Activity
332363 Log.d(LOG_TAG, "Edit Button is clicked.");
333364 startEditNoteActivity();
334365 break;
366+ case R.id.note_title_lock_button:
367+ Log.d(LOG_TAG, "note_title_lock_button is clicked.");
368+ showDialog(DIALOG_ID_LOCK);
369+ break;
370+ case R.id.note_title_unlock_button:
371+ Log.d(LOG_TAG, "note_title_unlock_button is clicked.");
372+ showDialog(DIALOG_ID_UNLOCK);
373+ break;
374+ case R.id.note_title_edittext:
375+ Log.d(LOG_TAG, "note_title_edittext is clicked.");
376+ noteContentEditText.clearFocus();
377+ break;
335378 }
336379
337380 Log.v(LOG_TAG, "Bye");
338381 }
339382
383+ // DialogInterface.OnClickListener
384+ @Override
385+ public void onClick(DialogInterface dialog, int which)
386+ {
387+ Log.v(LOG_TAG, "Hello");
388+ Log.d(LOG_TAG, "dialog => " + dialog);
389+ Log.d(LOG_TAG, "which => " + which);
390+
391+ if (which == Dialog.BUTTON_POSITIVE)
392+ {
393+ if (dialog == getLockDialog())
394+ {
395+ setNoteTitleLocked(true);
396+ }
397+ else if (dialog == getUnlockDialog())
398+ {
399+ setNoteTitleLocked(false);
400+ }
401+ }
402+ Log.v(LOG_TAG, "Bye");
403+ }
404+
340405 @Override
341406 public boolean onKeyDown(int keyCode, KeyEvent event)
342407 {
@@ -370,13 +435,14 @@ public class NoteDetailActivity extends Activity
370435 case R.id.note_title_edittext:
371436 if (hasFocus)
372437 {
438+ Log.d(LOG_TAG, "note_title_edittext has focus.");
373439 IMEUtils.showSoftKeyboardWindow(this, v);
374440 }
375441 break;
376442 case R.id.note_content_edittext:
377443 if (hasFocus)
378444 {
379- Log.d(LOG_TAG, LOG_TAG);
445+ Log.d(LOG_TAG, "note_content_edittext has focus.");
380446 actionBarContainer.setVisibility(View.GONE);
381447 IMEUtils.showSoftKeyboardWindow(this, v);
382448 }
@@ -390,16 +456,14 @@ public class NoteDetailActivity extends Activity
390456 Log.v(LOG_TAG, "Bye");
391457 }
392458
393- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
459+ @Override
460+ public void setTitle(int titleId)
394461 {
395- Log.v(LOG_TAG, "Hello");
396- switch (buttonView.getId())
462+ super.setTitle(titleId);
463+ if (titleTextView != null)
397464 {
398- case R.id.note_title_locked_togglebutton:
399- setNoteTitleEditable(!isChecked);
400- break;
465+ titleTextView.setText(titleId);
401466 }
402- Log.v(LOG_TAG, "Bye");
403467 }
404468
405469 @Override
@@ -411,8 +475,8 @@ public class NoteDetailActivity extends Activity
411475 if (requestCode == REQUEST_CODE_EDIT_NOTE)
412476 {
413477 loadNoteFromContentProvider();
414- bindNoteToViews();
415478 originalNote.copyFrom(currentNote);
479+ updateViews();
416480 }
417481
418482 Log.v(LOG_TAG, "Bye");
@@ -433,7 +497,8 @@ public class NoteDetailActivity extends Activity
433497 Log.d(LOG_TAG, "------------------------------------------------------------");
434498
435499 actionBarContainer.setVisibility(View.VISIBLE);
436- // load saved note uri
500+
501+ // load saved instance
437502 String newAction = null;
438503 Uri newNoteUri = null;
439504 Log.d(LOG_TAG, "savedInstanceState => " + savedInstanceState);
@@ -513,7 +578,7 @@ public class NoteDetailActivity extends Activity
513578 Log.d(LOG_TAG, "EXTRA_TITLE_LOCKED => " + extraTitleLocked);
514579 currentNote.setTitleLocked(extraTitleLocked);
515580
516- titleTextView.setText(R.string.add_new_note_title);
581+ setTitle(R.string.add_new_note_title);
517582 addNewNoteImageButton.setVisibility(View.VISIBLE);
518583 editNoteImageButton.setVisibility(View.GONE);
519584 deleteNoteImageButton.setVisibility(View.GONE);
@@ -555,23 +620,13 @@ public class NoteDetailActivity extends Activity
555620 loadNoteFromViews();
556621 }
557622
558- titleTextView.setText(R.string.edit_note_title);
623+ setTitle(R.string.edit_note_title);
559624 addNewNoteImageButton.setVisibility(View.VISIBLE);
560625 editNoteImageButton.setVisibility(View.GONE);
561626 deleteNoteImageButton.setVisibility(View.GONE);
562627
563628 noteEditContainer.setVisibility(View.VISIBLE);
564629 noteViewContainer.setVisibility(View.GONE);
565-
566- if (currentNote.isTitleLocked())
567- {
568- setNoteTitleEditable(false);
569- noteContentEditText.requestFocus();
570- }
571- else
572- {
573- noteTitleEditText.requestFocus();
574- }
575630 }
576631 else if (Intent.ACTION_VIEW.equals(newAction))
577632 {
@@ -593,7 +648,7 @@ public class NoteDetailActivity extends Activity
593648 currentNoteUri = newNoteUri;
594649 loadNoteFromContentProvider();
595650
596- titleTextView.setText(R.string.view_note_title);
651+ setTitle(R.string.view_note_title);
597652 addNewNoteImageButton.setVisibility(View.GONE);
598653 editNoteImageButton.setVisibility(View.VISIBLE);
599654 deleteNoteImageButton.setVisibility(View.VISIBLE);
@@ -620,19 +675,18 @@ public class NoteDetailActivity extends Activity
620675 currentNoteUri = newNoteUri;
621676 loadNoteFromContentProvider();
622677
623- titleTextView.setText(R.string.delete_note_title);
678+ setTitle(R.string.delete_note_title);
624679 addNewNoteImageButton.setVisibility(View.GONE);
625680 editNoteImageButton.setVisibility(View.GONE);
626681 deleteNoteImageButton.setVisibility(View.VISIBLE);
627682
628683 noteEditContainer.setVisibility(View.GONE);
629684 noteViewContainer.setVisibility(View.VISIBLE);
630-
631685 }
632686
633687 currentAction = newAction;
634- bindNoteToViews();
635688 originalNote.copyFrom(currentNote);
689+ updateViews();
636690
637691 Log.d(LOG_TAG, "isFinishing() => " + isFinishing());
638692 Log.d(LOG_TAG, "------------------------------------------------------------");
@@ -847,37 +901,44 @@ public class NoteDetailActivity extends Activity
847901 Log.v(LOG_TAG, "Bye");
848902 }
849903
850- private void bindNoteToViews()
904+ private void updateViews()
851905 {
906+ Log.v(LOG_TAG, "Hello");
907+ Log.v(LOG_TAG, "currentAction => " + currentAction);
852908 if (Intent.ACTION_EDIT.equals(currentAction))
853909 {
854- if (noteTitleEditText != null)
855- {
856- noteTitleEditText.setText(currentNote.getTitle());
857- }
858- if (noteContentEditText != null)
859- {
860- noteContentEditText.setText(currentNote.getContent());
861- }
862- if (noteTitleLockedToggleButton != null)
863- {
864- noteTitleLockedToggleButton.setChecked(currentNote.isTitleLocked());
865- }
866- noteEditContainer.setVisibility(View.VISIBLE);
867- noteViewContainer.setVisibility(View.GONE);
910+ updateNoteEditTexts();
911+ updateNoteTitleLockedViews();
912+ updateNoteLockButtonsViews();
868913 }
869914 else
870915 {
871- if (noteTitleTextView != null)
872- {
873- noteTitleTextView.setText(currentNote.getTitle());
874- }
875- if (noteContentTextView != null)
876- {
877- noteContentTextView.setText(currentNote.getContent());
878- }
879- noteEditContainer.setVisibility(View.GONE);
880- noteViewContainer.setVisibility(View.VISIBLE);
916+ updateNoteTextViews();
917+ }
918+ Log.v(LOG_TAG, "Bye");
919+ }
920+
921+ private void updateNoteEditTexts()
922+ {
923+ if (noteTitleEditText != null)
924+ {
925+ noteTitleEditText.setText(currentNote.getTitle());
926+ }
927+ if (noteContentEditText != null)
928+ {
929+ noteContentEditText.setText(currentNote.getContent());
930+ }
931+ }
932+
933+ private void updateNoteTextViews()
934+ {
935+ if (noteTitleTextView != null)
936+ {
937+ noteTitleTextView.setText(currentNote.getTitle());
938+ }
939+ if (noteContentTextView != null)
940+ {
941+ noteContentTextView.setText(currentNote.getContent());
881942 }
882943 }
883944
@@ -893,10 +954,72 @@ public class NoteDetailActivity extends Activity
893954 {
894955 currentNote.setContent(noteContentEditText.getText().toString());
895956 }
896- if (noteTitleLockedToggleButton != null)
897- {
898- currentNote.setTitleLocked(noteTitleLockedToggleButton.isChecked());
899- }
957+ }
958+ }
959+
960+ // ToDo : update message and title
961+ private Dialog getLockDialog()
962+ {
963+ if (lockDialog == null)
964+ {
965+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
966+ builder.setTitle(R.string.lock);
967+ builder.setMessage(R.string.lock);
968+ builder.setPositiveButton(android.R.string.ok, this);
969+ builder.setNegativeButton(android.R.string.cancel, this);
970+ lockDialog = builder.create();
971+ }
972+ return lockDialog;
973+ }
974+
975+ // ToDo : update message and title
976+ private Dialog getUnlockDialog()
977+ {
978+ if (unlockDialog == null)
979+ {
980+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
981+ builder.setTitle(R.string.unlock);
982+ builder.setMessage(R.string.unlock);
983+ builder.setPositiveButton(android.R.string.ok, this);
984+ builder.setNegativeButton(android.R.string.cancel, this);
985+ unlockDialog = builder.create();
986+ }
987+ return unlockDialog;
988+ }
989+
990+ private void setNoteTitleLocked(boolean locked)
991+ {
992+ Log.d(LOG_TAG, "locked => " + locked);
993+ currentNote.setTitleLocked(locked);
994+ updateNoteTitleLockedViews();
995+ updateNoteLockButtonsViews();
996+ }
997+
998+ private void updateNoteTitleLockedViews()
999+ {
1000+ if (currentNote.isTitleLocked())
1001+ {
1002+ setNoteTitleEditable(false);
1003+ noteContentEditText.requestFocus();
1004+ }
1005+ else
1006+ {
1007+ setNoteTitleEditable(true);
1008+ noteTitleEditText.requestFocus();
1009+ }
1010+ }
1011+
1012+ private void updateNoteLockButtonsViews()
1013+ {
1014+ if (currentNote.isTitleLocked())
1015+ {
1016+ noteTitleLockImageButton.setVisibility(View.GONE);
1017+ noteTitleUnlockImageButton.setVisibility(View.VISIBLE);
1018+ }
1019+ else
1020+ {
1021+ noteTitleLockImageButton.setVisibility(View.VISIBLE);
1022+ noteTitleUnlockImageButton.setVisibility(View.GONE);
9001023 }
9011024 }
9021025 }