Beispiel #1
0
		public async void AddGameHeroToSQl ()
		{

			string url = "https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v1/?key=6A9C411A88D047DA4C9E843EDF0B02F5&format=json&" +
				"language=en_us&itemizedonly=0";
			var ApiReq = new APIRequest ();
			var comm = new DBComm ();
			var temp = (JToken)await ApiReq.FetchJsonAsync (url);
			var jHeroes = (JToken)temp.SelectToken ("result.heroes");
			foreach (JToken jHero in jHeroes) {
				var hero = new Hero ();
				string cdnUrl = "http://cdn.dota2.com/apps/dota2/images/heroes/";
				hero.HeroId =(int) jHero.SelectToken ("id");
				hero.Name = (string)jHero.SelectToken ("name");
				hero.LocalName = (string)jHero.SelectToken ("localized_name");
				string heroName = hero.Name;
				heroName = heroName.Substring (14);
				hero.SHorImgUrl = cdnUrl+heroName+"_sb.png";
				hero.LHorImgUrl = cdnUrl+heroName+"_lg.png";
				hero.FHorImgUrl = cdnUrl+heroName+"_full.png";
				hero.FVerImgUrl = cdnUrl+heroName+"_vert.jpg";
				try {
						comm.Connect.Insert(hero);
						Console.Out.WriteLine (hero.LocalName);

				} catch (SQLiteException e) {
					Console.Out.WriteLine (e.Message);
				}
			}

		}
		async Task SetHeroesImageInLayout(CancellationToken token)
		{
			refreshFlag = true;
			APIRequest ApiReq = new APIRequest ();
			HeroDb heroDb = new HeroDb ();
			for (int i = 0; i < 5; i++) {
				token.ThrowIfCancellationRequested();

				Hero newHero = new Hero ();
				if (radiantPB.ListBanView [i].HeroId != 0) {
					var viewBanRad = FindViewById<RelativeLayout> (radiantPB.ListBanView [i].ResourceId);
					var imgRad = viewBanRad.FindViewById<ImageView> (Resource.Id.imageBan);
					var imgLine = viewBanRad.FindViewById<ImageView> (Resource.Id.imageLineBan);

					if (imgRad.Tag.ToString() == "no_ban") {
						//if (imgRad.GetTag == Resources.GetDrawable( Resource.Drawable.no_ban))
						//Bitmap bitmap = (BitmapDrawable)imgRad.Drawable.;
						newHero = heroDb.GetHeroFromSQL (radiantPB.ListBanView [i].HeroId);
						Bitmap b = BitmapFactory.DecodeByteArray (newHero.ImageHero, 0, newHero.ImageHero.Length);
						imgRad.SetImageBitmap (b);
						imgRad.Tag = "on_ban";
						imgLine.SetBackgroundResource (Resource.Drawable.on_ban);
						//img.SetScaleType (ImageView.ScaleType.Center);
					}
				}
				newHero = new Hero ();
				if (direPB.ListBanView [i].HeroId != 0) {
					var viewBanDire = FindViewById<RelativeLayout> (direPB.ListBanView [i].ResourceId);
					var imgDire = viewBanDire.FindViewById<ImageView> (Resource.Id.imageBan);
					var imgLine = viewBanDire.FindViewById<ImageView> (Resource.Id.imageLineBan);
					if (imgDire.Tag.ToString() == "no_ban") {
						newHero = heroDb.GetHeroFromSQL (direPB.ListBanView [i].HeroId);
						Bitmap b1 = BitmapFactory.DecodeByteArray (newHero.ImageHero, 0, newHero.ImageHero.Length);
						imgDire.SetImageBitmap (b1);
						imgDire.Tag = "on_ban";
						imgLine.SetBackgroundResource (Resource.Drawable.on_ban);
					}
				}
			}

			for (int i = 0; i < 5; i++) {
				token.ThrowIfCancellationRequested();
				Hero newHero = new Hero ();
				if (radiantPB.ListPicksView [i].HeroId != 0) {
					var viewPickRad = FindViewById<RelativeLayout> (radiantPB.ListPicksView [i].ResourceId);
					var imgRad = viewPickRad.FindViewById<ImageView> (Resource.Id.imagePick);
					var textHero = viewPickRad.FindViewById<TextView> (Resource.Id.textHeroNamePickTemp);
					if (imgRad.Tag.ToString() =="no_pick") {
						newHero = heroDb.GetHeroFromSQL (radiantPB.ListPicksView [i].HeroId);
						byte[] arr=await ApiReq.FetchByteArrAsync (newHero.FVerImgUrl);
						Bitmap b = BitmapFactory.DecodeByteArray (arr, 0, arr.Length);
						imgRad.SetImageBitmap (b);
						imgRad.Tag = "on_pick";
						textHero.SetBackgroundResource (Resource.Drawable.gradientDarkBlueToTransp);
						textHero.Text = newHero.LocalName;
					}
				}
				newHero = new Hero ();
				if (direPB.ListPicksView [i].HeroId != 0) {
					var viewPickDire = FindViewById<RelativeLayout> (direPB.ListPicksView [i].ResourceId);
					var imgDire = viewPickDire.FindViewById<ImageView> (Resource.Id.imagePick);
					var textHero = viewPickDire.FindViewById<TextView> (Resource.Id.textHeroNamePickTemp);
					if (imgDire.Tag.ToString() == "no_pick") {
						newHero = heroDb.GetHeroFromSQL (direPB.ListPicksView [i].HeroId);
						byte[] arr=await ApiReq.FetchByteArrAsync (newHero.FVerImgUrl);
						Bitmap b1 = BitmapFactory.DecodeByteArray (arr, 0, arr.Length);
						imgDire.SetImageBitmap (b1);
						imgDire.Tag = "on_pick";
						textHero.SetBackgroundResource (Resource.Drawable.gradientDarkBlueToTransp);
						textHero.Text = newHero.LocalName;

					}
				}
			}
			refreshFlag = false;
		}