Skip to content

Instantly share code, notes, and snippets.

@shannah
Last active November 30, 2015 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shannah/86c739edac34216d3c4d to your computer and use it in GitHub Desktop.
Save shannah/86c739edac34216d3c4d to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.codename1.tests.bglocation;
import com.codename1.location.Location;
import com.codename1.location.LocationListener;
/**
*
* @author shannah
*/
public class BackgroundLocationListener implements LocationListener {
@Override
public void locationUpdated(Location location) {
System.out.println("location updated "+location.getLatitude()+", "+location.getLongitude());
}
@Override
public void providerStateChanged(int newState) {
}
}
package com.codename1.tests.bglocation;
import com.codename1.location.Geofence;
import com.codename1.location.Location;
import com.codename1.location.LocationManager;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import java.io.IOException;
public class BGLocationTest {
private Form current;
private Resources theme;
public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
// Pro users - uncomment this code to get crash reports sent to you automatically
/*Display.getInstance().addEdtErrorHandler(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
evt.consume();
Log.p("Exception in AppName version " + Display.getInstance().getProperty("AppVersion", "Unknown"));
Log.p("OS " + Display.getInstance().getPlatformName());
Log.p("Error " + evt.getSource());
Log.p("Current Form " + Display.getInstance().getCurrent().getName());
Log.e((Throwable)evt.getSource());
Log.sendLog();
}
});*/
}
public void start() {
if(current != null){
current.show();
return;
}
Form hi = new Form("Hi World");
hi.addComponent(new Label("Hi World"));
LocationManager.getLocationManager()
.setBackgroundLocationListener(BackgroundLocationListener.class);
Location loc = new Location();
loc.setLatitude(51.5033630);
loc.setLongitude(-0.1276250);
Geofence gf = new Geofence("test", loc, 100, 100000);
LocationManager.getLocationManager()
.addGeoFencing(GeofenceListenerImpl.class, gf);
hi.show();
}
public void stop() {
current = Display.getInstance().getCurrent();
}
public void destroy() {
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.codename1.tests.bglocation;
import com.codename1.location.GeofenceListener;
/**
*
* @author shannah
*/
public class GeofenceListenerImpl implements GeofenceListener {
@Override
public void onExit(String id) {
System.out.println("Exited "+id);
}
@Override
public void onEntered(String id) {
System.out.println("Entered "+id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment