コード例 #1
1
//        protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
//        {
//            base.OnElementChanged(e);
//            var entry = (EntryWithValidation)e.NewElement;
//            if (entry != null)
//                Control.Background = CreateBorderForEntry(entry.BorderWidth, entry.BorderColor.ToAndroid(), entry.CornerRadius);
//        }


        GradientDrawable CreateBorderForEntry(int width, Android.Graphics.Color color, float cornerRadius, Android.Graphics.Color backgroundColor)
        {
            var gDrawable = new GradientDrawable(); 
            gDrawable.SetColor (backgroundColor);
            gDrawable.SetStroke(CorrectCornerWithDensity(width), color);
            gDrawable.SetCornerRadius(cornerRadius * Resources.DisplayMetrics.Density + 0.5F);
 
            return gDrawable;
        }
コード例 #2
0
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                var button = (CustomButton)e.NewElement;

                button.SizeChanged += (s, args) =>
                {
                    // Estado normal
                    _normal = new GradientDrawable();
                    _normal.SetColor(Android.Graphics.Color.DarkBlue);
                    _normal.SetCornerRadius(100);

                    // Estado pulsado
                    _pressed = new GradientDrawable();
                    _pressed.SetColor(Android.Graphics.Color.DarkCyan);
                    _pressed.SetCornerRadius(100);

                    var sld = new StateListDrawable();
                    sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                    sld.AddState(new int[] { }, _normal);
                    Control.SetBackgroundDrawable(sld);
                    Control.SetTextSize(ComplexUnitType.Px, 60);
                    Control.SetTextColor(Android.Graphics.Color.Silver);
                };
            }
        }
コード例 #3
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);
            if (e.NewElement != null)
            {
                var view = (CustomEntry)Element;
                if (view.IsCurvedCornersEnabled)
                {
                    // creating gradient drawable for the curved background
                    var _gradientBackground = new Android.Graphics.Drawables.GradientDrawable();
                    _gradientBackground.SetShape(ShapeType.Rectangle);
                    _gradientBackground.SetColor(view.BackgroundColor.ToAndroid());

                    // Thickness of the stroke line
                    _gradientBackground.SetStroke(view.BorderWidth, view.BorderColor.ToAndroid());

                    // Radius for the curves
                    _gradientBackground.SetCornerRadius(
                        DpToPixels(this.Context, Convert.ToSingle(view.CornerRadius)));

                    // set the background of the
                    Control.SetBackground(_gradientBackground);
                }
                // Set padding for the internal text from border
                Control.SetPadding(
                    (int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingTop,
                    (int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingBottom);
            }
        }
コード例 #4
0
        public BasicPackageManagerView(Context context)
            : base(context, Resource.Drawable.icon_menu_round)
        {
            // Initialize & style Status label
            StatusLabel = new TextView(context);
            StatusLabel.SetTextColor(Color.Black);

            GradientDrawable background = new GradientDrawable();
            background.SetCornerRadius(5);
            background.SetColor(Color.Argb(160, 255, 255, 255));
            StatusLabel.Background = background;

            StatusLabel.Gravity = Android.Views.GravityFlags.Center;
            StatusLabel.Typeface = Typeface.Create("HelveticaNeue", TypefaceStyle.Normal);

            DisplayMetrics screen = Resources.DisplayMetrics;

            int width = screen.WidthPixels / 2;
            int height = width / 4;

            int x = screen.WidthPixels / 2 - width / 2;
            int y = screen.HeightPixels / 100;

            var parameters = new RelativeLayout.LayoutParams(width, height);
            parameters.TopMargin = y;
            parameters.LeftMargin = x;

            AddView(StatusLabel, parameters);

            Menu = new CityChoiceMenu(context);
            AddView(Menu);
        }
コード例 #5
0
		protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
		{
			base.OnElementChanged(e);

			if (Control != null)
			{
				var button = e.NewElement;

				// Create a drawable for the button's normal state
				_normal = new Android.Graphics.Drawables.GradientDrawable();

				if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
					_normal.SetColor(Android.Graphics.Color.ParseColor("#ff2c2e2f"));
				else
					_normal.SetColor(button.BackgroundColor.ToAndroid());

				_normal.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
				_normal.SetCornerRadius(button.BorderRadius);

				// Create a drawable for the button's pressed state
				_pressed = new Android.Graphics.Drawables.GradientDrawable();
				var highlight = Context.ObtainStyledAttributes(new int[] { Android.Resource.Attribute.ColorActivatedHighlight }).GetColor(0, Android.Graphics.Color.Gray);
				_pressed.SetColor(highlight);
				_pressed.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
				_pressed.SetCornerRadius(button.BorderRadius);

				// Add the drawables to a state list and assign the state list to the button
				var sld = new StateListDrawable();
				sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
				sld.AddState(new int[] { }, _normal);
				Control.SetBackgroundDrawable(sld);
			}
		}
コード例 #6
0
        // resolves: button text alignment lost after click or IsEnabled change
        //public override void ChildDrawableStateChanged(Android.Views.View child)
        //{
        //  base.ChildDrawableStateChanged(child);
        //  Control.Text = Control.Text;
        //}

        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);
            if (!string.IsNullOrEmpty(e.NewElement?.FontFamily))
            {
                try
                {
                    var font = Typeface.CreateFromAsset(Forms.Context.ApplicationContext.Assets, e.NewElement.FontFamily + ".ttf");
                    Control.Typeface = font;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            if (Control != null)
            {
                SetAlignment();
                UpdatePadding();

                var density      = Math.Max(1, Resources.DisplayMetrics.Density);
                var button       = e.NewElement;
                var mode         = MeasureSpec.GetMode((int)button.BorderRadius);
                var borderRadius = button.BorderRadius * density;
                var borderWidth  = button.BorderWidth * density;

                // Create a drawable for the button's normal state
                _normal = new Android.Graphics.Drawables.GradientDrawable();

                if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
                {
                    _normal.SetColor(Android.Graphics.Color.ParseColor("#B2B2B2"));
                }
                else
                {
                    _normal.SetColor(button.BackgroundColor.ToAndroid());
                }

                _normal.SetStroke((int)borderWidth, button.BorderColor.ToAndroid());
                _normal.SetCornerRadius(borderRadius);

                // Create a drawable for the button's pressed state
                _pressed = new Android.Graphics.Drawables.GradientDrawable();
                var highlight = Context.ObtainStyledAttributes(new int[]
                {
                    Android.Resource.Attribute.ColorAccent                                                              //  .ColorActivatedHighlight
                }).GetColor(0, Android.Graphics.Color.Gray);

                _pressed.SetColor(highlight);
                _pressed.SetStroke((int)borderWidth, button.BorderColor.ToAndroid());
                _pressed.SetCornerRadius(borderRadius);

                // Add the drawables to a state list and assign the state list to the button
                var sld = new StateListDrawable();
                sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                sld.AddState(new int[] { }, _normal);
                //Control.SetBackground(sld);       //.SetBackgroundDrawable(sld); // deprecated
            }
        }
コード例 #7
0
        protected override void OnElementChanged(ElementChangedEventArgs <Button> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var button = e.NewElement;
                _normal = new GradientDrawable();

                if (button.BackgroundColor.R.Equals(-1) && button.BackgroundColor.G.Equals(-1) && button.BackgroundColor.B.Equals(-1))
                {
                    _normal.SetColor(Android.Graphics.Color.ParseColor("#ff2c2e2f"));
                }
                else
                {
                    _normal.SetColor(button.BackgroundColor.ToAndroid());
                }

                _normal.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _normal.SetCornerRadius(button.BorderRadius);

                // Create a drawable for the button's pressed state
                _pressed = new Android.Graphics.Drawables.GradientDrawable();
                var highlight = Context.ObtainStyledAttributes(new int[] { Android.Resource.Attribute.ColorActivatedHighlight }).GetColor(0, Android.Graphics.Color.Gray);
                _pressed.SetColor(highlight);
                _pressed.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _pressed.SetCornerRadius(button.BorderRadius);

                // Add the drawables to a state list and assign the state list to the button
                var sld = new StateListDrawable();
                sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                sld.AddState(new int[] { }, _normal);
                Control.Background = sld;
            }
        }
コード例 #8
0
        internal static GradientDrawable getBadgeDrawable(BadgeItem badgeItem, Context context)
        {
            GradientDrawable shape = new GradientDrawable();

            shape.SetShape(ShapeType.Rectangle);
            shape.SetCornerRadius(context.Resources.GetDimensionPixelSize(Resource.Dimension.badge_corner_radius));
            shape.SetColor(new Color(badgeItem.GetBackgroundColor(context)));
            shape.SetStroke(badgeItem.BorderWidth, new Color(badgeItem.GetBorderColor(context)));
            return(shape);
        }
コード例 #9
0
 /// <summary>
 /// ,
 /// </summary>
 /// <param name="e"></param>
 protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
 {
     base.OnElementChanged (e);
     if (e.OldElement==null && e.NewElement!=null) {
         var shape =  new GradientDrawable();
         shape.SetCornerRadius(((RoundedCornerView)e.NewElement).CornerRadius);
         shape.SetColor (Xamarin.Forms.Color.Transparent.ToAndroid ().ToArgb ());
         shape.SetStroke ((int)((RoundedCornerView)e.NewElement).BorderThickness, ((RoundedCornerView)e.NewElement).BorderColor.ToAndroid ());
         this.SetBackground(shape);
     }
 }
コード例 #10
0
        void SetFone(SearchBar button)
        {
            GradientDrawable _normal, _pressed;

            // Create a drawable for the button's normal state
            _normal = new Android.Graphics.Drawables.GradientDrawable();
            _normal.SetColor(button.BackgroundColor.ToAndroid());
            _normal.SetStroke(30, Android.Graphics.Color.Red);
            _normal.SetCornerRadius(5);
            this.Control.SetBackground(_normal);
        }
コード例 #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged (sender, e);
     if (e.PropertyName==RoundedCornerView.BorderColorProperty.PropertyName || e.PropertyName==RoundedCornerView.BorderThicknessProperty.PropertyName) {
         var shape =  new GradientDrawable();
         shape.SetCornerRadius(((RoundedCornerView)Element).CornerRadius);
         shape.SetColor (Xamarin.Forms.Color.Transparent.ToAndroid ().ToArgb ());
         shape.SetStroke ((int)((RoundedCornerView)Element).BorderThickness, ((RoundedCornerView)Element).BorderColor.ToAndroid ());
         this.SetBackground(shape);
     }
 }
コード例 #12
0
        private void UpdateLayout()
        {
            var label = Element as RoundedLabel;

            var background = new Android.Graphics.Drawables.GradientDrawable();

            background.SetCornerRadius((int)label.CornerRadius);
            background.SetStroke((int)label.BorderWidth, label.BorderColor.ToAndroid());
            background.SetColor(label.BackgroundColor.ToAndroid());
            SetBackgroundColor(Android.Graphics.Color.Transparent);
            SetBackgroundDrawable(background);
        }
コード例 #13
0
        protected override async void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);
            UpdateAlignment();
            UpdateFont();
            UpdatePadding();
            //UpdateMargin();

            _density = Resources.DisplayMetrics.Density;
            var targetButton = Control;
            if (targetButton != null) targetButton.SetOnTouchListener(TouchListener.Instance.Value);

            if (Element != null && Element.Font != Font.Default && targetButton != null) targetButton.Typeface = Element.Font.ToExtendedTypeface(Context);

            if (Element != null && BaseButton.Source != null) await SetImageSourceAsync(targetButton, BaseButton).ConfigureAwait(false);


            if (Control != null)
            {
                var button = e.NewElement;


                // Create a drawable for the button's normal state
                _normal = new Android.Graphics.Drawables.GradientDrawable();

                if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
                    _normal.SetColor(Android.Graphics.Color.ParseColor(buttonWhite));
                else
                    _normal.SetColor(button.BackgroundColor.ToAndroid());

                _normal.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _normal.SetCornerRadius(button.BorderRadius);


                // Create a drawable for the button's pressed state
                _pressed = new Android.Graphics.Drawables.GradientDrawable();
                var highlight = Android.Graphics.Color.ParseColor(buttonGrey);
                //var highlight = Context.ObtainStyledAttributes(new int[] { Android.Resource.Attribute.ColorActivatedHighlight }).GetColor(0, Android.Graphics.Color.ParseColor(buttonWhite));
                _pressed.SetColor(highlight);
                _pressed.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _pressed.SetCornerRadius(button.BorderRadius);

                // Add the drawables to a state list and assign the state list to the button
                var sld = new StateListDrawable();
                sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                sld.AddState(new int[] { }, _normal);
                Control.SetBackgroundDrawable(sld);
            }
        }
コード例 #14
0
        // resolves: button text alignment lost after click or IsEnabled change
        //public override void ChildDrawableStateChanged(Android.Views.View child)
        //{
        //  base.ChildDrawableStateChanged(child);
        //  Control.Text = Control.Text;
        //}

        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                SetAlignment();

                var density      = Math.Max(1, Resources.DisplayMetrics.Density);
                var button       = e.NewElement;
                var mode         = MeasureSpec.GetMode((int)button.BorderRadius);
                var borderRadius = button.BorderRadius * density;
                var borderWidth  = button.BorderWidth * density;

                // Create a drawable for the button's normal state
                _normal = new Android.Graphics.Drawables.GradientDrawable();

                if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
                {
                    _normal.SetColor(Android.Graphics.Color.ParseColor("#ff2c2e2f"));
                }
                else
                {
                    _normal.SetColor(button.BackgroundColor.ToAndroid());
                }

                _normal.SetStroke((int)borderWidth, button.BorderColor.ToAndroid());
                _normal.SetCornerRadius(borderRadius);

                // Create a drawable for the button's pressed state
                _pressed = new Android.Graphics.Drawables.GradientDrawable();
                var highlight = Context.ObtainStyledAttributes(new int[]
                {
                    Android.Resource.Attribute.ColorAccent                      //  .ColorActivatedHighlight
                }).GetColor(0, Android.Graphics.Color.Gray);

                _pressed.SetColor(highlight);
                _pressed.SetStroke((int)borderWidth, button.BorderColor.ToAndroid());
                _pressed.SetCornerRadius(borderRadius);

                // Add the drawables to a state list and assign the state list to the button
                var sld = new StateListDrawable();
                sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                sld.AddState(new int[] { }, _normal);
                Control.SetBackground(sld);     //.SetBackgroundDrawable(sld); // deprecated
            }
        }
コード例 #15
0
		private void init(Context context, IAttributeSet attrs) {
			mMinProgress = 0;
			mMaxProgress = 100;

			mProgressDrawable = (GradientDrawable) getDrawable(Resource.Drawable.rect_progress).Mutate();
			mProgressDrawable.SetCornerRadius(getCornerRadius());

			mCompleteDrawable = (GradientDrawable) getDrawable(Resource.Drawable.rect_complete).Mutate();
			mCompleteDrawable.SetCornerRadius(getCornerRadius());

			mErrorDrawable = (GradientDrawable) getDrawable(Resource.Drawable.rect_error).Mutate();
			mErrorDrawable.SetCornerRadius(getCornerRadius());

			if (attrs != null) {
				initAttributes(context, attrs);
			}
		}
コード例 #16
0
        private Toast FormatToast(Toast toast)
        {
            toast.SetGravity(GravityFlags.Center, 0, 0);
            View toastView = toast.View;

            GradientDrawable toastBackground = new Android.Graphics.Drawables.GradientDrawable();

            toastBackground.SetColor(Android.Graphics.Color.ParseColor(Constants.ToastMessageBackgroundColor));
            toastBackground.SetCornerRadius((float)35.0);
            toastView.SetBackgroundDrawable(toastBackground);

            TextView toastMessage = (TextView)toastView.FindViewById(Android.Resource.Id.Message);

            toastMessage.SetTextColor(Android.Graphics.Color.ParseColor(Constants.ToastMessageTextColor));

            return(toast);
        }
コード例 #17
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var button = e.NewElement;
                btn = e.NewElement as PopupSaveButton;

                // Create a drawable for the button's normal state
                _normal = new Android.Graphics.Drawables.GradientDrawable();

                if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
                {
                    _normal.SetColor(Android.Graphics.Color.ParseColor(Globals.WHITE));
                }
                else
                if (button.BackgroundColor != Color.Black)
                {
                    _normal.SetColor(button.BackgroundColor.ToAndroid());
                }
                else
                {
                    _normal.SetColor(Android.Graphics.Color.ParseColor(Globals.WHITE));
                }

                _normal.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _normal.SetCornerRadius(10);

                // Create a drawable for the button's pressed state
                _pressed = new Android.Graphics.Drawables.GradientDrawable();
                var highlight = Context.ObtainStyledAttributes(new int[] { Android.Resource.Attribute.ColorActivatedHighlight }).GetColor(0, Android.Graphics.Color.ParseColor(Globals.RED));
                _pressed.SetColor(highlight);
                _pressed.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _pressed.SetCornerRadius(button.BorderRadius);

                // Add the drawables to a state list and assign the state list to the button
                var sld = new StateListDrawable();
                sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                sld.AddState(new int[] { }, _normal);
                Control.SetBackgroundDrawable(sld);
            }
        }
コード例 #18
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var button = (StyledButton)e.NewElement;

                button.SizeChanged += (s, args) =>
                {
                    var radius = (float)Math.Min(button.Width, button.Height);

                    // Create a drawable for the button's normal state
                    _normal = new Android.Graphics.Drawables.GradientDrawable(GradientDrawable.Orientation.TopBottom, new[] {
                        Color.FromRgba(255, 255, 255, 255).ToAndroid().ToArgb(),
                        Color.FromRgba(17, 77, 10, 50).ToAndroid().ToArgb()
                    });

                    /*if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
                     *  _normal.SetColor(Android.Graphics.Color.ParseColor("#ff2c2e2f"));
                     * else
                     *  _normal.SetColor(button.BackgroundColor.ToAndroid());
                     */
                    _normal.SetCornerRadius(radius);

                    // Create a drawable for the button's pressed state
                    _pressed = new Android.Graphics.Drawables.GradientDrawable(GradientDrawable.Orientation.BottomTop, new[] {
                        Color.FromRgba(255, 255, 255, 255).ToAndroid().ToArgb(),
                        Color.FromRgba(17, 77, 10, 50).ToAndroid().ToArgb()
                    });
                    //var highlight = Context.ObtainStyledAttributes(new int[] { Android.Resource.Attribute.ColorActivatedHighlight }).GetColor(0, Android.Graphics.Color.Gray);
                    //_pressed.SetColor(highlight);
                    _pressed.SetCornerRadius(radius);

                    // Add the drawables to a state list and assign the state list to the button
                    var sld = new StateListDrawable();
                    sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                    sld.AddState(new int[] { }, _normal);
                    Control.SetBackgroundDrawable(sld);
                    Control.SetTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.White));
                };
            }
        }
コード例 #19
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var button = (RoundedButton)e.NewElement;

                button.SizeChanged += (s, args) =>
                {
                    var radius = (float)Math.Min(button.Width, button.Height) * 2;

                    // Create a drawable for the button's normal state
                    _normal = new Android.Graphics.Drawables.GradientDrawable();

                    if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
                    {
                        _normal.SetColor(Android.Graphics.Color.ParseColor("#ff2c2e2f"));
                    }
                    else
                    {
                        _normal.SetColor(button.BackgroundColor.ToAndroid());
                    }

                    _normal.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                    _normal.SetCornerRadius(radius);

                    // Create a drawable for the button's pressed state
                    _pressed = new Android.Graphics.Drawables.GradientDrawable();
                    var highlight = Context.ObtainStyledAttributes(new int[] { Android.Resource.Attribute.ColorActivatedHighlight }).GetColor(0, Android.Graphics.Color.Gray);
                    _pressed.SetColor(highlight);
                    _pressed.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                    _pressed.SetCornerRadius(radius);

                    // Add the drawables to a state list and assign the state list to the button
                    var sld = new StateListDrawable();
                    sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                    sld.AddState(new int[] { }, _normal);
                    Control.SetBackgroundDrawable(sld);
                };
            }
        }
コード例 #20
0
        public static void UpdateBackground(Border border, Android.Views.View view)
        {
            var strokeThickness = border.StrokeThickness;
            var context = view.Context;

            // create stroke drawable
            GradientDrawable strokeDrawable = null;

            // if thickness exists, set stroke drawable stroke and radius
            if(strokeThickness.HorizontalThickness + strokeThickness.VerticalThickness > 0) {
                strokeDrawable = new GradientDrawable ();
                strokeDrawable.SetColor (border.BackgroundColor.ToAndroid ());

                // choose thickest margin
                // the content is padded so it will look like the margin is with the given thickness
                strokeDrawable.SetStroke ((int)context.ToPixels (strokeThickness.ThickestSide()), border.Stroke.ToAndroid ());
                strokeDrawable.SetCornerRadius ((float)border.CornerRadius);
            }

            // create background drawable
            var backgroundDrawable = new GradientDrawable ();

            // set background drawable color based on Border's background color
            backgroundDrawable.SetColor (border.BackgroundColor.ToAndroid ());
            backgroundDrawable.SetCornerRadius((float)border.CornerRadius);

            if (strokeDrawable != null) {
                // if stroke drawable exists, create a layer drawable containing both stroke and background drawables
                var ld = new LayerDrawable (new Drawable[] { strokeDrawable, backgroundDrawable });
                ld.SetLayerInset (1, (int)context.ToPixels (strokeThickness.Left), (int)context.ToPixels (strokeThickness.Top), (int)context.ToPixels (strokeThickness.Right), (int)context.ToPixels (strokeThickness.Bottom));
                view.SetBackgroundDrawable (ld);
            } else {
                view.SetBackgroundDrawable (backgroundDrawable);
            }

            // set Android.View's padding to take into account the stroke thickiness
            view.SetPadding (
                (int)context.ToPixels (strokeThickness.Left + border.Padding.Left),
                (int)context.ToPixels (strokeThickness.Top + border.Padding.Top),
                (int)context.ToPixels (strokeThickness.Right + border.Padding.Right),
                (int)context.ToPixels (strokeThickness.Bottom + border.Padding.Bottom));
        }
コード例 #21
0
ファイル: BetterFrameRenderer.cs プロジェクト: cyanray/Cuckoo
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Frame> e)
        {
            base.OnElementChanged(e);

            var extFrame = e.NewElement as BetterFrame;

            var gd = new Android.Graphics.Drawables.GradientDrawable();

            gd.SetColor(extFrame.BackgroundColor.ToAndroid());

            gd.SetCornerRadius((float)extFrame.CornerRadius);

            if (extFrame.BorderStroke > 0)
            {
                // TODO: Supporting line border.
                // TODO:Supporting custom dashed line.
                gd.SetStroke(extFrame.BorderStroke, extFrame.BorderColor.ToAndroid(), 10f, 10f);
            }

            this.Background = gd;
        }
コード例 #22
0
ファイル: ButtonRenderer.cs プロジェクト: danya140/BonchApp
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);
            button = this.Control; button.SetAllCaps(false);
            var      label = (Android.Widget.Button)Control;                                          // for example
            Typeface font  = Typeface.CreateFromAsset(Forms.Context.Assets, "Fonts/RobotoLight.ttf"); // font name specified here

            label.Typeface = font;
            if (Control != null)
            {
                var button = e.NewElement;

                // Create a drawable for the button's normal state
                _normal = new Android.Graphics.Drawables.GradientDrawable();

                if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
                {
                    _normal.SetColor(Android.Graphics.Color.ParseColor("#95ffffff"));
                }
                else
                {
                    _normal.SetColor(Android.Graphics.Color.ParseColor("#95ffffff"));
                }
                _normal.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _normal.SetCornerRadius(button.BorderRadius);

                // Create a drawable for the button's pressed state
                _pressed = new Android.Graphics.Drawables.GradientDrawable();
                var highlight = Context.ObtainStyledAttributes(new int[] { Android.Resource.Attribute.ColorActivatedHighlight }).GetColor(0, Android.Graphics.Color.Gray);
                _pressed.SetColor(Android.Graphics.Color.ParseColor("#30ffffff"));
                _pressed.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _pressed.SetCornerRadius(button.BorderRadius);

                // Add the drawables to a state list and assign the state list to the button
                var sld = new StateListDrawable();
                sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                sld.AddState(new int[] { }, _normal);
                Control.SetBackgroundDrawable(sld);
            }
        }
コード例 #23
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            String rdText = this.Text.ToString();
            Paint textPaint = new Paint();
            textPaint.AntiAlias = true;
            textPaint.TextSize = this.TextSize;
            textPaint.TextAlign = Android.Graphics.Paint.Align.Center;

            float canvasWidth = canvas.Width;
            float textWidth = textPaint.MeasureText(rdText);

            if (Checked)
            {
                this.SetBackgroundResource(Resource.Drawable.RoundedShape);
                int[] colors = new int[] { this.Context.Resources.GetColor(Resource.Color.radioUnselectTop), this.Context.Resources.GetColor(Resource.Color.radioSelectTop )};
                GradientDrawable grad = new GradientDrawable(GradientDrawable.Orientation.TopBottom, colors);
                grad.SetBounds(0, 0, this.Width, this.Height);
                grad.SetCornerRadius(7f);
                this.SetBackgroundDrawable(grad);
            }
            else
            {
                this.SetBackgroundResource(Resource.Drawable.RoundedShape);
                int[] colors = new int[] { this.Context.Resources.GetColor(Resource.Color.radioUnselectTop), this.Context.Resources.GetColor(Resource.Color.radioUnselectBottom) };
                GradientDrawable grad = new GradientDrawable(GradientDrawable.Orientation.TopBottom, colors);
                grad.SetBounds(0, 0, this.Width, this.Height);
                grad.SetCornerRadius(7f);
                this.SetBackgroundDrawable(grad);
            }

            Paint paint = new Paint();
            paint.Color = Color.Transparent;
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            Rect rect = new Rect(0, 0, this.Width, this.Height);
            canvas.DrawRect(rect, paint);

            base.OnDraw(canvas);
        }
コード例 #24
0
        private void UpdateColors()
        {
            var button = Element as ShadowButton;

            var normal = new Android.Graphics.Drawables.GradientDrawable ();
            normal.SetColor (button.BackgroundColor.ToAndroid ());
            normal.SetStroke ((int)button.BorderWidth, button.BorderColor.ToAndroid ());
            normal.SetCornerRadius (button.BorderRadius);
            var shadow = new Android.Graphics.Drawables.GradientDrawable ();
            shadow.SetColor (button.ShadowColor.ToAndroid ());
            shadow.SetStroke ((int)button.BorderWidth, button.ShadowColor.ToAndroid ());
            shadow.SetCornerRadius (button.BorderRadius);

            _normal = new Android.Graphics.Drawables.LayerDrawable (
                new Drawable [] { shadow, normal }
            );

            var density = 3;

            _normal.SetLayerInset (1, 0, 0, 0, 2 * density);

            _pressed = new Android.Graphics.Drawables.GradientDrawable ();

            var highlight = Context.ObtainStyledAttributes (new int [] {
                Android.Resource.Attribute.ColorActivatedHighlight
            }).GetColor(0, Android.Graphics.Color.Gray);
            _pressed.SetColor (highlight);
            _pressed.SetStroke ((int)button.BorderWidth, button.BorderColor.ToAndroid ());
            _pressed.SetCornerRadius (button.BorderRadius);

            var sld = new StateListDrawable ();
            sld.AddState (new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
            sld.AddState (new int[] {}, _normal );

            Control.SetPaddingRelative (0, 0, 2, 0);
            Control.SetBackgroundDrawable (sld);
        }
コード例 #25
0
ファイル: CustomButtonRenderer.cs プロジェクト: hd910/Hungry
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                var button = e.NewElement;

                // Create a drawable for the button's normal state
                _normal = new Android.Graphics.Drawables.GradientDrawable();

                if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
                {
                    _normal.SetColor(Android.Graphics.Color.ParseColor("#ff2c2e2f"));
                }
                else
                {
                    _normal.SetColor(button.BackgroundColor.ToAndroid());
                }

                _normal.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _normal.SetCornerRadius(button.BorderRadius);

                // Create a drawable for the button's pressed state
                _pressed = new Android.Graphics.Drawables.GradientDrawable();
                _pressed.SetColor(Android.Graphics.Color.ParseColor("#f0472a"));
                _pressed.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _pressed.SetCornerRadius(button.BorderRadius);

                // Add the drawables to a state list and assign the state list to the button
                var sld = new StateListDrawable();
                sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                sld.AddState(new int[] { }, _normal);
                Control.SetBackgroundDrawable(sld);
            }
        }
コード例 #26
0
		public static void SetTheme(CheckBox checkBox, FlatTheme theme, 
			FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, int radius, int size, int border)
		{
			// creating unchecked-enabled state drawable
			GradientDrawable uncheckedEnabled = new GradientDrawable();
			uncheckedEnabled.SetCornerRadius(radius);
			uncheckedEnabled.SetSize(size, size);
			uncheckedEnabled.SetColor(Color.Transparent);
			uncheckedEnabled.SetStroke(border, theme.LightAccentColor);

			// creating checked-enabled state drawable
			GradientDrawable checkedOutside = new GradientDrawable();
			checkedOutside.SetCornerRadius(radius);
			checkedOutside.SetSize(size, size);
			checkedOutside.SetColor(Color.Transparent);
			checkedOutside.SetStroke(border, theme.LightAccentColor);

			PaintDrawable checkedCore = new PaintDrawable(theme.LightAccentColor);
			checkedCore.SetCornerRadius(radius);
			checkedCore.SetIntrinsicHeight(size);
			checkedCore.SetIntrinsicWidth(size);
			InsetDrawable checkedInside = new InsetDrawable(checkedCore, border + 2, border + 2, border + 2, border + 2);

			Drawable[] checkedEnabledDrawable = {checkedOutside, checkedInside};
			LayerDrawable checkedEnabled = new LayerDrawable(checkedEnabledDrawable);

			// creating unchecked-enabled state drawable
			GradientDrawable uncheckedDisabled = new GradientDrawable();
			uncheckedDisabled.SetCornerRadius(radius);
			uncheckedDisabled.SetSize(size, size);
			uncheckedDisabled.SetColor(Color.Transparent);
			uncheckedDisabled.SetStroke(border, theme.VeryLightAccentColor);

			// creating checked-disabled state drawable
			GradientDrawable checkedOutsideDisabled = new GradientDrawable();
			checkedOutsideDisabled.SetCornerRadius(radius);
			checkedOutsideDisabled.SetSize(size, size);
			checkedOutsideDisabled.SetColor(Color.Transparent);
			checkedOutsideDisabled.SetStroke(border, theme.VeryLightAccentColor);

			PaintDrawable checkedCoreDisabled = new PaintDrawable(theme.VeryLightAccentColor);
			checkedCoreDisabled.SetCornerRadius(radius);
			checkedCoreDisabled.SetIntrinsicHeight(size);
			checkedCoreDisabled.SetIntrinsicWidth(size);
			InsetDrawable checkedInsideDisabled = new InsetDrawable(checkedCoreDisabled, border + 2, border + 2, border + 2, border + 2);

			Drawable[] checkedDisabledDrawable = {checkedOutsideDisabled, checkedInsideDisabled};
			LayerDrawable checkedDisabled = new LayerDrawable(checkedDisabledDrawable);


			StateListDrawable states = new StateListDrawable();
			states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled}, uncheckedEnabled);
			states.AddState(new int[]{Android.Resource.Attribute.StateChecked, Android.Resource.Attribute.StateEnabled}, checkedEnabled);
			states.AddState(new int[]{-Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled}, uncheckedDisabled);
			states.AddState(new int[]{Android.Resource.Attribute.StateChecked, -Android.Resource.Attribute.StateEnabled}, checkedDisabled);
			checkBox.SetButtonDrawable(states);

			// setting padding for avoiding text to be appear on icon
			checkBox.SetPadding(size / 4 * 5, 0, 0, 0);
			checkBox.SetTextColor(theme.LightAccentColor);

			var typeface = FlatUI.GetFont(checkBox.Context, fontFamily, fontWeight);
			if (typeface != null) 
				checkBox.SetTypeface(typeface, TypefaceStyle.Normal);
		}
コード例 #27
0
        public static Drawable ColorWithBorders(this IStyleSheet styleSheet, IStyledObject control, Color color)
        {
            IStyleSheetHelper helper = styleSheet.Helper;
            Drawable drawable;
            if (styleSheet.Helper.HasBorder(control))
            {
                var shape = new GradientDrawable();
                var borderWidth = (int)Math.Round(helper.BorderWidth(control));
                Color borderColor = ToColorOrTransparent(helper.BorderColor(control));

                shape.SetShape(ShapeType.Rectangle);
                shape.SetColor(color);
                shape.SetCornerRadius(helper.BorderRadius(control));
                shape.SetStroke(borderWidth, borderColor);
                drawable = shape;
            }
            else
                drawable = new ColorDrawable(color);
            return drawable;
        }
コード例 #28
0
        public static bool BackgroundChanged(this IStyleHelper helper
            , IStyleSheet styleSheet, IBound bound, out Drawable background, bool whithoutImage = false)
        {
            if (!whithoutImage)
            {
                IBackgroundImage image;
                if (helper.TryGet(out image) && !string.IsNullOrWhiteSpace(image.Path))
                {
                    background = styleSheet.GetCache<ImageCache>().GetImage(image.Path, bound.Width, bound.Height);
                    return true;
                }

                // if control has background image, we have to ignore background color
                if (!string.IsNullOrWhiteSpace(image.Path))
                {
                    background = null;
                    return false;
                }
            }

            IBackgroundColor backgroundColor;
            IBorderStyle borderStyle;
            IBorderWidth borderWidth;
            IBorderColor borderColor;
            IBorderRadius borderRadius;
            if (helper.TryGet(out backgroundColor) | helper.TryGet(out borderStyle) | helper.TryGet(out borderWidth)
                | helper.TryGet(out borderColor) | helper.TryGet(out borderRadius))
            {
                if (borderStyle.Style == BorderStyleValues.Solid)
                {
                    var shape = new GradientDrawable();
                    var width = (int)Math.Round(borderWidth.Value);
                    Color color = borderColor.ToColorOrTransparent();

                    shape.SetShape(ShapeType.Rectangle);
                    shape.SetColor(backgroundColor.ToColorOrTransparent());
                    shape.SetCornerRadius(borderRadius.Radius);
                    shape.SetStroke(width, color);
                    background = shape;
                }
                else
                    background = new ColorDrawable(backgroundColor.ToColorOrTransparent());
                return true;
            }

            background = null;
            return false;
        }
コード例 #29
0
		public static void SetTheme(TextView textView, FlatTheme theme,
			FlatUI.FlatFontFamily fontFamily, FlatUI.FlatFontWeight fontWeight, int textColor, int backgroundColor,
			int customBackgroundColor, int cornerRadius)
		{

			if (backgroundColor != -1)
			{
				var bgColor = theme.DarkAccentColor;

				if (backgroundColor == 0)
					bgColor = theme.DarkAccentColor;
				else if (backgroundColor == 1)
					bgColor = theme.BackgroundColor;
				else if (backgroundColor == 2)
					bgColor = theme.LightAccentColor;
				else if (backgroundColor == 3)
					bgColor = theme.VeryLightAccentColor;

				GradientDrawable gradientDrawable = new GradientDrawable();
				gradientDrawable.SetColor(bgColor);
				gradientDrawable.SetCornerRadius(cornerRadius);
				textView.SetBackgroundDrawable(gradientDrawable);
			} 
			else if (customBackgroundColor != -1) 
			{
				var bgColor = theme.DarkAccentColor;

				if (customBackgroundColor == 0)
					bgColor = theme.DarkAccentColor;
				else if (customBackgroundColor == 1)
					bgColor = theme.BackgroundColor;
				else if (customBackgroundColor == 2)
					bgColor = theme.LightAccentColor;
				else if (customBackgroundColor == 3)
					bgColor = theme.VeryLightAccentColor;

				GradientDrawable gradientDrawable = new GradientDrawable();
				gradientDrawable.SetColor(bgColor);
				gradientDrawable.SetCornerRadius(cornerRadius);
				textView.SetBackgroundDrawable(gradientDrawable);
			}

			var txtColor = theme.VeryLightAccentColor;
			if (textColor == 0)
				txtColor = theme.DarkAccentColor;
			if (textColor == 1)
				txtColor = theme.BackgroundColor;
			if (textColor == 2)
				txtColor = theme.LightAccentColor;
			if (textColor == 3)
				txtColor = theme.VeryLightAccentColor;

			textView.SetTextColor(txtColor);

			var typeface = FlatUI.GetFont(textView.Context, fontFamily, fontWeight);
			if (typeface != null)
				textView.SetTypeface(typeface, TypefaceStyle.Normal);
		}
コード例 #30
0
		public RoundKnobButton(Context context, int back, Bitmap bmpRotorOn, Bitmap bmpRotorOff, int w, int h)
            : base(context)
        {
			Console.WriteLine("RoundKnobButton :: ctor :: Start");

			// We won't wait for our size to be calculated, we'll just store our fixed size
			m_Width = w; 
			m_Height = h;

			m_BmpRotorOn = bmpRotorOn;
			m_BmpRotorOff = bmpRotorOff;

			//
			// Create stator
			//
			ImageView ivBack = new ImageView(context);
			ivBack.SetImageResource(back);
			RelativeLayout.LayoutParams lp_ivBack = new RelativeLayout.LayoutParams(w, h);
			lp_ivBack.AddRule(LayoutRules.CenterInParent);
			AddView(ivBack, lp_ivBack);

			// 
			// Create Rotor
			// 

			m_RotorImaveView = new ImageView(context);
			m_RotorImaveView.SetImageBitmap(bmpRotorOff);

			RelativeLayout.LayoutParams lp_ivKnob = new RelativeLayout.LayoutParams(w, h);//LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			lp_ivKnob.AddRule(LayoutRules.CenterInParent);
			AddView(m_RotorImaveView, lp_ivKnob);

			SetState(true);

			//
			// Create Current Value Text
			//
			m_CurrentValueTextView = new TextView(context);
			m_CurrentValueTextView.SetTextSize(Android.Util.ComplexUnitType.Dip, 20);
			m_CurrentValueTextView.Gravity = GravityFlags.Center;
			RelativeLayout.LayoutParams lp_cvKnob = new RelativeLayout.LayoutParams(LayoutParams.WrapContent, h / 2);
			lp_cvKnob.AddRule(LayoutRules.CenterInParent);
			AddView(m_CurrentValueTextView, lp_cvKnob);

			// Border for TextView
			GradientDrawable gd = new GradientDrawable();
			gd.SetColor(20); // Changes this drawbale to use a single color instead of a gradient
			gd.SetCornerRadius(5);
			gd.SetStroke(1, Color.LightGray);
			// m_CurrentValueTextView.Background = gd;

			//
			// Circles
			//
			m_InnerCircle = new CircleView(context, w, h, w / 8);
			m_InnerCircle.Visibility = (m_ShowTouchPath) ? ViewStates.Visible : ViewStates.Invisible;
			RelativeLayout.LayoutParams lp_circle = new RelativeLayout.LayoutParams(w, h);
			lp_circle.AddRule(LayoutRules.CenterInParent);
			AddView(m_InnerCircle, lp_circle);

			m_OuterCircle = new CircleView(context, w, h, w / 3);
			m_OuterCircle.Visibility = (m_ShowTouchPath) ? ViewStates.Visible : ViewStates.Invisible;
			RelativeLayout.LayoutParams lp_circle2 = new RelativeLayout.LayoutParams(w, h);
			lp_circle2.AddRule(LayoutRules.CenterInParent);
			AddView(m_OuterCircle, lp_circle2);

			// Enable Gesture Detector
			gestureDetector = new GestureDetector(Context, this);
        }
コード例 #31
0
ファイル: UITextField.cs プロジェクト: Gerhic/Need2Park
		public void SetSlightlyRoundWithBackgroundColor (Color color)
		{
			GradientDrawable background = new GradientDrawable ();
			background.SetCornerRadius (Sizes.CornerRadius);
			background.SetColor (color);

			Background = background;
		}
コード例 #32
0
ファイル: Logon.cs プロジェクト: Fedorm/core-master
        public void Start(string message, string exceptionMessage = null)
        {
            Activity.FlipScreen(Resource.Layout.Logon);

            using (var userName = Activity.FindViewById<EditText>(Resource.Id.userName))
            using (var password = Activity.FindViewById<EditText>(Resource.Id.password))
            using (var loginButton = Activity.FindViewById<TextView>(Resource.Id.login))
            using (var demoButton = Activity.FindViewById<TextView>(Resource.Id.demo))
            using (var caption = Activity.FindViewById<TextView>(Resource.Id.caption))
            using (var caption1 = Activity.FindViewById<TextView>(Resource.Id.caption1))
            using (var caption2 = Activity.FindViewById<TextView>(Resource.Id.caption2))
            using (var bottomText1 = Activity.FindViewById<TextView>(Resource.Id.bottomText1))
            using (var bottomText2 = Activity.FindViewById<TextView>(Resource.Id.bottomText2))
            using (var messageText = Activity.FindViewById<TextView>(Resource.Id.loginMessage))
            using (var topImg = Activity.FindViewById<ImageView>(Resource.Id.imageViewTop))
            using (var bottomImg = Activity.FindViewById<ImageView>(Resource.Id.imageViewBottom))
            using (var lockImg = Activity.FindViewById<ImageView>(Resource.Id.lockImage))
            using (var logoImg = Activity.FindViewById<ImageView>(Resource.Id.logoImage))
            using (var topBitmap = (BitmapDrawable)topImg.Drawable)
            using (var botBitmap = (BitmapDrawable)bottomImg.Drawable)
            {
                userName.Hint = D.USER_NAME;
                password.Hint = D.PASSWORD;
                loginButton.Text = D.LOGON;
                demoButton.Text = D.DEMO;
                caption.Text = D.BIT_MOBILE;

                int width = Activity.Resources.DisplayMetrics.WidthPixels;

                int topHeight = topBitmap.Bitmap.Height * width / topBitmap.Bitmap.Width;
                topImg.LayoutParameters.Width = width;
                topImg.LayoutParameters.Height = topHeight;

                int botHeight = botBitmap.Bitmap.Height * width / botBitmap.Bitmap.Width;
                bottomImg.LayoutParameters.Width = width;
                bottomImg.LayoutParameters.Height = botHeight;

                const int radius = 10;

                Color baseColor = GetBaseColor();

                using (var shape = new GradientDrawable())
                {
                    shape.SetShape(ShapeType.Rectangle);
                    shape.SetColor(Color.Transparent);
                    shape.SetCornerRadius(radius);
                    shape.SetStroke(2, baseColor);
                    userName.SetBackgroundDrawable(shape);
                    password.SetBackgroundDrawable(shape);
                }

                using (var shape = new GradientDrawable())
                {
                    shape.SetShape(ShapeType.Rectangle);
                    shape.SetCornerRadius(radius);
                    shape.SetStroke(0, Color.Transparent);

                    Color buttonColor = GetLoginButtonColor();
                    shape.SetColor(buttonColor);
                    loginButton.SetBackgroundDrawable(shape);
                }

                using (var shape = new GradientDrawable())
                {
                    shape.SetShape(ShapeType.Rectangle);
                    shape.SetCornerRadius(radius);
                    shape.SetStroke(0, Color.Transparent);
                    Color buttonColor = GetDemoButtonColor();
                    shape.SetColor(buttonColor);
                    demoButton.SetBackgroundDrawable(shape);
                }

                messageText.Text = message;
                if (exceptionMessage != null)
                    messageText.SetTextColor(new Color(247, 71, 71));

                userName.Text = Settings.UserName;
                password.Text = Settings.DevelopModeEnabled || exceptionMessage != null ? Settings.Password : "";

                loginButton.Click += LoginButtonClick;
                demoButton.Click += DemoButtonOnClick;
                demoButton.Visibility = Settings.DemoEnabled ? ViewStates.Visible : ViewStates.Gone;

                if (Settings.CurrentSolutionType != SolutionType.BitMobile)
                {
                    caption.Text = "";

                    using (Drawable d = userName.GetCompoundDrawables()[0])
                        d.SetColorFilter(baseColor, PorterDuff.Mode.SrcIn);
                    using (Drawable d = password.GetCompoundDrawables()[0])
                        d.SetColorFilter(baseColor, PorterDuff.Mode.SrcIn);
                    lockImg.Drawable.SetColorFilter(baseColor, PorterDuff.Mode.SrcIn);
                    caption.Visibility = ViewStates.Invisible;
                    bottomText1.Text = D.EFFECTIVE_SOLUTIONS_BASED_ON_1C_FOR_BUSINESS;
                    bottomText2.Text = D.FIRST_BIT_COPYRIGHT;

                    SetBackground(topImg, bottomImg, caption1, caption2, logoImg);
                }
            }

            if (exceptionMessage != null && Settings.DevelopModeEnabled)
                using (var builder = new AlertDialog.Builder(Activity))
                {
                    builder.SetTitle(message);
                    builder.SetMessage(exceptionMessage);
                    builder.SetPositiveButton(D.OK, (sender, e) => { });
                    builder.Show();
                }

            if (Settings.WaitDebuggerEnabled)
                Toast.MakeText(Activity, "Waiting for debugger to attach", ToastLength.Long).Show();
        }
コード例 #33
0
		void updateBackground ()
		{
			var location = WuClient.Shared.Selected;

			var random = location == null || Settings.RandomBackgrounds;

			var gradients = location.GetTimeOfDayGradient (random);

			using (var gd = new GradientDrawable (GradientDrawable.Orientation.TopBottom, gradients.Item1.ToArray ()))
			{
				gd.SetCornerRadius (0f);

				if (viewPager.Background == null)
				{
					viewPager.Background = gd;

					Window.SetStatusBarColor (gradients.Item1 [0]);
					Window.SetNavigationBarColor (gradients.Item1 [1]);
				}
				else
				{
					var backgrounds = new Drawable [2];

					backgrounds [0] = viewPager.Background;
					backgrounds [1] = gd;

					var crossfader = new TransitionDrawable (backgrounds);

					viewPager.Background = crossfader;

					crossfader.StartTransition (1000);

					var statusBarAnimator = ValueAnimator.OfArgb (Window.StatusBarColor, gradients.Item1 [0]);

					statusBarAnimator.SetDuration (1000);
					statusBarAnimator.SetInterpolator (new AccelerateDecelerateInterpolator ());

					statusBarAnimator.Update += (sender, e) =>
					{
						var val = e.Animation.AnimatedValue as Java.Lang.Integer;

						var color = new Color ((int)val);

						Window.SetStatusBarColor (color);
					};

					var naviationBarAnimator = ValueAnimator.OfArgb (Window.NavigationBarColor, gradients.Item1 [1]);

					naviationBarAnimator.SetDuration (1000);
					naviationBarAnimator.SetInterpolator (new AccelerateDecelerateInterpolator ());

					naviationBarAnimator.Update += (sender, e) =>
					{
						var val = e.Animation.AnimatedValue as Java.Lang.Integer;

						var color = new Color ((int)val);

						Window.SetNavigationBarColor (color);
					};

					statusBarAnimator.Start ();
					naviationBarAnimator.Start ();
				}
			}
		}
コード例 #34
0
ファイル: UIView.cs プロジェクト: Gerhic/Need2Park
		public void SetRoundBordersWithColor (Color color, int currentSize, int strokeSize)
		{
			GradientDrawable outerBackground = new GradientDrawable ();
			outerBackground.SetCornerRadius (currentSize);
			outerBackground.SetStroke (strokeSize, color);

			Background = outerBackground;
		}
コード例 #35
0
ファイル: UIView.cs プロジェクト: Gerhic/Need2Park
		public void SetRoundWithColor (Color color, int currentSize)
		{
			GradientDrawable background = new GradientDrawable ();
			background.SetCornerRadius (currentSize);
			background.SetColor (color);

			Background = background;

			RemoveBorders ();
		}
コード例 #36
0
ファイル: UIView.cs プロジェクト: Gerhic/Need2Park
		public void SetSlightlyRoundWithBackgroundColor (Color color)
		{
			var cornerRadius = 6 * DeviceInfo.Density;
			GradientDrawable background = new GradientDrawable ();
			background.SetCornerRadius (cornerRadius);
			background.SetColor (color);

			Background = background;

			RemoveBorders ();
		}
コード例 #37
0
ファイル: UILabel.cs プロジェクト: Gerhic/Need2Park
		public void SetSlightlyRoundWithBackgroundColor (Color color, int radius = 0)
		{
			GradientDrawable background = new GradientDrawable ();
			if (radius == 0) {
				background.SetCornerRadius (MeasuredHeight / 10);
			} else {
				background.SetCornerRadius (radius);
			}
			background.SetColor (color);

			Background = background;
		}
コード例 #38
0
        public static void Init(MaterialDialog dialog)
        {
            MaterialDialog.Builder builder = dialog.MBuilder;

            dialog.SetCancelable(builder.Cancelable);
            dialog.SetCanceledOnTouchOutside(builder.Cancelable);
            if (builder.BackgroundColor == 0)
                builder.BackgroundColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_background_color);

            if (builder.BackgroundColor != 0)
            {
                GradientDrawable drawable = new GradientDrawable();
                drawable.SetCornerRadius(builder.Context.Resources.GetDimension(Resource.Dimension.sino_droid_md_bg_corner_radius));
                drawable.SetColor(builder.BackgroundColor);
                DialogUtils.SetBackgroundCompat(dialog.GetView(), drawable);
            }

            if (!builder.PositiveColorSet)
                builder.PositiveColor = DialogUtils.ResolveActionTextColorStateList(builder.Context, Resource.Attribute.sino_droid_md_positive_color, builder.PositiveColor);
            if (!builder.NeutralColorSet)
                builder.NeutralColor = DialogUtils.ResolveActionTextColorStateList(builder.Context, Resource.Attribute.sino_droid_md_neutral_color, builder.NeutralColor);
            if (!builder.NegativeColorSet)
                builder.NegativeColor = DialogUtils.ResolveActionTextColorStateList(builder.Context, Resource.Attribute.sino_droid_md_negative_color, builder.NegativeColor);
            if (!builder.WidgetColorSet)
                builder.WidgetColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_widget_color, builder.WidgetColor);

            if (!builder.TitleColorSet)
            {
                int titleColorFallback = DialogUtils.ResolveColor(dialog.Context, Android.Resource.Attribute.TextColorPrimary);
                builder.TitleColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_title_color, titleColorFallback);
            }

            if (!builder.ContentColorSet)
            {
                int contentColorFallback = DialogUtils.ResolveColor(dialog.Context, Android.Resource.Attribute.TextColorSecondary);
                builder.ContentColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_content_color, contentColorFallback);
            }
            if (!builder.ItemColorSet)
                builder.ItemColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_item_color, builder.ContentColor);

            dialog.Title = dialog.GetView().FindViewById<TextView>(Resource.Id.title);
            dialog.Icon = dialog.GetView().FindViewById<ImageView>(Resource.Id.icon);
            dialog.TitleFrame = dialog.GetView().FindViewById(Resource.Id.titleFrame);
            dialog.Content = dialog.GetView().FindViewById<TextView>(Resource.Id.content);
            dialog.ListView = dialog.GetView().FindViewById<ListView>(Resource.Id.contentListView);

            dialog.PositiveButton = dialog.GetView().FindViewById<MDButton>(Resource.Id.buttonDefaultPositive);
            dialog.NeutralButton = dialog.GetView().FindViewById<MDButton>(Resource.Id.buttonDefaultNeutral);
            dialog.NegativeButton = dialog.GetView().FindViewById<MDButton>(Resource.Id.buttonDefaultNegative);

            if (builder.InputCallback != null && builder.PositiveText == null)
                builder.PositiveText = builder.Context.GetText(Android.Resource.String.Ok);

            dialog.PositiveButton.Visibility = builder.PositiveText != null ? ViewStates.Visible : ViewStates.Gone;
            dialog.NeutralButton.Visibility = builder.NeutralText != null ? ViewStates.Visible : ViewStates.Gone;
            dialog.NegativeButton.Visibility = builder.NegativeText != null ? ViewStates.Visible : ViewStates.Gone;

            if (builder.Icon != null)
            {
                dialog.Icon.Visibility = ViewStates.Visible;
                dialog.Icon.SetImageDrawable(builder.Icon);
            }
            else
            {
                Drawable d = DialogUtils.ResolveDrawable(builder.Context, Resource.Attribute.sino_droid_md_icon);
                if (d != null)
                {
                    dialog.Icon.Visibility = ViewStates.Visible;
                    dialog.Icon.SetImageDrawable(d);
                }
                else
                {
                    dialog.Icon.Visibility = ViewStates.Gone;
                }
            }

            int maxIconSize = builder.MaxIconSize;
            if (maxIconSize == -1)
                maxIconSize = DialogUtils.ResolveDimension(builder.Context, Resource.Attribute.sino_droid_md_icon_max_size);
            if (builder.LimitIconToDefaultSize || DialogUtils.ResolveBoolean(builder.Context, Resource.Attribute.sino_droid_md_icon_limit_icon_to_default_size))
                maxIconSize = builder.Context.Resources.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_icon_max_size);
            if (maxIconSize > -1)
            {
                dialog.Icon.SetAdjustViewBounds(true);
                dialog.Icon.SetMaxHeight(maxIconSize);
                dialog.Icon.SetMaxWidth(maxIconSize);
                dialog.Icon.RequestLayout();
            }

            if (!builder.DividerColorSet)
            {
                int dividerFallback = DialogUtils.ResolveColor(dialog.Context, Resource.Attribute.sino_droid_md_divider);
                builder.DividerColor = DialogUtils.ResolveColor(builder.Context, Resource.Attribute.sino_droid_md_divider_color, dividerFallback);
            }
            dialog.GetView().SetDividerColor(new Color(builder.DividerColor));

            if (dialog.Title != null)
            {
                dialog.SetTypeface(dialog.Title, builder.MediumFont);
                dialog.Title.SetTextColor(builder.TitleColor);
                dialog.Title.Gravity = GravityExt.GetGravity(builder.TitleGravity);
                if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1)
                {
                    dialog.Title.TextAlignment = GravityExt.GetTextAlignment(builder.TitleGravity);
                }

                if (builder.Title == null)
                {
                    dialog.TitleFrame.Visibility = ViewStates.Gone;
                }
                else
                {
                    dialog.Title.Text = builder.Title;
                    dialog.TitleFrame.Visibility = ViewStates.Visible;
                }
            }

            if (dialog.Content != null)
            {
                dialog.Content.MovementMethod = new LinkMovementMethod();
                dialog.SetTypeface(dialog.Content, builder.RegularFont);
                dialog.Content.SetLineSpacing(0f, builder.ContentLineSpacingMultiplier);
                if (builder.PositiveColor == null)
                    dialog.Content.SetLinkTextColor(DialogUtils.ResolveColor(dialog.Context, Android.Resource.Attribute.TextColorPrimary));
                else
                    dialog.Content.SetLinkTextColor(builder.PositiveColor);
                dialog.Content.SetTextColor(builder.ContentColor);
                dialog.Content.Gravity = GravityExt.GetGravity(builder.ContentGravity);
                if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1)
                {
                    dialog.Content.TextAlignment = GravityExt.GetTextAlignment(builder.ContentGravity);
                }

                if (builder.Content != null)
                {
                    dialog.Content.Text = builder.Content;
                    dialog.Content.Visibility = ViewStates.Visible;
                }
                else
                {
                    dialog.Content.Visibility = ViewStates.Gone;
                }
            }

            dialog.GetView().SetButtonGravity(builder.ButtonsGravity);
            dialog.GetView().SetButtonStackedGravity(builder.BtnStackedGravity);
            dialog.GetView().SetForceStack(builder.ForceStacking);
            bool textAllCaps;
            if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich)
            {
                textAllCaps = DialogUtils.ResolveBoolean(builder.Context, Android.Resource.Attribute.TextAllCaps, true);
                if (textAllCaps)
                    textAllCaps = DialogUtils.ResolveBoolean(builder.Context, Resource.Attribute.textAllCaps, true);
            }
            else
            {
                textAllCaps = DialogUtils.ResolveBoolean(builder.Context, Resource.Attribute.textAllCaps, true);
            }

            MDButton positiveTextView = dialog.PositiveButton;
            dialog.SetTypeface(positiveTextView, builder.MediumFont);
            positiveTextView.SetAllCapsCompat(textAllCaps);
            positiveTextView.Text = builder.PositiveText;
            positiveTextView.SetTextColor(builder.PositiveColor);
            dialog.PositiveButton.SetStackedSelector(dialog.GetButtonSelector(DialogAction.Positive, true));
            dialog.PositiveButton.SetDefaultSelector(dialog.GetButtonSelector(DialogAction.Positive, false));
            dialog.PositiveButton.Tag = (int)DialogAction.Positive;
            dialog.PositiveButton.SetOnClickListener(dialog);
            dialog.PositiveButton.Visibility = ViewStates.Visible;

            MDButton negativeTextView = dialog.NegativeButton;
            dialog.SetTypeface(negativeTextView, builder.MediumFont);
            negativeTextView.SetAllCapsCompat(textAllCaps);
            negativeTextView.Text = builder.NegativeText;
            negativeTextView.SetTextColor(builder.NegativeColor);
            dialog.NegativeButton.SetStackedSelector(dialog.GetButtonSelector(DialogAction.Negative, true));
            dialog.NegativeButton.SetDefaultSelector(dialog.GetButtonSelector(DialogAction.Negative, false));
            dialog.NegativeButton.Tag = (int)DialogAction.Negative;
            dialog.NegativeButton.SetOnClickListener(dialog);
            dialog.NegativeButton.Visibility = ViewStates.Visible;

            MDButton neutralTextView = dialog.NeutralButton;
            dialog.SetTypeface(neutralTextView, builder.MediumFont);
            neutralTextView.SetAllCapsCompat(textAllCaps);
            neutralTextView.Text = builder.NeutralText;
            neutralTextView.SetTextColor(builder.NeutralColor);
            dialog.NeutralButton.SetStackedSelector(dialog.GetButtonSelector(DialogAction.Neutral, true));
            dialog.NeutralButton.SetDefaultSelector(dialog.GetButtonSelector(DialogAction.Neutral, false));
            dialog.NeutralButton.Tag = (int)DialogAction.Neutral;
            dialog.NeutralButton.SetOnClickListener(dialog);
            dialog.NeutralButton.Visibility = ViewStates.Visible;

            if (builder.ListCallbackMultiChoice != null)
                dialog.SelectedIndicesList = new List<int>();
            if (dialog.ListView != null && (builder.Items != null && builder.Items.Length > 0 || builder.Adapter != null))
            {
                dialog.ListView.Selector = dialog.GetListSelector();

                if (builder.Adapter == null)
                {
                    if (builder.ListCallbackSingleChoice != null)
                    {
                        dialog.ListType = ListType.Single;
                    }
                    else if (builder.ListCallbackMultiChoice != null)
                    {
                        dialog.ListType = ListType.Multi;
                        if (builder.SelectedIndices != null)
                            dialog.SelectedIndicesList = builder.SelectedIndices.ToList();
                    }
                    else
                    {
                        dialog.ListType = ListType.Regular;
                    }
                    builder.Adapter = new MaterialDialogAdapter(dialog, ListTypeExt.GetLayoutForType(dialog.ListType));
                }
                else if (builder.Adapter is MaterialSimpleListAdapter)
                {
                    ((MaterialSimpleListAdapter)builder.Adapter).SetDialog(dialog, false);
                }
            }
            SetupProgressDialog(dialog);

            SetupInputDialog(dialog);
            if (builder.CustomView != null)
            {
                dialog.GetView().FindViewById<MDRootLayout>(Resource.Id.root).NoTitleNoPadding();
                FrameLayout frame = dialog.GetView().FindViewById<FrameLayout>(Resource.Id.customViewFrame);
                dialog.CustomViewFrame = frame;
                View innerView = builder.CustomView;
                if (builder.WrapCustomViewInScroll)
                {
                    var r = dialog.Context.Resources;
                    int framePadding = r.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_dialog_frame_margin);
                    ScrollView sv = new ScrollView(dialog.Context);
                    int paddingTop = r.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_content_padding_top);
                    int paddingBottom = r.GetDimensionPixelSize(Resource.Dimension.sino_droid_md_content_padding_bottom);
                    sv.SetClipToPadding(false);
                    if (innerView is EditText)
                    {
                        sv.SetPadding(framePadding, paddingTop, framePadding, paddingBottom);
                    }
                    else
                    {
                        sv.SetPadding(0, paddingTop, 0, paddingBottom);
                        innerView.SetPadding(framePadding, 0, framePadding, 0);
                    }
                    sv.AddView(innerView, new ScrollView.LayoutParams(
                        ViewGroup.LayoutParams.MatchParent,
                        ViewGroup.LayoutParams.WrapContent));
                    innerView = sv;
                }
                frame.AddView(innerView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent,
                    ViewGroup.LayoutParams.WrapContent));
            }
            if (builder.ShowListener != null)
                dialog.SetOnShowListener(builder.ShowListener);
            if (builder.CancelListener != null)
                dialog.SetOnCancelListener(builder.CancelListener);
            if (builder.DismissListener != null)
                dialog.SetOnDismissListener(builder.DismissListener);
            if (builder.KeyListener != null)
                dialog.SetOnKeyListener(builder.KeyListener);

            dialog.SetOnShowListenerInternal();

            dialog.InvalidateList();
            dialog.SetViewInternal(dialog.GetView());
            dialog.CheckIfListInitScroll();
        }
コード例 #39
0
        protected override async void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);
            UpdateAlignment();
            UpdateFont();
            UpdatePadding();
            //UpdateMargin();

            _density = Resources.DisplayMetrics.Density;
            var targetButton = Control;

            if (targetButton != null)
            {
                targetButton.SetOnTouchListener(TouchListener.Instance.Value);
            }

            if (Element != null && Element.Font != Font.Default && targetButton != null)
            {
                targetButton.Typeface = Element.Font.ToExtendedTypeface(Context);
            }

            if (Element != null && BaseButton.Source != null)
            {
                await SetImageSourceAsync(targetButton, BaseButton).ConfigureAwait(false);
            }


            if (Control != null)
            {
                var button = e.NewElement;


                // Create a drawable for the button's normal state
                _normal = new Android.Graphics.Drawables.GradientDrawable();

                if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0)
                {
                    _normal.SetColor(Android.Graphics.Color.ParseColor(buttonWhite));
                }
                else
                {
                    _normal.SetColor(button.BackgroundColor.ToAndroid());
                }

                _normal.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _normal.SetCornerRadius(button.BorderRadius);


                // Create a drawable for the button's pressed state
                _pressed = new Android.Graphics.Drawables.GradientDrawable();
                var highlight = Android.Graphics.Color.ParseColor(buttonGrey);
                //var highlight = Context.ObtainStyledAttributes(new int[] { Android.Resource.Attribute.ColorActivatedHighlight }).GetColor(0, Android.Graphics.Color.ParseColor(buttonWhite));
                _pressed.SetColor(highlight);
                _pressed.SetStroke((int)button.BorderWidth, button.BorderColor.ToAndroid());
                _pressed.SetCornerRadius(button.BorderRadius);

                // Add the drawables to a state list and assign the state list to the button
                var sld = new StateListDrawable();
                sld.AddState(new int[] { Android.Resource.Attribute.StatePressed }, _pressed);
                sld.AddState(new int[] { }, _normal);
                Control.SetBackgroundDrawable(sld);
            }
        }