-
Notifications
You must be signed in to change notification settings - Fork 391
WIP: Improving view mode and rendering #2566
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
Open
harshad1
wants to merge
8
commits into
gsantner:master
Choose a base branch
from
harshad1:view_mode_options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7a292f8
Improving view mode options
harshad1 1ae2e5a
Improved line dividers
harshad1 c1e3aed
Balanced spacing for less visual jank
harshad1 9d70a9e
Merge branch 'master' into view_mode_options
gsantner af5c320
Changing how we get appSettings
harshad1 358c2d3
Uniform AppSettings in Fragment too
harshad1 b7433c7
Properly hiding keyboard
harshad1 164ed59
Merge branch 'master' into view_mode_options
gsantner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.text.Spannable; | ||
import android.text.style.LineBackgroundSpan; | ||
import android.text.style.LineHeightSpan; | ||
|
||
|
@@ -23,54 +24,71 @@ | |
public class TodoTxtSyntaxHighlighter extends TodoTxtBasicSyntaxHighlighter { | ||
|
||
private final static Pattern LINE_OF_TEXT = Pattern.compile("(?m)(.*)?"); | ||
private ParagraphDividerSpan _paragraphSpan; | ||
|
||
public TodoTxtSyntaxHighlighter(final AppSettings as) { | ||
super(as); | ||
} | ||
|
||
@Override | ||
public SyntaxHighlighterBase configure(Paint paint) { | ||
super.configure(paint); | ||
|
||
_delay = _appSettings.getHighlightingDelayTodoTxt(); | ||
return super.configure(paint); | ||
_paragraphSpan = new ParagraphDividerSpan(paint); | ||
|
||
return this; | ||
} | ||
|
||
@Override | ||
public void generateSpans() { | ||
|
||
super.generateSpans(); | ||
// Single span for the whole text - highly performant | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Single span for the whole file. Much faster! Much less highlighting jank! |
||
addSpanGroup(_paragraphSpan, 0, _spannable.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); | ||
|
||
// Paragraph space and divider half way up the space | ||
createSpanForMatches(LINE_OF_TEXT, matcher -> new ParagraphDividerSpan(_textColor)); | ||
super.generateSpans(); | ||
} | ||
|
||
// Adds spacing and divider line between paragraphs | ||
public static class ParagraphDividerSpan implements LineBackgroundSpan, LineHeightSpan, StaticSpan { | ||
private final int _lineColor; | ||
private int _origAscent = 0; | ||
private int _hash = 0; | ||
|
||
public ParagraphDividerSpan(@ColorInt int lineColor) { | ||
_lineColor = lineColor; | ||
private final @ColorInt int _lineColor; | ||
private final int _top, _ascent, _descent, _bottom, _offset; | ||
|
||
public ParagraphDividerSpan(final Paint paint) { | ||
final Paint.FontMetricsInt fm = paint.getFontMetricsInt(); | ||
_offset = Math.abs(fm.ascent) / 2; | ||
_top = fm.top; | ||
_ascent = fm.ascent; | ||
_descent = fm.descent; | ||
_bottom = fm.bottom; | ||
_lineColor = paint.getColor(); | ||
} | ||
|
||
@Override | ||
public void drawBackground(@NonNull Canvas canvas, @NonNull Paint paint, int left, int right, int top, int baseline, int bottom, @NonNull CharSequence text, int start, int end, int lineNumber) { | ||
if (start > 0 && text.charAt(start - 1) == '\n') { | ||
if (end > 0 && text.charAt(end - 1) == '\n') { | ||
paint.setColor(_lineColor); | ||
paint.setStrokeWidth(0); | ||
final float spacing = paint.getTextSize(); | ||
canvas.drawLine(left, top + spacing / 2, right, top + spacing / 2, paint); | ||
canvas.drawLine(left, bottom, right, bottom, paint); | ||
} | ||
} | ||
|
||
@Override | ||
public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v, Paint.FontMetricsInt fm) { | ||
if (_hash != text.hashCode()) { | ||
_origAscent = fm.ascent; | ||
_hash = text.hashCode(); | ||
fm.top = _top; | ||
fm.ascent = _ascent; | ||
fm.descent = _descent; | ||
fm.bottom = _bottom; | ||
|
||
if (start > 0 && text.charAt(start - 1) == '\n') { | ||
fm.top = _top - _offset; | ||
fm.ascent = _ascent - _offset; | ||
} | ||
|
||
if (end > 0 && text.charAt(end - 1) == '\n') { | ||
fm.descent = _descent + _offset; | ||
fm.bottom = _bottom + _offset; | ||
} | ||
boolean isFirstLineInParagraph = start > 0 && text.charAt(start - 1) == '\n'; | ||
fm.ascent = (isFirstLineInParagraph) ? (2 * _origAscent) : _origAscent; | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -453,6 +453,8 @@ private static void fetchAndInsertItem( | |
case AUDIO_BROWSE: { | ||
if (activity instanceof AppCompatActivity && nameEdit != null && pathEdit != null) { | ||
final GsFileBrowserOptions.SelectionListener fsListener = new GsFileBrowserOptions.SelectionListenerAdapter() { | ||
GsFileBrowserOptions.Options _dopt = null; | ||
|
||
@Override | ||
public void onFsViewerSelected(final String request, final File file, final Integer lineNumber) { | ||
setFields.callback(file); | ||
|
@@ -462,6 +464,20 @@ public void onFsViewerSelected(final String request, final File file, final Inte | |
public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { | ||
dopt.startFolder = currentFile.getParentFile(); | ||
dopt.rootFolder = GsFileBrowserListAdapter.VIRTUAL_STORAGE_ROOT; | ||
|
||
if (action == InsertType.LINK_BROWSE) { | ||
dopt.neutralButtonText = R.string.folder; | ||
} | ||
|
||
_dopt = dopt; | ||
} | ||
|
||
@Override | ||
public void onFsViewerNeutralButtonPressed(File currentFolder) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Select folder |
||
setFields.callback(currentFolder); | ||
if (_dopt != null) { | ||
_dopt.dialogInterface.dismiss();; | ||
} | ||
} | ||
}; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Do you see that scale still fitting quite good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. But I do all my testing just my own primary device - a pixel 7 pro