~plaxx/tomdroid/iteration-3

« back to all changes in this revision

Viewing changes to src/org/tomdroid/xml/NoteHandler.java

  • Committer: Olivier Bilodeau
  • Date: 2008-12-06 06:10:47 UTC
  • Revision ID: olivier@bottomlesspit.org-20081206061047-naf015mwg5dcl8qb
Basic implementation of bullets, no nested bullets yet
Some comments work

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
import android.text.Spannable;
31
31
import android.text.SpannableStringBuilder;
32
32
import android.text.style.BackgroundColorSpan;
 
33
import android.text.style.BulletSpan;
33
34
import android.text.style.RelativeSizeSpan;
34
35
import android.text.style.StrikethroughSpan;
35
36
import android.text.style.StyleSpan;
41
42
 * the responsibility of filling the note is something quite cohesive and hope 
42
43
 * the coupling involved won't do much damage. I guess time will tell.
43
44
 */
44
 
// FIXME This class needs love right now
45
45
public class NoteHandler extends DefaultHandler {
46
46
        
47
47
        // position keepers
56
56
        private boolean inSizeSmallTag = false;
57
57
        private boolean inSizeLargeTag = false;
58
58
        private boolean inSizeHugeTag = false;
 
59
        private boolean inList = false;
 
60
        private boolean inListItem = false;
59
61
        
60
 
        // tag names
 
62
        // -- Tomboy's notes XML tags names --
 
63
        // Style related
61
64
        private final static String NOTE_CONTENT = "note-content";
62
65
        private final static String BOLD = "bold";
63
66
        private final static String ITALIC = "italic";
64
67
        private final static String STRIKETHROUGH = "strikethrough";
65
68
        private final static String HIGHLIGHT = "highlight";
66
69
        private final static String MONOSPACE = "monospace";
67
 
        // Sizes are using a namespace identifier like <size:small></size:small>
 
70
        // Sizes are using a namespace identifier size. Ex: <size:small></size:small>
68
71
        private final static String NS_SIZE = "http://beatniksoftware.com/tomboy/size";
69
72
        private final static String SMALL = "small";
70
73
        private final static String LARGE = "large";
71
74
        private final static String HUGE = "huge";
 
75
        // List-related
 
76
        // TODO nested lists are not supported
 
77
        // I think that using a list integer instead of a boolean and incrementing or decrementing it depending on state would do it
 
78
        private final static String LIST = "list";
 
79
        private final static String LIST_ITEM = "list-item";
72
80
        
73
81
        // accumulate notecontent is this var since it spans multiple xml tags
74
82
        private SpannableStringBuilder ssb;
95
103
                }
96
104
 
97
105
                // if we are in note-content, keep and convert formatting tags
98
 
                // TODO is XML CaSe SeNsItIve? if not change equals to equalsIgnoreCase
 
106
                // TODO is XML CaSe SeNsItIve? if not change equals to equalsIgnoreCase and apply to endElement()
99
107
                if (inNoteContentTag) {
100
108
                        if (localName.equals(BOLD)) {
101
109
                                inBoldTag = true;
116
124
                                } else if (localName.equals(HUGE)) {
117
125
                                        inSizeHugeTag = true;
118
126
                                }
 
127
                        } else if (localName.equals(LIST)) {
 
128
                                inList = true;
 
129
                        } else if (localName.equals(LIST_ITEM)) {
 
130
                                inListItem = true;
119
131
                        }
120
132
                }
121
133
 
153
165
                                        inSizeLargeTag = false;
154
166
                                } else if (localName.equals(HUGE)) {
155
167
                                        inSizeHugeTag = false;
156
 
                                }
 
168
                                } 
 
169
                        } else if (localName.equals(LIST)) {
 
170
                                inList = false;
 
171
                        } else if (localName.equals(LIST_ITEM)) {
 
172
                                inListItem = false;
157
173
                        }
158
174
                }
159
175
        }
173
189
                        
174
190
                        // apply style if required
175
191
                        // TODO I haven't tested nested tags yet
176
 
                        // TODO BulletSpan?
 
192
                        // TODO I've read somewhere in the SDK that instead of reusing members I should store it in a localized variable.. if performance becomes an issue here, think about that!
177
193
                        if (inBoldTag) {
178
194
                                ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), ssb.length()-length, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
179
195
                        }
198
214
                        if (inSizeHugeTag) {
199
215
                                ssb.setSpan(new RelativeSizeSpan(Note.NOTE_SIZE_HUGE_FACTOR), ssb.length()-length, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
200
216
                        }
 
217
                        if (inList && inListItem) {
 
218
                                ssb.setSpan(new BulletSpan(), ssb.length()-length, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 
219
                        }
201
220
                }
202
221
        }
203
 
 
204
222
}