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) {
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
protected InputEventRecorder createInputEventRecorder() {
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() {
mTouchRecorder.pause();
}

View File

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