Merge lp:~benoit.soyeux/tomdroid/notebookFilter into lp:~tomdroid-maintainers/tomdroid/main

Proposed by Benoit Soyeux
Status: Needs review
Proposed branch: lp:~benoit.soyeux/tomdroid/notebookFilter
Merge into: lp:~tomdroid-maintainers/tomdroid/main
Diff against target: 1237 lines (+902/-61)
17 files modified
AndroidManifest.xml (+4/-1)
default.properties (+1/-1)
res/layout/notebooks.xml (+70/-0)
res/layout/notebooks_list_item.xml (+53/-0)
res/menu/main.xml (+5/-0)
res/values-fr/strings.xml (+5/-2)
res/values/strings.xml (+5/-2)
src/org/tomdroid/DbManager.java (+54/-0)
src/org/tomdroid/Note.java (+1/-0)
src/org/tomdroid/NoteManager.java (+26/-9)
src/org/tomdroid/NoteProvider.java (+5/-44)
src/org/tomdroid/Notebook.java (+9/-0)
src/org/tomdroid/NotebookManager.java (+108/-0)
src/org/tomdroid/NotebookProvider.java (+211/-0)
src/org/tomdroid/ui/Notebooks.java (+114/-0)
src/org/tomdroid/ui/Tomdroid.java (+112/-2)
src/org/tomdroid/util/NotebookListCursorAdapter.java (+119/-0)
To merge this branch: bzr merge lp:~benoit.soyeux/tomdroid/notebookFilter
Reviewer Review Type Date Requested Status
Tomdroid Maintainers Pending
Review via email: mp+76812@code.launchpad.net

Description of the change

Hello

I had the ability to filter notes from the notebook.
To do it, you can press on option button and click on display.
After there is a page with all notebook and you can check or uncheck notebook that you want show.
At the end you must press OK button to save and see the note list filtered by notebook selected before.

I use a standard android icon because I don't how create a svg picture file.

How can I add notebook in the template notes in the SD card image ?

I hope this new future will enjoy you

If you want test it, you can download the apk file with this link : http://www.starbusiness.fr/android/projets/Tomdroid/2011-09-23/Tomdroid-notebookFilter.apk

Best Reagards

To post a comment you must log in.
Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

Hi!

I had a quick view at your branch. Why is the minimal target sdk set to android-8? I reverted it to android-4 for testing.

There are already notes in different notebooks in our test samples. You should see at least two notebooks when using the samples. I also couldn't see them with your Filtering mechanism... maybe displaying the notebooks does not properly work with our test samples?

I also thought, that it isn't necessary to have a own activity just for choosing which notebook to display. Too many activities just confuse users. I would just do a Dialog box. http://developer.android.com/guide/topics/ui/dialogs.html
There you just set which notebook to display in the main note list and done. I for myself also think radio buttons are better - even tomboy can only display one notebook after the other, or all notes, which I would do as first entry in the list.
To display the notebook title, use the title in actionbar. It is not necessary, that there is Tomdorid written... everybody knows this from the icon.

I am sorry for criticizing your work that much. I just think, that one could do this feature much more simple for the user. Just a menu button "notebooks" which displays a dialog box showing a radio button list of all notebooks and "all notes". The result is displayed in the main note list activity - the actionbar title shows the current notebook (maybe even with clicking enabled to show the dialog again).

I would have loved to discuss this details in a Blueprint first, before you now already invested so much time in programming.

I haven't managed to run your branch in my Android 2.3 virtual machine, the application crashed on startup.

263. By Benoit Soyeux

I hope that fix a crash a the start up

264. By Benoit Soyeux

change text of notebook menu button

Revision history for this message
Benoit Soyeux (benoit.soyeux) wrote :

Hello

Thank you for your remark

I have try to fix you start up crash. Could you test ?
If you still get a crash could you send me the log ?

I also change the text of the menu button to notebook as you propose me.

If you need to download apk, you can use this link : http://www.starbusiness.fr/android/projets/Tomdroid/2011-09-27/Tomdroid-notebookFilter.apk

From my view, I prefer to allow select which notebook I want to show than to select just one.
It is why I use check box rather than radio button.

Best regards

265. By Benoit Soyeux

Add a new version to select notebook with dialog (not finish)

Revision history for this message
Benoit Soyeux (benoit.soyeux) wrote :

Hello

Do you have the time to test my fix to your crash ?

I Commit a new version, not finish with a second version using dialog instead activity to select notebook but I don't know how change check box in my dialog when somebody click on.

Best regards

Revision history for this message
Benoit Soyeux (benoit.soyeux) wrote :

Sorry I test new version on my phone and when i click on check box, the value change.
On my AVD, if I click on check box, I don't see some change.

266. By Benoit Soyeux

Finish to select notebook with a dialog interface

Revision history for this message
Stefan Hammer (j-4-deactivatedaccount) wrote :

Hi!

I don't get the crash on startup any more and i really love the dialog box. It is much nicer this way - 100% clearer and easier to use! Checking and unchecking works on all my virtual machines when syncing with Ubuntu One. When adding a new notebook, it is displayed properly.
When unchecking all notebooks in Dialogbox, no note should be shown - but all notes are displayed. Alternatively, unchecking of all notebooks should not be allowed, as it is in the filter-activity.

There is a minor problem with some xml tags: The font of the Dialog list is white (names of the notebooks), it just is black while the onclick event. This just appears in Android 1.6, not in 2.3.

What doesn't work at the moment is displaying Notebooks when syncing with our test SD-Card img file. There should be two notebooks displayed, but no notebook is shown at all. The list is empty, which doesn't look good at all, but this is another problem.
Now i pushed my own notes to an img file and mounted it as SD Card and it seems, that the whole notebook filtering does not work when syncing with the SD Card. My notes are shown, but my three notebooks not - the list is empty.

Great work otherwise - I am sure you can also fix the remaining bugs.
As you can see, I am not looking at the code atm. I am sure Olivier can do this much better than me.

Revision history for this message
Benoit Soyeux (benoit.soyeux) wrote :

Hello

I had a control to forbid no selection in the dialog box (for notebook filter).
This method is not the best solution but I don't know if it possible to disable OK button in the dialog box

In my project, I cannot synchronise with sd card. Is it normal ?

Best Regard
Benoit Soyeux

267. By Benoit Soyeux

Add a control to forbid 0 checkbox checked in the notebook selection

Revision history for this message
Olivier Bilodeau (plaxx) wrote :

Nice work Benoit! It'll need little things here and there so I'll need to branch it into the ~tomdroid-dev team so I can make changes to it.

Revision history for this message
Benoit Soyeux (benoit.soyeux) wrote :

Good news !

Thank you

> Nice work Benoit! It'll need little things here and there so I'll need to
> branch it into the ~tomdroid-dev team so I can make changes to it.

Unmerged revisions

267. By Benoit Soyeux

Add a control to forbid 0 checkbox checked in the notebook selection

266. By Benoit Soyeux

Finish to select notebook with a dialog interface

265. By Benoit Soyeux

Add a new version to select notebook with dialog (not finish)

264. By Benoit Soyeux

change text of notebook menu button

263. By Benoit Soyeux

I hope that fix a crash a the start up

262. By Benoit Soyeux

test to commit

261. By Benoit Soyeux

test

260. By Benoit Soyeux

Fix a bug on display / hide OK button on notebook filter page

259. By Benoit Soyeux

Add Bouton to validate notebook choices
Add title

258. By Benoit Soyeux

Add notebook filter by selecting it

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'AndroidManifest.xml'
2--- AndroidManifest.xml 2011-09-05 21:45:57 +0000
3+++ AndroidManifest.xml 2011-10-20 12:03:25 +0000
4@@ -1,7 +1,7 @@
5 <?xml version="1.0" encoding="utf-8"?>
6 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
7 package="org.tomdroid"
8- android:versionName="0.5.0" android:versionCode="7">
9+ android:versionCode="7" android:versionName="0.5.1">
10
11 <uses-sdk android:minSdkVersion="3"
12 android:targetSdkVersion="4" />
13@@ -59,6 +59,9 @@
14 android:authorities="org.tomdroid.notes"
15 />
16
17+ <provider android:name="NotebookProvider" android:authorities="org.tomdroid.notebooks"/>
18+ <activity android:name=".ui.Notebooks" android:label="@string/app_name"></activity>
19+
20 <activity android:name=".ui.PreferencesActivity" android:label="@string/app_name">
21
22 </activity>
23
24=== modified file 'default.properties'
25--- default.properties 2010-05-24 06:36:42 +0000
26+++ default.properties 2011-10-20 12:03:25 +0000
27@@ -10,5 +10,5 @@
28 # Indicates whether an apk should be generated for each density.
29 split.density=false
30 # Project target.
31-target=android-4
32+target=android-8
33 apk-configurations=
34
35=== added file 'res/drawable-hdpi/ic_menu_view.png'
36Binary files res/drawable-hdpi/ic_menu_view.png 1970-01-01 00:00:00 +0000 and res/drawable-hdpi/ic_menu_view.png 2011-10-20 12:03:25 +0000 differ
37=== added file 'res/drawable-mdpi/ic_menu_view.png'
38Binary files res/drawable-mdpi/ic_menu_view.png 1970-01-01 00:00:00 +0000 and res/drawable-mdpi/ic_menu_view.png 2011-10-20 12:03:25 +0000 differ
39=== added file 'res/drawable/icon_notebookfilter.png'
40Binary files res/drawable/icon_notebookfilter.png 1970-01-01 00:00:00 +0000 and res/drawable/icon_notebookfilter.png 2011-10-20 12:03:25 +0000 differ
41=== added file 'res/layout/notebooks.xml'
42--- res/layout/notebooks.xml 1970-01-01 00:00:00 +0000
43+++ res/layout/notebooks.xml 2011-10-20 12:03:25 +0000
44@@ -0,0 +1,70 @@
45+<?xml version="1.0" encoding="UTF-8"?>
46+<!--
47+ Tomdroid
48+ Tomboy on Android
49+ http://www.launchpad.net/tomdroid
50+
51+ Copyright 2011 Benoit Soyeux <benoit.soyeux@starbusiness.fr>
52+
53+ This file is part of Tomdroid.
54+
55+ Tomdroid is free software: you can redistribute it and/or modify
56+ it under the terms of the GNU General Public License as published by
57+ the Free Software Foundation, either version 3 of the License, or
58+ (at your option) any later version.
59+
60+ Tomdroid is distributed in the hope that it will be useful,
61+ but WITHOUT ANY WARRANTY; without even the implied warranty of
62+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+ GNU General Public License for more details.
64+
65+ You should have received a copy of the GNU General Public License
66+ along with Tomdroid. If not, see <http://www.gnu.org/licenses/>.
67+-->
68+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
69+ android:layout_width="fill_parent"
70+ android:layout_height="fill_parent"
71+ android:orientation="vertical"
72+ >
73+
74+ <include android:id="@+id/actionbar" layout="@layout/actionbar" />
75+
76+ <ListView android:id="@android:id/android:list"
77+ android:layout_width="fill_parent"
78+ android:layout_height="wrap_content"
79+ android:divider="#FFCCCCCC"
80+ android:dividerHeight="1px"
81+ android:cacheColorHint="#ffdddddd"
82+ />
83+
84+ <TextView android:id="@android:id/android:empty"
85+ android:layout_width="wrap_content"
86+ android:layout_height="wrap_content"
87+ android:text="@string/strListEmptyNoNotebooks"
88+ />
89+
90+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
91+ android:orientation="horizontal"
92+ android:layout_width="fill_parent"
93+ android:layout_height="wrap_content"
94+ android:gravity="bottom"
95+ android:layout_weight="1">
96+
97+ <Button android:id="@+id/buttonOk"
98+ android:text="@string/btnOk"
99+ android:layout_width="fill_parent"
100+ android:layout_height="wrap_content"
101+ android:layout_weight="1"
102+ android:onClick="validate"
103+ />
104+
105+ <Button android:id="@+id/buttonCancel"
106+ android:text="@string/btnCancel"
107+ android:layout_width="fill_parent"
108+ android:layout_height="wrap_content"
109+ android:layout_weight="1"
110+ android:onClick="close" />
111+
112+ </LinearLayout>
113+
114+</LinearLayout>
115\ No newline at end of file
116
117=== added file 'res/layout/notebooks_list_item.xml'
118--- res/layout/notebooks_list_item.xml 1970-01-01 00:00:00 +0000
119+++ res/layout/notebooks_list_item.xml 2011-10-20 12:03:25 +0000
120@@ -0,0 +1,53 @@
121+<?xml version="1.0" encoding="UTF-8"?>
122+<!--
123+ Tomdroid
124+ Tomboy on Android
125+ http://www.launchpad.net/tomdroid
126+
127+ Copyright 2011 Benoit Soyeux <benoit.soyeux@starbusiness.fr>
128+
129+ This file is part of Tomdroid.
130+
131+ Tomdroid is free software: you can redistribute it and/or modify
132+ it under the terms of the GNU General Public License as published by
133+ the Free Software Foundation, either version 3 of the License, or
134+ (at your option) any later version.
135+
136+ Tomdroid is distributed in the hope that it will be useful,
137+ but WITHOUT ANY WARRANTY; without even the implied warranty of
138+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
139+ GNU General Public License for more details.
140+
141+ You should have received a copy of the GNU General Public License
142+ along with Tomdroid. If not, see <http://www.gnu.org/licenses/>.
143+-->
144+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
145+ android:orientation="horizontal"
146+ android:layout_width="fill_parent"
147+ android:layout_height="wrap_content" >
148+
149+ <TextView xmlns:android="http://schemas.android.com/apk/res/android"
150+ android:id="@+id/notebook_name"
151+ android:layout_width="wrap_content"
152+ android:layout_height="fill_parent"
153+ android:textStyle="bold"
154+ android:textColor="#FF555555"
155+ android:textSize="18dp"
156+ android:paddingTop="5dip"
157+ android:paddingLeft="5dip"
158+ android:paddingRight="5dip"
159+ />
160+ <CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
161+ android:id="@+id/notebook_checkbox"
162+ android:layout_width="wrap_content"
163+ android:layout_height="wrap_content"
164+ android:layout_alignParentRight="true"
165+ android:textSize="18dp"
166+ android:paddingTop="5dip"
167+ android:paddingLeft="5dip"
168+ android:paddingRight="5dip"
169+ android:onClick="changeDisplay"
170+ />
171+
172+
173+</RelativeLayout>
174\ No newline at end of file
175
176=== modified file 'res/menu/main.xml'
177--- res/menu/main.xml 2011-09-05 17:34:35 +0000
178+++ res/menu/main.xml 2011-10-20 12:03:25 +0000
179@@ -22,12 +22,17 @@
180 along with Tomdroid. If not, see <http://www.gnu.org/licenses/>.
181 -->
182 <menu xmlns:android="http://schemas.android.com/apk/res/android">
183+ <item
184+ android:icon="@drawable/ic_menu_view"
185+ android:id="@+id/menuFilterNotebook"
186+ android:title="@string/menuFilterNotebook"/>
187
188 <item
189 android:icon="@android:drawable/ic_menu_search"
190 android:title="@string/menuSearch"
191 android:id="@+id/menuSearch"/>
192
193+
194 <item
195 android:icon="@android:drawable/ic_menu_info_details"
196 android:title="@string/menuAbout"
197
198=== modified file 'res/values-fr/strings.xml'
199--- res/values-fr/strings.xml 2011-09-05 21:44:12 +0000
200+++ res/values-fr/strings.xml 2011-10-20 12:03:25 +0000
201@@ -91,10 +91,13 @@
202 <string name="titleDefaultSorting">Choix du tri par défaut</string>
203 <string name="prefDefaultSorting">Tri par défaut</string>
204
205- <!-- NoteFiltering -->
206- <string name="menuFilterNotebook">Filtrer</string>
207+ <!-- NotebookFiltering -->
208+ <string name="menuFilterNotebook">Bloc-notes</string>
209+ <string name="menuFilterNotebookv2">Bloc-notes (dialog)</string>
210 <string name="strListEmptyNoNotebooks">Il n\'y a aucun bloc-note dans la base de donnèes</string>
211 <string name="allNotebooksFilter">Tous les bloc-notes</string>
212+ <string name="notebookSelectTitle">Bloc-notes à afficher</string>
213+ <string name="notebookMustSelectOne">Vous devez selectionner au moins un bloc-note</string>
214
215 <!-- List Longpress Menu -->
216 <string name="view">Voir</string>
217
218=== modified file 'res/values/strings.xml'
219--- res/values/strings.xml 2011-09-05 21:44:12 +0000
220+++ res/values/strings.xml 2011-10-20 12:03:25 +0000
221@@ -91,9 +91,12 @@
222 <string name="prefDefaultSorting">Default sort</string>
223
224 <!-- NotebookFiltering -->
225- <string name="menuFilterNotebook">Filter</string>
226- <string name="strListEmptyNoNotebooks">There are no notebooks in the database.</string>
227+ <string name="menuFilterNotebook">Notebooks</string>
228+ <string name="menuFilterNotebookv2">Notebooks (dialog)</string>
229+ <string name="strListEmptyNoNotebooks">There are no notebook in the database.</string>
230 <string name="allNotebooksFilter">All notebooks</string>
231+ <string name="notebookSelectTitle">Notebooks to display.</string>
232+ <string name="notebookMustSelectOne">You must selection at least one notebook</string>
233
234 <!-- List Longpress Menu -->
235 <string name="view">View</string>
236
237=== added file 'src/org/tomdroid/DbManager.java'
238--- src/org/tomdroid/DbManager.java 1970-01-01 00:00:00 +0000
239+++ src/org/tomdroid/DbManager.java 2011-10-20 12:03:25 +0000
240@@ -0,0 +1,54 @@
241+package org.tomdroid;
242+
243+import org.tomdroid.ui.Tomdroid;
244+
245+import android.content.Context;
246+import android.database.sqlite.SQLiteDatabase;
247+import android.database.sqlite.SQLiteOpenHelper;
248+import android.util.Log;
249+
250+public class DbManager extends SQLiteOpenHelper {
251+ private String TAG = "dbManager";
252+
253+ private static final String DATABASE_NAME = "tomdroid-notes.db";
254+ private static final int DB_VERSION = 3;
255+
256+ public DbManager(Context context) {
257+ super(context, DATABASE_NAME, null, DB_VERSION);
258+ }
259+
260+
261+ @Override
262+ public void onCreate(SQLiteDatabase db) {
263+ db.execSQL("CREATE TABLE " + Note.DB_TABLE + " ("
264+ + Note.ID + " INTEGER PRIMARY KEY,"
265+ + Note.GUID + " TEXT,"
266+ + Note.TITLE + " TEXT,"
267+ + Note.FILE + " TEXT,"
268+ + Note.NOTE_CONTENT + " TEXT,"
269+ + Note.MODIFIED_DATE + " STRING,"
270+ + Note.TAGS + " STRING"
271+ + ");");
272+ if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"Table note has been created");
273+
274+ db.execSQL("CREATE TABLE " + Notebook.DB_TABLE + " (" +
275+ Notebook.ID + " INTEGER PRIMARY KEY, " +
276+ Notebook.NAME + " STRING, " +
277+ Notebook.DISPLAY + " INTEGER" +
278+ ");");
279+ if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"Table notebook has been created");
280+
281+ }
282+
283+ @Override
284+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
285+ if (Tomdroid.LOGGING_ENABLED) {
286+ Log.d(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
287+ }
288+
289+ db.execSQL("DROP TABLE IF EXISTS " + Note.DB_TABLE);
290+ db.execSQL("DROP TABLE IF EXISTS " + Notebook.DB_TABLE);
291+ onCreate(db);
292+
293+ }
294+}
295
296=== modified file 'src/org/tomdroid/Note.java'
297--- src/org/tomdroid/Note.java 2011-09-05 19:47:25 +0000
298+++ src/org/tomdroid/Note.java 2011-10-20 12:03:25 +0000
299@@ -48,6 +48,7 @@
300 public static final String FILE = "file";
301 public static final String TAGS = "tags";
302 public static final String NOTE_CONTENT = "content";
303+ public static final String DB_TABLE = "notes";
304
305 // Logging info
306 private static final String TAG = "Note";
307
308=== modified file 'src/org/tomdroid/NoteManager.java'
309--- src/org/tomdroid/NoteManager.java 2011-09-05 19:47:25 +0000
310+++ src/org/tomdroid/NoteManager.java 2011-10-20 12:03:25 +0000
311@@ -119,6 +119,9 @@
312
313 if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"Note updated in content provider. TITLE:"+note.getTitle()+" GUID:"+note.getGuid());
314 }
315+
316+ // put TAGS in notebooks table
317+ NotebookManager.putNotebook(activity, note.getTags());
318 }
319
320 public static boolean deleteNote(Activity activity, int id)
321@@ -137,21 +140,29 @@
322 public static Cursor getAllNotes(Activity activity, Boolean includeNotebookTemplates) {
323 // get a cursor representing all notes from the NoteProvider
324 Uri notes = Tomdroid.CONTENT_URI;
325- String where = null;
326+ String where = NotebookManager.getNotebookDisplayed(activity);
327+ Log.i(TAG, "where:"+where);
328+ if (where!=""){
329+ where = Note.TAGS + " IN (" + where + ")";
330+ } else {
331+ if (!includeNotebookTemplates) {
332+ where = Note.TAGS + " NOT LIKE '%" + "system:template" + "%'";
333+ }
334+ }
335 String orderBy;
336- if (!includeNotebookTemplates) {
337- where = Note.TAGS + " NOT LIKE '%" + "system:template" + "%'";
338- }
339 orderBy = Note.MODIFIED_DATE + " DESC";
340 return activity.managedQuery(notes, LIST_PROJECTION, where, null, orderBy);
341 }
342
343-
344 public static ListAdapter getListAdapter(Activity activity, String querys) {
345
346- String where;
347+ String where = null;
348+ String notebookFilter = NotebookManager.getNotebookDisplayed(activity);
349+
350 if (querys==null) {
351- where=null;
352+ if (notebookFilter.compareTo("")!=0){
353+ where = notebookFilter;
354+ }
355 } else {
356 // sql statements to search notes
357 String[] query = querys.split(" ");
358@@ -162,11 +173,15 @@
359 where = where + "("+Note.TITLE+" LIKE '%"+string+"%' OR "+Note.NOTE_CONTENT+" LIKE '%"+string+"%')";
360 count++;
361 }
362+
363+ if (notebookFilter.compareTo("")!=0){
364+ where +=" AND " + notebookFilter;
365+ }
366 }
367+ Log.i(TAG, "where:"+where);
368
369 // get a cursor representing all notes from the NoteProvider
370- Uri notes = Tomdroid.CONTENT_URI;
371- Cursor notesCursor = activity.managedQuery(notes, LIST_PROJECTION, where, null, null);
372+ Cursor notesCursor = activity.managedQuery(Tomdroid.CONTENT_URI, LIST_PROJECTION, where, null, null);
373
374 // set up an adapter binding the TITLE field of the cursor to the list item
375 String[] from = new String[] { Note.TITLE };
376@@ -234,4 +249,6 @@
377
378 return xmlContent;
379 }
380+
381+
382 }
383
384=== modified file 'src/org/tomdroid/NoteProvider.java'
385--- src/org/tomdroid/NoteProvider.java 2010-09-17 20:37:42 +0000
386+++ src/org/tomdroid/NoteProvider.java 2011-10-20 12:03:25 +0000
387@@ -51,25 +51,20 @@
388 import android.content.ContentProvider;
389 import android.content.ContentUris;
390 import android.content.ContentValues;
391-import android.content.Context;
392 import android.content.UriMatcher;
393 import android.content.res.Resources;
394 import android.database.Cursor;
395 import android.database.SQLException;
396 import android.database.sqlite.SQLiteDatabase;
397-import android.database.sqlite.SQLiteOpenHelper;
398 import android.database.sqlite.SQLiteQueryBuilder;
399 import android.net.Uri;
400 import android.text.TextUtils;
401-import android.util.Log;
402
403 public class NoteProvider extends ContentProvider {
404
405 // ContentProvider stuff
406 // --
407- private static final String DATABASE_NAME = "tomdroid-notes.db";
408 private static final String DB_TABLE_NOTES = "notes";
409- private static final int DB_VERSION = 3;
410 private static final String DEFAULT_SORT_ORDER = Note.MODIFIED_DATE + " DESC";
411
412 private static HashMap<String, String> notesProjectionMap;
413@@ -79,48 +74,14 @@
414 private static final int NOTE_TITLE = 3;
415
416 private static final UriMatcher uriMatcher;
417-
418- // Logging info
419- private static final String TAG = "NoteProvider";
420-
421- /**
422- * This class helps open, create, and upgrade the database file.
423- */
424- private static class DatabaseHelper extends SQLiteOpenHelper {
425-
426- DatabaseHelper(Context context) {
427- super(context, DATABASE_NAME, null, DB_VERSION);
428- }
429-
430- @Override
431- public void onCreate(SQLiteDatabase db) {
432- db.execSQL("CREATE TABLE " + DB_TABLE_NOTES + " ("
433- + Note.ID + " INTEGER PRIMARY KEY,"
434- + Note.GUID + " TEXT,"
435- + Note.TITLE + " TEXT,"
436- + Note.FILE + " TEXT,"
437- + Note.NOTE_CONTENT + " TEXT,"
438- + Note.MODIFIED_DATE + " STRING,"
439- + Note.TAGS + " STRING"
440- + ");");
441- }
442-
443- @Override
444- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
445- if (Tomdroid.LOGGING_ENABLED) {
446- Log.d(TAG, "Upgrading database from version " + oldVersion + " to "
447- + newVersion + ", which will destroy all old data");
448- }
449- db.execSQL("DROP TABLE IF EXISTS notes");
450- onCreate(db);
451- }
452- }
453-
454- private DatabaseHelper dbHelper;
455+
456+
457+
458+ private DbManager dbHelper;
459
460 @Override
461 public boolean onCreate() {
462- dbHelper = new DatabaseHelper(getContext());
463+ dbHelper = new DbManager(getContext());
464 return true;
465 }
466
467
468=== added file 'src/org/tomdroid/Notebook.java'
469--- src/org/tomdroid/Notebook.java 1970-01-01 00:00:00 +0000
470+++ src/org/tomdroid/Notebook.java 2011-10-20 12:03:25 +0000
471@@ -0,0 +1,9 @@
472+package org.tomdroid;
473+
474+public class Notebook {
475+ public static final String ID = "_id";
476+ public static final String NAME = "name";
477+ public static final String DISPLAY = "display";
478+ public static final String PATERN = "system:notebook:";
479+ public static final String DB_TABLE = "notebooks";
480+}
481
482=== added file 'src/org/tomdroid/NotebookManager.java'
483--- src/org/tomdroid/NotebookManager.java 1970-01-01 00:00:00 +0000
484+++ src/org/tomdroid/NotebookManager.java 2011-10-20 12:03:25 +0000
485@@ -0,0 +1,108 @@
486+package org.tomdroid;
487+
488+import org.tomdroid.ui.Tomdroid;
489+import org.tomdroid.util.NotebookListCursorAdapter;
490+
491+import android.app.Activity;
492+import android.content.ContentResolver;
493+import android.content.ContentValues;
494+import android.database.Cursor;
495+import android.net.Uri;
496+import android.util.Log;
497+
498+public class NotebookManager {
499+ private static String TAG = "NotebookManager";
500+ public static final String[] FULL_PROJECTION = {Notebook.ID, Notebook.NAME,Notebook.DISPLAY};
501+ public static final String[] NAME_PROJECTION = {Notebook.ID, Notebook.NAME};
502+
503+ public static NotebookListCursorAdapter getNotbookListAdapter(Activity activity){
504+ Log.i(TAG, "getNotbookListAdapter starting");
505+
506+ // get a cursor representing all notes from the NoteProvider
507+ Cursor notebooksCursor = getAllNotebooks(activity, false);
508+ Log.i(TAG, "notebooksCursor OK");
509+
510+ // set up an adapter binding the TITLE field of the cursor to the list item
511+ String[] from = new String[] { Notebook.NAME};
512+ int[] to = new int[] { R.id.notebook_name};
513+ return new NotebookListCursorAdapter(activity, R.layout.notebooks_list_item, notebooksCursor, from, to);
514+ }
515+
516+ public static Cursor getAllNotebooks(Activity activity, Boolean includeNotebookTemplates) {
517+ // get a cursor representing all notes from the NoteProvider
518+ Uri notebooksUri = Tomdroid.CONTENT_URI_NOTEBOOK;
519+ String order = Notebook.NAME;
520+ Log.i(TAG, "getAllNotebooks :order OK");
521+ return activity.managedQuery(notebooksUri, FULL_PROJECTION, null, null, order);
522+ }
523+
524+ // puts a note in the content provider
525+ public static void putNotebook(Activity activity, String notebook) {
526+ if (notebook.compareTo("")!=0){
527+ if (Tomdroid.LOGGING_ENABLED) Log.i(TAG,"putNotebook : "+notebook);
528+ String[] notebooks = notebook.split(",");
529+ for (int i = 0; i < notebooks.length; i++) {
530+ notebook = notebooks[i];
531+
532+ if (notebook.startsWith(Notebook.PATERN)){
533+ notebook = notebook.substring(Notebook.PATERN.length());
534+ // verify if the notebook is already in the content provider
535+
536+ // TODO make the query prettier (use querybuilder)
537+ Uri uriNotebooks = Tomdroid.CONTENT_URI_NOTEBOOK;
538+ String[] whereArgs = new String[1];
539+ whereArgs[0] = notebook;
540+
541+
542+ // The note identifier is the guid
543+ if (Tomdroid.LOGGING_ENABLED) Log.d(TAG,"Query database if this notebook already exist");
544+ ContentResolver cr = activity.getContentResolver();
545+ Cursor managedCursor = cr.query(uriNotebooks,NoteManager.EMPTY_PROJECTION,Notebook.NAME + "= ?",whereArgs, null);
546+ activity.startManagingCursor(managedCursor);
547+
548+ // Preparing the values to be either inserted or updated
549+ // depending on the result of the previous query
550+
551+ if (managedCursor.getCount() == 0) {
552+ if (Tomdroid.LOGGING_ENABLED) Log.d(TAG,"This notebook does not exist in the db. It will be insert into the db");
553+ ContentValues values = new ContentValues();
554+ values.put(Notebook.NAME, notebook);
555+ values.put(Notebook.DISPLAY, 1);
556+
557+ // This note is not in the database yet we need to insert it
558+ if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"A new notebook has been detected (not yet in db)");
559+
560+ Log.i(TAG,"putNotebook : ajout de "+notebook);
561+ Uri uri = cr.insert(uriNotebooks, values);
562+
563+ if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"notebook inserted in content provider. ID: "+uri+" notebook:"+notebook);
564+ }
565+ }
566+ }
567+
568+
569+ }
570+ }
571+
572+ public static String getNotebookDisplayed(Activity activity){
573+ String filter = "";
574+ Uri notebooksUri = Tomdroid.CONTENT_URI_NOTEBOOK;
575+ String order = Notebook.NAME;
576+ Cursor cur = activity.managedQuery(notebooksUri, NAME_PROJECTION, Notebook.DISPLAY + "=1", null, order);
577+ if (cur.moveToFirst()){
578+ int col = cur.getColumnIndex(Notebook.NAME);
579+ filter+= Note.TAGS + " like '%" + cur.getString(col)+"%'";
580+ while (cur.moveToNext()){
581+ filter+=" OR ";
582+ filter+= Note.TAGS + " like '%" + cur.getString(col)+"%'";
583+ }
584+ filter = "("+filter+")";
585+ }
586+ Log.i(TAG, "filter :"+filter);
587+
588+ return filter;
589+ }
590+
591+
592+
593+}
594
595=== added file 'src/org/tomdroid/NotebookProvider.java'
596--- src/org/tomdroid/NotebookProvider.java 1970-01-01 00:00:00 +0000
597+++ src/org/tomdroid/NotebookProvider.java 2011-10-20 12:03:25 +0000
598@@ -0,0 +1,211 @@
599+package org.tomdroid;
600+
601+import java.util.HashMap;
602+
603+import org.tomdroid.ui.Tomdroid;
604+
605+import android.content.ContentUris;
606+import android.content.UriMatcher;
607+import android.content.ContentProvider;
608+import android.content.ContentValues;
609+import android.content.res.Resources;
610+import android.database.Cursor;
611+import android.database.SQLException;
612+import android.database.sqlite.SQLiteDatabase;
613+import android.database.sqlite.SQLiteQueryBuilder;
614+import android.net.Uri;
615+import android.text.TextUtils;
616+import android.util.Log;
617+
618+public class NotebookProvider extends ContentProvider {
619+
620+ // ContentProvider stuff
621+ // --
622+
623+ private static final String DEFAULT_SORT_ORDER = Notebook.NAME;
624+
625+ private static HashMap<String, String> notesProjectionMap;
626+
627+ private static final int NOTEBOOKS = 1;
628+ private static final int NOTEBOOK_ID = 2;
629+ private static final int NOTEBOOK_TITLE = 3;
630+
631+ private static final UriMatcher uriMatcher;
632+
633+ // Logging info
634+ private static final String TAG = "NotebookProvider";
635+
636+
637+ private DbManager dbHelper;
638+
639+
640+ @Override
641+ public boolean onCreate() {
642+ dbHelper = new DbManager(getContext());
643+ return false;
644+ }
645+
646+ @Override
647+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
648+ SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
649+
650+ qb.setTables(Notebook.DB_TABLE);
651+ qb.setProjectionMap(notesProjectionMap);
652+ switch (uriMatcher.match(uri)) {
653+ case NOTEBOOKS:
654+ break;
655+
656+ case NOTEBOOK_ID:
657+ qb.appendWhere(Notebook.ID + "=" + uri.getPathSegments().get(1));
658+ break;
659+
660+ case NOTEBOOK_TITLE:
661+ qb.appendWhere(Notebook.NAME + " LIKE '" + uri.getLastPathSegment()+"'");
662+ break;
663+
664+ default:
665+ throw new IllegalArgumentException("Unknown URI " + uri);
666+ }
667+
668+ // If no sort order is specified use the default
669+ String orderBy;
670+ if (TextUtils.isEmpty(sortOrder)) {
671+ orderBy = DEFAULT_SORT_ORDER;
672+ } else {
673+ orderBy = sortOrder;
674+ }
675+
676+ // Get the database and run the query
677+ SQLiteDatabase db = dbHelper.getReadableDatabase();
678+ for (int i = 0; i < projection.length; i++) {
679+ Log.i(TAG, "projection:"+projection[i]);
680+ }
681+ Log.i(TAG, "selection:"+selection);
682+ if (selectionArgs==null){
683+ Log.i(TAG, "selectionArgs:"+selectionArgs);
684+ }else{
685+ for (int i = 0; i < selectionArgs.length; i++) {
686+ Log.i(TAG, "selectionArgs:"+selectionArgs[i]);
687+ }
688+ }
689+ Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
690+
691+ // Tell the cursor what uri to watch, so it knows when its source data changes
692+ c.setNotificationUri(getContext().getContentResolver(), uri);
693+ return c;
694+ }
695+
696+ @Override
697+ public String getType(Uri uri) {
698+ Log.i(TAG,"getType");
699+ switch (uriMatcher.match(uri)) {
700+ case NOTEBOOKS:
701+ return Tomdroid.CONTENT_TYPE;
702+
703+ case NOTEBOOK_ID:
704+ return Tomdroid.CONTENT_ITEM_TYPE;
705+
706+ case NOTEBOOK_TITLE:
707+ return Tomdroid.CONTENT_ITEM_TYPE;
708+
709+ default:
710+ throw new IllegalArgumentException("Unknown URI " + uri);
711+ }
712+ }
713+
714+
715+ // TODO the following method is probably never called and probably wouldn't work
716+ @Override
717+ public Uri insert(Uri uri, ContentValues initialValues) {
718+ // Validate the requested uri
719+ if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"insert into notebook");
720+ if (uriMatcher.match(uri) != NOTEBOOKS) {
721+ throw new IllegalArgumentException("Unknown URI " + uri);
722+ }
723+
724+ ContentValues values;
725+ if (initialValues != null) {
726+ values = new ContentValues(initialValues);
727+ } else {
728+ values = new ContentValues();
729+ }
730+
731+
732+ // TODO does this make sense?
733+ if (values.containsKey(Notebook.NAME) == false) {
734+ Resources r = Resources.getSystem();
735+ values.put(Notebook.NAME, r.getString(android.R.string.untitled));
736+ }
737+
738+ if (values.containsKey(Notebook.DISPLAY) == false) {
739+ values.put(Notebook.DISPLAY, 1);
740+ }
741+
742+ SQLiteDatabase db = dbHelper.getWritableDatabase();
743+ long rowId = db.insert(Notebook.DB_TABLE, Notebook.NAME, values); // not so sure I did the right thing here
744+ if (rowId > 0) {
745+ Uri notebookUri = ContentUris.withAppendedId(Tomdroid.CONTENT_URI_NOTEBOOK, rowId);
746+ getContext().getContentResolver().notifyChange(notebookUri, null);
747+ return notebookUri;
748+ }
749+
750+ throw new SQLException("Failed to insert row into " + uri);
751+ }
752+
753+ @Override
754+ public int delete(Uri uri, String where, String[] whereArgs) {
755+ SQLiteDatabase db = dbHelper.getWritableDatabase();
756+ int count;
757+ switch (uriMatcher.match(uri)) {
758+ case NOTEBOOKS:
759+ count = db.delete(Notebook.DB_TABLE, where, whereArgs);
760+ break;
761+
762+ case NOTEBOOK_ID:
763+ String notebookId = uri.getPathSegments().get(1);
764+ count = db.delete(Notebook.DB_TABLE, Notebook.ID + "=" + notebookId + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
765+ break;
766+
767+ default:
768+ throw new IllegalArgumentException("Unknown URI " + uri);
769+ }
770+
771+ getContext().getContentResolver().notifyChange(uri, null);
772+ return count;
773+ }
774+
775+ @Override
776+ public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
777+ SQLiteDatabase db = dbHelper.getWritableDatabase();
778+ int count;
779+ switch (uriMatcher.match(uri)) {
780+ case NOTEBOOKS:
781+ count = db.update(Notebook.DB_TABLE, values, where, whereArgs);
782+ break;
783+
784+ case NOTEBOOK_ID:
785+ String noteId = uri.getPathSegments().get(1);
786+ count = db.update(Notebook.DB_TABLE, values, Notebook.ID + "=" + noteId + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), whereArgs);
787+ break;
788+
789+ default:
790+ throw new IllegalArgumentException("Unknown URI " + uri);
791+ }
792+
793+ getContext().getContentResolver().notifyChange(uri, null);
794+ return count;
795+ }
796+
797+ static {
798+ uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
799+ uriMatcher.addURI(Tomdroid.AUTHORITY_NOTEBOOK, "notebooks", NOTEBOOKS);
800+ uriMatcher.addURI(Tomdroid.AUTHORITY_NOTEBOOK, "notebooks/#", NOTEBOOK_ID);
801+ uriMatcher.addURI(Tomdroid.AUTHORITY_NOTEBOOK, "notebooks/*", NOTEBOOK_TITLE);
802+
803+ notesProjectionMap = new HashMap<String, String>();
804+ notesProjectionMap.put(Notebook.ID, Notebook.ID);
805+ notesProjectionMap.put(Notebook.NAME, Notebook.NAME);
806+ notesProjectionMap.put(Notebook.DISPLAY, Notebook.DISPLAY);
807+ }
808+
809+}
810
811=== added file 'src/org/tomdroid/ui/Notebooks.java'
812--- src/org/tomdroid/ui/Notebooks.java 1970-01-01 00:00:00 +0000
813+++ src/org/tomdroid/ui/Notebooks.java 2011-10-20 12:03:25 +0000
814@@ -0,0 +1,114 @@
815+package org.tomdroid.ui;
816+
817+import org.tomdroid.Notebook;
818+import org.tomdroid.NotebookManager;
819+import org.tomdroid.R;
820+import org.tomdroid.util.NotebookListCursorAdapter;
821+
822+import android.app.ListActivity;
823+import android.content.Intent;
824+import android.database.Cursor;
825+import android.os.Bundle;
826+import android.util.Log;
827+import android.view.Menu;
828+import android.view.MenuItem;
829+import android.view.View;
830+import android.widget.Button;
831+import android.widget.CheckBox;
832+import android.widget.ListView;
833+import android.widget.RelativeLayout;
834+import android.widget.TextView;
835+
836+public class Notebooks extends ListActivity {
837+
838+ // Logging info
839+ private static final String TAG = "Notebooks";
840+
841+ // UI to data model glue
842+ private NotebookListCursorAdapter adapter;
843+
844+ /** Called when the activity is created. */
845+ @Override
846+ public void onCreate(Bundle savedInstanceState) {
847+ super.onCreate(savedInstanceState);
848+ setContentView(R.layout.notebooks);
849+ Log.i(TAG, "setContentView OK");
850+
851+ // adapter that binds the ListView UI to the notebooks in the note manager
852+ adapter = NotebookManager.getNotbookListAdapter(this);
853+ setListAdapter(adapter);
854+
855+ TextView title = (TextView) findViewById(R.id.title);
856+ title.setText(getString(R.string.notebookSelectTitle));
857+ }
858+
859+ @Override
860+ public boolean onCreateOptionsMenu(Menu menu) {
861+ return true;
862+ }
863+
864+ @Override
865+ public boolean onOptionsItemSelected(MenuItem item) {
866+ return super.onOptionsItemSelected(item);
867+ }
868+
869+ public void onResume() {
870+ super.onResume();
871+ }
872+
873+
874+ @Override
875+ protected void onListItemClick(ListView l, View v, int position, long id) {
876+ Log.i(TAG,"onListItemClick");
877+
878+ Cursor item = (Cursor) adapter.getItem(position);
879+ String notebook = item.getString(item.getColumnIndexOrThrow(Notebook.NAME));
880+
881+ Bundle bundle = new Bundle();
882+ bundle.putString("notebook", notebook);
883+
884+ Intent i = new Intent(this.getApplicationContext(), Tomdroid.class);
885+ i.putExtras(bundle);
886+ startActivity(i);
887+
888+ //Intent i = new Intent(Intent.ACTION_VIEW,Tomdroid.CONTENT_URI, this, Tomdroid.class);
889+ //startActivity(i);
890+ }
891+
892+ public void changeDisplay(View v){
893+ Log.i(TAG, "changeDisplay:");
894+ CheckBox checkBox = (CheckBox) v;
895+ if (checkBox.isChecked()){
896+ Log.i(TAG, "changeDisplay:a afficher");
897+ } else {
898+ Log.i(TAG, "changeDisplay:a masquer");
899+ }
900+ RelativeLayout parent = (RelativeLayout) v.getParent();
901+ Log.i(TAG, "nb child:"+parent.getChildCount());
902+ TextView name = (TextView) parent.getChildAt(0);
903+ String notebook = (String) name.getText();
904+ Log.i(TAG, "name:"+notebook);
905+
906+ Button button = (Button) findViewById(R.id.buttonOk);
907+ if (adapter.changeValue(notebook, (checkBox.isChecked()) ? 1 : 0)==0){
908+ button.setEnabled(false);
909+ } else {
910+ button.setEnabled(true);
911+ }
912+ }
913+
914+ public void validate(View v){
915+ Log.i(TAG, "validate");
916+ if (adapter.getNbCheck()==0){
917+ Log.i(TAG, "There is no notebook checked ! You must check one or more to continue");
918+ } else {
919+ adapter.updateChange(this);
920+ this.finish();
921+ //this.startActivity(new Intent(this,Tomdroid.class));
922+ }
923+ }
924+
925+ public void close(View v){
926+ this.finish();
927+ }
928+}
929
930=== modified file 'src/org/tomdroid/ui/Tomdroid.java'
931--- src/org/tomdroid/ui/Tomdroid.java 2011-09-04 17:48:08 +0000
932+++ src/org/tomdroid/ui/Tomdroid.java 2011-10-20 12:03:25 +0000
933@@ -26,6 +26,8 @@
934
935 import org.tomdroid.Note;
936 import org.tomdroid.NoteManager;
937+import org.tomdroid.Notebook;
938+import org.tomdroid.NotebookManager;
939 import org.tomdroid.R;
940 import org.tomdroid.sync.ServiceAuth;
941 import org.tomdroid.sync.SyncManager;
942@@ -34,9 +36,12 @@
943 import org.tomdroid.util.Preferences;
944 import org.tomdroid.util.Send;
945
946+import android.R.bool;
947 import android.app.AlertDialog;
948 import android.app.ListActivity;
949 import android.app.ProgressDialog;
950+import android.content.ContentResolver;
951+import android.content.ContentValues;
952 import android.content.Context;
953 import android.content.DialogInterface;
954 import android.content.Intent;
955@@ -58,15 +63,19 @@
956 import android.widget.ListAdapter;
957 import android.widget.ListView;
958 import android.widget.TextView;
959+import android.widget.Toast;
960 import android.widget.AdapterView.AdapterContextMenuInfo;
961
962 public class Tomdroid extends ListActivity {
963
964 // Global definition for Tomdroid
965 public static final String AUTHORITY = "org.tomdroid.notes";
966+ public static final String AUTHORITY_NOTEBOOK = "org.tomdroid.notebooks";
967 public static final Uri CONTENT_URI = Uri
968 .parse("content://" + AUTHORITY
969 + "/notes");
970+ public static final Uri CONTENT_URI_NOTEBOOK= Uri.parse("content://" + AUTHORITY_NOTEBOOK + "/notebooks");
971+
972 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.tomdroid.note";
973 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.tomdroid.note";
974 public static final String PROJECT_HOMEPAGE = "http://www.launchpad.net/tomdroid/";
975@@ -76,7 +85,7 @@
976 public static final String NOTES_PATH = Environment.getExternalStorageDirectory()
977 + "/tomdroid/";
978 // Logging should be disabled for release builds
979- public static final boolean LOGGING_ENABLED = false;
980+ public static final boolean LOGGING_ENABLED = true;
981 // Set this to false for release builds, the reason should be obvious
982 public static final boolean CLEAR_PREFERENCES = false;
983
984@@ -114,7 +123,9 @@
985 }
986 }).setIcon(R.drawable.icon).show();
987 }
988-
989+
990+
991+
992 // adapter that binds the ListView UI to the notes in the note manager
993 adapter = NoteManager.getListAdapter(this);
994 setListAdapter(adapter);
995@@ -151,6 +162,11 @@
996 case R.id.menuSearch:
997 startSearch(null, false, null, false);
998 return true;
999+
1000+ case R.id.menuFilterNotebook:
1001+ //startActivity(new Intent(this, Notebooks.class));
1002+ selectNotebook();
1003+ return true;
1004 }
1005
1006 return super.onOptionsItemSelected(item);
1007@@ -216,6 +232,9 @@
1008
1009 SyncManager.setActivity(this);
1010 SyncManager.setHandler(this.syncMessageHandler);
1011+
1012+ adapter = NoteManager.getListAdapter(this);
1013+ setListAdapter(adapter);
1014 }
1015
1016 private void showAboutDialog() {
1017@@ -273,5 +292,96 @@
1018 .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
1019 }
1020 }
1021+
1022+ private int nbNotebook = 0;
1023+ private String[] notebooks = null;
1024+ private boolean[] checks = null;
1025+ private boolean[] update = null;
1026+ private Context myContext = null;
1027+
1028+
1029+ private void selectNotebook(){
1030+ AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
1031+ dialogBuilder.setTitle(R.string.notebookSelectTitle);
1032+
1033+ Cursor cur = NotebookManager.getAllNotebooks(this, false);
1034+ nbNotebook = cur.getCount();
1035+ notebooks = new String[nbNotebook];
1036+ checks = new boolean[nbNotebook];
1037+ update = new boolean[nbNotebook];
1038+ myContext = this.getApplicationContext();
1039+ int i=0;
1040+ boolean ok = cur.moveToFirst();
1041+ while (ok){
1042+ notebooks[i] = cur.getString(cur.getColumnIndex(Notebook.NAME));
1043+ checks[i] = cur.getInt(cur.getColumnIndex(Notebook.DISPLAY)) == 1;
1044+ update[i] = false;
1045+ ok = cur.moveToNext();
1046+ i++;
1047+ }
1048+
1049+ dialogBuilder.setMultiChoiceItems(notebooks,checks, new DialogInterface.OnMultiChoiceClickListener(){
1050+
1051+ public void onClick(DialogInterface dialog, int which, boolean isChecked) {
1052+ checks[which] = isChecked;
1053+ update[which] = true;
1054+ if (LOGGING_ENABLED) Log.d(TAG, "which:"+which+" isChecked:"+isChecked+" notebook:"+notebooks[which]);
1055+
1056+ boolean allUncheck = true;
1057+ for (int i=0; i<nbNotebook;i++){
1058+ if (checks[i]){
1059+ allUncheck = false;
1060+ }
1061+ }
1062+
1063+ if (allUncheck){
1064+ if (LOGGING_ENABLED) Log.d(TAG, "All checkbox are checked");
1065+ checks[which] = true;
1066+ Toast.makeText(myContext, myContext.getString(R.string.notebookMustSelectOne), Toast.LENGTH_SHORT).show();
1067+ }
1068+
1069+ }
1070+
1071+ });
1072+ dialogBuilder.setPositiveButton(R.string.btnOk, new DialogInterface.OnClickListener() {
1073+
1074+ public void onClick(DialogInterface dialog, int which) {
1075+
1076+ ContentResolver cr = getContentResolver();
1077+ String[] whereArgs = new String[1];
1078+
1079+ for (int i=0; i<nbNotebook;i++){
1080+ if (update[i]){
1081+ whereArgs[0] = notebooks[i];
1082+ ContentValues values = new ContentValues();
1083+ values.put(Notebook.DISPLAY, (checks[i]) ? 1 : 0);
1084+ cr.update(Tomdroid.CONTENT_URI_NOTEBOOK, values, Notebook.NAME +" = ?", whereArgs);
1085+ }
1086+ }
1087+
1088+ dialog.cancel();
1089+ updateView();
1090+ }
1091+ });
1092+ dialogBuilder.setNegativeButton(R.string.btnCancel, new DialogInterface.OnClickListener(){
1093+
1094+ public void onClick(DialogInterface dialog, int which) {
1095+ dialog.cancel();
1096+
1097+ }
1098+
1099+ });
1100+
1101+
1102+
1103+ AlertDialog dialog = dialogBuilder.create();
1104+ dialog.show();
1105+ }
1106+
1107+ public void updateView(){
1108+ adapter = NoteManager.getListAdapter(this);
1109+ setListAdapter(adapter);
1110+ }
1111+
1112
1113 }
1114
1115=== added file 'src/org/tomdroid/util/NotebookListCursorAdapter.java'
1116--- src/org/tomdroid/util/NotebookListCursorAdapter.java 1970-01-01 00:00:00 +0000
1117+++ src/org/tomdroid/util/NotebookListCursorAdapter.java 2011-10-20 12:03:25 +0000
1118@@ -0,0 +1,119 @@
1119+package org.tomdroid.util;
1120+
1121+import java.util.ArrayList;
1122+import java.util.HashMap;
1123+
1124+import org.tomdroid.Notebook;
1125+import org.tomdroid.R;
1126+import org.tomdroid.ui.Tomdroid;
1127+
1128+import android.app.Activity;
1129+import android.content.ContentResolver;
1130+import android.content.ContentValues;
1131+import android.content.Context;
1132+import android.database.Cursor;
1133+import android.net.Uri;
1134+import android.util.Log;
1135+import android.view.View;
1136+import android.widget.CheckBox;
1137+import android.widget.SimpleCursorAdapter;
1138+import android.widget.TextView;
1139+
1140+public class NotebookListCursorAdapter extends SimpleCursorAdapter {
1141+ public HashMap<String,String> checkboxInit = new HashMap<String, String>();;
1142+ public HashMap<String,String> checkbox = new HashMap<String, String>();;
1143+ public ArrayList<String > notebookName = new ArrayList<String>();
1144+
1145+ private String TAG = "NotebookListCursorAdapter";
1146+ private int nbNotebook = 0;
1147+ private int nbCheck = 0;
1148+
1149+
1150+ public NotebookListCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
1151+ super(context, layout, c, from, to);
1152+ nbNotebook = c.getCount();
1153+ nbCheck = 0;
1154+
1155+ if (c.moveToFirst()){
1156+ int colName = c.getColumnIndex(Notebook.NAME);
1157+ int colDipslay = c.getColumnIndex(Notebook.DISPLAY);
1158+
1159+ checkboxInit.put(c.getString(colName), c.getString(colDipslay));
1160+ notebookName.add(c.getString(colName));
1161+ if (c.getInt(colDipslay)==1){
1162+ nbCheck++;
1163+ }
1164+
1165+ while (c.moveToNext()){
1166+
1167+ if (c.getInt(colDipslay)==1){
1168+ nbCheck++;
1169+ }
1170+ checkboxInit.put(c.getString(colName), c.getString(colDipslay));
1171+ notebookName.add(c.getString(colName));
1172+ }
1173+ checkbox = (HashMap<String, String>) checkboxInit.clone();
1174+ }
1175+ }
1176+
1177+
1178+ @Override
1179+ public void bindView(View view, Context context, Cursor cursor) {
1180+ TextView name = (TextView) view.findViewById(R.id.notebook_name);
1181+ if (name!=null){
1182+ if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "notebook name:"+cursor.getString(cursor.getColumnIndex(Notebook.NAME)));
1183+ name.setText(cursor.getString(cursor.getColumnIndex(Notebook.NAME)));
1184+ }
1185+
1186+ CheckBox chekbox = (CheckBox) view.findViewById(R.id.notebook_checkbox);
1187+ if (chekbox!=null){
1188+ int dipslay = cursor.getInt(cursor.getColumnIndex(Notebook.DISPLAY));
1189+ if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "dipslay:"+dipslay);
1190+ chekbox.setChecked(dipslay==1);
1191+ }
1192+ }
1193+
1194+ public int changeValue(String notebook,int value){
1195+ checkbox.remove(notebook);
1196+ checkbox.put(notebook, ""+value);
1197+
1198+ if (value==1){
1199+ nbCheck++;
1200+ } else {
1201+ nbCheck--;
1202+ }
1203+ return nbCheck;
1204+ }
1205+
1206+ public void updateChange(Activity activity){
1207+ Log.i(TAG, "updateChange");
1208+ Uri uriNotebooks = Tomdroid.CONTENT_URI_NOTEBOOK;
1209+ String[] whereArgs = new String[1];
1210+ ContentResolver cr = activity.getContentResolver();
1211+
1212+ for (int i = 0; i < nbNotebook; i++) {
1213+ String notebook = notebookName.get(i);
1214+ if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "traitement :"+notebook);
1215+
1216+ if (checkbox.get(notebook).compareTo(checkboxInit.get(notebook))!=0){
1217+ if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, ""+notebook+" a changé");
1218+ whereArgs[0] = notebook;
1219+
1220+ ContentValues values = new ContentValues();
1221+ values.put(Notebook.DISPLAY, Integer.parseInt(checkbox.get(notebook)));
1222+ cr.update(uriNotebooks, values, Notebook.NAME +" = ?", whereArgs);
1223+
1224+ if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"Notebook updated in content provider. Name:"+notebook);
1225+ }
1226+
1227+ }
1228+ }
1229+
1230+
1231+ public int getNbCheck() {
1232+ return nbCheck;
1233+ }
1234+
1235+
1236+
1237+}

Subscribers

People subscribed via source and target branches