Commit 886db27a authored by Varun Patil's avatar Varun Patil

Add locate button to InstiMap

parent b960d2d7
...@@ -313,8 +313,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On ...@@ -313,8 +313,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
return; return;
case MY_PERMISSIONS_REQUEST_ACCESS_LOCATION: case MY_PERMISSIONS_REQUEST_ACCESS_LOCATION:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
MapFragment mapFragment = new MapFragment(); MapFragment.getMainActivity().setupGPS();
updateFragment(mapFragment);
} else { } else {
Toast toast = Toast.makeText(MainActivity.this, "Need Permission", Toast.LENGTH_SHORT); Toast toast = Toast.makeText(MainActivity.this, "Need Permission", Toast.LENGTH_SHORT);
toast.show(); toast.show();
......
...@@ -4,6 +4,7 @@ import android.Manifest; ...@@ -4,6 +4,7 @@ import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PointF; import android.graphics.PointF;
...@@ -20,6 +21,7 @@ import android.media.SoundPool; ...@@ -20,6 +21,7 @@ import android.media.SoundPool;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
...@@ -188,18 +190,36 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -188,18 +190,36 @@ public class MapFragment extends Fragment implements TextWatcher,
@Override @Override
public void onResponse(Call<List<Venue>> call, Response<List<Venue>> response) { public void onResponse(Call<List<Venue>> call, Response<List<Venue>> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
Locations mLocations = new Locations(response.body()); setupWithData(response.body());
}
}
@Override
public void onFailure(Call<List<Venue>> call, Throwable t) {
setupWithData(new ArrayList<Venue>());
}
});
}
void setupWithData(List<Venue> venues) {
Locations mLocations = new Locations(venues);
data = mLocations.data; data = mLocations.data;
markerlist = new ArrayList<com.mrane.data.Marker>(data.values()); markerlist = new ArrayList<com.mrane.data.Marker>(data.values());
setUpDrawer(); setUpDrawer();
setupMap(); setupMap();
setupGPS();
}
}
// Setup locate button
FloatingActionButton fab = getView().findViewById(R.id.locate_fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onFailure(Call<List<Venue>> call, Throwable t) { } public void onClick(View v) {
locate();
}
}); });
}
private void locate() {
setupGPS();
} }
...@@ -1038,8 +1058,7 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -1038,8 +1058,7 @@ public class MapFragment extends Fragment implements TextWatcher,
ActivityCompat.requestPermissions(getActivity(), ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_LOCATION); MY_PERMISSIONS_REQUEST_LOCATION);
} } else {
LocationManager locationManager = (LocationManager) LocationManager locationManager = (LocationManager)
getActivity().getSystemService(Context.LOCATION_SERVICE); getActivity().getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new MyLocationListener(); LocationListener locationListener = new MyLocationListener();
...@@ -1051,12 +1070,15 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -1051,12 +1070,15 @@ public class MapFragment extends Fragment implements TextWatcher,
Toast.makeText(getContext(), "No permission!", Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), "No permission!", Toast.LENGTH_LONG).show();
} }
} }
}
/*---------- Listener class to get coordinates ------------- */ /*---------- Listener class to get coordinates ------------- */
private class MyLocationListener implements LocationListener { private class MyLocationListener implements LocationListener {
@Override @Override
public void onLocationChanged(Location loc) { public void onLocationChanged(Location loc) {
if (getView() == null || getActivity() == null) return;
Toast.makeText( Toast.makeText(
getActivity().getBaseContext(), getActivity().getBaseContext(),
"Location changed: Lat: " + loc.getLatitude() + " Lng: " "Location changed: Lat: " + loc.getLatitude() + " Lng: "
...@@ -1075,11 +1097,6 @@ public class MapFragment extends Fragment implements TextWatcher, ...@@ -1075,11 +1097,6 @@ public class MapFragment extends Fragment implements TextWatcher,
A = new double[] {0.010619520345247447, -14.46472789089445, 61.00432524817795, 12.593699865482979, -1.3923808471860513, 0.05646175191919056, 0.3826096686410426, 0.07802615132849677, -10.35622400664665}; A = new double[] {0.010619520345247447, -14.46472789089445, 61.00432524817795, 12.593699865482979, -1.3923808471860513, 0.05646175191919056, 0.3826096686410426, 0.07802615132849677, -10.35622400664665};
int py = (int)(Zyn + A[0] + A[1]*x + A[2]*y + A[3]*x*x + A[4]*x*x*y + A[5]*x*x*y*y + A[6]*y*y + A[7]*x*y*y + A[8]*x*y); int py = (int)(Zyn + A[0] + A[1]*x + A[2]*y + A[3]*x*x + A[4]*x*x*y + A[5]*x*x*y*y + A[6]*y*y + A[7]*x*y*y + A[8]*x*y);
/*Toast.makeText(
getActivity().getBaseContext(),
"Location changed: Lat: " + px + " Lng: "
+ py, Toast.LENGTH_SHORT).show();*/
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()); SubsamplingScaleImageView.AnimationBuilder anim = campusMapView.animateCenter(user.getPoint());
......
...@@ -140,10 +140,10 @@ ...@@ -140,10 +140,10 @@
</LinearLayout> </LinearLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/loadingPanel"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center"> android:gravity="center"
android:id="@+id/loadingPanel">
<ProgressBar <ProgressBar
android:layout_width="wrap_content" android:layout_width="wrap_content"
...@@ -151,4 +151,19 @@ ...@@ -151,4 +151,19 @@
android:indeterminate="true" /> android:indeterminate="true" />
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="@+id/locate_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:src="@drawable/ic_my_location_black_24dp"
android:tint="@android:color/black" />
</RelativeLayout>
</FrameLayout> </FrameLayout>
\ No newline at end of file
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