Ejemplo n.º 1
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            RequestWindowFeature(WindowFeatures.NoTitle);
            Weather weather = await Core.GetWeather("51.0144", "114.1288");

            tagName = weather.Visibility.ToLower();
            token   = Intent.GetStringExtra("UserToken") ?? "";
            if (token != "")
            {
                InstagramClient client = new InstagramClient(token);
                MediasResponse  media  = await client.GetRecentMediaByTagName(tagName);

                var datas = media.Data;
                if (datas.Count > 0)
                {
                    Random rand        = new Random();
                    int    index       = rand.Next(0, media.Data.Count);
                    Bitmap imageBitmap = null;
                    String replacement = "p1080x1080";
                    Regex  rgx         = new Regex(@"(s|p)\d\d\dx\d\d\d");
                    String url         = media.Data.ElementAt <Media>(index).Images.StandardResolution.Url.ToString();
                    url = rgx.Replace(url, replacement);
                    using (var webClient = new WebClient())
                    {
                        var imageBytes = webClient.DownloadData(url);
                        if (imageBytes != null && imageBytes.Length > 0)
                        {
                            imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
                        }
                    }

                    SetContentView(Resource.Layout.weatherAPI);
                    ImageView image = FindViewById <ImageView>(Resource.Id.imgAbsolute);
                    image.SetImageBitmap(imageBitmap);
                    image.SetScaleType(ScaleType.CenterCrop);
                    runWeather("51.0114", "114.1288");
                    getGreeting();
                }
                ImageButton demo = FindViewById <ImageButton>(Resource.Id.demoMenu);
                demo.Click += delegate
                {
                    Intent intent = new Intent(this.ApplicationContext, typeof(DemoMenuActivity));
                    intent.SetFlags(ActivityFlags.NewTask);
                    StartActivity(intent);
                };
            }
            else
            {
                //TODO:pull image from database for criteria

                SetContentView(Resource.Layout.weatherAPI);
                ImageView image = FindViewById <ImageView>(Resource.Id.imgAbsolute);
                image.SetImageResource(Resource.Drawable.main);
                image.SetScaleType(ScaleType.CenterCrop);
                runWeather("51.0114", "114.1288");
            }



            // Set our view from the "main" layout resource
            //SetContentView(Resource.Layout.weatherAPI);


            // Get our button from the layout resource,
            // and attach an event to it
            //Button button = FindViewById<Button>(Resource.Id.weatherBtn);

            //button.Click += Button_Click;
        }