public static void GetBitmap(this Android.Views.View view, System.Action <Android.Graphics.Bitmap> callback)
        {
            var window           = Settings.Activity.Window;
            var bitmap           = Android.Graphics.Bitmap.CreateBitmap(view.Width, view.Height, Android.Graphics.Bitmap.Config.Argb8888);
            var locationInWindow = new int[2];

            view.GetLocationInWindow(locationInWindow);
            try
            {
                var rect = new Android.Graphics.Rect(locationInWindow[0], locationInWindow[1], locationInWindow[0] + view.Width, locationInWindow[1] + view.Height);
                PixelCopy.Request(window, rect, bitmap, new PixelCopyListener(callback, bitmap), null);
            }
            catch (Java.Lang.IllegalArgumentException e)
            {
                e.PrintStackTrace();
            }
        }
        public static Point[] GetTouches(MotionEvent.PointerCoords[] coords, Android.Views.View view, int[] startLocation)
        {
            //System.Diagnostics.Debug.WriteLine("c0=["+current.GetX()+","+current.GetY()+"]");

            int[] viewLocation = { 0, 0 };
            view?.GetLocationInWindow(viewLocation);

            int pointerCount = coords.Length;
            var array        = new Point[pointerCount];

            for (int i = 0; i < pointerCount; i++)
            {
                array[i] = DIP.ToPoint((double)(coords[i].X + viewLocation[0] - startLocation[0]), (double)(coords[i].Y + viewLocation[1] - startLocation[1]));
                //System.Diagnostics.Debug.WriteLine ("i=["+i+"] pc=["+pointerCoords.X+", "+pointerCoords.Y+"] a=["+array[i]+"]");
            }

            return(array);
        }
Exemple #3
0
        public static Point GetShowcasePointFromView(View view, ShowcaseView.ConfigOptions options)
        {
            var result = new Point();

            if (options.Insert == ShowcaseView.INSERTTOVIEW)
            {
                result.X = view.Left + view.Width / 2;
                result.Y = view.Top + view.Height / 2;
            }
            else
            {
                var coordinates = new int[2];

                view.GetLocationInWindow(coordinates);
                result.X = coordinates[0] + view.Width / 2;
                result.Y = coordinates[1] + view.Height / 2;
            }
            return result;
        }
        public static Point[] GetTouches(MotionEvent current, Android.Views.View view, int[] startLocation)
        {
            //System.Diagnostics.Debug.WriteLine("c0=["+current.GetX()+","+current.GetY()+"]");

            int[] viewLocation = { 0, 0 };
            try
            {
                view?.GetLocationInWindow(viewLocation);
            }
            catch (System.Exception) { return(new Point[] { }); }
            var pointerCoords = new MotionEvent.PointerCoords();
            int pointerCount  = current.PointerCount;
            var array         = new Point[pointerCount];

            for (int i = 0; i < pointerCount; i++)
            {
                current.GetPointerCoords(i, pointerCoords);
                array[i] = DIP.ToPoint((double)(pointerCoords.X + viewLocation[0] - startLocation[0]), (double)(pointerCoords.Y + viewLocation[1] - startLocation[1]));
                //System.Diagnostics.Debug.WriteLine ("i=["+i+"] pc=["+pointerCoords.X+", "+pointerCoords.Y+"] a=["+array[i]+"]");
            }

            return(array);
        }
        /// <summary>
        /// Gets the X, Y, Width, and Height of the fret which is represented on the screen by a view.
        /// </summary>
        /// <param name="fretNum">The number of the requested fret.</param>
        /// <returns>Returns the metrics of the requested fret.</returns>
        private FretMetrics GetFretMetrics(GuitarFret fretNum)
        {
            //Initialize a dummy fret.
            View fret = new View(_currentActivity);

            //Get the correct fret number.
            /*if (_currentActivity.Title == "TutorActivity")

            else if (_currentActivity.Title == "PlayerActivity")

            else if (_currentActivity.Title == "RecorderActivity")*/

            switch (fretNum)
            {
                case GuitarFret.OpenString:
                        fret = _currentActivity.FindViewById(Resource.Id.openString);
                    break;
                case GuitarFret.Fret1:
                        fret = _currentActivity.FindViewById(Resource.Id.fret1);
                    break;
                case GuitarFret.Fret2:
                        fret = _currentActivity.FindViewById(Resource.Id.fret2);
                    break;
                case GuitarFret.Fret3:
                        fret = _currentActivity.FindViewById(Resource.Id.fret3);
                    break;
                case GuitarFret.Fret4:
                        fret = _currentActivity.FindViewById(Resource.Id.fret4);
                    break;
                case GuitarFret.Fret5:
                        fret = _currentActivity.FindViewById(Resource.Id.fret5);
                    break;
                case GuitarFret.Fret6:
                        fret = _currentActivity.FindViewById(Resource.Id.fret6);
                    break;
            }

            //Get the X & Y coordinates of the fret on the screen.
            int[] coordinates = new int[2];
            fret.GetLocationInWindow(coordinates);

            //Summerize X, Y, Width, and Height.
            FretMetrics metrics = new FretMetrics(
                (int)fret.GetX(), //coordinates[0],
                (int)((TableRow)fret.Parent).GetY(), //coordinates[1],
                fret.MeasuredWidth,
                fret.MeasuredHeight);

            Log.Info("", fret.Tag.ToString());
            Log.Info(fret.GetX().ToString(), fret.GetY().ToString());
            Log.Info(coordinates[0].ToString(), coordinates[1].ToString());
            Log.Info(fret.Width.ToString(), fret.Height.ToString());
            Log.Info("Left", fret.Left.ToString());
            Log.Info("Right", fret.Right.ToString());
            Log.Info("Top", fret.Top.ToString());
            Log.Info("Bottom", fret.Bottom.ToString());

            return metrics;
        }