Merge lp:~mcveat/tomdroid/loggers-cleanup into lp:~tomdroid-maintainers/tomdroid/main

Proposed by Piotr Adamski
Status: Merged
Approved by: Olivier Bilodeau
Approved revision: 259
Merge reported by: Olivier Bilodeau
Merged at revision: not available
Proposed branch: lp:~mcveat/tomdroid/loggers-cleanup
Merge into: lp:~tomdroid-maintainers/tomdroid/main
Diff against target: 1070 lines (+248/-209)
16 files modified
src/org/tomdroid/Note.java (+9/-10)
src/org/tomdroid/NoteManager.java (+14/-13)
src/org/tomdroid/NoteProvider.java (+8/-15)
src/org/tomdroid/sync/SyncService.java (+12/-14)
src/org/tomdroid/sync/sd/SdCardSyncService.java (+18/-26)
src/org/tomdroid/sync/web/OAuthConnection.java (+8/-13)
src/org/tomdroid/sync/web/SnowySyncService.java (+15/-17)
src/org/tomdroid/sync/web/WebConnection.java (+9/-11)
src/org/tomdroid/ui/PreferencesActivity.java (+16/-17)
src/org/tomdroid/ui/Search.java (+8/-9)
src/org/tomdroid/ui/SyncMessageHandler.java (+6/-8)
src/org/tomdroid/ui/Tomdroid.java (+15/-22)
src/org/tomdroid/ui/ViewNote.java (+16/-17)
src/org/tomdroid/util/FirstNote.java (+3/-5)
src/org/tomdroid/util/NoteContentBuilder.java (+8/-12)
src/org/tomdroid/util/TLog.java (+83/-0)
To merge this branch: bzr merge lp:~mcveat/tomdroid/loggers-cleanup
Reviewer Review Type Date Requested Status
Olivier Bilodeau Approve
Review via email: mp+80501@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

Hello Piotr,

"if (Tomdroid.LOGGING_ENABLED)"s are written for all Log.xxx functions.

It is repetitious.
I think it will be more simpler if you create functions which check Tomdroid.LOGGING_ENABLED and use Log.xxx.

Regards,
Koichi Akabe

Revision history for this message
Alex Belisle Turcot (alex-belisleturcot) wrote :

Bu then, would the debug Strings be created every time, even when logging is
not enabled ?

check this:
http://stackoverflow.com/questions/963492/in-log4j-does-checking-isdebugenabled-before-logging-improve-performance

[quote]
*The guard statement (checking isDebugEnabled()) is there to prevent
potentially expensive computation of the log message*
...
*Better yet is to use a more up-to-date logging framework where the log
statements take a format string and a list of arguments to be substituted by
the formatter—but "lazily," only if the logger is enabled. This is the
approach taken by
slf4j<http://www.slf4j.org/apidocs/org/slf4j/Logger.html#debug%28java.lang.String,%20java.lang.Object%5B%5D%29>
.*
[/quote]

Current logging frameworks ensure sure that debug Strings are not
concatenated unless debug is enabled. I'm not sure how to do that in
Android, you may need to code this mini-framework yourself...

Regards,
Alex

On Thu, Oct 27, 2011 at 7:58 AM, Koichi Akabe <email address hidden> wrote:

> Hello Piotr,
>
> "if (Tomdroid.LOGGING_ENABLED)"s are written for all Log.xxx functions.
>
> It is repetitious.
> I think it will be more simpler if you create functions which check
> Tomdroid.LOGGING_ENABLED and use Log.xxx.
>
> Regards,
> Koichi Akabe
> --
> https://code.launchpad.net/~mcveat/tomdroid/loggers-cleanup/+merge/80501
> You are subscribed to branch lp:tomdroid.
>

Revision history for this message
Piotr Adamski (mcveat) wrote :

On Thu, Oct 27, 2011 at 2:25 PM, Alex Belisle Turcot
<email address hidden> wrote:
> Bu then, would the debug Strings be created every time, even when logging is
> not enabled ?

I was also concerned about that.

> Current logging frameworks ensure sure that debug Strings are not
> concatenated unless debug is enabled. I'm not sure how to do that in
> Android, you may need to code this mini-framework yourself...

Should be pretty straightforward, yet not so versatile with use of
java.text.MessageFormat and varargs. I'll try how it rolls this
evening.

Regards
Piotr

lp:~mcveat/tomdroid/loggers-cleanup updated
256. By Piotr Adamski

excluded turning off logging logic to separate clas TLog

257. By Piotr Adamski

merged with main

258. By Piotr Adamski

updated license note

259. By Piotr Adamski

removed forgotten debug statements

Revision history for this message
Piotr Adamski (mcveat) wrote :

I've implemented simple logging utility that should remove the boilerplate code of checking logging switch state, yet avoiding unnecessary string concatenations. Tell what you think about it.

Revision history for this message
Koichi Akabe (vbkaisetsu) wrote :

I think it is great work!!

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

Good stuff! Thanks! Next time try not to re-organize imports please. Makes patches larger than they should be and merging more complicated.

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

Turns out I needed to make additional changes. See https://code.launchpad.net/~tomdroid-dev/tomdroid/loggers-cleanup if you are interested.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/org/tomdroid/Note.java'
--- src/org/tomdroid/Note.java 2011-09-05 19:47:25 +0000
+++ src/org/tomdroid/Note.java 2011-10-27 17:18:24 +0000
@@ -23,19 +23,18 @@
23 */23 */
24package org.tomdroid;24package org.tomdroid;
2525
26import java.util.regex.Matcher;26import android.os.Handler;
27import java.util.regex.Pattern;27import android.text.SpannableStringBuilder;
2828import android.text.format.Time;
29import android.util.TimeFormatException;
29import org.json.JSONArray;30import org.json.JSONArray;
30import org.json.JSONObject;31import org.json.JSONObject;
31import org.tomdroid.util.NoteContentBuilder;32import org.tomdroid.util.NoteContentBuilder;
33import org.tomdroid.util.TLog;
32import org.tomdroid.util.XmlUtils;34import org.tomdroid.util.XmlUtils;
3335
34import android.os.Handler;36import java.util.regex.Matcher;
35import android.text.SpannableStringBuilder;37import java.util.regex.Pattern;
36import android.text.format.Time;
37import android.util.Log;
38import android.util.TimeFormatException;
3938
40public class Note {39public class Note {
4140
@@ -145,9 +144,9 @@
145 // Tomboy's (C# library) format: 2010-01-23T12:07:38.7743020-05:00144 // Tomboy's (C# library) format: 2010-01-23T12:07:38.7743020-05:00
146 Matcher m = dateCleaner.matcher(lastChangeDateStr);145 Matcher m = dateCleaner.matcher(lastChangeDateStr);
147 if (m.find()) {146 if (m.find()) {
148 Log.d(TAG, "I had to clean out extra sub-milliseconds from the date");147 TLog.d(TAG, "I had to clean out extra sub-milliseconds from the date");
149 lastChangeDateStr = m.group(1)+m.group(2);148 lastChangeDateStr = m.group(1)+m.group(2);
150 Log.v(TAG, "new date: "+lastChangeDateStr);149 TLog.v(TAG, "new date: {0}", lastChangeDateStr);
151 }150 }
152 151
153 lastChangeDate = new Time();152 lastChangeDate = new Time();
154153
=== modified file 'src/org/tomdroid/NoteManager.java'
--- src/org/tomdroid/NoteManager.java 2011-09-05 19:47:25 +0000
+++ src/org/tomdroid/NoteManager.java 2011-10-27 17:18:24 +0000
@@ -24,20 +24,19 @@
24 */24 */
25package org.tomdroid;25package org.tomdroid;
2626
27import java.util.regex.Matcher;
28import java.util.regex.Pattern;
29
30import org.tomdroid.ui.Tomdroid;
31import org.tomdroid.util.NoteListCursorAdapter;
32import org.tomdroid.util.XmlUtils;
33
34import android.app.Activity;27import android.app.Activity;
35import android.content.ContentResolver;28import android.content.ContentResolver;
36import android.content.ContentValues;29import android.content.ContentValues;
37import android.database.Cursor;30import android.database.Cursor;
38import android.net.Uri;31import android.net.Uri;
39import android.util.Log;
40import android.widget.ListAdapter;32import android.widget.ListAdapter;
33import org.tomdroid.ui.Tomdroid;
34import org.tomdroid.util.NoteListCursorAdapter;
35import org.tomdroid.util.TLog;
36import org.tomdroid.util.XmlUtils;
37
38import java.util.regex.Matcher;
39import java.util.regex.Pattern;
4140
42public class NoteManager {41public class NoteManager {
43 42
@@ -107,17 +106,19 @@
107 if (managedCursor.getCount() == 0) {106 if (managedCursor.getCount() == 0) {
108 107
109 // This note is not in the database yet we need to insert it108 // This note is not in the database yet we need to insert it
110 if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"A new note has been detected (not yet in db)");109 TLog.v(TAG, "A new note has been detected (not yet in db)");
111 110
112 Uri uri = cr.insert(Tomdroid.CONTENT_URI, values);111 Uri uri = cr.insert(Tomdroid.CONTENT_URI, values);
113112
114 if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"Note inserted in content provider. ID: "+uri+" TITLE:"+note.getTitle()+" GUID:"+note.getGuid());113 TLog.v(TAG, "Note inserted in content provider. ID: {0} TITLE:{1} GUID:{2}", uri, note.getTitle(),
114 note.getGuid());
115 } else {115 } else {
116 116
117 // Overwrite the previous note if it exists117 // Overwrite the previous note if it exists
118 cr.update(Tomdroid.CONTENT_URI, values, Note.GUID+" = ?", whereArgs);118 cr.update(Tomdroid.CONTENT_URI, values, Note.GUID+" = ?", whereArgs);
119 119
120 if (Tomdroid.LOGGING_ENABLED) Log.v(TAG,"Note updated in content provider. TITLE:"+note.getTitle()+" GUID:"+note.getGuid());120 TLog.v(TAG, "Note updated in content provider. TITLE:{0} GUID:{1}", note.getTitle(),
121 note.getGuid());
121 }122 }
122 }123 }
123 124
@@ -209,7 +210,7 @@
209 }210 }
210 else {211 else {
211 // TODO send an error to the user212 // TODO send an error to the user
212 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "Cursor returned null or 0 notes");213 TLog.d(TAG, "Cursor returned null or 0 notes");
213 }214 }
214 215
215 return id;216 return id;
@@ -229,7 +230,7 @@
229 Matcher m = stripTitle.matcher(xmlContent);230 Matcher m = stripTitle.matcher(xmlContent);
230 if (m.find()) {231 if (m.find()) {
231 xmlContent = xmlContent.substring(m.end(), xmlContent.length());232 xmlContent = xmlContent.substring(m.end(), xmlContent.length());
232 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "stripped the title from note-content");233 TLog.d(TAG, "stripped the title from note-content");
233 }234 }
234 235
235 return xmlContent;236 return xmlContent;
236237
=== modified file 'src/org/tomdroid/NoteProvider.java'
--- src/org/tomdroid/NoteProvider.java 2010-09-17 20:37:42 +0000
+++ src/org/tomdroid/NoteProvider.java 2011-10-27 17:18:24 +0000
@@ -43,16 +43,7 @@
43 */43 */
44package org.tomdroid;44package org.tomdroid;
4545
46import java.util.HashMap;46import android.content.*;
47import java.util.UUID;
48
49import org.tomdroid.ui.Tomdroid;
50
51import android.content.ContentProvider;
52import android.content.ContentUris;
53import android.content.ContentValues;
54import android.content.Context;
55import android.content.UriMatcher;
56import android.content.res.Resources;47import android.content.res.Resources;
57import android.database.Cursor;48import android.database.Cursor;
58import android.database.SQLException;49import android.database.SQLException;
@@ -61,7 +52,11 @@
61import android.database.sqlite.SQLiteQueryBuilder;52import android.database.sqlite.SQLiteQueryBuilder;
62import android.net.Uri;53import android.net.Uri;
63import android.text.TextUtils;54import android.text.TextUtils;
64import android.util.Log;55import org.tomdroid.ui.Tomdroid;
56import org.tomdroid.util.TLog;
57
58import java.util.HashMap;
59import java.util.UUID;
6560
66public class NoteProvider extends ContentProvider {61public class NoteProvider extends ContentProvider {
67 62
@@ -107,10 +102,8 @@
107102
108 @Override103 @Override
109 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {104 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
110 if (Tomdroid.LOGGING_ENABLED) {105 TLog.d(TAG, "Upgrading database from version {0} to {1}, which will destroy all old data",
111 Log.d(TAG, "Upgrading database from version " + oldVersion + " to "106 oldVersion, newVersion);
112 + newVersion + ", which will destroy all old data");
113 }
114 db.execSQL("DROP TABLE IF EXISTS notes");107 db.execSQL("DROP TABLE IF EXISTS notes");
115 onCreate(db);108 onCreate(db);
116 }109 }
117110
=== modified file 'src/org/tomdroid/sync/SyncService.java'
--- src/org/tomdroid/sync/SyncService.java 2010-12-13 02:55:59 +0000
+++ src/org/tomdroid/sync/SyncService.java 2011-10-27 17:18:24 +0000
@@ -24,23 +24,21 @@
24 */24 */
25package org.tomdroid.sync;25package org.tomdroid.sync;
2626
27import java.util.ArrayList;
28import java.util.HashMap;
29import java.util.concurrent.ExecutorService;
30import java.util.concurrent.Executors;
31
32import org.tomdroid.Note;
33import org.tomdroid.NoteManager;
34import org.tomdroid.ui.Tomdroid;
35import org.tomdroid.util.ErrorList;
36
37import org.tomdroid.R;
38import android.app.Activity;27import android.app.Activity;
39import android.database.Cursor;28import android.database.Cursor;
40import android.os.Handler;29import android.os.Handler;
41import android.os.Message;30import android.os.Message;
42import android.util.Log;
43import android.widget.Toast;31import android.widget.Toast;
32import org.tomdroid.Note;
33import org.tomdroid.NoteManager;
34import org.tomdroid.R;
35import org.tomdroid.util.ErrorList;
36import org.tomdroid.util.TLog;
37
38import java.util.ArrayList;
39import java.util.HashMap;
40import java.util.concurrent.ExecutorService;
41import java.util.concurrent.Executors;
4442
45public abstract class SyncService {43public abstract class SyncService {
46 44
@@ -174,7 +172,7 @@
174 } else {172 } else {
175 173
176 // TODO send an error to the user174 // TODO send an error to the user
177 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "Cursor returned null or 0 notes");175 TLog.d(TAG, "Cursor returned null or 0 notes");
178 }176 }
179 }177 }
180 178
@@ -214,7 +212,7 @@
214 212
215 protected void setSyncProgress(int progress) {213 protected void setSyncProgress(int progress) {
216 synchronized (TAG) {214 synchronized (TAG) {
217 Log.v(TAG, "sync progress: " + progress);215 TLog.v(TAG, "sync progress: {0}", progress);
218 Message progressMessage = new Message();216 Message progressMessage = new Message();
219 progressMessage.what = SYNC_PROGRESS;217 progressMessage.what = SYNC_PROGRESS;
220 progressMessage.arg1 = progress;218 progressMessage.arg1 = progress;
221219
=== modified file 'src/org/tomdroid/sync/sd/SdCardSyncService.java'
--- src/org/tomdroid/sync/sd/SdCardSyncService.java 2011-09-05 19:47:25 +0000
+++ src/org/tomdroid/sync/sd/SdCardSyncService.java 2011-10-27 17:18:24 +0000
@@ -24,30 +24,22 @@
24 */24 */
25package org.tomdroid.sync.sd;25package org.tomdroid.sync.sd;
2626
27import java.io.File;27import android.app.Activity;
28import java.io.FileInputStream;28import android.os.Handler;
29import java.io.FilenameFilter;29import android.util.TimeFormatException;
30import java.io.IOException;
31import java.io.InputStreamReader;
32import java.io.Reader;
33import java.io.StringReader;
34import java.util.regex.Matcher;
35import java.util.regex.Pattern;
36
37import javax.xml.parsers.SAXParser;
38import javax.xml.parsers.SAXParserFactory;
39
40import org.tomdroid.Note;30import org.tomdroid.Note;
41import org.tomdroid.sync.SyncService;31import org.tomdroid.sync.SyncService;
42import org.tomdroid.ui.Tomdroid;32import org.tomdroid.ui.Tomdroid;
43import org.tomdroid.util.ErrorList;33import org.tomdroid.util.ErrorList;
34import org.tomdroid.util.TLog;
44import org.xml.sax.InputSource;35import org.xml.sax.InputSource;
45import org.xml.sax.XMLReader;36import org.xml.sax.XMLReader;
4637
47import android.app.Activity;38import javax.xml.parsers.SAXParser;
48import android.os.Handler;39import javax.xml.parsers.SAXParserFactory;
49import android.util.Log;40import java.io.*;
50import android.util.TimeFormatException;41import java.util.regex.Matcher;
42import java.util.regex.Pattern;
5143
52public class SdCardSyncService extends SyncService {44public class SdCardSyncService extends SyncService {
53 45
@@ -89,18 +81,18 @@
89 setSyncProgress(0);81 setSyncProgress(0);
9082
91 // start loading local notes83 // start loading local notes
92 if (Tomdroid.LOGGING_ENABLED) Log.v(TAG, "Loading local notes");84 TLog.v(TAG, "Loading local notes");
93 85
94 File path = new File(Tomdroid.NOTES_PATH);86 File path = new File(Tomdroid.NOTES_PATH);
95 87
96 if (!path.exists())88 if (!path.exists())
97 path.mkdir();89 path.mkdir();
98 90
99 Log.i(TAG, "Path "+path+" exists: "+path.exists());91 TLog.i(TAG, "Path {0} exists: {1}", path, path.exists());
100 92
101 // Check a second time, if not the most likely cause is the volume doesn't exist93 // Check a second time, if not the most likely cause is the volume doesn't exist
102 if(!path.exists()) {94 if(!path.exists()) {
103 if (Tomdroid.LOGGING_ENABLED) Log.w(TAG, "Couldn't create "+path);95 TLog.w(TAG, "Couldn't create {0}", path);
104 sendMessage(NO_SD_CARD);96 sendMessage(NO_SD_CARD);
105 setSyncProgress(100);97 setSyncProgress(100);
106 return;98 return;
@@ -111,7 +103,7 @@
111 103
112 // If there are no notes, warn the UI through an empty message104 // If there are no notes, warn the UI through an empty message
113 if (fileList == null || fileList.length == 0) {105 if (fileList == null || fileList.length == 0) {
114 if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "There are no notes in "+path);106 TLog.i(TAG, "There are no notes in {0}", path);
115 sendMessage(PARSING_NO_NOTES);107 sendMessage(PARSING_NO_NOTES);
116 setSyncProgress(100);108 setSyncProgress(100);
117 return;109 return;
@@ -169,7 +161,7 @@
169 contents = readFile();161 contents = readFile();
170 } catch (IOException e) {162 } catch (IOException e) {
171 e.printStackTrace();163 e.printStackTrace();
172 if (Tomdroid.LOGGING_ENABLED) Log.w(TAG, "Something went wrong trying to read the note");164 TLog.w(TAG, "Something went wrong trying to read the note");
173 sendMessage(PARSING_FAILED, ErrorList.createError(note, e));165 sendMessage(PARSING_FAILED, ErrorList.createError(note, e));
174 onWorkDone();166 onWorkDone();
175 return;167 return;
@@ -193,27 +185,27 @@
193 StringReader sr = new StringReader(contents);185 StringReader sr = new StringReader(contents);
194 InputSource is = new InputSource(sr);186 InputSource is = new InputSource(sr);
195 187
196 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "parsing note");188 TLog.d(TAG, "parsing note");
197 xr.parse(is);189 xr.parse(is);
198190
199 // TODO wrap and throw a new exception here191 // TODO wrap and throw a new exception here
200 } catch (Exception e) {192 } catch (Exception e) {
201 e.printStackTrace();193 e.printStackTrace();
202 if(e instanceof TimeFormatException) Log.e(TAG, "Problem parsing the note's date and time");194 if(e instanceof TimeFormatException) TLog.e(TAG, "Problem parsing the note's date and time");
203 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents(note, e, contents));195 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents(note, e, contents));
204 onWorkDone();196 onWorkDone();
205 return;197 return;
206 }198 }
207199
208 // extract the <note-content..>...</note-content>200 // extract the <note-content..>...</note-content>
209 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "retrieving what is inside of note-content");201 TLog.d(TAG, "retrieving what is inside of note-content");
210 202
211 // FIXME here we are re-reading the whole note just to grab note-content out, there is probably a best way to do this (I'm talking to you xmlpull.org!)203 // FIXME here we are re-reading the whole note just to grab note-content out, there is probably a best way to do this (I'm talking to you xmlpull.org!)
212 Matcher m = note_content.matcher(contents);204 Matcher m = note_content.matcher(contents);
213 if (m.find()) {205 if (m.find()) {
214 note.setXmlContent(m.group(1));206 note.setXmlContent(m.group(1));
215 } else {207 } else {
216 if (Tomdroid.LOGGING_ENABLED) Log.w(TAG, "Something went wrong trying to grab the note-content out of a note");208 TLog.w(TAG, "Something went wrong trying to grab the note-content out of a note");
217 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents(note, "Something went wrong trying to grab the note-content out of a note", contents));209 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents(note, "Something went wrong trying to grab the note-content out of a note", contents));
218 onWorkDone();210 onWorkDone();
219 return;211 return;
220212
=== modified file 'src/org/tomdroid/sync/web/OAuthConnection.java'
--- src/org/tomdroid/sync/web/OAuthConnection.java 2010-08-31 21:00:35 +0000
+++ src/org/tomdroid/sync/web/OAuthConnection.java 2011-10-27 17:18:24 +0000
@@ -22,9 +22,7 @@
22 */22 */
23package org.tomdroid.sync.web;23package org.tomdroid.sync.web;
2424
25import java.io.UnsupportedEncodingException;25import android.net.Uri;
26import java.net.UnknownHostException;
27
28import oauth.signpost.OAuthConsumer;26import oauth.signpost.OAuthConsumer;
29import oauth.signpost.OAuthProvider;27import oauth.signpost.OAuthProvider;
30import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;28import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
@@ -33,7 +31,6 @@
33import oauth.signpost.exception.OAuthExpectationFailedException;31import oauth.signpost.exception.OAuthExpectationFailedException;
34import oauth.signpost.exception.OAuthMessageSignerException;32import oauth.signpost.exception.OAuthMessageSignerException;
35import oauth.signpost.exception.OAuthNotAuthorizedException;33import oauth.signpost.exception.OAuthNotAuthorizedException;
36
37import org.apache.http.HttpRequest;34import org.apache.http.HttpRequest;
38import org.apache.http.HttpResponse;35import org.apache.http.HttpResponse;
39import org.apache.http.client.methods.HttpGet;36import org.apache.http.client.methods.HttpGet;
@@ -41,11 +38,11 @@
41import org.apache.http.entity.StringEntity;38import org.apache.http.entity.StringEntity;
42import org.json.JSONException;39import org.json.JSONException;
43import org.json.JSONObject;40import org.json.JSONObject;
44import org.tomdroid.ui.Tomdroid;
45import org.tomdroid.util.Preferences;41import org.tomdroid.util.Preferences;
42import org.tomdroid.util.TLog;
4643
47import android.net.Uri;44import java.io.UnsupportedEncodingException;
48import android.util.Log;45import java.net.UnknownHostException;
4946
50public class OAuthConnection extends WebConnection {47public class OAuthConnection extends WebConnection {
51 48
@@ -168,14 +165,14 @@
168 return null;165 return null;
169 }166 }
170 167
171 if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Authorization URL : "+url);168 TLog.i(TAG, "Authorization URL : {0}", url);
172 169
173 return Uri.parse(url);170 return Uri.parse(url);
174 }171 }
175 172
176 public boolean getAccess(String verifier) throws UnknownHostException {173 public boolean getAccess(String verifier) throws UnknownHostException {
177 174
178 Log.i(TAG, "Verifier: "+verifier);175 TLog.i(TAG, "Verifier: {0}", verifier);
179 176
180 // this method shouldn't have been called177 // this method shouldn't have been called
181 if (isAuthenticated())178 if (isAuthenticated())
@@ -183,9 +180,7 @@
183 180
184 if (!requestToken.equals("") && !requestTokenSecret.equals("")) {181 if (!requestToken.equals("") && !requestTokenSecret.equals("")) {
185 consumer.setTokenWithSecret(requestToken, requestTokenSecret);182 consumer.setTokenWithSecret(requestToken, requestTokenSecret);
186 if(Tomdroid.LOGGING_ENABLED) {183 TLog.d(TAG, "Added request token {0} and request token secret {1)", requestTokenSecret, requestTokenSecret);
187 Log.d(TAG, "Added request token "+requestTokenSecret+" and request token secret "+requestTokenSecret);
188 }
189 }184 }
190 else185 else
191 return false;186 return false;
@@ -225,7 +220,7 @@
225 220
226 saveConfiguration();221 saveConfiguration();
227 222
228 if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Got access token "+consumer.getToken()+".");223 TLog.i(TAG, "Got access token {0}.", consumer.getToken());
229 224
230 return true;225 return true;
231 }226 }
232227
=== modified file 'src/org/tomdroid/sync/web/SnowySyncService.java'
--- src/org/tomdroid/sync/web/SnowySyncService.java 2010-11-05 23:54:32 +0000
+++ src/org/tomdroid/sync/web/SnowySyncService.java 2011-10-27 17:18:24 +0000
@@ -22,24 +22,22 @@
22 */22 */
23package org.tomdroid.sync.web;23package org.tomdroid.sync.web;
2424
25import java.net.UnknownHostException;25import android.app.Activity;
26import java.util.ArrayList;26import android.net.Uri;
2727import android.os.Handler;
28import android.os.Message;
28import org.json.JSONArray;29import org.json.JSONArray;
29import org.json.JSONException;30import org.json.JSONException;
30import org.json.JSONObject;31import org.json.JSONObject;
31import org.tomdroid.Note;32import org.tomdroid.Note;
32import org.tomdroid.sync.ServiceAuth;33import org.tomdroid.sync.ServiceAuth;
33import org.tomdroid.sync.SyncService;34import org.tomdroid.sync.SyncService;
34import org.tomdroid.ui.Tomdroid;
35import org.tomdroid.util.ErrorList;35import org.tomdroid.util.ErrorList;
36import org.tomdroid.util.Preferences;36import org.tomdroid.util.Preferences;
37import org.tomdroid.util.TLog;
3738
38import android.app.Activity;39import java.net.UnknownHostException;
39import android.net.Uri;40import java.util.ArrayList;
40import android.os.Handler;
41import android.os.Message;
42import android.util.Log;
4341
44public class SnowySyncService extends SyncService implements ServiceAuth {42public class SnowySyncService extends SyncService implements ServiceAuth {
45 43
@@ -88,7 +86,7 @@
88 authUri = auth.getAuthorizationUrl(server);86 authUri = auth.getAuthorizationUrl(server);
89 87
90 } catch (UnknownHostException e) {88 } catch (UnknownHostException e) {
91 Log.e(TAG, "Internet connection not available");89 TLog.e(TAG, "Internet connection not available");
92 sendMessage(NO_INTERNET);90 sendMessage(NO_INTERNET);
93 }91 }
94 92
@@ -114,12 +112,12 @@
114 boolean result = auth.getAccess(uri.getQueryParameter("oauth_verifier"));112 boolean result = auth.getAccess(uri.getQueryParameter("oauth_verifier"));
115113
116 if (result) {114 if (result) {
117 if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "The authorization process is complete.");115 TLog.i(TAG, "The authorization process is complete.");
118 } else {116 } else {
119 Log.e(TAG, "Something went wrong during the authorization process.");117 TLog.e(TAG, "Something went wrong during the authorization process.");
120 }118 }
121 } catch (UnknownHostException e) {119 } catch (UnknownHostException e) {
122 Log.e(TAG, "Internet connection not available");120 TLog.e(TAG, "Internet connection not available");
123 sendMessage(NO_INTERNET);121 sendMessage(NO_INTERNET);
124 }122 }
125 123
@@ -140,7 +138,7 @@
140 138
141 // start loading snowy notes139 // start loading snowy notes
142 setSyncProgress(0);140 setSyncProgress(0);
143 if (Tomdroid.LOGGING_ENABLED) Log.v(TAG, "Loading Snowy notes");141 TLog.v(TAG, "Loading Snowy notes");
144 142
145 final String userRef = Preferences.getString(Preferences.Key.SYNC_SERVER_USER_API);143 final String userRef = Preferences.getString(Preferences.Key.SYNC_SERVER_USER_API);
146 144
@@ -193,7 +191,7 @@
193 jsonNote = notes.getJSONObject(i);191 jsonNote = notes.getJSONObject(i);
194 insertNote(new Note(jsonNote));192 insertNote(new Note(jsonNote));
195 } catch (JSONException e) {193 } catch (JSONException e) {
196 Log.e(TAG, "Problem parsing the server response", e);194 TLog.e(TAG, e, "Problem parsing the server response");
197 String json = (jsonNote != null) ? jsonNote.toString(2) : rawResponse;195 String json = (jsonNote != null) ? jsonNote.toString(2) : rawResponse;
198 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents("JSON parsing", "json", e, json));196 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents("JSON parsing", "json", e, json));
199 }197 }
@@ -207,7 +205,7 @@
207 .getLong("latest-sync-revision"));205 .getLong("latest-sync-revision"));
208 206
209 } catch (JSONException e) {207 } catch (JSONException e) {
210 Log.e(TAG, "Problem parsing the server response", e);208 TLog.e(TAG, e, "Problem parsing the server response");
211 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents("JSON parsing", "json", e, rawResponse));209 sendMessage(PARSING_FAILED, ErrorList.createErrorWithContents("JSON parsing", "json", e, rawResponse));
212 setSyncProgress(100);210 setSyncProgress(100);
213 return;211 return;
@@ -216,7 +214,7 @@
216 setSyncProgress(100);214 setSyncProgress(100);
217 215
218 } catch (java.net.UnknownHostException e) {216 } catch (java.net.UnknownHostException e) {
219 Log.e(TAG, "Internet connection not available");217 TLog.e(TAG, "Internet connection not available");
220 sendMessage(NO_INTERNET);218 sendMessage(NO_INTERNET);
221 setSyncProgress(100);219 setSyncProgress(100);
222 return;220 return;
223221
=== modified file 'src/org/tomdroid/sync/web/WebConnection.java'
--- src/org/tomdroid/sync/web/WebConnection.java 2010-08-30 16:33:02 +0000
+++ src/org/tomdroid/sync/web/WebConnection.java 2011-10-27 17:18:24 +0000
@@ -22,21 +22,19 @@
22 */22 */
23package org.tomdroid.sync.web;23package org.tomdroid.sync.web;
2424
25import org.apache.http.HttpEntity;
26import org.apache.http.HttpResponse;
27import org.apache.http.client.ClientProtocolException;
28import org.apache.http.client.methods.HttpUriRequest;
29import org.apache.http.impl.client.DefaultHttpClient;
30import org.tomdroid.util.TLog;
31
25import java.io.BufferedReader;32import java.io.BufferedReader;
26import java.io.IOException;33import java.io.IOException;
27import java.io.InputStream;34import java.io.InputStream;
28import java.io.InputStreamReader;35import java.io.InputStreamReader;
29import java.net.UnknownHostException;36import java.net.UnknownHostException;
3037
31import org.apache.http.HttpEntity;
32import org.apache.http.HttpResponse;
33import org.apache.http.client.ClientProtocolException;
34import org.apache.http.client.methods.HttpUriRequest;
35import org.apache.http.impl.client.DefaultHttpClient;
36import org.tomdroid.ui.Tomdroid;
37
38import android.util.Log;
39
40public abstract class WebConnection {38public abstract class WebConnection {
41 39
42 private static final String TAG = "WebConnection";40 private static final String TAG = "WebConnection";
@@ -80,7 +78,7 @@
80 String result = null;78 String result = null;
81 79
82 // Examine the response status80 // Examine the response status
83 if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Response status : "+response.getStatusLine().toString());81 TLog.i(TAG, "Response status : {0}", response.getStatusLine().toString());
8482
85 // Get hold of the response entity83 // Get hold of the response entity
86 HttpEntity entity = response.getEntity();84 HttpEntity entity = response.getEntity();
@@ -96,7 +94,7 @@
96 94
97 result = convertStreamToString(instream);95 result = convertStreamToString(instream);
98 96
99 if (Tomdroid.LOGGING_ENABLED) Log.i(TAG, "Received : "+result);97 TLog.i(TAG, "Received : {0}", result);
100 98
101 // Closing the input stream will trigger connection release99 // Closing the input stream will trigger connection release
102 instream.close();100 instream.close();
103101
=== modified file 'src/org/tomdroid/ui/PreferencesActivity.java'
--- src/org/tomdroid/ui/PreferencesActivity.java 2011-09-04 17:48:08 +0000
+++ src/org/tomdroid/ui/PreferencesActivity.java 2011-10-27 17:18:24 +0000
@@ -23,22 +23,11 @@
23 */23 */
24package org.tomdroid.ui;24package org.tomdroid.ui;
2525
26import java.util.ArrayList;
27
28import org.tomdroid.NoteManager;
29import org.tomdroid.R;
30import org.tomdroid.sync.ServiceAuth;
31import org.tomdroid.sync.SyncManager;
32import org.tomdroid.sync.SyncService;
33import org.tomdroid.util.FirstNote;
34import org.tomdroid.util.Preferences;
35import org.tomdroid.util.SearchSuggestionProvider;
36
37import android.app.AlertDialog;26import android.app.AlertDialog;
38import android.app.ProgressDialog;27import android.app.ProgressDialog;
39import android.content.DialogInterface;28import android.content.DialogInterface;
29import android.content.DialogInterface.OnClickListener;
40import android.content.Intent;30import android.content.Intent;
41import android.content.DialogInterface.OnClickListener;
42import android.net.Uri;31import android.net.Uri;
43import android.os.Bundle;32import android.os.Bundle;
44import android.os.Handler;33import android.os.Handler;
@@ -46,12 +35,22 @@
46import android.preference.EditTextPreference;35import android.preference.EditTextPreference;
47import android.preference.ListPreference;36import android.preference.ListPreference;
48import android.preference.Preference;37import android.preference.Preference;
49import android.preference.PreferenceActivity;
50import android.preference.Preference.OnPreferenceChangeListener;38import android.preference.Preference.OnPreferenceChangeListener;
51import android.preference.Preference.OnPreferenceClickListener;39import android.preference.Preference.OnPreferenceClickListener;
40import android.preference.PreferenceActivity;
52import android.provider.SearchRecentSuggestions;41import android.provider.SearchRecentSuggestions;
53import android.util.Log;
54import android.widget.Toast;42import android.widget.Toast;
43import org.tomdroid.NoteManager;
44import org.tomdroid.R;
45import org.tomdroid.sync.ServiceAuth;
46import org.tomdroid.sync.SyncManager;
47import org.tomdroid.sync.SyncService;
48import org.tomdroid.util.FirstNote;
49import org.tomdroid.util.Preferences;
50import org.tomdroid.util.SearchSuggestionProvider;
51import org.tomdroid.util.TLog;
52
53import java.util.ArrayList;
5554
56public class PreferencesActivity extends PreferenceActivity {55public class PreferencesActivity extends PreferenceActivity {
57 56
@@ -89,7 +88,7 @@
89 88
90 // did the selection change?89 // did the selection change?
91 if (!syncService.getValue().contentEquals(selectedSyncServiceKey)) {90 if (!syncService.getValue().contentEquals(selectedSyncServiceKey)) {
92 Log.d(TAG, "preference change triggered");91 TLog.d(TAG, "preference change triggered");
93 92
94 syncServiceChanged(selectedSyncServiceKey);93 syncServiceChanged(selectedSyncServiceKey);
95 }94 }
@@ -126,7 +125,7 @@
126 Toast.makeText(getBaseContext(),125 Toast.makeText(getBaseContext(),
127 getString(R.string.deletedSearchHistory),126 getString(R.string.deletedSearchHistory),
128 Toast.LENGTH_LONG).show();127 Toast.LENGTH_LONG).show();
129 Log.d(TAG, "Deleted search history.");128 TLog.d(TAG, "Deleted search history.");
130 129
131 return true;130 return true;
132 }131 }
@@ -145,7 +144,7 @@
145 }144 }
146145
147 // service needs authentication146 // service needs authentication
148 Log.i(TAG, "Creating dialog");147 TLog.i(TAG, "Creating dialog");
149148
150 final ProgressDialog authProgress = ProgressDialog.show(this, "",149 final ProgressDialog authProgress = ProgressDialog.show(this, "",
151 getString(R.string.prefSyncCompleteAuth), true, false);150 getString(R.string.prefSyncCompleteAuth), true, false);
152151
=== modified file 'src/org/tomdroid/ui/Search.java'
--- src/org/tomdroid/ui/Search.java 2011-09-04 17:48:08 +0000
+++ src/org/tomdroid/ui/Search.java 2011-10-27 17:18:24 +0000
@@ -23,12 +23,6 @@
23 */23 */
24package org.tomdroid.ui;24package org.tomdroid.ui;
2525
26import org.tomdroid.Note;
27import org.tomdroid.NoteManager;
28import org.tomdroid.R;
29import org.tomdroid.sync.SyncManager;
30import org.tomdroid.util.SearchSuggestionProvider;
31
32import android.app.ListActivity;26import android.app.ListActivity;
33import android.app.SearchManager;27import android.app.SearchManager;
34import android.content.Intent;28import android.content.Intent;
@@ -38,11 +32,16 @@
38import android.os.Bundle;32import android.os.Bundle;
39import android.os.Handler;33import android.os.Handler;
40import android.provider.SearchRecentSuggestions;34import android.provider.SearchRecentSuggestions;
41import android.util.Log;
42import android.view.View;35import android.view.View;
43import android.widget.ListAdapter;36import android.widget.ListAdapter;
44import android.widget.ListView;37import android.widget.ListView;
45import android.widget.TextView;38import android.widget.TextView;
39import org.tomdroid.Note;
40import org.tomdroid.NoteManager;
41import org.tomdroid.R;
42import org.tomdroid.sync.SyncManager;
43import org.tomdroid.util.SearchSuggestionProvider;
44import org.tomdroid.util.TLog;
4645
47public class Search extends ListActivity {46public class Search extends ListActivity {
48 47
@@ -94,7 +93,7 @@
94 }93 }
9594
96 public void showResults(String query) {95 public void showResults(String query) {
97 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG,"Start searching for: "+query);96 TLog.d(TAG, "Start searching for: {0}", query);
98 97
99 98
100 // adapter that binds the ListView UI to the notes in the note manager99 // adapter that binds the ListView UI to the notes in the note manager
@@ -103,7 +102,7 @@
103 102
104 // set the view shown when query not found103 // set the view shown when query not found
105 listEmptyView = (TextView) findViewById(R.id.no_results);104 listEmptyView = (TextView) findViewById(R.id.no_results);
106 listEmptyView.setText(getString(R.string.strNoResults, new Object[] {query}));105 listEmptyView.setText(getString(R.string.strNoResults, query));
107 getListView().setEmptyView(listEmptyView);106 getListView().setEmptyView(listEmptyView);
108 }107 }
109 108
110109
=== modified file 'src/org/tomdroid/ui/SyncMessageHandler.java'
--- src/org/tomdroid/ui/SyncMessageHandler.java 2010-12-13 02:55:59 +0000
+++ src/org/tomdroid/ui/SyncMessageHandler.java 2011-10-27 17:18:24 +0000
@@ -24,24 +24,23 @@
24 */24 */
25package org.tomdroid.ui;25package org.tomdroid.ui;
2626
27import org.tomdroid.R;
28import org.tomdroid.sync.SyncManager;
29import org.tomdroid.sync.SyncService;
30import org.tomdroid.util.ErrorList;
31
32import android.app.Activity;27import android.app.Activity;
33import android.app.AlertDialog;28import android.app.AlertDialog;
34import android.content.DialogInterface;29import android.content.DialogInterface;
35import android.content.DialogInterface.OnClickListener;30import android.content.DialogInterface.OnClickListener;
36import android.os.Handler;31import android.os.Handler;
37import android.os.Message;32import android.os.Message;
38import android.util.Log;
39import android.view.View;33import android.view.View;
40import android.view.animation.Animation;34import android.view.animation.Animation;
41import android.view.animation.AnimationUtils;35import android.view.animation.AnimationUtils;
42import android.view.animation.RotateAnimation;36import android.view.animation.RotateAnimation;
43import android.widget.ImageView;37import android.widget.ImageView;
44import android.widget.Toast;38import android.widget.Toast;
39import org.tomdroid.R;
40import org.tomdroid.sync.SyncManager;
41import org.tomdroid.sync.SyncService;
42import org.tomdroid.util.ErrorList;
43import org.tomdroid.util.TLog;
4544
46public class SyncMessageHandler extends Handler {45public class SyncMessageHandler extends Handler {
4746
@@ -109,8 +108,7 @@
109 break;108 break;
110109
111 default:110 default:
112 if (Tomdroid.LOGGING_ENABLED)111 TLog.i(TAG, "handler called with an unknown message");
113 Log.i(TAG, "handler called with an unknown message");
114 break;112 break;
115113
116 }114 }
117115
=== modified file 'src/org/tomdroid/ui/Tomdroid.java'
--- src/org/tomdroid/ui/Tomdroid.java 2011-09-04 17:48:08 +0000
+++ src/org/tomdroid/ui/Tomdroid.java 2011-10-27 17:18:24 +0000
@@ -24,23 +24,13 @@
24 */24 */
25package org.tomdroid.ui;25package org.tomdroid.ui;
2626
27import org.tomdroid.Note;
28import org.tomdroid.NoteManager;
29import org.tomdroid.R;
30import org.tomdroid.sync.ServiceAuth;
31import org.tomdroid.sync.SyncManager;
32import org.tomdroid.sync.SyncService;
33import org.tomdroid.util.FirstNote;
34import org.tomdroid.util.Preferences;
35import org.tomdroid.util.Send;
36
37import android.app.AlertDialog;27import android.app.AlertDialog;
38import android.app.ListActivity;28import android.app.ListActivity;
39import android.app.ProgressDialog;29import android.app.ProgressDialog;
40import android.content.Context;30import android.content.Context;
41import android.content.DialogInterface;31import android.content.DialogInterface;
32import android.content.DialogInterface.OnClickListener;
42import android.content.Intent;33import android.content.Intent;
43import android.content.DialogInterface.OnClickListener;
44import android.content.pm.PackageManager.NameNotFoundException;34import android.content.pm.PackageManager.NameNotFoundException;
45import android.database.Cursor;35import android.database.Cursor;
46import android.net.Uri;36import android.net.Uri;
@@ -48,17 +38,22 @@
48import android.os.Environment;38import android.os.Environment;
49import android.os.Handler;39import android.os.Handler;
50import android.os.Message;40import android.os.Message;
51import android.util.Log;41import android.view.*;
52import android.view.ContextMenu;
53import android.view.Menu;
54import android.view.MenuInflater;
55import android.view.MenuItem;
56import android.view.View;
57import android.view.ContextMenu.ContextMenuInfo;42import android.view.ContextMenu.ContextMenuInfo;
43import android.widget.AdapterView.AdapterContextMenuInfo;
58import android.widget.ListAdapter;44import android.widget.ListAdapter;
59import android.widget.ListView;45import android.widget.ListView;
60import android.widget.TextView;46import android.widget.TextView;
61import android.widget.AdapterView.AdapterContextMenuInfo;47import org.tomdroid.Note;
48import org.tomdroid.NoteManager;
49import org.tomdroid.R;
50import org.tomdroid.sync.ServiceAuth;
51import org.tomdroid.sync.SyncManager;
52import org.tomdroid.sync.SyncService;
53import org.tomdroid.util.FirstNote;
54import org.tomdroid.util.Preferences;
55import org.tomdroid.util.Send;
56import org.tomdroid.util.TLog;
6257
63public class Tomdroid extends ListActivity {58public class Tomdroid extends ListActivity {
6459
@@ -75,8 +70,6 @@
75 // TODO hardcoded for now70 // TODO hardcoded for now
76 public static final String NOTES_PATH = Environment.getExternalStorageDirectory()71 public static final String NOTES_PATH = Environment.getExternalStorageDirectory()
77 + "/tomdroid/";72 + "/tomdroid/";
78 // Logging should be disabled for release builds
79 public static final boolean LOGGING_ENABLED = false;
80 // Set this to false for release builds, the reason should be obvious73 // Set this to false for release builds, the reason should be obvious
81 public static final boolean CLEAR_PREFERENCES = false;74 public static final boolean CLEAR_PREFERENCES = false;
8275
@@ -100,7 +93,7 @@
10093
101 // did we already show the warning and got destroyed by android's activity killer?94 // did we already show the warning and got destroyed by android's activity killer?
102 if (Preferences.getBoolean(Preferences.Key.FIRST_RUN)) {95 if (Preferences.getBoolean(Preferences.Key.FIRST_RUN)) {
103 Log.i(TAG, "Tomdroid is first run.");96 TLog.i(TAG, "Tomdroid is first run.");
104 97
105 // add a first explanatory note98 // add a first explanatory note
106 NoteManager.putNote(this, FirstNote.createFirstNote());99 NoteManager.putNote(this, FirstNote.createFirstNote());
@@ -197,7 +190,7 @@
197 Uri uri = intent.getData();190 Uri uri = intent.getData();
198191
199 if (uri != null && uri.getScheme().equals("tomdroid")) {192 if (uri != null && uri.getScheme().equals("tomdroid")) {
200 Log.i(TAG, "Got url : " + uri.toString());193 TLog.i(TAG, "Got url : {0}", uri.toString());
201194
202 final ProgressDialog dialog = ProgressDialog.show(this, "", getString(R.string.prefSyncCompleteAuth), true, false);195 final ProgressDialog dialog = ProgressDialog.show(this, "", getString(R.string.prefSyncCompleteAuth), true, false);
203196
204197
=== modified file 'src/org/tomdroid/ui/ViewNote.java'
--- src/org/tomdroid/ui/ViewNote.java 2011-09-05 15:05:46 +0000
+++ src/org/tomdroid/ui/ViewNote.java 2011-10-27 17:18:24 +0000
@@ -23,22 +23,11 @@
23 */23 */
24package org.tomdroid.ui;24package org.tomdroid.ui;
2525
26import java.util.regex.Matcher;
27import java.util.regex.Pattern;
28
29import org.tomdroid.Note;
30import org.tomdroid.NoteManager;
31import org.tomdroid.R;
32import org.tomdroid.sync.SyncManager;
33import org.tomdroid.util.LinkifyPhone;
34import org.tomdroid.util.NoteContentBuilder;
35import org.tomdroid.util.Send;
36
37import android.app.Activity;26import android.app.Activity;
38import android.app.AlertDialog;27import android.app.AlertDialog;
39import android.content.DialogInterface;28import android.content.DialogInterface;
29import android.content.DialogInterface.OnClickListener;
40import android.content.Intent;30import android.content.Intent;
41import android.content.DialogInterface.OnClickListener;
42import android.database.Cursor;31import android.database.Cursor;
43import android.graphics.Color;32import android.graphics.Color;
44import android.net.Uri;33import android.net.Uri;
@@ -48,11 +37,21 @@
48import android.text.SpannableStringBuilder;37import android.text.SpannableStringBuilder;
49import android.text.util.Linkify;38import android.text.util.Linkify;
50import android.text.util.Linkify.TransformFilter;39import android.text.util.Linkify.TransformFilter;
51import android.util.Log;
52import android.view.Menu;40import android.view.Menu;
53import android.view.MenuInflater;41import android.view.MenuInflater;
54import android.view.MenuItem;42import android.view.MenuItem;
55import android.widget.TextView;43import android.widget.TextView;
44import org.tomdroid.Note;
45import org.tomdroid.NoteManager;
46import org.tomdroid.R;
47import org.tomdroid.sync.SyncManager;
48import org.tomdroid.util.LinkifyPhone;
49import org.tomdroid.util.NoteContentBuilder;
50import org.tomdroid.util.Send;
51import org.tomdroid.util.TLog;
52
53import java.util.regex.Matcher;
54import java.util.regex.Pattern;
5655
57// TODO this class is starting to smell56// TODO this class is starting to smell
58public class ViewNote extends Activity {57public class ViewNote extends Activity {
@@ -91,7 +90,7 @@
91 if (uri != null) {90 if (uri != null) {
92 91
93 // We were triggered by an Intent URI 92 // We were triggered by an Intent URI
94 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "ViewNote started: Intent-filter triggered.");93 TLog.d(TAG, "ViewNote started: Intent-filter triggered.");
9594
96 // TODO validate the good action?95 // TODO validate the good action?
97 // intent.getAction()96 // intent.getAction()
@@ -107,7 +106,7 @@
107 106
108 } else {107 } else {
109 108
110 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "The note "+uri+" doesn't exist");109 TLog.d(TAG, "The note {0} doesn't exist", uri);
111 110
112 // TODO put error string in a translatable resource111 // TODO put error string in a translatable resource
113 new AlertDialog.Builder(this)112 new AlertDialog.Builder(this)
@@ -123,7 +122,7 @@
123 }122 }
124 } else {123 } else {
125 124
126 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "The Intent's data was null.");125 TLog.d(TAG, "The Intent's data was null.");
127 126
128 // TODO put error string in a translatable resource127 // TODO put error string in a translatable resource
129 new AlertDialog.Builder(this)128 new AlertDialog.Builder(this)
@@ -250,7 +249,7 @@
250 } else {249 } else {
251 250
252 // TODO send an error to the user251 // TODO send an error to the user
253 if (Tomdroid.LOGGING_ENABLED) Log.d(TAG, "Cursor returned null or 0 notes");252 TLog.d(TAG, "Cursor returned null or 0 notes");
254 }253 }
255 254
256 return null;255 return null;
257256
=== modified file 'src/org/tomdroid/util/FirstNote.java'
--- src/org/tomdroid/util/FirstNote.java 2010-10-09 19:58:11 +0000
+++ src/org/tomdroid/util/FirstNote.java 2011-10-27 17:18:24 +0000
@@ -22,13 +22,11 @@
22 */22 */
23package org.tomdroid.util;23package org.tomdroid.util;
2424
25import org.tomdroid.Note;
26
25import java.util.MissingResourceException;27import java.util.MissingResourceException;
26import java.util.ResourceBundle;28import java.util.ResourceBundle;
2729
28import org.tomdroid.Note;
29
30import android.util.Log;
31
32/**30/**
33 * Creates an introductory note object 31 * Creates an introductory note object
34 * @author Olivier Bilodeau <olivier@bottomlesspit.org>32 * @author Olivier Bilodeau <olivier@bottomlesspit.org>
@@ -40,7 +38,7 @@
40 private static final String TAG = "FirstNote";38 private static final String TAG = "FirstNote";
41 39
42 public static Note createFirstNote() {40 public static Note createFirstNote() {
43 Log.v(TAG, "Creating first note");41 TLog.v(TAG, "Creating first note");
44 42
45 Note note = new Note();43 Note note = new Note();
46 44
4745
=== modified file 'src/org/tomdroid/util/NoteContentBuilder.java'
--- src/org/tomdroid/util/NoteContentBuilder.java 2011-09-05 19:45:38 +0000
+++ src/org/tomdroid/util/NoteContentBuilder.java 2011-10-27 17:18:24 +0000
@@ -22,19 +22,15 @@
22 */22 */
23package org.tomdroid.util;23package org.tomdroid.util;
2424
25import java.io.StringReader;
26
27import javax.xml.parsers.SAXParser;
28import javax.xml.parsers.SAXParserFactory;
29
30import org.tomdroid.ui.Tomdroid;
31import org.tomdroid.xml.NoteContentHandler;
32import org.xml.sax.InputSource;
33
34import android.os.Handler;25import android.os.Handler;
35import android.os.Message;26import android.os.Message;
36import android.text.SpannableStringBuilder;27import android.text.SpannableStringBuilder;
37import android.util.Log;28import org.tomdroid.xml.NoteContentHandler;
29import org.xml.sax.InputSource;
30
31import javax.xml.parsers.SAXParser;
32import javax.xml.parsers.SAXParserFactory;
33import java.io.StringReader;
3834
39public class NoteContentBuilder implements Runnable {35public class NoteContentBuilder implements Runnable {
40 36
@@ -89,12 +85,12 @@
89 spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);85 spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
90 SAXParser sp = spf.newSAXParser();86 SAXParser sp = spf.newSAXParser();
9187
92 if (Tomdroid.LOGGING_ENABLED) Log.v(TAG, "parsing note");88 TLog.v(TAG, "parsing note");
93 sp.parse(noteContentIs, new NoteContentHandler(noteContent));89 sp.parse(noteContentIs, new NoteContentHandler(noteContent));
94 } catch (Exception e) {90 } catch (Exception e) {
95 e.printStackTrace();91 e.printStackTrace();
96 // TODO handle error in a more granular way92 // TODO handle error in a more granular way
97 Log.e(TAG, "There was an error parsing the note.");93 TLog.e(TAG, "There was an error parsing the note.");
98 successful = false;94 successful = false;
99 }95 }
100 96
10197
=== added file 'src/org/tomdroid/util/TLog.java'
--- src/org/tomdroid/util/TLog.java 1970-01-01 00:00:00 +0000
+++ src/org/tomdroid/util/TLog.java 2011-10-27 17:18:24 +0000
@@ -0,0 +1,83 @@
1/*
2 * Tomdroid
3 * Tomboy on Android
4 * http://www.launchpad.net/tomdroid
5 *
6 * Copyright 2011 Piotr Adamski <mcveat@gmail.com>
7 *
8 * This file is part of Tomdroid.
9 *
10 * Tomdroid is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Tomdroid is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Tomdroid. If not, see <http://www.gnu.org/licenses/>.
22 */
23package org.tomdroid.util;
24
25import android.util.Log;
26
27import static java.text.MessageFormat.format;
28
29/**
30 * @author Piotr Adamski <mcveat@gmail.com>
31 */
32public class TLog {
33 // Logging should be disabled for release builds
34 private static final boolean LOGGING_ENABLED = false;
35
36 public static void v(String tag, Throwable t, String msg, Object... args) {
37 if (LOGGING_ENABLED) Log.v(tag, format(msg, args), t);
38 }
39
40 public static void v(String tag, String msg, Object... args) {
41 v(tag, null, msg, args);
42 }
43
44 public static void d(String tag, Throwable t, String msg, Object... args) {
45 if (LOGGING_ENABLED) Log.d(tag, format(msg, args), t);
46 }
47
48 public static void d(String tag, String msg, Object... args) {
49 d(tag, null, msg, args);
50 }
51
52 public static void i(String tag, Throwable t, String msg, Object... args) {
53 if (LOGGING_ENABLED) Log.i(tag, format(msg, args), t);
54 }
55
56 public static void i(String tag, String msg, Object... args) {
57 i(tag, null, msg, args);
58 }
59
60 public static void w(String tag, Throwable t, String msg, Object... args) {
61 if (LOGGING_ENABLED) Log.w(tag, format(msg, args), t);
62 }
63
64 public static void w(String tag, String msg, Object... args) {
65 w(tag, null, msg, args);
66 }
67
68 public static void e(String tag, Throwable t, String msg, Object... args) {
69 Log.e(tag, format(msg, args), t);
70 }
71
72 public static void e(String tag, String msg, Object... args) {
73 e(tag, null, msg, args);
74 }
75
76 public static void wtf(String tag, Throwable t, String msg, Object... args) {
77 Log.wtf(tag, format(msg, args), t);
78 }
79
80 public static void wtf(String tag, String msg, Object... args) {
81 wtf(tag, null, msg, args);
82 }
83}

Subscribers

People subscribed via source and target branches