protected override void OnAttached() { // Get the Android View corresponding to the Element that the effect is attached to view = Control == null ? Container : Control; // Get access to the TouchEffect class in the .NET Standard library TouchEffect touchEffect = (TouchEffect)Element.Effects. FirstOrDefault(e => e is TouchEffect); if (touchEffect != null && view != null) { viewDictionary.Add(view, this); formsElement = Element; libTouchEffect = touchEffect; // Save fromPixels function fromPixels = view.Context.FromPixels; // Set event handler on View view.Touch += OnTouch; } }
protected override void OnAttached() { effect = TouchEffect.PickFrom(Element); if (effect == null || effect.IsDisabled) { return; } effect.Element = (VisualElement)Element; if (effect.NativeAnimation) { var nativeControl = Container; if (string.IsNullOrEmpty(nativeControl.Name)) { nativeControl.Name = Guid.NewGuid().ToString(); } if (nativeControl.Resources.ContainsKey(pointerDownAnimationKey)) { pointerDownStoryboard = (Storyboard)nativeControl.Resources[pointerDownAnimationKey]; } else { pointerDownStoryboard = new Storyboard(); var downThemeAnimation = new PointerDownThemeAnimation(); Storyboard.SetTargetName(downThemeAnimation, nativeControl.Name); pointerDownStoryboard.Children.Add(downThemeAnimation); nativeControl.Resources.Add(new KeyValuePair <object, object>(pointerDownAnimationKey, pointerDownStoryboard)); } if (nativeControl.Resources.ContainsKey(pointerUpAnimationKey)) { pointerUpStoryboard = (Storyboard)nativeControl.Resources[pointerUpAnimationKey]; } else { pointerUpStoryboard = new Storyboard(); var upThemeAnimation = new PointerUpThemeAnimation(); Storyboard.SetTargetName(upThemeAnimation, nativeControl.Name); pointerUpStoryboard.Children.Add(upThemeAnimation); nativeControl.Resources.Add(new KeyValuePair <object, object>(pointerUpAnimationKey, pointerUpStoryboard)); } } if (Container != null) { Container.PointerPressed += OnPointerPressed; Container.PointerReleased += OnPointerReleased; Container.PointerCanceled += OnPointerCanceled; Container.PointerExited += OnPointerExited; Container.PointerEntered += OnPointerEntered; Container.PointerCaptureLost += OnPointerCaptureLost; } }
void HandleCollectionViewSelection(TouchEffect sender) { if (!sender.Element.TryFindParentElementWithParentOfType(out var result, out CollectionView? parent)) { return; } var collectionView = parent ?? throw new NullReferenceException(); var item = result?.BindingContext ?? result ?? throw new NullReferenceException(); switch (collectionView.SelectionMode) { case SelectionMode.Single: collectionView.SelectedItem = item; break; case SelectionMode.Multiple: var selectedItems = collectionView.SelectedItems?.ToList() ?? new List <object>(); if (selectedItems.Contains(item)) { selectedItems.Remove(item); } else { selectedItems.Add(item); } collectionView.UpdateSelectedItems(selectedItems); break; } }
public App() { var label = new Label() { Text = "Touch Me", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, FontSize = 42 }; var touchEffect = new TouchEffect(); touchEffect.TouchAction += (s, e) => { label.Text = e.Type.ToString("f"); Console.WriteLine(e.Type.ToString()); }; label.Effects.Add(touchEffect); MainPage = new ContentPage() { Content = label }; }
Task SetRotationY(TouchEffect sender, TouchState touchState, HoverState hoverState, int duration, Easing easing) { var normalRotationY = sender.NormalRotationY; var pressedRotationY = sender.PressedRotationY; var hoveredRotationY = sender.HoveredRotationY; if (Abs(normalRotationY) <= double.Epsilon && Abs(pressedRotationY) <= double.Epsilon && Abs(hoveredRotationY) <= double.Epsilon) { return(Task.FromResult(false)); } var rotationY = normalRotationY; if (touchState == TouchState.Pressed) { rotationY = pressedRotationY; } else if (hoverState == HoverState.Hovered && sender.Element.IsSet(TouchEffect.HoveredRotationYProperty)) { rotationY = hoveredRotationY; } var element = sender.Element; if (duration <= 0) { element.RotationY = rotationY; return(Task.FromResult(true)); } return(element.RotateYTo(rotationY, (uint)Abs(duration), easing)); }
/* * Inizializzazione schermata dispositivo */ private void InizializeComponent(SKBitmap bitMap) { display = new Display(); gridLayout = new Grid(); bitMapArea = new BitMapArea(bitMap); canvasBitMap = new SKCanvasView(); canvasBitMap.PaintSurface += OnCanvasViewBitMapImgSurface; allRectangleArea = new List <RectangleArea>(); allTouchEffect = new List <long>(); Scale = MIN_SCALE; TranslationX = TranslationY = 0; AnchorX = AnchorY = 0; pinchGesture = new PinchGestureRecognizer(); pinchGesture.PinchUpdated += OnPinchUpdated; panGesture = new PanGestureRecognizer(); panGesture.PanUpdated += OnPanUpdated; touchEffect = new TouchEffect(); touchEffect.TouchAction += OnTouchEffectAction; touchEffect.Capture = true; gridLayout.Effects.Add(touchEffect); gridLayout.Children.Add(canvasBitMap); Content = gridLayout; }
void OnTouchEffectAction(object sender, TouchActionEventArgs args) { ContentView view = sender as ContentView; // identify the dragged contentView for (int i = 0; i < NoCV; i++) { if (view == contentViews[i]) { drag = i; break; } } switch (args.Type) { case TouchActionType.Pressed: // Don't allow a second touch on an already touched BoxView if (!dragDictionary.ContainsKey(view)) { dragDictionary.Add(view, new DragInfo(args.Id, args.Location)); // Set Capture property to true TouchEffect touchEffect = (TouchEffect)view.Effects.FirstOrDefault(e => e is TouchEffect); touchEffect.Capture = true; } OffScroll(); break; case TouchActionType.Moved: if (dragDictionary.ContainsKey(view) && dragDictionary[view].Id == args.Id) { Rectangle rect = AbsoluteLayout.GetLayoutBounds(view); Point initialLocation = dragDictionary[view].PressPoint; rect.X += args.Location.X - initialLocation.X; rect.Y += args.Location.Y - initialLocation.Y; AbsoluteLayout.SetLayoutBounds(view, rect); } break; case TouchActionType.Released: if (dragDictionary.ContainsKey(view) && dragDictionary[view].Id == args.Id) { Rectangle rect = AbsoluteLayout.GetLayoutBounds(view); localpositions[drag].X = rect.X; localpositions[drag].Y = rect.Y; Label2.Text = "Position in absoluteLayout: X = " + rect.X.ToString() + ", Y = " + rect.Y.ToString(); dragDictionary.Remove(view); } OnScroll(); break; } }
private void AddTouchEffect() { TouchEffect touchEffect = new TouchEffect(); touchEffect.TouchAction += TouchEffect_TouchAction; Helper.AddEffect(this.View, touchEffect); }
/* * void Button2(object sender, EventArgs args) * { * scrollView.ScrollToAsync( 100, 100, false ); * } */ //void AddBoxViewToLayout(AbsoluteLayout absLayout) void AddContentView() { ContentView contentView = new ContentView { WidthRequest = 200, HeightRequest = 100, BackgroundColor = Color.Black, Padding = new Thickness(2, 2, 2, 2), Content = new Editor { FontSize = 20, InputTransparent = true, // Disable to edit Text = "contentViews[" + NoCV + "]" } }; contentViews[NoCV] = contentView; NoCV++; Label4.Text = "The number of ContentView: " + NoCV.ToString(); TouchEffect touchEffect = new TouchEffect(); touchEffect.TouchAction += OnTouchEffectAction; contentView.Effects.Add(touchEffect); absoluteLayout.Children.Add(contentView); }
Task SetRotationX(TouchEffect sender, TouchState touchState, HoverState hoverState, int duration, Easing?easing) { var normalRotationX = sender.NormalRotationX; var pressedRotationX = sender.PressedRotationX; var hoveredRotationX = sender.HoveredRotationX; if (Abs(normalRotationX) <= double.Epsilon && Abs(pressedRotationX) <= double.Epsilon && Abs(hoveredRotationX) <= double.Epsilon) { return(Task.FromResult(false)); } var rotationX = normalRotationX; if (touchState == TouchState.Pressed) { rotationX = pressedRotationX; } else if (hoverState == HoverState.Hovered && (sender.Element?.IsSet(TouchEffect.HoveredRotationXProperty) ?? false)) { rotationX = hoveredRotationX; } var element = sender.Element; if (duration <= 0 && element != null) { element.AbortAnimations(); element.RotationX = rotationX; return(Task.FromResult(true)); } return(element?.RotateXTo(rotationX, (uint)Abs(duration), easing) ?? Task.FromResult(false)); }
public Key() { TouchEffect effect = new TouchEffect(); effect.TouchAction += OnTouchEffectAction; Effects.Add(effect); }
private void UpdateEffectColor() { _view.Touch -= OnTouch; _layer?.Dispose(); _layer = null; var color = TouchEffect.GetColor(Element); if (color == Color.Default) { return; } _color = color.ToAndroid(); if (EnableRipple) { _ripple.SetColor(GetPressedColorSelector(_color)); } else { _layer = new FrameLayout(Container.Context) { LayoutParameters = new ViewGroup.LayoutParams(-1, -1) }; _layer.SetBackgroundColor(_color); _view.Touch += OnTouch; } }
internal void HandleTouch(TouchEffect sender, TouchStatus status) { if (sender.IsDisabled) { return; } var canExecuteAction = sender.CanExecute; if (status != TouchStatus.Started || canExecuteAction) { if (!canExecuteAction) { status = TouchStatus.Canceled; } var state = status == TouchStatus.Started ? TouchState.Pressed : TouchState.Normal; if (status == TouchStatus.Started) { animationProgress = 0; animationState = state; } var isToggled = sender.IsToggled; if (isToggled.HasValue) { if (status != TouchStatus.Started) { durationMultiplier = (animationState == TouchState.Pressed && !isToggled.Value) || (animationState == TouchState.Normal && isToggled.Value) ? 1 - animationProgress : animationProgress; UpdateStatusAndState(sender, status, state); if (status == TouchStatus.Canceled) { sender.ForceUpdateState(false); return; } OnTapped(sender); sender.IsToggled = !isToggled; return; } state = isToggled.Value ? TouchState.Normal : TouchState.Pressed; } UpdateStatusAndState(sender, status, state); } if (status == TouchStatus.Completed) { OnTapped(sender); } }
protected override void OnAttached() { effect = TouchEffect.PickFrom(Element); if (effect?.IsDisabled ?? true) { return; } effect.Element = (VisualElement)Element; if (View == null) { return; } touchGesture = new TouchUITapGestureRecognizer(effect); if (((View as IVisualNativeElementRenderer)?.Control ?? View) is UIButton button) { button.AllTouchEvents += PreventButtonHighlight; ((TouchUITapGestureRecognizer)touchGesture).IsButton = true; } View.AddGestureRecognizer(touchGesture); if (XCT.IsiOS13OrNewer) { hoverGesture = new UIHoverGestureRecognizer(OnHover); View.AddGestureRecognizer(hoverGesture); } View.UserInteractionEnabled = true; }
void HandleCollectionViewSelection(TouchEffect sender) { if (!sender.Element.TryFindParentElementWithParentOfType(out var element, out CollectionView collectionView)) { return; } var item = element.BindingContext ?? element; switch (collectionView.SelectionMode) { case SelectionMode.Single: collectionView.SelectedItem = !item.Equals(collectionView.SelectedItem) ? item : null; break; case SelectionMode.Multiple: var selectedItems = collectionView.SelectedItems?.ToList() ?? new List <object>(); if (selectedItems.Contains(item)) { selectedItems.Remove(item); } else { selectedItems.Add(item); } collectionView.UpdateSelectedItems(selectedItems); break; } }
readonly Timer PetTimer; //This timer will check if no touch action is used in the last 5 seconds. Any touch interaction will reset this timer public PetContainer(Pet pet) { //This changes the dimensions of the box size to match the page height and width. AbsoluteLayout.SetLayoutBounds(this, new Rectangle(0, 0, 1, 1)); AbsoluteLayout.SetLayoutFlags(this, AbsoluteLayoutFlags.All); //Opacity = 0.25;//Remove when finalising //Color = Color.Black;//Remove when finalising HorizontalOptions = LayoutOptions.FillAndExpand; VerticalOptions = LayoutOptions.FillAndExpand; //Variable initialisation CurrentPet = pet; New_Position_X = 0; New_Position_Y = 0; UpdatePetStates(); //Allow for touch input TouchEffect effect = new TouchEffect(); effect.TouchAction += OnTouchEffectAction; Effects.Add(effect); PetTimer = new Timer(5 * 1000);//5 Seconds PetTimer.Elapsed += Step; PetTimer.AutoReset = true; PetTimer.Stop(); PetTimer.Start(); }
public ButtonItem() { _touchEff = new TouchEffect(); Effects.Add(_touchEff); _touchEff.StateChanged += TouchStateChanged; TouchEffect.SetCommand(this, new Command(InternalExecuteCommand)); }
Task SetOpacity(TouchEffect sender, TouchState touchState, HoverState hoverState, int duration, Easing easing) { var normalOpacity = sender.NormalOpacity; var pressedOpacity = sender.PressedOpacity; var hoveredOpacity = sender.HoveredOpacity; if (Abs(normalOpacity - 1) <= double.Epsilon && Abs(pressedOpacity - 1) <= double.Epsilon && Abs(hoveredOpacity - 1) <= double.Epsilon) { return(Task.FromResult(false)); } var opacity = normalOpacity; if (touchState == TouchState.Pressed) { opacity = pressedOpacity; } else if (hoverState == HoverState.Hovered && sender.Element.IsSet(TouchEffect.HoveredOpacityProperty)) { opacity = hoveredOpacity; } var element = sender.Element; if (duration <= 0) { element.Opacity = opacity; return(Task.FromResult(true)); } return(element.FadeTo(opacity, (uint)Abs(duration), easing)); }
protected override void OnDetached() { if (effect?.Element == null) { return; } if (((View as IVisualNativeElementRenderer)?.Control ?? View) is UIButton button) { button.AllTouchEvents -= PreventButtonHighlight; } if (touchGesture != null) { View?.RemoveGestureRecognizer(touchGesture); touchGesture?.Dispose(); touchGesture = null; } if (hoverGesture != null) { View?.RemoveGestureRecognizer(hoverGesture); hoverGesture?.Dispose(); hoverGesture = null; } effect.Element = null; effect = null; }
private void AddRipple() { var color = TouchEffect.GetColor(Element); if (color == Color.Default) { return; } _color = color.ToAndroid(); if (Element is Layout) { _rippleOverlay = new FrameLayout(Container.Context) { LayoutParameters = new ViewGroup.LayoutParams(-1, -1) }; _rippleListener = new ContainerOnLayoutChangeListener(_rippleOverlay); _view.AddOnLayoutChangeListener(_rippleListener); ((ViewGroup)_view).AddView(_rippleOverlay); _rippleOverlay.BringToFront(); _rippleOverlay.Foreground = CreateRipple(Color.Accent.ToAndroid()); } else { _orgDrawable = _view.Background; _view.Background = CreateRipple(Color.Accent.ToAndroid()); } _ripple.SetColor(GetPressedColorSelector(_color)); }
internal void HandleUserInteraction(TouchEffect sender, TouchInteractionStatus interactionStatus) { if (sender.InteractionStatus != interactionStatus) { sender.InteractionStatus = interactionStatus; sender.RaiseInteractionStatusChanged(); } }
public TouchRecognizer(Element element, UIView view, TouchEffect touchEffect) { this.element = element; this.view = view; this.touchEffect = touchEffect; viewDictionary.Add(view, this); }
private void AddTouchEffect() { TouchEffect touchEffect = new TouchEffect(); touchEffect.TouchAction += TouchEffect_TouchAction; Helper.AddEffect(RootGrid, touchEffect); longPressStarted = false; }
protected override void OnAttached() { if (View == null) { return; } effect = TouchEffect.PickFrom(Element); if (effect?.IsDisabled ?? true) { return; } effect.Element = (VisualElement)Element; View.Touch += OnTouch; UpdateClickHandler(); accessibilityManager = View.Context?.GetSystemService(Context.AccessibilityService) as AccessibilityManager; if (accessibilityManager != null) { accessibilityListener = new AccessibilityListener(this); accessibilityManager.AddAccessibilityStateChangeListener(accessibilityListener); accessibilityManager.AddTouchExplorationStateChangeListener(accessibilityListener); } if (XCT.SdkInt < (int)BuildVersionCodes.Lollipop || !effect.NativeAnimation) { return; } View.Clickable = true; View.LongClickable = true; CreateRipple(); if (Group == null) { if (XCT.SdkInt >= (int)BuildVersionCodes.M) { View.Foreground = ripple; } return; } rippleView = new FrameLayout(Group.Context ?? throw new NullReferenceException()) { LayoutParameters = new ViewGroup.LayoutParams(-1, -1), Clickable = false, Focusable = false, Enabled = false, }; View.LayoutChange += OnLayoutChange; rippleView.Background = ripple; Group.AddView(rippleView); rippleView.BringToFront(); }
protected override void Dispose(bool disposing) { if (disposing) { effect = null; Delegate = null; } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { effect = null; container = null; } base.Dispose(disposing); }
public FlatCheckBox() { InitializeComponent(); img.IsVisible = Icon != null; UpdateColors(); TouchEffect.SetCommand(this, TapCommand); }
public DraggableBoxView() { TouchEffect touchEffect = new TouchEffect { Capture = true }; touchEffect.TouchAction += OnTouchEffectAction; Effects.Add(touchEffect); }
internal void OnTapped(TouchEffect sender) { if (!sender.CanExecute || (sender.LongPressCommand != null && sender.InteractionStatus == TouchInteractionStatus.Completed)) { return; } sender.Command?.Execute(sender.CommandParameter); sender.RaiseCompleted(); }
void UpdateStatusAndState(TouchEffect sender, TouchStatus status, TouchState state) { if (sender.State != state || status != TouchStatus.Canceled) { sender.State = state; sender.RaiseStateChanged(); } sender.Status = status; sender.RaiseStatusChanged(); }