Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide margins if no overlay text #1951

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class HighlightingImageView extends AppCompatImageView {
private boolean isNightMode;
private boolean isColorFilterOn;
private int nightModeTextBrightness = Constants.DEFAULT_NIGHT_MODE_TEXT_BRIGHTNESS;
private int topBottom;

// Params for drawing text
private int fontSize;
Expand Down Expand Up @@ -143,13 +144,9 @@ public HighlightingImageView(Context context, AttributeSet attrs) {
}

public void setIsScrollable(boolean scrollable, boolean landscape) {
int topBottom = scrollable ? scrollableHeaderFooterSize :
landscape ? dualPageHeaderFooterSize : headerFooterSize;
topBottom = scrollable ? scrollableHeaderFooterSize :
landscape ? dualPageHeaderFooterSize : headerFooterSize;
verticalOffsetForScrolling = topBottom;
setPadding(horizontalSafeOffset,
topBottom + topSafeOffset,
horizontalSafeOffset,
topBottom + bottomSafeOffset);
fontSize = scrollable ? scrollableHeaderFooterFontSize :
landscape ? dualPageHeaderFooterFontSize : headerFooterFontSize;
}
Expand Down Expand Up @@ -525,6 +522,15 @@ protected void onDraw(@NonNull Canvas canvas) {
overlayText(canvas, getImageMatrix());
}

if(!didDraw){
setPadding(horizontalSafeOffset, topSafeOffset, horizontalSafeOffset, bottomSafeOffset);
} else {
setPadding(horizontalSafeOffset,
topBottom + topSafeOffset,
horizontalSafeOffset,
topBottom + bottomSafeOffset);
}
Comment on lines +525 to +532
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jazakumAllah khairan - may we move this back into setIsScrollable with a check? this onDraw method gets called every frame, so we want to keep it as light as possible - whereas setIsScrollable just happens once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, but I don't see an easy way to move this block back to setIsScrollable, because setIsScrollable is not aware of what happens in onDraw

Some observations:

  • show pages 1 and 2 (landscape, dual page) for the first time, then setIsScrollable is executed 8 times and onDraw is executed 6 times.
  • swipe to pages 3 and 4, then setIsScrollable is executed 2 times and onDraw is executed 4 times (reduces to 2 times when this if block is removed).
  • swipe back to pages 1 and 2, then only setIsScrollable is executed twice.


// run additional image draw helpers if any
if (imageDrawHelpers != null && pageCoordinates != null) {
for (ImageDrawHelper imageDrawHelper : imageDrawHelpers) {
Expand Down