Exemplo n.º 1
0
 private void btnResetClassic_Clicked(object sender, EventArgs e)
 {
     ClasicGameSetting.BoardSize       = 6;
     ClasicGameSetting.DifficultyLevel = DifficultyLevel.Medium;
     ClasicGameSetting.FirstMove       = false;
     XFToast.LongMessage("Classic mode is reset.");
 }
Exemplo n.º 2
0
        private async void ShowExitDialog()
        {
            XFToast.LongMessage("Press back again to exit");
            await Task.Delay(1000);

            _canClose = false;
        }
Exemplo n.º 3
0
        protected void btnSound_Clicked(object sender, EventArgs e)
        {
            ToolbarItem btnSound = (ToolbarItem)sender;

            IsMute = !IsMute;
            GlobalSetting.IsMute = IsMute;
            string newValue = IsMute ? "Off" : "On";

            btnSound.Icon = IsMute ? "soundmute" : "sound";
            XFToast.LongMessage($"Sound is {newValue}");
        }
        private async void btnDiffLevel_Clicked(object sender, EventArgs e)
        {
            var action = await DisplayActionSheet("Choose Difficulty level", "Cancel", null, GetButtons(3));

            if (action == null || action == "Cancel")
            {
                return;
            }
            var newDifficulyLevel = (DifficultyLevel)Enum.Parse(typeof(DifficultyLevel), action.Replace("» ", "").Trim());

            if (newDifficulyLevel == level)
            {
                return;
            }
            ClasicGameSetting.DifficultyLevel = newDifficulyLevel;
            new ClassicGameRunner().Start();
            btnDiffLevel.Text = action;
            XFToast.LongMessage($"Difficulty level is set to {action}");
        }
        private async void btnPlayerMode_Clicked(object sender, EventArgs e)
        {
            var action = await DisplayActionSheet("Choose Player mode", "Cancel", null, GetButtons(1));

            if (action == null || action == "Cancel")
            {
                return;
            }
            action = action.Replace("» ", "").Trim();
            bool is2Players = (action == "2 Players");

            if (is2Players == ClasicGameSetting.Is2Players)
            {
                return;
            }

            ClasicGameSetting.Is2Players = is2Players;
            new ClassicGameRunner().Start();
            XFToast.LongMessage($"Game is set to {action} mode");
        }
        private async void btnFirstMove_Clicked(object sender, EventArgs e)
        {
            var action = await DisplayActionSheet("Choose who should move first", "Cancel", null, GetButtons(4));

            if (action == null || action == "Cancel")
            {
                return;
            }
            action = action.Replace("» ", "").Trim();
            bool newFirstMove = (action == "CPU");

            if (newFirstMove == moveFirst)
            {
                return;
            }

            ClasicGameSetting.FirstMove = newFirstMove;
            new ClassicGameRunner().Start();
            btnFirstMove.Text = action;
            XFToast.LongMessage($"First move is set to {action}");
        }
        private async void btnBoardSize_Clicked(object sender, EventArgs e)
        {
            var action = await DisplayActionSheet("Choose Board size", "Cancel", null, GetButtons(2));

            if (action == null || action == "Cancel")
            {
                return;
            }
            action = action.Replace("» ", "").Trim();
            int newBoardSize = Convert.ToInt32(action.Split('x')[0]);

            if (newBoardSize == count)
            {
                return;
            }
            //count = newBoardSize;
            ClasicGameSetting.BoardSize = newBoardSize;
            new ClassicGameRunner().Start();
            //Parent.LaunchGame(newBoardSize);
            btnBoardSize.Text = action;// $"{newBoardSize}x{newBoardSize}";
            //RebuildMenu(2, action);
            //Detail = new NavigationPage(StartGame());
            XFToast.LongMessage($"Board size is set to {action}");
        }
Exemplo n.º 8
0
 private void btnResetChallange_Clicked(object sender, EventArgs e)
 {
     ChallengeGameSetting.ChallengeLevel = 1;
     ChallengeGameSetting.StarCount      = 0;
     XFToast.LongMessage("Challenge mode is reset to Level 1.");
 }
Exemplo n.º 9
0
 private void btnSave_Clicked(object sender, EventArgs e)
 {
     GlobalSetting.Player1Name = ePlayer1Name.Text;
     GlobalSetting.Player2Name = ePlayer2Name.Text;
     XFToast.LongMessage("Setting saved.");
 }
Exemplo n.º 10
0
        //public string localHostUrl = "http://192.168.0.174:8080/PSM2017/";

        public ScanPage()
        {
            zxings = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                AutomationId      = "zxingScannerView",
                IsScanning        = true
            };

            zxings.OnScanResult += (result) =>
                                   Device.BeginInvokeOnMainThread(async() =>
            {
                zxings.IsAnalyzing = false;
                string barcode     = result.Text;

                if (App.Database.GetProducts().Count < 10)
                {
                    string data              = "";
                    string postData          = "barcode=" + barcode;
                    string url               = localHostUrl + "dbGetProduct.php";
                    WebService searchProduct = new WebService();
                    data = searchProduct.postService(postData, url);
                    if (data.Contains("{"))
                    {
                        Product product = JsonConvert.DeserializeObject <Product>(data);
                        //Product product = products.Find(x => x.barcode == Int32.Parse(barcode));
                        App.Database.AddProduct(product);
                        await DisplayAlert("Item Added", product.name + " added into list.", "OK");
                    }
                    else
                    {
                        XFToast.LongMessage(data);
                    }
                }
                else
                {
                    await DisplayAlert("Alert!", "Your cart has 10 items. The cart could only hold up to 10 items. " +
                                       "Please pay for the item(s) or delete item!!!", "OK");
                }

                // Stop analysis until we navigate away so we don't keep reading barcodes
                zxings.IsAnalyzing = true;
                // Show an alert
                //await DisplayAlert("Scanned Barcode", result.Text, "OK");

                // Navigate away
                //await Navigation.PopAsync();
            });

            var scanOverlay = new RelativeLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };

            Xamarin.Forms.Label text = new Xamarin.Forms.Label
            {
                Text              = "Hold your phone up to the barcode",
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White
            };
            Xamarin.Forms.Label text2 = new Xamarin.Forms.Label
            {
                Text              = "Scanning will happen automatically",
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White
            };

            BoxView redLine = new BoxView
            {
                BackgroundColor = Color.Red,
                Opacity         = 0.6
            };
            BoxView boxView = new BoxView
            {
                BackgroundColor = Color.Black,
                Opacity         = 0.7
            };
            BoxView boxView2 = new BoxView
            {
                BackgroundColor = Color.Black,
                Opacity         = 0.7
            };
            BoxView boxView3 = new BoxView
            {
                BackgroundColor = Color.Black,
                Opacity         = 0.7
            };
            BoxView boxView4 = new BoxView
            {
                BackgroundColor = Color.Black,
                Opacity         = 0.7
            };

            scanOverlay.Children.Add(boxView,
                                     Constraint.RelativeToParent((parent) => {
                return(parent.X);
            }),
                                     Constraint.RelativeToParent((parent) => {
                return(parent.Y);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width * 0.1);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height);
            })
                                     );
            scanOverlay.Children.Add(boxView2,
                                     Constraint.RelativeToParent((parent) => {
                return(parent.Width * 0.9);
            }),
                                     Constraint.RelativeToParent((parent) => {
                return(parent.Y);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width * 0.1);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height);
            })
                                     );
            scanOverlay.Children.Add(boxView3,
                                     Constraint.RelativeToParent((parent) => {
                return(parent.Width * 0.1);
            }),
                                     Constraint.RelativeToParent((parent) => {
                return(parent.Y);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width * 0.8);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height * 0.2);
            })
                                     );
            scanOverlay.Children.Add(boxView4,
                                     Constraint.RelativeToParent((parent) => {
                return(parent.Width * 0.1);
            }),
                                     Constraint.RelativeToParent((parent) => {
                return(parent.Height * 0.6);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width * 0.8);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height * 0.4);
            })
                                     );
            scanOverlay.Children.Add(redLine,
                                     Constraint.RelativeToParent((parent) => {
                return(parent.Width * 0.1);
            }),
                                     Constraint.RelativeToParent((parent) => {
                return(parent.Height * 0.4);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width * 0.8);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(3);
            })
                                     );
            scanOverlay.Children.Add(text,
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width * 0.2);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height * 0.1);
            })
                                     );
            scanOverlay.Children.Add(text2,
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Width * 0.2);
            }),
                                     Constraint.RelativeToParent((parent) =>
            {
                return(parent.Height * 0.8);
            })
                                     );


            defaultOverlay = new ZXingDefaultOverlay
            {
                TopText    = "Hold your phone up to the barcode",
                BottomText = "Scanning will happen automatically",
                //ShowFlashButton = true,
                AutomationId = "zxingDefaultOverlay",
            };
            defaultOverlay.BindingContext = defaultOverlay;

            var customOverlay = new RelativeLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };
            var torchFAB = new FAB.Forms.FloatingActionButton();

            torchFAB.Source      = "flashlight_icon.png";
            torchFAB.NormalColor = Color.FromHex("FFE066");
            torchFAB.Size        = FAB.Forms.FabSize.Normal;
            torchFAB.Clicked    += (sender, args) =>
            {
                zxings.ToggleTorch();
            };

            var listFAB = new FAB.Forms.FloatingActionButton();

            listFAB.Source      = "shoping_cart.png";
            listFAB.NormalColor = Color.FromHex("FFE066");
            listFAB.Size        = FAB.Forms.FabSize.Normal;
            listFAB.Clicked    += async(sender, args) =>
            {
                //zxing.IsAnalyzing = false;
                //XFToast.LongMessage("Hello");
                await Navigation.PushAsync(new ListViewProduct());
            };

            var addFAB = new FAB.Forms.FloatingActionButton();

            addFAB.Source      = "plus_black_symbol.png";
            addFAB.NormalColor = Color.FromHex("FFE066");
            addFAB.Size        = FAB.Forms.FabSize.Normal;
            addFAB.Clicked    += async(sender, args) =>
            {
                if (App.Database.GetProducts().Count < 10)
                {
                    var config = new PromptConfig();
                    config.Title     = "Manual enter product barcode";
                    config.InputType = InputType.Number;
                    config.OnAction  = async(result) =>
                    {
                        if (result.Ok)
                        {
                            string     barcode       = result.Text;
                            string     postData      = "barcode=" + barcode;
                            string     url           = localHostUrl + "dbGetProduct.php";
                            WebService searchProduct = new WebService();
                            string     data          = searchProduct.postService(postData, url);

                            if (data.Contains("{"))
                            {
                                Product product = JsonConvert.DeserializeObject <Product>(data);
                                //Product product = products.Find(x => x.barcode == Int32.Parse(barcode));
                                App.Database.AddProduct(product);
                                await DisplayAlert("Item Added", product.name + " added into list.", "OK");
                            }
                            else
                            {
                                XFToast.LongMessage(data);
                            }
                        }
                        zxings.IsAnalyzing = true;
                    };
                    await Task.Run(() =>
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            zxings.IsAnalyzing = false;
                            UserDialogs.Instance.Prompt(config);
                        });
                    });
                }
                else
                {
                    await DisplayAlert("Alert!", "Your cart has 10 items.The cart could only hold up to 10 items. " +
                                       "Please pay for the item(s) or delete item!!!", "OK");
                }
                //App.Database.AddProduct(new Product {Name = "Milo", Price = 20.587, Barcode = 00001 });
            };

            var checkOutFAB = new FAB.Forms.FloatingActionButton();

            checkOutFAB.Source      = "cash_register_machine.png";
            checkOutFAB.NormalColor = Color.FromHex("FFE066");
            checkOutFAB.Size        = FAB.Forms.FabSize.Normal;
            checkOutFAB.Clicked    += (sender, args) =>
            {
                //XFToast.LongMessage("Check out");
                var products = App.Database.GetProducts();

                if (products.Count > 0)
                {
                    Task.Run(async() => {
                        PayPalItem[] paypalItems = new PayPalItem[products.Count];
                        int i = 0;


                        foreach (Product product in products)
                        {
                            PayPalItem paypalItem = new PayPalItem(product.name, 1, Convert.ToDecimal(product.price), "MYR"
                                                                   , product.barcode);
                            paypalItems[i] = paypalItem;
                            i++;
                        }

                        var result = await CrossPayPalManager.Current.Buy(paypalItems, new Decimal(0.0), new Decimal(0.00));
                        if (result.Status == PayPalStatus.Cancelled)
                        {
                            Debug.WriteLine("Cancelled");
                        }
                        else if (result.Status == PayPalStatus.Error)
                        {
                            Debug.WriteLine(result.ErrorMessage);
                        }
                        else if (result.Status == PayPalStatus.Successful)
                        {
                            Debug.WriteLine(result.ServerResponse.Response.Id);

                            var jsonArray = JsonConvert.SerializeObject(products);

                            string jsnArray          = jsonArray.ToString();
                            string postData          = "receipt=" + jsnArray;
                            string url               = localHostUrl + "genReceipt.php";
                            WebService searchProduct = new WebService();
                            string data              = searchProduct.postService(postData, url);
                            if (data.ToLower().Contains(".pdf"))
                            {
                                Device.BeginInvokeOnMainThread(async() =>
                                {
                                    await DisplayAlert("Payment Success", "The payment is success!!", "OK");
                                    App.Database.ClearList();
                                    downloadPDF(data);
                                    await DisplayAlert("Download Success", "Receipt downloaded", "OK");
                                });
                            }
                        }
                    });
                }
                else
                {
                    DisplayAlert("Alert!", "There are no item in the cart list.", "OK");
                }
            };

            var receiptFAB = new FAB.Forms.FloatingActionButton();

            receiptFAB.Source      = "receiptIcon";
            receiptFAB.NormalColor = Color.FromHex("FFE066");
            receiptFAB.Size        = FAB.Forms.FabSize.Normal;
            receiptFAB.Clicked    += async(sender, args) =>
            {
                await Navigation.PushAsync(new ListPDF());
            };

            /*
             * customOverlay.Children.Add(
             *  torchFAB,
             *  xConstraint: Constraint.RelativeToParent((parent) => { return parent.Width - 48; }),
             *  yConstraint: Constraint.RelativeToParent((parent) => { return 8; })
             * );
             *
             * customOverlay.Children.Add(
             *  listFAB,
             *  Constraint.RelativeToView(torchFAB, (Parent, sibling) => { return sibling.X; }),
             *  Constraint.RelativeToView(torchFAB, (Parent, sibling) => { return sibling.Y + 48; })
             * );
             * customOverlay.Children.Add(
             *  addFAB,
             *  Constraint.RelativeToView(listFAB, (Parent, sibling) => { return sibling.X; }),
             *  Constraint.RelativeToView(listFAB, (Parent, sibling) => { return sibling.Y + 48; })
             * );
             * customOverlay.Children.Add(
             *  checkOutFAB,
             *  Constraint.RelativeToView(addFAB, (Parent, sibling) => { return sibling.X; }),
             *  Constraint.RelativeToView(addFAB, (Parent, sibling) => { return sibling.Y + 48; })
             * );
             * customOverlay.Children.Add(
             *  receiptFAB,
             *  Constraint.RelativeToView(checkOutFAB, (Parent, sibling) => { return sibling.X; }),
             *  Constraint.RelativeToView(checkOutFAB, (Parent, sibling) => { return sibling.Y + 48; })
             * );
             */

            customOverlay.Children.Add(
                torchFAB,
                xConstraint: Constraint.RelativeToParent((parent) => { return(parent.X + 6); }),
                yConstraint: Constraint.RelativeToParent((parent) => { return(parent.Height * 0.6 + 24); })
                );

            customOverlay.Children.Add(
                listFAB,
                Constraint.RelativeToView(torchFAB, (Parent, sibling) => { return(sibling.X + 72); }),
                Constraint.RelativeToView(torchFAB, (Parent, sibling) => { return(sibling.Y); })
                );
            customOverlay.Children.Add(
                addFAB,
                Constraint.RelativeToView(listFAB, (Parent, sibling) => { return(sibling.X + 72); }),
                Constraint.RelativeToView(listFAB, (Parent, sibling) => { return(sibling.Y); })
                );
            customOverlay.Children.Add(
                checkOutFAB,
                Constraint.RelativeToView(addFAB, (Parent, sibling) => { return(sibling.X + 72); }),
                Constraint.RelativeToView(addFAB, (Parent, sibling) => { return(sibling.Y); })
                );
            customOverlay.Children.Add(
                receiptFAB,
                Constraint.RelativeToView(checkOutFAB, (Parent, sibling) => { return(sibling.X + 72); }),
                Constraint.RelativeToView(checkOutFAB, (Parent, sibling) => { return(sibling.Y); })
                );


            var grid = new Grid
            {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
            };

            grid.Children.Add(zxings);
            //grid.Children.Add(defaultOverlay);
            grid.Children.Add(scanOverlay);
            grid.Children.Add(customOverlay);


            Content = grid;
        }
Exemplo n.º 11
0
        private async void DataGet()
        {
            if (string.IsNullOrWhiteSpace(Barrel.Current.Get(Url1)) && !CrossConnectivity.Current.IsConnected)
            {
                XFToast.LongMessage("No Previous data or Internet");
            }
            else
            {
                try
                {
                    sls.Children.Clear();
                    newlist1 = await MoneyCache.GetAsync <List <News> >(Url1);

                    newlist2 = await MoneyCache.GetAsync <List <NepNews> >(Url2);

                    activi.IsRunning = false;
                    activi.IsVisible = false;
                    newlist1         = newlist1.Take(3).ToList();
                    newlist2         = newlist2.Take(3).ToList();
                    foreach (NepNews n in newlist2)
                    {
                        n.desc = n.description.Take(30) + "...";
                    }
                    NewsCollection1 = new ObservableCollection <News>(newlist1);
                    NewsCollection2 = new ObservableCollection <NepNews>(newlist2);


                    foreach (News n in newlist1)
                    {
                        Frame fram = new Frame
                        {
                            IsClippedToBounds = true,
                            HasShadow         = true,
                            BackgroundColor   = Color.White,
                            OutlineColor      = Color.Gray,
                            Margin            = new Thickness(7),
                            Padding           = new Thickness(5)
                        };

                        var slsins = new StackLayout
                        {
                            Orientation = StackOrientation.Vertical
                        };



                        var imag = new Image
                        {
                            Source            = n.images,
                            Aspect            = Aspect.AspectFill,
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            VerticalOptions   = LayoutOptions.Start
                        };



                        slsins.Children.Add(imag);

                        var slslb = new StackLayout
                        {
                            Orientation = StackOrientation.Vertical,
                            Padding     = new Thickness(10, 5, 10, 5)
                        };

                        Label title = new Label
                        {
                            Text           = n.title,
                            FontSize       = 18,
                            FontAttributes = FontAttributes.Bold,
                            TextColor      = Color.Black
                        };

                        Label desc = new Label
                        {
                            Text      = n.description,
                            FontSize  = 18,
                            TextColor = Color.Black
                        };

                        slslb.Children.Add(title);
                        slslb.Children.Add(desc);

                        slsins.Children.Add(slslb);

                        fram.Content = slsins;

                        var tapGestureRecognizer = new TapGestureRecognizer();
                        tapGestureRecognizer.Tapped += async(s, e) =>
                        {
                            if (CrossConnectivity.Current.IsConnected)
                            {
                                await Navigation.PushAsync(new NewsDetailPage(n), true);
                            }
                            else
                            {
                                XFToast.LongMessage("No Internet Connection");
                            }
                        };

                        fram.GestureRecognizers.Add(tapGestureRecognizer);
                        sls.Children.Add(fram);
                    }

                    foreach (NepNews n2 in newlist2)
                    {
                        Frame fram2 = new Frame
                        {
                            IsClippedToBounds = true,
                            HasShadow         = true,
                            BackgroundColor   = Color.White,
                            OutlineColor      = Color.Gray,
                            Margin            = new Thickness(7),
                            Padding           = new Thickness(5)
                        };
                        var slsins = new StackLayout
                        {
                            Orientation = StackOrientation.Vertical
                        };


                        var imag = new Image
                        {
                            Source            = n2.title_image,
                            Aspect            = Aspect.AspectFill,
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            VerticalOptions   = LayoutOptions.Start
                        };

                        slsins.Children.Add(imag);

                        var slslb = new StackLayout
                        {
                            Orientation = StackOrientation.Vertical,
                            Padding     = new Thickness(10, 5, 10, 5)
                        };

                        Label title = new Label
                        {
                            Text           = n2.title,
                            FontSize       = 18,
                            FontAttributes = FontAttributes.Bold,
                            TextColor      = Color.Black
                        };
                        n2.desc = Constants.ScrubHtml(n2.description);

                        Label desc = new Label
                        {
                            Text      = new String(n2.desc.Take(200).ToArray()) + "...",
                            FontSize  = 18,
                            TextColor = Color.Black
                        };

                        slslb.Children.Add(title);
                        slslb.Children.Add(desc);

                        slsins.Children.Add(slslb);

                        fram2.Content = slsins;

                        var tapGestureRecognizer2 = new TapGestureRecognizer();
                        tapGestureRecognizer2.Tapped += async(s, e) =>
                        {
                            await Navigation.PushAsync(new NepaliNewsDetailPage(n2), true);
                        };

                        fram2.GestureRecognizers.Add(tapGestureRecognizer2);
                        sls.Children.Add(fram2);
                    }
                    view.Content = sls;
                    view.Opacity = 0;
                    await view.FadeTo(1, 1000, Easing.SpringIn);
                }catch (Exception ex)
                {
                }
            }
        }