Exemplo n.º 1
0
 public PancakeDrawable(PancakeView pancake, Func <double, float> convertToPixels)
 {
     _pancake                  = pancake;
     _convertToPixels          = convertToPixels;
     _pancake.PropertyChanged += PancakeViewOnPropertyChanged;
 }
 public RoundedCornerOutlineProvider(PancakeView pancake, Func <double, float> convertToPixels)
 {
     _pancake         = pancake;
     _convertToPixels = convertToPixels;
 }
Exemplo n.º 3
0
        public SettingsPage()
        {
            BindingContext = new SettingsViewModel();

            var backImage = new Image
            {
                IsVisible = Device.RuntimePlatform != Device.Android,
                Opacity   = 0.98,
                Source    = "back",
                Aspect    = Aspect.AspectFill
            };

            AbsoluteLayout.SetLayoutBounds(backImage, new Rectangle(0, 0, 1, 1));
            AbsoluteLayout.SetLayoutFlags(backImage, AbsoluteLayoutFlags.All);

            var musicLabel = new Label
            {
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                FontSize   = 40,
                Text       = "MUSIC",
                TextColor  = Color.White,
                FontFamily = "MandaloreRegular",
            };

            AbsoluteLayout.SetLayoutBounds(musicLabel, new Rectangle(0, 0, 1, 1));
            AbsoluteLayout.SetLayoutFlags(musicLabel, AbsoluteLayoutFlags.All);

            var musicCrossOne = new BoxView
            {
                VerticalOptions = LayoutOptions.Center,
                Color           = Color.White,
                HeightRequest   = 2,
                Rotation        = 10
            };

            musicCrossOne.SetBinding(IsVisibleProperty, nameof(SettingsViewModel.IsMusicDisabled));
            AbsoluteLayout.SetLayoutBounds(musicCrossOne, new Rectangle(0, .5, 1, 2));
            AbsoluteLayout.SetLayoutFlags(musicCrossOne, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);

            var musicCrossTwo = new BoxView
            {
                VerticalOptions = LayoutOptions.Center,
                Color           = Color.White,
                HeightRequest   = 2,
                Rotation        = -10
            };

            musicCrossTwo.SetBinding(IsVisibleProperty, nameof(SettingsViewModel.IsMusicDisabled));
            AbsoluteLayout.SetLayoutBounds(musicCrossTwo, new Rectangle(0, .5, 1, 2));
            AbsoluteLayout.SetLayoutFlags(musicCrossTwo, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);


            var musicLayout = new PancakeView
            {
                Margin          = new Thickness(0, 30, 0, 0),
                HeightRequest   = 60,
                BorderColor     = Color.White,
                BorderThickness = 2,
                Content         = new AbsoluteLayout
                {
                    Children =
                    {
                        musicLabel,
                        musicCrossOne,
                        musicCrossTwo
                    }
                }
            };

            musicLayout.SetBinding(TouchEff.CommandProperty, nameof(SettingsViewModel.ChangeSettingCommand));
            TouchEff.SetCommandParameter(musicLayout, "music");
            TouchEff.SetNativeAnimation(musicLayout, true);

            var soundLabel = new Label
            {
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                FontSize   = 40,
                Text       = "SOUND",
                TextColor  = Color.White,
                FontFamily = "MandaloreRegular",
            };

            AbsoluteLayout.SetLayoutBounds(soundLabel, new Rectangle(0, 0, 1, 1));
            AbsoluteLayout.SetLayoutFlags(soundLabel, AbsoluteLayoutFlags.All);

            var soundCrossOne = new BoxView
            {
                VerticalOptions = LayoutOptions.Center,
                Color           = Color.White,
                HeightRequest   = 2,
                Rotation        = 10
            };

            soundCrossOne.SetBinding(IsVisibleProperty, nameof(SettingsViewModel.IsSoundDisabled));
            AbsoluteLayout.SetLayoutBounds(soundCrossOne, new Rectangle(0, .5, 1, 2));
            AbsoluteLayout.SetLayoutFlags(soundCrossOne, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);

            var soundCrossTwo = new BoxView
            {
                VerticalOptions = LayoutOptions.Center,
                Color           = Color.White,
                HeightRequest   = 2,
                Rotation        = -10
            };

            soundCrossTwo.SetBinding(IsVisibleProperty, nameof(SettingsViewModel.IsSoundDisabled));
            AbsoluteLayout.SetLayoutBounds(soundCrossTwo, new Rectangle(0, .5, 1, 2));
            AbsoluteLayout.SetLayoutFlags(soundCrossTwo, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);

            var soundLayout = new PancakeView
            {
                Margin          = new Thickness(0, 15, 0, 0),
                HeightRequest   = 60,
                BorderColor     = Color.White,
                BorderThickness = 2,
                Content         = new AbsoluteLayout
                {
                    Children =
                    {
                        soundLabel,
                        soundCrossOne,
                        soundCrossTwo
                    }
                }
            };

            soundLayout.SetBinding(TouchEff.CommandProperty, nameof(SettingsViewModel.ChangeSettingCommand));
            TouchEff.SetCommandParameter(soundLayout, "sound");
            TouchEff.SetNativeAnimation(soundLayout, true);


            var decreaseMapSizeLayout = new PancakeView
            {
                HeightRequest   = 60,
                WidthRequest    = 60,
                BorderColor     = Color.White,
                BorderThickness = 2,
                Content         = new Label
                {
                    HorizontalOptions       = LayoutOptions.CenterAndExpand,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Center,
                    FontSize   = 50,
                    Text       = "-",
                    TextColor  = Color.White,
                    FontFamily = "MandaloreRegular",
                }
            };

            decreaseMapSizeLayout.SetBinding(TouchEff.CommandProperty, nameof(SettingsViewModel.ChangeSettingCommand));
            TouchEff.SetCommandParameter(decreaseMapSizeLayout, "decreaseMapSize");
            TouchEff.SetNativeAnimation(decreaseMapSizeLayout, true);

            var increaseMapSizeLayout = new PancakeView
            {
                HeightRequest   = 60,
                WidthRequest    = 60,
                BorderColor     = Color.White,
                BorderThickness = 2,
                Content         = new Label
                {
                    HorizontalOptions       = LayoutOptions.CenterAndExpand,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Center,
                    FontSize   = 50,
                    Text       = "+",
                    TextColor  = Color.White,
                    FontFamily = "MandaloreRegular",
                }
            };

            increaseMapSizeLayout.SetBinding(TouchEff.CommandProperty, nameof(SettingsViewModel.ChangeSettingCommand));
            TouchEff.SetCommandParameter(increaseMapSizeLayout, "increaseMapSize");
            TouchEff.SetNativeAnimation(increaseMapSizeLayout, true);

            var mapSizeLabel = new Label
            {
                HorizontalTextAlignment = TextAlignment.Center,
                FontSize   = 30,
                TextColor  = Color.White,
                FontFamily = "MandaloreRegular",
            };

            mapSizeLabel.SetBinding(Label.TextProperty, nameof(SettingsViewModel.MapSizeText));

            var buttonsView = new PancakeView
            {
                Margin          = new Thickness(Device.Idiom == TargetIdiom.Phone ? 15 : 125, 0),
                Padding         = new Thickness(25),
                CornerRadius    = new CornerRadius(50, 10, 10, 50),
                BackgroundColor = Color.Black.MultiplyAlpha(.65),
                Content         = new StackLayout
                {
                    Spacing  = 0,
                    Children =
                    {
                        new Label
                        {
                            HorizontalTextAlignment = TextAlignment.Center,
                            VerticalTextAlignment   = TextAlignment.Center,
                            FontSize   = 50,
                            Text       = "SETTINGS",
                            TextColor  = Color.White,
                            FontFamily = "MandaloreHalftone",
                        },
                        musicLayout,
                        soundLayout,
                        new StackLayout
                        {
                            HeightRequest = 60,
                            Margin        = new Thickness(0, 15, 0, 0),
                            Orientation   = StackOrientation.Horizontal,
                            Children      =
                            {
                                decreaseMapSizeLayout,

                                new StackLayout
                                {
                                    Spacing           = 0,
                                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                                    Children          =
                                    {
                                        new Label
                                        {
                                            HorizontalTextAlignment = TextAlignment.Center,
                                            FontSize   = 30,
                                            Text       = "MAP SIZE",
                                            TextColor  = Color.White,
                                            FontFamily = "MandaloreRegular",
                                        },
                                        mapSizeLabel
                                    }
                                },

                                increaseMapSizeLayout
                            }
                        }
                    }
                }
            };

            AbsoluteLayout.SetLayoutBounds(buttonsView, new Rectangle(.5, .5, 1, -1));
            AbsoluteLayout.SetLayoutFlags(buttonsView, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);

            var mainMenuButton = new PancakeView
            {
                BackgroundColor = Color.Black.MultiplyAlpha(.65),
                CornerRadius    = new CornerRadius(0, 10, 10, 0),
                Padding         = new Thickness(10, 5),
                Margin          = new Thickness(15, Device.RuntimePlatform == Device.iOS ? 40 : 20),
                BorderColor     = Color.White,
                BorderThickness = 2,
                HeightRequest   = 40,
                Content         = new Label
                {
                    FontSize                = 30,
                    Text                    = "< MENU",
                    TextColor               = Color.White,
                    FontFamily              = "MandaloreRegular",
                    VerticalTextAlignment   = TextAlignment.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                }
            };

            AbsoluteLayout.SetLayoutBounds(mainMenuButton, new Rectangle(0, 0, -1, -1));
            AbsoluteLayout.SetLayoutFlags(mainMenuButton, AbsoluteLayoutFlags.PositionProportional);
            TouchEff.SetCommand(mainMenuButton, new Command(() =>
            {
                if (Preferences.Get("ShouldPlaySound", true))
                {
                    DependencyService.Resolve <IAudioService>().Play("click.mp3", false);
                }
                Navigation.PopAsync();
            }));
            TouchEff.SetNativeAnimation(mainMenuButton, true);

            Content = new AbsoluteLayout
            {
                Children =
                {
                    backImage,
                    mainMenuButton,
                    buttonsView
                }
            };

            NavigationPage.SetHasNavigationBar(this, false);
        }
Exemplo n.º 4
0
        public NotificationCell()
        {
            PancakeView frame = new PancakeView();

            frame.HasShadow       = false;
            frame.BorderThickness = 1;
            frame.SetAppThemeColor(PancakeView.BorderColorProperty, (Color)Application.Current.Resources["MainColor"], Color.White);
            //frame.Elevation = 20;
            frame.HorizontalOptions = LayoutOptions.FillAndExpand;
            frame.VerticalOptions   = LayoutOptions.Start;
            frame.BackgroundColor   = Color.White;
            frame.Margin            = new Thickness(10, 0, 10, 10);
            frame.Padding           = new Thickness(20, 23, 20, 10);
            frame.CornerRadius      = 30;
            StackLayout container = new StackLayout();

            container.Orientation = StackOrientation.Vertical;
            StackLayout titleContainer = new StackLayout();

            titleContainer.Orientation       = StackOrientation.Horizontal;
            titleContainer.HorizontalOptions = LayoutOptions.FillAndExpand;
            title.Text = "Заголовок";
            title.HorizontalTextAlignment = TextAlignment.Start;
            title.HorizontalOptions       = LayoutOptions.StartAndExpand;
            title.FontAttributes          = FontAttributes.Bold;
            title.FontSize               = 15;
            title.TextColor              = Color.Black;
            more.Text                    = $"{AppResources.Details} >";
            more.FontSize                = 13;
            more.TextDecorations         = TextDecorations.Underline;
            more.TextColor               = (Color)Application.Current.Resources["MainColor"];
            more.HorizontalTextAlignment = TextAlignment.End;
            more.VerticalOptions         = LayoutOptions.Center;
            more.HorizontalOptions       = LayoutOptions.EndAndExpand;
            more.MaxLines                = 1;
            more.MinimumWidthRequest     = 80;
            titleContainer.Children.Add(title);
            titleContainer.Children.Add(more);
            container.Children.Add(titleContainer);
            date.HorizontalOptions = LayoutOptions.Start;
            date.TextColor         = Color.Black;
            date.FontSize          = 12;
            date.VerticalOptions   = LayoutOptions.Center;
            date.Margin            = new Thickness(0, -5, 0, 0);
            container.Children.Add(date);
            text.HorizontalOptions = LayoutOptions.FillAndExpand;
            text.VerticalOptions   = LayoutOptions.FillAndExpand;
            text.TextColor         = Color.Black;
            text.FontSize          = 15;
            text.TextType          = TextType.Html;
            container.Children.Add(text);
            Grid containerMain = new Grid();

            containerMain.Padding           = 0;
            containerMain.ColumnDefinitions = new ColumnDefinitionCollection
            {
                new ColumnDefinition {
                    Width = GridLength.Star
                },
                new ColumnDefinition {
                    Width = new GridLength(5)
                }
            };

            containerMain.RowDefinitions = new RowDefinitionCollection
            {
                new RowDefinition {
                    Height = new GridLength(5)
                },
                new RowDefinition {
                    Height = GridLength.Star
                }
            };

            containerMain.Children.Add(container);
            Grid.SetRowSpan(container, 2);
            Grid.SetColumnSpan(container, 2);


            ReadIndicator = new Frame
            {
                CornerRadius    = 5,
                BackgroundColor = Color.Red,
                IsVisible       = false
            };

            ReadIndicator.SetBinding(View.IsVisibleProperty, "Read", BindingMode.TwoWay);

            containerMain.Children.Add(ReadIndicator, 1, 0);
            frame.Content        = containerMain;
            View                 = frame;
            View.BackgroundColor = Color.White;

            MessagingCenter.Subscribe <Object, int>(this, "SetNotificationRead", (sender, args) =>
            {
                if (this.ID == args)
                {
                    ReadIndicator.IsVisible = false;
                }
            });
        }
Exemplo n.º 5
0
        private void DrawBorder(ACanvas canvas, PancakeView control)
        {
            if (control.BorderThickness > 0)
            {
                var  borderThickness      = Context.ToPixels(control.BorderThickness);
                var  halfBorderThickness  = borderThickness / 2;
                bool hasShadowOrElevation = control.HasShadow || (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop && control.Elevation > 0);

                // TODO: This doesn't look entirely right yet when using it with rounded corners.
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (var rect = new RectF(control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Width + halfBorderThickness : canvas.Width - halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Height + halfBorderThickness : canvas.Height - halfBorderThickness))
                            {
                                Path path = null;
                                if (control.Sides != 4)
                                {
                                    path = ShapeUtils.CreatePolygonPath(Width, Height, control.Sides, control.CornerRadius.TopLeft, control.OffsetAngle);
                                }
                                else
                                {
                                    path = ShapeUtils.CreateRoundedRectPath(Width, Height,
                                                                            Context.ToPixels(control.CornerRadius.TopLeft),
                                                                            Context.ToPixels(control.CornerRadius.TopRight),
                                                                            Context.ToPixels(control.CornerRadius.BottomRight),
                                                                            Context.ToPixels(control.CornerRadius.BottomLeft));
                                }

                                if (control.BorderIsDashed)
                                {
                                    // dashes merge when thickness is increased
                                    // off-distance should be scaled according to thickness
                                    paint.SetPathEffect(new DashPathEffect(new float[] { 10, 5 * control.BorderThickness }, 0));
                                }

                                if ((control.BorderGradientStartColor != default(Xamarin.Forms.Color) && control.BorderGradientEndColor != default(Xamarin.Forms.Color)) || (control.BorderGradientStops != null && control.BorderGradientStops.Any()))
                                {
                                    var angle = control.BorderGradientAngle / 360.0;

                                    // Calculate the new positions based on angle between 0-360.
                                    var a = canvas.Width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.75) / 2)), 2);
                                    var b = canvas.Height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.0) / 2)), 2);
                                    var c = canvas.Width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.25) / 2)), 2);
                                    var d = canvas.Height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.5) / 2)), 2);

                                    if (control.BorderGradientStops != null && control.BorderGradientStops.Count > 0)
                                    {
                                        // A range of colors is given. Let's add them.
                                        var orderedStops = control.BorderGradientStops.OrderBy(x => x.Offset).ToList();
                                        var colors       = orderedStops.Select(x => x.Color.ToAndroid().ToArgb()).ToArray();
                                        var locations    = orderedStops.Select(x => x.Offset).ToArray();

                                        var shader = new LinearGradient(canvas.Width - (float)a, (float)b, canvas.Width - (float)c, (float)d, colors, locations, Shader.TileMode.Clamp);
                                        paint.SetShader(shader);
                                    }
                                    else
                                    {
                                        // Only two colors provided, use that.
                                        var shader = new LinearGradient(canvas.Width - (float)a, (float)b, canvas.Width - (float)c, (float)d, control.BorderGradientStartColor.ToAndroid(), control.BorderGradientEndColor.ToAndroid(), Shader.TileMode.Clamp);
                                        paint.SetShader(shader);
                                    }
                                }
                                else
                                {
                                    paint.Color = control.BorderColor.ToAndroid();
                                }

                                paint.StrokeCap   = Paint.Cap.Square;
                                paint.StrokeWidth = borderThickness;
                                paint.SetStyle(style);

                                canvas.DrawPath(path, paint);
                            }
            }
        }
        private void DrawBorder(ACanvas canvas, PancakeView control)
        {
            var  borderThickness      = Context.ToPixels(control.BorderThickness);
            var  halfBorderThickness  = borderThickness / 2;
            bool hasShadowOrElevation = control.HasShadow || control.Elevation > 0;

            // TODO: This doesn't look entirely right yet when using it with rounded corners.
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)

                            using (var rect = new RectF(control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? -halfBorderThickness : halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Width + halfBorderThickness : canvas.Width - halfBorderThickness,
                                                        control.BorderDrawingStyle == BorderDrawingStyle.Outside && !hasShadowOrElevation ? canvas.Height + halfBorderThickness : canvas.Height - halfBorderThickness))
                            {
                                path.AddRoundRect(rect, GetRadii(control), direction);

                                if (control.BorderIsDashed)
                                {
                                    paint.SetPathEffect(new DashPathEffect(new float[] { 10, 20 }, 0));
                                }

                                if ((control.BorderGradientStartColor != default(Color) && control.BorderGradientEndColor != default(Color)) || (control.BorderGradientStops != null && control.BorderGradientStops.Any()))
                                {
                                    var angle = control.BorderGradientAngle / 360.0;

                                    // Calculate the new positions based on angle between 0-360.
                                    var a = canvas.Width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.75) / 2)), 2);
                                    var b = canvas.Height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.0) / 2)), 2);
                                    var c = canvas.Width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.25) / 2)), 2);
                                    var d = canvas.Height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.5) / 2)), 2);

                                    if (control.BorderGradientStops != null)
                                    {
                                        // A range of colors is given. Let's add them.
                                        var orderedStops = control.BorderGradientStops.OrderBy(x => x.Offset).ToList();
                                        var colors       = orderedStops.Select(x => x.Color.ToAndroid().ToArgb()).ToArray();
                                        var locations    = orderedStops.Select(x => x.Offset).ToArray();

                                        var shader = new LinearGradient(canvas.Width - (float)a, (float)b, canvas.Width - (float)c, (float)d, colors, locations, Shader.TileMode.Clamp);
                                        paint.SetShader(shader);
                                    }
                                    else
                                    {
                                        // Only two colors provided, use that.
                                        var shader = new LinearGradient(canvas.Width - (float)a, (float)b, canvas.Width - (float)c, (float)d, control.BorderGradientStartColor.ToAndroid(), control.BorderGradientEndColor.ToAndroid(), Shader.TileMode.Clamp);
                                        paint.SetShader(shader);
                                    }
                                }
                                else
                                {
                                    paint.Color = control.BorderColor.ToAndroid();
                                }

                                paint.StrokeCap   = Paint.Cap.Square;
                                paint.StrokeWidth = borderThickness;
                                paint.SetStyle(style);

                                canvas.DrawPath(path, paint);
                            }
        }
Exemplo n.º 7
0
        public MainPage()
        {
            InitializeComponent();

            //Setare actiune pe poza de profil
            //actiune = Actiuni_PozaProfil.AdaugareDispozitiv;

            //Programatic
            bw.DoWork             += delegate { Thread.Sleep(1300); };
            bw.RunWorkerCompleted += delegate
            {
                PancakeView pancake = new PancakeView();
                pancake.CornerRadius = 10;

                Grid camera = new Grid {
                    BackgroundColor = Color.Aqua, HeightRequest = 100, WidthRequest = 140
                };
                camera.Children.Add(new Image
                {
                    Source = $"Zona{new Random().Next(1, 4)}", //apasat < 4 ? $"Zona{apasat}" : $"Zona{apasat - 2}",
                    Aspect = Aspect.AspectFill
                });

                Frame chenar_textCamera = new Frame
                {
                    BackgroundColor   = Color.FromHex("#ffa418"),
                    HasShadow         = false,
                    VerticalOptions   = LayoutOptions.Start,
                    HorizontalOptions = LayoutOptions.Start,
                    Margin            = 2,
                    Padding           = new Thickness(8, 2),
                    CornerRadius      = 10
                };

                chenar_textCamera.Content = new Label {
                    Text = "Zona " + nrDispozitive, TextColor = Color.White
                };

                camera.Children.Add(chenar_textCamera);
                pancake.Content = camera;
                carusel.Children.Add(pancake);

                lblListaDispozitive.Text = "Dispozitive";
                nrDispozitive++;
            };


            bwAdaugareCamera.DoWork             += delegate { Thread.Sleep(1300); };
            bwAdaugareCamera.RunWorkerCompleted += delegate
            {
                StackLayout camera = new StackLayout {
                    Orientation = StackOrientation.Vertical
                };

                BoxView linie = new BoxView
                {
                    BackgroundColor = Color.White,
                    HeightRequest   = 2,
                    WidthRequest    = 130
                };

                Label lblDenumireCamera = new Label
                {
                    Margin     = new Thickness(10, 0, 0, 0),
                    TextColor  = Color.White,
                    FontSize   = 18,
                    FontFamily = "TextSemiBold",
                    Text       = "Camera " + nrCamere
                };

                Label lblNrDispozitiveCamera = new Label
                {
                    Margin     = new Thickness(10, -10, 0, 0),
                    TextColor  = Color.FromHex("#95a8b6"),
                    FontSize   = 12,
                    FontFamily = "TextLight",
                    Text       = $"{new Random().Next(2, 6)} dispozitive"
                };

                camera.Children.Add(linie);
                camera.Children.Add(lblDenumireCamera);
                camera.Children.Add(lblNrDispozitiveCamera);

                chenarCamere.Children.Add(camera);

                lblListaCamere.Text = "Camere";
                nrCamere++;
            };
            //nimic

            /*for(int i = 1; i <= 5; i++)
             * {
             *//*PancakeView pancake = new PancakeView();
             *  pancake.CornerRadius = 10;
             *
             *  Grid camera = new Grid{ BackgroundColor = Color.Aqua, HeightRequest = 100, WidthRequest = 140 };
             *  camera.Children.Add(new Image {
             *      Source = i < 4 ? $"Zona{i}" : $"Zona{i - 2}",
             *      Aspect = Aspect.AspectFill });
             *
             *  Frame chenar_textCamera = new Frame {
             *      BackgroundColor = Color.FromHex("#ffa418"),
             *      HasShadow = false,
             *      VerticalOptions = LayoutOptions.Start,
             *      HorizontalOptions = LayoutOptions.Start,
             *      Margin = 2,
             *      Padding = new Thickness(8, 2),
             *      CornerRadius = 10
             *  };
             *
             *  chenar_textCamera.Content = new Label { Text = "Zona " + i, TextColor = Color.White };
             *
             *  camera.Children.Add(chenar_textCamera);
             *  pancake.Content = camera;
             *  carusel.Children.Add(pancake);*//*
             * }*/
        }
Exemplo n.º 8
0
        public GamePage()
        {
            _gameMap = new AbsoluteLayout
            {
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Margin            = new Thickness(15)
            };
            _gameMap.SetBinding(BindingContextProperty, nameof(GameViewModel.Numbers));
            _gameMap.BindingContextChanged += OnGameMapBindingContextChanged;
            AbsoluteLayout.SetLayoutBounds(_gameMap, new Rectangle(.5, .5, -1, -1));
            AbsoluteLayout.SetLayoutFlags(_gameMap, AbsoluteLayoutFlags.PositionProportional);

            var isClosing = false;

            var mainMenuButton = new PancakeView
            {
                BackgroundColor = Color.Black.MultiplyAlpha(.65),
                CornerRadius    = new CornerRadius(0, 10, 10, 0),
                Padding         = new Thickness(10, 5),
                Margin          = new Thickness(15, Device.RuntimePlatform == Device.iOS ? 40 : 20),
                BorderColor     = Color.White,
                BorderThickness = 2,
                HeightRequest   = 40,
                Content         = new Label
                {
                    FontSize                = 30,
                    Text                    = "< MENU",
                    TextColor               = Color.White,
                    FontFamily              = "MandaloreRegular",
                    VerticalTextAlignment   = TextAlignment.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                }
            };

            AbsoluteLayout.SetLayoutBounds(mainMenuButton, new Rectangle(0, 0, -1, -1));
            AbsoluteLayout.SetLayoutFlags(mainMenuButton, AbsoluteLayoutFlags.PositionProportional);
            Task.Run(async() =>
            {
                await Task.Delay(300);
                TouchEff.SetCommand(mainMenuButton, new Command(() =>
                {
                    if (isClosing || Navigation.NavigationStack.OfType <GamePage>().Count() > 1)
                    {
                        return;
                    }
                    isClosing = true;
                    if (Preferences.Get("ShouldPlaySound", true))
                    {
                        DependencyService.Resolve <IAudioService>().Play("click.mp3", false);
                    }
                    Navigation.PopAsync();
                }));
            });


            TouchEff.SetNativeAnimation(mainMenuButton, true);

            var newGameButton = new PancakeView
            {
                BackgroundColor = Color.Black.MultiplyAlpha(.65),
                CornerRadius    = new CornerRadius(0, 10, 10, 0),
                Padding         = new Thickness(10, 5),
                Margin          = new Thickness(15, Device.RuntimePlatform == Device.iOS ? 40 : 20),
                BorderColor     = Color.White,
                BorderThickness = 2,
                HeightRequest   = 40,
                Content         = new Label
                {
                    FontSize                = 30,
                    Text                    = "NEW GAME",
                    TextColor               = Color.White,
                    FontFamily              = "MandaloreRegular",
                    VerticalTextAlignment   = TextAlignment.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                }
            };

            AbsoluteLayout.SetLayoutBounds(newGameButton, new Rectangle(1, 0, -1, -1));
            AbsoluteLayout.SetLayoutFlags(newGameButton, AbsoluteLayoutFlags.PositionProportional);
            Task.Run(async() =>
            {
                await Task.Delay(300);
                TouchEff.SetCommand(newGameButton, new Command(async() =>
                {
                    if (isClosing)
                    {
                        return;
                    }
                    isClosing = true;
                    if (Preferences.Get("ShouldPlaySound", true))
                    {
                        DependencyService.Resolve <IAudioService>().Play("click.mp3", false);
                    }
                    await Navigation.PushAsync(new GamePage()
                    {
                        BindingContext = new GameViewModel()
                    });
                    Navigation.RemovePage(this);
                }));
            });
            TouchEff.SetNativeAnimation(newGameButton, true);


            var swapsCountLabel = new Label();

            swapsCountLabel.SetBinding(Label.TextProperty, nameof(GameViewModel.SwapsCount));

            var backImage = new Image
            {
                IsVisible = Device.RuntimePlatform != Device.Android,
                Opacity   = 0.98,
                Source    = "back",
                Aspect    = Aspect.AspectFill
            };

            AbsoluteLayout.SetLayoutBounds(backImage, new Rectangle(0, 0, 1, 1));
            AbsoluteLayout.SetLayoutFlags(backImage, AbsoluteLayoutFlags.All);

            var blurFrame = new PancakeView
            {
                CornerRadius    = new CornerRadius(50, 10, 10, 50),
                BorderColor     = Color.Red,
                BackgroundColor = Color.Black.MultiplyAlpha(.65)
            };

            AbsoluteLayout.SetLayoutBounds(blurFrame, new Rectangle(.5, .5, -1, -1));
            AbsoluteLayout.SetLayoutFlags(blurFrame, AbsoluteLayoutFlags.PositionProportional);

            var countLabel = new Label
            {
                FontSize   = 50,
                TextColor  = Color.White,
                FontFamily = "MandaloreHalftone"
            };

            countLabel.SetBinding(Label.TextProperty, nameof(GameViewModel.SwapsCount));

            var labelStack = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    new Label
                    {
                        FontSize   = 50,
                        TextColor  = Color.White,
                        Text       = "SWAPS:",
                        FontFamily = "MandaloreHalftone"
                    },
                    countLabel
                }
            };

            AbsoluteLayout.SetLayoutBounds(labelStack, new Rectangle(.5, .5, -1, -1));
            AbsoluteLayout.SetLayoutFlags(labelStack, AbsoluteLayoutFlags.PositionProportional);

            _gameMap.SizeChanged += (s, e) =>
            {
                using (blurFrame.Batch())
                {
                    blurFrame.WidthRequest  = _gameMap.Width;
                    blurFrame.HeightRequest = _gameMap.Height;
                }
                labelStack.TranslationY = -_gameMap.Height / 2 - labelStack.Height / 2 - 20;
            };

            Content = new AbsoluteLayout
            {
                Children =
                {
                    backImage,
                    mainMenuButton,
                    newGameButton,
                    labelStack,
                    blurFrame,
                    _gameMap
                }
            };

            PerformTransitionCommand = new Command(p =>
            {
                var transition        = (TransitionModel)p;
                var item              = _items[transition.Value - 1];
                item.InputTransparent = true;
                var fromPosition      = GetPosition(transition.FromIndex);
                var toPosition        = GetPosition(transition.ToIndex);
                var isVertical        = Math.Abs(fromPosition.X - toPosition.X) < Math.Abs(fromPosition.Y - toPosition.Y);

                var start = fromPosition.X;
                var end   = toPosition.X;
                if (isVertical)
                {
                    start = fromPosition.Y;
                    end   = toPosition.Y;
                }

                item.Animate("PerformTransition", new Animation(v =>
                {
                    var x = v;
                    var y = fromPosition.Y;
                    if (isVertical)
                    {
                        x = fromPosition.X;
                        y = v;
                    }
                    AbsoluteLayout.SetLayoutBounds(item, new Rectangle(x, y, fromPosition.Width, fromPosition.Height));
                }, start, end), 16, 250, Easing.CubicInOut, (d, b) =>
                {
                    item.InputTransparent = false;
                    if (!b)
                    {
                        item.BorderThickness = transition.ToIndex == transition.Value - 1
                            ? 2
                            : 0;
                    }
                });
            });

            HandleWinCommand = new Command(v =>
            {
                var okButton = new PancakeView
                {
                    Margin          = new Thickness(0, 30, 0, 0),
                    HeightRequest   = 60,
                    BorderColor     = Color.White,
                    BorderThickness = 2,
                    Content         = new Label
                    {
                        HorizontalTextAlignment = TextAlignment.Center,
                        VerticalTextAlignment   = TextAlignment.Center,
                        FontSize   = 40,
                        Text       = "HOORAY!",
                        TextColor  = Color.White,
                        FontFamily = "MandaloreRegular",
                    }
                };
                TouchEff.SetPressedOpacity(okButton, 0.7);
                TouchEff.SetPressedScale(okButton, 0.95);
                TouchEff.SetCommand(okButton, new Command(async() =>
                {
                    if (Preferences.Get("ShouldPlaySound", true))
                    {
                        DependencyService.Resolve <IAudioService>().Play("click.mp3", false);
                    }
                    await Navigation.PushAsync(new GamePage()
                    {
                        BindingContext = new GameViewModel()
                    });
                    Navigation.RemovePage(this);
                }));

                var popupView = new PancakeView
                {
                    Scale                   = 0,
                    Margin                  = new Thickness(25, 0),
                    Padding                 = new Thickness(25, 10, 25, 20),
                    CornerRadius            = new CornerRadius(50, 10, 10, 50),
                    BackgroundGradientStops = new GradientStopCollection
                    {
                        new GradientStop
                        {
                            Color  = Color.FromRgb(41, 36, 88),
                            Offset = .3f
                        },
                        new GradientStop
                        {
                            Color  = Color.FromRgb(16, 15, 29),
                            Offset = .7f
                        },
                        new GradientStop
                        {
                            Color  = Color.Black,
                            Offset = 1f
                        }
                    },
                    BorderColor     = Color.White,
                    BorderThickness = 2,
                    Content         = new StackLayout
                    {
                        Spacing  = 0,
                        Children =
                        {
                            new Label
                            {
                                HorizontalTextAlignment = TextAlignment.Center,
                                FontSize   = 50,
                                Text       = "CONGRATILATIONS",
                                TextColor  = Color.White,
                                FontFamily = "MandaloreHalftone",
                            },
                            new Label
                            {
                                HorizontalTextAlignment = TextAlignment.Center,
                                FontSize   = 40,
                                Text       = $"YOUR SCORE IS: {v}",
                                TextColor  = Color.White,
                                FontFamily = "MandaloreHalftone",
                            },
                            okButton
                        }
                    }
                };
                AbsoluteLayout.SetLayoutBounds(popupView, new Rectangle(.5, .5, 1, -1));
                AbsoluteLayout.SetLayoutFlags(popupView, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);

                var popup = new AbsoluteLayout
                {
                    Opacity         = 0,
                    BackgroundColor = Color.Black.MultiplyAlpha(.85),
                    Children        =
                    {
                        popupView
                    }
                };
                AbsoluteLayout.SetLayoutBounds(popup, new Rectangle(0, 0, 1, 1));
                AbsoluteLayout.SetLayoutFlags(popup, AbsoluteLayoutFlags.All);
                (Content as AbsoluteLayout).Children.Add(popup);
                popup.FadeTo(1, 350, Easing.CubicInOut);
                popupView.ScaleTo(1, 500, Easing.CubicInOut);
                if (Preferences.Get("ShouldPlaySound", true))
                {
                    Vibration.Vibrate(250);
                }
            });

            this.SetBinding(PerformTransitionCommandProperty, nameof(GameViewModel.PerformTransitionCommand));
            this.SetBinding(HandleWinCommandProperty, nameof(GameViewModel.HandleWinCommand));

            NavigationPage.SetHasNavigationBar(this, false);
        }
        public CollectionViewPopupPage()
        {
            AnimationTranslationValue = App.ScreenSize.Height;

            VerticalContentOptions = LayoutOptions.EndAndExpand;

            var collectionView = new CollectionView
            {
                VerticalOptions = LayoutOptions.Fill,
                HeightRequest   = 300,
                ItemsLayout     =
                    new LinearItemsLayout(ItemsLayoutOrientation.Vertical)
                {
                    ItemSpacing = 5
                },
                Header = new ContentView {
                    Content = new Label {
                        Text = "Header"
                    },
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.Center,
                },
                Footer = new ContentView
                {
                    Content = new Label {
                        Text = "Footer"
                    },
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.Center,
                },
                ItemTemplate = new DataTemplate(() => new Frame
                {
                    VerticalOptions   = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.Center,
                    HasShadow         = false,
                    HeightRequest     = 30,
                    WidthRequest      = 30,
                    CornerRadius      = 15,
                    BackgroundColor   = Color.LightGray,
                    Content           = new Label
                    {
                        Text              = "Sample",
                        TextColor         = Color.White,
                        VerticalOptions   = LayoutOptions.Center,
                        HorizontalOptions = LayoutOptions.Center
                    }
                }),
                ItemsSource = new List <object> {
                    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
                }
            };

            collectionView.Scrolled += (e, args) => this.IsPullToCloseEnabled = !(args.VerticalOffset > 0);

            DismissableContent = new PancakeView
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor = Color.White,
                CornerRadius    = new CornerRadius(10, 10, 0, 0),
                Content         = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Fill,
                    BackgroundColor = Color.White,
                    Padding         = 7,
                    Spacing         = 10,
                    Children        =
                    {
                        new BoxView
                        {
                            Color             = Color.LightGray,
                            WidthRequest      = 40,
                            HeightRequest     = 4,
                            CornerRadius      = 2,
                            HorizontalOptions = LayoutOptions.Center
                        },
                        new Label
                        {
                            Text              = "Pull to close",
                            LineBreakMode     = LineBreakMode.NoWrap,
                            HorizontalOptions = LayoutOptions.Center,
                            TextColor         = Color.Black
                        },
                        collectionView
                    }
                }
            };
        }
Exemplo n.º 10
0
        public MainMenuPage()
        {
            var backImage = new Image
            {
                IsVisible = Device.RuntimePlatform != Device.Android,
                Opacity   = 0.98,
                Source    = "back",
                Aspect    = Aspect.AspectFill
            };

            AbsoluteLayout.SetLayoutBounds(backImage, new Rectangle(0, 0, 1, 1));
            AbsoluteLayout.SetLayoutFlags(backImage, AbsoluteLayoutFlags.All);

            var settingButton = new PancakeView
            {
                Margin          = new Thickness(0, 30, 0, 0),
                HeightRequest   = 60,
                BorderColor     = Color.White,
                BorderThickness = 2,
                Content         = new Label
                {
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Center,
                    FontSize   = 40,
                    Text       = "SETTINGS",
                    TextColor  = Color.White,
                    FontFamily = "MandaloreRegular",
                }
            };

            TouchEff.SetPressedOpacity(settingButton, 0.7);
            TouchEff.SetPressedScale(settingButton, 0.95);
            TouchEff.SetCommand(settingButton, new Command(OnSettingsClicked));
            //TouchEff.SetNativeAnimation(settingButton, true);

            var startGameButton = new PancakeView
            {
                Margin          = new Thickness(0, 15, 0, 0),
                HeightRequest   = 60,
                BorderColor     = Color.White,
                BorderThickness = 2,
                Content         = new Label
                {
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Center,
                    FontSize   = 40,
                    Text       = "START GAME",
                    TextColor  = Color.White,
                    FontFamily = "MandaloreRegular",
                }
            };

            TouchEff.SetPressedOpacity(startGameButton, 0.7);
            TouchEff.SetPressedScale(startGameButton, 0.95);
            TouchEff.SetCommand(startGameButton, new Command(OnStartGameClicked));
            //TouchEff.SetNativeAnimation(startGameButton, true);

            var buttonsView = new PancakeView
            {
                TranslationY    = -37.5,
                Opacity         = 0,
                Margin          = new Thickness(Device.Idiom == TargetIdiom.Phone ? 15 : 125, 0),
                Padding         = new Thickness(25),
                CornerRadius    = new CornerRadius(50, 10, 10, 50),
                BackgroundColor = Color.Black.MultiplyAlpha(.65),
                Content         = new StackLayout
                {
                    Spacing  = 0,
                    Children =
                    {
                        new Label
                        {
                            HorizontalTextAlignment = TextAlignment.Center,
                            VerticalTextAlignment   = TextAlignment.Center,
                            FontSize   = 50,
                            Text       = "RAW ROWS",
                            TextColor  = Color.White,
                            FontFamily = "MandaloreHalftone",
                        },
                        settingButton,
                        startGameButton
                    }
                }
            };

            AbsoluteLayout.SetLayoutBounds(buttonsView, new Rectangle(.5, .5, 1, -1));
            AbsoluteLayout.SetLayoutFlags(buttonsView, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);

            Content = new AbsoluteLayout
            {
                Children =
                {
                    backImage,
                    buttonsView
                }
            };

            NavigationPage.SetHasNavigationBar(this, false);

            Task.Run(async() =>
            {
                await Task.Delay(500);
                Device.BeginInvokeOnMainThread(() => buttonsView.FadeTo(1, 1000, Easing.CubicInOut));
            });
        }
Exemplo n.º 11
0
        private void Setup(PancakeView pancake)
        {
            // Create the border layer
            if (pancake.BorderThickness > 0 || pancake.BackgroundColor != default(Color))
            {
                if (_borderLayer == null)
                {
                    _borderLayer = new CAShapeLayer();
                }

                // Set the border color to clear if it's not set.
                if (pancake.BorderColor == Xamarin.Forms.Color.Default)
                {
                    _borderLayer.StrokeColor = UIColor.Clear.CGColor;
                }
                else
                {
                    _borderLayer.StrokeColor = pancake.BorderColor.ToCGColor();
                }

                if (pancake.BackgroundColor == default(Color))
                {
                    _borderLayer.FillColor = null;
                }
                else
                {
                    _borderLayer.FillColor = pancake.BackgroundColor.ToCGColor();
                }

                _borderLayer.LineWidth = pancake.BorderThickness;

                // There's no border layer yet, insert it.
                if (Layer.Sublayers == null || (Layer.Sublayers != null && !Layer.Sublayers.Any(x => x.GetType() == typeof(CAShapeLayer))))
                {
                    Layer.InsertSublayer(_borderLayer, 0);
                }

                UpdateBorderLayer(pancake);
            }

            if (pancake.HasShadow)
            {
                // TODO: Ideally we want to be able to have individual corner radii + shadows
                // However, on iOS we can only do one radius + shadow.
                Layer.CornerRadius  = (nfloat)pancake.CornerRadii.TopLeft;
                Layer.ShadowRadius  = 10;
                Layer.ShadowColor   = UIColor.Black.CGColor;
                Layer.ShadowOpacity = 0.4f;
                Layer.ShadowOffset  = new SizeF();
                Layer.MasksToBounds = false;
            }
            else
            {
                Layer.ShadowOpacity = 0;
                Layer.MasksToBounds = true;
            }

            // Set the rasterization for performance optimization.
            Layer.RasterizationScale = UIScreen.MainScreen.Scale;
            Layer.ShouldRasterize    = true;
        }