//        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;
        }
        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);
            }
        }
        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);
        }
		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);
			}
		}
        GradientDrawable CreateBackgroundDrawable(CornerSide setCornerSide, Android.Graphics.Color backgroundColor, float cornerRadius)
        {
            var gDrawable = new GradientDrawable(); 

            float[] corners;

            //Set X and Y for each corner 
            //The corners are ordered top-left, top-right, bottom-right, bottom-left
            switch (setCornerSide)
            {
                case CornerSide.LeftSide:
                    corners = new float[]{ cornerRadius, cornerRadius, DefaultCorner, DefaultCorner, DefaultCorner, DefaultCorner, cornerRadius, cornerRadius };  
                    break; 
                case CornerSide.RightSide:
                    corners = new float[]{ DefaultCorner, DefaultCorner, cornerRadius, cornerRadius, cornerRadius, cornerRadius, DefaultCorner, DefaultCorner };
                    break; 
                default :
                    corners = new float[]{ DefaultCorner, DefaultCorner, DefaultCorner, DefaultCorner, DefaultCorner, DefaultCorner, DefaultCorner, DefaultCorner };
                    break;
            }

            gDrawable.SetCornerRadii(corners);
            gDrawable.SetColor(backgroundColor.ToArgb());

            return gDrawable;
        }
Exemple #6
0
        /// <summary>
        /// Used to set badge for given tab
        /// </summary>
        /// <param name="badgeItem">           holds badge data </param>
        /// <param name="bottomNavigationTab"> bottom navigation tab to which badge needs to be attached </param>
        private static void setBadgeForTab(BadgeItem badgeItem, BottomNavigationTab bottomNavigationTab)
        {
            if (badgeItem != null)
            {
                Context context = bottomNavigationTab.Context;

                GradientDrawable shape = getBadgeDrawable(badgeItem, context);
                bottomNavigationTab.badgeView.SetBackgroundDrawable(shape);

                bottomNavigationTab.BadgeItem = badgeItem;
                badgeItem.SetTextView(bottomNavigationTab.badgeView);
                bottomNavigationTab.badgeView.Visibility = ViewStates.Visible;

                bottomNavigationTab.badgeView.SetTextColor(new Color(badgeItem.GetTextColor(context)));
                bottomNavigationTab.badgeView.Text = badgeItem.Text;


                FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)bottomNavigationTab.badgeView.LayoutParameters;
                layoutParams.Gravity = badgeItem.Gravity;
                bottomNavigationTab.badgeView.LayoutParameters = layoutParams;

                if (badgeItem.Hidden)
                {
                    // if hide is called before the initialisation of bottom-bar this will handle that
                    // by hiding it.
                    badgeItem.Hide();
                }
            }
        }
        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
            }
        }
        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);
                };
            }
        }
Exemple #10
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            Android.Graphics.Drawables.GradientDrawable gd = new Android.Graphics.Drawables.GradientDrawable(Android.Graphics.Drawables.GradientDrawable.Orientation.TopBottom,
                                                                                                             new int[] { new global::Android.Graphics.Color(255, 255, 255, 0), new global::Android.Graphics.Color(255, 255, 255, 255), new global::Android.Graphics.Color(255, 255, 255, 255) });

            Background = gd;

            base.DispatchDraw(canvas);
        }
Exemple #11
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="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);
     }
 }
        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="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);
     }
 }
Exemple #15
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);
        }
    public static void InitializeFrom(this View nativeControl, Abstractions.RoundedBoxView formsControl)
    {
      if (nativeControl == null || formsControl == null)
        return;

      var background = new GradientDrawable();

      background.SetColor(formsControl.BackgroundColor.ToAndroid());

      nativeControl.Background = background;

      nativeControl.UpdateCornerRadius(formsControl.CornerRadius);
      nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness);
    }
Exemple #17
0
		void Initialize ()
		{
			var config = ViewConfiguration.Get (Context);
			this.pagingTouchSlop = config.ScaledPagingTouchSlop;
			this.minFlingVelocity = config.ScaledMinimumFlingVelocity;
			this.maxFlingVelocity = config.ScaledMaximumFlingVelocity;
			const int BaseShadowColor = 0;
			var shadowColors = new[] {
				Color.Argb (0x50, BaseShadowColor, BaseShadowColor, BaseShadowColor).ToArgb (),
				Color.Argb (0, BaseShadowColor, BaseShadowColor, BaseShadowColor).ToArgb ()
			};
			this.shadowDrawable = new GradientDrawable (GradientDrawable.Orientation.BottomTop,
			                                            shadowColors);
		}
        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);
            }
        }
        void SetBackgr(ViewGroup viewGroup)
        {
            for (int i = 0; i < viewGroup.ChildCount; i++)
            {
//				viewGroup.GetChildAt (i).SetBackgroundResource (Resource.Drawable.grd);
                ViewGroup v = viewGroup.GetChildAt(i)  as  ViewGroup;
                if (v != null)
                {
                    GradientDrawable _normal = new Android.Graphics.Drawables.GradientDrawable();
                    _normal.SetColor(Android.Graphics.Color.White);
                    v.SetBackground(_normal);
                    v.SetBackgroundResource(Resource.Drawable.grd);
                    SetBackgr(v);
                }
            }
        }
 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);
     }
 }
Exemple #21
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
            }
        }
        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);
        }
		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);
			}
		}
    public static void InitializeFrom(this View nativeControl, Abstractions.RoundedBoxView formsControl)
    {
      if (nativeControl == null || formsControl == null)
        return;

      var background = new GradientDrawable();

      background.SetColor(formsControl.BackgroundColor.ToAndroid());

	  if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBean) {
		nativeControl.Background = background;
	  } else {
		nativeControl.SetBackgroundDrawable(background);
	  }

      nativeControl.UpdateCornerRadius(formsControl.CornerRadius);
      nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness);
    }
		void Initialize ()
		{
			var config = ViewConfiguration.Get (Context);
			this.touchSlop = config.ScaledTouchSlop;
			this.pagingTouchSlop = config.ScaledPagingTouchSlop;
			this.minFlingVelocity = config.ScaledMinimumFlingVelocity;
			this.maxFlingVelocity = config.ScaledMaximumFlingVelocity;
			const int BaseShadowColor = 0;
			var shadowColors = new[] {
				Color.Argb (0x90, BaseShadowColor, BaseShadowColor, BaseShadowColor).ToArgb (),
				Color.Argb (0, BaseShadowColor, BaseShadowColor, BaseShadowColor).ToArgb ()
			};
			this.shadowDrawable = new GradientDrawable (GradientDrawable.Orientation.RightLeft,
				shadowColors);
			this.overlayPaint = new Paint {
				Color = Color.Black,
				AntiAlias = true
			};
		}
Exemple #26
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));
                };
            }
        }
        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);
            }
        }
Exemple #28
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);
                };
            }
        }
        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));
        }
Exemple #30
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;
        }
Exemple #31
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);
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
        {
            base.OnElementChanged (e);

            if (e.NewElement == null)
            {
                return;
            }

            var element = Element as AdvancedListView;

            if (Control != null)
            {
                UpdateVerticalScrollbar (element);

                Control.Scroll += (object sender, AbsListView.ScrollEventArgs e2) => {
                    //                  System.Diagnostics.Debug.WriteLine ("{0} -> {1}", scrollY, Control.MaxScrollAmount);
                    ReportContentOffset (element);
                    UpdateAffordances ();
                };
                Control.ScrollStateChanged += (object sender, AbsListView.ScrollStateChangedEventArgs e2) => {

                };

                _topOverlayMask = new GradientDrawable ();
                _topOverlayView = new Android.Views.View (Forms.Context);
                _topOverlayView.SetBackgroundDrawable (_topOverlayMask);
                AddView (_topOverlayView);

                _bottomOverlayMask = new GradientDrawable ();
                _bottomOverlayView = new Android.Views.View (Forms.Context);
                _bottomOverlayView.SetBackgroundDrawable (_bottomOverlayMask);
                AddView (_bottomOverlayView);

                UpdateAffordanceColors ();
                RequestLayout ();
            }
        }
        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);
        }
        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);
        }
Exemple #35
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);
            }
        }
		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);
		}
Exemple #37
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);
            }
        }
Exemple #38
0
		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;
		}
		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 ();
				}
			}
		}
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());
			}
		}
	}
}
Exemple #41
0
		public void SetCornerRadiusWithColor (Color backgroundColor, float[] arr)
		{
			GradientDrawable background = new GradientDrawable ();
			background.SetCornerRadii (arr);
			background.SetColor (backgroundColor);
			Background = background;
		}
Exemple #42
0
		public void SetSlightlyRoundWithBackgroundColor (Color color)
		{
			var cornerRadius = 6 * DeviceInfo.Density;
			GradientDrawable background = new GradientDrawable ();
			background.SetCornerRadius (cornerRadius);
			background.SetColor (color);

			Background = background;

			RemoveBorders ();
		}
Exemple #43
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();
        }
Exemple #44
0
		public void SetRoundWithColor (Color color, int currentSize)
		{
			GradientDrawable background = new GradientDrawable ();
			background.SetCornerRadius (currentSize);
			background.SetColor (color);

			Background = background;

			RemoveBorders ();
		}
Exemple #45
0
		public void SetMultiColorBackground (int[] colours)
		{
			GradientDrawable drawable = new GradientDrawable (GradientDrawable.Orientation.LeftRight, colours);
			Background = drawable;
		}
Exemple #46
0
		public void SetRoundBordersWithColor (Color color, int currentSize, int strokeSize)
		{
			GradientDrawable outerBackground = new GradientDrawable ();
			outerBackground.SetCornerRadius (currentSize);
			outerBackground.SetStroke (strokeSize, color);

			Background = outerBackground;
		}
        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();
        }
Exemple #48
0
 void Initialize()
 {
     var config = ViewConfiguration.Get (Context);
     this.pagingTouchSlop = config.ScaledPagingTouchSlop;
     this.minFlingVelocity = config.ScaledMinimumFlingVelocity;
     this.maxFlingVelocity = config.ScaledMaximumFlingVelocity;
     const int BaseShadowColor = 0;
     var shadowColors = new[] {
         Color.Argb (0x30, BaseShadowColor, BaseShadowColor, BaseShadowColor).ToArgb (),
         Color.Argb (0, BaseShadowColor, BaseShadowColor, BaseShadowColor).ToArgb ()
     };
     this.shadowDrawable = new GradientDrawable (GradientDrawable.Orientation.BottomTop,
                                                 shadowColors);
     var elevation = Resources.GetDimension (Resource.Dimension.design_fab_elevation);
     Android.Support.V4.View.ViewCompat.SetElevation (this, elevation);
 }