From ab578c792afbc6283368ef47c8825c90eaef3a8c Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Fri, 8 Jul 2016 00:18:40 +0300 Subject: [PATCH 1/4] Merge branch 'master' of https://github.com/sagidayan/TheSocialNotework-Android # Conflicts: # app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/LoginActivity.java # app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java --- .../matan/ara/sagi/thesocialnotework/GmapFragment.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 00face0..a246495 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 @@ -121,9 +121,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { } }); - - VolleyUtilSingleton.getInstance(getActivity()).get(Utils.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, Utils.genericErrorListener); -// VolleyUtilSingleton.getInstance(getActivity()).get(mainActivity.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, mainActivity.genericErrorListener); + LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude()); // mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!")); if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { @@ -132,6 +130,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { mMap.setMyLocationEnabled(true); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 12)); + VolleyUtilSingleton.getInstance(getActivity()).get(Utils.BASE_URL + "/note/all?uid=" + mainActivity.getUserId(), getNotesSuccessListener, Utils.genericErrorListener); + + } //response listener for getting all user notes From f042f9a46ba102d3aa6079425605f3373f574036 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Fri, 8 Jul 2016 00:58:22 +0300 Subject: [PATCH 2/4] added "avatar" property to Note --- .../matan/ara/sagi/thesocialnotework/Note.java | 14 ++++++++++++-- .../sagi/thesocialnotework/PersonalFragment.java | 1 + .../matan/ara/sagi/thesocialnotework/Utils.java | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Note.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Note.java index 34329fd..d18064b 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Note.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Note.java @@ -16,13 +16,13 @@ public class Note implements Parcelable{ protected int likes; protected ArrayList tags; protected float lat, lon; - protected String id, address, title, body, timestamp; + protected String id, address, title, body, timestamp, avatar; protected boolean isPublic; - public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic, int likes, ArrayList tags) { + public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic, int likes,String avatar, ArrayList tags) { this.id = id; this.lat = lat; this.lon = lon; @@ -34,18 +34,23 @@ public class Note implements Parcelable{ this.isPublic = isPublic; this.likes = likes; this.tags = tags; + this.avatar = avatar; } + + protected Note(Parcel in) { likes = in.readInt(); tags = in.createStringArrayList(); lat = in.readFloat(); lon = in.readFloat(); + id = in.readString(); address = in.readString(); title = in.readString(); body = in.readString(); timestamp = in.readString(); + avatar = in.readString(); isPublic = in.readByte() != 0; } @@ -72,6 +77,7 @@ public class Note implements Parcelable{ ", body='" + body + '\'' + ", timestamp=" + timestamp + ", isPublic=" + isPublic + + ", avatar=" + avatar+ '}'; } @@ -157,6 +163,9 @@ public class Note implements Parcelable{ public void setTags(ArrayList tags) { this.tags = tags; } + public String getAvatar() {return avatar;} + + public void setAvatar(String avatar) {this.avatar = avatar; } @Override public int describeContents() { @@ -174,6 +183,7 @@ public class Note implements Parcelable{ dest.writeString(title); dest.writeString(body); dest.writeString(timestamp); + dest.writeString(avatar); dest.writeByte((byte) (isPublic ? 1 : 0)); } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java index 49ef80d..1dacf2c 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/PersonalFragment.java @@ -301,6 +301,7 @@ public class PersonalFragment extends Fragment { time.toString(), noteObject.getBoolean("is_public"), noteObject.getInt("likes"), + noteObject.getString("avatar"), jsonArrayToStringArray(noteObject.getJSONArray("tags")) ); listOfNotes.add(addNote); 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 7d9d42d..4fa4af2 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 @@ -85,6 +85,7 @@ public class Utils { time.toString(), noteObject.getBoolean("is_public"), noteObject.getInt("likes"), + noteObject.getString("avatar"), jsonArrayToStringArray(noteObject.getJSONArray("tags")) ); return note; From f5782135202a3122a3cf0232000436f7614c1ace Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Fri, 8 Jul 2016 00:59:07 +0300 Subject: [PATCH 3/4] added other users notes in map --- .../sagi/thesocialnotework/GmapFragment.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) 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 a246495..adb4d99 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 @@ -29,6 +29,7 @@ import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; @@ -50,7 +51,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { private GoogleMap mMap; private GPSUtils gpsUtils; 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() { @@ -121,17 +122,27 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { } }); - + LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude()); // mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!")); if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } 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); + 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, MarkerOptions, List> { GoogleMap mMap; -// GmapFragment gmap; public getMarkersFromNotes(GoogleMap map) { mMap = map; -// gmap = GmapFragment. -// mMap = GmapFragment.getMap(); Log.d(TAG, "in async ctor"); } @@ -190,7 +198,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { protected List doInBackground(List... listOfNotes) { Log.d(TAG, "in async BG"); - String url = "http://www.aljazeera.com/mritems/images/site/DefaultAvatar.jpg"; List markerOptionList = new ArrayList<>(); // for (int i = 0 ; i< listOfNotes.length; i++) for (Note n : listOfNotes[0]) { @@ -199,7 +206,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { .title(n.getTitle()) .position(new LatLng(n.getLat(), n.getLon())) .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); // ); @@ -208,7 +215,6 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { } -//Bitmap.createScaledBitmap(myBitmap, 80, 80, false); } From 4a03c1c0248211b91fbb069d3f1845ee8a9c77c8 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Fri, 8 Jul 2016 02:05:58 +0300 Subject: [PATCH 4/4] added MarkerNoteStruct and dialog box for note in map --- .../sagi/thesocialnotework/GmapFragment.java | 161 +++++++++++++++--- .../thesocialnotework/MarkerNoteStruct.java | 25 +++ 2 files changed, 163 insertions(+), 23 deletions(-) create mode 100644 app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/MarkerNoteStruct.java 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; + } +}