protected override async void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.profile); Log.Debug (tag, "INICIANDO PERFIL"); Log.Debug (tag, "Seteando toolbar y scrollview"); mToolbar = FindViewById<SupportToolBar> (Resource.Id.toolbar); mScrollView = FindViewById<ScrollView> (Resource.Id.scrollView); SetSupportActionBar (mToolbar); SupportActionBar.SetHomeAsUpIndicator (Resource.Drawable.ic_arrow_back); SupportActionBar.SetDisplayHomeAsUpEnabled (true); SupportActionBar.SetHomeButtonEnabled (true); Point size = new Point (); Display display = WindowManager.DefaultDisplay; display.GetSize (size); mScreenHeight = size.Y; mScrollView.ViewTreeObserver.AddOnScrollChangedListener (this); nombreu = FindViewById<TextView> (Resource.Id.nombre); correou = FindViewById<TextView> (Resource.Id.correo); puntos = FindViewById<TextView> (Resource.Id.puntos); completado = FindViewById<TextView> (Resource.Id.completado); countup = FindViewById<TextView> (Resource.Id.countup); completadobarra = FindViewById<ProgressBar> (Resource.Id.completadobarra); entradasblog = new List<BlogEntry> (); updatefoto = FindViewById<Button> (Resource.Id.updatefoto); Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder (this); //progressBar.getProgressDrawable().setColorFilter(Color.RED, Mode.SRC_IN); completadobarra.ProgressDrawable.SetColorFilter(Color.ParseColor("#68FF68"), Android.Graphics.PorterDuff.Mode.SrcIn); source = 1; apath = ""; imgUri = null; esperafoto = FindViewById<ProgressBar> (Resource.Id.esperafoto); //foto = FindViewById<PlifToolbarMenu.CircleImageView> (Resource.Id.fotoperfil); foto = FindViewById<ImageView> (Resource.Id.fotoperfil); Typeface font = Typeface.CreateFromAsset(Assets, "Fonts/fa.ttf"); //Preferencias de la App var prefs = this.GetSharedPreferences("RunningAssistant.preferences", FileCreationMode.Private); idusuario = prefs.GetString ("id", null); correo = prefs.GetString ("email",null); var editor = prefs.Edit (); var nombre = prefs.GetString("nombre", null); SupportActionBar.Title = nombre; Log.Debug (tag, "Inicia foto de perfil"); fotoperfil = FindViewById<ImageView> (Resource.Id.fotoperfil); try{ JsonValue rutapre = await plifserver.FetchWeatherAsync ("http://plif.mx/mobile/get_img_usr?id="+idusuario); Log.Debug ("json","SI existe la ruta"); string extra="http://plif.mx/"; string path = rutapre [0] ["imagen_usuarios"] ["ruta"]; string first=path[0].ToString(); if(first=="u" || first=="U"){ //Toast.MakeText (Application.Context, "EMPIEZA CON U!!!", ToastLength.Long).Show (); path=extra+path; }else{ //no hagas nada, la imagen es de google o de algun otro lado. } Log.Debug (tag, "La ruta es: "+path); rutafoto=path; Koush.UrlImageViewHelper.SetUrlDrawable(fotoperfil, path, Resource.Drawable.profile); hayimagen="si"; }catch(Exception ex){ Log.Debug ("json","no existe la ruta"); fotoperfil.SetImageResource (Resource.Drawable.profile); hayimagen="no"; } string url = "http://plif.mx/perfil/" + idusuario + ".json?droid"; Log.Debug (tag, "la URL es: " + url); string completadonum = ""; try{ datos = await plifserver.FetchWeatherAsync(url); nombreu.Text = nombre; correou.Text = correo; puntos.Text = datos ["0"] ["Users"] ["puntos"]+" puntos"; //Log.Debug(tag, "El completado: "+datos ["completadoperfil"]); int comptemp=Int32.Parse(datos ["completadoperfil"]); if(comptemp==20){ //no hagas nada }else{ comptemp=comptemp+20; } completadonum = comptemp.ToString(); completado.Text="Tu perfil está completo al "+completadonum+"% ¡Complétalo desde nuestra web para ganar más puntos!"; //aqui ponemos lo que hay completado del perfil; }catch(Exception ex){ Log.Debug (tag, "F**K!! "+ex.ToString() ); } System.Threading.Tasks.Task.Factory.StartNew(() => { TextView cp = FindViewById<TextView> (Resource.Id.countup); int j = 0; Log.Debug(tag,"thread started"); //while (j<100){ for(j=0; j<=Int32.Parse(completadonum); j++){ Log.Debug(tag,"Ciclo For"); ThreadPool.QueueUserWorkItem (o => setprogreso (countup, j)); Log.Debug(tag,"Se llama al ThreadPool"); Thread.Sleep (25); Log.Debug(tag,"Retardo de 100ms"); j++; Log.Debug(tag,"El nuevo valor de J: "+j); } //cp.Text = j.ToString()+"%"; }); //Creamos el inflater para las vistas de los negocios LayoutInflater inflater = LayoutInflater.From(this); //creamos la ll donde se van a meter las entradas LinearLayout blogcontainer = FindViewById<LinearLayout> (Resource.Id.blogcontainer); try{ //Aquí vamos a llenar el blog JsonValue datosblog = datos["entradas"]; foreach(JsonObject data in datosblog){ Log.Debug(tag, "Entrada al blog: "+data["b"]["titulo"]); //JsonValue b = data["b"]; //JsonValue cero = data ["0"]; entradasblog.Add(new BlogEntry(){ Id=data["b"]["id"], Titulo=data["b"]["titulo"], User=data["b"]["user"], FechaPublicacion=data["b"]["fecha_publicacion"], Likes = data["b"]["likes"], ImagenCabezado=data["b"]["imgencabezado"], Promedio="lel" }); } Log.Debug(tag, "Justo antes del foreach del blog"); for(int j=0; j<entradasblog.Count; j++){ Log.Debug(tag, "Entramos al foreach del blog e inflamos"); View row = inflater.Inflate(Resource.Layout.blog_row, blogcontainer, false); //ESTE SETEA EL NOMBRE Log.Debug(tag, "creamos textview"); TextView tituloblog = row.FindViewById<TextView> (Resource.Id.entryname); Log.Debug(tag, "seteamos textview"); tituloblog.Text = entradasblog [j].Titulo; //inicia estrellas //ESTE SETEA LAS ESTRELLAS DE LA CALIFICACION ImageView cali = row.FindViewById<ImageView> (Resource.Id.calificacion); string cal = entradasblog[j].Promedio; switch (cal) { case "0": cali.SetImageResource (Resource.Drawable.e0); break; case "": cali.SetImageResource (Resource.Drawable.e0); break; case "null": cali.SetImageResource (Resource.Drawable.e0); break; case null: cali.SetImageResource (Resource.Drawable.e0); break; case "1": cali.SetImageResource (Resource.Drawable.e1); break; case "2": cali.SetImageResource (Resource.Drawable.e2); break; case "3": cali.SetImageResource (Resource.Drawable.e3); break; case "4": cali.SetImageResource (Resource.Drawable.e4); break; case "5": cali.SetImageResource (Resource.Drawable.e5); break; default: cali.SetImageResource (Resource.Drawable.e0); break; } //termina estrellas //inicia imagen //ESTE SETEA LA IMAGEN ImageView imagen = row.FindViewById<ImageView> (Resource.Id.NegocioFoto); if (entradasblog[j].ImagenCabezado == null || entradasblog[j].ImagenCabezado == "" || entradasblog[j].ImagenCabezado == "null") { //pon la imagen por defecto imagen.SetImageResource (Resource.Drawable.marca); } else { //TENEMOS QUE VERIFICAR SI LA IMAGEN ES DE GOOGLE O DE NOSOTROS!!! string extra="http://plif.mx/admin/"; string ruta=entradasblog[j].ImagenCabezado; string first=ruta[0].ToString(); if(first=="u" || first=="U"){ //Toast.MakeText (Application.Context, "EMPIEZA CON U!!!", ToastLength.Long).Show (); ruta=extra+ruta; }else{ //no hagas nada, la imagen es de google } Koush.UrlImageViewHelper.SetUrlDrawable (imagen, ruta, Resource.Drawable.bolaplace); //acaba imagen } //SETEA EL NUMERO DE CORAZONES TextView corazones = row.FindViewById<TextView> (Resource.Id.corazones); corazones.Text=entradasblog[j].Likes; Log.Debug(tag, "retornamos vista"); blogcontainer.AddView(row); }//For }catch(Exception ex){ Log.Debug (tag, "Algo en el blog falló D: "+ex.ToString()); } updatefoto.SetTypeface(font, TypefaceStyle.Normal); updatefoto.Click += async (object sender, EventArgs e) => { //actualizamos la foto alert.SetTitle("Actualizar foto"); alert.SetPositiveButton ("Desde cámara", (senderAlert, args) => { //abrimos el intent de la cámara updatefoto.Visibility=ViewStates.Gone; esperafoto.Visibility=ViewStates.Visible; source=2; Dictionary<string,string> diccionario = new Dictionary<string,string>(); List <byte[]> fossbytes = new List<byte[]>(); GetImage((async (b, p) => { Log.Debug(tag,"Inicia GETIMAGE"); AlphaAnimation alpha = new AlphaAnimation(1.0F, 0.4F); // change values as you want alpha.Duration=500; // Make animation instant alpha.FillAfter=true; // Tell it to persist after the animation ends // And then on your imageview fotoperfil.StartAnimation(alpha); Java.IO.File f = new Java.IO.File(p[0]); stream = this.ContentResolver.OpenInputStream(Android.Net.Uri.FromFile(f)); Bitmap temp =BitmapFactory.DecodeStream(stream); if(temp!=null){ Log.Debug("FOSSBYTES","Inicia conversión a bytes!"); byte[] tmp2 = pliffunctions.PathToByte2(p[0]); Log.Debug("FOSSBYTES","Termina conversión a bytes!"); fossbytes.Add(tmp2); diccionario.Add("imagen_usuario_id",hayimagen); diccionario.Add("usuario_id",idusuario); try{ //AQUI vamos a actualizar la foto del perfil con el codigo del multipart string resp = await plifserver.PostMultiPartForm ("http://plif.mx/pages/UpdateImgPerfil", fossbytes, "nada", "file[]", "image/jpeg", diccionario, true); Log.Debug(tag,"Respuesta del servidor: "+resp); //PONEMOS LA IMAGEN, MOSTRAMOS EL BOTON Y OCULTAMOS EL PROGRESSBAR JsonValue rutapre = await plifserver.FetchWeatherAsync ("http://plif.mx/mobile/get_img_usr?id="+idusuario); Log.Debug ("json","SI existe la ruta"); string path = "http://plif.mx/"+rutapre [0] ["imagen_usuarios"] ["ruta"]; Log.Debug (tag, "La ruta es: "+path); rutafoto=path; Koush.UrlImageViewHelper.SetUrlDrawable(fotoperfil, path, Resource.Drawable.profile); hayimagen="si"; AlphaAnimation alpha2 = new AlphaAnimation(0.4F, 1.0F); // change values as you want alpha2.Duration=500; // Make animation instant alpha2.FillAfter=true; // Tell it to persist after the animation ends // And then on your imageview updatefoto.Visibility=ViewStates.Visible; esperafoto.Visibility=ViewStates.Gone; fotoperfil.StartAnimation(alpha2); }catch(Exception ex){ updatefoto.Visibility=ViewStates.Visible; esperafoto.Visibility=ViewStates.Gone; AlphaAnimation alpha2 = new AlphaAnimation(0.4F, 1.0F); // change values as you want alpha2.Duration=500; // Make animation instant alpha2.FillAfter=true; // Tell it to persist after the animation ends // And then on your imageview fotoperfil.StartAnimation(alpha2); Toast.MakeText (Application.Context, "Ocurrió un error al actualizar la foto de perfil. Inténtalo de nuevo", ToastLength.Long).Show (); } } })); } ); fotoperfil.Click += (object sender2, EventArgs e2) => { //abrimos el intent de pantalla completa Log.Debug(tag,"clickeo la imagen!"); var pantallacompleta = new Intent (this, typeof(PantallaCompleta)); pantallacompleta.PutExtra("ruta",rutafoto); StartActivity (pantallacompleta); }; alert.SetNeutralButton ("Desde galería", (senderAlert, args) => { //abrimos el intent de la galería updatefoto.Visibility=ViewStates.Gone; esperafoto.Visibility=ViewStates.Visible; source=1; Dictionary<string,string> diccionario = new Dictionary<string,string>(); List <byte[]> fossbytes = new List<byte[]>(); GetImage((async (b, p) => { Log.Debug(tag,"Inicia GETIMAGE"); AlphaAnimation alpha = new AlphaAnimation(1.0F, 0.4F); // change values as you want alpha.Duration=500; // Make animation instant alpha.FillAfter=true; // Tell it to persist after the animation ends // And then on your imageview fotoperfil.StartAnimation(alpha); Java.IO.File f = new Java.IO.File(p[0]); stream = this.ContentResolver.OpenInputStream(Android.Net.Uri.FromFile(f)); Bitmap temp =BitmapFactory.DecodeStream(stream); if(temp!=null){ Log.Debug("FOSSBYTES","Inicia conversión a bytes!"); byte[] tmp2 = pliffunctions.PathToByte2(p[0]); Log.Debug("FOSSBYTES","Termina conversión a bytes!"); fossbytes.Add(tmp2); diccionario.Add("imagen_usuario_id",hayimagen); diccionario.Add("usuario_id",idusuario); try{ //AQUI vamos a actualizar la foto del perfil con el codigo del multipart string resp = await plifserver.PostMultiPartForm ("http://plif.mx/pages/UpdateImgPerfil", fossbytes, "nada", "file[]", "image/jpeg", diccionario, true); Log.Debug(tag,"Respuesta del servidor: "+resp); //PONEMOS LA IMAGEN, MOSTRAMOS EL BOTON Y OCULTAMOS EL PROGRESSBAR JsonValue rutapre = await plifserver.FetchWeatherAsync ("http://plif.mx/mobile/get_img_usr?id="+idusuario); Log.Debug ("json","SI existe la ruta"); string path = "http://plif.mx/"+rutapre [0] ["imagen_usuarios"] ["ruta"]; Log.Debug (tag, "La ruta es: "+path); rutafoto=path; Koush.UrlImageViewHelper.SetUrlDrawable(fotoperfil, path, Resource.Drawable.profile); hayimagen="si"; AlphaAnimation alpha2 = new AlphaAnimation(0.4F, 1.0F); // change values as you want alpha2.Duration=500; // Make animation instant alpha2.FillAfter=true; // Tell it to persist after the animation ends // And then on your imageview updatefoto.Visibility=ViewStates.Visible; esperafoto.Visibility=ViewStates.Gone; fotoperfil.StartAnimation(alpha2); }catch(Exception ex){ updatefoto.Visibility=ViewStates.Visible; esperafoto.Visibility=ViewStates.Gone; AlphaAnimation alpha2 = new AlphaAnimation(0.4F, 1.0F); // change values as you want alpha2.Duration=500; // Make animation instant alpha2.FillAfter=true; // Tell it to persist after the animation ends // And then on your imageview fotoperfil.StartAnimation(alpha2); Toast.MakeText (Application.Context, "Ocurrió un error al actualizar la foto de perfil. Inténtalo de nuevo", ToastLength.Long).Show (); } } })); } ); alert.Show(); }; }