示例#1
0
		public static AColor ToAndroid(this Color self, Color defaultColor)
		{
			if (self == Color.Default)
				return defaultColor.ToAndroid();

			return ToAndroid(self);
		}
示例#2
0
		public void UpdateTextColor(TextView control, Color color)
		{
			if (color == _currentTextColor)
				return;

			_currentTextColor = color;

			if (color.IsDefault)
				control.SetTextColor(_defaultTextColors);
			else
			{
				// Set the new enabled state color, preserving the default disabled state color
				int defaultDisabledColor = _defaultTextColors.GetColorForState(s_colorStates[1], color.ToAndroid());
				control.SetTextColor(new ColorStateList(s_colorStates, new[] { color.ToAndroid().ToArgb(), defaultDisabledColor }));
			}
		}
示例#3
0
		public object Create(Color startColor, Color endColor, PointF startPoint, PointF endPoint)
		{
			var shader = new ag.LinearGradient(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, startColor.ToAndroid(), endColor.ToAndroid(), 
				// is this correct?
				ag.Shader.TileMode.Clamp);
			var paint = new ag.Paint();
			paint.SetShader(shader);
			return new BrushObject { Paint = paint }; // TODO: initial matrix
		}
示例#4
0
		public object Create(Color color)
		{
			var result = new ag.Paint
			{
				Color = color.ToAndroid(),
			};
			result.SetStyle(ag.Paint.Style.Fill);
			return result;
		}
示例#5
0
        void UpdateBorderColor()
        {
            if (_disposed)
            {
                return;
            }

            Color borderColor = Element.BorderColor;

            _backgroundDrawable.SetStroke(3, borderColor.IsDefault ? AColor.White : borderColor.ToAndroid());
        }
示例#6
0
文件: PenHandler.cs 项目: mhusen/Eto
		public object Create(Color color, float thickness)
		{
			var paint = new ag.Paint 
			{ 
				Color = color.ToAndroid(), 
				StrokeWidth = thickness,
				StrokeCap = ag.Paint.Cap.Square,
				StrokeMiter = 10f
			};
			return paint;
		}
示例#7
0
        protected virtual ColorStateList GetItemTextColorStates()
        {
            if (IsDisposed)
            {
                return(null);
            }

            if (_originalTabTextColors == null)
            {
                _originalTabTextColors = (IsBottomTabPlacement) ? _bottomNavigationView.ItemTextColor : _tabLayout.TabTextColors;
            }

            Color barItemColor         = BarItemColor;
            Color barTextColor         = Element.BarTextColor;
            Color barSelectedItemColor = BarSelectedItemColor;

            if (barItemColor.IsDefault && barTextColor.IsDefault && barSelectedItemColor.IsDefault)
            {
                return(_originalTabTextColors);
            }

            if (_newTabTextColors != null)
            {
                return(_newTabTextColors);
            }

            int checkedColor;
            int defaultColor;

            if (!barTextColor.IsDefault)
            {
                checkedColor = barTextColor.ToAndroid().ToArgb();
                defaultColor = checkedColor;
            }
            else
            {
                defaultColor = barItemColor.ToAndroid().ToArgb();

                if (barItemColor.IsDefault && _originalTabTextColors != null)
                {
                    defaultColor = _originalTabTextColors.DefaultColor;
                }

                checkedColor = defaultColor;

                if (!barSelectedItemColor.IsDefault)
                {
                    checkedColor = barSelectedItemColor.ToAndroid().ToArgb();
                }
            }

            _newTabTextColors = GetColorStateList(defaultColor, checkedColor);
            return(_newTabTextColors);
        }
示例#8
0
        protected override void UpdateBackgroundColor()
        {
            Color colorToSet = Element.Color;

            if (_backgroundDrawable == null)
            {
                _backgroundDrawable = new GradientDrawable();
            }

            if (colorToSet != Color.Default)
            {
                _backgroundDrawable.SetColor(colorToSet.ToAndroid());
            }
            else
            {
                _backgroundDrawable.SetColor(colorToSet.ToAndroid(Color.Transparent));
            }

            this.SetBackground(_backgroundDrawable);
        }
示例#9
0
        protected override void UpdateBackgroundColor()
        {
            Color colorToSet = Element.Color;

            if (colorToSet == Color.Default)
            {
                colorToSet = Element.BackgroundColor;
            }

            SetBackgroundColor(colorToSet.ToAndroid(Color.Transparent));
        }
示例#10
0
            void SetTabColors () {
                for (int i = 0; i < Element.Children.Count; ++i) {
                    Page page = Element.Children[i];

                    Color tabColor = BottomBarPageExtensions.GetTabColor (page);

                    if (tabColor != Color.Transparent) {
                        _bottomBar.MapColorForTab (i, tabColor.ToAndroid ());
                    }
                }
            }
示例#11
0
        void UpdateBackgroundColor()
        {
            if (_disposed)
            {
                return;
            }

            Color bgColor = Element.BackgroundColor;

            _backgroundDrawable.SetColor(bgColor.IsDefault ? AColor.White : bgColor.ToAndroid());
        }
示例#12
0
 public void SetTheme(Color color)
 {
     if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.M)
     {
         Device.BeginInvokeOnMainThread(() =>
         {
             var currentWindow = GetCurrentWindow();
             currentWindow.DecorView.SystemUiVisibility = 0;
             currentWindow.SetStatusBarColor(color.ToAndroid());
         });
     }
 }
        public void SetStatusBarColor(string color)
        {
            Color barColor = Color.FromHex(color);

            //(Android.App.Application.Context as FormsAppCompatActivity).Window.SetStatusBarColor(barColor.ToAndroid());

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                var c = MainActivity.context as FormsAppCompatActivity;
                c?.RunOnUiThread(() => c.Window.SetStatusBarColor(barColor.ToAndroid()));
            }
        }
        public void ChangeStatusBarColor(Color color)
        {
            MainActivity main = ((MainActivity)CrossCurrentActivity.Current.Activity);

            // Set the status bar color.
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                main.Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
                main.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                main.Window.SetStatusBarColor(color.ToAndroid()); //main.Window.SetStatusBarColor(new Android.Graphics.Color(30, 138, 118));
            }
        }
示例#15
0
        protected override void OnStart()
        {
            base.OnStart();

            var window = Window;

            window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            window.ClearFlags(WindowManagerFlags.TranslucentStatus);
            Color color = (Color)Xamarin.Forms.Application.Current.Resources["Primary"];

            window.SetStatusBarColor(color.ToAndroid());
        }
示例#16
0
        public object Create(Color color, float thickness)
        {
            var paint = new ag.Paint
            {
                Color       = color.ToAndroid(),
                StrokeWidth = thickness,
                StrokeCap   = ag.Paint.Cap.Square,
                StrokeMiter = 10f
            };

            return(paint);
        }
示例#17
0
        public void ChangeStatusBarColor(Color color)
        {
            var activity = (FormsAppCompatActivity)Material.Context;

            var isColorDark = color.ToAndroid().IsColorDark();

            activity.SetStatusBarColor(color.ToAndroid());

            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                if (!isColorDark)
                {
                    activity.Window.DecorView.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.LightStatusBar;
                }

                else
                {
                    activity.Window.DecorView.SystemUiVisibility = StatusBarVisibility.Visible;
                }
            }
        }
示例#18
0
        public static ICharSequence GetTitle(Color titleColor, string title)
        {
            if (titleColor == null)
            {
                return(new Java.Lang.String(title));
            }

            var spannableTitle = new SpannableString(title ?? "");

            spannableTitle.SetSpan(new ForegroundColorSpan(titleColor.ToAndroid()), 0, spannableTitle.Length(), SpanTypes.ExclusiveExclusive);
            return(spannableTitle);
        }
        protected virtual void SetBackgroundColor(BottomNavigationView bottomView, Color color)
        {
            var    menuView                  = bottomView.GetChildAt(0) as BottomNavigationMenuView;
            var    oldBackground             = bottomView.Background;
            var    colorDrawable             = oldBackground as ColorDrawable;
            var    colorChangeRevealDrawable = oldBackground as ColorChangeRevealDrawable;
            AColor lastColor                 = colorChangeRevealDrawable?.EndColor ?? colorDrawable?.Color ?? Color.Default.ToAndroid();
            AColor newColor;

            if (color == Color.Default)
            {
                newColor = Color.White.ToAndroid();
            }
            else
            {
                newColor = color.ToAndroid();
            }

            if (menuView == null)
            {
                if (colorDrawable != null && lastColor == newColor)
                {
                    return;
                }

                if (lastColor != newColor || colorDrawable == null)
                {
                    bottomView.SetBackground(new ColorDrawable(newColor));
                }
            }
            else
            {
                if (colorChangeRevealDrawable != null && lastColor == newColor)
                {
                    return;
                }

                var index = ((IShellItemController)_shellItem).GetItems().IndexOf(_shellItem.CurrentItem);
                var menu  = bottomView.Menu;
                index = Math.Min(index, menu.Size() - 1);

                var child = menuView.GetChildAt(index);
                if (child == null)
                {
                    return;
                }

                var touchPoint = new Point(child.Left + (child.Right - child.Left) / 2, child.Top + (child.Bottom - child.Top) / 2);

                bottomView.SetBackground(new ColorChangeRevealDrawable(lastColor, newColor, touchPoint));
            }
        }
示例#20
0
        protected void UpdateBackgroundColor()
        {
            if (Element == null)
            {
                return;
            }

            Color backgroundColor = Element.BackgroundColor;

            if (backgroundColor.IsDefault)
            {
                if (SupportBackgroundTintList != null)
                {
                    Context context = Context;
                    int     id      = GlobalResource.Attribute.ButtonTint;
                    unchecked
                    {
                        using (var value = new TypedValue())
                        {
                            try
                            {
                                Resources.Theme theme = context.Theme;
                                if (theme != null && theme.ResolveAttribute(id, value, true))
#pragma warning disable 618
                                {
                                    SupportBackgroundTintList = Resources.GetColorStateList(value.Data);
                                }
#pragma warning restore 618
                                else
                                {
                                    SupportBackgroundTintList = new ColorStateList(ColorExtensions.States,
                                                                                   new[] { (int)0xffd7d6d6, 0x7fd7d6d6 });
                                }
                            }
                            catch (Exception ex)
                            {
                                Internals.Log.Warning("Xamarin.Forms.Platform.Android.ButtonRenderer",
                                                      "Could not retrieve button background resource: {0}", ex);
                                SupportBackgroundTintList = new ColorStateList(ColorExtensions.States,
                                                                               new[] { (int)0xffd7d6d6, 0x7fd7d6d6 });
                            }
                        }
                    }
                }
            }
            else
            {
                int intColor     = backgroundColor.ToAndroid().ToArgb();
                int disableColor = backgroundColor.MultiplyAlpha(0.5).ToAndroid().ToArgb();
                SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { intColor, disableColor });
            }
        }
示例#21
0
            void UpdateBackgroundColor()
            {
                Color modalBkgndColor = _modal.BackgroundColor;

                if (modalBkgndColor.IsDefault)
                {
                    _backgroundView.SetWindowBackground();
                }
                else
                {
                    _backgroundView.SetBackgroundColor(modalBkgndColor.ToAndroid());
                }
            }
示例#22
0
 public void SetStatusBarColor(Color color)
 {
     // The SetStatusBarcolor is new since API 21
     if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
     {
         var androidColor = color.ToAndroid();
         CrossCurrentActivity.Current.Activity.Window.SetStatusBarColor(androidColor);
     }
     else
     {
         // Here you will just have to set your color in styles.xml file as above.
     }
 }
示例#23
0
        public void SetColor(Color color)
        {
            var window = MainActivity.CurrentActivity.Window;

            window.SetStatusBarColor(color.ToAndroid());

            // For light colors, switch status bar icons to dark
            // BTW, Color.Default has a -1 luminosity.   Which is hard to deal with, since it should be 0 to 1. So we do a Math.Abs here
            if (Math.Abs(color.Luminosity) > 0.6)
            {
                window.DecorView.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.LightStatusBar;
            }
        }
示例#24
0
		protected virtual void SetColors(Toolbar toolbar, IShellToolbarTracker toolbarTracker, Color foreground, Color background, Color title)
		{
			var titleArgb = title.ToAndroid(ShellRenderer.DefaultTitleColor).ToArgb();

			if (_titleTextColor != titleArgb)
			{
				toolbar.SetTitleTextColor(titleArgb);
				_titleTextColor = titleArgb;
			}

			var newColor = background.ToAndroid(ShellRenderer.DefaultBackgroundColor);
			if (!(toolbar.Background is ColorDrawable cd) || cd.Color != newColor)
			{
				using (var colorDrawable = new ColorDrawable(background.ToAndroid(ShellRenderer.DefaultBackgroundColor)))
					toolbar.SetBackground(colorDrawable);
			}

			var newTintColor = foreground.IsDefault ? ShellRenderer.DefaultForegroundColor : foreground;

			if (toolbarTracker.TintColor != newTintColor)
				toolbarTracker.TintColor = newTintColor;
		}
        private void SetTint()
        {
            ImageView image = this.Control as ImageView;

            if (image == null)
            {
                return;
            }

            Color newColor = Shared.TintEffect.GetTintColor(this.Element);

            image.SetColorFilter(newColor.ToAndroid());
        }
示例#26
0
		protected override void UpdateBackgroundColor()
		{
			Color colorToSet = Element.Color;

			if (colorToSet == Color.Default)
				colorToSet = Element.BackgroundColor;

			if (_backgroundDrawable != null) {

				if (colorToSet != Color.Default)
					_backgroundDrawable.SetColor(colorToSet.ToAndroid());
				else
					_backgroundDrawable.SetColor(colorToSet.ToAndroid(Color.Transparent));

				this.SetBackground(_backgroundDrawable);
			}
			else {
				if (colorToSet == Color.Default)
					colorToSet = Element.BackgroundColor;
				SetBackgroundColor(colorToSet.ToAndroid(Color.Transparent));
			}
		}
        void UpdateColor()
        {
            Color color = Element.Color;

            if (!color.IsDefault)
            {
                Control.IndeterminateDrawable.SetColorFilter(color.ToAndroid(), PorterDuff.Mode.SrcIn);
            }
            else
            {
                Control.IndeterminateDrawable.ClearColorFilter();
            }
        }
示例#28
0
        public void SetColor(Color color)
        {
            var progress = color.IsDefault ? DefaultColor : color.ToAndroid();

            if (Forms.IsLollipopOrNewer)
            {
                IndeterminateTintList = ColorStateList.ValueOf(progress);
            }
            else
            {
                (Indeterminate ? IndeterminateDrawable : ProgressDrawable).SetColorFilter(color.ToAndroid(), FilterMode.SrcIn);
            }
        }
示例#29
0
        internal static void ApplySeekBarColors(this ASeekBar seekBar, Color progressColor, Color backgroundColor, Color thumbColor)
        {
            seekBar.ApplyProgressBarColors(progressColor, backgroundColor);

            if (Forms.IsLollipopOrNewer)
            {
                if (thumbColor.IsDefault)
                {
                    // reset everything to defaults
                    seekBar.ThumbTintList = seekBar.ProgressTintList;
                }
                else
                {
                    // handle the case where the thumb is set
                    var thumb = thumbColor.ToAndroid();
                    seekBar.ThumbTintList = ColorStateList.ValueOf(thumb);
                }
            }
            else
            {
                seekBar.Thumb.SetColorFilter(thumbColor.ToAndroid(), FilterMode.SrcIn);
            }
        }
示例#30
0
        protected virtual void UpdateBackgroundColor(Color color = null)
        {
            if (Element == null)
            {
                return;
            }

            Color backgroundColor = color ?? Element.BackgroundColor;

            if (backgroundColor != null)
            {
                SetBackgroundColor(backgroundColor.ToAndroid());
            }
        }
示例#31
0
        protected virtual ColorStateList GetItemIconTintColorState()
        {
            if (IsDisposed)
            {
                return(null);
            }

            if (IsBottomTabPlacement)
            {
                if (_orignalTabIconColors == null)
                {
                    _orignalTabIconColors = _bottomNavigationView.ItemIconTintList;
                }
            }
            // this ensures that existing behavior doesn't change
            else if (!IsBottomTabPlacement && BarSelectedItemColor.IsDefault && BarItemColor.IsDefault)
            {
                return(null);
            }

            Color barItemColor         = BarItemColor;
            Color barSelectedItemColor = BarSelectedItemColor;

            if (barItemColor.IsDefault && barSelectedItemColor.IsDefault)
            {
                return(_orignalTabIconColors);
            }

            if (_newTabIconColors != null)
            {
                return(_newTabIconColors);
            }

            int defaultColor = barItemColor.ToAndroid().ToArgb();

            if (barItemColor.IsDefault && _orignalTabIconColors != null)
            {
                defaultColor = _orignalTabIconColors.DefaultColor;
            }

            int checkedColor = defaultColor;

            if (!barSelectedItemColor.IsDefault)
            {
                checkedColor = barSelectedItemColor.ToAndroid().ToArgb();
            }

            _newTabIconColors = GetColorStateList(defaultColor, checkedColor);
            return(_newTabIconColors);
        }
示例#32
0
        private GradientDrawable GetBorderDrawable(Color borderColor, Color backgroundColor, float borderWidth, int borderRadius)
        {
            GradientDrawable gd = new GradientDrawable();

            borderWidth     = borderWidth > 0 ? borderWidth : 0;
            borderRadius    = borderRadius > 0 ? borderRadius : 0;
            borderColor     = borderColor != Color.Default ? borderColor : Color.Transparent;
            backgroundColor = backgroundColor != Color.Default ? backgroundColor : Color.Transparent;

            gd.SetColor(ColorStateList.ValueOf(backgroundColor.ToAndroid()));
            gd.SetStroke((int)borderWidth, ColorStateList.ValueOf(borderColor.ToAndroid()));
            gd.SetCornerRadius((float)borderRadius);
            return(gd);
        }
 void ISetStatusBarColor.SetStatusBarColor(Color color)
 {
     if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
     {
         var androidColor = color.ToAndroid();
         //Just use the plugin
         CrossCurrentActivity.Current.Activity.Window.SetStatusBarColor(androidColor);
     }
     else
     {
         // Here you will just have to set your
         // color in styles.xml file as shown below.
     }
 }
示例#34
0
        public static ICharSequence GetTitle(Color titleColor, string title)
        {
            if (titleColor == null)
            {
                return(new Java.Lang.String(title));
            }

            var spannableTitle = new SpannableString(title ?? "");

#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962
            spannableTitle.SetSpan(new ForegroundColorSpan(titleColor.ToAndroid()), 0, spannableTitle.Length(), SpanTypes.ExclusiveExclusive);
#pragma warning restore CA1416
            return(spannableTitle);
        }
示例#35
0
        void UpdateBarBackgroundColor()
        {
            if (_disposed || _tabLayout == null)
            {
                return;
            }

            Color tintColor = Element.BarBackgroundColor;

            if (Forms.IsLollipopOrNewer)
            {
                if (tintColor.IsDefault)
                {
                    _tabLayout.BackgroundTintMode = null;
                }
                else
                {
                    _tabLayout.BackgroundTintMode = PorterDuff.Mode.Src;
                    _tabLayout.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid());
                }
            }
            else
            {
                if (tintColor.IsDefault && _backgroundDrawable != null)
                {
                    _tabLayout.SetBackground(_backgroundDrawable);
                }
                else if (!tintColor.IsDefault)
                {
                    if (_backgroundDrawable == null)
                    {
                        _backgroundDrawable = _tabLayout.Background;
                    }
                    _tabLayout.SetBackgroundColor(tintColor.ToAndroid());
                }
            }
        }
示例#36
0
文件: PenHandler.cs 项目: mhusen/Eto
		public void SetColor(Pen widget, Color color)
		{
			widget.ToAndroid().Color = color.ToAndroid();
		}