use of be.brunoparmentier.openbikesharing.app.db.StationsDataSource in project OpenBikeSharing by bparmentier.
the class MapActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
getActionBar().setDisplayHomeAsUpEnabled(true);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
stationsDataSource = new StationsDataSource(this);
ArrayList<Station> stations = stationsDataSource.getStations();
map = (MapView) findViewById(R.id.mapView);
stationMarkerInfoWindow = new StationMarkerInfoWindow(R.layout.bonuspack_bubble, map);
/* handling map events */
MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this, this);
map.getOverlays().add(0, mapEventsOverlay);
/* markers list */
GridMarkerClusterer stationsMarkers = new GridMarkerClusterer();
Drawable clusterIconD = getResources().getDrawable(R.drawable.marker_cluster);
Bitmap clusterIcon = ((BitmapDrawable) clusterIconD).getBitmap();
map.getOverlays().add(stationsMarkers);
stationsMarkers.setIcon(clusterIcon);
stationsMarkers.setGridSize(100);
for (final Station station : stations) {
stationsMarkers.add(createStationMarker(station));
}
map.invalidate();
map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setMinZoomLevel(3);
/* map tile source */
String mapLayer = settings.getString(PREF_KEY_MAP_LAYER, "");
switch(mapLayer) {
case MAP_LAYER_MAPNIK:
map.setTileSource(TileSourceFactory.MAPNIK);
break;
case MAP_LAYER_CYCLEMAP:
map.setTileSource(TileSourceFactory.CYCLEMAP);
break;
case MAP_LAYER_OSMPUBLICTRANSPORT:
map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
break;
default:
map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
break;
}
GpsMyLocationProvider imlp = new GpsMyLocationProvider(this.getBaseContext());
imlp.setLocationUpdateMinDistance(1000);
imlp.setLocationUpdateMinTime(60000);
map.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
myLocationOverlay = new MyLocationNewOverlay(imlp, this.map);
myLocationOverlay.enableMyLocation();
map.getOverlays().add(this.myLocationOverlay);
mapController = map.getController();
if (savedInstanceState != null) {
mapController.setZoom(savedInstanceState.getInt(MAP_CURRENT_ZOOM_KEY));
mapController.setCenter(new GeoPoint(savedInstanceState.getDouble(MAP_CENTER_LAT_KEY), savedInstanceState.getDouble(MAP_CENTER_LON_KEY)));
} else {
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Location userLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (userLocation != null) {
mapController.setZoom(16);
mapController.animateTo(new GeoPoint(userLocation));
} else {
double bikeNetworkLatitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LATITUDE, 0));
double bikeNetworkLongitude = Double.longBitsToDouble(settings.getLong(PREF_KEY_NETWORK_LONGITUDE, 0));
mapController.setZoom(13);
mapController.setCenter(new GeoPoint(bikeNetworkLatitude, bikeNetworkLongitude));
Toast.makeText(this, R.string.location_not_found, Toast.LENGTH_LONG).show();
}
}
}
use of be.brunoparmentier.openbikesharing.app.db.StationsDataSource in project OpenBikeSharing by bparmentier.
the class StationsListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stations_list);
refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
refreshLayout.setColorSchemeResources(R.color.bike_red, R.color.parking_blue_dark);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
executeDownloadTask();
}
});
viewPager = (ViewPager) findViewById(R.id.viewPager);
viewPager.setOffscreenPageLimit(2);
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
@Override
public void onPageScrollStateChanged(int state) {
/* as explained on
http://stackoverflow.com/questions/25978462/swiperefreshlayout-viewpager-limit-horizontal-scroll-only
*/
refreshLayout.setEnabled(state == ViewPager.SCROLL_STATE_IDLE);
}
});
stationsDataSource = new StationsDataSource(this);
stations = stationsDataSource.getStations();
favStations = stationsDataSource.getFavoriteStations();
nearbyStations = new ArrayList<>();
tabsPagerAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(tabsPagerAdapter);
settings = PreferenceManager.getDefaultSharedPreferences(this);
actionBar = getActionBar();
int defaultTabIndex = Integer.valueOf(settings.getString(PREF_KEY_DEFAULT_TAB, "0"));
for (int i = 0; i < 3; i++) {
ActionBar.Tab tab = actionBar.newTab();
tab.setTabListener(this);
tab.setText(tabsPagerAdapter.getPageTitle(i));
actionBar.addTab(tab, (defaultTabIndex == i));
}
actionBar.setHomeButtonEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
boolean firstRun = settings.getString(PREF_KEY_NETWORK_ID, "").isEmpty();
setDBLastUpdateText();
if (firstRun) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.welcome_dialog_message);
builder.setTitle(R.string.welcome_dialog_title);
builder.setPositiveButton(R.string.welcome_dialog_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(StationsListActivity.this, BikeNetworksListActivity.class);
startActivityForResult(intent, PICK_NETWORK_REQUEST);
}
});
builder.setNegativeButton(R.string.welcome_dialog_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
AlertDialog dialog = builder.create();
dialog.show();
} else {
if (savedInstanceState != null) {
bikeNetwork = (BikeNetwork) savedInstanceState.getSerializable(KEY_BIKE_NETWORK);
stations = (ArrayList<Station>) savedInstanceState.getSerializable(KEY_STATIONS);
favStations = (ArrayList<Station>) savedInstanceState.getSerializable(KEY_FAV_STATIONS);
nearbyStations = (ArrayList<Station>) savedInstanceState.getSerializable(KEY_NEARBY_STATIONS);
} else {
String networkId = settings.getString(PREF_KEY_NETWORK_ID, "");
String stationUrl = settings.getString(PREF_KEY_API_URL, DEFAULT_API_URL) + "networks/" + networkId;
jsonDownloadTask = new JSONDownloadTask();
jsonDownloadTask.execute(stationUrl);
}
}
}
use of be.brunoparmentier.openbikesharing.app.db.StationsDataSource in project OpenBikeSharing by bparmentier.
the class StationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_station);
getActionBar().setDisplayHomeAsUpEnabled(true);
stationsDataSource = new StationsDataSource(this);
settings = PreferenceManager.getDefaultSharedPreferences(this);
station = (Station) getIntent().getSerializableExtra(KEY_STATION);
map = (MapView) findViewById(R.id.mapView);
final GeoPoint stationLocation = new GeoPoint((int) (station.getLatitude() * 1000000), (int) (station.getLongitude() * 1000000));
mapController = map.getController();
mapController.setZoom(16);
/* map tile source */
String mapLayer = settings.getString(PREF_KEY_MAP_LAYER, "");
switch(mapLayer) {
case MAP_LAYER_MAPNIK:
map.setTileSource(TileSourceFactory.MAPNIK);
break;
case MAP_LAYER_CYCLEMAP:
map.setTileSource(TileSourceFactory.CYCLEMAP);
break;
case MAP_LAYER_OSMPUBLICTRANSPORT:
map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
break;
default:
map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
break;
}
map.setMultiTouchControls(true);
/* Station marker */
Marker marker = new Marker(map);
marker.setPosition(stationLocation);
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER);
marker.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker, MapView mapView) {
return false;
}
});
/* Marker icon */
int emptySlots = station.getEmptySlots();
int freeBikes = station.getFreeBikes();
if ((emptySlots == 0 && freeBikes == 0) || station.getStatus() == StationStatus.CLOSED) {
marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker_unavailable));
} else {
double ratio = (double) freeBikes / (double) (freeBikes + emptySlots);
if (freeBikes == 0) {
marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker0));
} else if (freeBikes >= 1 && ratio <= 0.3) {
marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker25));
} else if (ratio > 0.3 && ratio < 0.7) {
marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker50));
} else if (ratio >= 0.7 && emptySlots >= 1) {
marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker75));
} else if (emptySlots == 0 || emptySlots == -1) {
marker.setIcon(getResources().getDrawable(R.drawable.ic_station_marker100));
}
}
map.getOverlays().add(marker);
TextView stationName = (TextView) findViewById(R.id.stationName);
TextView stationEmptySlots = (TextView) findViewById(R.id.stationEmptySlots);
TextView stationFreeBikes = (TextView) findViewById(R.id.stationFreeBikes);
stationName.setText(station.getName());
setLastUpdateText(station.getLastUpdate());
stationFreeBikes.setText(String.valueOf(station.getFreeBikes()));
if (station.getEmptySlots() == -1) {
ImageView stationEmptySlotsLogo = (ImageView) findViewById(R.id.stationEmptySlotsLogo);
stationEmptySlots.setVisibility(View.GONE);
stationEmptySlotsLogo.setVisibility(View.GONE);
} else {
stationEmptySlots.setText(String.valueOf(station.getEmptySlots()));
}
if (station.getAddress() != null) {
TextView stationAddress = (TextView) findViewById(R.id.stationAddress);
stationAddress.setText(station.getAddress());
stationAddress.setVisibility(View.VISIBLE);
}
/* extra info on station */
Boolean isBankingStation = station.isBanking();
Boolean isBonusStation = station.isBonus();
StationStatus stationStatus = station.getStatus();
if (isBankingStation != null) {
ImageView stationBanking = (ImageView) findViewById(R.id.stationBanking);
stationBanking.setVisibility(View.VISIBLE);
if (isBankingStation) {
stationBanking.setImageDrawable(getResources().getDrawable(R.drawable.ic_banking_on));
stationBanking.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), getString(R.string.cards_accepted), Toast.LENGTH_SHORT).show();
}
});
}
}
if (isBonusStation != null) {
ImageView stationBonus = (ImageView) findViewById(R.id.stationBonus);
stationBonus.setVisibility(View.VISIBLE);
if (isBonusStation) {
stationBonus.setImageDrawable(getResources().getDrawable(R.drawable.ic_bonus_on));
stationBonus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), getString(R.string.is_bonus_station), Toast.LENGTH_SHORT).show();
}
});
}
}
if ((stationStatus != null) && stationStatus == StationStatus.CLOSED) {
stationName.setPaintFlags(stationName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
mapController.setCenter(stationLocation);
}
use of be.brunoparmentier.openbikesharing.app.db.StationsDataSource in project OpenBikeSharing by bparmentier.
the class StationsListAppWidgetFactory method onCreate.
@Override
public void onCreate() {
// In onCreate() you setup any connections / cursors to your data source. Heavy lifting,
// for example downloading or creating content etc, should be deferred to onDataSetChanged()
// or getViewAt(). Taking more than 20 seconds in this call will result in an ANR.
stationsDataSource = new StationsDataSource(mContext);
stations = stationsDataSource.getFavoriteStations();
}
Aggregations