added MarkerNoteStruct and dialog box for note in map
This commit is contained in:
parent
f578213520
commit
4a03c1c024
2 changed files with 163 additions and 23 deletions
|
@ -1,6 +1,9 @@
|
|||
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
@ -15,6 +18,10 @@ import android.util.Log;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Response;
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
|
@ -38,6 +45,7 @@ import java.net.HttpURLConnection;
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
|
||||
|
@ -52,9 +60,11 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
|||
private GPSUtils gpsUtils;
|
||||
private MainActivity mainActivity;
|
||||
private final int MAX_ZOOM = 16, MIN_ZOOM = 9, DEFAULT_ZOOM = 12;
|
||||
private HashMap<Marker, Note> eventMarkerMap;
|
||||
|
||||
|
||||
public GmapFragment() {
|
||||
eventMarkerMap = new HashMap<Marker, Note>();
|
||||
}
|
||||
|
||||
|
||||
|
@ -122,6 +132,8 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
|||
|
||||
}
|
||||
});
|
||||
mMap.setInfoWindowAdapter(infoWindowAdapter);
|
||||
|
||||
|
||||
LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude());
|
||||
// mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!"));
|
||||
|
@ -136,7 +148,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
|||
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
try {
|
||||
jsonObj.put("id",mainActivity.getUserId());
|
||||
jsonObj.put("id", mainActivity.getUserId());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -146,6 +158,104 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
|||
|
||||
}
|
||||
|
||||
|
||||
GoogleMap.InfoWindowAdapter infoWindowAdapter = new GoogleMap.InfoWindowAdapter() { // Use default InfoWindow frame
|
||||
@Override
|
||||
public View getInfoWindow(Marker args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Defines the contents of the InfoWindow
|
||||
@Override
|
||||
public View getInfoContents(Marker args) {
|
||||
|
||||
// LatLng clickMarkerLatLng = args.getPosition();
|
||||
|
||||
// Getting view from the layout file info_window_layout
|
||||
|
||||
// Getting the position from the marker
|
||||
|
||||
|
||||
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
|
||||
public void onInfoWindowClick(Marker marker) {
|
||||
|
||||
Note note = eventMarkerMap.get(marker);
|
||||
final Dialog noteViewDialog = new Dialog(getActivity());
|
||||
noteViewDialog.setContentView(R.layout.note_display_full);
|
||||
noteViewDialog.setTitle("Someone wrote...");
|
||||
noteViewDialog.show();
|
||||
|
||||
|
||||
//get note_view_full layout elements
|
||||
final TextView title = (TextView) noteViewDialog.findViewById(R.id.ndf_title_textview);
|
||||
final TextView body = (TextView) noteViewDialog.findViewById(R.id.ndf_body_textview);
|
||||
final TextView time = (TextView) noteViewDialog.findViewById(R.id.ndf_time_textview);
|
||||
final TextView location = (TextView) noteViewDialog.findViewById(R.id.ndf_address_textview);
|
||||
final TextView likes = (TextView) noteViewDialog.findViewById(R.id.ndf_likes_textview);
|
||||
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);
|
||||
|
||||
|
||||
title.setText(note.getTitle());
|
||||
body.setText(note.getBody());
|
||||
time.setText(note.getTimestamp());
|
||||
location.setText("Tags: " + note.getAddress());
|
||||
likes.setText("Likes: " + note.getLikes());
|
||||
tags.setText(note.getTags().toString());
|
||||
permission.setText("Permission: " + (note.isPublic() ? "Public" : "Private"));
|
||||
|
||||
|
||||
// deleteBtn.setOnClickListener(new View.OnClickListener() {
|
||||
// public void onClick(View v) {
|
||||
// //Put up the Yes/No message box
|
||||
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
// builder
|
||||
// .setTitle("Delete Note")
|
||||
// .setMessage("Are you sure you want to delete the note?")
|
||||
// .setIcon(android.R.drawable.ic_dialog_alert)
|
||||
// .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// //Yes button clicked, do something
|
||||
// Toast.makeText(getActivity(), "Item Deleted!",
|
||||
// Toast.LENGTH_SHORT).show();
|
||||
// //TODO send delete
|
||||
// JSONObject delNote = new JSONObject();
|
||||
// try {
|
||||
// delNote.put("uid", userId);
|
||||
// delNote.put("nid", note.getId());
|
||||
// VolleyUtilSingleton.getInstance(getActivity()).post(BASE_URL + "/note/delete", delNote, deleteNoteSuccessListener, Utils.genericErrorListener);
|
||||
// listOfNotes.remove(position);
|
||||
//
|
||||
// } catch (JSONException e) {
|
||||
// Toast.makeText(getActivity(), "Something went wrong.\n Failed to delete note...", Toast.LENGTH_LONG).show();
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// noteList.setAdapter(noteListAdapter);
|
||||
// noteViewDialog.dismiss();
|
||||
// }
|
||||
// })
|
||||
// .setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// //Yes button clicked, do something
|
||||
// Toast.makeText(getActivity(), "Canceled",
|
||||
// Toast.LENGTH_SHORT).show();
|
||||
// noteViewDialog.dismiss();
|
||||
// }
|
||||
// }) //Do nothing on no
|
||||
// .show();
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//response listener for getting all user notes
|
||||
Response.Listener<JSONObject> getNotesSuccessListener = new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
|
@ -162,8 +272,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
|||
time.setTime(noteObject.getLong("created_at"));
|
||||
listOfNotes.add(Utils.getNoteFromJsonObj(noteObject, time));
|
||||
}
|
||||
new getMarkersFromNotes(mMap).execute(listOfNotes);
|
||||
// noteList.setAdapter(noteListAdapter);
|
||||
new getMarkersFromNotes(mMap, eventMarkerMap).execute(listOfNotes);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
@ -172,51 +281,57 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
|||
};
|
||||
|
||||
|
||||
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerOptions, List<MarkerOptions>> {
|
||||
private class getMarkersFromNotes extends AsyncTask<List<Note>, MarkerNoteStruct, Void> {
|
||||
GoogleMap mMap;
|
||||
HashMap<Marker, Note> eventMarkerMap;
|
||||
|
||||
public getMarkersFromNotes(GoogleMap map) {
|
||||
mMap = map;
|
||||
public getMarkersFromNotes(GoogleMap map, HashMap<Marker, Note> eventMarkerMap) {
|
||||
Log.d(TAG, "in async ctor");
|
||||
this.eventMarkerMap = eventMarkerMap;
|
||||
mMap = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(MarkerOptions... mo) {
|
||||
mMap.addMarker(mo[0]);
|
||||
}
|
||||
protected void onProgressUpdate(MarkerNoteStruct... mo) {
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<MarkerOptions> markerOptionList) {
|
||||
for (MarkerOptions mo : markerOptionList) {
|
||||
mMap.addMarker(mo);
|
||||
}
|
||||
Log.d(TAG, "in async post");
|
||||
eventMarkerMap.put(mMap.addMarker(mo[0].getMarker()),mo[0].getNote());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<MarkerOptions> doInBackground(List<Note>... listOfNotes) {
|
||||
protected Void doInBackground(List<Note>... listOfNotes) {
|
||||
Log.d(TAG, "in async BG");
|
||||
|
||||
List<MarkerOptions> markerOptionList = new ArrayList<>();
|
||||
// for (int i = 0 ; i< listOfNotes.length; i++)
|
||||
for (Note n : listOfNotes[0]) {
|
||||
// markerOptionList.add(
|
||||
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)));
|
||||
publishProgress(mo);
|
||||
// );
|
||||
|
||||
publishProgress(new MarkerNoteStruct(n,mo));
|
||||
|
||||
}
|
||||
return markerOptionList;
|
||||
return null;
|
||||
// return markerOptionList;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public Marker placeMarker(Note eventInfo) {
|
||||
//
|
||||
// Marker m = getMap().addMarker(new MarkerOptions()
|
||||
//
|
||||
// .position(eventInfo.getLatLong())
|
||||
//
|
||||
// .title(eventInfo.getName()));
|
||||
//
|
||||
//
|
||||
//
|
||||
// return m;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
|
||||
/**
|
||||
* Created by JERLocal on 7/8/2016.
|
||||
*/
|
||||
public class MarkerNoteStruct {
|
||||
private Note note;
|
||||
private MarkerOptions markerOptions;
|
||||
|
||||
public MarkerNoteStruct(Note note, MarkerOptions markerOptions){
|
||||
this.note = note;
|
||||
this.markerOptions = markerOptions;
|
||||
}
|
||||
|
||||
public Note getNote() {
|
||||
return note;
|
||||
}
|
||||
|
||||
public MarkerOptions getMarker() {
|
||||
return markerOptions;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue