use of de.bahnhoefe.deutschlands.bahnhofsfotos.util.NavItem 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();
}
Aggregations