Example #1
0
 protected void init()
 {
     recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView);
     drawView     = new DrawView(this, 96 * multiply, 64 * multiply, multiply, typeface);
     Android.Widget.LinearLayout.LayoutParams lp = new Android.Widget.LinearLayout.LayoutParams(96 * multiply, 64 * multiply);
     lp.SetMargins(10, 10, 10, 10);
     lp.Gravity = GravityFlags.Center;
     drawView.LayoutParameters = lp;
     drawView.SetBackgroundColor(Android.Graphics.Color.ParseColor("#000000"));
 }
Example #2
0
        private void DrawLines(float[] currentCoordinates, MotionEventActions action, DrawView drawView)
        {
            int[] draw;
            try
            {
                draw = drawView.GetCoordinates(currentCoordinates);
            }
            catch (InvalidCoordinatesException)
            {
                try
                {
                    LastDrawStep = DrawStep.StartProgram;
                    int[] drawOld = drawView.GetCoordinates(lastDrawnCoordinates);
                    SendToArduino("{p;" + drawOld[0] + "," + drawOld[1] + "}");
                    drawView.DrawLine(firstPointOfLineCoordinates, lastDrawnCoordinates);
                    return;
                }
                catch (InvalidCoordinatesException)
                {
                    LastDrawStep = DrawStep.StartProgram;
                    return;
                }
            }

            if (!equalsNumbers(lastDraw, draw))
            {
                drawningStep++;
                double lastDistancea = Math.Sqrt(Math.Pow((lastDrawnCoordinates[0] - currentCoordinates[0]), 2) + Math.Pow((lastDrawnCoordinates[1] - currentCoordinates[1]), 2));
                int    stepLimit     = 2;
                if (lastDistancea < 8)
                {
                    stepLimit = 3;
                }
                if (lastDistancea < 6)
                {
                    stepLimit = 4;
                }
                if (lastDistancea < 3)
                {
                    stepLimit = 5;
                }
                if (lastDistancea <= 1)
                {
                    stepLimit = 7;
                }
                if (lastDistancea > 30)
                {
                    stepLimit = 1;
                }
                if (lastDistancea > 40)
                {
                    stepLimit = 0;
                }

                if ((LastDrawStep == DrawStep.GetAngle && drawningStep > stepLimit) || action == MotionEventActions.Up)
                {
                    float  x2x1       = 0 - firstPointOfLineCoordinates[0] - lastDrawnCoordinates[0];
                    float  x3x1       = 0 - firstPointOfLineCoordinates[0] - currentCoordinates[0];
                    float  point21    = (0 - firstPointOfLineCoordinates[1] - lastDrawnCoordinates[1]) / x2x1;
                    float  point31    = (0 - firstPointOfLineCoordinates[1] - currentCoordinates[1]) / x3x1;
                    double distance   = Math.Sqrt(Math.Pow((firstPointOfLineCoordinates[0] - currentCoordinates[0]), 2) + Math.Pow((firstPointOfLineCoordinates[1] - currentCoordinates[1]), 2));
                    double varDecided = 0.002;

                    // DO DDEBUGOWANIA
                    // Console.WriteLine("{0:F5} ; {1:F5} ; {2:F8} ; {3:F8} ; {10:F8} ; X - {4:F2} ; Y - {5:F2} ; x - {6:F2} ; y - {7:F2} ; x - {8:F2} ; y - {9:F2}", point21, point31, Math.Abs(point21 - point31), lastDistancea, firstPointOfLineCoordinates[0], firstPointOfLineCoordinates[1], lastDrawnCoordinatesOnCanva[0] , lastDrawnCoordinatesOnCanva[1] ,currentCoordinates[0], currentCoordinates[1], varDecided);
                    // -----------------

                    if (x2x1 != 0 && x3x1 != 0)
                    {
                        if (Math.Abs(point21 - point31) > (float)varDecided || action == MotionEventActions.Up || lastDistance > distance)
                        {
                            lastDraw = drawView.GetCoordinates(lastDrawnCoordinates);
                            SendToArduino("{p;" + lastDraw[0] + "," + lastDraw[1] + "}");
                            drawView.DrawLine(firstPointOfLineCoordinates, lastDrawnCoordinates);

                            firstPointOfLineCoordinates = lastDrawnCoordinates;
                            LastDrawStep = DrawStep.CreatePoint;
                        }
                    }
                    if (action == MotionEventActions.Up)
                    {
                        LastDrawStep = DrawStep.CheckedAndDraw;
                    }
                    lastDistance = distance;
                    drawningStep = 0;
                }

                if (LastDrawStep == DrawStep.CreatePoint)
                {
                    lastDistance         = Math.Sqrt((draw[0] * draw[0]) + (draw[1] * draw[1]));
                    LastDrawStep         = DrawStep.GetAngle;
                    lastDrawnCoordinates = currentCoordinates;
                }
            }

            if (action == MotionEventActions.Down && (LastDrawStep == DrawStep.CheckedAndDraw || LastDrawStep == DrawStep.StartProgram))
            {
                firstPointOfLineCoordinates = currentCoordinates;
                SendToArduino("{d;" + draw[0] + "," + draw[1] + "}");
                LastDrawStep         = DrawStep.CreatePoint;
                lastDrawnCoordinates = currentCoordinates;
                lastDistance         = 0;
                drawView.DrawPoint(currentCoordinates);
                return;
            }
            lastDrawnCoordinates = currentCoordinates;
        }