just to save works
This commit is contained in:
24
app/src/main/assets/sample/画图/函数图像.js
Normal file
24
app/src/main/assets/sample/画图/函数图像.js
Normal file
@@ -0,0 +1,24 @@
|
||||
"ui";
|
||||
ui.layout(
|
||||
<frame>
|
||||
<canvas id="graphic" w="*" h="*"/>
|
||||
</frame>
|
||||
);
|
||||
|
||||
var f = function(x){
|
||||
return x * x + 3 * x - 4;
|
||||
}
|
||||
|
||||
var paint = new Paint();
|
||||
paint.setStrokeWidth(2);
|
||||
var start = -5;
|
||||
var end = 5;
|
||||
|
||||
ui.graphic.on("draw", function(canvas){
|
||||
var w = canvas.getWidth();
|
||||
for (var i = 0; i < w; i++) {
|
||||
var x = (end - start) / w * i + start;
|
||||
var y = f(x);
|
||||
canvas.drawPoint(x, y, paint);
|
||||
}
|
||||
});
|
||||
@@ -96,14 +96,15 @@ public class JavaScriptHighlighter implements SimpleTextWatcher.AfterTextChanged
|
||||
TokenStream ts = new TokenStream(null, sourceString, 0);
|
||||
HighlightTokens highlightTokens = new HighlightTokens(sourceString);
|
||||
int token;
|
||||
int color = mTheme.getColorForToken(Token.NAME);
|
||||
while ((token = ts.getToken()) != Token.EOF) {
|
||||
if (mRunningHighlighterId.get() != id)
|
||||
return;
|
||||
int color = mTheme.getColorForToken(token);
|
||||
color = mTheme.getColorForToken(token);
|
||||
highlightTokens.addToken(ts.getTokenBeg(), ts.getTokenEnd(), color);
|
||||
}
|
||||
if (highlightTokens.getCharCount() < sourceString.length()) {
|
||||
highlightTokens.addToken(highlightTokens.getCharCount(), sourceString.length(), mTheme.getColorForToken(Token.NAME));
|
||||
highlightTokens.addToken(highlightTokens.getCharCount(), sourceString.length(), color);
|
||||
}
|
||||
mCodeEditText.updateHighlightTokens(highlightTokens);
|
||||
}
|
||||
|
||||
@@ -76,9 +76,10 @@ public class AboutActivity extends BaseActivity {
|
||||
@Click(R.id.icon)
|
||||
void lol() {
|
||||
mLolClickCount++;
|
||||
Toast.makeText(this, R.string.text_lll, Toast.LENGTH_LONG).show();
|
||||
//Toast.makeText(this, R.string.text_lll, Toast.LENGTH_LONG).show();
|
||||
if (mLolClickCount >= 5) {
|
||||
crashTest();
|
||||
//crashTest();
|
||||
showEasterEgg();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,11 +93,8 @@ public class AboutActivity extends BaseActivity {
|
||||
new ThemeColorMaterialDialogBuilder(this)
|
||||
.title("Crash Test")
|
||||
.positiveText("Crash")
|
||||
.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
throw new RuntimeException("Crash Test");
|
||||
}
|
||||
.onPositive((dialog, which) -> {
|
||||
throw new RuntimeException("Crash Test");
|
||||
}).show();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
package com.stardust.scriptdroid.ui.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import com.stardust.theme.ThemeColorManagerCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/5/10.
|
||||
*/
|
||||
|
||||
public class PaintView extends View {
|
||||
|
||||
private List<Path> mPaths = new ArrayList<>();
|
||||
private Path mCurrentPath;
|
||||
private Paint mPaint;
|
||||
|
||||
public PaintView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public PaintView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public PaintView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||
public PaintView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
mPaint = new Paint();
|
||||
mPaint.setColor(ThemeColorManagerCompat.getColorPrimary());
|
||||
mPaint.setAntiAlias(true);
|
||||
mPaint.setStrokeWidth(5);
|
||||
setWillNotDraw(false);
|
||||
setClickable(true);
|
||||
setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
for (Path path : mPaths) {
|
||||
canvas.drawPath(path, mPaint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
float x = event.getY();
|
||||
float y = event.getY();
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
onTouchDown(x, y);
|
||||
return true;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
onTouchMove(x, y);
|
||||
return true;
|
||||
case MotionEvent.ACTION_UP:
|
||||
onTouchUp(x, y);
|
||||
return true;
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
private void onTouchDown(float x, float y) {
|
||||
if (mCurrentPath != null) {
|
||||
mCurrentPath.close();
|
||||
mPaths.add(mCurrentPath);
|
||||
invalidate();
|
||||
}
|
||||
mCurrentPath = new Path();
|
||||
mCurrentPath.moveTo(x, y);
|
||||
}
|
||||
|
||||
private void onTouchMove(float x, float y) {
|
||||
mCurrentPath.moveTo(x, y);
|
||||
}
|
||||
|
||||
private void onTouchUp(float x, float y) {
|
||||
mCurrentPath.close();
|
||||
mPaths.add(mCurrentPath);
|
||||
mCurrentPath = null;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.stardust.scriptdroid.ui.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2018/3/16.
|
||||
*/
|
||||
|
||||
public class TestSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
|
||||
|
||||
private volatile boolean mDrawing = true;
|
||||
private static final String LOG_TAG = "TestSurfaceView";
|
||||
private ExecutorService mDrawingThreadPool;
|
||||
|
||||
public TestSurfaceView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public TestSurfaceView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public TestSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
getHolder().addCallback(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
performDraw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
|
||||
}
|
||||
|
||||
private void performDraw() {
|
||||
if (mDrawingThreadPool == null)
|
||||
mDrawingThreadPool = Executors.newCachedThreadPool();
|
||||
mDrawingThreadPool.execute(() -> {
|
||||
SurfaceHolder holder = getHolder();
|
||||
while (mDrawing) {
|
||||
Canvas canvas = holder.lockCanvas();
|
||||
canvas.drawColor(Color.RED);
|
||||
holder.unlockCanvasAndPost(canvas);
|
||||
}
|
||||
Log.d(LOG_TAG, "drawing thread: mRunning = false");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onWindowVisibilityChanged(int visibility) {
|
||||
if (visibility == VISIBLE) {
|
||||
if (mDrawingThreadPool != null) {
|
||||
mDrawing = true;
|
||||
performDraw();
|
||||
}
|
||||
} else {
|
||||
mDrawing = false;
|
||||
}
|
||||
super.onWindowVisibilityChanged(visibility);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
Log.d(LOG_TAG, "surfaceDestroyed: mRunning = true");
|
||||
mDrawing = false;
|
||||
Log.d(LOG_TAG, "surfaceDestroyed: mRunning = false");
|
||||
mDrawingThreadPool.shutdown();
|
||||
mDrawingThreadPool = null;
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,7 @@
|
||||
android:layout_width="600dp"
|
||||
android:layout_height="600dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:padding="200dp"
|
||||
android:src="@drawable/ic_android_eat_js"/>
|
||||
|
||||
<com.stardust.scriptdroid.ui.settings.PaintView
|
||||
<com.stardust.scriptdroid.ui.settings.TestSurfaceView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user