use of be.brunoparmentier.openbikesharing.app.models.StationStatus in project OpenBikeSharing by bparmentier.
the class StationsListAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.station_list_item, parent, false);
}
final Station station = getItem(position);
if (station != null) {
TextView stationNameTitle = (TextView) v.findViewById(R.id.stationNameTitle);
TextView freeBikesValue = (TextView) v.findViewById(R.id.freeBikesValue);
TextView emptySlotsValue = (TextView) v.findViewById(R.id.emptySlotsValue);
StationStatus stationStatus = station.getStatus();
if (stationNameTitle != null) {
stationNameTitle.setText(station.getName());
if (stationStatus == StationStatus.CLOSED) {
stationNameTitle.setPaintFlags(stationNameTitle.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else {
stationNameTitle.setPaintFlags(stationNameTitle.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
}
}
if (freeBikesValue != null) {
int bikes = station.getFreeBikes();
freeBikesValue.setText(String.valueOf(bikes));
}
if (emptySlotsValue != null) {
int emptySlots = station.getEmptySlots();
ImageView emptySlotsLogo = (ImageView) v.findViewById(R.id.emptySlotsLogo);
if (emptySlots == -1) {
emptySlotsLogo.setVisibility(View.GONE);
emptySlotsValue.setVisibility(View.GONE);
} else {
emptySlotsLogo.setVisibility(View.VISIBLE);
emptySlotsValue.setVisibility(View.VISIBLE);
emptySlotsValue.setText(String.valueOf(emptySlots));
}
}
}
return v;
}
use of be.brunoparmentier.openbikesharing.app.models.StationStatus 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);
}
Aggregations