Пример #1
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            var   app   = UIScreen.MainScreen.ApplicationFrame;
            Bound bound = new Bound(app.Width, app.Height);

            LayoutBehaviour.Screen(stylesheet, this, _child, bound);

            Rectangle old = _child.Frame;

            _child.Frame = new Rectangle(old.Left + app.Left, old.Top + app.Top, old.Width, old.Height);

            // background color
            _view.BackgroundColor = stylesheet.GetHelper <StyleHelper> ().ColorOrClear <BackgroundColor> (this);

            if (OnLoad != null)
            {
                OnLoad.Execute();
            }

            Frame = new Rectangle(app.Left, app.Top, bound);

            return(bound);
        }
Пример #2
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            // background color
            _view.BackgroundColor = stylesheet.GetHelper <StyleHelper>().ColorOrClear <BackgroundColor> (this);

            return(styleBound);
        }
Пример #3
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            // background color
            _view.SetBackgroundColor(stylesheet
                                     .GetHelper <StyleHelper>()
                                     .ColorOrTransparent <BackgroundColor>(this));

            return(styleBound);
        }
Пример #4
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            var style = stylesheet.GetHelper <StyleHelper>();

            // color
            _view.IndeterminateDrawable.SetColorFilter(style.ColorOrTransparent <Color>(this)
                                                       , Android.Graphics.PorterDuff.Mode.Multiply);

            return(styleBound);
        }
Пример #5
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            var style = stylesheet.GetHelper <StyleHelper>();

            // background color, borders
            var background = style.Background(this, _applicationContext, true);

            _view.SetBackgroundDrawable(background);

            // text color
            _view.SetTextColor(style.ColorOrTransparent <Color>(this));

            // placeholder color
            var hintColor = style.Color <PlaceholderColor>(this);

            if (hintColor != null)
            {
                string text = _view.Text;
                _view.Text = null;
                _view.SetHintTextColor(hintColor.Value);
                _view.Text = text;
            }

            // font
            style.SetFontSettings(this, _view, styleBound.Height);

            // padding
            int pl = style.Padding <PaddingLeft>(this, styleBound.Width).Round();
            int pt = style.Padding <PaddingTop>(this, styleBound.Height).Round();
            int pr = style.Padding <PaddingRight>(this, styleBound.Width).Round();
            int pb = style.Padding <PaddingBottom>(this, styleBound.Height).Round();

            View.SetPadding(pl, pt, pr, pb);

            // text align
            switch (style.TextAlign(this))
            {
            case TextAlign.Align.Left:
                _view.Gravity = GravityFlags.Left;
                break;

            case TextAlign.Align.Center:
                _view.Gravity = GravityFlags.Center;
                break;

            case TextAlign.Align.Right:
                _view.Gravity = GravityFlags.Right;
                break;
            }
            return(styleBound);
        }
Пример #6
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            var style = stylesheet.GetHelper <StyleHelper>();

            // background color, background image, borders
            var background = style.Background(this, ApplicationContext);

            _view.SetBackgroundDrawable(background);

            return(LayoutChildren(stylesheet, styleBound, maxBound));
        }
Пример #7
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            StyleHelper style = stylesheet.GetHelper <StyleHelper>();

            // color
            _view.Color = style.ColorOrClear <Color> (this);

            _view.HidesWhenStopped = true;

            return(styleBound);
        }
Пример #8
0
		bool InitImage (BitMobile.Controls.StyleSheet.StyleSheet stylesheet)
		{
			if (_backgroungImageCache == null) {
				if (Source != null) {
					_backgroungImageCache = UIImage.FromFile (FileSystemProvider.TranslatePath (_context.LocalStorage, Source));
				} else {
					String imgPath = stylesheet.GetHelper<StyleHelper> ().BackgroundImage (this);
					if (imgPath != null)
						_backgroungImageCache = UIImage.LoadFromData (MonoTouch.Foundation.NSData.FromStream (_context.DAL.GetImageByName (imgPath)));
				}
			}

			return _backgroungImageCache != null;
		}
Пример #9
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            StyleHelper style = stylesheet.GetHelper <StyleHelper> ();

            base.Apply(stylesheet, styleBound, maxBound);

            // background color, borders
            style.SetBackgroundSettings(this);

            // text color
            _view.TextColor = style.ColorOrClear <BitMobile.Controls.StyleSheet.Color> (this);

            // placeholder color
            _placeholderColor = style.Color <PlaceholderColor> (this);
            SetupPlaceholder(_placeholder);

            // font
            UIFont f = style.Font(this, styleBound.Height);

            if (f != null)
            {
                _view.Font = f;
            }

            // padding
            _view.PaddingLeft   = style.Padding <PaddingLeft> (this, styleBound.Width);
            _view.PaddingTop    = style.Padding <PaddingTop> (this, styleBound.Height);
            _view.PaddingRight  = style.Padding <PaddingRight> (this, styleBound.Width);
            _view.PaddingBottom = style.Padding <PaddingBottom> (this, styleBound.Height);

            // text align
            switch (style.TextAlign(this))
            {
            case TextAlign.Align.Left:
                _view.TextAlignment = UITextAlignment.Left;
                break;

            case TextAlign.Align.Center:
                _view.TextAlignment = UITextAlignment.Center;
                break;

            case TextAlign.Align.Right:
                _view.TextAlignment = UITextAlignment.Right;
                break;
            }

            _view.Text = _text;

            return(styleBound);
        }
Пример #10
0
 bool InitBackgroundImage(StyleSheet.StyleSheet stylesheet)
 {
     if (_backgroundImageCache == null)
     {
         String imgPath = stylesheet.GetHelper <StyleHelper> ().BackgroundImage(this);
         if (imgPath != null)
         {
             Stream imgStream = _applicationContext.DAL.GetImageByName(imgPath);
             if (imgStream != null)
             {
                 _backgroundImageCache = UIImage.LoadFromData(MonoTouch.Foundation.NSData.FromStream(imgStream));
             }
         }
     }
     return(_backgroundImageCache != null);
 }
Пример #11
0
		public override Bound Apply (StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
		{
			base.Apply (stylesheet, styleBound, maxBound);

			StyleHelper style = stylesheet.GetHelper<StyleHelper> ();

			// background image
			if (InitImage (stylesheet)) {
				_view.Image = _backgroungImageCache;

				// selected-color
				var selectedColor = style.Color<SelectedColor> (this);
				if (selectedColor != null)
					_selectedImage = GetFilteredImage (_backgroungImageCache, selectedColor);
			}

			return styleBound;
		}
Пример #12
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            StyleHelper style = stylesheet.GetHelper <StyleHelper> ();

            // background color, background image, borders
            if (!InitBackgroundImage(stylesheet))
            {
                style.SetBackgroundSettings(this);
            }
            _backgroundColor = _view.BackgroundColor;

            // selected-color
            _selectedColor = style.Color <SelectedColor> (this);

            return(LayoutChildren(stylesheet, styleBound, maxBound));
        }
Пример #13
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            StyleHelper style = stylesheet.GetHelper <StyleHelper> ();

            // background color, background image, borders
            if (!InitBackgroundImage(stylesheet))
            {
                style.SetBackgroundSettings(this);
            }

            Bound bound = LayoutChildren(stylesheet, styleBound, maxBound);

            _view.ContentSize = new SizeF(bound.ContentWidth, bound.ContentHeight);

            return(styleBound);
        }
Пример #14
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            var style = stylesheet.GetHelper <StyleHelper>();

            // background image
            if (Source == null)
            {
                var background = style.Background(this, _applicationContext);
                _view.SetBackgroundDrawable(background);
            }

            //selected color
            _selectedColor = style.Color <SelectedColor>(this);

            return(styleBound);
        }
Пример #15
0
        public bool InitializeImage(BitMobile.Controls.StyleSheet.StyleSheet stylesheet)
        {
            String imgPath = stylesheet.GetHelper <StyleHelper> ().BackgroundImage(this);

            if (imgPath != null)
            {
                System.IO.Stream imgStream = _applicationContext.DAL.GetImageByName(imgPath);
                if (imgStream != null)
                {
                    _backgroundImageCache = UIImage.LoadFromData(MonoTouch.Foundation.NSData.FromStream(imgStream));

                    ImageWidth  = (int)_backgroundImageCache.Size.Width;
                    ImageHeight = (int)_backgroundImageCache.Size.Height;

                    return(true);
                }
            }
            return(false);
        }
Пример #16
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            var style = stylesheet.GetHelper <StyleHelper>();

            // background color, background image, borders
            var background = style.Background(this, _applicationContext);

            _view.SetBackgroundDrawable(background);

            // selected color
            Android.Graphics.Color?selectedColor = style.Color <SelectedColor>(this);
            if (selectedColor != null)
            {
                _selectedBackground = style.ColorWithBorders(this, selectedColor.Value);
            }

            return(LayoutChildren(stylesheet, styleBound, maxBound));
        }
Пример #17
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);


            StyleHelper style = stylesheet.GetHelper <StyleHelper> ();

            // background color, background image, borders
            if (InitBackgroundImage(stylesheet))
            {
                _view.SetBackgroundImage(_backgroundImageCache, UIControlState.Normal);
            }
            else
            {
                style.SetBackgroundSettings(this);
            }

            // font
            UIFont f = style.Font(this, styleBound.Height);

            if (f != null)
            {
                _view.Font = f;
            }

            // text color
            _textColor = style.ColorOrClear <Color> (this);
            _view.SetTitleColor(_textColor, UIControlState.Normal);

            // selected-color
            var selectedColor = style.Color <SelectedColor> (this);

            if (selectedColor != null)
            {
                _view.SetTitleColor(selectedColor, UIControlState.Highlighted);
            }

            _view.SetTitle(_text, UIControlState.Normal);
            return(styleBound);
        }
Пример #18
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            var style = stylesheet.GetHelper <StyleHelper>();

            // background color, background image, borders
            var background = style.Background(this, _applicationContext);

            _view.SetBackgroundDrawable(background);

            // font
            style.SetFontSettings(this, _view, styleBound.Height);

            // text color
            _textColor = style.ColorOrTransparent <Color>(this);
            _view.SetTextColor(_textColor);

            //selected color
            _selectedColor = style.Color <SelectedColor>(this);

            return(styleBound);
        }
Пример #19
0
        public bool InitializeImage(StyleSheet.StyleSheet stylesheet)
        {
            bool result = false;

            if (Source != null)
            {
                string path = FileSystemProvider.TranslatePath(_applicationContext.LocalStorage, Source);
                var    img  = (BitmapDrawable)Drawable.CreateFromPath(path);
                if (img != null)
                {
                    View.SetBackgroundDrawable(img);

                    ImageWidth  = img.Bitmap.Width;
                    ImageHeight = img.Bitmap.Height;
                    result      = true;
                }
            }
            else
            {
                result = stylesheet.GetHelper <StyleHelper>().InitializeImageContainer(this, _applicationContext);
            }

            return(result);
        }
Пример #20
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            StyleHelper style = stylesheet.GetHelper <StyleHelper> ();

            _view.Text = _text;

            // background color, borders
            style.SetBackgroundSettings(this);

            //  text-format
            _textFormat = style.TextFormat(this);

            // font
            UIFont f = style.Font(this, styleBound.Height);

            if (f != null)
            {
                _view.Font = f;
            }

            switch (_textFormat)
            {
            case TextFormat.Format.Text:
                _view.Text = _text;

                // text color
                _view.TextColor = _textColor = style.ColorOrClear <BitMobile.Controls.StyleSheet.Color> (this);

                // selected-color
                _selectedColor = style.Color <SelectedColor> (this);

                break;

            case TextFormat.Format.Html:
                string span = string.Format("<span style=\"font-family: {0}; font-size: {1:F0}; color: {2}\">{3}</span>", _view.Font.FamilyName, _view.Font.PointSize, "{0}", "{1}");

                // text color
                _textHtmlSpan = string.Format(span, style.ColorString <BitMobile.Controls.StyleSheet.Color> (this), "{0}");

                // selected-color
                string selectedColor = style.ColorString <SelectedColor> (this);
                if (selectedColor != null)
                {
                    _selectedHtmlSpan = string.Format(span, selectedColor, "{0}");
                }

                SetSpannedText(_textHtmlSpan);
                break;

            default:
                throw new NotImplementedException("Text format not found: " + _textFormat);
            }

            // word wrap
            bool nowrap = style.WhiteSpaceKind(this) == WhiteSpace.Kind.Nowrap;

            if (!nowrap)
            {
                _view.TextContainer.LineBreakMode        = UILineBreakMode.WordWrap;
                _view.TextContainer.MaximumNumberOfLines = 0;
            }
            else
            {
                _view.TextContainer.LineBreakMode        = UILineBreakMode.TailTruncation;
                _view.TextContainer.MaximumNumberOfLines = 1;
            }

            // text align
            switch (style.TextAlign(this))
            {
            case TextAlign.Align.Left:
                _view.TextAlignment = UITextAlignment.Left;
                break;

            case TextAlign.Align.Center:
                _view.TextAlignment = UITextAlignment.Center;
                break;

            case TextAlign.Align.Right:
                if (nowrap)
                {
                    _view.TextContainer.LineBreakMode = UILineBreakMode.HeadTruncation;
                }
                _view.TextAlignment = UITextAlignment.Right;
                break;
            }

            // text padding
            float pl = style.Padding <PaddingLeft> (this, styleBound.Width);
            float pt = style.Padding <PaddingTop> (this, styleBound.Height);
            float pr = style.Padding <PaddingRight> (this, styleBound.Width);
            float pb = style.Padding <PaddingBottom> (this, styleBound.Height);

            _view.TextContainerInset = new UIEdgeInsets(pt, pl, pb, pr);

            Bound resultBound = styleBound;

            // size to content
            bool sizeByWidth  = style.SizeToContentWidth(this);
            bool sizeByHeight = style.SizeToContentHeight(this);

            if (sizeByWidth || sizeByHeight)
            {
                float measureWidth  = sizeByWidth ? maxBound.Width : styleBound.Width;
                float measureHeight = sizeByHeight ? maxBound.Height : styleBound.Height;

                SizeF size = _view.SizeThatFits(new SizeF(measureWidth, measureHeight));

                float w = sizeByWidth ? size.Width + pl + pr : styleBound.Width;
                float h = sizeByHeight ? size.Height + pt + pb : styleBound.Height;

                resultBound = new Bound(w, h);
            }

            return(resultBound);
        }
Пример #21
0
 public bool InitializeImage(StyleSheet.StyleSheet stylesheet)
 {
     return(stylesheet.GetHelper <StyleHelper>().InitializeImageContainer(this, ApplicationContext));
 }
Пример #22
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            var style = stylesheet.GetHelper <StyleHelper>();

            // text-format
            _textFormat = style.TextFormat(this);
            SetText();

            // background color, borders
            var background = style.Background(this, _applicationContext, true);

            _view.SetBackgroundDrawable(background);

            // font
            style.SetFontSettings(this, _view, styleBound.Height);

            // text color
            _textColor = style.ColorOrTransparent <Color>(this);
            _view.SetTextColor(_textColor);

            //selected color
            _selectedColor = style.Color <SelectedColor>(this);

            // word wrap
            bool nowrap = style.WhiteSpaceKind(this) == WhiteSpace.Kind.Nowrap;

            if (nowrap)
            {
                _view.SetSingleLine();
            }

            // text align
            switch (style.TextAlign(this))
            {
            case TextAlign.Align.Left:
                _view.Gravity = GravityFlags.Left | GravityFlags.Top;
                if (nowrap)
                {
                    _view.Ellipsize = Android.Text.TextUtils.TruncateAt.End;
                }
                break;

            case TextAlign.Align.Center:
                _view.Gravity = GravityFlags.Center | GravityFlags.Top;
                if (nowrap)
                {
                    _view.Ellipsize = Android.Text.TextUtils.TruncateAt.End;
                }
                break;

            case TextAlign.Align.Right:
                _view.Gravity = GravityFlags.Right | GravityFlags.Top;
                if (nowrap)
                {
                    _view.Ellipsize = Android.Text.TextUtils.TruncateAt.Start;
                }
                break;
            }

            // text padding
            int pl = style.Padding <PaddingLeft>(this, styleBound.Width).Round();
            int pt = style.Padding <PaddingTop>(this, styleBound.Height).Round();
            int pr = style.Padding <PaddingRight>(this, styleBound.Width).Round();
            int pb = style.Padding <PaddingBottom>(this, styleBound.Height).Round();

            _view.SetPadding(pl, pt, pr, pb);

            bool sizeByWith   = style.SizeToContentWidth(this);
            bool sizeByHeight = style.SizeToContentHeight(this);

            if (sizeByWith || sizeByHeight)
            {
                float measureWidth  = sizeByWith ? maxBound.Width : styleBound.Width;
                float measureHeight = sizeByHeight ? maxBound.Height : styleBound.Height;

                int wspec = View.MeasureSpec.MakeMeasureSpec(Math.Round(measureWidth), MeasureSpecMode.AtMost);
                int hspec = View.MeasureSpec.MakeMeasureSpec(Math.Round(measureHeight), MeasureSpecMode.AtMost);

                _view.Measure(wspec, hspec);
                float w = sizeByWith ? _view.MeasuredWidth : styleBound.Width;
                float h = sizeByHeight ? _view.MeasuredHeight : styleBound.Height;
                return(new Bound(w, h));
            }
            return(styleBound);
        }
Пример #23
0
        public override Bound Apply(StyleSheet.StyleSheet stylesheet, Bound styleBound, Bound maxBound)
        {
            base.Apply(stylesheet, styleBound, maxBound);

            StyleHelper style = stylesheet.GetHelper <StyleHelper> ();

            // background color, borders
            style.SetBackgroundSettings(this);

            // text color
            _view.TextColor = style.ColorOrClear <Color> (this);

            // placeholder color
            UIColor placeholderColor = style.Color <PlaceholderColor> (this);

            if (placeholderColor != null)
            {
                _placeholderView.TextColor = placeholderColor;
            }

            // font
            UIFont f = style.Font(this, styleBound.Height);

            if (f != null)
            {
                _view.Font = f;
            }

            // padding
            float pl = style.Padding <PaddingLeft> (this, styleBound.Width);
            float pt = style.Padding <PaddingTop> (this, styleBound.Height);
            float pr = style.Padding <PaddingRight> (this, styleBound.Width);
            float pb = style.Padding <PaddingBottom> (this, styleBound.Height);

            if (ApplicationContext.OSVersion.Major >= 7)
            {
                _view.TextContainerInset = new UIEdgeInsets(pt, pl, pb, pr);
            }

            // text align
            switch (style.TextAlign(this))
            {
            case TextAlign.Align.Left:
                _view.TextAlignment = UITextAlignment.Left;
                break;

            case TextAlign.Align.Center:
                _view.TextAlignment = UITextAlignment.Center;
                break;

            case TextAlign.Align.Right:
                _view.TextAlignment = UITextAlignment.Right;
                break;
            }

            _placeholderView.Font  = _view.Font;
            _placeholderView.Frame = new System.Drawing.RectangleF(pl, pt, maxBound.Width - (pl + pr), maxBound.Height - (pt + pb));
            _placeholderView.SizeToFit();

            return(styleBound);
        }