Merge branch 'master' of github.com:sagidayan/TheSocialNotework-Android
This commit is contained in:
commit
c2d8312f7f
5 changed files with 193 additions and 34 deletions
|
@ -1,6 +1,9 @@
|
||||||
package com.android_app.matan.ara.sagi.thesocialnotework;
|
package com.android_app.matan.ara.sagi.thesocialnotework;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -15,6 +18,10 @@ import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
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.android.volley.Response;
|
||||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||||
|
@ -29,6 +36,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;
|
||||||
|
@ -37,6 +45,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;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
|
@ -50,10 +59,12 @@ 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;
|
||||||
|
private HashMap<Marker, Note> eventMarkerMap;
|
||||||
|
|
||||||
|
|
||||||
public GmapFragment() {
|
public GmapFragment() {
|
||||||
|
eventMarkerMap = new HashMap<Marker, Note>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,19 +132,130 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
mMap.setInfoWindowAdapter(infoWindowAdapter);
|
||||||
|
|
||||||
|
|
||||||
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());
|
LatLng userLocation = new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude());
|
||||||
// mMap.addMarker(new MarkerOptions().position(userLocation).title("I Am Here!"));
|
// 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) {
|
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;
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 for getting all user notes
|
||||||
Response.Listener<JSONObject> getNotesSuccessListener = new Response.Listener<JSONObject>() {
|
Response.Listener<JSONObject> getNotesSuccessListener = new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -150,8 +272,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback {
|
||||||
time.setTime(noteObject.getLong("created_at"));
|
time.setTime(noteObject.getLong("created_at"));
|
||||||
listOfNotes.add(Utils.getNoteFromJsonObj(noteObject, time));
|
listOfNotes.add(Utils.getNoteFromJsonObj(noteObject, time));
|
||||||
}
|
}
|
||||||
new getMarkersFromNotes(mMap).execute(listOfNotes);
|
new getMarkersFromNotes(mMap, eventMarkerMap).execute(listOfNotes);
|
||||||
// noteList.setAdapter(noteListAdapter);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
|
Log.e(TAG, "newNoteSuccess:" + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -160,56 +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;
|
GoogleMap mMap;
|
||||||
// GmapFragment gmap;
|
HashMap<Marker, Note> eventMarkerMap;
|
||||||
|
|
||||||
public getMarkersFromNotes(GoogleMap map) {
|
public getMarkersFromNotes(GoogleMap map, HashMap<Marker, Note> eventMarkerMap) {
|
||||||
mMap = map;
|
|
||||||
// gmap = GmapFragment.
|
|
||||||
// mMap = GmapFragment.getMap();
|
|
||||||
Log.d(TAG, "in async ctor");
|
Log.d(TAG, "in async ctor");
|
||||||
|
this.eventMarkerMap = eventMarkerMap;
|
||||||
|
mMap = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onProgressUpdate(MarkerOptions... mo) {
|
protected void onProgressUpdate(MarkerNoteStruct... mo) {
|
||||||
mMap.addMarker(mo[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
eventMarkerMap.put(mMap.addMarker(mo[0].getMarker()),mo[0].getNote());
|
||||||
protected void onPostExecute(List<MarkerOptions> markerOptionList) {
|
|
||||||
for (MarkerOptions mo : markerOptionList) {
|
|
||||||
mMap.addMarker(mo);
|
|
||||||
}
|
|
||||||
Log.d(TAG, "in async post");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<MarkerOptions> doInBackground(List<Note>... listOfNotes) {
|
protected Void 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<>();
|
|
||||||
// for (int i = 0 ; i< listOfNotes.length; i++)
|
|
||||||
for (Note n : listOfNotes[0]) {
|
for (Note n : listOfNotes[0]) {
|
||||||
// markerOptionList.add(
|
|
||||||
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(url), 80, 80, false)));
|
.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;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//Bitmap.createScaledBitmap(myBitmap, 80, 80, false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,13 +16,13 @@ public class Note implements Parcelable{
|
||||||
protected int likes;
|
protected int likes;
|
||||||
protected ArrayList<String> tags;
|
protected ArrayList<String> tags;
|
||||||
protected float lat, lon;
|
protected float lat, lon;
|
||||||
protected String id, address, title, body, timestamp;
|
protected String id, address, title, body, timestamp, avatar;
|
||||||
protected boolean isPublic;
|
protected boolean isPublic;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic, int likes, ArrayList<String> tags) {
|
public Note(String id, float lat, float lon, String address, String title, String body, String timestamp, boolean isPublic, int likes,String avatar, ArrayList<String> tags) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.lat = lat;
|
this.lat = lat;
|
||||||
this.lon = lon;
|
this.lon = lon;
|
||||||
|
@ -34,18 +34,23 @@ public class Note implements Parcelable{
|
||||||
this.isPublic = isPublic;
|
this.isPublic = isPublic;
|
||||||
this.likes = likes;
|
this.likes = likes;
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
|
this.avatar = avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected Note(Parcel in) {
|
protected Note(Parcel in) {
|
||||||
likes = in.readInt();
|
likes = in.readInt();
|
||||||
tags = in.createStringArrayList();
|
tags = in.createStringArrayList();
|
||||||
lat = in.readFloat();
|
lat = in.readFloat();
|
||||||
lon = in.readFloat();
|
lon = in.readFloat();
|
||||||
|
|
||||||
id = in.readString();
|
id = in.readString();
|
||||||
address = in.readString();
|
address = in.readString();
|
||||||
title = in.readString();
|
title = in.readString();
|
||||||
body = in.readString();
|
body = in.readString();
|
||||||
timestamp = in.readString();
|
timestamp = in.readString();
|
||||||
|
avatar = in.readString();
|
||||||
isPublic = in.readByte() != 0;
|
isPublic = in.readByte() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +77,7 @@ public class Note implements Parcelable{
|
||||||
", body='" + body + '\'' +
|
", body='" + body + '\'' +
|
||||||
", timestamp=" + timestamp +
|
", timestamp=" + timestamp +
|
||||||
", isPublic=" + isPublic +
|
", isPublic=" + isPublic +
|
||||||
|
", avatar=" + avatar+
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +163,9 @@ public class Note implements Parcelable{
|
||||||
public void setTags(ArrayList<String> tags) {
|
public void setTags(ArrayList<String> tags) {
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
|
public String getAvatar() {return avatar;}
|
||||||
|
|
||||||
|
public void setAvatar(String avatar) {this.avatar = avatar; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
|
@ -174,6 +183,7 @@ public class Note implements Parcelable{
|
||||||
dest.writeString(title);
|
dest.writeString(title);
|
||||||
dest.writeString(body);
|
dest.writeString(body);
|
||||||
dest.writeString(timestamp);
|
dest.writeString(timestamp);
|
||||||
|
dest.writeString(avatar);
|
||||||
dest.writeByte((byte) (isPublic ? 1 : 0));
|
dest.writeByte((byte) (isPublic ? 1 : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,6 +301,7 @@ public class PersonalFragment extends Fragment {
|
||||||
time.toString(),
|
time.toString(),
|
||||||
noteObject.getBoolean("is_public"),
|
noteObject.getBoolean("is_public"),
|
||||||
noteObject.getInt("likes"),
|
noteObject.getInt("likes"),
|
||||||
|
noteObject.getString("avatar"),
|
||||||
jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
||||||
);
|
);
|
||||||
listOfNotes.add(addNote);
|
listOfNotes.add(addNote);
|
||||||
|
|
|
@ -85,6 +85,7 @@ public class Utils {
|
||||||
time.toString(),
|
time.toString(),
|
||||||
noteObject.getBoolean("is_public"),
|
noteObject.getBoolean("is_public"),
|
||||||
noteObject.getInt("likes"),
|
noteObject.getInt("likes"),
|
||||||
|
noteObject.getString("avatar"),
|
||||||
jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
jsonArrayToStringArray(noteObject.getJSONArray("tags"))
|
||||||
);
|
);
|
||||||
return note;
|
return note;
|
||||||
|
|
Loading…
Reference in a new issue