protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Page> e) { base.OnElementChanged(e); if (e.OldElement != null || Element == null) { return; } var layout = new Android.Widget.LinearLayout(this.Context); layout.SetBackgroundColor(Android.Graphics.Color.Black); layout.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); VideoView mVideoView = new VideoView(Context); mVideoView.SetVideoPath("android.resource://" + this.Context.PackageName + "/" + Resource.Drawable.IntroGladys); layout.SetVerticalGravity(GravityFlags.Center); layout.SetHorizontalGravity(GravityFlags.Center); mVideoView.LayoutParameters = new LayoutParams(LayoutParams.FillParent, LayoutParams.FillParent); layout.AddView(mVideoView); mVideoView.Start(); _view = layout; AddView(_view); }
void SetArrows() { if (Element.ShowArrows) { if (prevBtn == null) { prevBtn = nativeView.FindViewById <AWidget.LinearLayout>(Resource.Id.prev); prevBtn.SetBackgroundColor(Element.ArrowsBackgroundColor.ToAndroid()); prevBtn.Visibility = Element.Position == 0 ? AViews.ViewStates.Gone : AViews.ViewStates.Visible; prevBtn.Alpha = Element.ArrowsTransparency; var prevArrow = nativeView.FindViewById <AWidget.ImageView>(Resource.Id.prevArrow); prevArrow.SetColorFilter(Element.ArrowsTintColor.ToAndroid()); prevBtn.Click += delegate { if (Element.Position > 0) { Element.Position = Element.Position - 1; } }; } if (nextBtn == null) { nextBtn = nativeView.FindViewById <AWidget.LinearLayout>(Resource.Id.next); nextBtn.SetBackgroundColor(Element.ArrowsBackgroundColor.ToAndroid()); nextBtn.Visibility = Element.Position == Element.ItemsSource.GetCount() - 1 ? AViews.ViewStates.Gone : AViews.ViewStates.Visible; nextBtn.Alpha = Element.ArrowsTransparency; var nextArrow = nativeView.FindViewById <AWidget.ImageView>(Resource.Id.nextArrow); nextArrow.SetColorFilter(Element.ArrowsTintColor.ToAndroid()); nextBtn.Click += delegate { if (Element.Position < Element.ItemsSource.GetCount() - 1) { Element.Position = Element.Position + 1; } }; } } else { if (prevBtn != null) { prevBtn.Visibility = AViews.ViewStates.Gone; } if (nextBtn != null) { nextBtn.Visibility = AViews.ViewStates.Gone; } } }
void SetArrows() { if (Element.ShowArrows) { if (prevBtn == null) { prevBtn = nativeView.FindViewById <AWidget.LinearLayout>(Resource.Id.prev); prevBtn.SetBackgroundColor(Element.ArrowsBackgroundColor.ToAndroid()); prevBtn.Visibility = Element.Position == 0 || Element.ItemsSource.GetCount() == 0 ? AViews.ViewStates.Gone : AViews.ViewStates.Visible; prevBtn.Alpha = Element.ArrowsTransparency; prevBtn.SetMinimumWidth((int)Element.ArrowsWidth); prevBtn.SetMinimumHeight((int)Element.ArrowsHeight); var prevArrow = nativeView.FindViewById <AWidget.ImageView>(Resource.Id.prevArrow); prevArrow.SetColorFilter(Element.ArrowsTintColor.ToAndroid()); prevBtn.Click += PrevBtn_Click; } if (nextBtn == null) { nextBtn = nativeView.FindViewById <AWidget.LinearLayout>(Resource.Id.next); nextBtn.SetBackgroundColor(Element.ArrowsBackgroundColor.ToAndroid()); nextBtn.Visibility = Element.Position == Element.ItemsSource.GetCount() - 1 || Element.ItemsSource.GetCount() == 0 ? AViews.ViewStates.Gone : AViews.ViewStates.Visible; nextBtn.Alpha = Element.ArrowsTransparency; var nextArrow = nativeView.FindViewById <AWidget.ImageView>(Resource.Id.nextArrow); nextArrow.SetColorFilter(Element.ArrowsTintColor.ToAndroid()); nextBtn.Click += NextBtn_Click; } } else { if (prevBtn == null || nextBtn == null) { return; } prevBtn.Visibility = AViews.ViewStates.Gone; nextBtn.Visibility = AViews.ViewStates.Gone; } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (Element == null || viewPager == null) { return; } var rect = this.Element.Bounds; switch (e.PropertyName) { case "Orientation": orientationChanged = true; SetNativeView(); Element.SendPositionSelected(); Element.PositionSelectedCommand?.Execute(null); break; case "BackgroundColor": viewPager.SetBackgroundColor(Element.BackgroundColor.ToAndroid()); break; case "IsSwipeEnabled": SetIsSwipeEnabled(); break; case "IndicatorsTintColor": indicators?.SetFillColor(Element.IndicatorsTintColor.ToAndroid()); break; case "CurrentPageIndicatorTintColor": indicators?.SetPageColor(Element.CurrentPageIndicatorTintColor.ToAndroid()); break; case "IndicatorsShape": indicators?.SetStyle((int)Element.IndicatorsShape); break; case "ShowIndicators": SetIndicators(); break; case "ItemsSource": SetPosition(); viewPager.Adapter = new PageAdapter(Element); viewPager.SetCurrentItem(Element.Position, false); SetArrowsVisibility(); indicators?.SetViewPager(viewPager); Element.SendPositionSelected(); Element.PositionSelectedCommand?.Execute(null); if (Element.ItemsSource != null && Element.ItemsSource is INotifyCollectionChanged) { ((INotifyCollectionChanged)Element.ItemsSource).CollectionChanged += ItemsSource_CollectionChanged; } break; case "ItemTemplate": viewPager.Adapter = new PageAdapter(Element); viewPager.SetCurrentItem(Element.Position, false); indicators?.SetViewPager(viewPager); Element.SendPositionSelected(); Element.PositionSelectedCommand?.Execute(null); break; case "Position": if (!isChangingPosition) { SetCurrentPage(Element.Position); } break; case "ShowArrows": SetArrows(); break; case "ArrowsBackgroundColor": if (prevBtn == null || nextBtn == null) { return; } prevBtn.SetBackgroundColor(Element.ArrowsBackgroundColor.ToAndroid()); nextBtn.SetBackgroundColor(Element.ArrowsBackgroundColor.ToAndroid()); break; case "ArrowsTintColor": var prevArrow = nativeView.FindViewById <AWidget.ImageView>(Resource.Id.prevArrow); prevArrow.SetColorFilter(Element.ArrowsTintColor.ToAndroid()); var nextArrow = nativeView.FindViewById <AWidget.ImageView>(Resource.Id.nextArrow); nextArrow.SetColorFilter(Element.ArrowsTintColor.ToAndroid()); break; case "ArrowsTransparency": if (prevBtn == null || nextBtn == null) { return; } prevBtn.Alpha = Element.ArrowsTransparency; nextBtn.Alpha = Element.ArrowsTransparency; break; } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); var rect = this.Element.Bounds; switch (e.PropertyName) { case "Orientation": if (Element != null) { orientationChanged = true; SetNativeView(); Element.SendPositionSelected(); Element.PositionSelectedCommand?.Execute(null); } break; case "InterPageSpacing": //var metrics = Resources.DisplayMetrics; //var interPageSpacing = Element.InterPageSpacing * metrics.Density; //viewPager.PageMargin = (int)interPageSpacing; break; case "BackgroundColor": viewPager?.SetBackgroundColor(Element.BackgroundColor.ToAndroid()); break; case "IsSwipingEnabled": SetIsSwipingEnabled(); break; case "IndicatorsTintColor": indicators?.SetFillColor(Element.IndicatorsTintColor.ToAndroid()); break; case "CurrentPageIndicatorTintColor": indicators?.SetPageColor(Element.CurrentPageIndicatorTintColor.ToAndroid()); break; case "IndicatorsShape": indicators?.SetStyle(Element.IndicatorsShape); break; case "ShowIndicators": SetIndicators(); break; case "ItemsSource": if (Element != null && viewPager != null) { SetPosition(); viewPager.Adapter = new PageAdapter(Element); viewPager.SetCurrentItem(Element.Position, false); indicators?.SetViewPager(viewPager); Element.SendPositionSelected(); Element.PositionSelectedCommand?.Execute(null); if (Element.ItemsSource != null && Element.ItemsSource is INotifyCollectionChanged) { ((INotifyCollectionChanged)Element.ItemsSource).CollectionChanged += ItemsSource_CollectionChanged; } } break; case "ItemTemplate": if (Element != null && viewPager != null) { viewPager.Adapter = new PageAdapter(Element); viewPager.SetCurrentItem(Element.Position, false); indicators?.SetViewPager(viewPager); Element.SendPositionSelected(); Element.PositionSelectedCommand?.Execute(null); } break; case "Position": if (Element != null && !isSwiping) { SetCurrentPage(Element.Position); } break; case "ShowArrows": SetArrows(); break; case "ArrowsBackgroundColor": if (prevBtn != null && nextBtn != null) { prevBtn.SetBackgroundColor(Element.ArrowsBackgroundColor.ToAndroid()); nextBtn.SetBackgroundColor(Element.ArrowsBackgroundColor.ToAndroid()); } break; case "ArrowsTintColor": if (prevBtn != null && nextBtn != null) { var prevArrow = nativeView.FindViewById <AWidget.ImageView>(Resource.Id.prevArrow); prevArrow.SetColorFilter(Element.ArrowsTintColor.ToAndroid()); var nextArrow = nativeView.FindViewById <AWidget.ImageView>(Resource.Id.nextArrow); nextArrow.SetColorFilter(Element.ArrowsTintColor.ToAndroid()); } break; } }