Пример #1
0
        void ConnectToService()
        {
            try
            {
                var key = Xamarin.InAppBilling.Utilities.Security.Unify(new[]
                {
                    GetNumberString(3),
                    GetNumberString(6),
                    GetNumberString(1),
                    GetNumberString(4),
                    GetNumberString(2),
                    GetNumberString(7),
                    GetNumberString(0),
                    GetNumberString(5)
                },
                                                                        new[] { 0, 1, 2, 3, 4, 5, 6, 7 }
                                                                        );

                _serviceConnection              = new InAppBillingServiceConnection(this, key);
                _serviceConnection.OnConnected += HandleOnConnected;
                _serviceConnection.Connect();
            }
            catch (Exception ex)
            {
                GaService.TrackAppException(this.Class, "ConnectToService", ex, false);
            }
        }
Пример #2
0
        private async void HandleOnConnected()
        {
            try
            {
                _billingHandler = _serviceConnection.BillingHandler;
                if (_billingHandler == null)
                {
                    ErrorOccur("Нет подключения");
                    return;
                }
                _billingHandler.OnProductPurchased += BillingHandlerOnProductPurchased;
                _billingHandler.BuyProductError    += BillingHandler_BuyProductError;
                Rep.DatabaseHelper.DatabaseChanged += InstanceOnDatabaseChanged;
                await GetInventory();

                if (_allErshProducts == null || !_allErshProducts.Any() || _allProducts == null || !_allProducts.Any())
                {
                    ErrorOccur("Нет подключения");
                    return;
                }
                SetupInventory();
            }
            catch (Exception ex)
            {
                GaService.TrackAppException(this.Class, "HandleOnConnected", ex, true);
                ErrorOccur(ex.Message);
            }
        }
Пример #3
0
        private void BillingHandlerOnProductPurchasedError(int responseCode, string sku)
        {
            var message = string.Format("Store(BillingHandlerOnOnProductPurchasedError)/nresponse code={0}, sku = {1}",
                                        responseCode, sku);

            GaService.TrackAppException(message, false);
        }
Пример #4
0
        private void Initialize()
        {
            try
            {
                _isEndGame = Intent.GetBooleanExtra("isEnd", false);

                _listView = FindViewById <ListView>(Resource.Id.playerTournamentListView);
                var sortedPlayersList = Rep.Instance.Players.Players.OrderByDescending(player => player.Score).ToList();
                SetFirstItem(sortedPlayersList.First(), _isEndGame);
                sortedPlayersList.RemoveAt(0);
                var adapter = new ResultPlayersAdapter(this, sortedPlayersList);
                _listView.Adapter = adapter;

                _startNewGameButton = FindViewById <Button>(Resource.Id.startNewGameButton);
                this.AddButtonTouchListener(_startNewGameButton);
                _startNewGameButton.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);

                _endGameButton = FindViewById <Button>(Resource.Id.endGameButton);
                this.AddButtonTouchListener(_endGameButton);
                _endGameButton.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);

                _dialog = new DialogRatingFragment()
                {
                    ShowsDialog = true
                };
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "Initialize", exception, false);
            }
        }
Пример #5
0
        private void ServiceConnectionOnInAppBillingError(InAppBillingErrorType error, string message)
        {
            var message1 = string.Format("Store(ServiceConnectionOnInAppBillingError)/nerror={0}, message = {1}", error, message);

            GaService.TrackAppException(message1, false);
            ErrorOccur("Error of service connection: " + message);
        }
Пример #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);
                _task = Rep.DatabaseHelper.Tasks.Enumerator.Current;
                var category = Rep.DatabaseHelper.Tasks.GetCategory(_task.CategoryId);
                SetContentView(Resource.Layout.ImageCard);
                _image = FindViewById <ImageView>(Resource.Id.imageCardView);
                var imageIdentifier = this.Resources.GetIdentifier(category.Image, "drawable", this.PackageName);
                _image.SetImageResource(imageIdentifier);

                var text = FindViewById <TextView>(Resource.Id.textCard);
                text.SetTypeface(Rep.FontManager.Get(Font.BankirRetro), TypefaceStyle.Normal);
                text.Text = _task.TaskName;

                _contentFrameLayout = FindViewById(Resource.Id.contentFrameLayout);

                _contentFrameLayout.Click += ContentFrameLayoutOnClick;
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "OnCreate", exception, false);
                base.OnBackPressed();
            }
        }
        private void MakePhoto_Click(object sender, EventArgs e)
        {
            try
            {
                var picker = new MediaPicker(this);
                if (!picker.IsCameraAvailable || !picker.PhotosSupported)
                {
                    ShowUnsupported();
                    return;
                }
                var store = new StoreCameraMediaOptions
                {
                    Directory = "Ersh",
                    Name      = string.Format("ersh_{0}.jpg", DateTime.Now.Ticks + new Random().Next())
                };

                var intent = picker.GetTakePhotoUI(store);
                this.StartActivityForResult(intent, 2);
            }

            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "MakePhoto_Click", exception, false);
            }
        }
Пример #8
0
        public View CreateActionButton(int resourceId)
        {
            _actionButton = LayoutInflater.Inflate(resourceId, null);
            try
            {
                var layout   = ActionBar.CustomView.FindViewById <RelativeLayout>(Resource.Id.customActionButton);
                var textView = _actionButton as TextView;
                if (textView != null)
                {
                    textView.SetTypeface(Rep.FontManager.Get(Font.Condensed), TypefaceStyle.Normal);
                }
                var param = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.WrapContent,
                    ViewGroup.LayoutParams.MatchParent);
                param.AddRule(LayoutRules.CenterVertical);
                param.AddRule(LayoutRules.AlignParentRight);
                layout.AddView(_actionButton, param);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "CreateActionButton", exception, false);
            }

            return(_actionButton);
        }
Пример #9
0
        void SetFirstItem(Player player, bool isEndGame)
        {
            try
            {
                var leadString  = FindViewById <TextView>(Resource.Id.leadText);
                var imageView   = FindViewById <ImageView>(Resource.Id.playerImage);
                var textScore   = FindViewById <TextView>(Resource.Id.scoreText);
                var playerName  = FindViewById <TextView>(Resource.Id.playerName);
                var playerScore = FindViewById <TextView>(Resource.Id.playerScore);

                leadString.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);
                textScore.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);
                playerName.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);
                playerScore.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);

                imageView.SetImageBitmap(player.Image);
                playerName.Text  = player.Name.ToUpper();
                playerScore.Text = player.Score.ToString();
                leadString.Text  = Resources.GetString(isEndGame
                    ? Resource.String.WinnerString
                    : Resource.String.LeadString);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "SetFirstItem", exception, false);
            }
        }
Пример #10
0
 protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
 {
     try
     {
         if (resultCode == Result.Canceled)
         {
             return;
         }
         if (requestCode == 100)
         {
             StartActivityForResult(typeof(ChoosePlayerActivity), 101);
         }
         if (requestCode == 101)
         {
             var position = data.GetIntExtra("player_id", -1);
             if (position < 0)
             {
                 throw new InvalidOperationException("You should choose player");
             }
             var player = Rep.Instance.Players[position];
             player.Score -= 5;
             _taskDialog   = TaskDialog.Bear;
             ShowDialogTask(player, _taskEnumerator.Current.Score);
         }
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "OnActivityResult", exception, false);
     }
 }
Пример #11
0
        private void ChooseNewPhoto(object sender, EventArgs e)
        {
            try
            {
                var prev = FragmentManager.FindFragmentByTag("dialog");

                ChoosePhotoDialog dialog;
                if (prev == null)
                {
                    dialog              = new ChoosePhotoDialog();
                    dialog.ChoosePhoto += ChoosePhoto_Click;
                    dialog.MakePhoto   += MakePhoto_Click;
                }
                else
                {
                    dialog = (ChoosePhotoDialog)prev;
                }

                var fragmentTransaction = FragmentManager.BeginTransaction();
                dialog.Show(fragmentTransaction, "dialog");
            }

            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "ChooseNewPhoto", exception, false);
            }
        }
Пример #12
0
        private void SetConfirmButtonEnabled(bool enabled)
        {
            try
            {
                if (_confirmButton.Enabled == enabled)
                {
                    return;
                }
                _confirmButton.Enabled = enabled;
                _confirmButton.SetTextColor(enabled ? Resources.GetColor(Resource.Color.white) : this.GetColorWithOpacity(Resource.Color.white, Resource.Color.button_text_disabled));
                if (enabled)
                {
                    _confirmButton.Background.ClearColorFilter();
                }
                else
                {
                    _confirmButton.Background.SetColorFilter(Resources.GetColor(Resource.Color.button_disabled), PorterDuff.Mode.SrcAtop);
                }
            }

            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "SetConfirmButtonEnabled", exception, false);
            }
        }
Пример #13
0
 private AlertDialog.Builder GetShopDialog()
 {
     try
     {
         var builder = new AlertDialog.Builder(this);
         builder.SetTitle(Resource.String.GoToShopingString);
         builder.SetMessage(Resource.String.GoToSaleString);
         builder.SetPositiveButton(GetString(Resource.String.YesString), delegate
         {
             var store = new Intent(this, typeof(StoreActivity));
             store.PutExtra("from_game", true);
             this.StartActivityWithoutBackStack(store);
         });
         builder.SetNegativeButton(GetString(Resource.String.NoString), delegate
         {
             var intent = new Intent(this, typeof(ResultsGameActivity));
             intent.PutExtra("isEnd", true);
             this.StartActivityWithoutBackStack(intent);
         });
         builder.SetCancelable(false);
         return(builder);
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "GetShopDialog", exception, false);
         throw;
     }
 }
Пример #14
0
        private Intent GetIntentStartActivity(bool isDefault)
        {
            try
            {
                Rep.Instance.Players.Enumerator.SetCurrent(isDefault ? 0 : this.GetCurrentPlayer());
                if (isDefault)
                {
                    return(new Intent(this, typeof(MainMenuActivity)));
                }
                var prefX     = GetSharedPreferences("X", FileCreationMode.Private);
                var className = prefX.GetString("lastActivity", null);
                switch (className)
                {
                case StringConst.GameActivity:
                    return(new Intent(this, typeof(GameActivity)));

                case StringConst.MainMenuActivity:
                    return(new Intent(this, typeof(MainMenuActivity)));

                case StringConst.ResultGameActivity:
                    var intent = new Intent(this, typeof(ResultsGameActivity));
                    intent.PutExtra("isEnd", true);
                    return(intent);

                default:
                    return(new Intent(this, typeof(MainMenuActivity)));
                }
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "GetIntentStartActivity", exception, false);
                return(new Intent(this, typeof(MainMenuActivity)));
            }
        }
Пример #15
0
        private async void HandleOnConnected()
        {
            try
            {
                Toast.MakeText(this, "Произошло подключение", ToastLength.Short).Show();
                _billingHandler = _serviceConnection.BillingHandler;
                if (_billingHandler == null)
                {
                    return;
                }
                _billingHandler.OnProductPurchased                += BillingHandlerOnProductPurchased;
                _billingHandler.OnProductPurchasedError           += BillingHandlerOnProductPurchasedError;
                _billingHandler.BuyProductError                   += _billingHandler_BuyProductError;
                _billingHandler.InAppBillingProcesingError        += (message) => { ErrorOccur("InAppBillingProcesingError: " + message); };
                _billingHandler.OnGetProductsError                += (int responseCode, Bundle ownedItems) => { ErrorOccur("OnGetProductsError: " + responseCode); };
                _billingHandler.OnInvalidOwnedItemsBundleReturned += (Bundle ownedItems) => { ErrorOccur("OnInvalidOwnedItemsBundleReturned"); };
                _billingHandler.OnPurchaseConsumedError           += (int responseCode, string token) => { ErrorOccur("OnPurchaseConsumedError: token=" + token); };
                _billingHandler.OnPurchaseFailedValidation        += (Purchase purchase, string purchaseData, string purchaseSignature)
                                                                     => { ErrorOccur(string.Format("OnPurchaseFailedValidation: id={0}, state={1}", purchase.ProductId, purchase.PurchaseState)); };
                Rep.Instance.DatabaseChanged += InstanceOnDatabaseChanged;
                await GetInventory();

                SetupInventory();
            }
            catch (Exception ex)
            {
                GaService.TrackAppException(ex.Message, true);
                ErrorOccur(ex.Message);
            }
        }
Пример #16
0
        private void SetDescriptionText()
        {
            try
            {
                var taskCount    = Rep.DatabaseHelper.Tasks.Count;
                var allTaskCount = IntConst.AllTaskCount - Rep.DatabaseHelper.Tasks.Count;
                _taskDescription.Text = _purchases.Any(x => x.IsAll && x.ProductType == StringConst.Task)
                    ? string.Format("Вам доступны все {0} заданий и безлимитная подписка на новые",
                                    IntConst.AllTaskCount)
                    : string.Format("У вас {0} заданий, {1}", taskCount,
                                    allTaskCount == 0 ? "вы можете купить безлимитную подписку на новые" : "можно купить еще " + allTaskCount);

                var bonusCount    = Rep.DatabaseHelper.Bonuses.Count;
                var allBonusCount = IntConst.AllBonusCount - Rep.DatabaseHelper.Bonuses.Count;
                _bonusDescription.Text = _purchases.Any(x => x.IsAll && x.ProductType == StringConst.Bonus)
                    ? string.Format("Вам доступны все {0} бонусов и безлимитная подписка на новые",
                                    IntConst.AllBonusCount)
                    : string.Format("У вас {0} бонусов, {1}", bonusCount,
                                    allBonusCount == 0 ? "вы можете купить безлимитную подписку на новые" : "можно купить еще " + allBonusCount);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "SetDescriptionText", exception, false);
            }
        }
Пример #17
0
        private void Initialize()
        {
            try
            {
                _chooseFromContactsButton = FindViewById <Button>(Resource.Id.chooseFromContButton);
                _confirmButton            = FindViewById <Button>(Resource.Id.confirmButton);
                _cancelButton             = FindViewById <Button>(Resource.Id.cancelButton);
                _editText          = FindViewById <EditText>(Resource.Id.playerName);
                _playerImageButton = FindViewById <ImageButton>(Resource.Id.playerImage);

                SetFont(_cancelButton);
                SetFont(_confirmButton);
                SetFont(_chooseFromContactsButton);
                SetFontItalic(_editText);



                _confirmButton.Background.Alpha = 255;
                _confirmButton.SetTextColor(Resources.GetColor(Resource.Color.white));
                _cancelButton.Background.Alpha = 255;
                _cancelButton.SetTextColor(Resources.GetColor(Resource.Color.white));

                _confirmButton.Enabled = true; SetConfirmButtonEnabled(false);


                _player = new Player();
                //To set _playImage to default
                PlayerImagePath = null;
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "Initialize", exception, false);
            }
        }
Пример #18
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);

                var viewGroup = this.LayoutInflater.Inflate(Resource.Layout.YorshActionBar, null);
                var param     = new ActionBar.LayoutParams(
                    ViewGroup.LayoutParams.MatchParent,
                    ViewGroup.LayoutParams.MatchParent);
                var title = viewGroup.FindViewById <TextView>(Resource.Id.titleText);
                title.Text       = Title;
                AllowBackPressed = true;
                title.SetTypeface(Rep.FontManager.Get(Font.Bold), TypefaceStyle.Normal);
                ActionBar.SetIcon(new ColorDrawable(Resources.GetColor(Android.Resource.Color.Transparent)));
                ActionBar.SetDisplayShowTitleEnabled(false);
                ActionBar.SetDisplayShowCustomEnabled(true);
                ActionBar.SetCustomView(viewGroup, param);

                SetHomeButtonEnabled(true);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "SetHomeButtonEnabled", exception, false);
            }
        }
Пример #19
0
        //Get Photo and Name from Contact
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            try
            {
                if (resultCode == Result.Canceled)
                {
                    return;
                }

                if (requestCode == 2)
                {
                    _player.FromContacts = false;
                    data.GetMediaFileExtraAsync(this).ContinueWith(t =>
                                                                   PlayerImagePath = t.Result.Path);
                }

                if (requestCode == 3)
                {
                    if (data == null || data.Data == null)
                    {
                        return;
                    }

                    var addressBook = new AddressBook(Application.Context)
                    {
                        PreferContactAggregation = false
                    };

                    var contact = addressBook.Load(data.Data.LastPathSegment);

                    if (string.IsNullOrEmpty(contact.DisplayName))
                    {
                        Toast.MakeText(this, Resources.GetString(Resource.String.NoNameString), ToastLength.Short)
                        .Show();
                    }
                    else
                    {
                        _editText.Text = contact.DisplayName;
                    }


                    if (contact.GetThumbnail() != null)
                    {
                        _player.FromContacts = true;
                        PlayerImagePath      = data.Data.LastPathSegment;
                    }
                    else
                    {
                        _player.FromContacts = false;
                        PlayerImagePath      = null;
                    }
                }
            }

            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "OnActivityResult", exception, false);
            }
        }
Пример #20
0
        private async void BillingHandlerOnProductPurchased(int response, Purchase purchase, string purchaseData, string purchaseSignature)
        {
            var ershPurchase = PurchaseCreator.Create(purchase.ProductId);

            if (!ershPurchase.IsAll && GetPurchasesContainesKey(ershPurchase.OrdiginalId).Count() + 1 == GetProductsContainesKey(ershPurchase.OrdiginalId).Count())
            {
                GaService.TrackAppEvent(StringConst.TrackEventCardsAreEnds, string.Format("{0}", ershPurchase.OrdiginalId));
            }

            await Rep.DatabaseHelper.AddProductAsync(ershPurchase);
        }
Пример #21
0
 void MoveNextPlayer()
 {
     try
     {
         _playerEnumerator.MoveNext();
         RefreshPlayer();
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "MoveNextPlayer", exception, false);
     }
 }
Пример #22
0
 protected override void OnPause()
 {
     try
     {
         //_startGameButton.Background.ClearColorFilter();
         base.OnPause();
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "OnPause", exception, false);
     }
 }
Пример #23
0
        public async Task ResetAsync()
        {
            try
            {
                await _players.ResetAsync();

                await _helper.ResetAsync();
            }
            catch (Exception exception)
            {
                GaService.TrackAppException("Rep", "ResetAsync", exception, false);
            }
        }
Пример #24
0
 private void OnLicenseChecked()
 {
     try
     {
         InitConnectToGoogleStore();
         _serviceConnection.Connect();
         CreateLocalDatabase();
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "OnLicenseChecked", exception, true);
     }
 }
Пример #25
0
 async Task RefreshPurchaseItems()
 {
     try
     {
         var purchased     = _serviceConnection.BillingHandler.GetPurchases(ItemType.Product);
         var ershPurchases = purchased == null ? new List <ErshPurchase>() : purchased.Where(purchase => purchase.PurchaseState == 0).Select(purchase => PurchaseCreator.Create(purchase.ProductId)).ToList();
         await Rep.DatabaseHelper.CheckAndRefreshPurshases(ershPurchases, _serviceConnection.Connected);
     }
     catch (Exception ex)
     {
         GaService.TrackAppException(this.Class, "RefreshPurchaseItems", ex, false);
     }
 }
Пример #26
0
 protected override void OnResume()
 {
     try
     {
         base.OnResume();
         _listView.Adapter      = new AddNewPlayerListAdapter(this);
         IsPlayersCountValidate = Rep.Instance.Players.Count > 1;
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "OnResume", exception, false);
     }
 }
Пример #27
0
 private void RefreshPurchasedItems()
 {
     try
     {
         var purchases = _billingHandler.GetPurchases(ItemType.Product);
         _purchases = purchases == null
             ? new List <ErshPurchase>()
             : purchases.Where(purchase => purchase.PurchaseState == 0).Select(purchase => PurchaseCreator.Create(purchase.ProductId)).ToList();
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "RefreshPurchasedItem", exception, false);
     }
 }
Пример #28
0
 protected override void OnCreate(Bundle bundle)
 {
     try
     {
         base.OnCreate(bundle);
         SetContentView(Resource.Layout.AddNewPlayer);
         Initialize();
         RegisterSubscribes();
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "OnCreate", exception, false);
     }
 }
Пример #29
0
 public void SetHomeButtonEnabled(bool enabled)
 {
     try
     {
         ActionBar.SetDisplayHomeAsUpEnabled(enabled);
         ActionBar.SetDisplayShowHomeEnabled(enabled);
         var title = ActionBar.CustomView.FindViewById <TextView>(Resource.Id.titleText);
         title.SetPadding(0, 0, enabled ? 100 : 0, 0);
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "SetHomeButtonEnabled", exception, false);
     }
 }
Пример #30
0
 void RefreshPlayer()
 {
     try
     {
         var player = _playerEnumerator.Current;
         FindViewById <ImageView>(Resource.Id.playerInGameImage).SetImageBitmap(player.Image);
         _playerName.Text     = player.Name;
         _playerPosition.Text = Resources.GetString(Resource.String.PositionPlayerString) + Rep.Instance.Players.GetPosition(player);
         _playerScore.Text    = player.Score.ToString();
     }
     catch (Exception exception)
     {
         GaService.TrackAppException(this.Class, "RefreshPlayer", exception, false);
     }
 }