Commit 9e2278a3 authored by Varun Patil's avatar Varun Patil

Setup locate button properly

parent 886db27a
...@@ -141,7 +141,10 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -141,7 +141,10 @@ public class MapFragment extends Fragment implements TextWatcher,
public static final int SOUND_ID_REMOVE = 2; public static final int SOUND_ID_REMOVE = 2;
public SoundPool soundPool; public SoundPool soundPool;
public int[] soundPoolIds; public int[] soundPoolIds;
Marker user = new Marker("You", "", 0, 0, 1, "");
private boolean GPSIsSetup = false;
private boolean followingUser = false;
private Marker user = new Marker("You", "", 0, 0, 1, "");
private Handler mHandler = new Handler() { private Handler mHandler = new Handler() {
@Override @Override
...@@ -219,8 +222,13 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -219,8 +222,13 @@ public class MapFragment extends Fragment implements TextWatcher,
} }
private void locate() { private void locate() {
setupGPS(); followingUser = true;
if (!GPSIsSetup) {
setupGPS();
} else if (user != null) {
SubsamplingScaleImageView.AnimationBuilder anim = campusMapView.animateCenter(user.getPoint());
if (anim != null) anim.start();
}
} }
private void setupMap() { private void setupMap() {
...@@ -1066,6 +1074,7 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -1066,6 +1074,7 @@ public class MapFragment extends Fragment implements TextWatcher,
locationManager.requestLocationUpdates( locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 50, 1, locationListener); LocationManager.GPS_PROVIDER, 50, 1, locationListener);
campusMapView.addMarker(user); campusMapView.addMarker(user);
GPSIsSetup = true;
} catch (SecurityException ignored) { } catch (SecurityException ignored) {
Toast.makeText(getContext(), "No permission!", Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), "No permission!", Toast.LENGTH_LONG).show();
} }
...@@ -1099,8 +1108,10 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -1099,8 +1108,10 @@ public class MapFragment extends Fragment implements TextWatcher,
if (px > 0 && py > 0 && px < 5430 && py < 5375){ if (px > 0 && py > 0 && px < 5430 && py < 5375){
user.setPoint(new PointF(px, py)); user.setPoint(new PointF(px, py));
SubsamplingScaleImageView.AnimationBuilder anim = campusMapView.animateCenter(user.getPoint()); if (followingUser) {
if (anim != null) anim.start(); SubsamplingScaleImageView.AnimationBuilder anim = campusMapView.animateCenter(user.getPoint());
if (anim != null) anim.start();
}
campusMapView.invalidate(); campusMapView.invalidate();
} }
} }
...@@ -1114,5 +1125,9 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -1114,5 +1125,9 @@ public class MapFragment extends Fragment implements TextWatcher,
@Override @Override
public void onStatusChanged(String provider, int status, Bundle extras) {} public void onStatusChanged(String provider, int status, Bundle extras) {}
} }
public void setFollowingUser(boolean followingUser) {
this.followingUser = followingUser;
}
} }
...@@ -736,26 +736,10 @@ public class CampusMapView extends SubsamplingScaleImageView { ...@@ -736,26 +736,10 @@ public class CampusMapView extends SubsamplingScaleImageView {
return scale; return scale;
} }
// public void setAddedMarkers(String addedMarkerString) { @Override
// addedMarkerList = new ArrayList<Marker>(); public boolean onTouchEvent(MotionEvent event) {
// String[] addedMarkerNames = addedMarkerString.split("###"); MapFragment.getMainActivity().setFollowingUser(false);
// for (String s : addedMarkerNames) { return super.onTouchEvent(event);
// if (!s.equals("")) { }
// Log.d("test123","names = " + s);
// if (data.containsKey(s)) {
// addedMarkerList.add(data.get(s));
// }
// }
// }
// }
//
// public String getAddedMarkerString() {
// String s = "";
// for (Marker m : addedMarkerList) {
// s = s + m.name + "###";
// }
// Log.d("test123","addedMarkerStringGen = " + s);
// return s;
// }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment