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;
        }
        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.º 3
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.º 4
0
        private void UpdateRadius()
        {
            var radiusDp = (float)(Element.CornerRadius * Resources.DisplayMetrics.Density);

            controlBackground.SetCornerRadius(radiusDp);
        }
Exemplo n.º 5
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();
                    }
                }
            });
        }