Skip to content

Commit

Permalink
Turned off Location Services while the application is running in the …
Browse files Browse the repository at this point in the history
…background.
  • Loading branch information
gregfrasco committed Apr 4, 2016
1 parent 2b467b3 commit afc0a18
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
Binary file modified app/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "mbta.mbtabuddy"
minSdkVersion 19
targetSdkVersion 23
versionCode 4
versionName "1.3"
versionCode 5
versionName "1.4"
}
buildTypes {
release {
Expand Down
51 changes: 36 additions & 15 deletions app/src/main/java/com/mbtabuddy/TrackerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TrackerFragment extends Fragment implements OnMapReadyCallback {
private LocationManager locationManager;

@Override
public void onCreate(Bundle savedInstanceState){
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

Expand Down Expand Up @@ -96,7 +96,7 @@ public void onClick(View v) {
final int MIN_DIST = 20;
final View byLineView = retView.findViewById(R.id.stations_by_line);
//final TranslateAnimation ta =
// new TranslateAnimation(toMeButton.getLeft(), toMeButton.getLeft(), toMeButton.getTop(), toMeButton.getTop() + byLineView.getHeight());
// new TranslateAnimation(toMeButton.getLeft(), toMeButton.getLeft(), toMeButton.getTop(), toMeButton.getTop() + byLineView.getHeight());
//ta.setDuration(1000);
//ta.setFillAfter(false);

Expand All @@ -105,12 +105,11 @@ public void onClick(View v) {
slide.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction())
{
switch (event.getAction()) {
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_SCROLL:
if(byLineView.getVisibility() == View.GONE) {
if (byLineView.getVisibility() == View.GONE) {
byLineView.setVisibility(View.VISIBLE);
byLineView.startAnimation(animShow);

Expand All @@ -137,13 +136,12 @@ public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:

if(byLineView.getVisibility() == View.GONE) {
if (byLineView.getVisibility() == View.GONE) {

}
else{
} else {
byLineView.setVisibility(View.GONE);
byLineView.startAnimation(animHide);
// toMeButton.setY(toMeLoc);
// toMeButton.setY(toMeLoc);
}
break;

Expand All @@ -156,7 +154,6 @@ public boolean onTouch(View v, MotionEvent event) {
});



View mapLayout = retView.findViewById(R.id.map_layout);
mapLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
Expand All @@ -175,13 +172,11 @@ public boolean onTouch(View v, MotionEvent event) {
return retView;
}

private void createStationList(View view)
{
private void createStationList(View view) {
//Create our list of lines for each lines enum
List<ByLineListContainer> lineItems = new ArrayList<>();
final List<Line> lineVals = Lines.getInstance().values();
for(Line line : lineVals)
{
for (Line line : lineVals) {
ByLineListContainer newLineItem = new ByLineListContainer();
newLineItem.lineColor = line;
newLineItem.lineName = line.getLineName();
Expand Down Expand Up @@ -221,7 +216,7 @@ public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
googleMap.getUiSettings().setZoomControlsEnabled(true);
//Get our mapManager singleton and give it the context
mapManager = new MapManager(getActivity(),mMap);
mapManager = new MapManager(getActivity(), mMap);
/*mapManager.drawAllTrainLines();
mapManager.setMap(mMap);*/

Expand All @@ -248,6 +243,32 @@ public void onMapReady(GoogleMap googleMap) {

}

@Override
public void onResume() {
super.onResume();
if(this.mMap != null) {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(getActivity(),
new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION},
PermissionConstants.LOCATION_TrackerFragment.getValue());
} else {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsManager);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, gpsManager);
gpsManager.InitLocationManager(getActivity(), locationManager, mapManager);
}
}
}

@Override
public void onPause() {
super.onPause();
if (ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
locationManager.removeUpdates(gpsManager);
}

class LoadMapLines extends AsyncTask<Void, Void, Void>
{
private ProgressDialog pd;
Expand Down

0 comments on commit afc0a18

Please sign in to comment.