Added Utils.URLtoImageView

This commit is contained in:
Sagi Dayan 2016-07-08 02:35:50 +03:00
parent e9da6be78d
commit 7347bcb8c4
3 changed files with 33 additions and 16 deletions

View file

@ -104,7 +104,7 @@ public class MainActivity extends AppCompatActivity
gpsUtils.getLocation(); gpsUtils.getLocation();
//Change The Avatar //Change The Avatar
new setUserAvatar().execute(); Utils.URLtoImageView(menu_avatar, user.getAvatar());
} }
@Override @Override
@ -201,19 +201,4 @@ public class MainActivity extends AppCompatActivity
public String getUserId(){return user.getId();} public String getUserId(){return user.getId();}
private class setUserAvatar extends AsyncTask<Void, Void, Bitmap> {
@Override
protected Bitmap doInBackground(Void... v) {
Bitmap b = Utils.getBitmapFromURL(self.user.getAvatar());
return b;
}
@Override
protected void onPostExecute(Bitmap b){
self.menu_avatar.setImageBitmap(b);
}
}
} }

View file

@ -6,7 +6,9 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
@ -23,6 +25,7 @@ import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
@ -335,6 +338,7 @@ public class PersonalFragment extends Fragment {
final TextView tags = (TextView) noteViewDialog.findViewById(R.id.ndf_tags_textview); final TextView tags = (TextView) noteViewDialog.findViewById(R.id.ndf_tags_textview);
final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview); final TextView permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview);
final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton); final ImageButton deleteBtn = (ImageButton) noteViewDialog.findViewById(R.id.ndf_delete_imagebutton);
final ImageView avatar = (ImageView)noteViewDialog.findViewById(R.id.note_user_avatar);
title.setText(note.getTitle()); title.setText(note.getTitle());
@ -344,6 +348,7 @@ public class PersonalFragment extends Fragment {
likes.setText("Likes: " + note.getLikes()); likes.setText("Likes: " + note.getLikes());
tags.setText(note.getTags().toString()); tags.setText(note.getTags().toString());
permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private")); permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private"));
Utils.URLtoImageView(avatar, note.getAvatar());
deleteBtn.setOnClickListener(new View.OnClickListener() { deleteBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {

View file

@ -4,7 +4,9 @@ import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log; import android.util.Log;
import android.widget.ImageView;
import com.android.volley.Response; import com.android.volley.Response;
import com.android.volley.VolleyError; import com.android.volley.VolleyError;
@ -105,4 +107,29 @@ public class Utils {
} }
return stringArray; return stringArray;
} }
public static void URLtoImageView(ImageView iv, String url){
new setUserAvatar(iv, url).execute();
}
private static class setUserAvatar extends AsyncTask<Void, Void, Bitmap> {
private ImageView iv;
private String url;
public setUserAvatar(ImageView imageView, String url){
this.iv = imageView;
this.url = url;
}
@Override
protected Bitmap doInBackground(Void... v) {
Bitmap b = Utils.getBitmapFromURL(url);
return b;
}
@Override
protected void onPostExecute(Bitmap b){
iv.setImageBitmap(b);
}
}
} }