use of org.ebookdroid.core.codec.Annotation in project LibreraReader by foobnix.
the class AdvGuestureDetector method onSingleTapUp.
@Override
public boolean onSingleTapUp(final MotionEvent e) {
updateBorders();
if (!AppState.get().isMusicianMode && !AppState.get().isIgnoreAnnotatations || AppState.get().editWith == AppState.EDIT_DELETE) {
alowConfirm = false;
Annotation annotation2 = avc.isAnnotationTap(e.getX(), e.getY());
if (annotation2 == null && annotation != null) {
annotation = null;
avc.selectAnnotation(null);
return true;
}
annotation = annotation2;
if (annotation != null) {
avc.selectAnnotation(annotation);
if (AppState.get().editWith == AppState.EDIT_DELETE) {
docCtrl.onAnnotationTap(annotation.getPageHandler(), annotation.getPage(), annotation.getIndex());
avc.selectAnnotation(null);
annotation = null;
} else {
if (annotation.type == AnnotationType.TEXT) {
docCtrl.showAnnotation(annotation);
} else {
docCtrl.showEditDialogIfNeed();
}
}
return true;
}
if (isTextFormat) {
String text = avc.processLongTap(true, e, e, false);
if (TxtUtils.isFooterNote(text)) {
AppState.get().selectedText = text;
avc.processLongTap(true, e, e, true);
docCtrl.onLongPress(e);
return false;
}
if (TxtUtils.isNotEmpty(text)) {
docCtrl.clearSelectedText();
// docCtrl.closeFooterNotesDialog();
AppState.get().selectedText = null;
}
}
}
if (!AppState.get().isMusicianMode) {
boolean processTap = avc.processTap(TouchManager.Touch.SingleTap, e);
if (processTap) {
return false;
}
}
if (clickUtils.isClickRight(e.getX(), e.getY())) {
docCtrl.onRightPress();
} else if (clickUtils.isClickLeft(e.getX(), e.getY())) {
docCtrl.onLeftPress();
} else if (clickUtils.isClickTop(e.getX(), e.getY())) {
docCtrl.onTopPress();
} else if (clickUtils.isClickBottom(e.getX(), e.getY())) {
docCtrl.onBottomPress();
} else if (clickUtils.isClickCenter(e.getX(), e.getY())) {
// docCtrl.onSingleTap();
alowConfirm = true;
return false;
}
return true;
}
use of org.ebookdroid.core.codec.Annotation in project LibreraReader by foobnix.
the class AbstractViewController method isAnnotationTap.
public final Annotation isAnnotationTap(final float x, final float y) {
final float zoom = base.getZoomModel().getZoom();
final RectF rect = new RectF(x, y, x, y);
rect.offset(getScrollX(), getScrollY());
for (final Page page : model.getPages(firstVisiblePage, lastVisiblePage + 1)) {
final RectF bounds = page.getBounds(zoom);
if (RectF.intersects(bounds, rect)) {
if (page.annotations == null) {
continue;
}
for (Annotation a : page.annotations) {
RectF wordRect = page.getPageRegion(bounds, a);
if (wordRect == null) {
continue;
}
boolean intersects = RectF.intersects(wordRect, rect);
LOG.d("Annotation", wordRect, rect, intersects);
if (intersects) {
LOG.d("Intersects with Annotation", a);
return a;
}
}
}
}
return null;
}
use of org.ebookdroid.core.codec.Annotation in project LibreraReader by foobnix.
the class VerticalModeController method saveChanges.
@Override
public void saveChanges(final List<PointF> points, final int color) {
if (SettingsManager.getBookSettings().cropPages) {
onCrop();
return;
}
final float zoom = ctr.getZoomModel().getZoom();
int scrollX = ctr.getDocumentController().getView().getScrollX();
int scrollY = ctr.getDocumentController().getView().getScrollY();
final Map<Integer, List<PointF>> result = new HashMap<Integer, List<PointF>>();
final int first = ctr.getDocumentController().getFirstVisiblePage();
final int last = ctr.getDocumentController().getLastVisiblePage() + 1;
LOG.d("first", first, "last", last);
for (PointF p : points) {
RectF tapRect = new RectF(p.x, p.y, p.x, p.y);
tapRect.offset(scrollX, scrollY);
Iterable<Page> pages = ctr.getDocumentModel().getPages(first, last);
for (Page page : pages) {
RectF pbounds = page.getBounds(zoom);
float aspect = page.getAspectRatio();
float k = page.cpi.width / pbounds.width();
LOG.d("PAGE #", page.index.viewIndex);
LOG.d("PAGE wxh", page.cpi.width, page.cpi.height);
LOG.d("PAGE dpi", page.cpi.dpi, page.cpi.dpi);
LOG.d("pbounds p", pbounds, "zoom", zoom, "aspect", aspect);
LOG.d("pbounds p", pbounds, "zoom", zoom, "aspect", aspect);
if (RectF.intersects(pbounds, tapRect)) {
int pNumber = page.index.docIndex;
List<PointF> list = result.get(pNumber);
if (list == null) {
list = new ArrayList<PointF>();
}
p.x += scrollX;
p.y += scrollY - pbounds.top;
p.x = p.x * k;
p.y = p.y * k;
list.add(p);
result.put(pNumber, list);
}
}
}
float width = AppState.get().editLineWidth * 3;
float alpha = AppState.get().editAlphaColor;
ctr.getDecodeService().addAnnotation(result, color, width, alpha, new ResultResponse<Pair<Integer, List<Annotation>>>() {
@Override
public boolean onResultRecive(Pair<Integer, List<Annotation>> p) {
ctr.getDocumentModel().getPageObject(p.first).annotations = p.second;
ctr.getDocumentController().toggleRenderingEffects();
return false;
}
});
}
use of org.ebookdroid.core.codec.Annotation in project LibreraReader by foobnix.
the class VerticalModeController method underlineText.
@Override
public void underlineText(int color, float width, AnnotationType type) {
if (ctr == null || ctr.getDocumentController() == null || ctr.getDocumentModel() == null) {
LOG.d("Can't underlineText");
return;
}
final int first = ctr.getDocumentController().getFirstVisiblePage();
final int last = ctr.getDocumentController().getLastVisiblePage();
for (int i = first; i < last + 1; i++) {
final Page page = ctr.getDocumentModel().getPageByDocIndex(i);
if (page == null || page.selectedText == null) {
continue;
}
List<TextWord> texts = page.selectedText;
final ArrayList<PointF> quadPoints = new ArrayList<PointF>();
for (TextWord text : texts) {
RectF rect = text.getOriginal();
quadPoints.add(new PointF(rect.left, rect.bottom));
quadPoints.add(new PointF(rect.right, rect.bottom));
quadPoints.add(new PointF(rect.right, rect.top));
quadPoints.add(new PointF(rect.left, rect.top));
}
PointF[] array = quadPoints.toArray(new PointF[quadPoints.size()]);
ctr.getDecodeService().underlineText(i, array, color, type, new ResultResponse<List<Annotation>>() {
@Override
public boolean onResultRecive(List<Annotation> arg0) {
page.annotations = arg0;
page.selectedText = new ArrayList<TextWord>();
ctr.getDocumentController().toggleRenderingEffects();
return false;
}
});
}
}
use of org.ebookdroid.core.codec.Annotation in project LibreraReader by foobnix.
the class MuPdfPage method getAnnotations.
@Override
public List<Annotation> getAnnotations() {
TempHolder.lock.lock();
List<Annotation> result = new ArrayList<Annotation>();
try {
Annotation[] list = getAnnotationsInternal(docHandle, pageHandle);
if (list != null) {
for (int i = 0; i < list.length; i++) {
Annotation a = list[i];
update(a);
a.setIndex(i);
a.setPage(pageNumber);
a.setPageHandler(pageHandle);
result.add(a);
LOG.d("getAnnotation1s", pageNumber, i, "h", pageHandle);
}
}
} finally {
TempHolder.lock.unlock();
}
return result;
}
Aggregations