Exemplo n.º 1
0
        public PMButton(Context context) : base(context)
        {
            Gravity = Android.Views.GravityFlags.Center;
            SetTextColor(Color.White);

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

            background.SetColor(Colors.ActionBar.ToArgb());
            background.SetCornerRadius(5);

            Background = background;
        }
        private void UpdateColors()
        {
            var element = Element as CustomSwitch;

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

            track.SetColor(element.TrackColor.ToAndroid());
            track.SetSize((int)Element.Width, (int)Element.Height);
            Control.TrackDrawable = track;

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

            if (Element.IsToggled)
            {
                thumb.SetColor(element.OnThumbColor.ToAndroid());
            }
            else
            {
                thumb.SetColor(element.OffThumbColor.ToAndroid());
            }

            Control.ThumbDrawable = thumb;
        }
        void SetCornerRadius(int radius)
        {
#if __IOS__
            Layer.CornerRadius = radius;
#elif __ANDROID__
            var existing = View.BackgroundColor.ToNativeColor();

            var drawable = new Android.Graphics.Drawables.GradientDrawable();
            drawable.SetCornerRadius(View.CornerRadius * Forms.Context.Resources.DisplayMetrics.Density);
            drawable.SetColor(existing.ToArgb());

            Background = drawable;
#endif
        }
Exemplo n.º 4
0
        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;
                this.Control.SetHintTextColor(ag.Color.ParseColor("#e5e5e5"));
            }

            if (Control != null)
            {
                Graphicss.Drawables.GradientDrawable gd = new Graphicss.Drawables.GradientDrawable();
                gd.SetColor(global::Android.Graphics.Color.Transparent);
                gd.SetStroke(2, global::Android.Graphics.Color.Gray);
                this.Control.SetBackgroundDrawable(gd);
            }
        }
Exemplo n.º 5
0
        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;
                this.Control.SetHintTextColor(ag.Color.Gray);
                this.Control.SetBackgroundColor(global::Android.Graphics.Color.White);
                this.Control.SetCursorVisible(true);
                //if (Control != null)
                //{
                Graphicss.Drawables.GradientDrawable gd = new Graphicss.Drawables.GradientDrawable();
                gd.SetColor(global::Android.Graphics.Color.Transparent);
                gd.SetStroke(2, global::Android.Graphics.Color.Gray);
                this.Control.SetBackgroundDrawable(gd);
                //}
                //	this.Control.Background = this.Resources.GetDrawable(Resource.Drawable.withBorder);
            }

            // This line do the trick
            //			Control.FocusChange += Control_FocusChange;
        }
Exemplo n.º 6
0
        public PMButton(Context context)
            : base(context)
        {
            Gravity = Android.Views.GravityFlags.Center;
            SetTextColor(Color.White);

            var background = new Android.Graphics.Drawables.GradientDrawable();
            background.SetColor(Colors.ActionBar.ToArgb());
            background.SetCornerRadius(5);

            Background = background;
        }
Exemplo n.º 7
0
 private void UpdateColor()
 {
     controlBackground.SetColor(Element.Color.ToAndroid());
 }
Exemplo n.º 8
0
        public async Task Show(TopAlert alert)
        {
            await Stop();

            this._Token = new CancellationTokenSource();

            this._Delay = alert.Duration;

            var            activity      = Xamarin.Forms.Forms.Context as Android.App.Activity;
            IWindowManager windowManager = Xamarin.Forms.Forms.Context.GetSystemService(Android.App.Service.WindowService).JavaCast <IWindowManager>();

            this._Layout = (LinearLayout)activity.LayoutInflater.Inflate(Resource.Layout.AlertBox, null, false);
            this._Layout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            var submain = this._Layout.FindViewById <LinearLayout> (Resource.Id.linearLayout3);

            submain.SetBackgroundColor(alert.BackgroundColor.ToAndroid());

            var main = _Layout.FindViewById <LinearLayout> (Resource.Id.linearLayout1);

            var id = Xamarin.Forms.Forms.Context.Resources.GetIdentifier("alertborder", "drawable", Xamarin.Forms.Forms.Context.PackageName);

            Android.Graphics.Drawables.GradientDrawable drawable =
                Xamarin.Forms.Forms.Context.Resources.GetDrawable(id).JavaCast <Android.Graphics.Drawables.GradientDrawable>();


            var text = submain.FindViewById <TextView> (Resource.Id.textView1);

            text.SetTextColor(alert.TextColor.ToAndroid());
            text.Text = alert.Text;

            if (alert.TextSize > 0)
            {
                text.TextSize = alert.TextSize;
            }

            drawable.SetColor(alert.BorderColor.ToAndroid());
            drawable.SetCornerRadius(alert.BorderWidth);
            main.SetBackground(drawable);

            //activity.ActionBar.Hide ();

            var actionBarHeight = activity.ActionBar.Height;

            var intent = alert.Intent;

            var p = new WindowManagerLayoutParams(
                windowManager.DefaultDisplay.Width - intent * 2,
                (alert.AlertHeight < 0 ? 200 : (int)alert.AlertHeight),
                WindowManagerTypes.SystemAlert,
                0 | WindowManagerFlags.NotFocusable,
                Android.Graphics.Format.Translucent);

            var yOffset = alert.TopOffset;

            p.Gravity = GravityFlags.Top | GravityFlags.Left;
            p.X       = intent;
            p.Y       = alert.TopOffset + yOffset + (activity.ActionBar.IsShowing ? actionBarHeight : 0);
            p.Height  = (alert.AlertHeight < 0 ? 200 : (int)alert.AlertHeight);
            windowManager.AddView(_Layout, p);

            this._Layout.Touch += LayoutTouched;

            Task.Run(async() => {
                await Task.Delay(alert.Duration, this._Token.Token);

                if (this._Token != null && this._Token.IsCancellationRequested == false)
                {
                    if (alert.FadeOut)
                    {
                        Xamarin.Forms.Device.BeginInvokeOnMainThread(() => {
                            // this works
                            this._fadeOut = ObjectAnimator.OfFloat(_Layout, "alpha", 1f, 0f);
                            this._fadeOut.SetDuration(1000);
                            this._fadeOut.AnimationEnd += _fadeOut_AnimationEnd;
                            this._Set = new AnimatorSet();
                            this._Set.Play(_fadeOut);
                            this._Set.Start();
                        });
                    }
                    else
                    {
                        Stop();
                    }
                }
            });
        }