use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station in project RSAndroidApp by RailwayStations.
the class DetailsActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
final int itemId = item.getItemId();
if (itemId == R.id.nav_to_station) {
startNavigation(DetailsActivity.this);
} else if (itemId == R.id.timetable) {
final Intent timetableIntent = new Timetable().createTimetableIntent(Country.getCountryByCode(countries, station.getCountry()), station);
if (timetableIntent != null) {
startActivity(timetableIntent);
} else {
Toast.makeText(this, R.string.timetable_missing, Toast.LENGTH_LONG).show();
}
} else if (itemId == R.id.share_photo) {
final Intent shareIntent = createFotoSendIntent();
shareIntent.putExtra(Intent.EXTRA_TEXT, Country.getCountryByCode(countries, station != null ? station.getCountry() : null).getTwitterTags() + " " + binding.details.etbahnhofname.getText());
shareIntent.setType("image/jpeg");
startActivity(createChooser(shareIntent, "send"));
} else if (itemId == R.id.station_info) {
showStationInfo(null);
} else if (itemId == R.id.provider_android_app) {
final List<ProviderApp> providerApps = Country.getCountryByCode(countries, station.getCountry()).getCompatibleProviderApps();
if (providerApps.size() == 1) {
providerApps.get(0).openAppOrPlayStore(this);
} else if (providerApps.size() > 1) {
final CharSequence[] appNames = providerApps.stream().map(ProviderApp::getName).toArray(CharSequence[]::new);
new SimpleDialogs().simpleSelect(this, getResources().getString(R.string.choose_provider_app), appNames, (dialog, which) -> {
if (which >= 0 && providerApps.size() > which) {
providerApps.get(which).openAppOrPlayStore(DetailsActivity.this);
}
});
} else {
Toast.makeText(this, R.string.provider_app_missing, Toast.LENGTH_LONG).show();
}
} else if (itemId == android.R.id.home) {
navigateUp();
} else {
return super.onOptionsItemSelected(item);
}
return true;
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station in project RSAndroidApp by RailwayStations.
the class DetailsActivity method startNavigation.
private void startNavigation(final Context context) {
final NavItem[] items = { new NavItem(" " + getString(R.string.nav_oepnv), R.drawable.ic_directions_bus_gray_24px), new NavItem(" " + getString(R.string.nav_car), R.drawable.ic_directions_car_gray_24px), new NavItem(" " + getString(R.string.nav_bike), R.drawable.ic_directions_bike_gray_24px), new NavItem(" " + getString(R.string.nav_walk), R.drawable.ic_directions_walk_gray_24px), new NavItem(" " + getString(R.string.nav_show), R.drawable.ic_info_gray_24px), new NavItem(" " + getString(R.string.nav_show_on_map), R.drawable.ic_map_gray_24px) };
final ListAdapter adapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item, android.R.id.text1, items) {
@NonNull
public View getView(final int position, final View convertView, @NonNull final ViewGroup parent) {
// Use super class to create the View
final View v = super.getView(position, convertView, parent);
final TextView tv = v.findViewById(android.R.id.text1);
// Put the image on the TextView
tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
// Add margin between image and text (support various screen densities)
final int dp5 = (int) (5 * getResources().getDisplayMetrics().density + 0.5f);
final int dp7 = (int) (20 * getResources().getDisplayMetrics().density);
tv.setCompoundDrawablePadding(dp5);
tv.setPadding(dp7, 0, 0, 0);
return v;
}
};
final double lat = station != null ? station.getLat() : latitude;
final double lon = station != null ? station.getLon() : longitude;
final AlertDialog.Builder navBuilder = new AlertDialog.Builder(this);
navBuilder.setIcon(R.mipmap.ic_launcher);
navBuilder.setTitle(R.string.navMethod);
navBuilder.setAdapter(adapter, (dialog, navItem) -> {
final String dlocation;
Intent intent = null;
switch(navItem) {
case 0:
dlocation = String.format("google.navigation:ll=%s,%s&mode=Transit", lat, lon);
Log.d(TAG, "findnavigation case 0: " + dlocation);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
break;
case 1:
dlocation = String.format("google.navigation:ll=%s,%s&mode=d", lat, lon);
Log.d(TAG, "findnavigation case 1: " + dlocation);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
break;
case 2:
dlocation = String.format("google.navigation:ll=%s,%s&mode=b", lat, lon);
Log.d(TAG, "findnavigation case 2: " + dlocation);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
break;
case 3:
dlocation = String.format("google.navigation:ll=%s,%s&mode=w", lat, lon);
Log.d(TAG, "findnavigation case 3: " + dlocation);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
break;
case 4:
dlocation = String.format("geo:0,0?q=%s,%s(%s)", lat, lon, binding.details.etbahnhofname.getText());
Log.d(TAG, "findnavigation case 4: " + dlocation);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(dlocation));
break;
case 5:
intent = new Intent(DetailsActivity.this, MapsActivity.class);
intent.putExtra(MapsActivity.EXTRAS_LATITUDE, lat);
intent.putExtra(MapsActivity.EXTRAS_LONGITUDE, lon);
intent.putExtra(MapsActivity.EXTRAS_MARKER, getMarkerRes());
Log.d(TAG, "findnavigation case 5: " + lat + "," + lon);
break;
}
try {
startActivity(intent);
} catch (final Exception e) {
final Toast toast = Toast.makeText(context, R.string.activitynotfound, Toast.LENGTH_LONG);
toast.show();
}
}).show();
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station in project RSAndroidApp by RailwayStations.
the class MapsActivity method addMarkers.
private void addMarkers(final List<Station> stationMarker, final List<Upload> uploadList) {
double minLat = 0;
double maxLat = 0;
double minLon = 0;
double maxLon = 0;
for (final Station station : stationMarker) {
final boolean isPendingUpload = isPendingUpload(station, uploadList);
final BahnhofGeoItem geoItem = new BahnhofGeoItem(station, isPendingUpload);
final LatLong bahnhofPos = geoItem.getLatLong();
if (minLat == 0.0) {
minLat = bahnhofPos.latitude;
maxLat = bahnhofPos.latitude;
minLon = bahnhofPos.longitude;
maxLon = bahnhofPos.longitude;
} else {
minLat = Math.min(minLat, bahnhofPos.latitude);
maxLat = Math.max(maxLat, bahnhofPos.latitude);
minLon = Math.min(minLon, bahnhofPos.longitude);
maxLon = Math.max(maxLon, bahnhofPos.longitude);
}
clusterer.addItem(geoItem);
}
clusterer.redraw();
if (myPos == null || (myPos.latitude == 0.0 && myPos.longitude == 0.0)) {
myPos = new LatLong((minLat + maxLat) / 2, (minLon + maxLon) / 2);
}
updatePosition();
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station in project RSAndroidApp by RailwayStations.
the class MapsActivity method onTap.
@Override
public void onTap(final BahnhofGeoItem marker) {
final Intent intent = new Intent(MapsActivity.this, DetailsActivity.class);
final String id = marker.getStation().getId();
final String country = marker.getStation().getCountry();
try {
final Station station = dbAdapter.getStationByKey(country, id);
intent.putExtra(DetailsActivity.EXTRA_STATION, station);
startActivity(intent);
} catch (final RuntimeException e) {
Log.wtf(TAG, String.format("Could not fetch station id %s that we put onto the map", id), e);
}
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Station in project RSAndroidApp by RailwayStations.
the class NearbyNotificationService method checkNearestStation.
private void checkNearestStation() {
double minDist = 3e3;
Station nearest = null;
for (final Station station : nearStations) {
final double dist = calcDistance(station);
if (dist < minDist) {
nearest = station;
minDist = dist;
}
}
if (nearest != null && minDist < MIN_NOTIFICATION_DISTANCE) {
notifyNearest(nearest, minDist);
Log.i(TAG, "Issued notification to user");
} else {
Log.d(TAG, "No notification - nearest station was " + minDist + " km away: " + nearest);
}
}
Aggregations