use of im.tny.segvault.disturbances.model.RStation in project underlx by underlx.
the class StationActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
super.onBackPressed();
return true;
case R.id.menu_share_location:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(String.format(Locale.ROOT, "geo:0,0?q=%f,%f(%s)", worldCoords[0], worldCoords[1], getTitle())));
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// oh well
}
return true;
case R.id.menu_share_webprofile:
// TODO: un-hardcode this URL, move it to strings
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(getString(R.string.link_format_station), stationId)));
try {
startActivity(browserIntent);
} catch (ActivityNotFoundException e) {
// oh well
}
return true;
case R.id.menu_favorite:
Realm realm = Application.getDefaultRealmInstance(this);
realm.beginTransaction();
RStation rstation = realm.where(RStation.class).equalTo("id", stationId).findFirst();
boolean isFavorite = rstation.isFavorite();
isFavorite = !isFavorite;
rstation.setFavorite(isFavorite);
realm.copyToRealm(rstation);
realm.commitTransaction();
realm.close();
if (isFavorite) {
item.setTitle(R.string.act_station_favorite);
item.setIcon(R.drawable.ic_star_white_24dp);
} else {
item.setTitle(R.string.act_station_unfavorite);
item.setIcon(R.drawable.ic_star_border_white_24dp);
}
return true;
}
return super.onOptionsItemSelected(item);
}
use of im.tny.segvault.disturbances.model.RStation in project underlx by underlx.
the class StationActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.station, menu);
Realm realm = Application.getDefaultRealmInstance(this);
RStation rstation = realm.where(RStation.class).equalTo("id", stationId).findFirst();
boolean isFavorite = false;
if (rstation != null) {
isFavorite = rstation.isFavorite();
}
realm.close();
MenuItem favItem = menu.findItem(R.id.menu_favorite);
if (isFavorite) {
favItem.setTitle(R.string.act_station_favorite);
favItem.setIcon(R.drawable.ic_star_white_24dp);
} else {
favItem.setTitle(R.string.act_station_unfavorite);
favItem.setIcon(R.drawable.ic_star_border_white_24dp);
}
return true;
}
use of im.tny.segvault.disturbances.model.RStation in project underlx by underlx.
the class MainService method putNetwork.
private void putNetwork(final Network net) {
synchronized (lock) {
// create Realm stations for the network if they don't exist already
Realm realm = Application.getDefaultRealmInstance(this);
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
for (Station s : net.getStations()) {
if (realm.where(RStation.class).equalTo("id", s.getId()).count() == 0) {
RStation rs = new RStation();
rs.setStop(s);
rs.setNetwork(net.getId());
realm.copyToRealm(rs);
}
}
}
});
realm.close();
net.setEdgeWeighter(cweighter);
networks.put(net.getId(), net);
S2LS loc = new S2LS(net, new S2LSChangeListener());
locServices.put(net.getId(), loc);
WiFiLocator wl = new WiFiLocator(net);
wfc.setLocatorForNetwork(net, wl);
loc.addNetworkDetector(wl);
loc.addProximityDetector(wl);
loc.addLocator(wl);
}
}
Aggregations