added other users notes in map

This commit is contained in:
Aran Zaiger 2016-07-08 00:59:07 +03:00
parent f042f9a46b
commit f578213520

View file

@ -29,6 +29,7 @@ import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions; import com.google.android.gms.maps.model.MarkerOptions;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
@ -50,7 +51,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
private GoogleMap mMap; private GoogleMap mMap;
private GPSUtils gpsUtils; private GPSUtils gpsUtils;
private MainActivity mainActivity; private MainActivity mainActivity;
private final int MAX_ZOOM = 16, MIN_ZOOM = 9; private final int MAX_ZOOM = 16, MIN_ZOOM = 9, DEFAULT_ZOOM = 12;
public GmapFragment() { public GmapFragment() {
@ -128,10 +129,20 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
return; return;
} }
mMap.setMyLocationEnabled(true); mMap.setMyLocationEnabled(true);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 12)); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, DEFAULT_ZOOM));
//get my notes
VolleyUtilSingleton.getInstance(getActivity()).get(Utils.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, Utils.genericErrorListener); VolleyUtilSingleton.getInstance(getActivity()).get(Utils.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, Utils.genericErrorListener);
JSONObject jsonObj = new JSONObject();
try {
jsonObj.put("id",mainActivity.getUserId());
} catch (JSONException e) {
e.printStackTrace();
}
//get other notes
VolleyUtilSingleton.getInstance(getActivity()).post(Utils.BASE_URL + "/note/getPublic", jsonObj, getNotesSuccessListener, Utils.genericErrorListener);
} }
@ -163,12 +174,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerOptions, List<MarkerOptions>> { private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerOptions, List<MarkerOptions>> {
GoogleMap mMap; GoogleMap mMap;
// GmapFragment gmap;
public getMarkersFromNotes(GoogleMap map) { public getMarkersFromNotes(GoogleMap map) {
mMap = map; mMap = map;
// gmap = GmapFragment.
// mMap = GmapFragment.getMap();
Log.d(TAG, "in async ctor"); Log.d(TAG, "in async ctor");
} }
@ -190,7 +198,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
protected List<MarkerOptions> doInBackground(List<Note>... listOfNotes) { protected List<MarkerOptions> doInBackground(List<Note>... listOfNotes) {
Log.d(TAG, "in async BG"); Log.d(TAG, "in async BG");
String url = "http://www.aljazeera.com/mritems/images/site/DefaultAvatar.jpg";
List<MarkerOptions> markerOptionList = new ArrayList<>(); List<MarkerOptions> markerOptionList = new ArrayList<>();
// for (int i = 0 ; i< listOfNotes.length; i++) // for (int i = 0 ; i< listOfNotes.length; i++)
for (Note n : listOfNotes[0]) { for (Note n : listOfNotes[0]) {
@ -199,7 +206,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
.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(url), 80, 80, false))); .icon(BitmapDescriptorFactory.fromBitmap(Bitmap.createScaledBitmap(Utils.getBitmapFromURL(n.getAvatar()), 80, 80, false)));
publishProgress(mo); publishProgress(mo);
// ); // );
@ -208,7 +215,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
} }
//Bitmap.createScaledBitmap(myBitmap, 80, 80, false);
} }