Skip to content

Instantly share code, notes, and snippets.

public class MapsPresenterImpl implements MapsPresenter, LocationCallback, GeofenceCallback {
private static final String TAG = MapsPresenterImpl.class.getSimpleName();
private MapsView view;
private GoogleLocationApiManager googleLocationApiManager;
private GeofencingManager geofencingManager;
private List<CompanyLocation> companyLocationList = new ArrayList<>();
public MapsPresenterImpl(MapsView view, FragmentActivity fragmentActivity, Context context) {
if(view == null) throw new NullPointerException("view can not be NULL");
public interface MapsPresenter {
void connectToLocationService();
void disconnectFromLocationService();
void fetchCompanyLocations();
void onMapReady();
}
public interface MapsView {
void generateMap();
void updateLocationOnMap(Location location);
void showGeofences(List<CompanyLocation> companyLocationList);
}
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, MapsView {
private GoogleMap mMap;
private MapsPresenter presenter;
private Marker currentPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
/**
* Just a dummy container class in order to
* collect {@link com.google.android.gms.location.Geofence}
* and {@link com.google.android.gms.maps.model.LatLng} in one entity
*/
public class CompanyLocation {
private LatLng coordinates;
private Geofence geofence;
@kostovtd
kostovtd / AlertDialog.java
Last active December 7, 2016 21:03
A code snippet for overriding the behavior of AlertDialog buttons
final AlertDialog dialog = new AlertDialog.Builder(context)
.setView(v)
.setTitle(R.string.my_title)
.setPositiveButton(android.R.string.ok, null) //Set to null. We override the onclick
.setNegativeButton(android.R.string.cancel, null)
.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
@kostovtd
kostovtd / MapsActivity.java
Created December 3, 2016 08:23
View Layer for GeofencingExample app
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
@kostovtd
kostovtd / CompanyLocation.java
Created December 3, 2016 08:21
Model Layer for GeofencingExample app
import com.google.android.gms.location.Geofence;
import com.google.android.gms.maps.model.LatLng;
/**
* Just a dummy container class in order to
* collect {@link com.google.android.gms.location.Geofence}
* and {@link com.google.android.gms.maps.model.LatLng} in one entity
*/
public class CompanyLocation {
productFlavors {
newYorkTimes {
...
}
theGuardian {
...
}
productFlavors {
newYorkTimes {
applicationId "com.nyt.rss"
buildConfigField 'String', 'HOST', '"http://nytimes.com"'
}
theGuardian {
applicationId "com.theguardian.rss"
buildConfigField 'String', 'HOST', '"http://theguardian.com"'