Simple Notepad Application for Android OS
Revision | 3af251b42254ce15847e6eaaea34e24dff1ce632 (tree) |
---|---|
Zeit | 2012-08-11 21:58:13 |
Autor | Masahiko, SAWAI <say@user...> |
Commiter | Masahiko, SAWAI |
NoteDB に新しいテーブルを追加するための準備
@@ -34,27 +34,32 @@ interface NoteDBConstants | ||
34 | 34 | |
35 | 35 | String DATABASE_NAME = "NoteDB"; |
36 | 36 | int DATABASE_VERSION = 5; |
37 | - String TABLE_NAME = "Notes"; | |
38 | - // CREATE SQL | |
39 | - String CREATE_TABLE_SQL = "CREATE TABLE " + TABLE_NAME + "(" | |
40 | - + " " + NoteColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT" | |
41 | - + ", " + NoteColumns.TITLE + " TEXT" | |
42 | - + ", " + NoteColumns.CONTENT + " TEXT" | |
43 | - + ", " + NoteColumns.TITLE_LOCKED + " BOOLEAN NOT NULL" | |
44 | - + ", " + NoteColumns.CONTENT_LOCKED + " BOOLEAN NOT NULL" | |
45 | - + ", " + NoteColumns.DATE_ADDED + " INTEGER NOT NULL" | |
46 | - + ", " + NoteColumns.DATE_MODIFIED + " INTEGER NOT NULL" | |
47 | - + ");"; | |
48 | - // DROP SQL | |
49 | - String DROP_TABLE_SQL = "DROP TABLE " + TABLE_NAME + ";"; | |
50 | - String CREATE_TITLE_INDEX_SQL = "CREATE INDEX " + NoteColumns.TITLE + "_index " | |
51 | - + "ON " + TABLE_NAME + "(" + NoteColumns.TITLE + ");"; | |
52 | - String CREATE_CONTENT_INDEX_SQL = "CREATE INDEX " + NoteColumns.CONTENT + "_index " | |
53 | - + "ON " + TABLE_NAME + "(" + NoteColumns.CONTENT + ");"; | |
54 | - String CREATE_DATE_ADDED_INDEX_SQL = "CREATE INDEX " + NoteColumns.DATE_ADDED + "_index " | |
55 | - + "ON " + TABLE_NAME + "(" + NoteColumns.DATE_ADDED + ");"; | |
56 | - String CREATE_DATE_MODIFIED_INDEX_SQL = "CREATE INDEX " + NoteColumns.DATE_MODIFIED + "_index " | |
57 | - + "ON " + TABLE_NAME + "(" + NoteColumns.DATE_MODIFIED + ");"; | |
58 | - String REINDEX_SQL = "REINDEX;"; | |
59 | - String VACCUM_SQL = "VACUUM;"; | |
37 | + | |
38 | + interface Notes | |
39 | + { | |
40 | + | |
41 | + String TABLE_NAME = "Notes"; | |
42 | + // CREATE SQL | |
43 | + String CREATE_TABLE_SQL = "CREATE TABLE " + TABLE_NAME + "(" | |
44 | + + " " + NoteColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT" | |
45 | + + ", " + NoteColumns.TITLE + " TEXT" | |
46 | + + ", " + NoteColumns.CONTENT + " TEXT" | |
47 | + + ", " + NoteColumns.TITLE_LOCKED + " BOOLEAN NOT NULL" | |
48 | + + ", " + NoteColumns.CONTENT_LOCKED + " BOOLEAN NOT NULL" | |
49 | + + ", " + NoteColumns.DATE_ADDED + " INTEGER NOT NULL" | |
50 | + + ", " + NoteColumns.DATE_MODIFIED + " INTEGER NOT NULL" | |
51 | + + ");"; | |
52 | + // DROP SQL | |
53 | + String DROP_TABLE_SQL = "DROP TABLE " + TABLE_NAME + ";"; | |
54 | + String CREATE_TITLE_INDEX_SQL = "CREATE INDEX " + NoteColumns.TITLE + "_index " | |
55 | + + "ON " + TABLE_NAME + "(" + NoteColumns.TITLE + ");"; | |
56 | + String CREATE_CONTENT_INDEX_SQL = "CREATE INDEX " + NoteColumns.CONTENT + "_index " | |
57 | + + "ON " + TABLE_NAME + "(" + NoteColumns.CONTENT + ");"; | |
58 | + String CREATE_DATE_ADDED_INDEX_SQL = "CREATE INDEX " + NoteColumns.DATE_ADDED + "_index " | |
59 | + + "ON " + TABLE_NAME + "(" + NoteColumns.DATE_ADDED + ");"; | |
60 | + String CREATE_DATE_MODIFIED_INDEX_SQL = "CREATE INDEX " + NoteColumns.DATE_MODIFIED + "_index " | |
61 | + + "ON " + TABLE_NAME + "(" + NoteColumns.DATE_MODIFIED + ");"; | |
62 | + String REINDEX_SQL = "REINDEX;"; | |
63 | + String VACCUM_SQL = "VACUUM;"; | |
64 | + } | |
60 | 65 | } |
@@ -62,16 +62,16 @@ class NoteDBHelper extends SQLiteOpenHelper | ||
62 | 62 | public void onCreate(SQLiteDatabase db) |
63 | 63 | { |
64 | 64 | Log.w(LOG_TAG, "Create database."); |
65 | - Log.w(LOG_TAG, "CREATE_TABLE_SQL => " + CREATE_TABLE_SQL); | |
66 | - db.execSQL(CREATE_TABLE_SQL); | |
67 | - Log.w(LOG_TAG, "CREATE_TITLE_INDEX_SQL => " + CREATE_TITLE_INDEX_SQL); | |
68 | - db.execSQL(CREATE_TITLE_INDEX_SQL); | |
69 | - Log.w(LOG_TAG, "CREATE_CONTENT_INDEX_SQL => " + CREATE_CONTENT_INDEX_SQL); | |
70 | - db.execSQL(CREATE_CONTENT_INDEX_SQL); | |
71 | - Log.w(LOG_TAG, "CREATE_DATE_ADDED_INDEX_SQL => " + CREATE_DATE_ADDED_INDEX_SQL); | |
72 | - db.execSQL(CREATE_DATE_ADDED_INDEX_SQL); | |
73 | - Log.w(LOG_TAG, "CREATE_DATE_MODIFIED_INDEX_SQL => " + CREATE_DATE_MODIFIED_INDEX_SQL); | |
74 | - db.execSQL(CREATE_DATE_MODIFIED_INDEX_SQL); | |
65 | + Log.w(LOG_TAG, "Notes.CREATE_TABLE_SQL => " + Notes.CREATE_TABLE_SQL); | |
66 | + db.execSQL(Notes.CREATE_TABLE_SQL); | |
67 | + Log.w(LOG_TAG, "Notes.CREATE_TITLE_INDEX_SQL => " + Notes.CREATE_TITLE_INDEX_SQL); | |
68 | + db.execSQL(Notes.CREATE_TITLE_INDEX_SQL); | |
69 | + Log.w(LOG_TAG, "Notes.CREATE_CONTENT_INDEX_SQL => " + Notes.CREATE_CONTENT_INDEX_SQL); | |
70 | + db.execSQL(Notes.CREATE_CONTENT_INDEX_SQL); | |
71 | + Log.w(LOG_TAG, "Notes.CREATE_DATE_ADDED_INDEX_SQL => " + Notes.CREATE_DATE_ADDED_INDEX_SQL); | |
72 | + db.execSQL(Notes.CREATE_DATE_ADDED_INDEX_SQL); | |
73 | + Log.w(LOG_TAG, "Notes.CREATE_DATE_MODIFIED_INDEX_SQL => " + Notes.CREATE_DATE_MODIFIED_INDEX_SQL); | |
74 | + db.execSQL(Notes.CREATE_DATE_MODIFIED_INDEX_SQL); | |
75 | 75 | } |
76 | 76 | |
77 | 77 | @Override |
@@ -87,7 +87,7 @@ class NoteDBHelper extends SQLiteOpenHelper | ||
87 | 87 | backupV4To(db, backupDir); |
88 | 88 | } |
89 | 89 | // upgrade table |
90 | - db.execSQL(DROP_TABLE_SQL); | |
90 | + db.execSQL(Notes.DROP_TABLE_SQL); | |
91 | 91 | |
92 | 92 | // restore data |
93 | 93 | onCreate(db); |
@@ -97,12 +97,12 @@ class NoteDBHelper extends SQLiteOpenHelper | ||
97 | 97 | |
98 | 98 | public void reindex(SQLiteDatabase db) |
99 | 99 | { |
100 | - db.execSQL(REINDEX_SQL); | |
100 | + db.execSQL(Notes.REINDEX_SQL); | |
101 | 101 | } |
102 | 102 | |
103 | 103 | public void vacuum(SQLiteDatabase db) |
104 | 104 | { |
105 | - db.execSQL(VACCUM_SQL); | |
105 | + db.execSQL(Notes.VACCUM_SQL); | |
106 | 106 | } |
107 | 107 | |
108 | 108 | public void backupV4To(SQLiteDatabase db, File backupDirectory) |
@@ -110,7 +110,7 @@ class NoteDBHelper extends SQLiteOpenHelper | ||
110 | 110 | Log.v(LOG_TAG, "Hello"); |
111 | 111 | Log.v(LOG_TAG, "backupDirectory => " + backupDirectory); |
112 | 112 | |
113 | - Cursor cursor = db.query(TABLE_NAME, null, null, null, null, null, null); | |
113 | + Cursor cursor = db.query(Notes.TABLE_NAME, null, null, null, null, null, null); | |
114 | 114 | if (cursor != null && cursor.moveToFirst()) |
115 | 115 | { |
116 | 116 | int idIndex = cursor.getColumnIndex(NoteColumns._ID); |
@@ -173,7 +173,7 @@ class NoteDBHelper extends SQLiteOpenHelper | ||
173 | 173 | values.put(NoteColumns.CONTENT_LOCKED, note.contentLocked); |
174 | 174 | values.put(NoteColumns.DATE_ADDED, note.added); |
175 | 175 | values.put(NoteColumns.DATE_MODIFIED, note.modified); |
176 | - db.insert(TABLE_NAME, null, values); | |
176 | + db.insert(Notes.TABLE_NAME, null, values); | |
177 | 177 | } |
178 | 178 | catch (FileNotFoundException ex) |
179 | 179 | { |
@@ -45,10 +45,10 @@ public class NoteProvider extends ContentProvider | ||
45 | 45 | |
46 | 46 | private static final String LOG_TAG = "simple-notepad"; |
47 | 47 | // URI |
48 | - private static final int ITEM_ALL = 1; | |
49 | - private static final int ITEM_BY_ID = 2; | |
50 | - private static final int SUGGEST_SEARCH_ALL = 3; | |
51 | - private static final int SUGGEST_SEARCH_BY_WORD = 4; | |
48 | + private static final int NOTES_ITEM_ALL = 1; | |
49 | + private static final int NOTES_ITEM_BY_ID = 2; | |
50 | + private static final int NOTES_SUGGEST_SEARCH_ALL = 3; | |
51 | + private static final int NOTES_SUGGEST_SEARCH_BY_WORD = 4; | |
52 | 52 | private static final UriMatcher URI_MATCHER; |
53 | 53 | private static final Map<String, String> SUGGESTION_PROJECTION_MAP; |
54 | 54 | // DB |
@@ -57,10 +57,10 @@ public class NoteProvider extends ContentProvider | ||
57 | 57 | static |
58 | 58 | { |
59 | 59 | URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); |
60 | - URI_MATCHER.addURI(NoteStore.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SUGGEST_SEARCH_ALL); | |
61 | - URI_MATCHER.addURI(NoteStore.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SUGGEST_SEARCH_BY_WORD); | |
62 | - URI_MATCHER.addURI(NoteStore.AUTHORITY, "notes", ITEM_ALL); | |
63 | - URI_MATCHER.addURI(NoteStore.AUTHORITY, "notes/#", ITEM_BY_ID); | |
60 | + URI_MATCHER.addURI(NoteStore.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, NOTES_SUGGEST_SEARCH_ALL); | |
61 | + URI_MATCHER.addURI(NoteStore.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", NOTES_SUGGEST_SEARCH_BY_WORD); | |
62 | + URI_MATCHER.addURI(NoteStore.AUTHORITY, "notes", NOTES_ITEM_ALL); | |
63 | + URI_MATCHER.addURI(NoteStore.AUTHORITY, "notes/#", NOTES_ITEM_BY_ID); | |
64 | 64 | |
65 | 65 | SUGGESTION_PROJECTION_MAP = new HashMap<String, String>(); |
66 | 66 | SUGGESTION_PROJECTION_MAP.put(SearchManager.SUGGEST_COLUMN_TEXT_1, |
@@ -91,35 +91,35 @@ public class NoteProvider extends ContentProvider | ||
91 | 91 | Log.d(LOG_TAG, "query uri => " + uri); |
92 | 92 | |
93 | 93 | SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); |
94 | - qb.setTables(TABLE_NAME); | |
94 | + qb.setTables(Notes.TABLE_NAME); | |
95 | 95 | |
96 | 96 | int match = URI_MATCHER.match(uri); |
97 | 97 | switch (match) |
98 | 98 | { |
99 | - case SUGGEST_SEARCH_ALL: | |
100 | - case SUGGEST_SEARCH_BY_WORD: | |
99 | + case NOTES_SUGGEST_SEARCH_ALL: | |
100 | + case NOTES_SUGGEST_SEARCH_BY_WORD: | |
101 | 101 | qb.setProjectionMap(SUGGESTION_PROJECTION_MAP); |
102 | 102 | break; |
103 | 103 | } |
104 | 104 | |
105 | 105 | switch (match) |
106 | 106 | { |
107 | - case SUGGEST_SEARCH_BY_WORD: | |
107 | + case NOTES_SUGGEST_SEARCH_BY_WORD: | |
108 | 108 | Log.d(LOG_TAG, "*SEARCH_BY_WORD"); |
109 | 109 | String queryWord = uri.getLastPathSegment().trim(); |
110 | 110 | Log.d(LOG_TAG, "queryWord => " + queryWord); |
111 | 111 | setUpQueryByWord(qb, queryWord); |
112 | 112 | break; |
113 | - case SUGGEST_SEARCH_ALL: | |
113 | + case NOTES_SUGGEST_SEARCH_ALL: | |
114 | 114 | break; |
115 | - case ITEM_ALL: | |
115 | + case NOTES_ITEM_ALL: | |
116 | 116 | uri.getQueryParameter("q"); |
117 | 117 | Log.d(LOG_TAG, "*SEARCH_BY_WORD"); |
118 | 118 | String q = uri.getQueryParameter("q"); |
119 | 119 | Log.d(LOG_TAG, "queryWord => " + q); |
120 | 120 | setUpQueryByWord(qb, q); |
121 | 121 | break; |
122 | - case ITEM_BY_ID: | |
122 | + case NOTES_ITEM_BY_ID: | |
123 | 123 | qb.appendWhere(NoteColumns._ID + "=" + uri.getPathSegments().get(1)); |
124 | 124 | break; |
125 | 125 | default: |
@@ -143,7 +143,7 @@ public class NoteProvider extends ContentProvider | ||
143 | 143 | Log.v(LOG_TAG, "Hello"); |
144 | 144 | Uri newUri = null; |
145 | 145 | |
146 | - long rowID = noteDB.insert(TABLE_NAME, null, initialValues); | |
146 | + long rowID = noteDB.insert(Notes.TABLE_NAME, null, initialValues); | |
147 | 147 | Log.d(LOG_TAG, "rowID => " + rowID); |
148 | 148 | |
149 | 149 | if (rowID > 0) |
@@ -169,10 +169,10 @@ public class NoteProvider extends ContentProvider | ||
169 | 169 | |
170 | 170 | switch (URI_MATCHER.match(uri)) |
171 | 171 | { |
172 | - case ITEM_ALL: | |
173 | - count = noteDB.delete(TABLE_NAME, where, whereArgs); | |
172 | + case NOTES_ITEM_ALL: | |
173 | + count = noteDB.delete(Notes.TABLE_NAME, where, whereArgs); | |
174 | 174 | break; |
175 | - case ITEM_BY_ID: | |
175 | + case NOTES_ITEM_BY_ID: | |
176 | 176 | String itemId = uri.getPathSegments().get(1); |
177 | 177 | StringBuilder whereClause = new StringBuilder(); |
178 | 178 | whereClause.append(NoteStore.NoteColumns._ID); |
@@ -185,7 +185,7 @@ public class NoteProvider extends ContentProvider | ||
185 | 185 | whereClause.append(")"); |
186 | 186 | } |
187 | 187 | |
188 | - count = noteDB.delete(TABLE_NAME, whereClause.toString(), | |
188 | + count = noteDB.delete(Notes.TABLE_NAME, whereClause.toString(), | |
189 | 189 | whereArgs); |
190 | 190 | break; |
191 | 191 |
@@ -207,11 +207,11 @@ public class NoteProvider extends ContentProvider | ||
207 | 207 | |
208 | 208 | switch (URI_MATCHER.match(uri)) |
209 | 209 | { |
210 | - case ITEM_ALL: | |
211 | - count = noteDB.update(TABLE_NAME, values, where, whereArgs); | |
210 | + case NOTES_ITEM_ALL: | |
211 | + count = noteDB.update(Notes.TABLE_NAME, values, where, whereArgs); | |
212 | 212 | break; |
213 | 213 | |
214 | - case ITEM_BY_ID: | |
214 | + case NOTES_ITEM_BY_ID: | |
215 | 215 | String segment = uri.getPathSegments().get(1); |
216 | 216 | |
217 | 217 | StringBuilder whereClause = new StringBuilder(); |
@@ -225,7 +225,7 @@ public class NoteProvider extends ContentProvider | ||
225 | 225 | whereClause.append(where); |
226 | 226 | whereClause.append(")"); |
227 | 227 | } |
228 | - count = noteDB.update(TABLE_NAME, values, | |
228 | + count = noteDB.update(Notes.TABLE_NAME, values, | |
229 | 229 | whereClause.toString(), whereArgs); |
230 | 230 | break; |
231 | 231 |
@@ -247,11 +247,11 @@ public class NoteProvider extends ContentProvider | ||
247 | 247 | |
248 | 248 | switch (URI_MATCHER.match(uri)) |
249 | 249 | { |
250 | - case SUGGEST_SEARCH_ALL: | |
251 | - case ITEM_ALL: | |
250 | + case NOTES_SUGGEST_SEARCH_ALL: | |
251 | + case NOTES_ITEM_ALL: | |
252 | 252 | type = NoteStore.NOTE_LIST_CONTENT_TYPE; |
253 | 253 | break; |
254 | - case ITEM_BY_ID: | |
254 | + case NOTES_ITEM_BY_ID: | |
255 | 255 | type = NoteStore.NOTE_ITEM_CONTENT_TYPE; |
256 | 256 | break; |
257 | 257 | default: |
@@ -277,7 +277,7 @@ public class NoteProvider extends ContentProvider | ||
277 | 277 | } |
278 | 278 | catch (NumberFormatException e) |
279 | 279 | { |
280 | - Log.e(LOG_TAG, "limit parameter is illegal value : limitText => " + limit); | |
280 | + Log.e(LOG_TAG, "limit parameter is illegal value : limitText => " + limit, e); | |
281 | 281 | limit = null; |
282 | 282 | } |
283 | 283 | } |
@@ -30,7 +30,6 @@ import android.database.Cursor; | ||
30 | 30 | import android.database.sqlite.SQLiteDatabase; |
31 | 31 | import android.net.Uri; |
32 | 32 | import android.provider.BaseColumns; |
33 | -import android.text.TextUtils; | |
34 | 33 | import org.routine_work.utils.Log; |
35 | 34 | |
36 | 35 | /** |
@@ -32,6 +32,7 @@ import android.content.SearchRecentSuggestionsProvider; | ||
32 | 32 | */ |
33 | 33 | public class RecentQueryTextSuggestionProvider extends SearchRecentSuggestionsProvider |
34 | 34 | { |
35 | + | |
35 | 36 | public static final String AUTHORITY = "org.routine_work.notepad.recent_query_text_suggestion_provider"; |
36 | 37 | |
37 | 38 | public RecentQueryTextSuggestionProvider() |