1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 01:39:18 +02:00

change style for existing highlighting

This commit is contained in:
Nikolay Pultsin 2013-05-06 02:13:20 +04:00
parent 42f6ab142f
commit 68a58cf242
33 changed files with 123 additions and 23 deletions

View file

@ -8,6 +8,6 @@ DONE save bookmark style
DONE change style (color) for bookmarks: user interface
** edit styles
** add/remove styles
** menu on bookmark tap
DONE menu on bookmark tap
DONE watch bookmark changes
DONE fix selection bookmark range

View file

@ -229,6 +229,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Выдаліць закладку"/>
</node>
<node name="selection" value="Вылучэньне">
<node name="copyToClipboard" value="Скапіяваць у кішэню"/>

View file

@ -228,6 +228,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Премахни отбелязването"/>
</node>
<node name="selection" value="Етикет">
<node name="copyToClipboard" value="Копирай в буфера"/>

View file

@ -227,6 +227,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Esborra punt de llibre"/>
</node>
<node name="selection" value="Selección" toBeTranslated="true">
<node name="copyToClipboard" value="Copiar al portapapeles" toBeTranslated="true"/>

View file

@ -232,6 +232,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Odstranit záložku"/>
</node>
<node name="selection" value="Výběr">
<node name="copyToClipboard" value="Kopírovat do schránky"/>

View file

@ -217,6 +217,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Lesezeichen löschen"/>
</node>
<node name="selection" value="Auswahl">
<node name="copyToClipboard" value="In die Zwischenablage kopieren"/>

View file

@ -223,6 +223,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s"/>
<node name="deleteBookmark" value="Delete bookmark"/>
</node>
<node name="selection" value="Selection">
<node name="copyToClipboard" value="Copy to clipboard"/>

View file

@ -227,6 +227,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Borrar marcador"/>
</node>
<node name="selection" value="Selección">
<node name="copyToClipboard" value="Copiar al portapapeles"/>

View file

@ -216,6 +216,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Supprimer le marque-page"/>
</node>
<node name="selection" value="Sélection">
<node name="copyToClipboard" value="Copier dans le presse-papiers"/>

View file

@ -213,6 +213,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Eliminar marcador"/>
</node>
<node name="selection" value="Selección">
<node name="copyToClipboard" value="Copiar no portapapeis"/>

View file

@ -213,6 +213,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Könyvelző törlése"/>
</node>
<node name="selection" value="Kijelölés">
<node name="copyToClipboard" value="Vágólapra másol"/>

View file

@ -214,6 +214,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Cancella segnalibro"/>
</node>
<node name="selection" value="Selezione">
<node name="copyToClipboard" value="Copia negli Appunti"/>

View file

@ -228,6 +228,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="სანიშნის წაშლა"/>
</node>
<node name="selection" value="ნიშნული">
<node name="copyToClipboard" value="ბუფერში დაკოპირება"/>

View file

@ -223,6 +223,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Slett bokmerke"/>
</node>
<node name="selection" value="Utvalg">
<node name="copyToClipboard" value="Kopier til utklippstavle"/>

View file

@ -223,6 +223,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Bladwijzer verwijderen"/>
</node>
<node name="selection" value="Selectie">
<node name="copyToClipboard" value="Kopieer naar klembord"/>

View file

@ -213,6 +213,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Usuń zakładkę"/>
</node>
<node name="selection" value="Zaznaczenie">
<node name="copyToClipboard" value="Skopiuj do schowka"/>

View file

@ -225,6 +225,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Deletar marcador"/>
</node>
<node name="selection" value="Seleção">
<node name="copyToClipboard" value="Copiar para o clipboard"/>

View file

@ -213,6 +213,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Sterge marcaj"/>
</node>
<node name="selection" value="Selectie">
<node name="copyToClipboard" value="Copiati în clipboard"/>

View file

@ -228,6 +228,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Стиль %s"/>
<node name="deleteBookmark" value="Стереть закладку"/>
</node>
<node name="selection" value="Пометка">
<node name="copyToClipboard" value="Скопировать в буфер"/>

View file

@ -223,6 +223,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Обриши обележивач"/>
</node>
<node name="selection" value="Одабир">
<node name="copyToClipboard" value="Умножи"/>

View file

@ -213,6 +213,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="ลบบุ๊คมาร์ค"/>
</node>
<node name="selection" value="เลือก">
<node name="copyToClipboard" value="คัดลอกไปที่คลิปบอร์ด"/>

View file

@ -223,6 +223,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Yer imini sil"/>
</node>
<node name="selection" value="Seçenekler">
<node name="copyToClipboard" value="Panoya kopyala"/>

View file

@ -213,6 +213,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Стерти закладку"/>
</node>
<node name="selection" value="Позначка">
<node name="copyToClipboard" value="Скопіювати до буфера"/>

View file

@ -213,6 +213,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="Xoa đánh dấu"/>
</node>
<node name="selection" value="Lựa chọn">
<node name="copyToClipboard" value="Chép vào Clipboard"/>

View file

@ -213,6 +213,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="删除书签"/>
</node>
<node name="selection" value="选择">
<node name="copyToClipboard" value="复制到剪贴板"/>

View file

@ -213,6 +213,7 @@
</node>
<node name="highlightingStyleMenu">
<node name="style" value="Style %s" toBeTranslated="true"/>
<node name="deleteBookmark" value="刪除書籤"/>
</node>
<node name="selection" value="選擇">
<node name="copyToClipboard" value="複製"/>

View file

@ -36,15 +36,26 @@ public class SelectionBookmarkAction extends FBAndroidAction {
@Override
protected void run(Object ... params) {
final Bookmark bookmark = Reader.addSelectionBookmark();
UIUtil.showMessageText(
BaseActivity,
ZLResource.resource("selection").getResource("bookmarkCreated").getValue()
.replace("%s", bookmark.getText())
);
final boolean existingBookmark;
final Bookmark bookmark;
if (params.length != 0) {
existingBookmark = true;
bookmark = (Bookmark)params[0];
} else {
existingBookmark = false;
bookmark = Reader.addSelectionBookmark();
UIUtil.showMessageText(
BaseActivity,
ZLResource.resource("selection").getResource("bookmarkCreated").getValue()
.replace("%s", bookmark.getText())
);
}
final Intent intent =
new Intent(BaseActivity.getApplicationContext(), StyleListActivity.class);
intent.putExtra(FBReader.BOOKMARK_KEY, SerializerUtil.serialize(bookmark));
intent.putExtra(StyleListActivity.EXISTING_BOOKMARK_KEY, existingBookmark);
OrientationUtil.startActivity(BaseActivity, intent);
}
}

View file

@ -39,7 +39,10 @@ import org.geometerplus.fbreader.book.*;
import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow;
public class StyleListActivity extends ListActivity {
static final String EXISTING_BOOKMARK_KEY = "existing.bookmark";
private final BookCollectionShadow myCollection = new BookCollectionShadow();
private boolean myExistingBookmark;
private Bookmark myBookmark;
@Override
@ -53,6 +56,7 @@ public class StyleListActivity extends ListActivity {
super.onStart();
myCollection.bindToService(this, new Runnable() {
public void run() {
myExistingBookmark = getIntent().getBooleanExtra(EXISTING_BOOKMARK_KEY, false);
myBookmark = SerializerUtil.deserializeBookmark(
getIntent().getStringExtra(FBReader.BOOKMARK_KEY)
);
@ -86,11 +90,11 @@ public class StyleListActivity extends ListActivity {
}
public final int getCount() {
return myStyles.size();
return myExistingBookmark ? myStyles.size() + 1 : myStyles.size();
}
public final HighlightingStyle getItem(int position) {
return myStyles.get(position);
return position < myStyles.size() ? myStyles.get(position) : null;
}
public final long getItemId(int position) {
@ -104,22 +108,37 @@ public class StyleListActivity extends ListActivity {
final HighlightingStyle style = getItem(position);
final ImageView colorView = (ImageView)view.findViewById(R.id.style_item_color);
colorView.setImageDrawable(new ColorDrawable(ZLAndroidColorUtil.rgb(style.BackgroundColor)));
final TextView titleView = (TextView)view.findViewById(R.id.style_item_title);
String title = ZLResource.resource("highlightingStyleMenu")
.getResource("style").getValue();
title = title.replace("%s", String.valueOf(style.Id));
titleView.setText(title);
if (style != null) {
colorView.setVisibility(View.VISIBLE);
colorView.setImageDrawable(new ColorDrawable(ZLAndroidColorUtil.rgb(style.BackgroundColor)));
titleView.setText(
ZLResource.resource("highlightingStyleMenu")
.getResource("style").getValue()
.replace("%s", String.valueOf(style.Id))
);
} else {
colorView.setVisibility(View.GONE);
titleView.setText(
ZLResource.resource("highlightingStyleMenu")
.getResource("deleteBookmark").getValue()
);
}
return view;
}
public final void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final HighlightingStyle style = getItem(position);
myCollection.bindToService(StyleListActivity.this, new Runnable() {
public void run() {
myBookmark.setStyleId(getItem(position).Id);
myCollection.saveBookmark(myBookmark);
if (style != null) {
myBookmark.setStyleId(style.Id);
myCollection.saveBookmark(myBookmark);
} else {
myCollection.deleteBookmark(myBookmark);
}
finish();
}
});

View file

@ -26,8 +26,8 @@ import org.geometerplus.zlibrary.text.view.*;
import org.geometerplus.fbreader.book.*;
public final class BookmarkHighlighting extends ZLTextSimpleHighlighting {
final IBookCollection myCollection;
final Bookmark myBookmark;
final IBookCollection Collection;
final Bookmark Bookmark;
private static ZLTextPosition startPosition(Bookmark bookmark) {
return new ZLTextFixedPosition(bookmark.getParagraphIndex(), bookmark.getElementIndex(), 0);
@ -44,13 +44,13 @@ public final class BookmarkHighlighting extends ZLTextSimpleHighlighting {
BookmarkHighlighting(ZLTextView view, IBookCollection collection, Bookmark bookmark) {
super(view, startPosition(bookmark), endPosition(bookmark));
myCollection = collection;
myBookmark = bookmark;
Collection = collection;
Bookmark = bookmark;
}
@Override
public ZLColor getBackgroundColor() {
final HighlightingStyle bmStyle = myCollection.getHighlightingStyle(myBookmark.getStyleId());
final HighlightingStyle bmStyle = Collection.getHighlightingStyle(Bookmark.getStyleId());
return bmStyle != null ? bmStyle.BackgroundColor : new ZLColor(255, 255, 255);
}
}

View file

@ -81,6 +81,15 @@ public final class FBView extends ZLTextView {
return true;
}
final ZLTextHighlighting highlighting = findHighlighting(x, y, MAX_SELECTION_DISTANCE);
if (highlighting instanceof BookmarkHighlighting) {
myReader.runAction(
ActionCode.SELECTION_BOOKMARK,
((BookmarkHighlighting)highlighting).Bookmark
);
return true;
}
myReader.runAction(getZoneMap().getActionByCoordinates(
x, y, getContextWidth(), getContextHeight(),
isDoubleTapSupported() ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.singleTap

View file

@ -39,6 +39,14 @@ public abstract class ZLTextHighlighting implements Comparable<ZLTextHighlightin
page.EndCursor.compareTo(getStartPosition()) > 0;
}
boolean intersects(ZLTextRegion region) {
final ZLTextRegion.Soul soul = region.getSoul();
return
!isEmpty() &&
soul.compareTo(getStartPosition()) >= 0 &&
soul.compareTo(getEndPosition()) <= 0;
}
public int compareTo(ZLTextHighlighting highlighting) {
final int cmp = getStartPosition().compareTo(highlighting.getStartPosition());
return cmp != 0 ? cmp : getEndPosition().compareTo(highlighting.getEndPosition());

View file

@ -79,6 +79,21 @@ public final class ZLTextRegion {
}
return 0;
}
public final int compareTo(ZLTextPosition position) {
final int ppi = position.getParagraphIndex();
if (ParagraphIndex != ppi) {
return ParagraphIndex < ppi ? -1 : 1;
}
final int pei = position.getElementIndex();
if (EndElementIndex < pei) {
return -1;
}
if (StartElementIndex > pei) {
return 1;
}
return 0;
}
}
public static interface Filter {

View file

@ -1543,6 +1543,19 @@ public abstract class ZLTextView extends ZLTextViewBase {
return getSelectedRegion(myCurrentPage);
}
protected ZLTextHighlighting findHighlighting(int x, int y, int maxDistance) {
final ZLTextRegion region = findRegion(x, y, maxDistance, ZLTextRegion.AnyRegionFilter);
if (region == null) {
return null;
}
for (ZLTextHighlighting h : myHighlightings) {
if (h.intersects(region)) {
return h;
}
}
return null;
}
protected ZLTextRegion findRegion(int x, int y, ZLTextRegion.Filter filter) {
return findRegion(x, y, Integer.MAX_VALUE - 1, filter);
}