• 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

Revision940a232fc92070881fc09b1f17670aa0f1d54cad (tree)
Time2012-09-03 13:45:17
AuthorMasahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

* NoteListItemViewBinder を NoteCursorAdapter に変更

Change Summary

Incremental Difference

--- a/ToDo.txt
+++ b/ToDo.txt
@@ -106,6 +106,8 @@ Title, Content, Focus
106106
107107 !! notepad-app-level-11
108108
109+#* NoteListItemViewBinder を NoteCursorAdapter に変更
110+
109111 !! notepad-common
110112
111113 #* ノートの複数削除をループではなく SQL 一つで行うようにする
--- a/notepad-app-level-11/src/org/routine_work/notepad/PickNoteActivity.java
+++ b/notepad-app-level-11/src/org/routine_work/notepad/PickNoteActivity.java
@@ -37,8 +37,7 @@ import android.text.TextUtils;
3737 import android.view.View;
3838 import android.widget.AdapterView;
3939 import android.widget.ListView;
40-import android.widget.SimpleCursorAdapter;
41-import org.routine_work.notepad.fragment.NoteListItemViewBinder;
40+import org.routine_work.notepad.fragment.NoteCursorAdapter;
4241 import org.routine_work.notepad.prefs.NotepadPreferenceUtils;
4342 import org.routine_work.notepad.provider.NoteStore;
4443 import org.routine_work.utils.Log;
@@ -52,7 +51,7 @@ public class PickNoteActivity extends ListActivity
5251 // class variables
5352 private static final String LOG_TAG = "simple-notepad";
5453 // instance variables
55- private SimpleCursorAdapter listAdapter;
54+ private NoteCursorAdapter listAdapter;
5655
5756 @Override
5857 public void onCreate(Bundle savedInstanceState)
@@ -70,10 +69,11 @@ public class PickNoteActivity extends ListActivity
7069 setTitle(title);
7170 }
7271
73- listAdapter = new SimpleCursorAdapter(this,
74- R.layout.note_list_item, null,
75- NOTE_LIST_MAPPING_FROM, NOTE_LIST_MAPPING_TO);
76- listAdapter.setViewBinder(new NoteListItemViewBinder(this));
72+// listAdapter = new SimpleCursorAdapter(this,
73+// R.layout.note_list_item, null,
74+// NOTE_LIST_MAPPING_FROM, NOTE_LIST_MAPPING_TO);
75+// listAdapter.setViewBinder(new NoteListItemViewBinder(this));
76+ listAdapter = new NoteCursorAdapter(this, null);
7777 setListAdapter(listAdapter);
7878
7979 LoaderManager loaderManager = getLoaderManager();
--- a/notepad-app-level-11/src/org/routine_work/notepad/fragment/DeleteNotesFragment.java
+++ b/notepad-app-level-11/src/org/routine_work/notepad/fragment/DeleteNotesFragment.java
@@ -52,7 +52,7 @@ public class DeleteNotesFragment extends ListFragment
5252 {
5353
5454 private static final String LOG_TAG = "simple-notepad";
55- private SimpleCursorAdapter listAdapter;
55+ private NoteCursorAdapter listAdapter;
5656
5757 public DeleteNotesFragment()
5858 {
@@ -80,12 +80,13 @@ public class DeleteNotesFragment extends ListFragment
8080 super.onActivityCreated(savedInstanceState);
8181
8282 // Init list adapter
83- NoteListItemViewBinder noteListItemViewBinder = new NoteListItemViewBinder(getActivity());
84- noteListItemViewBinder.setCheckboxVisible(true);
85- listAdapter = new SimpleCursorAdapter(getActivity(),
86- R.layout.note_list_item, null,
87- NOTE_LIST_MAPPING_FROM, NOTE_LIST_MAPPING_TO);
88- listAdapter.setViewBinder(noteListItemViewBinder);
83+// NoteListItemViewBinder noteListItemViewBinder = new NoteListItemViewBinder(getActivity());
84+// noteListItemViewBinder.setCheckboxVisible(true);
85+// listAdapter = new SimpleCursorAdapter(getActivity(),
86+// R.layout.note_list_item, null,
87+// NOTE_LIST_MAPPING_FROM, NOTE_LIST_MAPPING_TO);
88+// listAdapter.setViewBinder(noteListItemViewBinder);
89+ listAdapter = new NoteCursorAdapter(getActivity(), null, true);
8990 setListAdapter(listAdapter);
9091
9192 // Init LoaderManager
--- a/notepad-app-level-11/src/org/routine_work/notepad/fragment/NoteListItemViewBinder.java
+++ b/notepad-app-level-11/src/org/routine_work/notepad/fragment/NoteCursorAdapter.java
@@ -26,47 +26,81 @@ package org.routine_work.notepad.fragment;
2626 import android.content.Context;
2727 import android.database.Cursor;
2828 import android.view.View;
29-import android.widget.CheckedTextView;
3029 import android.widget.SimpleCursorAdapter;
3130 import android.widget.TextView;
3231 import org.routine_work.notepad.R;
32+import org.routine_work.notepad.provider.NoteStore;
3333 import org.routine_work.notepad.utils.TimeFormatUtils;
3434 import org.routine_work.utils.Log;
35-import org.routine_work.widget.CheckableLinearLayout;
3635
3736 /**
3837 *
39- * @author sawai
38+ * @author Masahiko, SAWAI <masahiko.sawai@gmail.com>
4039 */
41-public class NoteListItemViewBinder
40+public class NoteCursorAdapter extends SimpleCursorAdapter
4241 implements SimpleCursorAdapter.ViewBinder
4342 {
4443
4544 private static final String LOG_TAG = "simple-notepad";
45+ private static final String[] NOTE_LIST_MAPPING_FROM =
46+ {
47+ NoteStore.Note.Columns.TITLE,
48+ NoteStore.Note.Columns.CONTENT,
49+ NoteStore.Note.Columns.DATE_MODIFIED,
50+ };
51+ private static final int[] NOTE_LIST_MAPPING_TO =
52+ {
53+ R.id.note_title_textview,
54+ R.id.note_content_textview,
55+ R.id.note_modified_textview,
56+ };
4657 private Context context;
47- private boolean checkboxVisible = false;
58+ private boolean checkable = false;
4859
49- public NoteListItemViewBinder(Context context)
60+ public NoteCursorAdapter(Context context, Cursor c)
5061 {
51- this.context = context;
62+ this(context, c, false);
5263 }
5364
54- public boolean isCheckboxVisible()
65+ public NoteCursorAdapter(Context context, Cursor c, boolean checkable)
5566 {
56- return checkboxVisible;
67+ super(context, R.layout.note_list_item, c,
68+ NOTE_LIST_MAPPING_FROM, NOTE_LIST_MAPPING_TO);
69+ this.checkable = checkable;
70+ this.context = context;
71+ setViewBinder(this);
5772 }
5873
59- public void setCheckboxVisible(boolean checkboxVisible)
74+ @Override
75+ public void bindView(View view, Context context, Cursor cursor)
6076 {
61- this.checkboxVisible = checkboxVisible;
77+ Log.v(LOG_TAG, "Hello");
78+ super.bindView(view, context, cursor);
79+
80+ View checkbox = view.findViewById(android.R.id.checkbox);
81+ if (checkbox != null)
82+ {
83+ if (checkable)
84+ {
85+ checkbox.setVisibility(View.VISIBLE);
86+ }
87+ else
88+ {
89+ checkbox.setVisibility(View.GONE);
90+ }
91+ }
92+
93+ Log.v(LOG_TAG, "Bye");
6294 }
6395
96+ // SimpleCursorAdapter.ViewBinder
6497 @Override
6598 public boolean setViewValue(View view, Cursor cursor, int columnIndex)
6699 {
67100 boolean result = false;
68101
69- switch (view.getId())
102+ int viewId = view.getId();
103+ switch (viewId)
70104 {
71105 case R.id.note_modified_textview:
72106 long modifiedTime = cursor.getLong(columnIndex);
@@ -74,7 +108,6 @@ public class NoteListItemViewBinder
74108 TextView modifiedTextView = (TextView) view;
75109 modifiedTextView.setText(modifiedText);
76110 result = true;
77- updateCheckedTextViewVisibility(view);
78111 break;
79112 case R.id.note_content_textview:
80113 String contentText = cursor.getString(columnIndex);
@@ -88,44 +121,13 @@ public class NoteListItemViewBinder
88121 return result;
89122 }
90123
91- private void updateCheckedTextViewVisibility(View view)
124+ public boolean isCheckable()
92125 {
93- CheckableLinearLayout listItemView = findCheckableLinearLayout(view);
94-// Log.d(LOG_TAG, "listItemView => " + listItemView);
95- if (listItemView != null)
96- {
97- View foundView = listItemView.findViewById(android.R.id.checkbox);
98- if (foundView instanceof CheckedTextView)
99- {
100- CheckedTextView checkedTextView = (CheckedTextView) foundView;
101- if (isCheckboxVisible())
102- {
103- checkedTextView.setVisibility(View.VISIBLE);
104- }
105- else
106- {
107- checkedTextView.setVisibility(View.GONE);
108- }
109- }
110- }
111-
126+ return checkable;
112127 }
113128
114- private CheckableLinearLayout findCheckableLinearLayout(View view)
129+ public void setCheckable(boolean checkable)
115130 {
116- CheckableLinearLayout result = null;
117- View target = view;
118-
119- while ((target instanceof CheckableLinearLayout) == false)
120- {
121- target = (View) target.getParent();
122- }
123-
124- if (target != null)
125- {
126- result = (CheckableLinearLayout) target;
127- }
128-
129- return result;
131+ this.checkable = checkable;
130132 }
131133 }
--- a/notepad-app-level-11/src/org/routine_work/notepad/fragment/NoteListFragment.java
+++ b/notepad-app-level-11/src/org/routine_work/notepad/fragment/NoteListFragment.java
@@ -45,7 +45,6 @@ import android.view.ViewGroup;
4545 import android.widget.AbsListView;
4646 import android.widget.AdapterView.AdapterContextMenuInfo;
4747 import android.widget.ListView;
48-import android.widget.SimpleCursorAdapter;
4948 import org.routine_work.notepad.NotepadConstants;
5049 import org.routine_work.notepad.R;
5150 import org.routine_work.notepad.provider.NoteStore;
@@ -60,10 +59,9 @@ public class NoteListFragment extends ListFragment
6059
6160 private static final String LOG_TAG = "simple-notepad";
6261 private boolean narrowLayout = false;
63- private SimpleCursorAdapter listAdapter;
62+ private NoteCursorAdapter listAdapter;
6463 private Uri contentUri;
6564 private NoteControlCallback noteControlCallback;
66- private NoteListItemViewBinder noteListItemViewBinder;
6765
6866 public NoteListFragment()
6967 {
@@ -117,11 +115,7 @@ public class NoteListFragment extends ListFragment
117115 Log.v(LOG_TAG, "Hello");
118116 super.onActivityCreated(savedInstanceState);
119117
120- noteListItemViewBinder = new NoteListItemViewBinder(getActivity());
121- int listItemLayoutId = R.layout.note_list_item;
122- listAdapter = new SimpleCursorAdapter(getActivity(),
123- listItemLayoutId, null, NOTE_LIST_MAPPING_FROM, NOTE_LIST_MAPPING_TO);
124- listAdapter.setViewBinder(noteListItemViewBinder);
118+ listAdapter = new NoteCursorAdapter(getActivity(), null, false);
125119 setListAdapter(listAdapter);
126120
127121 LoaderManager loaderManager = getLoaderManager();
@@ -251,7 +245,7 @@ public class NoteListFragment extends ListFragment
251245 {
252246 boolean result = false;
253247 Log.v(LOG_TAG, "Hello");
254- noteListItemViewBinder.setCheckboxVisible(true);
248+ listAdapter.setCheckable(true);
255249 Log.v(LOG_TAG, "Bye");
256250 return result;
257251 }
@@ -279,7 +273,7 @@ public class NoteListFragment extends ListFragment
279273 public void onDestroyActionMode(ActionMode actionMode)
280274 {
281275 Log.v(LOG_TAG, "Hello");
282- noteListItemViewBinder.setCheckboxVisible(false);
276+ listAdapter.setCheckable(false);
283277 Log.v(LOG_TAG, "Bye");
284278 }
285279 // END ---------- AbsListView.MultiChoiceModeListener
--- a/notepad-app/src/org/routine_work/notepad/NoteCursorAdapter.java
+++ b/notepad-app/src/org/routine_work/notepad/NoteCursorAdapter.java
@@ -107,6 +107,13 @@ public class NoteCursorAdapter extends SimpleCursorAdapter
107107 modifiedTextView.setText(modifiedText);
108108 result = true;
109109 break;
110+ case R.id.note_content_textview:
111+ String contentText = cursor.getString(columnIndex);
112+ contentText = contentText.replace('\n', ' ');
113+ TextView contentTextView = (TextView) view;
114+ contentTextView.setText(contentText);
115+ result = true;
116+ break;
110117 }
111118
112119 return result;