Esempio n. 1
0
        public static async Task <List <Bitmap> > GetBackdrop(string movieID, string type)
        {
            string key = "253ceb1e198e26b094348524da5bc8ab";

            string query = string.Format("https://api.themoviedb.org/3/{0}/{1}?api_key={2}", type, movieID, key);

            var result = downloadjson.getJson(query);

            List <Bitmap> photob = new List <Bitmap>();
            Bitmap        ph     = null;

            try
            {
                Java.Net.URL link1 = new Java.Net.URL("http://image.tmdb.org/t/p/w780/" + result["backdrop_path"].ToString());
                await Task.Run(() => { ph = BitmapFactory.DecodeStream(link1.OpenStream()); });

                photob.Add(ph);
            }
            catch (Exception ex) {
            }


            try
            {
                Java.Net.URL link2 = new Java.Net.URL("http://image.tmdb.org/t/p/w185/" + result["poster_path"].ToString());
                await Task.Run(() => { ph = BitmapFactory.DecodeStream(link2.OpenStream()); });

                photob.Add(ph);
                return(photob);
            }
            catch (Exception ex) {}
            return(photob);
        }
Esempio n. 2
0
        public Drawable GetDrawable(string source)
        {
            Drawable drawable;
            Bitmap   bitMap;

            BitmapFactory.Options bitMapOption;
            try
            {
                bitMapOption = new BitmapFactory.Options();
                bitMapOption.InJustDecodeBounds = false;
                bitMapOption.InPreferredConfig  = Bitmap.Config.Argb4444;
                bitMapOption.InPurgeable        = true;
                bitMapOption.InInputShareable   = true;
                var url = new Java.Net.URL(source);

                bitMap   = BitmapFactory.DecodeStream(url.OpenStream(), null, bitMapOption);
                drawable = new BitmapDrawable(bitMap);
                //var url = new Java.Net.URL(source);
                //drawable =  Drawable.CreateFromStream(url.OpenStream(), null);
            }
            catch (Exception ex)
            {
                return(null);
            }

            drawable.SetBounds(0, 0, bitMapOption.OutWidth, bitMapOption.OutHeight);
            return(drawable);
        }
Esempio n. 3
0
            private static Bitmap DownloadImage(string url, string uid)
            {
                Bitmap imageBitmap = null;

                try
                {
                    byte[] imageBytes;
                    using (var mstream = new MemoryStream())
                    {
                        using (var imageUrl = new Java.Net.URL(url))
                        {
                            var options = new BitmapFactory.Options
                            {
                                InSampleSize = 1,
                                InPurgeable  = true
                            };

                            var bit = BitmapFactory.DecodeStream(imageUrl.OpenStream(), null, options);
                            bit.Compress(Bitmap.CompressFormat.Jpeg, 70, mstream);
                        }
                        imageBytes = mstream.ToArray();
                        System.IO.File.WriteAllBytes(System.IO.Path.Combine(baseDir, uid), imageBytes);
                        if (imageBytes != null && imageBytes.Length > 0)
                        {
                            var options = new BitmapFactory.Options
                            {
                                InJustDecodeBounds = true,
                            };
                            // BitmapFactory.DecodeResource() will return a non-null value; dispose of it.
                            using (var dispose = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length))
                            {
                            }
                            var imageHeight  = options.OutHeight;
                            var imageWidth   = options.OutWidth;
                            var imageType    = options.OutMimeType;
                            var height       = (float)options.OutHeight;
                            var width        = (float)options.OutWidth;
                            var inSampleSize = 1D;

                            if (height > 100 || width > 100)
                            {
                                inSampleSize = width > height
                                                    ? height / 100
                                                    : width / 100;
                            }
                            options.InSampleSize       = (int)inSampleSize;
                            options.InJustDecodeBounds = false;
                            return(BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length, options));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteLine(LogPriority.Error, "GetImageFromBitmap Error", ex.Message);
                }
                return(imageBitmap);
            }
Esempio n. 4
0
        private async Task <string> DownloadFile(string url)
        {
            string path = string.Empty;

            try
            {
                var fileName = GetFileName(url);
                path = System.IO.Path.Combine(Path, fileName);

                int totalBytes = GetFileSize(url);

                using (var fileUrl = new Java.Net.URL(url))
                {
                    using (var stream = fileUrl.OpenStream())
                    {
                        byte[] bytes          = new byte[totalBytes];
                        int    numBytesToRead = totalBytes;
                        int    numBytesRead   = 0;

                        while (numBytesToRead > 0)
                        {
                            // Read may return anything from 0 to numBytesToRead.
                            int n = await stream.ReadAsync(bytes, numBytesRead, numBytesToRead);

                            // Break when the end of the file is reached.
                            if (n == 0)
                            {
                                //await Task.Yield();
                                break;
                            }

                            numBytesRead   += n;
                            numBytesToRead -= n;

                            float percentage = (float)numBytesRead / (float)totalBytes;

                            var message = new DownloadProgressMessage()
                            {
                                Percentage = percentage
                            };

                            MessagingCenter.Send <DownloadProgressMessage>(message, "DownloadProgressMessage");
                        }

                        File.WriteAllBytes(path, bytes);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogPriority.Error, "GetImageFromBitmap Error", ex.Message);
            }

            return(path);
        }
Esempio n. 5
0
        static bool Download(Uri uri, string target)
        {
            var buffer = new byte[4 * 1024];

            try
            {               // use Java.Net.URL instead of WebClient...
                var tmpfile  = target + ".tmp";
                var imageUrl = new Java.Net.URL(uri.AbsoluteUri);
                var stream   = imageUrl.OpenStream();
                LogDebug("====== open " + ImageName(uri.AbsoluteUri));
                using (var o = File.Open(tmpfile, FileMode.OpenOrCreate)) {
                    byte[] buf = new byte[1024];
                    int    r;
                    while ((r = stream.Read(buf, 0, buf.Length)) > 0)
                    {
                        o.Write(buf, 0, r);
                    }
                }

                //using (var file = new FileStream(tmpfile, FileMode.Create, FileAccess.Write, FileShare.Read))
                //{
                //var req = WebRequest.Create(uri) as HttpWebRequest;

                //using (var resp = req.GetResponse())
                //{
                //    using (var s = resp.GetResponseStream())
                //    {
                //        int n;
                //        while ((n = s.Read(buffer, 0, buffer.Length)) > 0)
                //        {
                //            file.Write(buffer, 0, n);
                //        }
                //    }
                //}
                //}
                if (!File.Exists(target))                   // we're never updating images if they change, to reduce Exceptions and speed up
                {
                    File.Move(tmpfile, target);
                }
                return(true);
            }
            catch (Exception e)
            {
                LogDebug(String.Format("Problem with {0} {1}", uri, e.Message));
                return(false);
            }
        }
Esempio n. 6
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View view = convertView; // re-use an existing view, if one is available

            if (view == null)        // otherwise create a new one
            {
                view = _context.LayoutInflater.Inflate(Android.Resource.Layout.ActivityListItem, null);
            }
            view.FindViewById <TextView>(Android.Resource.Id.Text1).Text = _items[position].Text;

            var imageUrl = new Java.Net.URL(_items[position].User.ProfileImageUrl);

            Task.Factory.StartNew(() =>
            {
                System.IO.Stream stream = imageUrl.OpenStream();
                var bitmap = Android.Graphics.BitmapFactory.DecodeStream(stream);
                (view.FindViewById <ImageView>(Android.Resource.Id.Icon)).SetImageBitmap(bitmap);
            });
            return(view);
        }
Esempio n. 7
0
        protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
        {
            string nodeResponse = "";

            try
            {
                var localNodeServer = new Java.Net.URL("http://localhost:3000/");
                var input           = new BufferedReader(
                    new InputStreamReader(localNodeServer.OpenStream()));
                String inputLine;
                while ((inputLine = input.ReadLine()) != null)
                {
                    nodeResponse = nodeResponse + inputLine;
                }
                input.Close();
            }
            catch (Exception ex)
            {
                nodeResponse = ex.ToString();
            }
            return(nodeResponse);
        }
        private string DownloadImage(string url)
        {
            try {
                using (var stream = new MemoryStream()) {
                    using (var imageUrl = new Java.Net.URL(url)) {
                        var options = new BitmapFactory.Options {
                            InSampleSize = 1,
                            InPurgeable  = true
                        };

                        var bit = BitmapFactory.DecodeStream(imageUrl.OpenStream(), null, options);
                        bit.Compress(Bitmap.CompressFormat.Png, 70, stream);
                    }
                    var imageBytes = stream.ToArray();

                    File.WriteAllBytes(this.Path, imageBytes);
                }
            } catch (Exception ex) {
                Log.WriteLine(LogPriority.Error, "GetImageFromBitmap Error", ex.Message);
            }

            return(this.Path);
        }
		private string DownloadImage (string url)
		{
			try {
			    using (var stream = new MemoryStream ()) {
					using (var imageUrl = new Java.Net.URL (url)) {
						var options = new BitmapFactory.Options {
							InSampleSize = 1,
							InPurgeable = true
						};

						var bit = BitmapFactory.DecodeStream (imageUrl.OpenStream (), null, options);
						bit.Compress (Bitmap.CompressFormat.Png, 70, stream);
					}
					var imageBytes = stream.ToArray ();

					File.WriteAllBytes (this.Path, imageBytes);
				}
			} catch (Exception ex) {
				Log.WriteLine (LogPriority.Error, "GetImageFromBitmap Error", ex.Message);
			}

			return this.Path;
		}
Esempio n. 10
0
		static bool Download(Uri uri, string target)
		{
			var buffer = new byte[4 * 1024];

			try
			{   // use Java.Net.URL instead of WebClient...
				var tmpfile = target + ".tmp";
				var imageUrl = new Java.Net.URL(uri.AbsoluteUri);
				var stream = imageUrl.OpenStream();
				LogDebug("====== open " + ImageName(uri.AbsoluteUri));
				using (var o = File.Open(tmpfile, FileMode.OpenOrCreate)) {
					byte[] buf = new byte[1024];
					int r;
					while ((r = stream.Read(buf, 0, buf.Length)) > 0) {
						o.Write(buf, 0, r);
					}
				}

				//using (var file = new FileStream(tmpfile, FileMode.Create, FileAccess.Write, FileShare.Read))
				//{
				//var req = WebRequest.Create(uri) as HttpWebRequest;

				//using (var resp = req.GetResponse())
				//{
				//    using (var s = resp.GetResponseStream())
				//    {
				//        int n;
				//        while ((n = s.Read(buffer, 0, buffer.Length)) > 0)
				//        {
				//            file.Write(buffer, 0, n);
				//        }
				//    }
				//}
				//}
				if (!File.Exists(target))   // we're never updating images if they change, to reduce Exceptions and speed up
					File.Move(tmpfile, target);
				return true;
			}
			catch (Exception e)
			{
				LogDebug(String.Format("Problem with {0} {1}", uri, e.Message));
				return false;
			}
		}
Esempio n. 11
0
        public static async Task <MovieDetails> GetMovieDetails(string movieID, string type)
        {
            string key = "253ceb1e198e26b094348524da5bc8ab";

            string query = string.Format("https://api.themoviedb.org/3/{0}/{1}?api_key={2}", type, movieID, key);

            var result = downloadjson.getJson(query);

            MovieDetails current = null;

            if (type == "movie")
            {
                //create new object
                current = new MovieDetails();
                try { current.title = result["original_title"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); };
                try { current.ID = (int)result["id"]; } catch (Exception ex) { Console.Write(ex.ToString()); }
                try { current.imdbID = result["imdb_id"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); }
                try { current.budget = (string)result["budget"]; } catch (Exception ex) { Console.Write(ex.ToString()); }
                try { current.overview = result["overview"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); }
                try { current.release_date = result["release_date"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); }
                try { current.duration = (int)result["runtime"]; } catch (Exception ex) { Console.Write(ex.ToString()); }
                try { current.revenue = (int)result["revenue"]; } catch (Exception ex) { Console.Write(ex.ToString()); }

                try
                {
                    Java.Net.URL link2 = new Java.Net.URL("http://image.tmdb.org/t/p/w185/" + result["poster_path"].ToString());
                    await Task.Run(() => { current.poster = BitmapFactory.DecodeStream(link2.OpenStream()); });
                }
                catch (Exception ex) { Console.Write(ex.ToString()); }
                //**************** SKATIOMA ZANRUS ***************************

                JArray   items  = (JArray)result["genres"];
                int      length = items.Count;
                string[] ar     = new string[length];
                for (int i = 0; i < length; i++)
                {
                    ar[i] = result["genres"][i]["name"].ToString();
                }
                current.genres = ar;

                try
                {
                    query = string.Format("http://api.themoviedb.org/3/movie/{0}/videos?api_key={1}", movieID, key);
                    var objectas = downloadjson.getJson(query);
                    current.trailer = objectas["results"][0]["key"].ToString();
                }
                catch (Exception ex) { Console.Write(ex.ToString()); }
            }
            else if (type == "tv")
            {
                current = new MovieDetails();
                try { current.title = result["name"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); };
                try { current.ID = (int)result["id"]; } catch (Exception ex) { Console.Write(ex.ToString()); }
                try { current.imdbID = result["imdb_id"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); }
                try { current.overview = result["overview"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); }
                try { current.first_air_date_date = result["first_air_date"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); }
                current.duration = (int)result["episode_run_time"][0];
                try
                {
                    Java.Net.URL link2 = new Java.Net.URL("http://image.tmdb.org/t/p/w185/" + result["poster_path"].ToString());
                    await Task.Run(() => { current.poster = BitmapFactory.DecodeStream(link2.OpenStream()); });
                }
                catch (Exception ex) { Console.Write(ex.ToString()); }
                //**************** SKATIOMA ZANRUS ***************************

                JArray   items  = (JArray)result["genres"];
                int      length = items.Count;
                string[] ar     = new string[length];
                for (int i = 0; i < length; i++)
                {
                    ar[i] = result["genres"][i]["name"].ToString();
                }
                current.genres = ar;

                try
                {
                    query = string.Format("http://api.themoviedb.org/3/tv/{0}/videos?api_key={1}", movieID, key);
                    var objectas = downloadjson.getJson(query);
                    current.trailer = objectas["results"][0]["key"].ToString();
                }
                catch (Exception ex) { Console.Write(ex.ToString()); }

                current.created_by_name    = Lolas(result, "created_by", "name");
                current.seasons            = Lolas(result, "seasons", "id");
                current.networks_id        = Lolas(result, "networks", "name");
                current.status             = result["status"].ToString();
                current.number_of_seasons  = result["number_of_seasons"].ToString();
                current.number_of_episodes = result["number_of_episodes"].ToString();
                current.release_date       = result["first_air_date"].ToString();
            }


            return(current);
        }
Esempio n. 12
0
        public static async Task <CastDetails> GetSeasons(string movieID, string season)
        {
            string key = "253ceb1e198e26b094348524da5bc8ab";

            string query = string.Format("https://api.themoviedb.org/3/tv/{0}/season/{1}?api_key={2}&language=en-US", movieID, season, key);

            var result = downloadjson.getJson(query);

            CastDetails currentPerson = null;


            //create new object
            currentPerson = new CastDetails();
            try
            {
                currentPerson.Name = result["name"].ToString();
                currentPerson.ID   = result["id"].ToString();
            }
            catch (Exception ex) { }


            try
            {
                Java.Net.URL link2 = new Java.Net.URL("http://image.tmdb.org/t/p/w185/" + result["poster_path"].ToString());
                await Task.Run(() => { currentPerson.profile_path = BitmapFactory.DecodeStream(link2.OpenStream()); });
            }
            catch (Exception ex) { }

            return(currentPerson);
        }
Esempio n. 13
0
        public static async Task <MovieDetails> GetBasicInfo(string movieID, string type)
        {
            string key = "253ceb1e198e26b094348524da5bc8ab";

            string query = string.Format("https://api.themoviedb.org/3/{0}/{1}?api_key={2}", type, movieID, key);

            var result = downloadjson.getJson(query);

            MovieDetails current = null;

            if (type == "movie")
            {
                //create new object
                current = new MovieDetails();
                try { current.title = result["original_title"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); };
                try { current.ID = (int)result["id"]; } catch (Exception ex) { Console.Write(ex.ToString()); }
                try
                {
                    Java.Net.URL link2 = new Java.Net.URL("http://image.tmdb.org/t/p/w185/" + result["poster_path"].ToString());
                    await Task.Run(() => { current.poster = BitmapFactory.DecodeStream(link2.OpenStream()); });
                }
                catch (Exception ex) { Console.Write(ex.ToString()); }
            }
            else if (type == "tv")
            {
                //create new object
                current = new MovieDetails();
                try { current.title = result["name"].ToString(); } catch (Exception ex) { Console.Write(ex.ToString()); };
                try { current.ID = (int)result["id"]; } catch (Exception ex) { Console.Write(ex.ToString()); }
                try
                {
                    Java.Net.URL link2 = new Java.Net.URL("http://image.tmdb.org/t/p/w185/" + result["poster_path"].ToString());
                    await Task.Run(() => { current.poster = BitmapFactory.DecodeStream(link2.OpenStream()); });
                }
                catch (Exception ex) { Console.Write(ex.ToString()); }
            }


            return(current);
        }