Exemplo n.º 1
0
        public void SetWordList(IEnumerable <FoundWord> lstWords)
        {
            _grdWordList.RemoveAllViews();
            int ndx = 0;

            if (lstWords != null && _mainActivity._chkShowWordList.Checked)
            {
                foreach (var item in lstWords)
                {
                    LetterWheelLayout.GetColorFromFoundWordType(item.foundWordType, out var forecolr, out var backColr);
                    var tv = new TextView(_mainActivity)
                    {
                        Text = item.word,
                    };
                    tv.SetBackgroundColor(backColr);
                    tv.SetTextColor(forecolr);
                    tv.Click += (o, e) =>
                    {
                        MainActivity.DoLookupOnlineDictionary(tv.Text);
                    };
                    var x     = ndx / _grdWordList.RowCount;
                    var y     = ndx - x * _grdWordList.RowCount;
                    var parms = new GridLayout.LayoutParams(GridLayout.InvokeSpec(y), GridLayout.InvokeSpec(x));
                    tv.LayoutParameters = parms;
                    parms.RightMargin   = 5;
//                    ((GridLayout.LayoutParams)(tv.LayoutParameters)).RightMargin = 2;
                    _grdWordList.AddView(tv);
                    ndx++;
                }
            }
            _mainActivity._txtWordListLen.Text = ndx.ToString();
        }
Exemplo n.º 2
0
        void CreateLayout()
        {
            //            dp(Density Pixels), here's a formula to convert PXs from DPs:
            //(int)(< numberOfDPs > *getContext().getResources().getDisplayMetrics().density + 0.5f)
            WindowManager.DefaultDisplay.GetSize(_ptScreenSize);
            SetContentView(Resource.Layout.content_main);
            var layout = FindViewById <RelativeLayout>(Resource.Id.container);

            _txtTitle   = FindViewById <TextView>(Resource.Id.textViewTitle);
            idTitleText = _txtTitle.Id;

            _txtTimer = new TextView(this)
            {
                Id            = idtxtTimer,
                TextSize      = 20,
                TextAlignment = TextAlignment.TextEnd
            };
            layout.AddView(_txtTimer);


            _grdXWord = new GridLayout(this)
            {
                Id            = idGrdXWord,
                ColumnCount   = _nCols,
                RowCount      = _nRows,
                Orientation   = GridOrientation.Horizontal,
                AlignmentMode = GridAlign.Bounds
            };
            //            _grdXWord.SetBackgroundColor(Color.Red);
            layout.AddView(_grdXWord);

            this._viewBorder = new TextView(this)
            {
                Id = idBorder,
            };
            _viewBorder.SetBackgroundColor(Color.Black);
            var bordLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 10);

            _viewBorder.LayoutParameters = bordLP;
            layout.AddView(_viewBorder);

            /// the letterwheel is a circle. want some buttons/ui on either side, so use a 3 col grid layout
            ///
            _gridLayoutLetterWheel = new LinearLayout(this)
            {
                Id          = idLtrWheelView,
                Orientation = Orientation.Horizontal,
            };
            layout.AddView(_gridLayoutLetterWheel);

            var linearLayoutCol0 = new LinearLayout(this)
            {
                Orientation = Orientation.Vertical,
            };

            _gridLayoutLetterWheel.AddView(linearLayoutCol0, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent));

            _btnShuffle = new Button(this)
            {
                Text             = "Shuf",
                TextSize         = 8,
                LayoutParameters = new LinearLayout.LayoutParams(200, LinearLayout.LayoutParams.WrapContent)
            };
            linearLayoutCol0.AddView(_btnShuffle);
            _btnShuffle.Click += (o, e) =>
            {
                _LetterWheelView.Shuffle();
            };

            _txtScore = new TextView(this)
            {
            };
            _txtScore.LayoutParameters = new LinearLayout.LayoutParams(200, LinearLayout.LayoutParams.MatchParent);
            linearLayoutCol0.AddView(_txtScore);

            _txtLenTargetWord = new EditText(this)
            {
                Text             = Xamarin.Essentials.Preferences.Get(prefTargWorLen, 7).ToString(),
                TextSize         = 14,
                LayoutParameters = new LinearLayout.LayoutParams(120, LinearLayout.LayoutParams.WrapContent)
            };
            linearLayoutCol0.AddView(_txtLenTargetWord);

            _txtLenSubword = new EditText(this)
            {
                Text             = Xamarin.Essentials.Preferences.Get(prefSubWordLen, 5).ToString(),
                TextSize         = 14,
                LayoutParameters = new LinearLayout.LayoutParams(120, LinearLayout.LayoutParams.WrapContent)
            };
            linearLayoutCol0.AddView(_txtLenSubword);



            _chkShowWordList = new CheckBox(this)
            {
                Text             = "List",
                TextSize         = 8,
                LayoutParameters = new LinearLayout.LayoutParams(200, LinearLayout.LayoutParams.WrapContent),
                Checked          = Xamarin.Essentials.Preferences.Get(prefShowWordList, true)
            };
            _chkShowWordList.CheckedChange += (o, e) =>
            {
                Xamarin.Essentials.Preferences.Set(prefShowWordList, _chkShowWordList.Checked);
                _ctrlWordList.Visibility   = _chkShowWordList.Checked ? ViewStates.Visible : ViewStates.Invisible;
                _txtWordListLen.Visibility = _chkShowWordList.Checked ? ViewStates.Visible : ViewStates.Invisible;
            };
            linearLayoutCol0.AddView(_chkShowWordList);

            _txtWordListLen = new TextView(this)
            {
                TextSize         = 12,
                LayoutParameters = new LinearLayout.LayoutParams(100, LinearLayout.LayoutParams.WrapContent),
            };
            linearLayoutCol0.AddView(_txtWordListLen);

            var linearLayouCol2 = new LinearLayout(this)
            {
                Orientation = Orientation.Vertical
            };
            var lininside = new LinearLayout(this)
            {
                Orientation = Orientation.Horizontal
            };

            _txtWordSoFar = new TextView(this)
            {
                Id            = idtxtWordSofar,
                TextSize      = 15,
                TextAlignment = TextAlignment.Center
            };
            _txtWordSoFar.Click += (o, e) =>
            {
                DoLookupOnlineDictionary(_txtWordSoFar.Text);
            };
            //            _txtWordSoFar.SetForegroundGravity(GravityFlags.CenterHorizontal);
            lininside.AddView(_txtWordSoFar);
            var p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);

            p.Gravity    = GravityFlags.Center;
            p.LeftMargin = 150;
            p.TopMargin  = 15;
            lininside.LayoutParameters = p;
            linearLayouCol2.AddView(lininside);
            _LetterWheelView = new LetterWheelLayout(this)
            {
                LayoutParameters = new LinearLayout.LayoutParams((int)(0.59 * _ptScreenSize.X), LinearLayout.LayoutParams.WrapContent)
            };
            _LetterWheelView.SetGravity(GravityFlags.Center);
            linearLayouCol2.AddView(_LetterWheelView);
            _gridLayoutLetterWheel.AddView(linearLayouCol2);

            var linearLayoutCol3 = new LinearLayout(this)
            {
                Orientation = Orientation.Vertical,
            };
            var layoutpCol3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);

            layoutpCol3.LeftMargin = 100;
            _gridLayoutLetterWheel.AddView(linearLayoutCol3, layoutpCol3);

            _btnNew = new Button(this)
            {
                Text             = "New",
                TextSize         = 8,
                LayoutParameters = new LinearLayout.LayoutParams(100, LinearLayout.LayoutParams.WrapContent),
            };
            _btnNew.Click += BtnNew_Click;
            linearLayoutCol3.AddView(_btnNew, new LinearLayout.LayoutParams(200, LinearLayout.LayoutParams.WrapContent));

            _txtNumHintsUsed = new TextView(this)
            {
                TextSize         = 12,
                LayoutParameters = new LinearLayout.LayoutParams(100, LinearLayout.LayoutParams.WrapContent),
            };
            linearLayoutCol3.AddView(_txtNumHintsUsed);

            _ctrlWordList = new WordListControl(this);
            {
            };
            //            _ctrlWordList.AddTestWords();
            layout.AddView(_ctrlWordList);


            SetLayoutForOrientation(Android.Content.Res.Orientation.Portrait);
        }