From 7347bcb8c4066dda4b9f2bddf250f257af3780a5 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Fri, 8 Jul 2016 02:35:50 +0300 Subject: [PATCH] Added Utils.URLtoImageView --- .../sagi/thesocialnotework/MainActivity.java | 17 +----------- .../thesocialnotework/PersonalFragment.java | 5 ++++ .../ara/sagi/thesocialnotework/Utils.java | 27 +++++++++++++++++++ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java index a1d12e2..e16aa5c 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MainActivity.java @@ -104,7 +104,7 @@ public class MainActivity extends AppCompatActivity gpsUtils.getLocation(); //Change The Avatar - new setUserAvatar().execute(); + Utils.URLtoImageView(menu_avatar, user.getAvatar()); } @Override @@ -201,19 +201,4 @@ public class MainActivity extends AppCompatActivity public String getUserId(){return user.getId();} - private class setUserAvatar extends AsyncTask { - - @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); - } - - } - } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java index 1dacf2c..529fb60 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java @@ -6,7 +6,9 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.pm.PackageManager; +import android.graphics.Bitmap; import android.net.Uri; +import android.os.AsyncTask; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; @@ -23,6 +25,7 @@ import android.widget.Button; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.ListView; import android.widget.Switch; 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 permission = (TextView) noteViewDialog.findViewById(R.id.ndf_permission_textview); 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()); @@ -344,6 +348,7 @@ public class PersonalFragment extends Fragment { likes.setText("Likes: " + note.getLikes()); tags.setText(note.getTags().toString()); permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private")); + Utils.URLtoImageView(avatar, note.getAvatar()); deleteBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java index 4fa4af2..03dfd85 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java @@ -4,7 +4,9 @@ import android.app.ProgressDialog; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.os.AsyncTask; import android.util.Log; +import android.widget.ImageView; import com.android.volley.Response; import com.android.volley.VolleyError; @@ -105,4 +107,29 @@ public class Utils { } return stringArray; } + + public static void URLtoImageView(ImageView iv, String url){ + new setUserAvatar(iv, url).execute(); + } + + private static class setUserAvatar extends AsyncTask { + 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); + } + + } }