1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

bookmark style (in progress)

This commit is contained in:
Nikolay Pultsin 2013-05-02 17:35:21 +04:00
parent e8d28b6d87
commit 4bdf7a0a71
5 changed files with 39 additions and 9 deletions

View file

@ -840,8 +840,10 @@ final class SQLiteBooksDatabase extends BooksDatabase {
.append(" bm.bookmark_id,bm.book_id,b.title,bm.bookmark_text,")
.append("bm.creation_time,bm.modification_time,bm.access_time,bm.access_counter,")
.append("bm.model_id,bm.paragraph,bm.word,bm.char,")
.append("bm.end_paragraph,bm.end_word,bm.end_character")
.append(" FROM Bookmarks AS bm INNER JOIN Books AS b ON b.book_id = bm.book_id")
.append("bm.end_paragraph,bm.end_word,bm.end_character,")
.append("bm.style_id")
.append(" FROM Bookmarks AS bm")
.append(" INNER JOIN Books AS b ON b.book_id = bm.book_id")
.append(" WHERE");
if (query.Book != null) {
sql.append(" b.book_id = " + query.Book.getId() +" AND");
@ -868,7 +870,8 @@ final class SQLiteBooksDatabase extends BooksDatabase {
(int)cursor.getLong(12),
cursor.isNull(13) ? -1 : (int)cursor.getLong(13),
cursor.isNull(14) ? -1 : (int)cursor.getLong(14),
query.Visible
query.Visible,
(int)cursor.getLong(15)
));
}
cursor.close();
@ -1392,8 +1395,11 @@ final class SQLiteBooksDatabase extends BooksDatabase {
myDatabase.execSQL(
"CREATE TABLE IF NOT EXISTS HighlightingStyle(" +
"style_id INTEGER PRIMARY KEY," +
"name TEXT," +
"bg_color INTEGER NOT NULL)");
myDatabase.execSQL("INSERT INTO HighlightingStyle (style_id, bg_color) VALUES (1, 127*256*256 + 127*256 + 127)");
myDatabase.execSQL("INSERT INTO HighlightingStyle (style_id, name, bg_color) VALUES (1, 'default', 136*256*256 + 138*256 + 133)"); // #888a85
myDatabase.execSQL("INSERT INTO HighlightingStyle (style_id, name, bg_color) VALUES (2, 'orange', 245*256*256 + 121*256 + 0)"); // #f57900
myDatabase.execSQL("INSERT INTO HighlightingStyle (style_id, name, bg_color) VALUES (3, 'blue', 114*160*256 + 159*256 + 207)"); // #729fcf
myDatabase.execSQL("ALTER TABLE Bookmarks ADD COLUMN style_id INTEGER NOT NULL REFERENCES HighlightingStyle(style_id) DEFAULT 1");
myDatabase.execSQL("UPDATE Bookmarks SET end_paragraph = LENGTH(bookmark_text)");
}

View file

@ -42,6 +42,7 @@ public final class Bookmark extends ZLTextFixedPosition {
private Date myLatestDate;
private ZLTextFixedPosition myEnd;
private int myLength;
private int myStyleId;
public final String ModelId;
public final boolean IsVisible;
@ -52,7 +53,8 @@ public final class Bookmark extends ZLTextFixedPosition {
String modelId,
int start_paragraphIndex, int start_elementIndex, int start_charIndex,
int end_paragraphIndex, int end_elementIndex, int end_charIndex,
boolean isVisible
boolean isVisible,
int styleId
) {
super(start_paragraphIndex, start_elementIndex, start_charIndex);
@ -78,6 +80,8 @@ public final class Bookmark extends ZLTextFixedPosition {
} else {
myLength = end_paragraphIndex;
}
myStyleId = styleId;
}
private static class Buffer {
@ -197,6 +201,7 @@ mainLoop:
ModelId = modelId;
IsVisible = isVisible;
myEnd = new ZLTextFixedPosition(end);
myStyleId = 1;
}
public long getId() {
@ -207,6 +212,10 @@ mainLoop:
return myBookId;
}
public int getStyleId() {
return myStyleId;
}
public String getText() {
return myText;
}

View file

@ -92,7 +92,8 @@ public abstract class BooksDatabase {
String modelId,
int start_paragraphIndex, int start_wordIndex, int start_charIndex,
int end_paragraphIndex, int end_wordIndex, int end_charIndex,
boolean isVisible
boolean isVisible,
int styleId
) {
return new Bookmark(
id, bookId, bookTitle, text,
@ -100,7 +101,8 @@ public abstract class BooksDatabase {
modelId,
start_paragraphIndex, start_wordIndex, start_charIndex,
end_paragraphIndex, end_wordIndex, end_charIndex,
isVisible
isVisible,
styleId
);
}

View file

@ -284,6 +284,10 @@ class XMLSerializer extends AbstractSerializer {
"length", String.valueOf(bookmark.getLength())
);
}
appendTag(
buffer, "style", true,
"id", String.valueOf(bookmark.getStyleId())
);
closeTag(buffer, "bookmark");
return buffer.toString();
}
@ -784,6 +788,7 @@ class XMLSerializer extends AbstractSerializer {
private int myEndElementIndex;
private int myEndCharIndex;
private boolean myIsVisible;
private int myStyle;
public Bookmark getBookmark() {
return myState == State.READ_NOTHING ? myBookmark : null;
@ -809,6 +814,7 @@ class XMLSerializer extends AbstractSerializer {
myEndElementIndex = -1;
myEndCharIndex = -1;
myIsVisible = false;
myStyle = 1;
myState = State.READ_NOTHING;
}
@ -824,7 +830,8 @@ class XMLSerializer extends AbstractSerializer {
myModelId,
myStartParagraphIndex, myStartElementIndex, myStartCharIndex,
myEndParagraphIndex, myEndElementIndex, myEndCharIndex,
myIsVisible
myIsVisible,
myStyle
);
}
@ -886,6 +893,12 @@ class XMLSerializer extends AbstractSerializer {
} catch (Exception e) {
throw new SAXException("XML parsing error", e);
}
} else if ("style".equals(localName)) {
try {
myStyle = Integer.parseInt(attributes.getValue("id"));
} catch (Exception e) {
throw new SAXException("XML parsing error", e);
}
} else {
throw new SAXException("Unexpected tag " + localName);
}

View file

@ -41,6 +41,6 @@ public final class BookmarkHighlighting extends ZLTextSimpleHighlighting {
@Override
public ZLColor getBackgroundColor() {
return new ZLColor(127, 127, 127);
return new ZLColor(0x888A85);
}
}