/// <summary>
		/// Gets the touched view.
		/// </summary>
		/// <param name="viewGroup">The view group.</param>
		/// <param name="point">The point.</param>
		/// <param name="offset">The offset.</param>
		/// <returns>Tuple&lt;View, PointF&gt;.</returns>
		public static Tuple<View, PointF> GetTouchedView(this ViewGroup viewGroup, PointF point, PointF offset = null)
        {
            offset = offset ?? new PointF();

            for (var n = 0; n < viewGroup.ChildCount; n++)
            {
                var view = viewGroup.GetChildAt(n);

                if (view.IsHit(point))
                {
                    var vg = view as ViewGroup;
                    if (vg != null)
                    {
                        offset = new PointF(offset.X + vg.Left, offset.Y + vg.Top);
                        var p = new PointF(point.X - vg.Left, point.Y - vg.Top);
                        return GetTouchedView(vg, p, offset);
                    }
                    else if (string.IsNullOrWhiteSpace(view.ContentDescription))
                    {
                        return new Tuple<View, PointF>(viewGroup, offset);
                    }

                    return new Tuple<View, PointF>(view, offset);
                }
            }

            return null;
        }
        public override void Draw(Canvas canvas)
        {
            if (_placeholderBounds == null)
            {
                var centerPoint  = new PointF(canvas.Width / 2f, canvas.Height / 2f);
                var width        = _context.DpToPx(_size);
                var sizeInPixels = new SizeF(width, width);
                var x            = centerPoint.X - (sizeInPixels.Width / 2f);
                var y            = centerPoint.Y - (sizeInPixels.Height / 2f);

                _placeholderBounds = new RectF(
                    x,
                    y,
                    x + sizeInPixels.Width,
                    y + sizeInPixels.Height);

                SetAvatarTextValues();
            }

            canvas.DrawCircle(
                canvas.Width / 2f,
                canvas.Height / 2f,
                _placeholderBounds.Width() / 2f,
                _backgroundPaint);

            canvas.DrawText(_avatarText, _textStartXPoint, _textStartYPoint, _textPaint);
        }
        bool ProcessTouchMove(APointF point)
        {
            if (_contentView == null || !TouchInsideContent(point))
            {
                return(false);
            }

            if (!_isSwiping && _swipeThreshold == 0)
            {
                _swipeDirection = SwipeDirectionHelper.GetSwipeDirection(new Point(_initialPoint.X, _initialPoint.Y), new Point(point.X, point.Y));
                RaiseSwipeStarted();
                _isSwiping = true;
            }

            if (!ValidateSwipeDirection())
            {
                return(false);
            }

            _swipeOffset = GetSwipeOffset(_initialPoint, point);
            UpdateSwipeItems();

            if (Math.Abs(_swipeOffset) > double.Epsilon)
            {
                Swipe();
            }
            else
            {
                ResetSwipe();
            }

            RaiseSwipeChanging();

            return(true);
        }
        void ProcessTouchSwipeItems(APointF point)
        {
            var swipeItems = GetSwipeItemsByDirection();

            if (swipeItems == null || _actionView == null)
            {
                return;
            }

            for (int i = 0; i < _actionView.ChildCount; i++)
            {
                var swipeButton = _actionView.GetChildAt(i);

                var swipeItemX      = swipeButton.Left / _density;
                var swipeItemY      = swipeButton.Top / _density;
                var swipeItemHeight = swipeButton.Height / _density;
                var swipeItemWidth  = swipeButton.Width / _density;


                if (TouchInsideContent(swipeItemX, swipeItemY, swipeItemWidth, swipeItemHeight, point.X, point.Y))
                {
                    var swipeItem = swipeItems[i];

                    ExecuteSwipeItem(swipeItem);

                    if (swipeItems.SwipeBehaviorOnInvoked != SwipeBehaviorOnInvoked.RemainOpen)
                    {
                        ResetSwipe();
                    }

                    break;
                }
            }
        }
        bool ProcessTouchUp(APointF point)
        {
            _isTouchDown = false;

            if (!TouchInsideContent(point))
            {
                ProcessTouchSwipeItems(point);
            }

            if (!_isSwiping)
            {
                return(false);
            }

            _isSwiping = false;

            RaiseSwipeEnded();

            if (!ValidateSwipeDirection())
            {
                return(false);
            }

            ValidateSwipeThreshold();

            return(false);
        }
        public override bool OnInterceptTouchEvent(MotionEvent e)
        {
            switch (e.Action)
            {
            case MotionEventActions.Down:
                _downX        = e.RawX;
                _downY        = e.RawY;
                _initialPoint = new APointF(e.GetX() / _density, e.GetY() / _density);
                break;

            case MotionEventActions.Move:
                float x = Math.Abs((_downX - e.GetX()) / _density);
                float y = Math.Abs((_downY - e.GetY()) / _density);

                if (x > SwipeMinimumDelta || y > SwipeMinimumDelta)
                {
                    ProcessSwipingInteractions(e);
                }
                break;

            case MotionEventActions.Cancel:
            case MotionEventActions.Up:
                ProcessSwipingInteractions(e);
                break;
            }

            return(false);
        }
Beispiel #7
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            float x;

            if (e.PointerCount == 1)
            {
                x = e.GetX();

                if (x < _bounds.Left)
                    x = _bounds.Left;
                if (x > _bounds.Right)
                    x = _bounds.Right;

                _sliderPositionRaw = new PointF(x, _bounds.CenterY());
                _isActive = e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Move;

                var scaleX = _bounds.Width() / 2f;

                x = (x - scaleX) * 100f / scaleX;
            }
            else if (e.PointerCount == 2)
            {
                x = (e.GetX(0) + e.GetX(1)) / 2f;

                if (x < _bounds.Left)
                    x = _bounds.Left;
                if (x > _bounds.Right)
                    x = _bounds.Right;

                _sliderPositionRaw = new PointF(x, _bounds.CenterY());
                _isActive = e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Move;

                var scaleX = _bounds.Width() / 2f;

                x = (x - scaleX) * 10f / scaleX;
            }
            else
            {
                _isActive = false;
                return true;
            }

            switch (e.Action)
            {
                case MotionEventActions.Down:
                    OnSliderStart(x);
                    break;
                case MotionEventActions.Up:
                    OnSliderStop();
                    break;
                case MotionEventActions.Move:
                    OnSliderMove(x);
                    break;
            }

            Invalidate();
            return true;
        }
		/// <summary>
		/// Determines whether the specified point is hit.
		/// </summary>
		/// <param name="view">The view.</param>
		/// <param name="point">The point.</param>
		/// <returns><c>true</c> if the specified point is hit; otherwise, <c>false</c>.</returns>
		public static bool IsHit(this Android.Views.View view, PointF point)
        {
            var r = new Rect();
            view.GetHitRect(r);

            var touch = new Rect((int)point.X, (int)point.Y, (int)point.X, (int)point.Y);

            return r.Intersect(touch);
        }
        bool TouchInsideContent(APointF point)
        {
            if (_contentView == null)
            {
                return(false);
            }

            bool touchContent = TouchInsideContent(_contentView.Left + _contentView.TranslationX, _contentView.Top + _contentView.TranslationY, _contentView.Width, _contentView.Height, _context.ToPixels(point.X), _context.ToPixels(point.Y));

            return(touchContent);
        }
Beispiel #10
0
        public PointF TransformPoint(PointF p)
        {
            var px = new ag.PointF[] { p.ToAndroid() };

#if TODO
            this.Control.TransformPoints(px);
#else
            throw new NotImplementedException();
#endif


            return(px[0].ToEto());
        }
Beispiel #11
0
        internal static ag.PointF[] ToAndroid(this PointF[] points)
        {
            var result =
                new ag.PointF[points.Length];

            for (var i = 0;
                 i < points.Length;
                 ++i)
            {
                var p = points[i];
                result[i] =
                    new ag.PointF(p.X, p.Y);
            }

            return(result);
        }
        bool ProcessTouchDown(APointF point)
        {
            if (_isSwiping || _isTouchDown || _contentView == null)
            {
                return(false);
            }

            if (TouchInsideContent(point))
            {
                ResetSwipe();
            }

            _initialPoint = point;
            _isTouchDown  = true;

            return(true);
        }
        float GetSwipeOffset(APointF initialPoint, APointF endPoint)
        {
            float swipeOffset = 0;

            switch (_swipeDirection)
            {
            case SwipeDirection.Left:
            case SwipeDirection.Right:
                swipeOffset = endPoint.X - initialPoint.X;
                break;

            case SwipeDirection.Up:
            case SwipeDirection.Down:
                swipeOffset = endPoint.Y - initialPoint.Y;
                break;
            }

            return(swipeOffset);
        }
        bool HandleTouchInteractions(GestureStatus status, APointF point)
        {
            switch (status)
            {
            case GestureStatus.Started:
                return(!ProcessTouchDown(point));

            case GestureStatus.Running:
                return(!ProcessTouchMove(point));

            case GestureStatus.Completed:
                ProcessTouchUp(point);
                break;
            }

            _isTouchDown = false;

            return(true);
        }
Beispiel #15
0
 public static double LineToCursorDistance(Point cursor, Point p1, Point p2)
 {
     PointF dichtbij;
     float dx = p2.X - p1.X;
     float dy = p2.Y - p1.Y;
     //als de lijn een punt is
     if ((dx == 0) && (dy == 0))
     {
         dichtbij = new PointF (p1.X, p1.Y);
         dx = cursor.X - dichtbij.X;
         dy = cursor.Y - dichtbij.Y;
         return Math.Sqrt(dx * dx + dy * dy);
     }
     float t = ((cursor.X - p1.X) * dx + (cursor.Y - p1.Y) * dy)
         / (dx * dx + dy * dy);
     if (t < 0)
     {
         dichtbij = new PointF (p1.X, p1.Y);
         dx = cursor.X - dichtbij.X;
         dy = cursor.Y - dichtbij.Y;
     }
     else if (t > 1)
     {
         dichtbij = new PointF (p2.X, p2.Y);
         dx = cursor.X - dichtbij.X;
         dy = cursor.Y - dichtbij.Y;
     }
     else
     {
         dichtbij = new PointF(p1.X + t * dx, p1.Y + t * dy);
         dx = cursor.X - dichtbij.X;
         dy = cursor.Y - dichtbij.Y;
     }
     double a = Math.Sqrt(dx * dx + dy * dy);
     return a;
 }
Beispiel #16
0
        /// <summary>
        /// Method to update our sliders
        /// </summary>
        /// <param name="events"></param>
        public void update(MotionEvent events)
        {
            switch (events.Action & events.ActionMasked)
            {
                case MotionEventActions.Down:
                    //save the ID of the active pointer
                    mActivePointerId = events.PointerCount - 1;

                    //remember where we started
                    mLastTouchY = events.GetY(mActivePointerId);
                    break;

                case MotionEventActions.Move:
                    //only get the vertical movement
                    float y = events.GetY(mActivePointerId);

                    //set touchingpoint
                    _touchingPoint.Y = (int)y;

                    //remember this touch point for the next move event
                    mLastTouchY = y;

                    //invalidate to request a redraw
                    Invalidate();
                    break;

                case MotionEventActions.Up:
                    //reset our touching point on release
                    _touchingPoint = new PointF(INIT_X, INIT_Y);
                    mLastTouchY = 0;
                    release = true;
                    break;
            }//end switch

            //set the touching points to min/max when they go out of bounds
            if (_touchingPoint.Y < 13)
                _touchingPoint.Y = 13;

            if (_touchingPoint.Y > 189)
                _touchingPoint.Y = 189;

            //determine the percentage of power forward/backward
            //-83 < 0 > 83
            _power = Convert.ToInt32((_touchingPoint.Y - 13) - 88);

            //make sure we can return a power value for the engine between 100 and - 100
            //100 being max power forwards, -100 max power reverse.
            if (_power < -1)
            {
                _power = Convert.ToInt32((Math.Abs(_power / 88)) * 100);
            }//end if
            else if (_power > 1)
            {
                _power = Convert.ToInt32((_power / 88) * 100);
                _power *= -1;
            }//end else if
            else
                _power = 0;

            if (_power > 100)
                _power = 100;

            if (_power < -100)
                _power = -100;

            //set the power value in our singleton class so we can send it to CARMEN
            //Make sure we dont update too often, so we dont lock the thread
            if (DateTime.Now - LastUpdate > interval)
            {
                LastUpdate = DateTime.Now;
                if (this.Id == Resource.Id.sliderControls0)
                    Send_Singleton.Instance.left = (int)_power;
                else if (this.Id == Resource.Id.sliderControls1)
                    Send_Singleton.Instance.right = (int)_power;
            }//end if
        }
Beispiel #17
0
		/// <summary>
		/// Updates the current state with the given event.
		/// </summary>
		/// <param name="curr">The current event.</param>
		protected override void UpdateStateByEvent (MotionEvent curr)
		{
			base.UpdateStateByEvent (curr);

			MotionEvent prev = _previousEvent;

			// focus internal
			_currFocusInternal = DetermineFocalPoint (curr);
			_prevFocusInternal = DetermineFocalPoint (prev);

			// focus external
			// - preven skipping of focus delta when a finger is added or removed.
			bool skipNextMoveEvent = prev.PointerCount != curr.PointerCount;
			_focusDeltaExternal = skipNextMoveEvent ? FocusDeltaZero : new PointF (_currFocusInternal.X - _prevFocusInternal.X,
			                                                                      _currFocusInternal.Y - _prevFocusInternal.Y);

			// - don't directly use _focusInternal (or skipping will occur). Add
			// 		unskipped delta values to _focusInternal instead.
			_focusExternal.X += _focusDeltaExternal.X;
			_focusExternal.Y += _focusDeltaExternal.Y;
        }
        bool ProcessSwipingInteractions(MotionEvent e)
        {
            bool?handled = true;
            var  point   = new APointF(e.GetX() / _density, e.GetY() / _density);

            switch (e.Action)
            {
            case MotionEventActions.Down:
                _downX = e.RawX;
                _downY = e.RawY;

                handled = HandleTouchInteractions(GestureStatus.Started, point);

                if (handled == true)
                {
                    Parent.RequestDisallowInterceptTouchEvent(true);
                }

                break;

            case MotionEventActions.Up:
                handled = HandleTouchInteractions(GestureStatus.Completed, point);

                if (Parent == null)
                {
                    break;
                }

                Parent.RequestDisallowInterceptTouchEvent(false);
                break;

            case MotionEventActions.Move:
                handled = HandleTouchInteractions(GestureStatus.Running, point);

                if (handled == true || Parent == null)
                {
                    break;
                }

                Parent.RequestDisallowInterceptTouchEvent(true);
                break;

            case MotionEventActions.Cancel:
                handled = HandleTouchInteractions(GestureStatus.Canceled, point);

                if (Parent == null)
                {
                    break;
                }

                Parent.RequestDisallowInterceptTouchEvent(false);
                break;
            }

            if (handled.HasValue)
            {
                return(!handled.Value);
            }

            return(false);
        }
		public override bool OnInterceptTouchEvent(MotionEvent ev)
		{
			if (_mTouchInterceptionListener == null)
			{
				return false;
			}

			// In here, we must initialize touch state variables
			// and ask if we should intercept this event.
			// Whether we should intercept or not is kept for the later event handling.
			switch (ev.ActionMasked)
			{
				case MotionEventActions.Down:
					_mInitialPoint = new PointF(ev.GetX(), ev.GetY());
					_mPendingDownMotionEvent = MotionEvent.ObtainNoHistory(ev);
					_mDownMotionEventPended = true;
					_mIntercepting = _mTouchInterceptionListener.ShouldInterceptTouchEvent(ev, false, 0, 0);
					_mBeganFromDownMotionEvent = _mIntercepting;
					_mChildrenEventsCanceled = false;
					return _mIntercepting;
				case MotionEventActions.Move:
					// ACTION_MOVE will be passed suddenly, so initialize to avoid exception.
					if (_mInitialPoint == null)
					{
						_mInitialPoint = new PointF(ev.GetX(), ev.GetY());
					}

					// diffX and diffY are the origin of the motion, and should be difference
					// from the position of the ACTION_DOWN event occurred.
					float diffX = ev.GetX() - _mInitialPoint.X;
					float diffY = ev.GetY() - _mInitialPoint.Y;
					_mIntercepting = _mTouchInterceptionListener.ShouldInterceptTouchEvent(ev, true, diffX, diffY);
					return _mIntercepting;
			}
			return false;
		}
		void UpdatePathArrow()
		{
			if (_pathArrow == null)
				_pathArrow = new global::Android.Graphics.Path ();
			else
				_pathArrow.Reset ();

			// Create arrow
			// We have a direction, so draw an arrow
			var direction = 180.0 - ((DirectionArrow)Element).Direction;
			if (direction < 0)
				direction += 360.0;
			direction = direction % 360.0;

			double rad1 = direction / 180.0 * Math.PI;
			double rad2 = (direction + 180.0 + 30.0) / 180.0 * Math.PI;
			double rad3 = (direction + 180.0 - 30.0) / 180.0 * Math.PI; 
			double rad4 = (direction + 180.0) / 180.0 * Math.PI; 

			PointF p1 = new PointF ((float)(_centerX + _size * Math.Sin (rad1)), (float)(_centerY + _size * Math.Cos (rad1)));
			PointF p2 = new PointF ((float)(_centerX + _size * Math.Sin (rad2)), (float)(_centerY + _size * Math.Cos (rad2)));
			PointF p3 = new PointF ((float)(_centerX + _size * Math.Sin (rad3)), (float)(_centerY + _size * Math.Cos (rad3)));
			PointF p4 = new PointF ((float)(_centerX + _sizeSmall * Math.Sin (rad4)), (float)(_centerY + _sizeSmall * Math.Cos (rad4)));

			_pathArrow.MoveTo (p1.X, p1.Y);
			_pathArrow.LineTo (p2.X, p2.Y);
			_pathArrow.LineTo (p4.X, p4.Y);
			_pathArrow.LineTo (p3.X, p3.Y);
			_pathArrow.LineTo (p1.X, p1.Y);
		}
Beispiel #21
0
 //public float[] T = new float[2];
 public Tuple2fT()
 {
     s = new PointF(0.0f, 0.0f);
 }
        protected override void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }

            if (disposing)
            {
                if (Element != null)
                {
                    Element.CloseRequested -= OnCloseRequested;
                }

                if (_detector != null)
                {
                    _detector.Dispose();
                    _detector = null;
                }

                if (_scrollParent != null)
                {
                    if (_scrollParent is ScrollView scrollView)
                    {
                        scrollView.Scrolled -= OnParentScrolled;
                    }

                    if (_scrollParent is ListView listView)
                    {
                        listView.Scrolled -= OnParentScrolled;
                    }

                    if (_scrollParent is Xamarin.Forms.CollectionView collectionView)
                    {
                        collectionView.Scrolled -= OnParentScrolled;
                    }
                }

                if (_contentView != null)
                {
                    _contentView.RemoveFromParent();
                    _contentView.Dispose();
                    _contentView = null;
                }

                if (_actionView != null)
                {
                    _actionView.RemoveFromParent();
                    _actionView.Dispose();
                    _actionView = null;
                }

                if (_initialPoint != null)
                {
                    _initialPoint.Dispose();
                    _initialPoint = null;
                }
            }

            _isDisposed = true;

            base.Dispose(disposing);
        }
		public override void DrawMarker (PointF p0, Canvas p1)
		{
			float density = context.Resources.DisplayMetrics.Density / 1.5f;
			Bitmap bitmap = BitmapFactory.DecodeResource (context.Resources, Resource.Drawable.pin);
			p1.DrawBitmap(bitmap,(float)p0.X-(12*density),(float)p0.Y-(35*density),new Paint());
		}
Beispiel #24
0
        void MoveCropView( PointF delta )
        {
            // update the crop view by how much it should be moved
            float xPos = CropView.GetX( ) + delta.X;
            float yPos = CropView.GetY( ) + delta.Y;

            // clamp to valid bounds
            xPos = Math.Max( CropViewMinPos.X, Math.Min( xPos, CropViewMaxPos.X ) );
            yPos = Math.Max( CropViewMinPos.Y, Math.Min( yPos, CropViewMaxPos.Y ) );

            CropView.SetX( xPos );
            CropView.SetY( yPos );

            MaskLayer.Position = new PointF( CropView.GetX( ), CropView.GetY( ) );
        }
Beispiel #25
0
        void SetMode( CropMode mode )
        {
            if( mode == Mode )
            {
                throw new Exception( string.Format( "Crop Mode {0} requested, but already in that mode.", mode ) );
            }

            switch( mode )
            {
                case CropMode.Editing:
                {
                    // If we're entering edit mode for the first time
                    if ( Mode == CropMode.None )
                    {
                        // Animate in the mask
                        SimpleAnimator_Float floatAnimator = new SimpleAnimator_Float( MaskLayer.Opacity, MaskFadeAmount, MaskFadeTime,
                            delegate( float percent, object value )
                            {
                                Rock.Mobile.Threading.Util.PerformOnUIThread( delegate
                                    {
                                        MaskLayer.Opacity = (float)value;
                                    } );
                            },
                            null );

                        floatAnimator.Start( );

                        // turn on our cropper
                        CropView.Visibility = ViewStates.Visible;

                        // and set the source image to the scaled source.
                        ImageView.SetImageBitmap( ScaledSourceImage );
                    }
                    // else we're coming FROM Preview Mode, so we need to animate
                    else
                    {
                        Animating = true;

                        // setup the dimension changes
                        System.Drawing.SizeF startSize = new System.Drawing.SizeF( ImageView.Width, ImageView.Height );
                        System.Drawing.SizeF endSize = new System.Drawing.SizeF( CropView.Width, CropView.Height );

                        PointF startPos = new PointF( ImageView.GetX( ), ImageView.GetY( ) );
                        PointF endPos = new PointF( CropView.GetX( ), CropView.GetY( ) );

                        // now animate the cropped image up to its full size
                        AnimateImageView( ImageView, startPos, endPos, startSize, endSize, ImageAnimationTime,
                            delegate
                            {
                                ImageView.SetImageBitmap( null );

                                // release any cropped image we had.
                                if ( CroppedImage != null )
                                {
                                    CroppedImage.Dispose( );
                                    CroppedImage = null;
                                }

                                // release the scaled version if we had it
                                if ( ScaledCroppedImage != null )
                                {
                                    ScaledCroppedImage.Dispose( );
                                    ScaledCroppedImage = null;
                                }

                                ImageView.SetImageBitmap( ScaledSourceImage );
                                ImageView.LayoutParameters.Width = ScaledSourceImage.Width;
                                ImageView.LayoutParameters.Height = ScaledSourceImage.Height;

                                // center the image
                                ImageView.SetX( (ScreenSize.Width - ImageView.LayoutParameters.Width ) / 2 );
                                ImageView.SetY( (ScreenSize.Height - ImageView.LayoutParameters.Height ) / 2 );

                                MaskLayer.Visibility = ViewStates.Visible;
                                CropView.Visibility = ViewStates.Visible;

                                SimpleAnimator_Float floatAnimator = new SimpleAnimator_Float( MaskLayer.Opacity, MaskFadeAmount, MaskFadeTime,
                                    delegate( float percent, object value )
                                    {
                                        Rock.Mobile.Threading.Util.PerformOnUIThread( delegate
                                            {
                                                MaskLayer.Opacity = (float)value;
                                                CropView.Alpha = percent;
                                            } );
                                    },
                                    // FINISHED MASK FADE-OUT
                                    delegate
                                    {
                                        Rock.Mobile.Threading.Util.PerformOnUIThread( delegate
                                            {
                                                Animating = false;
                                            });
                                    });
                                floatAnimator.Start( );
                            } );
                    }

                    break;
                }

                case CropMode.Previewing:
                {
                    // don't allow a state change while we're animating
                    Animating = true;

                    SimpleAnimator_Float floatAnimator = new SimpleAnimator_Float( MaskLayer.Opacity, 1.00f, MaskFadeTime,
                        delegate( float percent, object value )
                        {
                            Rock.Mobile.Threading.Util.PerformOnUIThread( delegate
                                {
                                    MaskLayer.Opacity = (float)value;
                                    CropView.Alpha = 1.0f - percent;
                                } );
                        },
                        // FINISHED MASK FADE-IN
                        delegate
                        {
                            Rock.Mobile.Threading.Util.PerformOnUIThread( delegate
                                {
                                    // hide the mask and cropper
                                    MaskLayer.Visibility = ViewStates.Gone;
                                    CropView.Visibility = ViewStates.Gone;

                                    // create the cropped image
                                    CroppedImage = CropImage( SourceImage, new System.Drawing.RectangleF( CropView.GetX( ) - CropViewMinPos.X,
                                        CropView.GetY( ) - CropViewMinPos.Y,
                                        CropView.LayoutParameters.Width,
                                        CropView.LayoutParameters.Height ) );

                                    // create a scaled version of the cropped image
                                    float scaledWidth = (float)CroppedImage.Width * (1.0f / ScreenToImageScalar);
                                    float scaledHeight = (float)CroppedImage.Height * (1.0f / ScreenToImageScalar);
                                    ScaledCroppedImage = Bitmap.CreateScaledBitmap( CroppedImage, (int)scaledWidth, (int)scaledHeight, false );

                                    // set the scaled cropped image
                                    ImageView.SetImageBitmap( null );
                                    ImageView.SetImageBitmap( ScaledCroppedImage );

                                    // start the scaled cropped image scaled down further to match its size within the full image.
                                    ImageView.SetX( CropView.GetX( ) );
                                    ImageView.SetY( CropView.GetY( ) );
                                    ImageView.LayoutParameters.Width = CropView.Width;
                                    ImageView.LayoutParameters.Height = CropView.Height;

                                    // setup the dimension changes
                                    System.Drawing.SizeF startSize = new System.Drawing.SizeF( ScaledCroppedImage.Width, ScaledCroppedImage.Height );

                                    System.Drawing.SizeF endSize;
                                    if( ScreenSize.Width < ScreenSize.Height )
                                    {
                                        endSize = new System.Drawing.SizeF( ScreenSize.Width, (float)System.Math.Ceiling( ScreenSize.Width * ( startSize.Width / startSize.Height ) ) );
                                    }
                                    else
                                    {
                                        endSize = new System.Drawing.SizeF( (float)System.Math.Ceiling( ScreenSize.Height * ( startSize.Height / startSize.Width ) ), ScreenSize.Height );
                                    }

                                    PointF startPos = new PointF( CropView.GetX( ), CropView.GetY( ) );
                                    PointF endPos = new PointF( (ScreenSize.Width - endSize.Width) / 2, (ScreenSize.Height - endSize.Height) / 2 );

                                    // now animate the cropped image up to its full size
                                    AnimateImageView( ImageView, startPos, endPos, startSize, endSize, ImageAnimationTime,
                                        delegate
                                        {
                                            Animating = false;
                                        } );
                                } );
                        } );

                    floatAnimator.Start( );
                    break;
                }
            }

            Mode = mode;
        }
Beispiel #26
0
        void AnimateImageView( View imageView, PointF startPos, PointF endPos, System.Drawing.SizeF startSize, System.Drawing.SizeF endSize, float duration, SimpleAnimator.AnimationComplete completeDelegate )
        {
            // calculate the deltas once before we start
            float xDelta = endPos.X - startPos.X;
            float yDelta = endPos.Y - startPos.Y;

            float deltaWidth = endSize.Width - startSize.Width;
            float deltaHeight = endSize.Height - startSize.Height;

            // create an animator
            SimpleAnimator_Float imageAnimator = new SimpleAnimator_Float( 0.00f, 1.00f, duration,
                delegate( float percent, object value )
                {
                    Rock.Mobile.Threading.Util.PerformOnUIThread( delegate
                        {
                            // each update, interpolate the deltas and apply
                            imageView.SetX( startPos.X + ( xDelta * percent ) );
                            imageView.SetY( startPos.Y + ( yDelta * percent ) );

                            imageView.LayoutParameters.Width = (int)( startSize.Width + ( deltaWidth * percent ) );
                            imageView.LayoutParameters.Height = (int)( startSize.Height + ( deltaHeight * percent ) );

                            // force the image to re-evaluate its size
                            imageView.RequestLayout( );
                        } );
                },
                //ANIMATION COMPLETE
                delegate
                {
                    if ( completeDelegate != null )
                    {
                        Rock.Mobile.Threading.Util.PerformOnUIThread( delegate
                            {
                                completeDelegate( );
                            } );
                    }
                } );

            imageAnimator.Start( );
        }
Beispiel #27
0
        public bool OnTouch( View v, MotionEvent e )
        {
            if ( Mode == CropMode.Editing )
            {
                switch ( e.Action )
                {
                    case MotionEventActions.Down:
                    {
                        // stamp our position so we can update the crop view
                        LastTapPos = new PointF( e.GetX( ), e.GetY( ) );
                        break;
                    }

                    case MotionEventActions.Move:
                    {
                        // adjust by the amount moved
                        PointF delta = new PointF( e.GetX( ) - LastTapPos.X, e.GetY( ) - LastTapPos.Y );

                        MoveCropView( delta );

                        LastTapPos = new PointF( e.GetX( ), e.GetY( ) );
                        break;
                    }

                    case MotionEventActions.Up:
                    {

                        break;
                    }
                }
            }

            return true;
        }
Beispiel #28
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (container == null)
            {
                // Currently in a layout without a container, so no reason to create our view.
                return null;
            }

            Point displaySize = new Point( );
            Activity.WindowManager.DefaultDisplay.GetSize( displaySize );
            ScreenSize = new System.Drawing.SizeF( displaySize.X, displaySize.Y );

            // scale the image to match the view's width
            ScreenToImageScalar = (float) SourceImage.Width / (float) ScreenSize.Width;

            // get the scaled dimensions, maintaining aspect ratio
            float scaledWidth = (float)SourceImage.Width * (1.0f / ScreenToImageScalar);
            float scaledHeight = (float)SourceImage.Height * (1.0f / ScreenToImageScalar);

            // now, if the scaled height is too large, re-calc with Height is the dominant,
            // so we guarantee a fit within the view.
            if( scaledHeight > ScreenSize.Height )
            {
                ScreenToImageScalar = (float) SourceImage.Height / (float) ScreenSize.Height;

                scaledWidth = (float)SourceImage.Width * (1.0f / ScreenToImageScalar);
                scaledHeight = (float)SourceImage.Height * (1.0f / ScreenToImageScalar);
            }

            ScaledSourceImage = Bitmap.CreateScaledBitmap( SourceImage, (int)scaledWidth, (int)scaledHeight, false );

            // setup our layout for touch input
            RelativeLayout view = inflater.Inflate( Resource.Layout.ImageCrop, container, false ) as RelativeLayout;
            view.SetOnTouchListener( this );

            // create the view that will display the image to crop
            ImageView = new AspectScaledImageView( Rock.Mobile.PlatformSpecific.Android.Core.Context );
            ImageView.LayoutParameters = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent );
            ImageView.LayoutParameters.Width = ScaledSourceImage.Width;
            ImageView.LayoutParameters.Height = ScaledSourceImage.Height;

            // center the image
            ImageView.SetX( (ScreenSize.Width - ImageView.LayoutParameters.Width ) / 2 );
            ImageView.SetY( (ScreenSize.Height - ImageView.LayoutParameters.Height ) / 2 );

            view.AddView( ImageView );

            // create the draggable crop view that will let the user pic which part of the image to use.
            CropView = new View( Rock.Mobile.PlatformSpecific.Android.Core.Context );
            CropView.LayoutParameters = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent );

            // the crop view's dimensions should be based on what the user wanted to crop to. We'll do width, and then height as a scale of width.
            CropView.LayoutParameters.Width = (int) (scaledWidth < scaledHeight ? scaledWidth : scaledHeight);
            CropView.LayoutParameters.Height = (int) ((float) CropView.LayoutParameters.Width * CropAspectRatio);

            // the crop view should be a nice outlined rounded rect
            float _Radius = 3.0f;
            RoundRectShape rectShape = new RoundRectShape( new float[] { _Radius,
                                                                         _Radius,
                                                                         _Radius,
                                                                         _Radius,
                                                                         _Radius,
                                                                         _Radius,
                                                                         _Radius,
                                                                         _Radius }, null, null );
            // configure its paint
            ShapeDrawable border = new ShapeDrawable( rectShape );
            border.Paint.SetStyle( Paint.Style.Stroke );
            border.Paint.StrokeWidth = 8;
            border.Paint.Color = Color.WhiteSmoke;
            CropView.Background = border;

            // set our clamp values
            CropViewMinPos = new PointF( (ScreenSize.Width - scaledWidth) / 2,
                                         (ScreenSize.Height - scaledHeight) / 2 );

            CropViewMaxPos = new PointF( CropViewMinPos.X + (scaledWidth - CropView.LayoutParameters.Width),
                                         CropViewMinPos.Y + (scaledHeight - CropView.LayoutParameters.Height) );

            view.AddView( CropView );

            // create a mask layer that will block out the parts of the image that will be cropped
            MaskLayer = new Rock.Mobile.PlatformSpecific.Android.Graphics.MaskLayer( (int)ScreenSize.Width, (int)ScreenSize.Height, CropView.LayoutParameters.Width, CropView.LayoutParameters.Height, Rock.Mobile.PlatformSpecific.Android.Core.Context );
            MaskLayer.LayoutParameters = new RelativeLayout.LayoutParams( (int)ScreenSize.Width, (int)ScreenSize.Height );
            MaskLayer.Opacity = 0.00f;
            view.AddView( MaskLayer );

            // Now setup our bottom area with cancel, crop, and text to explain
            RelativeLayout bottomBarLayout = new RelativeLayout( Rock.Mobile.PlatformSpecific.Android.Core.Context );
            bottomBarLayout.LayoutParameters = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent );
            ((RelativeLayout.LayoutParams)bottomBarLayout.LayoutParameters).AddRule( LayoutRules.AlignParentBottom );

            // set the nav subBar color (including opacity)
            Color navColor = Rock.Mobile.UI.Util.GetUIColor( PrivateSubNavToolbarConfig.BackgroundColor );
            navColor.A = (Byte) ( (float) navColor.A * PrivateSubNavToolbarConfig.Opacity );
            bottomBarLayout.SetBackgroundColor( navColor );

            bottomBarLayout.LayoutParameters.Height = 150;
            view.AddView( bottomBarLayout );

            // setup the cancel button (which will undo cropping or take you back to the picture taker)
            CancelButton = new Button( Rock.Mobile.PlatformSpecific.Android.Core.Context );
            CancelButton.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent );
            CancelButton.Gravity = GravityFlags.Left;
            ((RelativeLayout.LayoutParams)CancelButton.LayoutParameters).AddRule( LayoutRules.AlignParentLeft );

            // set the crop button's font
            Android.Graphics.Typeface fontFace = Rock.Mobile.PlatformSpecific.Android.Graphics.FontManager.Instance.GetFont( PrivateControlStylingConfig.Icon_Font_Secondary );
            CancelButton.SetTypeface( fontFace, Android.Graphics.TypefaceStyle.Normal );
            CancelButton.SetTextSize( Android.Util.ComplexUnitType.Dip, PrivateImageCropConfig.CropCancelButton_Size );
            CancelButton.Text = PrivateImageCropConfig.CropCancelButton_Text;

            CancelButton.Click += (object sender, EventArgs e) =>
                {
                    // don't allow button presses while animations are going on
                    if( Animating == false )
                    {
                        // if they hit cancel while previewing, go back to editing
                        if( Mode == CropMode.Previewing )
                        {
                            SetMode( CropMode.Editing );
                        }
                        else
                        {
                            // they pressed it while they're in editing mode, so go back to camera mode
                            Activity.OnBackPressed( );
                        }
                    }
                };

            bottomBarLayout.AddView( CancelButton );

            // setup the Confirm button, which will use a font to display its graphic
            ConfirmButton = new Button( Rock.Mobile.PlatformSpecific.Android.Core.Context );
            ConfirmButton.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent );
            ConfirmButton.Gravity = GravityFlags.Right;
            ((RelativeLayout.LayoutParams)ConfirmButton.LayoutParameters).AddRule( LayoutRules.AlignParentRight );

            // set the crop button's font
            fontFace = Rock.Mobile.PlatformSpecific.Android.Graphics.FontManager.Instance.GetFont( PrivateControlStylingConfig.Icon_Font_Secondary );
            ConfirmButton.SetTypeface( fontFace, Android.Graphics.TypefaceStyle.Normal );
            ConfirmButton.SetTextSize( Android.Util.ComplexUnitType.Dip, PrivateImageCropConfig.CropOkButton_Size );
            ConfirmButton.Text = PrivateImageCropConfig.CropOkButton_Text;

            // when clicked, we should crop the image.
            ConfirmButton.Click += (object sender, EventArgs e) =>
                {
                    // don't allow button presses while animations are going on
                    if( Animating == false )
                    {
                        // if they pressed confirm while editing, go to preview
                        if( Mode == CropMode.Editing )
                        {
                            SetMode( CropMode.Previewing );
                        }
                        else
                        {
                            // notify the caller
                            SpringboardParent.ModalFragmentDone( CroppedImage );
                        }
                    }
                };

            bottomBarLayout.AddView( ConfirmButton );

            // start in editing mode (obviously)
            SetMode( CropMode.Editing );

            // start the cropper centered
            MoveCropView( new PointF( (ScreenSize.Width - CropView.LayoutParameters.Width) / 2, (ScreenSize.Height - CropView.LayoutParameters.Height) / 2 ) );

            MaskLayer.Position = new PointF( CropView.GetX( ), CropView.GetY( ) );

            return view;
        }
		/// <summary>
		/// Gets the equilateral triangle.
		/// </summary>
		/// <param name="width">The width.</param>
		/// <param name="height">The height.</param>
		/// <returns>Path.</returns>
		private Path GetEquilateralTriangle(int width, int height)
		{
			PointF p1, p2, p3;
			if(_arrowDirection == ArrowDirection.LEFT)
			{
				p1 = new PointF(0, (height) / 2);
				p2 = new PointF(width, 0);
				p3 = new PointF(width, height);
			} else
			{
				p1 = new PointF(width, height / 2);
				p2 = new PointF(0, 0);
				p3 = new PointF(0, height);
			}
			Path path = new Path();
			path.MoveTo(p1.X, p1.Y);
			path.LineTo(p2.X, p2.Y);
			path.LineTo(p3.X, p3.Y);
			return path;
		}
		private void ComputeDataPoints()
		{
			double minValue = (double) datapoints.Min ();
			double maxValue = (double) datapoints.Max ();

			var columnWidth = (float) Width / datapoints.Length;
			var columnCenter = (float) columnWidth / 2;

			_chartPoints = new PointF[datapoints.Length];

			for (var i = 0; i < datapoints.Length; i++) {
				var x = columnCenter;
				var y = Scale (datapoints [i], minValue, maxValue, 1, chartPixelHeight);
				_chartPoints [i] = new PointF (x, y);
				columnCenter += columnWidth;
			}
		}
Beispiel #31
0
        void MapControl_Touch(object sender, TouchEventArgs args)
        {
            if (_map.Lock) return;

            var x = (int)args.Event.RawX;
            var y = (int)args.Event.RawY;

            switch (args.Event.Action)
            {
            case MotionEventActions.Down:
                _previousMap = null;
                _mode = Drag;
                break;
            case MotionEventActions.Up:
                _previousMap = null;
                _mode = None;
                _map.ViewChanged (true);
                break;
            case MotionEventActions.Pointer2Down:
                _previousMap = null;
                _oldDist = Spacing(args.Event);
                MidPoint(_currentMid, args.Event);
                _previousMid = _currentMid;
                _mode = Zoom;
                break;
            case MotionEventActions.Pointer2Up:
                _previousMap = null;
                _previousMid = null;
                _mode = Drag;
                _map.ViewChanged (true);
                break;
            case MotionEventActions.Move:
                switch (_mode)
                {
                case Drag:
                    _currentMap = new PointF (x, y);
                    if (_previousMap != null) {
                        _map.Viewport.Transform (_currentMap.X, _currentMap.Y, _previousMap.X, _previousMap.Y);
                        RefreshGraphics ();
                    }
                    _previousMap = _currentMap;                    
                    break;
                case Zoom:
                    if (args.Event.PointerCount < 2) return;

                    var newDist = Spacing (args.Event);
                    var scale = newDist / _oldDist;

                    _oldDist = Spacing (args.Event);
                    _previousMid = new PointF (_currentMid.X, _currentMid.Y);
                    MidPoint (_currentMid, args.Event);
                    _map.Viewport.Transform(_currentMid.X, _currentMid.Y, _previousMid.X, _previousMid.Y, scale);
                    RefreshGraphics ();
                    break;
                }
                break;
            }
        }
Beispiel #32
0
		public PointF TransformPoint(PointF p)
		{
			var px = new ag.PointF[] { p.ToAndroid() };

#if TODO
			this.Control.TransformPoints(px);
#else
			throw new NotImplementedException();
#endif


			return px[0].ToEto();
		}
Beispiel #33
0
 public static PointF ToEto(this ag.PointF point)
 {
     return(new PointF(point.X, point.Y));
 }
Beispiel #34
0
        //--------------------------------------------------------------
        // STATIC METHODS
        //--------------------------------------------------------------
        public static Bitmap CreateImage(int blockSize, TetrisColor color)
        {
            if(color == TetrisColor.ColorMax)
                return null;

            // Create the image with its canvas to draw in it
            Bitmap image = Bitmap.CreateBitmap(blockSize, blockSize, Bitmap.Config.Argb8888);
            Canvas imageCanvas = new Canvas(image);

            // Calculate the width of the borders with a percentage of the size of the block
            float borderWidth = BorderWidth * blockSize;
            float borderWidth3D = BorderWidth3D * blockSize;

            // Calculate all the colors for the block based on its tetris color
            Color baseColor = adjustColor(Utils.getAndroidColor(color), SvBaseColor);
            Color topColor = adjustColor(baseColor, SvTopColor);
            Color leftColor = adjustColor(baseColor, SvLeftColor);
            Color rightColor = adjustColor(baseColor, SvRightColor);
            Color bottomColor = adjustColor(baseColor, SvBottomColor);
            Color borderColor = adjustColor(baseColor, SvBorderColor);

            // Draw the border
            Paint borderPaint = new Paint {AntiAlias = true, Color = borderColor};
            for(int i = 0 ; i < BorderWidth ; i++)
            {
                imageCanvas.DrawRect(i, blockSize - i, blockSize - i, i, borderPaint);
            }
            borderPaint.Dispose();

            // Define the corners of the big rectangle without the border
            PointF outerRectTopLeft = new PointF(
                borderWidth,
                borderWidth);
            PointF outerRectTopRight = new PointF(
                blockSize - borderWidth,
                borderWidth);
            PointF outerRectBottomRight = new PointF(
                blockSize - borderWidth,
                blockSize - borderWidth);
            PointF outerRectBottomLeft = new PointF(
                borderWidth,
                blockSize - borderWidth);

            // Define the corners of the small rectangle in the middle
            PointF innerRectTopLeft = new PointF(
                borderWidth + borderWidth3D,
                borderWidth + borderWidth3D);
            PointF innerRectTopRight = new PointF(
                blockSize -borderWidth - borderWidth3D,
                borderWidth + borderWidth3D);
            PointF innerRectBottomRight = new PointF(
                blockSize -borderWidth - borderWidth3D,
                blockSize -borderWidth - borderWidth3D);
            PointF innerRectBottomLeft = new PointF(
                borderWidth + borderWidth3D,
                blockSize -borderWidth - borderWidth3D);

            // Draw inner square
            PointF[] innerSquare = new[]
            {
                innerRectTopLeft,
                innerRectTopRight,
                innerRectBottomRight,
                innerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, innerSquare, baseColor);

            // Draw top 3D border
            PointF[] top3dBorder = new[]
            {
                outerRectTopLeft,
                outerRectTopRight,
                innerRectTopRight,
                innerRectTopLeft
            };
            drawPolygonInCanvas(imageCanvas, top3dBorder, topColor);

            // Draw bottom 3D border
            PointF[] bottom3dBorder = new[]
            {
                innerRectBottomLeft,
                innerRectBottomRight,
                outerRectBottomRight,
                outerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, bottom3dBorder, bottomColor);

            // Draw left 3D border
            PointF[] left3dBorder = new[]
            {
                outerRectTopLeft,
                innerRectTopLeft,
                innerRectBottomLeft,
                outerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, left3dBorder, leftColor);

            // Draw right 3D border
            PointF[] right3dBorder = new[]
            {
                innerRectTopRight,
                outerRectTopRight,
                outerRectBottomRight,
                innerRectBottomRight
            };
            drawPolygonInCanvas(imageCanvas, right3dBorder, rightColor);

            imageCanvas.Dispose();

            return image;
        }
Beispiel #35
0
 public void AddLine(float startX, float startY, float endX, float endY)
 {
     this.Control.MoveTo(startX, startY);
     this.Control.LineTo(endX, endY);
     position = new ag.PointF(endX, endY);
 }
Beispiel #36
0
 private static void MidPoint(PointF point, MotionEvent me)
 {
     var x = me.GetX(0) + me.GetX(1);
     var y = me.GetY(0) + me.GetY(1);
     point.Set(x / 2, y / 2);
 }
		public static void MoveTo (this Path path, PointF point) => path.MoveTo (point.X, point.Y);
Beispiel #38
0
        void MapView_Touch(object sender, TouchEventArgs args)
        {
            var x = (int)args.Event.RawX;
            var y = (int)args.Event.RawY;
            switch (args.Event.Action)
            {
                case MotionEventActions.Down:
                    _previousMap = null;
                    _mode = Drag;
                    break;
                case MotionEventActions.Up:
                    _previousMap = null;
                    Invalidate();
                    _mode = None;
                    _map.ViewChanged(true);
                    break;
                case MotionEventActions.Pointer2Down:
                    _previousMap = null;
                    _oldDist = Spacing(args.Event);
                    MidPoint(_currentMid, args.Event);
                    _previousMid = _currentMid;
                    _mode = Zoom;
                    break;
                case MotionEventActions.Pointer2Up:
                    _previousMap = null;
                    _previousMid = null;
                    _mode = Drag;
                    break;
                case MotionEventActions.Move:
                    switch (_mode)
                    {
                        case Drag:
                            _currentMap = new PointF(x, y);
                            if (_previousMap != null)
                            {
                                _map.Viewport.Transform(
                                    _currentMap.X,
                                    _currentMap.Y,
                                    _previousMap.X,
                                    _previousMap.Y);
                                Invalidate();
                            }
                            _previousMap = _currentMap;
                            break;
                        case Zoom:
                            {
                                if (args.Event.PointerCount < 2)
                                    return;

                                var newDist = Spacing(args.Event);
                                var scale = newDist / _oldDist;

                                _oldDist = Spacing(args.Event);
                                _previousMid = new PointF(_currentMid.X, _currentMid.Y);
                                MidPoint(_currentMid, args.Event);
                                _map.Viewport.Center = _map.Viewport.ScreenToWorld(
                                    _currentMid.X,
                                    _currentMid.Y);
                                _map.Viewport.Resolution = _map.Viewport.Resolution / scale;
                                _map.Viewport.Center = _map.Viewport.ScreenToWorld(
                                    (_map.Viewport.Width - _currentMid.X),
                                    (_map.Viewport.Height - _currentMid.Y));
                                _map.Viewport.Transform(
                                    _currentMid.X,
                                    _currentMid.Y,
                                    _previousMid.X,
                                    _previousMid.Y);
                                Invalidate();
                            }
                            break;
                    }
                    break;
            }
        }
		public static void LineTo (this Path path, PointF point) => path.LineTo (point.X, point.Y);
Beispiel #40
0
        private static void drawPolygonInCanvas(Canvas canvas, PointF[] polygon, Color color)
        {
            var path = new Path();
            // Set the first point, that the drawing will start from.
            path.MoveTo(polygon[0].X, polygon[0].Y);
            for (var i = 1; i < polygon.Length; i++)
            {
                // Draw a line from the previous point in the path to the new point.
                path.LineTo(polygon[i].X, polygon[i].Y);
            }

            Paint paint = new Paint {
                AntiAlias = true,
                Color = color
            };
            paint.SetStyle(Paint.Style.Fill);
            canvas.DrawPath(path, paint);

            paint.Dispose();
        }
		public override bool OnTouchEvent(MotionEvent ev)
		{
			if (_mTouchInterceptionListener != null)
			{
				switch (ev.ActionMasked)
				{
					case MotionEventActions.Down:
						if (_mIntercepting)
						{
							_mTouchInterceptionListener.OnDownMotionEvent(ev);
							DuplicateTouchEventForChildren(ev);
							return true;
						}
						break;
					case MotionEventActions.Move:
						// ACTION_MOVE will be passed suddenly, so initialize to avoid exception.
						if (_mInitialPoint == null)
						{
							_mInitialPoint = new PointF(ev.GetX(), ev.GetY());
						}

						// diffX and diffY are the origin of the motion, and should be difference
						// from the position of the ACTION_DOWN event occurred.
						float diffX = ev.GetX() - _mInitialPoint.X;
						float diffY = ev.GetY() - _mInitialPoint.Y;
						_mIntercepting = _mTouchInterceptionListener.ShouldInterceptTouchEvent(ev, true, diffX, diffY);
						if (_mIntercepting)
						{
							// If this layout didn't receive ACTION_DOWN motion event,
							// we should generate ACTION_DOWN event with current position.
							if (!_mBeganFromDownMotionEvent)
							{
								_mBeganFromDownMotionEvent = true;

								MotionEvent event2 = MotionEvent.ObtainNoHistory(_mPendingDownMotionEvent);
								event2.SetLocation(ev.GetX(), ev.GetY());
								_mTouchInterceptionListener.OnDownMotionEvent(event2);

								_mInitialPoint = new PointF(ev.GetX(), ev.GetY());
								diffX = diffY = 0;
							}

							// Children's touches should be canceled
							if (!_mChildrenEventsCanceled)
							{
								_mChildrenEventsCanceled = true;
								DuplicateTouchEventForChildren(ObtainMotionEvent(ev, MotionEventActions.Cancel));
							}

							_mTouchInterceptionListener.OnMoveMotionEvent(ev, diffX, diffY);

							// If next mIntercepting become false,
							// then we should generate fake ACTION_DOWN event.
							// Therefore we set pending flag to true as if this is a down motion event.
							_mDownMotionEventPended = true;

							// Whether or not this event is consumed by the listener,
							// assume it consumed because we declared to intercept the event.
							return true;
						}
						if (_mDownMotionEventPended)
						{
							_mDownMotionEventPended = false;
							MotionEvent event2 = MotionEvent.ObtainNoHistory(_mPendingDownMotionEvent);
							event2.SetLocation(ev.GetX(), ev.GetY());
							DuplicateTouchEventForChildren(ev, event2);
						}
						else
						{
							DuplicateTouchEventForChildren(ev);
						}

						// If next mIntercepting become true,
						// then we should generate fake ACTION_DOWN event.
						// Therefore we set beganFromDownMotionEvent flag to false
						// as if we haven't received a down motion event.
						_mBeganFromDownMotionEvent = false;

						// Reserve children's click cancellation here if they've already canceled
						_mChildrenEventsCanceled = false;
						break;
					case MotionEventActions.Up:
					case MotionEventActions.Cancel:
						_mBeganFromDownMotionEvent = false;
						if (_mIntercepting)
						{
							_mTouchInterceptionListener.OnUpOrCancelMotionEvent(ev);
						}

						// Children's touches should be canceled regardless of
						// whether or not this layout intercepted the consecutive motion events.
						if (!_mChildrenEventsCanceled)
						{
							_mChildrenEventsCanceled = true;
							if (_mDownMotionEventPended)
							{
								_mDownMotionEventPended = false;
								MotionEvent event2 = MotionEvent.ObtainNoHistory(_mPendingDownMotionEvent);
								event2.SetLocation(ev.GetX(), ev.GetY());
								DuplicateTouchEventForChildren(ev, event2);
							}
							else
							{
								DuplicateTouchEventForChildren(ev);
							}
						}
						return true;
				}
			}
			return base.OnTouchEvent(ev);
		}
Beispiel #42
0
 public static XIR.Point RemoteRepresentation(this AG.PointF point)
 => new XIR.Point(point.X, point.Y);
Beispiel #43
0
		/// <summary>
		/// detect faces on a picture and draw a square in each face
		/// </summary>
		private void detectFaces(){
			//first check if picture has been taken
			if(null != cameraBitmap){
				//get width of a picture
				int width = cameraBitmap.Width;
				//get height of a picture
				int height = cameraBitmap.Height;
				//Initialize a facedetector with the picture dimensions and the max number of faces to check
				FaceDetector detector = new FaceDetector(width, height, MainActivity.MAX_FACES);
				//Create an array of faces with the number of max faces to check
				Android.Media.FaceDetector.Face[] faces = new Android.Media.FaceDetector.Face[MainActivity.MAX_FACES];

				//create a main bitmap
				Bitmap bitmap565 = Bitmap.CreateBitmap(width, height, Bitmap.Config.Rgb565);
				//create a dither paint
				Paint ditherPaint = new Paint();
				//create a draw paint
				Paint drawPaint = new Paint();

				//set true dither to dither paint variable
				ditherPaint.Dither = true;
				//set color red for the square
				drawPaint.Color = Color.Red;
				//set stroke to style
				drawPaint.SetStyle(Paint.Style.Stroke);
				//set stroke width
				drawPaint.StrokeWidth = 2;

				//Create a canvas
				Canvas canvas = new Canvas();
				//set bitmap to canvas
				canvas.SetBitmap(bitmap565);
				//draw bitmap to canvas
				canvas.DrawBitmap(cameraBitmap, 0, 0, ditherPaint);

				//get a number of faces detected
				int facesFound = detector.FindFaces(bitmap565, faces);
				//mid face point
				PointF midPoint = new PointF();
				//eye distance variable
				float eyeDistance = 0.0f;
				//confidence variable
				float confidence = 0.0f;
				//print numbre of faces found
				System.Console.WriteLine ("Number of faces found: " + facesFound);

				//check if found at least one face
				if(facesFound > 0)
				{
					//for each face draw a red squeare
					for(int index=0; index<facesFound; ++index){
						// get midpoint of a face
						faces[index].GetMidPoint(midPoint);
						//get eye distance
						eyeDistance = faces[index].EyesDistance();
						//get confidence
						confidence = faces [index].Confidence ();
						//print all parameters
						System.Console.WriteLine ("Confidence: " + confidence + 
							", Eye distance: " + eyeDistance + 
							", Mid Point: (" + midPoint.X + ", " + midPoint.Y + ")");
						//draw a square in the picture
						canvas.DrawRect((int)midPoint.X - eyeDistance , 
							(int)midPoint.Y- eyeDistance , 
							(int)midPoint.X + eyeDistance, 
							(int)midPoint.Y + eyeDistance, drawPaint);
					}
				}

				//get imageview from layout
				ImageView imageView = (ImageView)FindViewById(Resource.Id.image_view);
				//set image with the red squares to imageview
				imageView.SetImageBitmap(bitmap565);
			}
		}
		public static Bitmap Draw(int width, int height, double direction)
		{
			if(width == 0 || height == 0)
					return null;

			int w2 = width / 2;
			int h2 = height / 2;

			Paint light = new Paint(PaintFlags.AntiAlias);
			Paint dark = new Paint(PaintFlags.AntiAlias);
			Paint black = new Paint(PaintFlags.AntiAlias);

			light.Color = new Color(128, 0, 0, 255);
			light.StrokeWidth = 0f;
			light.SetStyle(Paint.Style.FillAndStroke);

			dark.Color = new Color(255, 0, 0, 255);
			dark.StrokeWidth = 0f;
			dark.SetStyle(Paint.Style.FillAndStroke);

			black.Color = new Color(0, 0, 0, 255);
			black.StrokeWidth = 0f;
			black.SetStyle(Paint.Style.Stroke);

			// Values of direction are between 0° and 360°, but for drawing we need -180° to +180°
			direction -= 180;

			double rad1 = direction / 180.0 * Math.PI;
			double rad2 = (direction + 180.0 + 30.0) / 180.0 * Math.PI;
			double rad3 = (direction + 180.0 - 30.0) / 180.0 * Math.PI; 
			double rad4 = (direction + 180.0) / 180.0 * Math.PI; 

			PointF p1 = new PointF((float) (w2 + w2 * Math.Sin (rad1)), (float) (h2 + h2 * Math.Cos (rad1)));
			PointF p2 = new PointF((float) (w2 + w2 * Math.Sin (rad2)), (float) (h2 + h2 * Math.Cos (rad2)));
			PointF p3 = new PointF((float) (w2 + w2 * Math.Sin (rad3)), (float) (h2 + h2 * Math.Cos (rad3)));
			PointF p4 = new PointF((float) (w2 + width / 3 * Math.Sin (rad4)), (float) (h2 + height / 3 * Math.Cos (rad4)));

			Bitmap b = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);

			using(Canvas c = new Canvas(b)) {
				int cx = c.Width / 2 - 1;
				int cy = c.Height / 2 - 1;

				global::Android.Graphics.Path path1 = new global::Android.Graphics.Path ();
				global::Android.Graphics.Path path2 = new global::Android.Graphics.Path ();
				global::Android.Graphics.Path path3 = new global::Android.Graphics.Path ();

				path1.MoveTo (p1.X,p1.Y);
				path1.LineTo (p2.X,p2.Y);
				path1.LineTo (p4.X,p4.Y);
				path1.LineTo (p1.X,p1.Y);

				path2.MoveTo (p1.X,p1.Y);
				path2.LineTo (p3.X,p3.Y);
				path2.LineTo (p4.X,p4.Y);
				path2.LineTo (p1.X,p1.Y);

				path3.MoveTo (p1.X,p1.Y);
				path3.LineTo (p2.X,p2.Y);
				path3.LineTo (p4.X,p4.Y);
				path3.LineTo (p1.X,p1.Y);
				path3.LineTo (p3.X,p3.Y);
				path3.LineTo (p4.X,p4.Y);

				light.Color = new Color (128, 0, 0, 255);
				dark.Color = new Color (255, 0, 0, 255);
				black.Color = new Color (0, 0, 0, 255);

				c.DrawPath (path1, light);
				c.DrawPath (path2, dark);
				c.DrawPath (path3, black);
			}

			return b;
		}
Beispiel #45
0
		internal static ag.PointF[] ToAndroid(this PointF[] points)
		{
			var result =
				new ag.PointF[points.Length];

			for (var i = 0;
				i < points.Length;
				++i)
			{
				var p = points[i];
				result[i] =
					new ag.PointF(p.X, p.Y);
			}

			return result;
		}
Beispiel #46
0
        public override bool OnTouchEvent (MotionEvent e)
        {
            // check correct zoomlevel
            if (rows.Count <= 12) {
                return base.OnTouchEvent (e);
            }

            if (e.Action == MotionEventActions.Down) {
                // check selected row
                selectedRowIndex = GetSelectedBarIndex (Convert.ToInt32 (e.GetX ()), Convert.ToInt32 (e.GetY ()));
                if (selectedRowIndex == -1) {
                    ZoomOutBars ();
                    return base.OnTouchEvent (e);
                }
                tapInitialPos = new PointF (e.GetX (), e.GetY ());
            }

            if (e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Cancel) {
                // set a small threshold to detect drag
                if ( Math.Abs ( tapInitialPos.X - e.GetX ()) > 30 || Math.Abs ( tapInitialPos.Y - e.GetY ()) > 30 ) {
                    ZoomOutBars ();
                    return base.OnTouchEvent (e);
                }
                ZoomInBars (selectedRowIndex);
            }
            return true;
        }