Inheritance: VisualElement, IViewController
Ejemplo n.º 1
1
        public async override Task Appearing(View content, PopupPage page)
        {
            var taskList = new List<Task>();

            taskList.Add(base.Appearing(content, page));

            if (content != null)
            {
                var topOffset = GetTopOffset(content, page);
                var leftOffset = GetLeftOffset(content, page);

                if (PositionIn == MoveAnimationOptions.Top)
                {
                    content.TranslationY = -topOffset;
                }
                else if (PositionIn == MoveAnimationOptions.Bottom)
                {
                    content.TranslationY = topOffset;
                }
                else if (PositionIn == MoveAnimationOptions.Left)
                {
                    content.TranslationX = -leftOffset;
                }
                else if (PositionIn == MoveAnimationOptions.Right)
                {
                    content.TranslationX = leftOffset;
                }

                taskList.Add(content.TranslateTo(_defaultTranslationX, _defaultTranslationY, DurationIn, EasingIn));
            }

            page.IsVisible = true;

            await Task.WhenAll(taskList);
        }
        public QuestionContainerView(ISurveyItem item, View questionView, SurveyPageAppearance appearance)
        {
            var headerView = new QuestionHeaderView (item, appearance) {
                VerticalOptions = LayoutOptions.Start
            };

            var inputStackLayout = new StackLayout () {
                Style = appearance.QuestionContainerLayoutStyle,
                Children = {
                    StandardViews.CreateSeparator (appearance.ItemSeperatorStyle),
                    questionView,
                    StandardViews.CreateSeparator (appearance.ItemSeperatorStyle)
                }
            };

            var stackLayout = new StackLayout {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children = {
                    headerView,
                    inputStackLayout,
                }
            };

            if (!String.IsNullOrWhiteSpace (item.Footnote)) {
                var footerView = new QuestionFooterView (item, appearance);
                stackLayout.Children.Add (footerView);
            }

            Content = stackLayout;
        }
 public override void Disposing(View content, PopupPage page)
 {
     if (HasBackgroundAnimation && page.BackgroundImage == null)
     {
         page.BackgroundColor = _backgroundColor;
     }
 }
        public bool ContainsTransaction(View view)
        {
            if(view == null)
                throw new ArgumentNullException("view");

            return _transactions.ContainsKey(view);
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Shows the _popup centered to the parent view.
		/// </summary>
		/// <param name="popupView">The _popup view.</param>
		public void ShowPopup(View popupView) {
			ShowPopup(
				popupView,
				Constraint.RelativeToParent(p => (Width - _popup.WidthRequest) / 2),
				Constraint.RelativeToParent(p => (Height -_popup.HeightRequest) / 2)
				);
		}
Ejemplo n.º 6
0
        /// <summary>
        /// Instantiate a new <see cref="PopupTappedEventArgs"/>
        /// </summary>
        /// <param name="popup">The popup that was tapped</param>
        /// <param name="view">The view that was tapped</param>
        /// <returns></returns>
        public static PopupTappedEventArgs Create(Popup popup, View view)
        {
            PopupSectionType housingSectionType;

            var parentView = view.FindParent(ve =>
            {
                var parentSectionType = ve.GetValue(Popup.SectionTypeProperty);
                var currentSection = (PopupSectionType)parentSectionType;

                return currentSection == PopupSectionType.Body
                       || currentSection == PopupSectionType.Footer
                       || currentSection == PopupSectionType.Header;
            });

            if (parentView == null)
            {
                housingSectionType = PopupSectionType.Backdrop;
            }
            else
            {
                housingSectionType = (PopupSectionType)parentView.GetValue(Popup.SectionTypeProperty);
            }

            var controlType = (PopupSectionType)view.GetValue(Popup.SectionTypeProperty);
            var evt = new PopupTappedEventArgs
            {
                Popup = popup,
                ControlTapped = view,
                IsUserControl = controlType == PopupSectionType.NotSet,
                Section = housingSectionType
            };

            return evt;
        }
        public void AnimationListAdd(View view)
        {
            if (!isListShowed)
                view.RotationX = 90;

            animationList.Add(view);
        }
Ejemplo n.º 8
0
            public void OnClick(View view)
            {
                var renderer = view.Tag as AppCompatButtonRenderer;

                if (renderer != null)
                    renderer.Element.InvokeSendClicked();
            }
        public QuestionInputViewContainer(IQuestion question, View view, SurveyPageAppearance appearance)
        {
            view.HorizontalOptions = LayoutOptions.FillAndExpand;

            var errorLabel = new Label {
                Style = appearance.QuestionErrorLabelStyle,
                Text = String.Empty,
                IsVisible = false,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            question.PropertyChanged += (sender, e) => {
                if (e.PropertyName == "HasError") {
                    if (question.HasError) {
                        errorLabel.Text = question.ErrorMessage;
                        errorLabel.IsVisible = true;
                    } else {
                        errorLabel.IsVisible = false;
                    }
                }
            };

            Content = new StackLayout {
                Orientation = StackOrientation.Vertical,
                Style = appearance.QuestionInputViewContainerLayoutStyle,
                Children = {
                    view,
                    errorLabel
                }
            };
        }
Ejemplo n.º 10
0
        public void AddToContext(View view, bool inputTransparent = true)
        {
            panelLayout.Children.RemoveAt(panelLayout.Children.Count - 1);

            if (inputTransparent)
            {
                var viewGestures = new ViewGestures();
                viewGestures.Content = view;
                viewGestures.BackgroundColor = BackgroundColor;

                viewGestures.Tap += (s, e) => { OnClick(); };
                if (panelAlignEnum == PanelAlignEnum.paLeft)
                    viewGestures.SwipeLeft += (s, e) => { OnClick(); };
                else if (panelAlignEnum == PanelAlignEnum.paRight)
                    viewGestures.SwipeRight += (s, e) => { OnClick(); };

                AddView(viewGestures);
                previousView = viewGestures;
            }
            else
            {
                AddView(view);
                previousView = view;
            }

            CloseContext();
        }
Ejemplo n.º 11
0
        public ShadowBoxCell(View content, double boxHeight, double boxWidth)
        {
            BoxWidth = boxWidth;
            BoxHeight = boxHeight;

            var frameImage = new Frame {
                Padding = 5,
                Content = content,
                BackgroundColor = Color.White,
                HasShadow = false,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                OutlineColor = Color.Black,
                HeightRequest = BoxHeight,
                WidthRequest = BoxWidth,
                MinimumHeightRequest = BoxHeight,
                MinimumWidthRequest = BoxWidth,
            };

            var frameBackground1 = new Frame {
                Padding = 5,
                BackgroundColor = Color.Gray,
                HasShadow = false,
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                OutlineColor = Color.Black,
                HeightRequest = BoxHeight,
                WidthRequest = BoxWidth,
                MinimumHeightRequest = BoxHeight,
                MinimumWidthRequest = BoxWidth,
            };

            var grid = new Grid {
                RowSpacing = 0,
                Padding = new Thickness (0, 0, 0, 0),
            };

            grid.RowDefinitions.Add (new RowDefinition { Height = new GridLength (300) });
            grid.ColumnDefinitions.Add (new ColumnDefinition { Width = new GridLength (300) });

            var relativeLayout = new RelativeLayout ();

            relativeLayout.Children.Add (frameBackground1,
                Constraint.Constant (2),
                Constraint.Constant (2)
            );

            relativeLayout.Children.Add (frameImage,
                Constraint.RelativeToView (frameBackground1, (parent, sibling) => {
                    return sibling.X - 1;
                }),
                Constraint.RelativeToView (frameBackground1, (parent, sibling) => {
                    return sibling.Y - 1;
                }));

            grid.Children.Add (relativeLayout, 0, 0);

            Content = grid;
        }
Ejemplo n.º 12
0
 public ViewWithGridPosition(View view, int row, int column, int rowSpan = 1, int columnSpan = 1)
 {
     this.View = view;
       this.Row = row;
       this.RowSpan = rowSpan;
       this.Column = column;
       this.ColumnSpan = columnSpan;
 }
        public Transaction GetTransactionFor(View view)
        {
            var transaction = _transactions.First(x => x.Key == view);

            var transactionValue = transaction.Value;

            return transactionValue;
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Shows the popup centered to the parent view.
 /// </summary>
 /// <param name="popupView">The popup view.</param>
 public void ShowPopup(View popupView)
 {
     this.ShowPopup(
         popupView,
         Constraint.RelativeToParent(p => (this.Width - this.popup.WidthRequest) / 2),
         Constraint.RelativeToParent(p => (this.Height- this.popup.HeightRequest) / 2)
         );
 }
 public override void Preparing(View content, PopupPage page)
 {
     if (HasBackgroundAnimation && page.BackgroundImage == null)
     {
         _backgroundColor = page.BackgroundColor;
         page.BackgroundColor = GetColor(0);
     }
 }
 private static void OnBindableContentChanged(BindableObject bindable, View oldValue, View newValue)
 {
     var source = bindable as EditableLabel;
     if (source == null)
     {
         return;
     }
     source.OnBindableContentChanged();
 }
Ejemplo n.º 17
0
        public PopupDialog(View view, ContentPage parentPage)
        {
            ParentPage = parentPage;
            PopupParent = view;
            _lastwidth = parentPage.Width;
            _lastwidth = parentPage.Height;

            HorizontalOptions = LayoutOptions.FillAndExpand;
            VerticalOptions = LayoutOptions.FillAndExpand;
            BackgroundColor = Color.Transparent;
            SetLayoutFlags(view, AbsoluteLayoutFlags.None);
            SetLayoutBounds(view, new Rectangle(0f, 0f, parentPage.Width - parentPage.Padding.HorizontalThickness, parentPage.Height - parentPage.Padding.VerticalThickness));
            Children.Add(view);
            ParentPage.SizeChanged += ((object sender, EventArgs e) =>
            {
                if (PopupParent != null && ParentPage.Width > 0)
                {
                    if (Math.Abs(_lastwidth - ParentPage.Width) > .001)
                    {
                        #region ReSizing the poupup

                        _lastwidth = ParentPage.Width;
                        _lastheight = ParentPage.Height;

                        SetLayoutBounds(PopupParent,
                            new Rectangle(0f, 0f, parentPage.Width - parentPage.Padding.HorizontalThickness,
                                parentPage.Height - parentPage.Padding.VerticalThickness));

                        if (PopupView != null && PopupVisible)
                        {
                            _popupWidth = ParentPage.Width * _viewScale;
                            _popupHeight = ParentPage.Height * _viewScale;
                            _popupLeft = ((ParentPage.Width - ParentPage.Padding.HorizontalThickness) - _popupWidth) / 2;
                            _popupTop = ((ParentPage.Height - ParentPage.Padding.VerticalThickness) - _popupHeight) / 2;
                            if (IsModal)
                            {
                                SetLayoutBounds(PopupShield, new Rectangle(0, 0, ParentPage.Width, ParentPage.Height));

                                if (!Children.Contains(PopupShield))
                                {
                                    Children.Add(PopupShield);
                                }
                            }
                            SetLayoutBounds(PopupFramer, new Rectangle(_popupLeft, _popupTop, _popupWidth, _popupHeight));
                            TitleLabel.WidthRequest = _popupWidth - 21;
                            if (!Children.Contains(PopupFramer))
                            {
                                Children.Add(PopupFramer);
                            }
                        }
                    }

                    #endregion
                }
            });
        }
        public void AddTransaction(View viewToBePlaced, Transaction transaction)
        {
            if(viewToBePlaced == null)
                throw new ArgumentNullException("viewToBePlaced");

            if(transaction == null)
                throw new ArgumentNullException("transaction");

            _transactions.Add(viewToBePlaced, transaction);
        }
Ejemplo n.º 19
0
        public override void Preparing(View content, PopupPage page)
        {
            base.Preparing(content, page);

            page.IsVisible = false;

            if(content == null) return;

            UpdateDefaultTranslations(content);
        }
Ejemplo n.º 20
0
		public void ShowPopup(View popupView, Constraint xConstraint, Constraint yConstraint, Constraint widthConstraint = null, Constraint heightConstraint = null)
		{
			DismissPopup();
			_popup = popupView;

			_content.InputTransparent = true;
			Children.Add(_popup, xConstraint, yConstraint, widthConstraint, heightConstraint);

			UpdateChildrenLayout();
		}
Ejemplo n.º 21
0
        public override void Disposing(View content, PopupPage page)
        {
            base.Disposing(content, page);

            page.IsVisible = true;

            if (content == null) return;

            content.TranslationY = _defaultTranslationY;
        }
Ejemplo n.º 22
0
		public void DismissPopup()
		{
			if (_popup != null)
			{
				Children.Remove(_popup);
				_popup = null;
			}

			_content.InputTransparent = false;
		}
Ejemplo n.º 23
0
 public override void Disposing(View content, PopupPage page)
 {
     if (HasBackgroundAnimation)
     {
         page.Opacity = _defaultOpacity;
     }
     else if (content != null)
     {
         page.Opacity = _defaultOpacity;
     }
 }
 /// <summary>
 /// Utility function to locate a specific interest
 /// </summary>
 /// <param name="view">The view that has the interest</param>
 /// <param name="interestedin">The collection of <see cref="GestureInterest"/></param>
 /// <returns>A <see cref="ViewInterest"/></returns>
 internal void RegisterInterests(View view,IEnumerable<GestureInterest>interestedin )
 {
     var vi = _viewInterests.FirstOrDefault(x => x.View == view);
     if (vi == null)
     {
         vi = new ViewInterest { View = view };
         _viewInterests.Add(vi);
     }
      vi.Interests=new List<GestureInterest>(interestedin.ToList());
     BindInterests(vi);
 }
Ejemplo n.º 25
0
 protected AbsoluteLayout BusyIndicator(View content, ActivityIndicator indicator)
 {
     var overlay = new AbsoluteLayout();
     AbsoluteLayout.SetLayoutFlags(content, AbsoluteLayoutFlags.PositionProportional);
     AbsoluteLayout.SetLayoutBounds(content, new Rectangle(0f, 0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
     AbsoluteLayout.SetLayoutFlags(indicator, AbsoluteLayoutFlags.PositionProportional);
     AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
     overlay.Children.Add(content);
     overlay.Children.Add(indicator);
     return overlay;
 }
		public static void Handle(View newElement, View oldElement, UIView nativeView)
		{
			if (newElement != null)
			{
				Register(newElement, nativeView);
			}
			else if (oldElement != null)
			{
				UnRegister(oldElement, nativeView);
			}
		}
		public SliderView (View rootview, double height, double width) 
		{
			//Set the height and width to be used throughout the SLiderView
			_height = height;
			_width = width;

			//Set the current view to the view that was initialized
			_currentView = rootview;

			//Create the ObservableCollection for the Children property
			Children = new ObservableCollection<View> ();
			Children.Insert (0, _currentView);

			//Create the ViewScreen that will schol the current layout.
			ViewScreen = new AbsoluteLayout {
				HeightRequest = _height,
				WidthRequest = _width,
			};

			//Create a StackLayout for the little white dots that will be at the boom of the slider
			dotLayout = new StackLayout {
				HorizontalOptions = LayoutOptions.CenterAndExpand,
				VerticalOptions = LayoutOptions.Center,
				Orientation = StackOrientation.Horizontal,
			};

			//Make one button and add it to the dotLayout
			Button whiteDot = new Button {
				BorderRadius = 5,
				HeightRequest = 10,
				WidthRequest = 10,
				StyleId = 0.ToString(),
				BackgroundColor = Color.White
			};
			dotLayout.Children.Add (whiteDot);

			//Add ObservableCollection CollectionChanged event to update the little white dots as children are added and removed
			Children.CollectionChanged += Children_CollectionChanged;

			Rectangle dotRect = new Rectangle (
				x: _width/2 - (15)/2,
				y: _height - 15,
				width: 15,
				height: 10
			);

			//Layout the current view to the ViewScreen
			ViewScreen.Children.Add (_currentView, new Rectangle (0, 0, width, height));
			//Layout the dotLayout to the ViewScreen. This must be done AFTER the current view is added so the dots are on the top level
			ViewScreen.Children.Add (dotLayout, dotRect);

			//Set the content of the ContentView to the ViewScreen	
			Content = ViewScreen;
		}
Ejemplo n.º 28
0
		internal override void ComputeConstraintForView(View view)
		{
			bool isFixedHorizontally = (Constraint & LayoutConstraint.HorizontallyFixed) != 0;
			bool isFixedVertically = (Constraint & LayoutConstraint.VerticallyFixed) != 0;

			var result = LayoutConstraint.None;
			if (isFixedVertically && view.VerticalOptions.Alignment == LayoutAlignment.Fill)
				result |= LayoutConstraint.VerticallyFixed;
			if (isFixedHorizontally && view.HorizontalOptions.Alignment == LayoutAlignment.Fill)
				result |= LayoutConstraint.HorizontallyFixed;
			view.ComputedConstraint = result;
		}
 // NOTE: can get the loading indicator centered with AbsoluteLayout, but then other elements/layout behave/look strange ...
 protected AbsoluteLayout CreateLoadingIndicatorAbsoluteLayout(View content)
 {
     var overlay = new AbsoluteLayout();
     var loadingIndicator = CreateLoadingIndicator();
     AbsoluteLayout.SetLayoutFlags(content, AbsoluteLayoutFlags.PositionProportional);
     AbsoluteLayout.SetLayoutBounds(content, new Rectangle(0f, 0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
     AbsoluteLayout.SetLayoutFlags(loadingIndicator, AbsoluteLayoutFlags.PositionProportional);
     AbsoluteLayout.SetLayoutBounds(loadingIndicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
     overlay.Children.Add(content);
     overlay.Children.Add(loadingIndicator);
     return overlay;
 }
        public MasterSamplePageWindows(MasterSample sample, MultiPage<ContentPage> mainPage, ContentPage rootPage)
        {
            propertyStackLayout = new StackLayout
            {
                Orientation = StackOrientation.Vertical,

                VerticalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor = Color.FromHex("#FFEDEDEB"),
                Padding = new Thickness(10,0,10,10)
            };

            var headerStackLayout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                HeightRequest = 50,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };
            var optionsLabel = new Label
            {
                TextColor = Color.FromHex("#1196CD"),
                Text = "Options",
                
                FontSize = 20,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center
            };
            headerStackLayout.Children.Add(optionsLabel);

            //AbsoluteLayout.SetLayoutBounds(optionsLabel,);

            var optionsHeaderImage = new Image
            {

                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                Aspect = Aspect.AspectFit,
                Source = ImageSource.FromFile("Icons/optionBack.png")
            };


            var tapGesture = new TapGestureRecognizer();
            tapGesture.Tapped += tapGesture_Tapped;
            optionsHeaderImage.GestureRecognizers.Add(tapGesture);
            headerStackLayout.Children.Add(optionsHeaderImage);

            propertyStackLayout.Children.Add(headerStackLayout);

            var mainContent = new StackLayout { Spacing = 0 };
            headerView = GetHeaderLayout(sample, mainPage, rootPage);
            mainContent.Children.Add(headerView);
            mainContent.Children.Add(GetControlLayout(sample));
            Content = mainContent;
        }
Ejemplo n.º 31
0
    public static UIView ConvertFormsToNative(Xamarin.Forms.View view, CGRect size)
    {
        var renderer = RendererFactory.GetRenderer(view);

        renderer.NativeView.Frame = size;

        renderer.NativeView.AutoresizingMask = UIViewAutoresizing.All;
        renderer.NativeView.ContentMode      = UIViewContentMode.ScaleToFill;

        renderer.Element.Layout(size.ToRectangle());

        var nativeView = renderer.NativeView;

        nativeView.SetNeedsLayout();

        return(nativeView);
    }
Ejemplo n.º 32
0
        bool IVideoPlayer.LoadScreen(Xamarin.Forms.View view, float screenWidth, string uri)
        {
            var Uiview = (view as NativeViewWrapper).NativeView;

            avasset               = AVAsset.FromUrl(NSUrl.FromString(uri));
            avplayerItem          = new AVPlayerItem(avasset);
            avplayer              = new AVPlayer(avplayerItem);
            _playerViewController = new AVPlayerViewController {
                Player = avplayer
            };
            avplayerLayer = AVPlayerLayer.FromPlayer(_playerViewController.Player);
            Uiview.Layer.AddSublayer(avplayerLayer);
            avplayerLayer.Frame = new CoreGraphics.CGRect(0, 0, screenWidth, 260);
            _playerViewController.ShowsPlaybackControls = true;
            _playerViewController.Player.Play();
            IsPlaying = true;
            return(true);
        }
Ejemplo n.º 33
0
        private void imgTap2x3(Xamarin.Forms.View arg1, object arg2)
        {
            var simg2x2 = img2x2.Source.ToString();
            var simg1x3 = img1x3.Source.ToString();

            if (simg2x2 == "File: " + filenull)
            {
                img2x2.Source = img2x3.Source;
                img2x3.Source = filenull;
                imgControl();
            }
            else if (simg1x3 == "File: " + filenull)
            {
                img1x3.Source = img2x3.Source;
                img2x3.Source = filenull;
                imgControl();
            }
        }
Ejemplo n.º 34
0
        private void imgTap0x0(Xamarin.Forms.View arg1, object arg2)
        {
            var simg0x1 = img0x1.Source.ToString();
            var simg1x0 = img1x0.Source.ToString();

            if (simg0x1 == "File: " + filenull)
            {
                img0x1.Source = img0x0.Source;
                img0x0.Source = filenull;
                imgControl();
            }
            else if (simg1x0 == "File: " + filenull)
            {
                img1x0.Source = img0x0.Source;
                img0x0.Source = filenull;
                imgControl();
            }
        }
Ejemplo n.º 35
0
        async Task ShareWithFriends(Xamarin.Forms.View element)
        {
            try
            {
                Analytics.TrackEvent("ShareWithFriends");
                var bounds = element.GetAbsoluteBounds();

                await Share.RequestAsync(new ShareTextRequest
                {
                    PresentationSourceBounds = bounds.ToSystemRectangle(),
                    Title = "Island Tracker for ACNH",
                    Text  = "Checkout Island Tracker for ACNH and track turnips with me: https://islandtracker.app"
                });
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 36
0
        private void PopulatePredictionView(string stopName, int secondsToArrival, string plateNumber = "")
        {
            if (string.Equals("-1", plateNumber))
            {
                plateNumber = "";
            }
            Xamarin.Forms.View stopNameView    = CreateStopNameView(stopName);
            Xamarin.Forms.View plateNumberView = CreateDescriptionView(plateNumber);
            Xamarin.Forms.View minutesView     = CreatArrivalMinutesView(secondsToArrival / 60);
            Grid innerGrid = new Grid {
                ColumnDefinitions = DEFAULT_COLUMN_DEFINITION, RowDefinitions = DEFAULT_ROW_DEFINITION
            };

            innerGrid.Children.Add(stopNameView);
            innerGrid.Children.Add(plateNumberView, 1, 2, 0, 1);
            innerGrid.Children.Add(minutesView, 2, 3, 0, 1);
            Children.Add(innerGrid);
        }
Ejemplo n.º 37
0
        public FormsElementWrapper(Xamarin.Forms.View content, Element parent)
        {
            content.Parent = parent;

            Renderer = content != null?Platform.CreateRenderer(content) : null;

            Platform.SetRenderer(content, Renderer);

            var cachedBindingContext = content.BindingContext;

            content.BindingContext = cachedBindingContext;
            if (Renderer == null)
            {
                return;
            }

            AddSubview(Renderer.NativeView);
        }
Ejemplo n.º 38
0
 void DisconnectChildElementFromItsParentListeners(Xamarin.Forms.View child)
 {
     if (child != null)
     {
         if (_children.Contains(child))
         {
             _children.Remove(child);
         }
         if (_listeners != null)
         {
             foreach (var parentListener in _listeners)
             {
                 var gestureHandler = GetInstanceForElement(child);
                 gestureHandler?.RemoveListener(parentListener);
             }
         }
     }
 }
Ejemplo n.º 39
0
        public static AViews.View ToAndroid(this Xamarin.Forms.View view, Rectangle size)
        {
            //var vRenderer = RendererFactory.GetRenderer (view);

            //if (Platform.GetRenderer(view) == null)
            Platform.SetRenderer(view, Platform.CreateRenderer(view));
            var vRenderer = Platform.GetRenderer(view);

            var viewGroup = vRenderer.View;

            vRenderer.Tracker.UpdateLayout();
            var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height);

            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
            return(viewGroup);
        }
Ejemplo n.º 40
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_formsCell != null)
                {
                    _formsCell.PropertyChanged -= CellPropertyChanged;
                    _formsCell = null;
                }

                ViewHolder = null;

                //_renderer?.View?.RemoveFromParent();
                //_renderer?.Dispose();
                _renderer = null;
            }
            base.Dispose(disposing);
        }
Ejemplo n.º 41
0
        FrameworkElement CreateView(object item)
        {
            Xamarin.Forms.View formsView = null;
            var bindingContext           = item;

            var dt   = bindingContext as Xamarin.Forms.DataTemplate;
            var view = bindingContext as View;

            // Support for List<DataTemplate> as ItemsSource
            if (dt != null)
            {
                formsView = (Xamarin.Forms.View)dt.CreateContent();
            }
            else
            {
                if (view != null)
                {
                    formsView = view;
                }
                else
                {
                    var selector = Element.ItemTemplate as Xamarin.Forms.DataTemplateSelector;
                    if (selector != null)
                    {
                        formsView = (Xamarin.Forms.View)selector.SelectTemplate(bindingContext, Element).CreateContent();
                    }
                    else
                    {
                        formsView = (Xamarin.Forms.View)Element.ItemTemplate.CreateContent();
                    }

                    formsView.BindingContext = bindingContext;
                }
            }

            formsView.Parent = this.Element;

            var element = formsView.ToWindows(new Xamarin.Forms.Rectangle(0, 0, ElementWidth, ElementHeight));

            //if (dt == null && view == null)
            //formsView.Parent = null;

            return(element);
        }
Ejemplo n.º 42
0
        public void ShowContent(Xamarin.Forms.View content, bool mathParent = true)
        {
            // build the loading page with native base
            content.Parent = Xamarin.Forms.Application.Current.MainPage;

            if (mathParent)
            {
                content.Layout(new Rectangle(0, 0,
                                             Xamarin.Forms.Application.Current.MainPage.Width,
                                             Xamarin.Forms.Application.Current.MainPage.Height));
            }
            else
            {
                content.Layout(new Rectangle(Xamarin.Forms.Application.Current.MainPage.Width - content.WidthRequest, Xamarin.Forms.Application.Current.MainPage.Height - content.HeightRequest,
                                             content.WidthRequest,
                                             content.HeightRequest));
            }

            var renderer = content.GetOrCreateRenderer();

            contentNativeView = renderer?.View;

            contentDialog = new Dialog(CrossCurrentActivity.Current.Activity);
            contentDialog.RequestWindowFeature((int)WindowFeatures.NoTitle);
            if (mathParent)
            {
                contentDialog.SetCanceledOnTouchOutside(false);
                contentDialog.SetOnKeyListener(new DialogInterfaceOnKeyListener());
            }
            else
            {
                contentDialog.SetCanceledOnTouchOutside(true);
            }
            contentDialog.SetContentView(contentNativeView);

            Window window = contentDialog.Window;

            window.SetLayout(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
            window.ClearFlags(WindowManagerFlags.DimBehind);
            window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));

            // Show Popup
            contentDialog?.Show();
        }
        public void Toast(IDialogMsg dialogMsg, DialogConfig config = null, bool islong = false, bool isNative = false)
        {
            Xamarin.Forms.View toastView = isNative ? null : _dialogsInitize.GetInitToastView();
            if (config == null)
            {
                config = new DialogConfig()
                {
                    DialogPosition = DialogPosition.ToastDefault
                };
            }
            ToastDialogUtil toastDialog = new ToastDialogUtil(_activity, toastView, config
                                                              , dialogMsg, islong, isNative);
            var toast = toastDialog.Builder();

            if (toast != null)
            {
                toast.Show();
            }
        }
Ejemplo n.º 44
0
        private void AnimateButtonTouched(Xamarin.Forms.View view, uint duration, string hexColorInitial, string hexColorFinal, int repeatCountMax)
        {
            var repeatCount = 0;

            view.Animate("changedBG", new Animation((val) => {
                if (repeatCount == 0)
                {
                    view.BackgroundColor = Color.FromHex(hexColorInitial);
                }
                else
                {
                    view.BackgroundColor = Color.FromHex(hexColorFinal);
                }
            }), duration, finished: (val, b) => {
                repeatCount++;
            }, repeat: () => {
                return(repeatCount < repeatCountMax);
            });
        }
Ejemplo n.º 45
0
        public IXFPopupCtrl CreateDropDown(Xamarin.Forms.View anchor, Xamarin.Forms.View drop)
        {
            CustomDropDown dropctr = null;

            //get the renderer of anchor
            if (anchor != null)
            {
                var ar = anchor.GetValue(RendererProperty);
                if (ar != null)
                {
                    var dropView = Convert(drop, anchor);

                    if (dropView == null)
                    {
                        return(null);
                    }

                    double w = (int)anchor.Width;
                    double h = XFPopupConst.SCREEN_HEIGHT / 2;
                    drop.WidthRequest = w;
                    var size = drop.GetSizeRequest(w, XFPopupConst.SCREEN_HEIGHT / 2);
                    if (size.Request.Height < h)
                    {
                        h = size.Request.Height;
                    }


                    drop.Layout(new Rectangle(0, 0, w, h));

                    float density = Forms.Context.Resources.DisplayMetrics.Density;
                    w = w * density;
                    h = h * density;


                    var native = dropView as Android.Views.View;
                    native.LayoutParameters = new ViewGroup.LayoutParams((int)w, (int)h);

                    dropctr = new CustomDropDown(ar as Android.Views.View, native, (int)w + 4, (int)h + 10);
                }
            }

            return(dropctr);
        }
Ejemplo n.º 46
0
        public static ViewGroup ConvertFormsToNative(Xamarin.Forms.View view, Rectangle size)
        {
            if (Platform.GetRenderer(view) == null)
            {
                Platform.SetRenderer(view, Platform.CreateRenderer(view));
            }
            var vRenderer = Platform.GetRenderer(view);


            var viewGroup = vRenderer.ViewGroup;

            vRenderer.Tracker.UpdateLayout();
            var layoutParams = new ViewGroup.LayoutParams((int)size.Width, (int)size.Height);

            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)view.WidthRequest, (int)view.HeightRequest);
            return(viewGroup);
        }
Ejemplo n.º 47
0
        private Android.Views.View ConvertFormsToNative(Xamarin.Forms.View view, Xamarin.Forms.Rectangle size)
        {
            viewRenderer = Platform.CreateRendererWithContext(view, Context);
            var viewGroup = viewRenderer.View;

            viewRenderer.Tracker.UpdateLayout();

            if (view.HeightRequest > 0)
            {
                size.Height = view.HeightRequest;
            }

            var layoutParams = new ViewGroup.LayoutParams((int)(size.Width * Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density), (int)(size.Height * Xamarin.Essentials.DeviceDisplay.MainDisplayInfo.Density));

            viewGroup.LayoutParameters = layoutParams;
            view.Layout(size);
            viewGroup.Layout(0, 0, (int)view.Width, (int)view.Height);
            return(viewGroup);
        }
Ejemplo n.º 48
0
        public void ApplyMaskToView(Xamarin.Forms.View view, ViewMaskerType maskType)
        {
            var renderer   = view.GetRenderer();
            var nativeView = renderer.NativeView;

            if (maskType == ViewMaskerType.None)
            {
                view.SizeChanged     -= OnSizeChanged;
                nativeView.Layer.Mask = null;
            }
            else
            {
                var maskLayer = GetMaskShape(maskType, new Xamarin.Forms.Size(view.Width, view.Height));
                maskLayer.Frame       = nativeView.Bounds;
                nativeView.Layer.Mask = maskLayer;
                view.SizeChanged     += OnSizeChanged;
            }
            nativeView.Tag = (int)maskType;
        }
Ejemplo n.º 49
0
        public async override Task Appearing(Xamarin.Forms.View content, PopupPage page)
        {
            var taskList = new List <Task>();

            taskList.Add(base.Appearing(content, page));

            if (content != null)
            {
                var topOffset = GetTopOffset(content, page);
                content.TranslationY = topOffset;

                taskList.Add(content.TranslateTo(content.TranslationX, _defaultTranslationY, DurationIn, EasingIn));
            }
            ;

            page.IsVisible = true;

            await Task.WhenAll(taskList);
        }
Ejemplo n.º 50
0
        private async Task Animate(Xamarin.Forms.View view, bool isCurrent)
        {
            //if (isCurrent)
            view.IsVisible = true;

            Rectangle beginRect = Rectangle.Zero;
            Rectangle endRect   = Rectangle.Zero;

            //设置起始和终止值
            beginRect = setbeginRect(isCurrent, _Direct);
            endRect   = setendRect(isCurrent, _Direct);

            view.Layout(beginRect);
            await view.LayoutTo(endRect, easing : Easing.Linear)
            .ContinueWith(t =>
            {
                // BUG 会使填充失效
                view.IsVisible = isCurrent;
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
        protected override void OnAttachedTo(Xamarin.Forms.View visualElement)
        {
            base.OnAttachedTo(visualElement);

            var events = AssociatedObject?.GetType().GetRuntimeEvents().ToArray();

            if (events.Any())
            {
                _eventInfo = events.FirstOrDefault(e => e.Name == EventName);
                if (_eventInfo == null)
                {
                    throw new ArgumentException(String.Format("EventToCommand: Can't find any event named '{0}' on attached type", EventName));
                }

                MethodInfo methodInfo = typeof(EventToCommandBehavior).GetTypeInfo().GetDeclaredMethod("OnFired");
                _handler = methodInfo.CreateDelegate(_eventInfo.EventHandlerType, this);
                _eventInfo.AddEventHandler(AssociatedObject, _handler);
                //AddEventHandler(_eventInfo, AssociatedObject, OnFired);
            }
        }
Ejemplo n.º 52
0
        void OnPopupRequest(Xamarin.Forms.View view)
        {
            // Null Check
            if (Effect.Parent.ItemsSource == null)
            {
                return;
            }

            // Clear Old
            ToggleMenu.Menu.Clear();

            // Add New
            foreach (var item in Effect.Parent.ItemsSource)
            {
                ToggleMenu.Menu.Add(item.ToString());
            }

            // Popup
            ToggleMenu.Show();
        }
Ejemplo n.º 53
0
        bool IVideoPlayer.LoadScreen(Xamarin.Forms.View view, float screenHeight, string uri)
        {
            videoView = (view as NativeViewWrapper).NativeView as VideoView;
            videoView.SetVideoURI(Android.Net.Uri.Parse(uri));
            videoView.Start();
            CurrentStream   = uri;
            mediaController = new MediaController(videoView.Context);
            mediaController.SetMediaPlayer(videoView);
            videoView.SetMediaController(mediaController);
            for (int i = 0; i < 15; i++)
            {
                if (videoView.IsPlaying)
                {
                    return(true);
                }

                return(false);
            }
            return(false);
        }
Ejemplo n.º 54
0
        public void ShowTooltip(Xamarin.Forms.View onView, TooltipConfig config)
        {
            var control = GetOrCreateRenderer(onView).View;

            if (!string.IsNullOrEmpty(config.Text))
            {
                ToolTip.Builder builder;
                var             position      = config.Position;
                var             parentContent = control.RootView;
                switch (position)
                {
                case TooltipPosition.Top:
                    builder = new ToolTip.Builder(global::Android.App.Application.Context, control,
                                                  parentContent as ViewGroup, config.Text.PadRight(80, ' '), ToolTip.PositionAbove);
                    break;

                case TooltipPosition.Left:
                    builder = new ToolTip.Builder(global::Android.App.Application.Context, control,
                                                  parentContent as ViewGroup, config.Text.PadRight(80, ' '), ToolTip.PositionLeftTo);
                    break;

                case TooltipPosition.Right:
                    builder = new ToolTip.Builder(global::Android.App.Application.Context, control,
                                                  parentContent as ViewGroup, config.Text.PadRight(80, ' '), ToolTip.PositionRightTo);
                    break;

                default:
                    builder = new ToolTip.Builder(global::Android.App.Application.Context, control,
                                                  parentContent as ViewGroup, config.Text.PadRight(80, ' '), ToolTip.PositionBelow);
                    break;
                }

                builder.SetAlign(ToolTip.AlignLeft);
                builder.SetBackgroundColor(config.BackgroundColor.ToAndroid());
                builder.SetTextColor(config.TextColor.ToAndroid());

                toolTipView = builder.Build();

                _toolTipsManager?.Show(toolTipView);
            }
        }
Ejemplo n.º 55
0
        protected override void OnElementChanged(ElementChangedEventArgs <VideoPlayer> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                _videoPlayer = e.NewElement;
                _parent      = e.NewElement.Parent as View;

                if (Control == null)
                {
                    RelativeLayout layout = new RelativeLayout(Context);
                    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MatchParent, 1);

                    _mediaController = new MediaController(Context);
                    _videoView       = new PrivateVideoView(Context, _videoPlayer);

                    layout.AddView(_videoView);
                    layoutParams.AddRule(LayoutRules.CenterInParent);

                    _videoView.LayoutParameters = layoutParams;

                    _videoView.SetMediaController(_mediaController);

                    SetNativeControl(layout);
                }

                if (e.NewElement.Source is VideoPlayer.FileSource fileSource)
                {
                    _videoView.SetVideoPath(fileSource.Path);
                }
                else if (e.NewElement.Source is VideoPlayer.UrlSource urlSource)
                {
                    _videoView.SetVideoURI(Uri.Parse(urlSource.Url));
                }
            }

            if (e.OldElement != null)
            {
            }
        }
        public IVisualElementRenderer Convert(Xamarin.Forms.View source, Xamarin.Forms.VisualElement valid)
        {
            IVisualElementRenderer render = (IVisualElementRenderer)source.GetValue(RendererProperty);

            if (render == null)
            {
                render = RendererFactory.GetRenderer(source);
                source.SetValue(RendererProperty, render);
                if (valid != null)
                {
                    var p = PlatformProperty.GetValue(valid);
                    if (p != null)
                    {
                        //PlatformProperty.SetValue(source, p);
                        //IsPlatformEnabledProperty.SetValue(source, true);
                    }
                }
            }

            return(render);
        }
Ejemplo n.º 57
0
        public static Rectangle GetAbsoluteBounds(this Xamarin.Forms.View element)
        {
            Element looper = element;

            var absoluteX = element.X + element.Margin.Top;
            var absoluteY = element.Y + element.Margin.Left;

            // TODO: add logic to handle titles, headers, or other non-view bars

            while (looper.Parent != null)
            {
                looper = looper.Parent;
                if (looper is Xamarin.Forms.View v)
                {
                    absoluteX += v.X + v.Margin.Top;
                    absoluteY += v.Y + v.Margin.Left;
                }
            }

            return(new Rectangle(absoluteX, absoluteY, element.Width, element.Height));
        }
Ejemplo n.º 58
0
 public static void AddContainerElements(Grid uiContainer, List <CardElement> elements, RenderContext context)
 {
     foreach (var cardElement in elements)
     {
         // each element has a row
         FrameworkElement uiElement = context.Render(cardElement);
         if (uiElement != null)
         {
             if (cardElement.Separator && uiContainer.RowDefinitions.Count > 0)
             {
                 AddSeperator(context, cardElement, uiContainer);
             }
             uiContainer.RowDefinitions.Add(new RowDefinition()
             {
                 Height = GridLength.Auto
             });
             Grid.SetRow(uiElement, uiContainer.RowDefinitions.Count - 1);
             uiContainer.Children.Add(uiElement);
         }
     }
 }
            public override Java.Lang.Object InstantiateItem(AViews.ViewGroup container, int position)
            {
                Xamarin.Forms.View formsView = null;

                object bindingContext = null;

                if (Element.ItemsSource != null)
                {
                    bindingContext = Element.ItemsSource.Cast <object> ().ElementAt(position);
                }

                var selector = Element.ItemTemplate as DataTemplateSelector;

                if (selector != null)
                {
                    formsView = (View)selector.SelectTemplate(bindingContext, Element).CreateContent();
                }
                else
                {
                    formsView = (View)Element.ItemTemplate.CreateContent();
                }

                formsView.BindingContext = bindingContext;
                formsView.Parent         = this.Element;

                // Width in dip and not in pixels. (all Xamarin.Forms controls use dip for their WidthRequest and HeightRequest)
                // Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density
                var nativeConverted = FormsToNativeDroid.ConvertFormsToNative(formsView, new Rectangle(0, 0, Element.Width, Element.Height));

                nativeConverted.Tag = position;

                var pager = (ViewPager)container;

                nativeConverted.RestoreHierarchyState(mViewStates);

                pager.AddView(nativeConverted);

                return(nativeConverted);
            }
Ejemplo n.º 60
0
        public static UIView ToiOS(this Xamarin.Forms.View view, CGRect size)
        {
            if (Platform.GetRenderer(view) == null)
            {
                Platform.SetRenderer(view, Platform.CreateRenderer(view));
            }

            var vRenderer = Platform.GetRenderer(view);

            vRenderer.NativeView.Frame = size;

            vRenderer.NativeView.AutoresizingMask = UIViewAutoresizing.All;
            vRenderer.NativeView.ContentMode      = UIViewContentMode.ScaleToFill;

            vRenderer.Element?.Layout(size.ToRectangle());

            var nativeView = vRenderer.NativeView;

            nativeView.SetNeedsLayout();

            return(nativeView);
        }