Simple Notepad Application for Android OS
Revision | 940a232fc92070881fc09b1f17670aa0f1d54cad (tree) |
---|---|
Time | 2012-09-03 13:45:17 |
Author | Masahiko, SAWAI <say@user...> |
Commiter | Masahiko, SAWAI |
* NoteListItemViewBinder を NoteCursorAdapter に変更
@@ -106,6 +106,8 @@ Title, Content, Focus | ||
106 | 106 | |
107 | 107 | !! notepad-app-level-11 |
108 | 108 | |
109 | +#* NoteListItemViewBinder を NoteCursorAdapter に変更 | |
110 | + | |
109 | 111 | !! notepad-common |
110 | 112 | |
111 | 113 | #* ノートの複数削除をループではなく SQL 一つで行うようにする |
@@ -37,8 +37,7 @@ import android.text.TextUtils; | ||
37 | 37 | import android.view.View; |
38 | 38 | import android.widget.AdapterView; |
39 | 39 | 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; | |
42 | 41 | import org.routine_work.notepad.prefs.NotepadPreferenceUtils; |
43 | 42 | import org.routine_work.notepad.provider.NoteStore; |
44 | 43 | import org.routine_work.utils.Log; |
@@ -52,7 +51,7 @@ public class PickNoteActivity extends ListActivity | ||
52 | 51 | // class variables |
53 | 52 | private static final String LOG_TAG = "simple-notepad"; |
54 | 53 | // instance variables |
55 | - private SimpleCursorAdapter listAdapter; | |
54 | + private NoteCursorAdapter listAdapter; | |
56 | 55 | |
57 | 56 | @Override |
58 | 57 | public void onCreate(Bundle savedInstanceState) |
@@ -70,10 +69,11 @@ public class PickNoteActivity extends ListActivity | ||
70 | 69 | setTitle(title); |
71 | 70 | } |
72 | 71 | |
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); | |
77 | 77 | setListAdapter(listAdapter); |
78 | 78 | |
79 | 79 | LoaderManager loaderManager = getLoaderManager(); |
@@ -52,7 +52,7 @@ public class DeleteNotesFragment extends ListFragment | ||
52 | 52 | { |
53 | 53 | |
54 | 54 | private static final String LOG_TAG = "simple-notepad"; |
55 | - private SimpleCursorAdapter listAdapter; | |
55 | + private NoteCursorAdapter listAdapter; | |
56 | 56 | |
57 | 57 | public DeleteNotesFragment() |
58 | 58 | { |
@@ -80,12 +80,13 @@ public class DeleteNotesFragment extends ListFragment | ||
80 | 80 | super.onActivityCreated(savedInstanceState); |
81 | 81 | |
82 | 82 | // 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); | |
89 | 90 | setListAdapter(listAdapter); |
90 | 91 | |
91 | 92 | // Init LoaderManager |
@@ -26,47 +26,81 @@ package org.routine_work.notepad.fragment; | ||
26 | 26 | import android.content.Context; |
27 | 27 | import android.database.Cursor; |
28 | 28 | import android.view.View; |
29 | -import android.widget.CheckedTextView; | |
30 | 29 | import android.widget.SimpleCursorAdapter; |
31 | 30 | import android.widget.TextView; |
32 | 31 | import org.routine_work.notepad.R; |
32 | +import org.routine_work.notepad.provider.NoteStore; | |
33 | 33 | import org.routine_work.notepad.utils.TimeFormatUtils; |
34 | 34 | import org.routine_work.utils.Log; |
35 | -import org.routine_work.widget.CheckableLinearLayout; | |
36 | 35 | |
37 | 36 | /** |
38 | 37 | * |
39 | - * @author sawai | |
38 | + * @author Masahiko, SAWAI <masahiko.sawai@gmail.com> | |
40 | 39 | */ |
41 | -public class NoteListItemViewBinder | |
40 | +public class NoteCursorAdapter extends SimpleCursorAdapter | |
42 | 41 | implements SimpleCursorAdapter.ViewBinder |
43 | 42 | { |
44 | 43 | |
45 | 44 | 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 | + }; | |
46 | 57 | private Context context; |
47 | - private boolean checkboxVisible = false; | |
58 | + private boolean checkable = false; | |
48 | 59 | |
49 | - public NoteListItemViewBinder(Context context) | |
60 | + public NoteCursorAdapter(Context context, Cursor c) | |
50 | 61 | { |
51 | - this.context = context; | |
62 | + this(context, c, false); | |
52 | 63 | } |
53 | 64 | |
54 | - public boolean isCheckboxVisible() | |
65 | + public NoteCursorAdapter(Context context, Cursor c, boolean checkable) | |
55 | 66 | { |
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); | |
57 | 72 | } |
58 | 73 | |
59 | - public void setCheckboxVisible(boolean checkboxVisible) | |
74 | + @Override | |
75 | + public void bindView(View view, Context context, Cursor cursor) | |
60 | 76 | { |
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"); | |
62 | 94 | } |
63 | 95 | |
96 | + // SimpleCursorAdapter.ViewBinder | |
64 | 97 | @Override |
65 | 98 | public boolean setViewValue(View view, Cursor cursor, int columnIndex) |
66 | 99 | { |
67 | 100 | boolean result = false; |
68 | 101 | |
69 | - switch (view.getId()) | |
102 | + int viewId = view.getId(); | |
103 | + switch (viewId) | |
70 | 104 | { |
71 | 105 | case R.id.note_modified_textview: |
72 | 106 | long modifiedTime = cursor.getLong(columnIndex); |
@@ -74,7 +108,6 @@ public class NoteListItemViewBinder | ||
74 | 108 | TextView modifiedTextView = (TextView) view; |
75 | 109 | modifiedTextView.setText(modifiedText); |
76 | 110 | result = true; |
77 | - updateCheckedTextViewVisibility(view); | |
78 | 111 | break; |
79 | 112 | case R.id.note_content_textview: |
80 | 113 | String contentText = cursor.getString(columnIndex); |
@@ -88,44 +121,13 @@ public class NoteListItemViewBinder | ||
88 | 121 | return result; |
89 | 122 | } |
90 | 123 | |
91 | - private void updateCheckedTextViewVisibility(View view) | |
124 | + public boolean isCheckable() | |
92 | 125 | { |
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; | |
112 | 127 | } |
113 | 128 | |
114 | - private CheckableLinearLayout findCheckableLinearLayout(View view) | |
129 | + public void setCheckable(boolean checkable) | |
115 | 130 | { |
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; | |
130 | 132 | } |
131 | 133 | } |
@@ -45,7 +45,6 @@ import android.view.ViewGroup; | ||
45 | 45 | import android.widget.AbsListView; |
46 | 46 | import android.widget.AdapterView.AdapterContextMenuInfo; |
47 | 47 | import android.widget.ListView; |
48 | -import android.widget.SimpleCursorAdapter; | |
49 | 48 | import org.routine_work.notepad.NotepadConstants; |
50 | 49 | import org.routine_work.notepad.R; |
51 | 50 | import org.routine_work.notepad.provider.NoteStore; |
@@ -60,10 +59,9 @@ public class NoteListFragment extends ListFragment | ||
60 | 59 | |
61 | 60 | private static final String LOG_TAG = "simple-notepad"; |
62 | 61 | private boolean narrowLayout = false; |
63 | - private SimpleCursorAdapter listAdapter; | |
62 | + private NoteCursorAdapter listAdapter; | |
64 | 63 | private Uri contentUri; |
65 | 64 | private NoteControlCallback noteControlCallback; |
66 | - private NoteListItemViewBinder noteListItemViewBinder; | |
67 | 65 | |
68 | 66 | public NoteListFragment() |
69 | 67 | { |
@@ -117,11 +115,7 @@ public class NoteListFragment extends ListFragment | ||
117 | 115 | Log.v(LOG_TAG, "Hello"); |
118 | 116 | super.onActivityCreated(savedInstanceState); |
119 | 117 | |
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); | |
125 | 119 | setListAdapter(listAdapter); |
126 | 120 | |
127 | 121 | LoaderManager loaderManager = getLoaderManager(); |
@@ -251,7 +245,7 @@ public class NoteListFragment extends ListFragment | ||
251 | 245 | { |
252 | 246 | boolean result = false; |
253 | 247 | Log.v(LOG_TAG, "Hello"); |
254 | - noteListItemViewBinder.setCheckboxVisible(true); | |
248 | + listAdapter.setCheckable(true); | |
255 | 249 | Log.v(LOG_TAG, "Bye"); |
256 | 250 | return result; |
257 | 251 | } |
@@ -279,7 +273,7 @@ public class NoteListFragment extends ListFragment | ||
279 | 273 | public void onDestroyActionMode(ActionMode actionMode) |
280 | 274 | { |
281 | 275 | Log.v(LOG_TAG, "Hello"); |
282 | - noteListItemViewBinder.setCheckboxVisible(false); | |
276 | + listAdapter.setCheckable(false); | |
283 | 277 | Log.v(LOG_TAG, "Bye"); |
284 | 278 | } |
285 | 279 | // END ---------- AbsListView.MultiChoiceModeListener |
@@ -107,6 +107,13 @@ public class NoteCursorAdapter extends SimpleCursorAdapter | ||
107 | 107 | modifiedTextView.setText(modifiedText); |
108 | 108 | result = true; |
109 | 109 | 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; | |
110 | 117 | } |
111 | 118 | |
112 | 119 | return result; |