public static Android.Widget.FrameLayout AddViewOnFrameLayout(Android.Views.View view, int width, int height) { var layout = new Android.Widget.FrameLayout(view.Context); layout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); view.LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(width, height); layout.AddView(view); return(layout); }
void CreateDialog() { if (_TextPickerCell.Items == null || _TextPickerCell.Items.Count == 0) { return; } var displayValues = _TextPickerCell.Items.Cast <object>().Select(x => x.ToString()).ToArray(); _picker = new APicker(_context); _picker.DescendantFocusability = DescendantFocusability.BlockDescendants; _picker.MinValue = 0; _picker.MaxValue = _TextPickerCell.Items.Count - 1; _picker.SetDisplayedValues(displayValues); _picker.Value = Math.Max(_TextPickerCell.Items.IndexOf(_TextPickerCell.SelectedItem), 0); _picker.WrapSelectorWheel = _TextPickerCell.IsCircularPicker; if (_dialog == null) { using (var builder = new AlertDialog.Builder(_context)) { builder.SetTitle(_title); Android.Widget.FrameLayout parent = new Android.Widget.FrameLayout(_context); parent.AddView(_picker, new Android.Widget.FrameLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, GravityFlags.Center)); builder.SetView(parent); builder.SetNegativeButton(global::Android.Resource.String.Cancel, (o, args) => { ClearFocus(); }); builder.SetPositiveButton(global::Android.Resource.String.Ok, (o, args) => { _TextPickerCell.SelectedItem = _TextPickerCell.Items[_picker.Value]; _command?.Execute(_TextPickerCell.Items[_picker.Value]); ClearFocus(); }); _dialog = builder.Create(); } _dialog.SetCanceledOnTouchOutside(true); _dialog.DismissEvent += (ss, ee) => { _dialog.Dispose(); _dialog = null; _picker.RemoveFromParent(); _picker.Dispose(); _picker = null; }; _dialog.Show(); } }
protected override void OnElementChanged(ElementChangedEventArgs <MapView> e) { base.OnElementChanged(e); if (e.OldElement != null) { e.OldElement.AnnotationChanged -= Element_AnnotationChanged; e.OldElement.TakeSnapshotFunc -= TakeMapSnapshot; e.OldElement.GetFeaturesAroundPointFunc -= GetFeaturesAroundPoint; if (map != null) { RemoveMapEvents(); } } if (e.NewElement == null) { return; } e.NewElement.AnnotationChanged += Element_AnnotationChanged; if (Control == null) { var activity = (AppCompatActivity)Context; var view = new Android.Widget.FrameLayout(activity) { Id = GenerateViewId() }; SetNativeControl(view); fragment = new MapViewFragment(); activity.SupportFragmentManager.BeginTransaction() .Replace(view.Id, fragment) .CommitAllowingStateLoss(); fragment.GetMapAsync(this); currentCamera = new Position(); if (mapReady) { if (Element.Annotations != null) { AddAnnotations(Element.Annotations.ToArray()); if (Element.Annotations is INotifyCollectionChanged notifyCollection) { notifyCollection.CollectionChanged -= OnAnnotationsCollectionChanged; notifyCollection.CollectionChanged += OnAnnotationsCollectionChanged; } } OnMapRegionChanged(); } } }
void CreateDialog() { _picker = new APicker(_context); _picker.MinValue = _min; _picker.MaxValue = _max; _picker.Value = _NumberPikcerCell.Number; if (_dialog == null) { using (var builder = new AlertDialog.Builder(_context)) { builder.SetTitle(_title); Android.Widget.FrameLayout parent = new Android.Widget.FrameLayout(_context); parent.AddView(_picker, new Android.Widget.FrameLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, GravityFlags.Center)); builder.SetView(parent); builder.SetNegativeButton(global::Android.Resource.String.Cancel, (o, args) => { ClearFocus(); }); builder.SetPositiveButton(global::Android.Resource.String.Ok, (o, args) => { _NumberPikcerCell.Number = _picker.Value; _command?.Execute(_picker.Value); ClearFocus(); }); _dialog = builder.Create(); } _dialog.SetCanceledOnTouchOutside(true); _dialog.DismissEvent += (ss, ee) => { _dialog.Dispose(); _dialog = null; _picker.RemoveFromParent(); _picker.Dispose(); _picker = null; }; _dialog.Show(); } }
protected override void OnElementChanged( ElementChangedEventArgs <MapView> e) { base.OnElementChanged(e); if (e.OldElement != null) { if (e.OldElement?.TakeSnapshotFunc != null) { // ReSharper disable once DelegateSubtraction e.OldElement.TakeSnapshotFunc -= TakeMapSnapshot; } if (e.OldElement?.GetFeaturesAroundPointFunc != null) { // ReSharper disable once DelegateSubtraction e.OldElement.GetFeaturesAroundPointFunc -= GetFeaturesAroundPoint; } } if (e.NewElement == null) { return; } if (Control != null) { return; } var activity = (AppCompatActivity)Context; var view = new Android.Widget.FrameLayout(activity) { Id = GenerateViewId() }; SetNativeControl(view); _fragment = new MapViewFragment(); activity.SupportFragmentManager.BeginTransaction() .Replace(view.Id, _fragment) .Commit(); _fragment.GetMapAsync(this); _currentCamera = new Position(); }
void CreateDialog() { if (_dialog != null) { return; } var picker = new APicker(_view.Context); picker.MinValue = _min; picker.MaxValue = _max; picker.Value = _number; using (var builder = new AlertDialog.Builder(_view.Context)) { builder.SetTitle(AddNumberPicker.GetTitle(Element)); Android.Widget.FrameLayout parent = new Android.Widget.FrameLayout(_view.Context); parent.AddView(picker, new Android.Widget.FrameLayout.LayoutParams( ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, GravityFlags.Center)); builder.SetView(parent); builder.SetNegativeButton(global::Android.Resource.String.Cancel, (o, args) => { }); builder.SetPositiveButton(global::Android.Resource.String.Ok, (o, args) => { AddNumberPicker.SetNumber(Element, picker.Value); _command?.Execute(picker.Value); }); _dialog = builder.Create(); } _dialog.SetCanceledOnTouchOutside(true); _dialog.DismissEvent += (ss, ee) => { _dialog.Dispose(); _dialog = null; picker.RemoveFromParent(); picker.Dispose(); picker = null; }; _dialog.Show(); }
protected override void OnElementChanged(ElementChangedEventArgs <MapView> e) { base.OnElementChanged(e); if (e.OldElement != null) { e.OldElement.AnnotationsChanged -= Element_AnnotationsChanged; e.OldElement.Functions = null; if (map != null) { RemoveMapEvents(); } } if (e.NewElement == null) { return; } if (Control == null) { var activity = (AppCompatActivity)Context.GetActivity(); var view = new Android.Widget.FrameLayout(activity) { Id = GenerateViewId() }; SetNativeControl(view); fragment = MapViewFragment.Create(Element, Context); activity.SupportFragmentManager .BeginTransaction() .Replace(view.Id, fragment) .CommitAllowingStateLoss(); fragment.GetMapAsync(this); currentCamera = new NxLatLng(); } }
public Android.Views.View GetNativeView(View element) { this.Element.Children.Add(element); Android.Views.View targetView = null; for (int i = 0; i < ViewGroup.ChildCount; i++) { var view = ViewGroup.GetChildAt(i); var property = view.GetType().GetProperty("Element"); if (property != null) { var elem = property.GetValue(view); if (elem == element) { targetView = view; break; } } } if (targetView == null) { return(null); } ((Android.Views.ViewGroup)targetView.Parent).RemoveView(targetView); var container = new Android.Widget.FrameLayout(this.Context); container.LayoutParameters = new LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent); targetView.LayoutParameters = new Android.Widget.FrameLayout.LayoutParams(Utils.DpToPx((float)element.WidthRequest), Utils.DpToPx((float)element.HeightRequest)); container.AddView(targetView); return(container); }
protected override void OnElementChanged(ElementChangedEventArgs <MapView> e) { base.OnElementChanged(e); if (e.OldElement != null) { e.OldElement.AnnotationChanged -= Element_AnnotationChanged; e.OldElement.TakeSnapshotFunc -= TakeMapSnapshot; e.OldElement.GetFeaturesAroundPointFunc -= GetFeaturesAroundPoint; if (map != null) { RemoveMapEvents(); } } if (e.NewElement == null) { return; } e.NewElement.AnnotationChanged += Element_AnnotationChanged; if (Control == null) { var activity = (AppCompatActivity)Context; if (e.NewElement.InsideFragment) { var view = new Android.Widget.FrameLayout(activity) { Id = GenerateViewId() }; SetNativeControl(view); fragment = new MapViewFragment(); activity.SupportFragmentManager.BeginTransaction() .Replace(view.Id, fragment) .CommitAllowingStateLoss(); fragment.GetMapAsync(this); currentCamera = new Position(); } else { this.mapView = new Sdk.Maps.MapView(activity); this.mapView.SetStyleUrl(this.GetDefaultStyle()); // TODO: Call these lifecycle events in the correct place. They should be called from the // Activity's respective methods, not from here. Idk what problems this could cause. // Note: this is why the renderer originally used Fragments. They have their own lifecycles // that are not tied to the main activity (which we only have one of because of Forms). this.mapView.OnCreate(null); this.mapView.OnStart(); this.mapView.OnResume(); this.SetNativeControl(this.mapView); this.mapView.AddOnMapChangedListener(this); this.mapView.GetMapAsync(this); } if (mapReady) { if (Element.Annotations != null) { AddAnnotations(Element.Annotations.ToArray()); if (Element.Annotations is INotifyCollectionChanged notifyCollection) { notifyCollection.CollectionChanged -= OnAnnotationsCollectionChanged; notifyCollection.CollectionChanged += OnAnnotationsCollectionChanged; } } OnMapRegionChanged(); } } }