Skip to content

Commit a210a02

Browse files
committed
improve: reduce accessibility service cost
1 parent f093c07 commit a210a02

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

app/src/main/java/io/neoterm/frontend/terminal/TerminalView.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.view.MenuItem;
2525
import android.view.MotionEvent;
2626
import android.view.View;
27+
import android.view.accessibility.AccessibilityManager;
2728
import android.view.inputmethod.BaseInputConnection;
2829
import android.view.inputmethod.EditorInfo;
2930
import android.view.inputmethod.InputConnection;
@@ -102,6 +103,8 @@ public final class TerminalView extends View {
102103
*/
103104
private boolean mEnableWordBasedIme = false;
104105

106+
private boolean mAccessibilityEnabled;
107+
105108
public TerminalView(Context context) {
106109
super(context);
107110
commonInit(context);
@@ -283,6 +286,8 @@ public void onLongPress(MotionEvent e) {
283286
}
284287
});
285288
mScroller = new Scroller(context);
289+
AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
290+
mAccessibilityEnabled = am != null && am.isEnabled();
286291
}
287292

288293
/**
@@ -460,8 +465,8 @@ public void onScreenUpdated() {
460465
// 如果二者不一样,即 mTop != 0,则说明用户在脚本输出的时候滚动了屏幕
461466
// 很有可能时用户需要观察上面脚本的输出结果
462467
// 那么这个时候我们就不跟随输出滚动屏幕
463-
// int currentScroll = computeVerticalScrollOffset();
464-
// int expectedScroll = mEmulator.getScreen().getActiveRows() - mEmulator.mRows;
468+
// int currentScroll = computeVerticalScrollOffset();
469+
// int expectedScroll = mEmulator.getScreen().getActiveRows() - mEmulator.mRows;
465470

466471
if (mTopRow != 0) {
467472
isScreenHeld = true;
@@ -508,8 +513,10 @@ public void onScreenUpdated() {
508513

509514
// Basic accessibility service
510515
String contentText = mEmulator.getScreen()
511-
.getSelectedText(0, mTopRow, mEmulator.mColumns, mTopRow +mEmulator.mRows);
512-
setContentDescription(contentText);
516+
.getSelectedText(0, mTopRow, mEmulator.mColumns, mTopRow + mEmulator.mRows);
517+
if (mAccessibilityEnabled) {
518+
setContentDescription(contentText);
519+
}
513520
}
514521

515522
public int getTextSize() {

0 commit comments

Comments
 (0)