public bool TryGetRepresentedView(object view, bool withSubviews, out IInspectView representedView)
        {
            representedView = null;

            var androidView = view as AndroidView;

            if (androidView == null)
            {
                return(false);
            }

            representedView = FormsInspectViewHelper.GetInspectView(
                androidView,
                v => v == agent.GetTopActivity()?.Window?.DecorView,
                (container, page) => new AndroidFormsInspectView(container, page, withSubviews),
                page => new AndroidFormsInspectView(page, withSubviews: withSubviews),
                v => {
                // Return null if the passed view isn't a Forms view.
                var visualElementRenderer = v as IVisualElementRenderer;
                if (visualElementRenderer != null)
                {
                    return(new AndroidFormsInspectView(visualElementRenderer.Element, withSubviews));
                }
                return(null);
            },
                ex => new AndroidFormsInspectView(ex),
                () => new AndroidFormsRootInspectView {
                DisplayName = agent.Identity.ApplicationName
            });

            return(representedView != null);
        }
Example #2
0
        public void IntegrateWith(EvaluationContextManager evaluationContextManager)
        {
            realAgent = evaluationContextManager.Context as AndroidAgent;

            if (realAgent == null)
            {
                return;
            }

            if (realAgent.ViewHierarchyHandlerManager == null)
            {
                return;
            }

            try {
                realAgent.ViewHierarchyHandlerManager.AddViewHierarchyHandler(HierarchyKind,
                                                                              new AndroidFormsViewHierarchyHandler(realAgent));

                evaluationContextManager.RepresentationManager.AddProvider <FormsRepresentationProvider> ();

                if (realAgent.ClientSessionUri.SessionKind == ClientSessionKind.Workbook)
                {
                    evaluationContextManager.RegisterResetStateHandler(ResetStateHandler);

                    // Set up launching the Forms activity.
                    Log.Debug(TAG, "Setting up activity type and grabbing current activity...");
                    var activityType = Type.GetType(FormsActivityTypeName);

                    if (activityType == null)
                    {
                        Log.Warning(TAG, "Could not fully initialize Xamarin.Forms integration, missing Forms launch activity.");
                        return;
                    }

                    var intent = new Intent(Application.Context, activityType);
                    intent.AddFlags(ActivityFlags.NewTask);

                    var currentActivity = realAgent.GetTopActivity();

                    // Launch the Forms activity.
                    Log.Debug(TAG, "Launching Forms activity via intent.");
                    Application.Context.StartActivity(intent);

                    // Wrap the previous activity up to reduce confusion.
                    Log.Debug(TAG, "Finishing existing activity.");
                    currentActivity.Finish();
                }

                Log.Info(TAG, "Registered Xamarin.Forms agent integration!");
            } catch (Exception e) {
                Log.Error(TAG, "Could not register Xamarin.Forms agent integration.", e);
            }
        }