예제 #1
0
        private void FormValidator_Load(object sender, EventArgs e)
        {
            // populate the tree from top-level
            foreach (string modelview in this.m_targets.Keys)
            {
                Concept concept = this.m_targets[modelview];

                TreeNode tnView = new TreeNode();
                tnView.Tag  = concept;
                tnView.Text = modelview;
                this.treeView.Nodes.Add(tnView);

                SortedList <string, Type> listTypes = new SortedList <string, Type>();

                Type[] types = concept.GetType().Assembly.GetTypes();
                foreach (Type t in types)
                {
                    if (t.IsPublic && t.IsClass && !t.IsAbstract && t.Namespace.Equals(concept.GetType().Namespace))
                    {
                        string dispname           = t.Name;
                        DisplayNameAttribute disp = (DisplayNameAttribute)t.GetCustomAttribute(typeof(DisplayNameAttribute));
                        if (disp != null)
                        {
                            dispname = disp.DisplayName;
                        }

                        listTypes.Add(dispname, t);
                    }
                }

                foreach (string sort in listTypes.Keys)
                {
                    Type t = listTypes[sort];

                    TreeNode tn = new TreeNode();
                    tn.Tag  = t;
                    tn.Text = sort;
                    tnView.Nodes.Add(tn);

                    PropertyInfo[] props = t.GetProperties();
                    foreach (PropertyInfo prop in props)
                    {
                        if (prop.Name != "Target")
                        {
                            TreeNode tnProp = new TreeNode();
                            tnProp.Tag  = prop;
                            tnProp.Text = prop.Name;
                            tn.Nodes.Add(tnProp);
                        }
                    }
                }
            }

            this.backgroundWorker.RunWorkerAsync();
        }
예제 #2
0
        protected View CreateConceptView(Concept concept)
        {
            View view;

            var inflater = LayoutInflater.From(Activity.BaseContext);

            if (concept is InputText)
            {
                view = inflater.Inflate(Resource.Layout.InputTextConcept, null);
                if ((concept as InputText).LetterCount > 0)
                {
                    (view as EditText).SetMinEms((concept as InputText).LetterCount);
                }
                else
                {
                    (view as EditText).SetMinEms((concept as InputText).Text.Length - ((concept as InputText).Text.Length / 2));
                }

                if ((concept as InputText).Size > 0)
                {
                    (view as EditText).SetTextSize(Android.Util.ComplexUnitType.Dip, (concept as InputText).Size);
                }
            }
            else if (concept is BaseText)
            {
                var baseText = (concept as BaseText);
                if (baseText.LetterTags != null && baseText.LetterTags.Count > 0)
                {
                    view = ApplyLetterTags(inflater, baseText);
                }
                else
                {
                    view = inflater.Inflate(Resource.Layout.BaseText, null);
                    var tvText = view.FindViewById <TextView>(Resource.Id.tvText);
                    DecorateText(tvText, baseText, new Android.Graphics.Color(
                                     ContextCompat.GetColor(Activity.BaseContext, Resource.Color.neon)),
                                 TextDecorationType.Background);
                    SetTextAlign(tvText, baseText);
                    SetTextColor(tvText, baseText);
                    AdjustTextSize(tvText, baseText);
                }

                if (baseText is ISound && baseText.SoundPath != null)
                {
                    var speakerDecorator = (ViewGroup)inflater.Inflate(Resource.Layout.BaseTextSpeaker, null);
                    speakerDecorator.AddView(view);
                    view = speakerDecorator;
                }

                if (IsTextCardCallback(concept as BaseText))
                {
                    var cardView = (FrameLayout)inflater.Inflate(Resource.Layout.CardConcept, null);

                    if (baseText.Size > 0)
                    {
                        cardView.LayoutParameters = new FrameLayout.LayoutParams(
                            baseText.Size > 0 ? ToPx(baseText.Size) : ViewGroup.LayoutParams.MatchParent,
                            baseText.Size > 0 ? ToPx(baseText.Size) : ViewGroup.LayoutParams.MatchParent);
                    }

                    cardView.AddView(view);
                    view = cardView;
                }
                else
                {
                    if (!baseText.ShowAsPlainText)
                    {
                        var borderedView = (FrameLayout)inflater.Inflate(Resource.Layout.BaseTextBordered, null);
                        borderedView.AddView(view);
                        view = borderedView;
                    }
                }
            }
            else if (concept is Speaker)
            {
                view = inflater.Inflate(Resource.Layout.SpeakerConcept, null);

                if (IsSpeakerCardCallback(concept as Speaker))
                {
                    var cardView = (FrameLayout)inflater.Inflate(Resource.Layout.CardConcept, null);
                    cardView.AddView(view);
                    view = cardView;
                }
                else
                {
                    view.SetBackgroundResource(Resource.Drawable.concept_bordered);
                }
            }
            else if (concept is Picture)
            {
                var picture = concept as Picture;

                view = inflater.Inflate(Resource.Layout.PictureConcept, null);

                if (concept.ActivateOnSuccess || concept.ActivateOnMistake)
                {
                    int defaultSize = (IsSmallHeight() ? 100 : 120);
                    (view as ViewGroup).GetChildAt(0).LayoutParameters = new FrameLayout.LayoutParams(ToPx(defaultSize), ToPx(defaultSize));
                }

                if (picture.Size > 0)
                {
                    (view as ViewGroup).GetChildAt(0).LayoutParameters = new FrameLayout.LayoutParams(
                        picture.Size > 0 ? ToPx(picture.Size) : ViewGroup.LayoutParams.MatchParent,
                        picture.Size > 0 ? ToPx(picture.Size) : ViewGroup.LayoutParams.MatchParent);
                }

                if (!string.IsNullOrEmpty(picture.ImagePath))
                {
                    var bitmap = BitmapLoader.Instance.LoadBitmap(CountPictureItems(), Activity.BaseContext, picture.ImagePath);
                    if (bitmap != null)
                    {
                        var ivPicture = view.FindViewById <ImageView>(Resource.Id.ivPicture);
                        ivPicture.SetImageBitmap(bitmap);
                    }
                }

                if (IsPictureCardCallback(picture))
                {
                    var cardView = (FrameLayout)inflater.Inflate(Resource.Layout.CardConcept, null);
                    cardView.AddView(view);
                    view = cardView;
                }
            }
            else if (concept is Models.Space)
            {
                view = new Android.Widget.Space(Activity.BaseContext);
                view.LayoutParameters = new LinearLayout.LayoutParams(ToPx((concept as Models.Space).Width), ToPx((concept as Models.Space).Height));
            }
            else
            {
                view = inflater.Inflate(Resource.Layout.BaseText, null);
                var tvText = view.FindViewById <TextView>(Resource.Id.tvText);
                tvText.Text = string.Format("Concept type {0} does not exist!", concept.GetType().ToString());
            }

            // Attach concept object to view
            SetTag <Concept>(view, Resource.Id.concept_tag_key, concept);

            // Attach click handler
            view.Click += ConceptView_Click_PlaySound;

            return(view);
        }