fix bitmapHashMap
This commit is contained in:
parent
f72c82c3e9
commit
e72bbb3fcf
2 changed files with 35 additions and 29 deletions
|
@ -31,6 +31,7 @@ import com.google.android.gms.maps.GoogleMap;
|
||||||
import com.google.android.gms.maps.MapFragment;
|
import com.google.android.gms.maps.MapFragment;
|
||||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||||
import com.google.android.gms.maps.SupportMapFragment;
|
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.BitmapDescriptorFactory;
|
||||||
import com.google.android.gms.maps.model.CameraPosition;
|
import com.google.android.gms.maps.model.CameraPosition;
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
|
@ -316,18 +317,6 @@ 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<List<Note>, MarkerNoteStruct, Void> {
|
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerNoteStruct, Void> {
|
||||||
GoogleMap mMap;
|
GoogleMap mMap;
|
||||||
|
@ -349,18 +338,21 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(List<Note>... listOfNotes) {
|
protected Void doInBackground(List<Note>... listOfNotes) {
|
||||||
Log.d(TAG, "in async BG");
|
Log.d(TAG, "in async BG");
|
||||||
|
|
||||||
|
BitmapDescriptor b;
|
||||||
|
|
||||||
for (Note n : listOfNotes[0]) {
|
for (Note n : listOfNotes[0]) {
|
||||||
|
b = BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(Utils.getBitmapFromURL(n.getAvatar()), 80, 80, false));
|
||||||
MarkerOptions mo = new MarkerOptions()
|
MarkerOptions mo = new MarkerOptions()
|
||||||
.title(n.getTitle())
|
.title(n.getTitle())
|
||||||
.position(new LatLng(n.getLat(), n.getLon()))
|
.position(new LatLng(n.getLat(), n.getLon()))
|
||||||
.snippet(n.getBody())
|
.snippet(n.getBody())
|
||||||
.icon(BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(Utils.getBitmapFromURL(n.getAvatar()), 80, 80, false)));
|
.icon(b);
|
||||||
|
|
||||||
publishProgress(new MarkerNoteStruct(n,mo));
|
publishProgress(new MarkerNoteStruct(n,mo));
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
// return markerOptionList;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ import android.widget.ImageView;
|
||||||
|
|
||||||
import com.android.volley.Response;
|
import com.android.volley.Response;
|
||||||
import com.android.volley.VolleyError;
|
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.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -21,6 +23,7 @@ import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JERLocal on 7/7/2016.
|
* Created by JERLocal on 7/7/2016.
|
||||||
|
@ -30,17 +33,24 @@ public class Utils {
|
||||||
public static final String TAG = "Utils";
|
public static final String TAG = "Utils";
|
||||||
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
public static final String BASE_URL = "http://thesocialnotework-api.appspot.com/api";
|
||||||
public static ProgressDialog progress;
|
public static ProgressDialog progress;
|
||||||
|
private static HashMap<String, Bitmap> bitmapHash = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
public static Bitmap getBitmapFromURL(String imageUrl) {
|
|
||||||
|
|
||||||
|
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 {
|
try {
|
||||||
URL url = new URL(imageUrl);
|
URL new_url = new URL(url);
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) new_url.openConnection();
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.connect();
|
connection.connect();
|
||||||
InputStream input = connection.getInputStream();
|
InputStream input = connection.getInputStream();
|
||||||
Bitmap myBitmap = BitmapFactory.decodeStream(input);
|
Bitmap myBitmap = BitmapFactory.decodeStream(input);
|
||||||
|
bitmapHash.put(url, myBitmap);
|
||||||
return myBitmap;
|
return myBitmap;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -48,6 +58,8 @@ public class Utils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// //Generic response ErrorListener
|
// //Generic response ErrorListener
|
||||||
public static Response.ErrorListener genericErrorListener = new Response.ErrorListener() {
|
public static Response.ErrorListener genericErrorListener = new Response.ErrorListener() {
|
||||||
|
@ -130,8 +142,10 @@ public class Utils {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Bitmap doInBackground(Void... v) {
|
protected Bitmap doInBackground(Void... v) {
|
||||||
Bitmap b = Utils.getBitmapFromURL(url);
|
// Bitmap b;
|
||||||
return b;
|
|
||||||
|
return Utils.getBitmapFromURL(url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue