touch record lazy initialize

This commit is contained in:
hyb1996
2018-02-27 09:39:58 +08:00
parent b8633fa059
commit 86c1371e93
2 changed files with 19 additions and 12 deletions

View File

@@ -43,7 +43,21 @@ public class GlobalActionRecorder implements Recorder.OnStateChangedListener {
public GlobalActionRecorder(Context context) { public GlobalActionRecorder(Context context) {
mContext = new ContextThemeWrapper(context.getApplicationContext(), R.style.AppTheme); mContext = new ContextThemeWrapper(context.getApplicationContext(), R.style.AppTheme);
mTouchRecorder = new TouchRecorder(context) { }
public void start() {
if (mTouchRecorder == null) {
mTouchRecorder = createTouchRecorder();
}
mTouchRecorder.reset();
mDiscard = false;
mTouchRecorder.setOnStateChangedListener(this);
mTouchRecorder.start();
}
private TouchRecorder createTouchRecorder() {
return new TouchRecorder(mContext) {
@Override @Override
protected InputEventRecorder createInputEventRecorder() { protected InputEventRecorder createInputEventRecorder() {
if (Pref.rootRecordGeneratesBinary()) if (Pref.rootRecordGeneratesBinary())
@@ -54,14 +68,6 @@ public class GlobalActionRecorder implements Recorder.OnStateChangedListener {
}; };
} }
public void start() {
mTouchRecorder.reset();
mDiscard = false;
mTouchRecorder.setOnStateChangedListener(this);
mTouchRecorder.start();
}
public void pause() { public void pause() {
mTouchRecorder.pause(); mTouchRecorder.pause();
} }

View File

@@ -151,6 +151,7 @@ public class CodeEditText extends AppCompatEditText {
int lineNumberColor = mTheme.getLineNumberColor(); int lineNumberColor = mTheme.getLineNumberColor();
if (DEBUG) if (DEBUG)
Log.d(LOG_TAG, "draw line: " + (mLastLineForDraw - mFirstLineForDraw + 1)); Log.d(LOG_TAG, "draw line: " + (mLastLineForDraw - mFirstLineForDraw + 1));
mLogger.addSplit("before draw line");
for (int line = mFirstLineForDraw; line <= mLastLineForDraw && line < lineCount; line++) { for (int line = mFirstLineForDraw; line <= mLastLineForDraw && line < lineCount; line++) {
int lineBottom = layout.getLineTop(line + 1); int lineBottom = layout.getLineTop(line + 1);
int lineBaseline = lineBottom - layout.getLineDescent(line); int lineBaseline = lineBottom - layout.getLineDescent(line);
@@ -181,8 +182,6 @@ public class CodeEditText extends AppCompatEditText {
} else { } else {
previousColor = highlightTokens.colors[previousColorPos]; previousColor = highlightTokens.colors[previousColorPos];
} }
if (DEBUG)
Log.d(LOG_TAG, "draw line " + line + ": " + (visibleCharEnd - visibleCharStart));
int i; int i;
for (i = visibleCharStart; i < visibleCharEnd; i++) { for (i = visibleCharStart; i < visibleCharEnd; i++) {
int color; int color;
@@ -204,7 +203,9 @@ public class CodeEditText extends AppCompatEditText {
paint.setColor(previousColor); paint.setColor(previousColor);
float offsetX = paint.measureText(text, lineStart, previousColorPos); float offsetX = paint.measureText(text, lineStart, previousColorPos);
canvas.drawText(text, previousColorPos, visibleCharEnd, paddingLeft + offsetX, lineBaseline, paint); canvas.drawText(text, previousColorPos, visibleCharEnd, paddingLeft + offsetX, lineBaseline, paint);
if (DEBUG) {
mLogger.addSplit("draw line " + line + " (" + (visibleCharEnd - visibleCharStart) + ") ");
}
} }
} }