protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); RequestWindowFeature(WindowFeatures.NoTitle); SetContentView(Resource.Layout.GameplayLayout); var gameData = Intent.GetStringExtra(GameModel.GetKey()); GameModel gameModel = GameModel.DeserializeFromJson(gameData); this.balloonOverlayLayer = FindViewById <RelativeLayout> (Resource.Id.balloonOverlay); this.bottomSectionText = balloonOverlayLayer.FindViewById <TextView>(Resource.Id.textView1); this.balloonViewContainer = this.balloonOverlayLayer.FindViewById <RelativeLayout> (Resource.Id.balloonContainerRelativeLayout); this.gameoverOverlayLayer = balloonOverlayLayer.FindViewById <RelativeLayout>(Resource.Id.gameOverOverlay); this.gameoverText = gameoverOverlayLayer.FindViewById <TextView> (Resource.Id.gameoverTextView); this.textureView = gameoverOverlayLayer.FindViewById <TextureView>(Resource.Id.textureView1); this.textureView.SurfaceTextureListener = this; AndHUD.Shared.Show(this, "Loading Game Data", -1, MaskType.Black); ((POPpicApplication)Application).GetGameRepository(this).ContinueWith(r => { viewModel = new GameplayViewModel(r.Result, gameModel, Resources.DisplayMetrics.WidthPixels, Resources.DisplayMetrics.HeightPixels); viewModel.Tick += StopWatchTick; viewModel.InitializeAsync().ContinueWith((t) => { if (!t.IsFaulted) { this.player1TimeText = FindViewById <TextView> (Resource.Id.leftplayerTimeText); this.player1NameText = FindViewById <TextView> (Resource.Id.leftPlayerNameText); this.player1NameText.Text = this.viewModel.PlayerName1; this.player2TimeText = FindViewById <TextView> (Resource.Id.rightplayerTimeText); this.player2NameText = FindViewById <TextView> (Resource.Id.rightPlayerNameText); this.player2NameText.Text = this.viewModel.PlayerName2; this.finishRoundButton = balloonOverlayLayer.FindViewById <Button>(Resource.Id.button1); this.finishRoundButton.Text = this.viewModel.FinishTurnButtonText; this.finishRoundButton.Click += OnNextRoundClicked; // this.balloonImage.Touch += OnBalloonTouched; this.balloonView = new BalloonBackgroundView(this, this.viewModel); this.balloonView.BalloonTouchChanged += this.OnBalloonTouched; // Bitmap background; Bitmap balloon; if (this.viewModel.BackgroundImageStream != null && this.viewModel.BalloonImageStream != null) { background = BitmapFactory.DecodeStream(this.viewModel.BackgroundImageStream); balloon = BitmapFactory.DecodeStream(this.viewModel.BalloonImageStream); } else { background = BitmapFactory.DecodeResource(Resources, Resource.Drawable.balloonbackground); balloon = BitmapFactory.DecodeResource(Resources, Resource.Drawable.balloon); } var pop = BitmapFactory.DecodeResource(Resources, Resource.Drawable.popImage); balloonView.SetImages(background, balloon, pop); this.balloonViewContainer.AddView(this.balloonView); this.SetImage(Resource.Id.leftPlayerImage, this.viewModel.PlayerProfileImage1); this.SetImage(Resource.Id.rightPlayerImage, this.viewModel.PlayerProfileImage2); if (this.viewModel.LoserImgData != null) { Bitmap bmp = BitmapFactory.DecodeByteArray(this.viewModel.LoserImgData, 0, this.viewModel.LoserImgData.Length); SetResultImage(bmp); ShowOverlay(); } this.bottomSectionText.Text = this.viewModel.BottomHintText; UpdateUI(); } else { AndHUD.Shared.ShowError(this, "Error Loading Game", MaskType.Black, TimeSpan.FromSeconds(3)); Finish(); } AndHUD.Shared.Dismiss(); }, TaskScheduler.FromCurrentSynchronizationContext()); }, TaskScheduler.FromCurrentSynchronizationContext()); inflationMediaPlayer = new MediaPlayer(); var fd = Application.Resources.OpenRawResourceFd(Resource.Raw.aria02); inflationMediaPlayer.SetDataSource(fd.FileDescriptor, fd.StartOffset, fd.Length); inflationMediaPlayer.SetAudioStreamType(Android.Media.Stream.System); inflationMediaPlayer.Prepare(); poppingMediaPlayer = new MediaPlayer(); var popFd = Application.Resources.OpenRawResourceFd(Resource.Raw.BalloonPop); poppingMediaPlayer.SetDataSource(popFd.FileDescriptor, popFd.StartOffset, popFd.Length); poppingMediaPlayer.SetAudioStreamType(Android.Media.Stream.System); poppingMediaPlayer.Prepare(); }
public override void OnBackPressed() { this.Finish(); this.balloonView.CleanupBitmaps(); this.balloonView = null; }