void ReleaseDesignerOutlets()
        {
            if (TotalCoins != null)
            {
                TotalCoins.Dispose();
                TotalCoins = null;
            }

            if (AmountToConsume != null)
            {
                AmountToConsume.Dispose();
                AmountToConsume = null;
            }

            if (ConsumeButton != null)
            {
                ConsumeButton.Dispose();
                ConsumeButton = null;
            }

            if (SpecialView != null)
            {
                SpecialView.Dispose();
                SpecialView = null;
            }

            if (ViewTouched != null)
            {
                ViewTouched.Dispose();
                ViewTouched = null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Views the did load.
        /// </summary>
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Wireup amount to consume
            AmountToConsume.ShouldBeginEditing = delegate(UITextField field){
                //Placeholder
                UIView.BeginAnimations("keyboard");
                UIView.SetAnimationDuration(0.3f);
                MoveView(-170);
                UIView.CommitAnimations();
                return(true);
            };
            AmountToConsume.ShouldReturn = delegate(UITextField field){
                field.ResignFirstResponder();
                //this.View.EndEditing(true);
                UIView.BeginAnimations("keyboard");
                UIView.SetAnimationDuration(0.3f);
                MoveView(0);
                UIView.CommitAnimations();
                //field.Text holds the current value


                return(true);
            };
            AmountToConsume.ShouldEndEditing = delegate(UITextField field){
                field.ResignFirstResponder();
                //this.View.EndEditing(true);
                UIView.BeginAnimations("keyboard");
                UIView.SetAnimationDuration(0.3f);
                MoveView(0);
                UIView.CommitAnimations();
                //field.Text holds the current value

                return(true);
            };

            // Stop editing if the user touches the view
            ViewTouched.AddTarget(async delegate() {
                // Close the keyboard if displayed
                AmountToConsume.EndEditing(true);
            });


            // Wireup the consume button
            ConsumeButton.TouchUpInside += (object sender, EventArgs e) => {
                // Close the keyboard if displayed
                AmountToConsume.EndEditing(true);

                // Trap all errors
                try {
                    // Verify
                    int amount    = int.Parse(AmountToConsume.Text);
                    int available = PurchaseManager.ProductQuantityAvailable("gold.coins");

                    // Valid amount?
                    if (amount < 1 || amount > available)
                    {
                        //Display Alert Dialog Box
                        using (var alert = new UIAlertView("Xamarin.InAppPurchase", "Not a valid amount to consume. The amount to consume must be at least one and less than the available amount.", null, "OK", null))
                        {
                            alert.Show();
                        }

                        // Abort
                        return;
                    }

                    // Ask the purchase manager to consume the amount
                    PurchaseManager.ConsumeProductQuantity("gold.coins", amount);
                }
                catch {
                    //Display Alert Dialog Box
                    using (var alert = new UIAlertView("Xamarin.InAppPurchase", "Not a valid amount to consume.", null, "OK", null))
                    {
                        alert.Show();
                    }
                }
            };
        }