public void Bind(Activity activity)
        {
            if (activity == null)
                throw new ArgumentNullException();

            activity.SetContentView(ResourceId);

            if (BindOutlets)
            {
                FieldInfo[] fields = activity.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
                foreach (FieldInfo field in fields)
                {
                    object[] outlets = field.GetCustomAttributes(typeof(OutletAttribute), false);
                    if (outlets.Length == 0)
                        continue;

                    OutletAttribute outlet = (OutletAttribute) outlets[0];
                    field.SetValue(activity, activity.FindViewById(outlet.ResourceId));
                }
            }

            if (BindActions)
            {
                MethodInfo[] methods = activity.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
                foreach (MethodInfo method in methods)
                {
                    object[] actions = method.GetCustomAttributes(typeof(ActionAttribute), false);
                    if (actions.Length == 0)
                        continue;

                    foreach (ActionAttribute action in actions)
                    {
                        try
                        {
                            FieldInfo field = activity.GetType().GetField(action.Field, BindingFlags.NonPublic | BindingFlags.Instance);
                            if (field == null)
                                throw new Exception();

                            EventInfo handler = field.FieldType.GetEvent(action.Handler, BindingFlags.Public | BindingFlags.Instance);
                            if (handler == null)
                                throw new Exception();

                            handler.AddEventHandler(field.GetValue(activity), Delegate.CreateDelegate(handler.EventHandlerType, activity, method));
                        }
                        catch
                        {
                            Console.WriteLine("Can't bind {0}.{1} with {2}", action.Field, action.Handler, method.Name);
                            continue;
                        }
                    }
                }
            }
        }
        public ActivityRoutedViewHost(Activity hostActivity)
        {
            var keyUp = hostActivity.GetType()
                .GetMethods(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Instance)
                .FirstOrDefault(x => x.Name == "OnKeyUp");

            if (keyUp == null) {
                throw new Exception("You must override OnKeyUp and call theRoutedViewHost.OnKeyUp");
            }

            var viewFor = hostActivity as IViewFor;
            if (viewFor == null) {
                throw new Exception("You must implement IViewFor<TheViewModelClass>");
            }

            bool firstSet = false;
            _inner = _hostScreen.Router.ViewModelObservable()
                .Where(x => x != null)
                .Subscribe(vm => {
                    if (!firstSet) {
                        viewFor.ViewModel = vm;
                        firstSet = true;
                        return;
                    }

                    var view = RxRouting.ResolveView(vm);
                    if (view.GetType() != typeof(Type)) {
                        throw new Exception("Views in Android must be the Type of an Activity");
                    }

                    hostActivity.StartActivity((Type)view);
                });
        }
Ejemplo n.º 3
0
        public static void InvalidateOptionsMenu(Activity act)
        {
            try {
                _invalidateOptMenuMethod = act.GetType().GetMethod("InvalidateOptionsMenu", new Type[]{});
            } catch (Exception)
            {
                // Do nothing if method doesn't exist
            }

            if (_invalidateOptMenuMethod != null) {
                try {
                    _invalidateOptMenuMethod.Invoke(act, (new Object[]{}));
                } catch (Exception)
                {
                    // Do nothing
                }
            }
        }
Ejemplo n.º 4
0
        public ActivityRoutedViewHost(Activity hostActivity, IViewLocator viewLocator = null)
        {
            viewLocator = viewLocator ?? ViewLocator.Current;
            var platform = RxApp.DependencyResolver.GetService<IPlatformOperations>();

            var keyUp = hostActivity.GetType()
                .GetMethods(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Instance)
                .FirstOrDefault(x => x.Name == "OnKeyUp");

            if (keyUp == null) {
                throw new Exception("You must override OnKeyUp and call theRoutedViewHost.OnKeyUp");
            }

            var viewFor = hostActivity as IViewFor;
            if (viewFor == null) {
                throw new Exception("You must implement IViewFor<TheViewModelClass>");
            }

            bool firstSet = false;

            _inner = _hostScreen.Router.CurrentViewModel
                .Where(x => x != null)
                .Subscribe(vm => {
                    if (!firstSet) {
                        viewFor.ViewModel = vm;
                        firstSet = true;
                        return;
                    }

                    var view = viewLocator.ResolveView(vm, platform.GetOrientation());
                    if (view.GetType() != typeof(Type)) {
                        throw new Exception("Views in Android must be the Type of an Activity");
                    }
                    
                    hostActivity.StartActivity((Type)view);
                });
        }
Ejemplo n.º 5
0
 private void StartActivity(Activity sourceActivity, Type activityType)
 {
     var intent = new Intent(sourceActivity, activityType);
     intent.PutExtra("sourceActivity", sourceActivity.GetType().FullName);
     sourceActivity.StartActivity(intent);
 }
Ejemplo n.º 6
0
        public void OnAttached(Activity activity)
        {
            var actionBar = activity.GetActionBar();
            if (actionBar == null)
            {
                Tracer.Error("Cannot apply ActionBarView the ActionBar is null, activity {0}", activity.GetType().FullName);
                return;
            }

            var activityView = activity as IActivityView;
            if (activityView != null)
                activityView.Mediator.Destroyed += DestroyedHandler;

            if (_resourceId != int.MinValue)
            {
                if (_tabContentId != int.MinValue)
                    ServiceProvider.AttachedValueProvider.SetValue(actionBar, TabContentIdKey, _tabContentId);
                using (XmlReader reader = Context.Resources.GetLayout(_resourceId))
                {
                    //NOTE XDocument throws an error.
                    var document = new XmlDocument();
                    document.Load(reader);
                    using (var stringReader = new StringReader(PlatformExtensions.XmlTagsToUpper(document.InnerXml)))
                    {
                        var barTemplate = (ActionBarTemplate)Serializer.Deserialize(stringReader);
                        barTemplate.Apply(activity);
                    }
                }
            }

            if (_bindings == null)
                return;
            for (int i = 0; i < _bindings.Count; i++)
                BindingServiceProvider.BindingProvider.CreateBindingsFromString(actionBar, _bindings[i], null);
            this.RemoveFromParent();
            this.ClearBindingsRecursively(true, true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Tag screen using type of activity as name.
        /// </summary>
        /// <param name="activity">Activity which's type name to use for TagScreen.</param>
        public void TagScreen(Activity activity)
        {
            if (!IsEnabled)
                return;
            if (null == activity)
                throw new ArgumentNullException("activity");

            var activityType = activity.GetType();
            var screen = activityType.Name;
            TagScreen(screen);
        }
Ejemplo n.º 8
0
 private static string GetActivityName(Activity activity)
 {
     return activity.GetType().Name;
 }