Skip to content

Commit

Permalink
Adds start without activity param
Browse files Browse the repository at this point in the history
  • Loading branch information
netodevel committed Jan 2, 2018
1 parent 8434242 commit ae6ccdd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ dependencies {
// }))

.start(getBaseContext(), this);

// IF YOU WANT RUN IN SERVICE
// .start(this);
}

@Override
Expand Down
19 changes: 1 addition & 18 deletions app/src/main/java/br/com/safety/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package br.com.safety.sample;

import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import br.com.safety.locationlistenerhelper.core.CurrentLocationListener;
import br.com.safety.locationlistenerhelper.core.CurrentLocationReceiver;
import br.com.safety.locationlistenerhelper.core.LocationTracker;

public class MainActivity extends AppCompatActivity {
Expand All @@ -31,20 +27,7 @@ public void onClick(View v) {
.setInterval(1000)
.setGps(true)
.setNetWork(false)
.currentLocation(new CurrentLocationReceiver(new CurrentLocationListener() {

@Override
public void onCurrentLocation(Location location) {
Log.d("callback", ":onCurrentLocation" + location.getLongitude());
locationTracker.stopLocationService(getBaseContext());
}

@Override
public void onPermissionDiened() {
Log.d("callback", ":onPermissionDiened");
locationTracker.stopLocationService(getBaseContext());
}
})).start(getBaseContext(), MainActivity.this);
.start(getBaseContext());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ public LocationTracker start(Context context, AppCompatActivity appCompatActivit
return this;
}

public LocationTracker start(Context context) {
startLocationService(context);

if (this.currentLocationReceiver != null) {
IntentFilter intentFilter = new IntentFilter(SettingsLocationTracker.ACTION_CURRENT_LOCATION_BROADCAST);
intentFilter.addAction(SettingsLocationTracker.ACTION_PERMISSION_DEINED);
context.registerReceiver(this.currentLocationReceiver, intentFilter);
}
return this;
}

private void startLocationService(Context context) {
Intent serviceIntent = new Intent(context, LocationService.class);
saveSettingsInLocalStorage(context);
Expand Down

0 comments on commit ae6ccdd

Please sign in to comment.