Skip to content

Commit 3c8b499

Browse files
authored
Merge pull request #61 from CMPUT301F17T11/eshna3
location stuff
2 parents 74aca7f + fa61832 commit 3c8b499

File tree

4 files changed

+132
-83
lines changed

4 files changed

+132
-83
lines changed

app/src/main/java/com/cmput301f17t11/cupofjava/Views/HabitEventTimeLineActivity.java

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ public void onResume(){
266266
@Override
267267
public void onClick(View v) {
268268

269-
final CharSequence mapsOptions[] = new CharSequence[] {"ALL", "5K RADIUS",
270-
"Recent Friends Events", "Filtered Map"};
269+
final CharSequence mapsOptions[] = new CharSequence[] {"ALL"};
271270

272271
android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog
273272
.Builder(getActivity());
@@ -280,15 +279,15 @@ public void onClick(DialogInterface dialog, int which) {
280279
case 0:
281280
mapsAll(0);
282281
break;
283-
case 1:
282+
/*case 1:
284283
mapsAll(1);
285284
break;
286285
case 2:
287286
dialog.dismiss();
288287
break;
289288
case 3:
290289
dialog.dismiss();
291-
break;
290+
break;*/
292291
}
293292
}
294293
});
@@ -374,34 +373,46 @@ public void onDetach() {
374373

375374

376375
public void mapsAll(int type ){
377-
Intent intent = new Intent(getActivity(), MapsActivity.class);
378-
Bundle bundle = new Bundle();
379-
380-
double [] latititudes = new double [events.size()];
381-
double [] longitudes = new double [events.size()];
382-
for (int i = 0; i < events.size(); i++)
383-
{
384-
if(events.get(i).getIsLocationSet()) {
385-
latititudes[i] = events.get(i).getLocation().getLatitude();
386-
longitudes[i] = events.get(i).getLocation().getLongitude();
387-
}
388376

377+
if(events.isEmpty()){
378+
Toast.makeText(getContext(), "No Events to view", Toast.LENGTH_LONG).show();
389379
}
390-
int size = 0;
391-
for(int i = 0; i< events.size(); i++)
392-
{
393-
if(latititudes[i]!= 0.0 && longitudes[i]!= 0.0){
394-
size++;
380+
else {
381+
Intent intent = new Intent(getActivity(), MapsActivity.class);
382+
//Bundle bundle = new Bundle();
383+
384+
//double [] latititudes = new double [events.size()];
385+
//double [] longitudes = new double [events.size()];
386+
ArrayList<Double> latititudes = new ArrayList<>();
387+
ArrayList<Double> longitudes = new ArrayList<>();
388+
ArrayList<String> markerTitles = new ArrayList<>();
389+
for (int i = 0; i < events.size(); i++) {
390+
if (events.get(i).getIsLocationSet()) {
391+
latititudes.add(events.get(i).getLocation().getLatitude());
392+
longitudes.add(events.get(i).getLocation().getLongitude());
393+
markerTitles.add(events.get(i).getHabitTitle());
394+
}
395+
395396
}
396-
}
397397

398398

399-
bundle.putDoubleArray("lat", latititudes);
400-
bundle.putDoubleArray("lon", longitudes);
401-
bundle.putInt("type", type );
402399

403-
intent.putExtras(bundle);
404-
startActivity(intent);
400+
//intent.putExtras(bundle);
401+
402+
intent.putExtra("lat", latititudes);
403+
intent.putExtra("lon", longitudes);
404+
intent.putExtra("markerTitles", markerTitles);
405+
intent.putExtra("type", type);
406+
startActivity(intent);
407+
408+
NearbyTab nearbyTab = new NearbyTab();
409+
Bundle bundle2 = new Bundle();
410+
bundle2.putSerializable("lat", latititudes);
411+
bundle2.putSerializable("lon", longitudes);
412+
bundle2.putInt("type", type );
413+
bundle2.putStringArrayList("markerTitles", markerTitles);
414+
nearbyTab.setArguments(bundle2);
415+
}
405416
}
406417

407418
/**

app/src/main/java/com/cmput301f17t11/cupofjava/Views/MapsActivity.java

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.cmput301f17t11.cupofjava.Views;
22

33
import android.app.Dialog;
4+
import android.app.Fragment;
45
import android.content.Intent;
56
import android.location.Location;
7+
import android.support.v4.app.FragmentActivity;
68
import android.support.v7.app.AppCompatActivity;
79
import android.os.Bundle;
810
import android.util.Log;
@@ -26,18 +28,20 @@
2628

2729
import java.util.ArrayList;
2830

29-
public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {
31+
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
3032

3133
GoogleMap mGoogleMap;
3234

33-
double currentLat;
34-
double currentLon;
35-
double [] latitudes;
36-
double [] longitudes;
35+
double currentLat = 53.525049;
36+
double currentLon = -113.524605;
37+
//double [] latitudes;
38+
//double [] longitudes;
39+
ArrayList<Double> latitudes;
40+
ArrayList<Double> longitudes;
41+
ArrayList<String> markerTitles;
3742
Geolocation location;
3843
int type;
39-
EditText showLocation;
40-
Button getLocation;
44+
MapFragment mapFragment;
4145
@Override
4246
protected void onCreate(Bundle savedInstanceState) {
4347

@@ -46,37 +50,36 @@ protected void onCreate(Bundle savedInstanceState) {
4650
Toast.makeText(this, "Google Play Services Works", Toast.LENGTH_LONG).show();
4751
setContentView(R.layout.maps_activity);
4852
initMap();
49-
}
50-
53+
Intent intent = getIntent();
54+
latitudes = (ArrayList<Double>) intent.getSerializableExtra("lat");
55+
longitudes = (ArrayList<Double>) intent.getSerializableExtra("lon");
56+
markerTitles = intent.getStringArrayListExtra("markerTitles");
57+
type = intent.getIntExtra("type", type);
58+
if (type == 1) { //within 5km
59+
60+
for (int i = 0; i < latitudes.size(); i++) {
61+
double lat2 = latitudes.get(i);
62+
double lng2 = longitudes.get(i);
63+
if ((within5(currentLat, currentLon, lat2, lng2) <= 5.0) == false) {
64+
//do nothing
65+
} else {
66+
latitudes.remove(i);
67+
longitudes.remove(i);
68+
markerTitles.remove(i);
69+
70+
}
71+
}
5172

52-
Bundle bundle = getIntent().getExtras();
53-
if(bundle!= null){
54-
latitudes = bundle.getDoubleArray("lat");
55-
longitudes = bundle.getDoubleArray("lon");
56-
type = bundle.getInt("type");
73+
}
5774

58-
currentLat = bundle.getDouble("currentLat");
59-
currentLon = bundle.getDouble("currentLon");
6075

6176
}
62-
if(type == 1){ //within 5km
63-
64-
for (int i = 0; i < latitudes.length; i++)
65-
{
66-
double lat2= latitudes[i];
67-
double lng2= longitudes[i];
68-
if ((within5(currentLat, currentLon, lat2, lng2) <= 5.0) == false){
69-
//do nothing
70-
}
71-
else{
72-
latitudes[i] = 0.0;
73-
longitudes[i] = 0.0;
74-
}
75-
}
77+
}
78+
79+
80+
7681

77-
}
7882

79-
}
8083

8184
public boolean googleServicesAvailable() {
8285
GoogleApiAvailability api = GoogleApiAvailability.getInstance();
@@ -93,38 +96,39 @@ public boolean googleServicesAvailable() {
9396
}
9497

9598
private void initMap() {
96-
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
99+
if(mapFragment!= null)
100+
{
101+
getFragmentManager().beginTransaction().remove(mapFragment).commit();
102+
}
103+
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
97104
mapFragment.getMapAsync(this);
105+
106+
98107
}
99108

100109
@Override
101110
public void onMapReady(GoogleMap googleMap) {
102111
mGoogleMap = googleMap;
103-
for(int i = 0; i < (latitudes).length; i++){
104-
if(latitudes[i]!= 0.0 && longitudes[i]!= 0.0 ) {
105-
goToLocationZoomed(latitudes[i], longitudes[i], 15);
106-
}
112+
for(int i = 0; i < latitudes.size(); i++){
113+
goToLocationZoomed(latitudes.get(i), longitudes.get(i), 10, markerTitles.get(i));
114+
107115

108116
}
109117
}
110118

111-
private void goToLocationZoomed(double lat, double lng, float zoom) {
119+
120+
private void goToLocationZoomed(double lat, double lng, float zoom, String markerTitle) {
112121
LatLng latLng = new LatLng(lat, lng);
113122
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, zoom);
114123
mGoogleMap.moveCamera(cameraUpdate);
115124
MarkerOptions markerOptions = new MarkerOptions()
116-
.title("U of A").position(new LatLng(lat, lng));
125+
.title(markerTitle).position(new LatLng(lat, lng));
117126
mGoogleMap.addMarker(markerOptions);
118-
/*for(int i = 0; i < eventLoc.size(); i ++){
119-
double latitude = eventLoc.get(i).getLatitude();
120-
double longitude = eventLoc.get(i).getLongitude();
121-
MarkerOptions markerOptions = new MarkerOptions()
122-
.title("U of A").position(new LatLng(latitude, longitude));
123-
mGoogleMap.addMarker(markerOptions);
124-
}*/
127+
125128

126129
}
127130

131+
128132
/**
129133
*
130134
* @param lat1

app/src/main/java/com/cmput301f17t11/cupofjava/Views/NearbyTab.java

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
import android.support.annotation.Nullable;
77
import android.support.v4.app.Fragment;
88
import android.os.Bundle;
9+
import android.util.Log;
910
import android.view.LayoutInflater;
1011
import android.view.View;
1112
import android.view.ViewGroup;
1213
import android.widget.Toast;
1314

15+
import com.cmput301f17t11.cupofjava.Controllers.ElasticsearchController;
16+
import com.cmput301f17t11.cupofjava.Controllers.EventFilteringHelper;
17+
import com.cmput301f17t11.cupofjava.Models.HabitEvent;
1418
import com.cmput301f17t11.cupofjava.R;
1519
import com.google.android.gms.common.ConnectionResult;
1620
import com.google.android.gms.common.GoogleApiAvailability;
@@ -26,11 +30,14 @@
2630
import com.google.android.gms.maps.model.LatLng;
2731
import com.google.android.gms.maps.model.MarkerOptions;
2832

33+
import java.util.ArrayList;
34+
2935
public class NearbyTab extends Fragment implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
3036

3137
MapView mMapView;
3238
private GoogleMap googleMap;
3339
GoogleApiClient mGoogleApiClient;
40+
ArrayList<HabitEvent> events = new ArrayList<>();
3441

3542
// TODO: Rename parameter arguments, choose names that match
3643
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
@@ -40,7 +47,7 @@ public class NearbyTab extends Fragment implements OnMapReadyCallback, GoogleApi
4047
// TODO: Rename and change types of parameters
4148
private String mParam1;
4249
private String mParam2;
43-
private String userName;
50+
String userName;
4451

4552
private NearbyTab.OnFragmentInteractionListener mListener;
4653

@@ -76,7 +83,7 @@ public void onCreate(Bundle savedInstanceState) {
7683
if (getArguments() != null) {
7784
mParam1 = getArguments().getString(ARG_PARAM1);
7885
mParam2 = getArguments().getString(ARG_PARAM2);
79-
this.userName = getArguments().getString("userName");
86+
userName = getArguments().getString("userName");
8087
}
8188
}
8289

@@ -103,6 +110,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
103110
e.printStackTrace();
104111
}
105112

113+
/******************************/
114+
115+
116+
117+
/*****************************/
106118
mMapView.getMapAsync(new OnMapReadyCallback() {
107119
@Override
108120
public void onMapReady(GoogleMap mMap) {
@@ -113,11 +125,39 @@ public void onMapReady(GoogleMap mMap) {
113125

114126
// For dropping a marker at a point on the Map
115127
LatLng uOfA = new LatLng(53.526830, -113.527208);
116-
googleMap.addMarker(new MarkerOptions().position(uOfA).title("Marker Title").snippet("Marker Description"));
128+
129+
ElasticsearchController.GetEventsTask getEventsTask = new ElasticsearchController.GetEventsTask();
130+
getEventsTask.execute(userName);
131+
try {
132+
ArrayList<HabitEvent> foundHabitEvents = getEventsTask.get();
133+
if (!foundHabitEvents.isEmpty()) {
134+
135+
events.addAll(foundHabitEvents);
136+
Log.i("HabitEventTimeline: found events :", events.toString());
137+
} else {
138+
Log.i("HabitEventTimeline", "Did Not find habit events" + events.toString());
139+
140+
}
141+
} catch (Exception e) {
142+
Log.i("HabitEventTimeline", "Failed to get the Habit Events from the async object");
143+
144+
}
145+
events = EventFilteringHelper.reverseChronological(events);
146+
//events2 = EventFilteringHelper.filterByComment()
147+
148+
for(int i = 0; i< events.size(); i++){
149+
if(events.get(i).getIsLocationSet()) {
150+
151+
LatLng pos = new LatLng(events.get(i).getLocation().getLatitude(), events.get(i).getLocation().getLongitude());
152+
googleMap.addMarker(new MarkerOptions().position(pos).title(events.get(i).getHabitTitle()).snippet(events.get(i).getDateAsString()));
153+
CameraPosition cameraPosition = new CameraPosition.Builder().target(uOfA).zoom(10).build();
154+
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
155+
}
156+
}
157+
//googleMap.addMarker(new MarkerOptions().position(uOfA).title("Marker Title").snippet("Marker Description"));
117158

118159
// For zooming automatically to the location of the marker
119-
CameraPosition cameraPosition = new CameraPosition.Builder().target(uOfA).zoom(15).build();
120-
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
160+
121161

122162

123163

app/src/main/java/com/cmput301f17t11/cupofjava/Views/TimeLineFragment.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
4949
View view = inflater.inflate(R.layout.fragment_home, container, false);
5050
Bundle bundle = getArguments();
5151
this.userName = bundle.getString("userName");
52-
this.currentLat = bundle.getDouble("currentLat",0.0);
53-
this.currentLon = bundle.getDouble("currentLon",0.0);
54-
55-
5652

5753
TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tablayout2);
5854

@@ -107,8 +103,6 @@ public Fragment getItem(int position) {
107103
HabitEventTimeLineActivity habitEventTimeLineActivity = new HabitEventTimeLineActivity();
108104
Bundle bundle = new Bundle();
109105
bundle.putString("userName", userName);
110-
bundle.putDouble("currentLat", currentLat);
111-
bundle.putDouble("currentLon", currentLon);
112106
habitEventTimeLineActivity.setArguments(bundle);
113107
return habitEventTimeLineActivity;
114108
case 1:

0 commit comments

Comments
 (0)