| | |
| | | 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.graphics.Rect; |
| | | import android.graphics.RectF; |
| | | 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); |
| | | path.addOval(new RectF(new Rect(100,100,200,200)), 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; |
| | | } |
| | | } |
| | | //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.graphics.Rect; |
| | | //import android.graphics.RectF; |
| | | //import android.opengl.GLSurfaceView; |
| | | //import android.os.Bundle; |
| | | //import android.support.annotation.NonNull; |
| | | //import android.support.annotation.Nullable; |
| | | //import android.support.v7.widget.Toolbar; |
| | | //import android.util.Log; |
| | | //import android.view.LayoutInflater; |
| | | //import android.view.SurfaceHolder; |
| | | //import android.view.SurfaceView; |
| | | //import android.view.View; |
| | | //import android.view.ViewGroup; |
| | | //import android.widget.LinearLayout; |
| | | // |
| | | //import javax.security.auth.login.LoginException; |
| | | // |
| | | //import me.yokeyword.fragmentation.SupportFragment; |
| | | //import safeluck.drive.evaluation.R; |
| | | ////import safeluck.drive.evaluation.render.GLRender; |
| | | // |
| | | // |
| | | ///** |
| | | // * 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{ |
| | | // private boolean isDrawing = false; |
| | | // |
| | | // public static SupportFragment newInstance(){ |
| | | // return new MapFragment(); |
| | | // } |
| | | // private GLSurfaceView mGLSurfaceView; |
| | | // private static final String TAG = "MapFragment"; |
| | | // private SurfaceHolder holder; |
| | | // Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| | | // Path path = new Path(); |
| | | // private Canvas canvas; |
| | | // private int x=-1; |
| | | // private int y = -1; |
| | | // private Toolbar toolbar; |
| | | // |
| | | // private LinearLayout linearLayout;//surfaceview的父容器,为了移动surfaceview而使用,因为scrollto不能移动view, |
| | | // |
| | | // @Nullable |
| | | // @Override |
| | | // public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
| | | // View view = inflater.inflate(R.layout.layout_mapfragment,container,false); |
| | | // initView(view); |
| | | // return view; |
| | | // } |
| | | // |
| | | // private void initView(View view) { |
| | | // toolbar = view.findViewById(R.id.toolbar); |
| | | // toolbar.setTitle("简单地图"); |
| | | // |
| | | // mGLSurfaceView = view.findViewById(R.id.glsurface); |
| | | // mGLSurfaceView.setRenderer(new GLRender()); |
| | | // } |
| | | // |
| | | // |
| | | // |
| | | //} |