diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java index 149e5f3..1774054 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java @@ -31,6 +31,7 @@ import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; +import com.google.android.gms.maps.model.BitmapDescriptor; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; @@ -314,19 +315,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { } } }; - - - private View.OnClickListener cameraBtnListener = new View.OnClickListener() - { - - public void onClick(View v) - { - - Log.d(TAG, "in camera Button"); - - } - - }; + private class getMarkersFromNotes extends AsyncTask, MarkerNoteStruct, Void> { @@ -349,18 +338,21 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { @Override protected Void doInBackground(List... listOfNotes) { Log.d(TAG, "in async BG"); + + BitmapDescriptor b; + for (Note n : listOfNotes[0]) { + b = BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(Utils.getBitmapFromURL(n.getAvatar()), 80, 80, false)); MarkerOptions mo = new MarkerOptions() .title(n.getTitle()) .position(new LatLng(n.getLat(), n.getLon())) .snippet(n.getBody()) - .icon(BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(Utils.getBitmapFromURL(n.getAvatar()), 80, 80, false))); + .icon(b); publishProgress(new MarkerNoteStruct(n,mo)); } return null; -// return markerOptionList; } 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 32dd0e0..00eedfe 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 @@ -10,6 +10,8 @@ import android.widget.ImageView; import com.android.volley.Response; import com.android.volley.VolleyError; +import com.google.android.gms.maps.model.BitmapDescriptor; +import com.google.android.gms.maps.model.BitmapDescriptorFactory; import org.json.JSONArray; import org.json.JSONException; @@ -21,6 +23,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; /** * Created by JERLocal on 7/7/2016. @@ -30,22 +33,31 @@ public class Utils { public static final String TAG = "Utils"; public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api"; public static ProgressDialog progress; + private static HashMap bitmapHash = new HashMap<>(); - public static Bitmap getBitmapFromURL(String imageUrl) { - try { - URL url = new URL(imageUrl); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoInput(true); - connection.connect(); - InputStream input = connection.getInputStream(); - Bitmap myBitmap = BitmapFactory.decodeStream(input); - return myBitmap; - } catch (IOException e) { - e.printStackTrace(); - return null; + public static Bitmap getBitmapFromURL(String url) { + if (Utils.bitmapHash.containsKey(url)){ + Log.d(TAG, "getBitmapFromURL: Found is hash"); + return bitmapHash.get(url); + } else { + Log.d(TAG, "getBitmapFromURL: New value to HashMap"); + try { + URL new_url = new URL(url); + HttpURLConnection connection = (HttpURLConnection) new_url.openConnection(); + connection.setDoInput(true); + connection.connect(); + InputStream input = connection.getInputStream(); + Bitmap myBitmap = BitmapFactory.decodeStream(input); + bitmapHash.put(url, myBitmap); + return myBitmap; + } catch (IOException e) { + e.printStackTrace(); + return null; + } } + } @@ -130,8 +142,10 @@ public class Utils { @Override protected Bitmap doInBackground(Void... v) { - Bitmap b = Utils.getBitmapFromURL(url); - return b; +// Bitmap b; + + return Utils.getBitmapFromURL(url); + } @Override