Ejemplo n.º 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;
        }
Ejemplo n.º 2
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);
            }
        }
		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);
			}
		}
        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;
            }
        }
        // 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
            }
        }
Ejemplo n.º 6
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);
        }
 /// <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);
     }
 }
Ejemplo n.º 8
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);
        }
 /// <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);
     }
 }
Ejemplo n.º 10
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);
        }
        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);
            }
        }
 protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
 {
     base.OnElementChanged (e);
     if (e.OldElement == null && e.NewElement != null) {
         var entry = e.NewElement as ExtendedEntry;
         var shape =  new GradientDrawable();
         shape.SetColor (Xamarin.Forms.Color.Transparent.ToAndroid ().ToArgb ());
         shape.SetStroke (0, Xamarin.Forms.Color.Transparent.ToAndroid ());
         this.Control.SetBackground(shape);
         this.Control.SetHintTextColor (Xamarin.Forms.Color.Gray.ToAndroid());
         this.Control.SetTextColor (Xamarin.Forms.Color.Black.ToAndroid());
         this.Control.SetPadding (0, 0, 0, 0);
         this.SetKeyboard (entry.CustomKeyboard);
         this.SetFont (entry);
     }
 }
Ejemplo n.º 13
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
            }
        }
        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);
            }
        }
Ejemplo n.º 15
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));
        }
Ejemplo n.º 16
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);
                };
            }
        }
Ejemplo n.º 17
0
        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;
        }
Ejemplo n.º 18
0
        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);
            }
        }
        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);
        }
Ejemplo n.º 20
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();
                _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);
            }
        }
Ejemplo n.º 21
0
        /* Snippet 2 Ende */
        /// <summary>
        /// Aufgenommenes Foto durch Project Oxford analysieren lassen und das Ergebnis visualisieren
        /// </summary>
        /// <param name="requestCode"></param>
        /// <param name="resultCode"></param>
        /// <param name="data"></param>
        protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            var progressBar = FindViewById<ProgressBar>(Resource.Id.progressBar1);
            try
            {
                // User canceled
                if (resultCode == Result.Canceled)
                    return;

                MediaFile file = await data.GetMediaFileExtraAsync(this);

                //Alte Face-Rectangles entfernen
                var rellayout = FindViewById<RelativeLayout>(Resource.Id.relativeLayout1);
                for (int i = 2; i < rellayout.ChildCount; i++)
                {
                    rellayout.RemoveViewAt(i);
                }
                
                progressBar.Visibility = ViewStates.Visible;

                //Foto in ImageView anzeigen
                var bmp = BitmapFactory.DecodeFile(file.Path);
                ImageView _imgView = FindViewById<ImageView>(Resource.Id.imageView1);
                _imgView.SetImageBitmap(bmp);

                //Bild Analyse durch Project Oxford
                await _vm.Load(file.GetStream());

                //Brechnen der Face Rectangle Positionen
                float scale;
                if (_imgView.Width / bmp.Width >= _imgView.Height / bmp.Height)
                {
                    scale = (float)bmp.Height / _imgView.Height;
                }
                else
                {
                    scale = (float)bmp.Width / _imgView.Width;
                }

                var relX = (_imgView.Width - bmp.Width / scale) / 2;
                var relY = (_imgView.Height - bmp.Height / scale) / 2;
                foreach (Emotion.Contract.Emotion emo in _vm.Emotions)
                {
                    //Zeichnen der Face Rectangles
                    var butt = new Button(this);
                    GradientDrawable drawable = new GradientDrawable();
                    drawable.SetShape(ShapeType.Rectangle);
                    drawable.SetStroke(5, Color.Rgb(34, 135, 202));
                    drawable.SetColor(Color.Transparent);
                    butt.Background = drawable;
                    var layoutparams = new RelativeLayout.LayoutParams((int)Math.Ceiling(emo.FaceRectangle.Width / scale), (int)Math.Ceiling(emo.FaceRectangle.Height / scale));
                    layoutparams.SetMargins((int)Math.Ceiling(emo.FaceRectangle.Left / scale + relX), (int)Math.Ceiling(emo.FaceRectangle.Top / scale + relY), 0, 0);

                    butt.LayoutParameters = layoutparams;
                    butt.SetPadding(0, 0, 0, 0);
                    butt.Click += (e, s) =>
                    {
                        //Bei Klick auf Face Rectangle Emotionswerte anzeigen
                        (FindViewById<ProgressBar>(Resource.Id.angerProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Anger * 100);
                        (FindViewById<ProgressBar>(Resource.Id.contemptProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Contempt * 100);
                        (FindViewById<ProgressBar>(Resource.Id.disgustProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Disgust * 100);
                        (FindViewById<ProgressBar>(Resource.Id.fearProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Fear * 100);
                        (FindViewById<ProgressBar>(Resource.Id.happinessProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Happiness * 100);
                        (FindViewById<ProgressBar>(Resource.Id.neutralProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Neutral * 100);
                        (FindViewById<ProgressBar>(Resource.Id.sadnessProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Sadness * 100);
                        (FindViewById<ProgressBar>(Resource.Id.surpriseProgressBar)).Progress = (int)Math.Ceiling(emo.Scores.Surprise * 100);
                    };
                    rellayout.AddView(butt);
                }
            }
            finally{ progressBar.Visibility = ViewStates.Invisible; }
        }
		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);
		}
Ejemplo n.º 23
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;
        }
Ejemplo n.º 24
0
using System;
using Xamarin.Forms;
using HowlOut;
using HowlOut.Droid;
using Xamarin.Forms.Platform.Android;
using System.ComponentModel;
using Android.Graphics.Drawables;
using Android.Views;

[assembly: ExportRenderer(typeof(CustomEditor), typeof(CustomEditorRenderer))]
namespace HowlOut.Droid
{
	public class CustomEditorRenderer : EditorRenderer
	{
		protected override void OnElementChanged(
			ElementChangedEventArgs<Editor> e)
		{
			base.OnElementChanged(e);

			if (e.NewElement != null)
			{
				var element = e.NewElement as CustomEditor;
				this.Control.Hint = element.Placeholder;
				GradientDrawable gd = new GradientDrawable();
				gd.SetStroke(5, Color.White.ToAndroid());
				this.Control.SetBackgroundDrawable(gd);
				this.Control.Gravity = GravityFlags.Center;
				this.Control.SetHintTextColor(Color.White.ToAndroid());
			}
		}

		protected override void OnElementPropertyChanged(
			object sender,
			PropertyChangedEventArgs e)
		{
			base.OnElementPropertyChanged(sender, e);

			if (e.PropertyName == CustomEditor.PlaceholderProperty.PropertyName)
			{
				var element = this.Element as CustomEditor;
				this.Control.Hint = element.Placeholder;
				GradientDrawable gd = new GradientDrawable();
				gd.SetStroke(5, Color.White.ToAndroid());
				this.Control.SetBackgroundDrawable(gd);
				this.Control.Gravity = GravityFlags.Center;
				this.Control.SetHintTextColor(Color.White.ToAndroid());
			}
		}
	}
}
Ejemplo n.º 25
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;
        }
Ejemplo n.º 26
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);
            }
        }
Ejemplo n.º 27
0
        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();
        }
Ejemplo n.º 28
0
        //ConsoleColor favoriteButtonDefaultColor;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            tempList.Add ("1. First movie.   50%");
            tempList.Add ("2. Second movie.  50%");

            //set buttons
            leaderboardButton = FindViewById<Button> (Resource.Id.leaderboard);
            //set views
            scrollView = FindViewById<ScrollView> (Resource.Id.mainScrollView);

            int lbCount = 0;

            //create SYstem.Threading.Timer object. Acts as Updater for leaderboard button.
            Timer timer = new Timer((o) =>
            {
                    RunOnUiThread(() =>
                    {

                            //set text
                            leaderboardButton.Text = tempList[lbCount];
                            //change counter for next iteration
                            lbCount++;
                            //if too high set to 0.
                            if(lbCount >= tempList.Count)
                                lbCount = 0;

                            Console.WriteLine("lbCount: " + lbCount);
                            Console.WriteLine("message: %d" + tempList[lbCount]);
                    });

            }, null, 0, 10000);

            favoritesButton = FindViewById<Button> (Resource.Id.favorites);
            //get starting color of favorite button (will be the default)
            //favoriteButtonDefaultColor = new SolidColorBrush(favoritesButton.Background);
            //now set to off option.
            //favoritesButton.Background = new SolidColorBrush(Colors.DarkGray);

            favoritesButton.Click += delegate
            {
                if(favoriteColorState == 0)
                {
                    //favoritesButton.Background = favoriteButtonDefaultColor;
                    var onButtonText = Resources.GetString(Resource.String.favOn);
                    favoritesButton.Text = onButtonText;
                    favoriteColorState = 1;
                }
                else if(favoriteColorState == 1)
                {
                    //favoritesButton.Background = new SolidColorBrush(Colors.DarkGray);
                    var offButtonText = Resources.GetString(Resource.String.favOff);
                    favoritesButton.Text = offButtonText;
                    favoriteColorState = 0;
                }
            };//end listener

            //*********TESTING**************

            //			// Get our button from the layout resource,
            //			// and attach an event to it
            //			Button button = FindViewById<Button> (Resource.Id.myButton);
            //
            //			button.Click += delegate {
            //				button.Text = string.Format ("{0} clicks!", count++);
            //			};

            // Creating a new RelativeLayout
            //new RelativeLayout(this);
            //relativeLayout.RemoveView ((ScrollView)relativeLayout.Parent);

            // Defining the RelativeLayout layout parameters.
            // In this case I want to fill its parent
            //RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent);

            //rlp.AddRule (LayoutRules.);
                //RelativeLayout.LayoutParams.FILL_PARENT,
                //RelativeLayout.LayoutParams.FILL_PARENT);

            //lp.addRule(RelativeLayout.CENTER_IN_PARENT);

            // Setting the RelativeLayout as our content view
            //SetContentView(relativeLayout, lp);

            LinearLayout linearLayout = FindViewById<LinearLayout>(Resource.Id.linearLayout2);

            for(int i = 0; i<=10; i++)
            {

                Button btn1 = new Button (this);
                btn1.Text = "btn" + i;
                btn1.Id = i;

                // Defining the layout parameters of the TextView
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WrapContent,
                    LinearLayout.LayoutParams.WrapContent);

                // Setting the parameters on the TextView
                btn1.LayoutParameters = lp;

                //set layout orientation
                linearLayout.Orientation = Orientation.Vertical;

                //ctrl-alt-space after term for auto import

                //set border
                GradientDrawable border = new GradientDrawable();
                border.SetColor(0x7FFFFFFF); //white background
                border.SetStroke(1, Color.Black); //black border with full opacity//0xFF000000
                if(Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.JellyBean)
                {
                    linearLayout.SetBackgroundDrawable(border);
                }
                else
                {
                    linearLayout.SetBackgroundDrawable(border);
                }

                // Adding the TextView to the RelativeLayout as a child
                linearLayout.AddView(btn1);

            }//end temp for loop
        }
Ejemplo n.º 29
0
		public void SetRoundBordersWithColor (Color color, int currentSize, int strokeSize)
		{
			GradientDrawable outerBackground = new GradientDrawable ();
			outerBackground.SetCornerRadius (currentSize);
			outerBackground.SetStroke (strokeSize, color);

			Background = outerBackground;
		}
		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);
        }
Ejemplo n.º 31
0
using System;

using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using HowlOut;
using HowlOut.Droid;
using Android.Graphics.Drawables;

[assembly: ExportRenderer(typeof(CustomEntry), typeof(CustomEntryRenderer))]
namespace HowlOut.Droid
{
	public class CustomEntryRenderer : EntryRenderer
	{
		protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
		{
			base.OnElementChanged(e);

			if (Control != null)
			{
				GradientDrawable gd = new GradientDrawable();
				gd.SetStroke(5, Color.White.ToAndroid());
				this.Control.SetBackgroundDrawable(gd);
				this.Control.Gravity = Android.Views.GravityFlags.CenterHorizontal;
				this.Control.SetHintTextColor(Color.White.ToAndroid());
			}
		}
	}
}