public AndroidFormsInspectView(Page page, bool useNativeViewBounds = false, bool withSubviews = true) { if (page == null) { throw new ArgumentNullException(nameof(page)); } element = page; PopulateTypeInformationFromObject(page); // TODO: Pull the ClassId or some user-set property as the description? var nativeView = Platform.GetRenderer(page).View; if (!useNativeViewBounds) { Transform = XIVR.GetViewTransform(nativeView); if (Transform == null) { X = page.Bounds.X; Y = page.Bounds.Y; } } else { var location = new int [2]; nativeView.GetLocationOnScreen(location); X = location [0]; // You are the worst, Android. Here we need to convert the location we get to dips, // because Xamarin.Forms Bounds are in dips, and then also subtract the status bar, // once again converting to dips. var yDips = nativeView.Context.FromPixels(location [1]); var window = ((Activity)nativeView.Context).Window; var rect = new Rect(); window.DecorView.GetWindowVisibleDisplayFrame(rect); var statusBarHeight = rect.Top; var statusBarDips = nativeView.Context.FromPixels(statusBarHeight); Y = yDips - statusBarDips; } Width = page.Bounds.Width; Height = page.Bounds.Height; Kind = ViewKind.Primary; Visibility = page.GetViewVisibility(); if (withSubviews) { HandlePageChildren( page, (p, b) => new AndroidFormsInspectView(p, useNativeViewBounds || b), e => new AndroidFormsInspectView(e), AddSubview ); } }
public AndroidFormsInspectView(Element element, bool withSubviews = true) { if (element == null) { throw new ArgumentNullException(nameof(element)); } this.element = element; PopulateTypeInformationFromObject(element); var velement = element as VisualElement; if (velement != null) { var nativeView = Platform.GetRenderer(velement).View; DisplayName = element.GetType().Name; try { DisplayName += " :" + nativeView.Resources.GetResourceName(nativeView.Id).TrimId(); } catch { } Transform = XIVR.GetViewTransform(nativeView); if (Transform == null) { X = velement.Bounds.X; Y = velement.Bounds.Y; } Width = velement.Bounds.Width; Height = velement.Bounds.Height; Visibility = velement.GetViewVisibility(); } else { // Since this is not a visual element, set it as collapsed by default. Visibility = ViewVisibility.Collapsed; } Kind = ViewKind.Primary; // TODO: Figure out different types of elements and extra useful data from them when appropriate. Description = GetDescriptionFromElement(element, supplementaryDescriptionMap); if (withSubviews) { HandleElementChildren(element, e => new AndroidFormsInspectView(e), AddSubview); } }
protected override void UpdateCapturedImage() { VisualElement ve; if ((ve = element as VisualElement) != null) { // If the VisualElement is a view and is not a layout, snapshot its children, // as we've reached the leaf of the tree. Otherwise, skip children. var skipChildren = !(ve is View && !(ve is Layout)); var nativeView = Platform.GetRenderer(ve).View; if (nativeView != null) { CapturedImage = XIVR.RenderAsPng(nativeView, skipChildren); } } }
public AndroidInspectView(View view, bool withSubviews = true) { if (view == null) { throw new ArgumentNullException(nameof(view)); } this.view = view; // FIXME: special case certain view types and fill in the Description property if (withSubviews) { Transform = ViewRenderer.GetViewTransform(view); if (Transform == null) { X = view.Left; Y = view.Top; } } else { var locArray = new int [2]; view.GetLocationOnScreen(locArray); X = locArray [0]; Y = locArray [1]; } Width = view.Width; Height = view.Height; Kind = ViewKind.Primary; Visibility = view.Visibility.ToViewVisibility(); PopulateTypeInformationFromObject(view); DisplayName = view.GetType().Name; try { DisplayName += " :" + view.Resources.GetResourceName(view.Id).TrimId(); } catch { } if (view is Button) { Description = ((Button)view).Text; } else if (view is TextView) { Description = ((TextView)view).Text; } if (!withSubviews) { return; } var subviews = view.Subviews(); if (subviews != null && subviews.Length > 0) { for (int i = 0; i < subviews.Length; i++) { AddSubview(new AndroidInspectView(subviews [i])); } } }
protected override void UpdateCapturedImage() { CapturedImage = ViewRenderer.RenderAsPng(view, true); }