New file |
| | |
| | | package safeluck.drive.evaluation.fragment; |
| | | |
| | | import android.graphics.Canvas; |
| | | import android.graphics.Color; |
| | | import android.graphics.Paint; |
| | | import android.graphics.Path; |
| | | import android.graphics.PathDashPathEffect; |
| | | import android.os.Bundle; |
| | | import android.support.annotation.NonNull; |
| | | import android.support.annotation.Nullable; |
| | | import android.view.LayoutInflater; |
| | | import android.view.SurfaceHolder; |
| | | import android.view.SurfaceView; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.R; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | | * Created by lzw on 2019/9/26. 15:20:58 |
| | | * 邮箱:632393724@qq.com |
| | | * All Rights Saved! Chongqing AnYun Tech co. LTD |
| | | */ |
| | | public class MapFragment extends SupportFragment implements SurfaceHolder.Callback { |
| | | private boolean isDrawing = false; |
| | | |
| | | public static SupportFragment newInstance(){ |
| | | return new MapFragment(); |
| | | } |
| | | private SurfaceView mSurfaceView; |
| | | private SurfaceHolder holder; |
| | | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| | | Path path = new Path(); |
| | | private Canvas canvas; |
| | | @Nullable |
| | | @Override |
| | | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | |
| | | |
| | | mSurfaceView = new SurfaceView(getActivity()); |
| | | ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); |
| | | holder = mSurfaceView.getHolder(); |
| | | holder.addCallback(this); |
| | | mSurfaceView.setLayoutParams(layoutParams); |
| | | mSurfaceView.setKeepScreenOn(true); |
| | | return mSurfaceView; |
| | | } |
| | | |
| | | @Override |
| | | public void surfaceCreated(final SurfaceHolder holder) { |
| | | isDrawing = true; |
| | | //开启线程 进行画图 |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | while (isDrawing){ |
| | | drawPath(); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | private void drawPath() { |
| | | try { |
| | | canvas = holder.lockCanvas(); |
| | | paint.setColor(Color.RED); |
| | | path.addCircle(mSurfaceView.getWidth()/2,mSurfaceView.getHeight()/2,70, Path.Direction.CW); |
| | | canvas.drawPath(path,paint); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if (canvas != null){ |
| | | holder.unlockCanvasAndPost(canvas); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void surfaceDestroyed(SurfaceHolder holder) { |
| | | isDrawing = false; |
| | | } |
| | | } |