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

ZLView.my[View]Context => private

This commit is contained in:
Nikolay Pultsin 2013-04-26 14:05:01 +02:00
parent 754d895f19
commit 66e172b5c4
4 changed files with 45 additions and 33 deletions

View file

@ -82,7 +82,7 @@ public final class FBView extends ZLTextView {
}
myReader.runAction(getZoneMap().getActionByCoordinates(
x, y, myContext.getWidth(), myContext.getHeight(),
x, y, getContextWidth(), getContextHeight(),
isDoubleTapSupported() ? TapZoneMap.Tap.singleNotDoubleTap : TapZoneMap.Tap.singleTap
), x, y);
@ -100,7 +100,7 @@ public final class FBView extends ZLTextView {
return true;
}
myReader.runAction(getZoneMap().getActionByCoordinates(
x, y, myContext.getWidth(), myContext.getHeight(), TapZoneMap.Tap.doubleTap
x, y, getContextWidth(), getContextHeight(), TapZoneMap.Tap.doubleTap
), x, y);
return true;
}
@ -117,7 +117,7 @@ public final class FBView extends ZLTextView {
return true;
}
if (myReader.AllowScreenBrightnessAdjustmentOption.getValue() && x < myContext.getWidth() / 10) {
if (myReader.AllowScreenBrightnessAdjustmentOption.getValue() && x < getContextWidth() / 10) {
myIsBrightnessAdjustmentInProgress = true;
myStartY = y;
myStartBrightness = ZLibrary.Instance().getScreenBrightness();
@ -159,11 +159,11 @@ public final class FBView extends ZLTextView {
synchronized (this) {
if (myIsBrightnessAdjustmentInProgress) {
if (x >= myContext.getWidth() / 5) {
if (x >= getContextWidth() / 5) {
myIsBrightnessAdjustmentInProgress = false;
startManualScrolling(x, y);
} else {
final int delta = (myStartBrightness + 30) * (myStartY - y) / myContext.getHeight();
final int delta = (myStartBrightness + 30) * (myStartY - y) / getContextHeight();
ZLibrary.Instance().setScreenBrightness(myStartBrightness + delta);
return true;
}

View file

@ -23,14 +23,26 @@ import org.geometerplus.zlibrary.core.application.ZLApplication;
abstract public class ZLView {
public final ZLApplication Application;
protected ZLPaintContext myContext = new DummyPaintContext();
private ZLPaintContext myViewContext = new DummyPaintContext();
protected ZLView(ZLApplication application) {
Application = application;
}
protected final void setContext(ZLPaintContext context) {
myViewContext = context;
}
public final ZLPaintContext getContext() {
return myContext;
return myViewContext;
}
public final int getContextWidth() {
return myViewContext.getWidth();
}
public final int getContextHeight() {
return myViewContext.getHeight();
}
abstract public interface FooterArea {

View file

@ -382,13 +382,13 @@ public abstract class ZLTextView extends ZLTextViewBase {
@Override
public synchronized void preparePage(ZLPaintContext context, PageIndex pageIndex) {
myContext = context;
setContext(context);
preparePaintInfo(getPage(pageIndex));
}
@Override
public synchronized void paint(ZLPaintContext context, PageIndex pageIndex) {
myContext = context;
setContext(context);
final ZLFile wallpaper = getWallpaperFile();
if (wallpaper != null) {
context.clear(wallpaper, getWallpaperMode());
@ -561,7 +561,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
float charsPerLine = Math.min(effectiveWidth / charWidth,
charsPerParagraph * 1.2f);
final int strHeight = getWordHeight() + myContext.getDescent();
final int strHeight = getWordHeight() + getContext().getDescent();
final int effectiveHeight = (int) (textHeight - (getTextStyle().getSpaceBefore()
+ getTextStyle().getSpaceAfter()) / charsPerParagraph);
final int linesPerPage = effectiveHeight / strHeight;
@ -626,7 +626,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
}
private final float computeCharWidth(char[] pattern, int length) {
return myContext.getStringWidth(pattern, 0, length) / ((float)length);
return getContext().getStringWidth(pattern, 0, length) / ((float)length);
}
public static class PagePosition {
@ -758,8 +758,8 @@ public abstract class ZLTextView extends ZLTextViewBase {
} else {
right = selectionEndArea.XEnd;
}
myContext.setFillColor(color);
myContext.fillRectangle(left, top, right, bottom);
getContext().setFillColor(color);
getContext().fillRectangle(left, top, right, bottom);
}
}
}
@ -769,7 +769,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
drawBackgroung(mySelection, getSelectedBackgroundColor(), page, info, from, to, y);
drawBackgroung(myHighlighting, getHighlightingColor(), page, info, from, to, y);
final ZLPaintContext context = myContext;
final ZLPaintContext context = getContext();
final ZLTextParagraphCursor paragraph = info.ParagraphCursor;
int index = from;
final int endElementIndex = info.EndElementIndex;
@ -872,7 +872,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
final int startCharIndex,
final int endIndex
) {
final ZLPaintContext context = myContext;
final ZLPaintContext context = getContext();
final ZLTextLineInfo info = new ZLTextLineInfo(paragraphCursor, startIndex, startCharIndex, getTextStyle());
final ZLTextLineInfo cachedInfo = myLineInfoCache.get(info);
if (cachedInfo != null) {
@ -1061,7 +1061,7 @@ public abstract class ZLTextView extends ZLTextViewBase {
private void prepareTextLine(ZLTextPage page, ZLTextLineInfo info, int y) {
y = Math.min(y + info.Height, getTopMargin() + getTextAreaHeight() - 1);
final ZLPaintContext context = myContext;
final ZLPaintContext context = getContext();
final ZLTextParagraphCursor paragraphCursor = info.ParagraphCursor;
setTextStyle(info.StartStyle);

View file

@ -70,7 +70,7 @@ abstract class ZLTextViewBase extends ZLView {
final int getWordHeight() {
if (myWordHeight == -1) {
final ZLTextStyle textStyle = myTextStyle;
myWordHeight = (int)(myContext.getStringHeight() * textStyle.getLineSpacePercent() / 100) + textStyle.getVerticalShift();
myWordHeight = (int)(getContext().getStringHeight() * textStyle.getLineSpacePercent() / 100) + textStyle.getVerticalShift();
}
return myWordHeight;
}
@ -95,11 +95,11 @@ abstract class ZLTextViewBase extends ZLView {
}
int getTextAreaHeight() {
return myContext.getHeight() - getTopMargin() - getBottomMargin();
return getContextHeight() - getTopMargin() - getBottomMargin();
}
int getTextAreaWidth() {
return myContext.getWidth() - getLeftMargin() - getRightMargin();
return getContextWidth() - getLeftMargin() - getRightMargin();
}
final ZLTextStyle getTextStyle() {
@ -111,7 +111,7 @@ abstract class ZLTextViewBase extends ZLView {
myTextStyle = style;
myWordHeight = -1;
}
myContext.setFont(style.getFontFamily(), style.getFontSize(metrics()), style.isBold(), style.isItalic(), style.isUnderline(), style.isStrikeThrough());
getContext().setFont(style.getFontFamily(), style.getFontSize(metrics()), style.isBold(), style.isItalic(), style.isUnderline(), style.isStrikeThrough());
}
final void resetTextStyle() {
@ -182,7 +182,7 @@ abstract class ZLTextViewBase extends ZLView {
return getWordWidth((ZLTextWord)element, charIndex);
} else if (element instanceof ZLTextImageElement) {
final ZLTextImageElement imageElement = (ZLTextImageElement)element;
final ZLPaintContext.Size size = myContext.imageSize(
final ZLPaintContext.Size size = getContext().imageSize(
imageElement.ImageData,
getTextAreaSize(),
getScalingType(imageElement)
@ -191,7 +191,7 @@ abstract class ZLTextViewBase extends ZLView {
} else if (element == ZLTextElement.Indent) {
return myTextStyle.getFirstLineIndentDelta();
} else if (element instanceof ZLTextFixedHSpaceElement) {
return myContext.getSpaceWidth() * ((ZLTextFixedHSpaceElement)element).Length;
return getContext().getSpaceWidth() * ((ZLTextFixedHSpaceElement)element).Length;
}
return 0;
}
@ -201,30 +201,30 @@ abstract class ZLTextViewBase extends ZLView {
return getWordHeight();
} else if (element instanceof ZLTextImageElement) {
final ZLTextImageElement imageElement = (ZLTextImageElement)element;
final ZLPaintContext.Size size = myContext.imageSize(
final ZLPaintContext.Size size = getContext().imageSize(
imageElement.ImageData,
getTextAreaSize(),
getScalingType(imageElement)
);
return (size != null ? size.Height : 0) +
Math.max(myContext.getStringHeight() * (myTextStyle.getLineSpacePercent() - 100) / 100, 3);
Math.max(getContext().getStringHeight() * (myTextStyle.getLineSpacePercent() - 100) / 100, 3);
}
return 0;
}
final int getElementDescent(ZLTextElement element) {
return element instanceof ZLTextWord ? myContext.getDescent() : 0;
return element instanceof ZLTextWord ? getContext().getDescent() : 0;
}
final int getWordWidth(ZLTextWord word, int start) {
return
start == 0 ?
word.getWidth(myContext) :
myContext.getStringWidth(word.Data, word.Offset + start, word.Length - start);
word.getWidth(getContext()) :
getContext().getStringWidth(word.Data, word.Offset + start, word.Length - start);
}
final int getWordWidth(ZLTextWord word, int start, int length) {
return myContext.getStringWidth(word.Data, word.Offset + start, length);
return getContext().getStringWidth(word.Data, word.Offset + start, length);
}
private char[] myWordPartArray = new char[20];
@ -232,12 +232,12 @@ abstract class ZLTextViewBase extends ZLView {
final int getWordWidth(ZLTextWord word, int start, int length, boolean addHyphenationSign) {
if (length == -1) {
if (start == 0) {
return word.getWidth(myContext);
return word.getWidth(getContext());
}
length = word.Length - start;
}
if (!addHyphenationSign) {
return myContext.getStringWidth(word.Data, word.Offset + start, length);
return getContext().getStringWidth(word.Data, word.Offset + start, length);
}
char[] part = myWordPartArray;
if (length + 1 > part.length) {
@ -246,7 +246,7 @@ abstract class ZLTextViewBase extends ZLView {
}
System.arraycopy(word.Data, word.Offset + start, part, 0, length);
part[length] = '-';
return myContext.getStringWidth(part, 0, length + 1);
return getContext().getStringWidth(part, 0, length + 1);
}
int getAreaLength(ZLTextParagraphCursor paragraph, ZLTextElementArea area, int toCharIndex) {
@ -265,7 +265,7 @@ abstract class ZLTextViewBase extends ZLView {
}
final void drawWord(int x, int y, ZLTextWord word, int start, int length, boolean addHyphenationSign, ZLColor color) {
final ZLPaintContext context = myContext;
final ZLPaintContext context = getContext();
context.setTextColor(color);
if (start == 0 && length == -1) {
drawString(x, y, word.Data, word.Offset, word.Length, word.getMark(), 0);
@ -289,7 +289,7 @@ abstract class ZLTextViewBase extends ZLView {
}
private final void drawString(int x, int y, char[] str, int offset, int length, ZLTextWord.Mark mark, int shift) {
final ZLPaintContext context = myContext;
final ZLPaintContext context = getContext();
if (mark == null) {
context.drawString(x, y, str, offset, length);
} else {