示例#1
0
        /// <summary>
        /// Wires a control to a property.
        /// This should be called in the Fragment's OnCreateView, with the newly inflated layout.
        /// </summary>
        /// <param name="fragment">The fragment.</param>
        /// <param name="inflatedView">The inflated view.</param>
        /// <param name="resolveMembers">The resolve members.</param>
        public static void WireUpControls(this Fragment fragment, View inflatedView, ResolveStrategy resolveMembers = ResolveStrategy.Implicit)
        {
            if (fragment == null)
            {
                throw new ArgumentNullException(nameof(fragment));
            }

            var members = fragment.GetWireUpMembers(resolveMembers);

            foreach (var member in members)
            {
                try
                {
                    // Find the android control with the same name from the view
                    var view = inflatedView.GetControl(fragment.GetType().Assembly, member.GetResourceName());

                    // Set the activity field's value to the view with that identifier
                    member.SetValue(fragment, view);
                }
                catch (Exception ex)
                {
                    throw new
                          MissingFieldException("Failed to wire up the Property " + member.Name + " to a View in your layout with a corresponding identifier", ex);
                }
            }
        }
示例#2
0
        private void ReplaceFragment(Fragment fragment)
        {
            var ft = SupportFragmentManager.BeginTransaction();

            ft.Replace(Resource.Id.content_view, fragment, fragment.GetType().Name);
            ft.Commit();
        }
示例#3
0
 public void LoadFragment(Fragment fragment)
 {
     SupportFragmentManager
         .BeginTransaction()
         .Replace(Resource.Id.layout_container, fragment)
         .AddToBackStack(fragment.GetType().Name)
         .Commit();
 }
示例#4
0
 protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
 {
     Android.Support.V4.App.Fragment currentFragment = GetCurrentFragment();
     if (currentFragment.GetType() == typeof(AlertSendFragment))
     {
         ((AlertSendFragment)currentFragment).ResetAlertScreen("", false);
     }
 }
示例#5
0
 public void LoadFragment(Fragment fragment)
 {
     SupportFragmentManager
     .BeginTransaction()
     .Replace(Resource.Id.layout_container, fragment)
     .AddToBackStack(fragment.GetType().Name)
     .Commit();
 }
示例#6
0
        /// <summary>
        /// Called when a fragment is attached to this activity
        /// </summary>
        /// <param name="fragment">The fragment that is being attached</param>
        public override void OnAttachFragment(Fragment fragment)
        {
            base.OnAttachFragment(fragment);
            if (this.fragments == null)
            {
                this.fragments = new SparseArray <Fragment>();
            }

            if (fragment.GetType() == typeof(CustomerTicketsFragment))
            {
                this.fragments.Put(CustomerTicketsPage, fragment);
            }

            if (fragment.GetType() == typeof(DsrTicketsFragment))
            {
                this.fragments.Put(DsrTicketsPage, fragment);
            }
        }
        public override void OnAttachFragment(Fragment fragment)
        {
            base.OnAttachFragment(fragment);
            if (this._fragments == null)
            {
                this._fragments = new SparseArray <Fragment>();
            }

            if (fragment.GetType() == typeof(CustomerDetailFragment))
            {
                this._fragments.Put(CustomerDetailsPagerAdapter.CustomerRegistrationInfoFragment, fragment);
            }

            if (fragment.GetType() == typeof(CustomerTicketsFragment))
            {
                this._fragments.Put(CustomerDetailsPagerAdapter.CustomerTicketsFragmentPage, fragment);
            }

            if (fragment.GetType() == typeof(FragmentCustomerPhotos))
            {
                this._fragments.Put(CustomerDetailsPagerAdapter.CustomerPhotosFragmentPage, fragment);
            }
        }
        /// <summary>
        /// This should be called in the Fragment's OnCreateView, with the newly inflated layout
        /// </summary>
        /// <param name="This"></param>
        /// <param name="inflatedView"></param>
        public static void WireUpControls(this Android.Support.V4.App.Fragment This, View inflatedView)
        {
            var members = This.GetType().GetRuntimeProperties()
                          .Where(m => m.PropertyType.IsSubclassOf(typeof(View)));

            members.ToList().ForEach(m => {
                try {
                    // Find the android control with the same name from the view
                    var view = inflatedView.getControlInternal(m.PropertyType, m.Name);

                    // Set the activity field's value to the view with that identifier
                    m.SetValue(This, view);
                } catch (Exception ex) {
                    throw new MissingFieldException("Failed to wire up the Property "
                                                    + m.Name + " to a View in your layout with a corresponding identifier", ex);
                }
            });
        }
 public static void Load(Android.Support.V4.App.Fragment fragment)
 {
     LazyLoadList [fragment.GetType().Name] = fragment;
 }
 private void ReplaceFragment(Fragment fragment)
 {
     var ft = SupportFragmentManager.BeginTransaction();
     ft.Replace(Resource.Id.content_view, fragment, fragment.GetType().Name);
     ft.Commit();
 }
示例#11
0
        /// <summary>
        /// Populates the Fields in the Fragment with values stored within the BundleContext
        /// </summary>
        /// <param name="step"></param>
        public void LoadStepContext(Android.Support.V4.App.Fragment step)
        {
            var fields = step.GetType().GetFields();

            var args = step.Arguments;

            if (args == null)
            {
                args = new Bundle();
            }

            foreach (var field in fields)
            {
                if (field.CustomAttributes == null || !field.CustomAttributes.Any(a => a.AttributeType == typeof(WizardStateAttribute)))
                {
                    continue; // Only process those fields that are decorated with WizardStateAttribute
                }
                try {
                    if (field.FieldType == typeof(string))
                    {
                        args.PutString(field.Name, ContextBundle.GetString(field.Name));
                    }
                    else if (field.FieldType == typeof(int))
                    {
                        args.PutInt(field.Name, ContextBundle.GetInt(field.Name));
                    }
                    else if (field.FieldType == typeof(bool))
                    {
                        args.PutBoolean(field.Name, ContextBundle.GetBoolean(field.Name));
                    }
                    else if (field.FieldType == typeof(double))
                    {
                        args.PutDouble(field.Name, ContextBundle.GetDouble(field.Name));
                    }
                    else if (field.FieldType == typeof(float))
                    {
                        args.PutFloat(field.Name, ContextBundle.GetFloat(field.Name));
                    }
                    else if (field.FieldType == typeof(short))
                    {
                        args.PutShort(field.Name, ContextBundle.GetShort(field.Name));
                    }
                    else if (field.FieldType == typeof(DateTime))
                    {
                        args.PutLong(field.Name, ContextBundle.GetLong(field.Name));
                    }
                    else if (field.FieldType == typeof(char))
                    {
                        args.PutChar(field.Name, ContextBundle.GetChar(field.Name));
                    }
                    else if (typeof(Parcelable).IsAssignableFrom(field.FieldType))
                    {
                        args.PutParcelable(field.Name, ContextBundle.GetParcelable(field.Name) as IParcelable);
                    }
                    else if (field.FieldType is Java.IO.ISerializable)
                    {
                        args.PutSerializable(field.Name, ContextBundle.GetSerializable(field.Name));
                    }
                    else if (field.FieldType.IsValueType == false)   //Runtime serialization for reference type.. use json.net serialization
                    {
                        args.PutString(field.Name, ContextBundle.GetString(field.Name));
                    }
                    else
                    {
                        //TODO: Add support for arrays
                        throw new ArgumentException(string.Format("Unsuported type. Cannot pass value to variable {0} of step {1}. Variable type is unsuported.",
                                                                  field.Name, step.GetType().FullName));
                    }
                }
                catch (FieldAccessException f) {
                    throw new ArgumentException(string.Format("Unable to access the field: {0}. Only public fields are supported", field.Name), f);
                }
            }

            if (step is WizardFragment)
            {
                BindFields((WizardFragment)step, args);
            }
            else
            {
                step.Arguments = args;
            }
        }
示例#12
0
        /// <summary>
        /// Extracts the data from the Fragment and stores it into the Bundle
        /// </summary>
        /// <param name="step"></param>
        public void PersistStepContext(Android.Support.V4.App.Fragment step)
        {
            var fields = step.GetType().GetFields();

            foreach (var field in fields)
            {
                if (field.CustomAttributes == null || !field.CustomAttributes.Any(a => a.AttributeType == typeof(WizardStateAttribute)))
                {
                    continue; // Only process those fields that are decorated with WizardStateAttribute
                }
                try {
                    if (field.FieldType == typeof(string))
                    {
                        ContextBundle.PutString(field.Name, field.GetValue(step) as string);
                    }
                    else if (field.FieldType == typeof(int))
                    {
                        ContextBundle.PutInt(field.Name, (int)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(bool))
                    {
                        ContextBundle.PutBoolean(field.Name, (bool)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(double))
                    {
                        ContextBundle.PutDouble(field.Name, (double)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(float))
                    {
                        ContextBundle.PutFloat(field.Name, (float)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(short))
                    {
                        ContextBundle.PutShort(field.Name, (short)field.GetValue(step));
                    }
                    else if (field.FieldType == typeof(DateTime))
                    {
                        ContextBundle.PutLong(field.Name, ((DateTime)field.GetValue(step)).Ticks);
                    }
                    else if (field.FieldType == typeof(char))
                    {
                        ContextBundle.PutChar(field.Name, (char)field.GetValue(step));
                    }
                    else if (typeof(Parcelable).IsAssignableFrom(field.FieldType))   //Support for Pacelable to be deprecated
                    {
                        ContextBundle.PutParcelable(field.Name, field.GetValue(step) as IParcelable);
                    }
                    else if (field.FieldType is Java.IO.ISerializable)   //Support for Java.IO.ISerializable to be deprecated
                    {
                        ContextBundle.PutSerializable(field.Name, field.GetValue(step) as Java.IO.ISerializable);
                    }
                    else if (field.FieldType.IsValueType == false)   //Runtime serialization for reference type.. use json.net serialization
                    {
                        ContextBundle.PutString(field.Name, Newtonsoft.Json.JsonConvert.SerializeObject(field.GetValue(step)));
                    }
                    else
                    {
                        //TODO: Add support for arrays
                        throw new ArgumentException(string.Format("Unsuported type. Cannot pass value to variable {0} of step {1}. Variable type is unsuported.",
                                                                  field.Name, step.GetType().FullName));
                    }
                }
                catch (FieldAccessException f) {
                    throw new ArgumentException(string.Format("Unable to access the field: {0}. Only public fields are supported", field.Name), f);
                }
            }
        }