From d7bc9707d3438105f0970ccb4c427e047b0fef4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20P=C3=B3=C5=82grabia?= Date: Fri, 26 Aug 2016 22:59:05 +0200 Subject: [PATCH] Fixed issue with not receiving location data. --- .../urbanexplorer/fragments/HomeFragment.java | 17 ++++------------- app/src/main/res/layout-v21/activity_main.xml | 19 ------------------- 2 files changed, 4 insertions(+), 32 deletions(-) delete mode 100644 app/src/main/res/layout-v21/activity_main.xml diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java index 9346e9a..1a075ab 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java @@ -33,7 +33,6 @@ public class HomeFragment extends Fragment implements LocationListener { private boolean locationEnabled; private LocationManager locationService; private String locationProvider; - private HomeFragment homeFrag; private boolean locationServicesActivated = false; public HomeFragment() { @@ -64,20 +63,13 @@ public class HomeFragment extends Fragment implements LocationListener { return inflater.inflate(R.layout.fragment_home, container, false); } - public void setLocationData(double lat, double lng) { - TextView locationInfo = (TextView) getActivity().findViewById(R.id.locationInfo); - locationInfo.setText("Location: (" + lat + "," + lng + ")"); - } - @Override public void onLocationChanged(Location location) { Log.i(CLASS_TAG, "Location provider changed: " + location); double lat = location.getLatitude(); double lng = location.getLongitude(); - HomeFragment homeFrag = (HomeFragment) getActivity() - .getSupportFragmentManager() - .findFragmentById(R.id.home); - homeFrag.setLocationData(lat, lng); + TextView locationInfo = (TextView) getActivity().findViewById(R.id.locationInfo); + locationInfo.setText("Location: (" + lat + "," + lng + ")"); } @Override @@ -99,12 +91,11 @@ public class HomeFragment extends Fragment implements LocationListener { public void onResume() { super.onResume(); - homeFrag = (HomeFragment) getChildFragmentManager().findFragmentById(R.id.home_frag); if (locationProvider != null) { locationService.requestLocationUpdates(locationProvider, MIN_TIME, MIN_DISTANCE, - homeFrag); + this); locationServicesActivated = true; Toast.makeText(getActivity(), "Location resumed", Toast.LENGTH_LONG).show(); } @@ -114,7 +105,7 @@ public class HomeFragment extends Fragment implements LocationListener { public void onPause() { super.onPause(); if (locationServicesActivated) { - locationService.removeUpdates(homeFrag); + locationService.removeUpdates(this); } } diff --git a/app/src/main/res/layout-v21/activity_main.xml b/app/src/main/res/layout-v21/activity_main.xml deleted file mode 100644 index 0c8a795..0000000 --- a/app/src/main/res/layout-v21/activity_main.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - -