Skip to content

Commit

Permalink
chore: update code style & class visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosemoe committed Sep 30, 2023
1 parent 9648d08 commit 6182ab1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
61 changes: 32 additions & 29 deletions editor/src/main/java/io/github/rosemoe/sora/widget/CodeEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ int binarySearchEndBlock(int firstVis, List<CodeBlock> blocks) {
@NonNull
public List<Span> getSpansForLine(int line) {
var spanMap = textStyles == null ? null : textStyles.spans;
if (defaultSpans.size() == 0) {
if (defaultSpans.isEmpty()) {
defaultSpans.add(Span.obtain(0, EditorColorScheme.TEXT_NORMAL));
}
try {
Expand Down Expand Up @@ -2576,7 +2576,7 @@ public boolean onQueryTextSubmit(String text) {

@Override
public boolean onQueryTextChange(String text) {
if (text == null || text.length() == 0) {
if (text == null || text.isEmpty()) {
getSearcher().stopSearch();
return false;
}
Expand Down Expand Up @@ -2604,14 +2604,9 @@ public boolean onActionItemClicked(final ActionMode am, MenuItem p2) {
return false;
}
switch (p2.getItemId()) {
case 1:
getSearcher().gotoPrevious();
break;
case 0:
getSearcher().gotoNext();
break;
case 2:
case 3:
case 1 -> getSearcher().gotoPrevious();
case 0 -> getSearcher().gotoNext();
case 2, 3 -> {
final boolean replaceAll = p2.getItemId() == 3;
final EditText et = new EditText(getContext());
et.setHint(I18nConfig.getResourceId(R.string.sora_editor_replacement));
Expand All @@ -2629,7 +2624,7 @@ public boolean onActionItemClicked(final ActionMode am, MenuItem p2) {
dialog.dismiss();
})
.show();
break;
}
}
return false;
}
Expand Down Expand Up @@ -3523,7 +3518,7 @@ public void pasteText() {
}

} catch (Exception e) {
e.printStackTrace();
Log.w(LOG_TAG, e);
Toast.makeText(getContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
Expand Down Expand Up @@ -3558,7 +3553,7 @@ public void copyText(boolean shouldCopyLine) {
if (e.getCause() instanceof TransactionTooLargeException) {
Toast.makeText(getContext(), I18nConfig.getResourceId(R.string.sora_editor_clip_text_length_too_large), Toast.LENGTH_SHORT).show();
} else {
e.printStackTrace();
Log.w(LOG_TAG, e);
Toast.makeText(getContext(), e.getClass().toString(), Toast.LENGTH_SHORT).show();
}
}
Expand Down Expand Up @@ -4319,7 +4314,7 @@ protected void releaseEdgeEffects() {
//-------------------------Override methods--------------------------------------
//-------------------------------------------------------------------------------
@Override
protected void onDraw(Canvas canvas) {
protected void onDraw(@NonNull Canvas canvas) {
super.onDraw(canvas);

renderer.draw(canvas);
Expand Down Expand Up @@ -4379,33 +4374,41 @@ public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
switch (action) {
case AccessibilityNodeInfo.ACTION_COPY:
case AccessibilityNodeInfo.ACTION_COPY -> {
copyText();
return true;
case AccessibilityNodeInfo.ACTION_CUT:
}
case AccessibilityNodeInfo.ACTION_CUT -> {
cutText();
return true;
case AccessibilityNodeInfo.ACTION_PASTE:
}
case AccessibilityNodeInfo.ACTION_PASTE -> {
pasteText();
return true;
case AccessibilityNodeInfo.ACTION_SET_TEXT:
}
case AccessibilityNodeInfo.ACTION_SET_TEXT -> {
setText(arguments.getCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE));
return true;
case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
}
case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD -> {
movePageDown();
return true;
case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
}
case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD -> {
movePageUp();
return true;
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
switch (action) {
case android.R.id.accessibilityActionScrollDown:
case android.R.id.accessibilityActionScrollDown -> {
movePageDown();
return true;
case android.R.id.accessibilityActionScrollUp:
}
case android.R.id.accessibilityActionScrollUp -> {
movePageUp();
return true;
}
}
}
return super.performAccessibilityAction(action, arguments);
Expand All @@ -4420,21 +4423,21 @@ public CharSequence getAccessibilityClassName() {
public boolean dispatchTouchEvent(MotionEvent event) {
int x = (int) event.getX();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_DOWN -> {
downX = x;
if (forceHorizontalScrollable) {
getParent().requestDisallowInterceptTouchEvent(true);
}
break;
case MotionEvent.ACTION_MOVE:
}
case MotionEvent.ACTION_MOVE -> {
int deltaX = x - downX;
if (forceHorizontalScrollable && !touchHandler.hasAnyHeldHandle()) {
if (deltaX > 0 && getScroller().getCurrX() == 0
|| deltaX < 0 && getScroller().getCurrX() == getScrollMaxX()) {
getParent().requestDisallowInterceptTouchEvent(false);
}
}
break;
}
}
return super.dispatchTouchEvent(event);
}
Expand Down Expand Up @@ -4484,9 +4487,9 @@ public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_TEXT);
} else if (region == RegionResolverKt.REGION_LINE_NUMBER) {
switch (props.actionWhenLineNumberClicked) {
case DirectAccessProps.LN_ACTION_SELECT_LINE:
case DirectAccessProps.LN_ACTION_PLACE_SELECTION_HOME:
case DirectAccessProps.LN_ACTION_SELECT_LINE, DirectAccessProps.LN_ACTION_PLACE_SELECTION_HOME -> {
return PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_HAND);
}
}
}
return super.onResolvePointerIcon(event, pointerIndex);
Expand Down Expand Up @@ -4890,7 +4893,7 @@ public void onFormatSucceed(@NonNull CharSequence applyContent, @Nullable TextRa
var end = cursorRange.getEnd();
setSelectionRegion(start.line, start.column, end.line, end.column);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
Log.w(LOG_TAG, e);
}
}
getScroller().forceFinished(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* @author Rose
* @author Akash Yadav
*/
class EditorKeyEventHandler {
public class EditorKeyEventHandler {

private static final String TAG = "EditorKeyEventHandler";
private final CodeEditor editor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import io.github.rosemoe.sora.lang.diagnostic.DiagnosticsContainer;
import io.github.rosemoe.sora.lang.styling.Styles;

class EditorStyleDelegate implements StyleReceiver {
public class EditorStyleDelegate implements StyleReceiver {

private final WeakReference<CodeEditor> editorRef;
private PairedBracket foundPair;
Expand Down

0 comments on commit 6182ab1

Please sign in to comment.