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 adb4d99..60ea4f7 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 @@ -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 eventMarkerMap; public GmapFragment() { + eventMarkerMap = new HashMap(); } @@ -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 getNotesSuccessListener = new Response.Listener() { @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, MarkerOptions, List> { + private class getMarkersFromNotes extends AsyncTask, MarkerNoteStruct, Void> { GoogleMap mMap; + HashMap eventMarkerMap; - public getMarkersFromNotes(GoogleMap map) { - mMap = map; + public getMarkersFromNotes(GoogleMap map, HashMap 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 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 doInBackground(List... listOfNotes) { + protected Void doInBackground(List... listOfNotes) { Log.d(TAG, "in async BG"); - - List 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; +// +// } + } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MarkerNoteStruct.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MarkerNoteStruct.java new file mode 100644 index 0000000..bb173fd --- /dev/null +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MarkerNoteStruct.java @@ -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; + } +}